Warn about `dict.fromkeys(keys, mutable)`
janosh opened this issue · comments
Janosh Riebesell commented
Suggest the following fix when passing a mutable 2nd arg to dict.fromkeys()
since modifications will affect all keys which is a common pitfall.
# bad
dict.fromkeys((1, 2), {})
dict.fromkeys((1, 2), [])
dict.fromkeys((1, 2), set())
# ...
# good
{key: {} for key in (1, 2)}
{key: [] for key in (1, 2)}
{key: set() for key in (1, 2)}
Examples:
Related issue: astral-sh/ruff#4613