-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Rewrite list(x for x in y)
to list(y)
#10403
Labels
Comments
charliermarsh
added
rule
Implementing or modifying a lint rule
help wanted
Contributions especially welcome
labels
Mar 14, 2024
I would like to contribute on this. Should I implement it on inside C400 or add an another rule which matches only expression of type |
I think we should augment C400 to support it. |
Closed by #10419. Thanks @boolean-light! |
charliermarsh
pushed a commit
that referenced
this issue
Mar 15, 2024
…matches `C416` (#10419) ## Summary Short-circuit implementation mentioned in #10403. I implemented this by extending C400: - Made `UnnecessaryGeneratorList` have information of whether the the short-circuiting occurred (to put diagnostic) - Add additional check for whether in `unnecessary_generator_list` function. Please give me suggestions if you think this isn't the best way to handle this :) ## Test Plan Extended `C400.py` a little, and written the cases where: - Code could be converted to one single conversion to `list` e.g. `list(x for x in range(3))` -> `list(range(3))` - Code couldn't be converted to one single conversion to `list` e.g. `list(2 * x for x in range(3))` -> `[2 * x for x in range(3)]` - `list` function is not built-in, and should not modify the code in any way.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Given
list(x for x in y)
, we first hit C400, which fixes to[x for x in y]
, which hits C416, which fixes tolist(y)
. We should consider short-circuiting this.The text was updated successfully, but these errors were encountered: