-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[perflint
] Handle tuples in dictionary comprehensions (PERF403
)
#19934
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
Conversation
4ef1ddb
to
dce411b
Compare
@ntBre |
Thank you! I'll try to get to it this week :) |
|
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.
Thank you, this looks great! I just had a few small suggestions.
crates/ruff_linter/src/rules/perflint/rules/manual_dict_comprehension.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/perflint/rules/manual_dict_comprehension.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/perflint/rules/manual_dict_comprehension.rs
Outdated
Show resolved
Hide resolved
da2587d
to
63f7ca4
Compare
@ntBre Thanks again! |
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.
Thank you!
perflint
] Handle tuples in dictionary comprehensions (PERF403
)
This pull request fixes the bug described in issue #19153.
The issue occurred when
PERF403
incorrectly flagged cases involving tuple unpacking in a for loop. For example:This code was wrongly suggested to be rewritten into a dictionary comprehension, which changes the semantics.
Changes in this PR:
Updated the
PERF403
rule to correctly handle tuple unpacking in loop targets.Added regression tests to ensure this case (and similar ones) are no longer flagged incorrectly.
Why:
This ensures that
PERF403
only triggers when a dictionary comprehension is semantically equivalent to the original loop, preventing false positives.