Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-90633: Improve error and docs for typing.assert_never #91720

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

Merged
merged 4 commits into from
Apr 25, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Apply suggestions from code review
Thanks Alex!

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
  • Loading branch information
JelleZijlstra and AlexWaygood authored Apr 24, 2022
commit 8d63329dbcb125bb476703e2cb67423870022a4e
5 changes: 4 additions & 1 deletion 5 Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2341,14 +2341,17 @@ Functions and decorators
case _ as unreachable:
assert_never(unreachable)

Here, the type annotations allow the type checker to infer that the
Here, the annotations allow the type checker to infer that the
last case can never execute, because ``arg`` is either
an :class:`int` or a :class:`str`, and both options are covered by
earlier cases.
If a type checker finds that a call to ``assert_never()`` is
reachable, it will emit an error. For example, if the type annotation
for ``arg`` was instead ``int | str | float``, the type checker would
emit an error pointing out that ``unreachable`` is of type :class:`float`.
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
For a call to ``assert_never`` to succeed, the inferred type of
the argument passed in must be the bottom type, :data:`Never`, and nothing
else.

At runtime, this throws an exception when called.

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.