You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PLR5501 and PLW0120 safe fixes delete a trailing comment on the else: line #29395
The safe fixes for collapsible-else-if (PLR5501) and useless-else-on-loop (PLW0120) delete a comment that
trails the else: they remove. The superfluous-else-* fixes (RET505–RET508) keep such a comment and move it to
its own line.
deff(a, b):
ifa:
return1else: # explain the fallbackifb:
return2else:
return3
For comparison, ruff check --isolated --select RET505 --fix on
deff(a):
ifa:
return1else: # the fallbackreturn2
keeps the comment:
deff(a):
ifa:
return1# the fallbackreturn2
remove_else in flake8_return/rules/function.rs handles this explicitly ("if there is a comment on the same line as
the Colon, let's keep it"). convert_to_elif (PLR5501) and remove_else in useless_else_on_loop.rs (PLW0120)
replace from the start of the else line and keep only what follows that line. #9779 and #13545 fixed own-line comments
between else: and the nested if; those are kept now, but a comment on the else: line itself is not.
Real-world cases: pydantic 2.14.1, pydantic/deprecated/json.py lines 109 and 132
(else: # We have exited the for loop without finding a suitable encoder), and contourpy 1.4.0, tests/util_config.py line 445 (else: # !quad_as_tri).
(Found while running Ruff's safe fixes over the top PyPI packages.)
Activity
[`pylint`] Mark fixes unsafe when deleting comments (`PLR5501`, `PLW0…