[ruff] Implement mutable-fromkeys-value (RUF024)#9597
Merged
charliermarsh merged 4 commits intoastral-sh:mainfrom Jan 22, 2024
Merged
[ruff] Implement mutable-fromkeys-value (RUF024)#9597charliermarsh merged 4 commits intoastral-sh:mainfrom
ruff] Implement mutable-fromkeys-value (RUF024)#9597charliermarsh merged 4 commits intoastral-sh:mainfrom
Conversation
58bf244 to
e9410b9
Compare
Implement rule `mutable-fromkeys-value` (`RUF023`) with a fix marked as unsafe. Fix formatting in docs
e9410b9 to
6cd8382
Compare
Contributor
|
Member
|
Could you maybe use RUF024 for this? I'm using RUF023 for #9564 :) |
Contributor
Author
|
Oops, I will change it when I am back at my desk |
Contributor
|
Can you also open an issue on this for flake8-bugbear? I'm sure they'd love to include this rule and it would make more sense with a reserved B error code. Other ruff rule suggestions have been added there and we usually migrate the rule alias. |
Contributor
|
Ah nvm, there is an issue that has been open for a while: PyCQA/flake8-bugbear#387 |
mutable-fromkeys-value (RUF023)mutable-fromkeys-value (RUF024)
Contributor
Author
|
Thanks for renaming the PR @AlexWaygood, didn't realise I had missed that |
charliermarsh
approved these changes
Jan 22, 2024
Member
charliermarsh
left a comment
There was a problem hiding this comment.
Excellent work, thank you.
mutable-fromkeys-value (RUF024)ruff] Implement mutable-fromkeys-value (RUF024)
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
Implement rule
mutable-fromkeys-value(RUF023).Autofixes
to
{key: [] for key in foo}The fix is marked as unsafe as it changes runtime behaviour. It also uses
keyas the comprehension variable, which may not always be desired.Closes #4613.
Test Plan
cargo test