-
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
Add known limitation to C416
with dictionaries
#13627
Conversation
|
crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs
Outdated
Show resolved
Hide resolved
C416
with tuple keysC416
with dictionaries
crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs
Outdated
Show resolved
Hide resolved
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.
Nice!
crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs
Outdated
Show resolved
Hide resolved
/// When the comprehension iterates over a sequence, the fix is correct. However, Ruff cannot | ||
/// consistently infer if the iterable type is a sequence or a mapping. |
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.
It's not really just the autofix that's incorrect in these cases: the message and suggestion of the rule's diagnostic is also incorrect in these cases
/// When the comprehension iterates over a sequence, the fix is correct. However, Ruff cannot | |
/// consistently infer if the iterable type is a sequence or a mapping. | |
/// When the comprehension iterates over a sequence, the rule's suggestion is correct. | |
/// However, Ruff cannot consistently infer if the iterable type is a sequence or a mapping. |
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.
I mean, it should be dict(iterable.keys())
right? I think the rule is correct and just the fix is wrong?
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.
Oh. Yeah, great point :)
I think we should try to improve C416 before it's stabilized, so it's not wrong so often. The fix could be safe for non-dict comprehensions if we don't mind dropping some comments. |
The policy I've been using for the minor releases I've been shepherding has been not to stabilise any rules that have significant open issues on the tracker |
Part of #13625
See also #13629