-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[flake8-comprehensions
] Skip C416
if comprehension contains unpacking
#14909
Conversation
|
...comprehensions/snapshots/ruff_linter__rules__flake8_comprehensions__tests__C416_C416.py.snap
Outdated
Show resolved
Hide resolved
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
@dylwil3 @dhruvmanila Thanks for the comments. Could you take another look? |
| | ||
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()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d
might look like {"list": [1, 2]}
. If so, it can't be fixed to dict(d.items())
.
Looking at this now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Outdated
Show resolved
Hide resolved
Signed-off-by: harupy <[email protected]>
83413c9
to
7e67d05
Compare
Does this also solve #4491 ? Could you add a test demonstrating that if so? |
@dylwil3 No, it doesn't solve that issue. To solve that issue, I think type inference is required. |
Summary
Fix #11482. Applies adamchainz/flake8-comprehensions#205 to ruff.
C416
should be skipped if comprehension contains unpacking. Here's an example:Test Plan
Existing checks