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
Ruff preview rule RUF047 (needless-else) complains on the code that has an intentionally added empty else branch as one of recommended by pylint ways to fix the rule confusing-consecutive-elif / R5601:
Description:
Used when an elif statement follows right after an indented block which itself ends with if or elif. It may not be obvious if the elif statement was willingly or mistakenly unindented. Extracting the indented if statement into a separate function might avoid confusion and prevent errors.
Problematic code:
def myfunc(shall_continue: bool, shall_exit: bool):
if shall_continue:
if input("Are you sure?") == "y":
print("Moving on.")
elif shall_exit: # [confusing-consecutive-elif]
print("Exiting.")
Correct code:
# Option 1: add explicit 'else'
def myfunc(shall_continue: bool, shall_exit: bool):
if shall_continue:
if input("Are you sure?") == "y":
print("Moving on.")
else:
pass
elif shall_exit:
print("Exiting.")
...
Currently we need to either suppress ruff or pylint rules for such cases.
Actually, I'm not sure what is the bigger problem here: the fact the ruff complains on the problem or the fact that I can't suppress it locally.
Local suppression of the ruff locally in this case doesn't work because of RUF100 [*] Unused 'noqa' directive (unused: 'RUF047')
The text was updated successfully, but these errors were encountered:
The first issue is about RUF047 conflicting with R5601. This isn't about two Ruff rules conflicting. This is about R5601 in the original pylint linter making a conflicting recommendation with one of Ruff's rules.
Ruff doesn't currently have a reimplementation of R5601 in its pylint category. The rule was considered in #10103, but was rejected for now. In general, we try to guarantee that no two Ruff rules will offer conflicting recommendations, but I don't think we make any guarantees about being able to run Ruff alongside other linters.
This is an edge case, as else branches with any kinds of comments, pragma or not, are never reported. Thus, I think it is more preferable to either suppress R5601 or add a (normal) comment explaining why that empty branch is necessary.
Description
ruff 0.9.3
Ruff preview rule
RUF047 (needless-else)
complains on the code that has an intentionally added emptyelse
branch as one of recommended by pylint ways to fix the rule confusing-consecutive-elif / R5601:Currently we need to either suppress ruff or pylint rules for such cases.
Actually, I'm not sure what is the bigger problem here: the fact the ruff complains on the problem or the fact that I can't suppress it locally.
Local suppression of the ruff locally in this case doesn't work because of
RUF100 [*] Unused 'noqa' directive (unused: 'RUF047')
The text was updated successfully, but these errors were encountered: