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

[Enhancement]: use of dict.setdefault #349

Open
pums974 opened this issue Nov 8, 2024 · 1 comment
Open

[Enhancement]: use of dict.setdefault #349

pums974 opened this issue Nov 8, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@pums974
Copy link

pums974 commented Nov 8, 2024

Overview

This is a suggestion for a new rule

I propose to suggest more usage of some_dict.setdefault(key, default value)

Proposal

It could replace a pattern a bit more obscure :

some_dict[key] = some_dict.get(key, default_value)

# or even
if key not in some_dict:
    some_dict[key]
@pums974 pums974 added the enhancement New feature or request label Nov 8, 2024
@dosisod
Copy link
Owner

dosisod commented Nov 20, 2024

Hi @pums974 , thank you for opening this! I think this is a good suggestion, and am open to PRs. AFAICT this isn't implemented in Ruff, so adding it into Refurb would be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants