-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrong
Description
I have code like this:
class Possibility(Generic[T]):
def __init__(self, produce: Callable[[], T]):
self._produce = produce
def produce(self) -> T:
return self._produce()
def reject() -> NoReturn:
raise RuntimeError
def nothing() -> Possibility[NoReturn]:
return Possibility(lambda: reject()) # Error here
On the last line I get an error, "Return statement in function which does not return".
This is about the lambda, not about the explicit return statement! If I write return Possibility(reject)
it works. (But in the real code, the lambda takes a parameter and reject is a method of that parameter, so I can't do that. My workaround is to turn the lambda into a function, but that's verbose.)
If you can't fix things so that the lambda inherits the "never returns" bit, then how about making the error clearer, e.g. "Lambda never returns"?
AMDmi3
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong