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

[rule] replace if key in dict: del dict[key] with dict.pop(key, None) #7537

Closed
dorschw opened this issue Sep 20, 2023 · 4 comments · Fixed by #14553
Closed

[rule] replace if key in dict: del dict[key] with dict.pop(key, None) #7537

dorschw opened this issue Sep 20, 2023 · 4 comments · Fixed by #14553
Labels
accepted Ready for implementation rule Implementing or modifying a lint rule

Comments

@dorschw
Copy link

dorschw commented Sep 20, 2023

I'd suggest it to flake8-simplify, but their repo seems inactive since late March 😞
If there's a better place to suggest it, please let me know and I'll copy it there.

- if key in dictionary:
-     del dictionary[key]
+ dictionary.pop(key, None)
@dorschw dorschw changed the title replace if key in dict: del dict[key] with dict.pop(key, None) [rule] replace if key in dict: del dict[key] with dict.pop(key, None) Sep 20, 2023
@charliermarsh charliermarsh added rule Implementing or modifying a lint rule needs-decision Awaiting a decision from a maintainer accepted Ready for implementation and removed needs-decision Awaiting a decision from a maintainer labels Sep 20, 2023
@charliermarsh
Copy link
Member

Seems reasonable to me as a ruff rule.

@Skylion007
Copy link
Contributor

You should bring this rule up to the flake8-simplify folks too, they love this kind of stuff and if they implement it, we have a nice rule code for us to build on.

@ScDor
Copy link

ScDor commented Sep 27, 2023 via email

@harupy
Copy link
Contributor

harupy commented Oct 14, 2023

@charliermarsh Can I work on this?

TheBits pushed a commit to TheBits/ruff that referenced this issue Dec 11, 2024
## Summary

Resolves astral-sh#7537.

## Test Plan

`cargo nextest run` and `cargo insta test`.

---------

Co-authored-by: Micha Reiser <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants