-
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
Warn about dict.fromkeys(keys, mutable)
#4613
Comments
Oh interesting, I've never seen that! |
janosh
changed the title
Error on
Warn about May 24, 2023
dict.fromkeys(keys, mutable)
dict.fromkeys(keys, mutable)
Flake8-bugbear might be interested in adding this rule too, you should open an issue there as well. |
charliermarsh
added
accepted
Ready for implementation
and removed
needs-decision
Awaiting a decision from a maintainer
labels
Jan 20, 2024
Marking as accepted, makes sense to me. |
I'll implement this tomorrow (as a precursor to #9592)! |
charliermarsh
pushed a commit
that referenced
this issue
Jan 22, 2024
## Summary Implement rule `mutable-fromkeys-value` (`RUF023`). Autofixes ```python dict.fromkeys(foo, []) ``` to ```python {key: [] for key in foo} ``` The fix is marked as unsafe as it changes runtime behaviour. It also uses `key` as the comprehension variable, which may not always be desired. Closes #4613. ## Test Plan `cargo test`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ruff
should error and suggest the following fix when passing a mutable 2nd arg todict.fromkeys()
since modifications will affect all keys which is a common pitfall.Examples:
The text was updated successfully, but these errors were encountered: