Skip to content
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

Made proposed change to the typing spec with regard to NoReturn and… #1570

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions docs/spec/special-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,16 @@ is unreachable and will behave accordingly::
return 'whatever works' # Error might be not reported by some checkers
# that ignore errors in unreachable blocks

The ``NoReturn`` type is only valid as a return annotation of functions,
and considered an error if it appears in other positions::

from typing import NoReturn

# All of the following are errors
def bad1(x: NoReturn) -> int:
...
bad2: NoReturn = None
def bad3() -> list[NoReturn]:
...

``Never``
---------

Since Python 3.11, the ``typing`` module has a primitive ``Never``. This
represents the bottom type, a type that has no members. Type checkers are
expected to treat this type as equivalent to ``NoReturn``, but it is explicitly
also allowed in argument positions.
Since Python 3.11, the ``typing`` module contains a primitive ``Never``. It
represents the bottom type, a type that has no members.

The ``Never`` type is equivalent to ``NoReturn``, which is discussed above.
The ``NoReturn`` type is conventionally used in return annotations of
functions, and ``Never`` is typically used in other locations, but the two
types are completely interchangeable.

Tuples
------
Expand Down
Loading