-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Recognize functions like exit() as not returning #2280
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
Something like this? NoReturn = Union[()]
def exit(n: int) -> NoReturn: ... |
That is one way to do it, but it may be a little confusing. |
It's better than special casing exit(), which will not be robust and cannot be as flexible. If naming is the problem, it can be solved (as above) from outside of mypy. Converging to naming conventions of another language such as |
Having a general mechanism would be more flexible, but that's harder since we'll need to standardize on a solution (this has been discussed before and needs a decision here: python/typing#165). Special casing a few functions like |
Let's start by special casing the exit functions in the standard library. That might be good enough for a while. |
Here's a strategy that could work. Make mypy understand Union[()] as the
magic, and update typeshed to mark up sys.exit(), os.exit() and
builtins.exit() with `-> Union[()]`. We won't need changes to typing.py
immediately (because this is only in the stubs) but we should still go
ahead and update typing.py to allow Union[()] -- currently it doesn't allow
this. We should also update PEP 484 to explain this.
Since it's relatively uncommon apart from those few builtins maybe we won't
need to pick a name for this -- Union[()] can be the idiomatic way to spell
it.
|
We're going to spell this as |
It looks like this issue is fixed now. At least the original example works correctly. |
Yeah, this is fixed as of #2798. |
This generates a warning when using
--warn-no-return
, even though it's safe:It would be nice if mypy knew about at least the most common stdlib functions that never return such as
sys.exit
.The text was updated successfully, but these errors were encountered: