Content-Length: 237350 | pFad | http://github.com/astral-sh/ruff/pull/16775

72 [`ruff`] implement `IfKeyNotInDictAssign` rule (RUF060) by alex-700 · Pull Request #16775 · astral-sh/ruff · GitHub
Skip to content
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

[ruff] implement IfKeyNotInDictAssign rule (RUF060) #16775

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alex-700
Copy link
Contributor

Summary

Implement IfKeyNotInDictAssign rule (RUF060)

which suggest to use setdefault.

closes #7897
see also dosisod/refurb#349

Notes

In the implementation:

  • the functions is_same_arg/is_same_key are implemented in a strange (syntactic) way. I think it's worth catching complex expressions here (espessially in arg case), but can't find the right machinery to structured comparison of it.
  • the functions is_idempotent/is_cheap_to_evaluate are implemented in really simple and conservative way, and so have a lot of false negative. We can implement them by using walk_expr machinery instead (e.g. to find function call-s), but I do not have strong opinion here. What do you think, is additional code complexity worth it?

Test Plan

cargo test

@MichaReiser MichaReiser added rule Implementing or modifying a lint rule needs-decision Awaiting a decision from a maintainer labels Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Linting Rule: Prefer setdefault Over Conditional Key Checks for Dictionary Assignment
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/astral-sh/ruff/pull/16775

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy