[flake8-comprehensions] Skip C416 if comprehension contains unpacking#14909
Merged
dhruvmanila merged 8 commits intoastral-sh:mainfrom Dec 20, 2024
Merged
[flake8-comprehensions] Skip C416 if comprehension contains unpacking#14909dhruvmanila merged 8 commits intoastral-sh:mainfrom
flake8-comprehensions] Skip C416 if comprehension contains unpacking#14909dhruvmanila merged 8 commits intoastral-sh:mainfrom
Conversation
Contributor
|
harupy
commented
Dec 11, 2024
...comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C416_C416.py.snap
Show resolved
Hide resolved
harupy
commented
Dec 11, 2024
crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs
Outdated
Show resolved
Hide resolved
C416 if comprehension contains unpackingflake8-comprehensions] Skip C416 if comprehension contains unpacking
Contributor
Author
|
@dylwil3 @dhruvmanila Thanks for the comments. Could you take another look? |
harupy
commented
Dec 17, 2024
| | | ||
| 9 | {k: v for k, v in d.items()} | ||
| 10 | [(k, v) for k, v in d.items()] | ||
| 11 | {k: (a, b) for k, (a, b) in d.items()} |
Contributor
Author
There was a problem hiding this comment.
d might look like {"list": [1, 2]}. If so, it can't be fixed to dict(d.items()).
Member
|
Looking at this now |
dhruvmanila
approved these changes
Dec 19, 2024
Member
dhruvmanila
left a comment
There was a problem hiding this comment.
Looks good. It's a bummer that we have to move away from ComparableExpr which adds a lot of complexity around matching and extracting the values.
crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs
Show resolved
Hide resolved
83413c9 to
7e67d05
Compare
Collaborator
|
Does this also solve #4491 ? Could you add a test demonstrating that if so? |
Contributor
Author
|
@dylwil3 No, it doesn't solve that issue. To solve that issue, I think type inference is required. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fix #11482. Applies adamchainz/flake8-comprehensions#205 to ruff.
C416should be skipped if comprehension contains unpacking. Here's an example:Test Plan
Existing checks