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
I'm wondering whether there could be a Ruff rule for this. Often, Ruff lacks the type information. But in this case type information isn't needed. If a function:
has a return annotation,
and it's different than -> None or -> NoReturn,
and the body
isn't a stub (... or pass)
doesn't have a returnanywhere (in that case RET503 takes over)
and control flow can reach the end of the body
report an error
defok_1() ->int|None:
return2defok_2() ->int|None:
return# < maybe a second rule later could reject `return` without a value in this scenariodefok_3() ->int|None:
raiseNotImplementedErrordefok_4() ->int|None: ...
defok_5() ->int|None:
passdefok_6() ->int|None:
if ...:
return42# RET503 will cause an error heredefok_7():
f()
defbad_1() ->int|None:
f()
defbad_2() ->int|None:
if ...:
raiseValueError()
The text was updated successfully, but these errors were encountered:
I just stumbled over a bug in our codebase:
The last line should have been
return f()
.While Mypy reports a
Missing return statement
, Pyright does not. This is a deliberate decision by the Pyright maintainer (point 2) as there is no type issue here. In this case Mypy actually does some static analysis outside of its main responsibility.I'm wondering whether there could be a Ruff rule for this. Often, Ruff lacks the type information. But in this case type information isn't needed. If a function:
-> None
or-> NoReturn
,...
orpass
)return
anywhere (in that case RET503 takes over)The text was updated successfully, but these errors were encountered: