Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Other rules for replacing lambda expressions #114

Open
ericbn opened this issue Mar 27, 2022 · 1 comment
Open

Other rules for replacing lambda expressions #114

ericbn opened this issue Mar 27, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@ericbn
Copy link

ericbn commented Mar 27, 2022

Since you have "lambda: [] is equivalent to the builtin list", I suggest other rules with similar refactoring strategies:

  • lambda: {} is equivalent to the builtin dict
  • lambda arg: f(arg) is equivalent to f
  • lambda obj: obj.attr is equivalent to operator.attrgetter('attr')
  • lambda items: items[0] is equivalent to operator.itemgetter(0)
  • lambda obj: obj.name() is equivalent to operator.methodcaller('name')

The descriptions are still not generic enough, and maybe should not be the ones to be really used.

Some of these rules can be rather complex, in terms of all the possible variations.

@sbdchd sbdchd added the enhancement New feature or request label Mar 27, 2022
@djmattyg007
Copy link

lambda obj: obj.name() is equivalent to operator.methodcaller('name')

This may be equivalent, but it is certainly worse. It requires more code, it requires importing another module, and its intent is simply not as clear to inexperienced programmers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants