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
For the following code snippet ruff detects a violation of SIM505:
def foo_sim108(bar):
if bar is not None:
xyz = bar
else:
xyz = "bar"
return xyz
and proposes
def foo_sim108(bar):
xyz=bar if bar is not None else "bar"
return xyz
Usually I would omit xyz and write
def foo_ret505(bar):
if bar is not None:
return bar
else:
return "bar"
which is simplified by RET505 to
def foo(bar):
if bar is not None:
return bar
return "bar"
However the shortest version would be
def simplified_foo(bar):
return bar if bar is not None else "bar"
For me it is a special case for SIM108 (return means that a value is assigned to the function output), but ruff does not propose this solution.
Is this intended?
If yes, I would be happy to have this behavior described in the SIM108 documentation.
If no, I would love to have it implemented.
Keywords: SIM108, RET505
Ruff version: 0.7.0
The text was updated successfully, but these errors were encountered:
Yes, this is intentional because there's RET504 that detects the unnecessary assignment to xyz before returning (playground). Keeping the rules separate is that users are in control on whether they prefer the assignment before the return or not.
For the following code snippet ruff detects a violation of SIM505:
and proposes
Usually I would omit xyz and write
which is simplified by RET505 to
However the shortest version would be
For me it is a special case for SIM108 (return means that a value is assigned to the function output), but ruff does not propose this solution.
Is this intended?
If yes, I would be happy to have this behavior described in the SIM108 documentation.
If no, I would love to have it implemented.
Keywords: SIM108, RET505
Ruff version: 0.7.0
The text was updated successfully, but these errors were encountered: