dosisod/refurb

[Enhancement]: use of dict.setdefault

Opened this issue · 1 comments

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]

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.