mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
519 B
519 B
unnecessary-generator-dict (C402)
Derived from the flake8-comprehensions linter.
Autofix is always available.
What it does
Checks for unnecessary generators that can be rewritten as dict
comprehensions.
Why is this bad?
It is unnecessary to use dict
around a generator expression, since
there are equivalent comprehensions for these types. Using a
comprehension is clearer and more idiomatic.
Examples
dict((x, f(x)) for x in foo)
Use instead:
{x: f(x) for x in foo}