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
When a function receives as argument another function that does not return, then the error Return statement in function which does not return can raise or not depending on the argument construction:
if is lambda raises error
if is defined using def error does not raise
To Reproduce
fromtypingimportCallable, NoReturndef_raise(err: Exception) ->NoReturn:
raiseerrdef_foo(f: Callable[[], NoReturn]) ->NoReturn:
f()
def_raise_2() ->NoReturn:
raiseException("foo")
value: bool=True# dummy var to enable to put the two casesifvalue:
y: NoReturn=_foo(_raise_2) # mypy does not complainelse:
x: NoReturn=_foo(lambda: _raise(Exception("foo"))) # mypy complains
Expected Behavior
mypy should not complain about non-existent return statements in the lambda definition (case of variable x) as the lambda definition is equivalent to the def _raise_2 definition.
even if return f() is used in _foo this should not trigger an error when the type being returned is also NoReturn
Actual Behavior
mypy sees an implicit return statement in lambdas definition
return of a NoReturn is not allowed
Your Environment error: Return statement in function which does not return [misc]
Mypy version used: 1.0.1
Mypy command-line flags: --show-error-codes
Mypy configuration options from mypy.ini (and other config files):
[mypy]
warn_no_return = True
Python version used: 3.11
The text was updated successfully, but these errors were encountered:
Bug Report
When a function receives as argument another function that does not return, then the error
Return statement in function which does not return
can raise or not depending on the argument construction:def
error does not raiseTo Reproduce
Expected Behavior
x
) as the lambda definition is equivalent to thedef _raise_2
definition.return f()
is used in_foo
this should not trigger an error when the type being returned is alsoNoReturn
Actual Behavior
NoReturn
is not allowedYour Environment
error: Return statement in function which does not return [misc]
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: