-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
typing.NoReturn and typing.Never are somewhat unclear #117492
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
Thanks, feel free to submit a PR clarifying the documentation.
|
The reason a function with |
Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
…7678) (cherry picked from commit 852263e) Co-authored-by: Nice Zombies <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
…#118547) (cherry picked from commit 852263e) Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Nice Zombies <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
Documentation
In the typing docs, typing.Never and typing.NoReturn are somewhat unclear.
NoReturn used to be a type for function annotations when the function never returns. PEP 484 even says "The NoReturn type is only valid as a return annotation of functions, and considered an error if it appears in other positions". In practice, however, NoReturn was used as a bottom type, which eventually culminated in the addition of Never in #90633. However, it's still somewhat unclear from the typing docs exactly how you're supposed to use typing.Never and typing.NoReturn. In particular, are you supposed to prefer NoReturn for the return types of functions that never return?
Never
Never says, in part:
It then gives one example, a function never_call_me with an argument of type Never. Presumably this is the "a function that should never be called" case.
NoReturn
NoReturn says, in part
Further information: https://typing.readthedocs.io/en/latest/spec/special-types.html#noreturn , https://typing.readthedocs.io/en/latest/spec/special-types.html#never, https://typing.readthedocs.io/en/latest/source/unreachable.html#never-and-noreturn
Linked PRs
typing.Never
#117678typing.Never
(GH-117678) #118547The text was updated successfully, but these errors were encountered: