mirror of
https://github.com/astral-sh/ruff
synced 2026-01-20 21:10:48 -05:00
453 B
453 B
if-to-dict (SIM116)
Derived from the flake8-simplify linter.
Autofix is always available.
What it does
Checks for three or more consecutive if-statements with direct returns
Why is this bad?
These can be simplified by using a dictionary
Example
if x = 1:
return "Hello"
elif x = 2:
return "Goodbye"
else:
return "Goodnight"
Use instead:
return {1: "Hello", 2: "Goodbye"}.get(x, "Goodnight")