Remove None From Default Get¶
Sourcery refactoring id: remove-none-from-default-get
¶
Description:¶
Replace dict.get(x, None)
with dict.get(x)
Before:¶
hats = {"bowler": Bowler(), "sombrero": Sombrero()}
fedora = hats.get("fedora", None)
After:¶
hats = {"bowler": Bowler(), "sombrero": Sombrero()}
fedora = hats.get("fedora")
Explanation:¶
When using a dictionary's get
method you can specify a default to return if
the key is not found. This defaults to None
, so it is unnecessary to specify
None
if this is the required behaviour. Removing the unnecessary argument
makes the code slightly shorter and clearer.