Skip to content
New issue

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

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

Already on GitHub? # to your account

Add "simplify comprehension" check #126

Merged
merged 1 commit into from
Nov 18, 2022
Merged

Conversation

dosisod
Copy link
Owner

@dosisod dosisod commented Nov 18, 2022

This check will try and simplify your comprehension expressions, and suggest that you use shorthand notation in the case of passing generators or comprehensions to list and set.

I am disabling this by default though. The issue being that in some cases, following Refurb's advice will make your code faster, and in some cases, make it slower. This is mainly due to the fact that generator expressions, although more succinct (no wrapping brackets), will incur more run-time overhead because it lazily evaluates, whereas list/set comprehensions can be eager. On the flip side, list/set comprehensions are much faster then constructing a list/set manually.

Currently, there is no way to pass arguments into a check. Once this functionality is in place, I will re-enable this check, since users should be able to specify whether they want to optimize for using shorthand notation, using generators, or list/set comprehensions (ie, eager).

This check will try and simplify your comprehension expressions, and suggest
that you use shorthand notation in the case of passing generators or
comprehensions to `list` and `set`.

I am disabling this by default though. The issue being that in some cases,
following Refurb's advice will make your code faster, and in some cases, make
it slower. This is mainly due to the fact that generator expressions, although
more succinct (no wrapping brackets), will incur more run-time overhead because
it lazily evaluates, whereas list/set comprehensions can be eager. On the flip
side, list/set comprehensions are much faster then constructing a `list`/`set`
manually.

Currently, there is no way to pass arguments into a check. Once this
functionality is in place, I will re-enable this check, since users should be
able to specify whether they want to optimize for using shorthand notation,
using generators, or list/set comprehensions (ie, eager).
@dosisod dosisod merged commit d132209 into master Nov 18, 2022
@dosisod dosisod deleted the simplify-comprehension branch November 18, 2022 03:28
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant