-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
ruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
Summary
if-else-block-instead-of-if-exp (SIM108) should apply when the assignment in the if block (though not the one in the else block) is annotated. Example:
$ cat >sim108.py <<'# EOF'
def f(x: object) -> int:
if x:
y: int = 1
else:
y = 2
return y
# EOF
$ ruff --isolated check sim108.py --select SIM108 --unsafe-fixes --fix
All checks passed!The ideal fixed version is:
def f(x: object) -> int:
y: int = 1 if x else 2
return yVersion
ruff 0.14.4 (c7ff982 2025-11-06)
Metadata
Metadata
Assignees
Labels
ruleImplementing or modifying a lint ruleImplementing or modifying a lint rule