-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Generate a warning/error on assigning values of type NoReturn #4179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This example actually generates an error on master:
For me this is OK. We can keep this open if you want a dedicated error message for such cases, but I think this is quite low priority. |
Here's another example of how from typing import NoReturn, Union
def one() -> NoReturn:
raise ValueError()
def two() -> int:
return 1
def three(arg: int) -> Union[int, NoReturn]:
if arg > 0:
return two()
return one()
reveal_type(three(1)) # types.py:15: error: Revealed type is 'Union[builtins.int, <nothing>]'
reveal_type(three(1) + 1) # types.py:16: error: Revealed type is 'builtins.int' But, it surely should not do this. |
Why is this incorrect? I don't see any problem with simplifying |
@ilevkivskyi Year later lol. What if the exception is raised explicitly? In my opinion it would make sense to note that this is expected behaviour, isn't it?
|
@Dambre |
Surely |
It would be nice if mypy warned in this situation.
The text was updated successfully, but these errors were encountered: