Add "simplify comprehension" check #126
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andset
.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).