This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: typing.Never and typing.assert_never
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.11
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: JelleZijlstra Nosy List: AlexWaygood, David Foster, JelleZijlstra, gvanrossum, kj, sobolevn
Priority: normal Keywords: patch

Created on 2022-01-22 22:48 by JelleZijlstra, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30842 closed JelleZijlstra, 2022-01-23 23:40
Messages (5)
msg411297 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-01-22 22:48
At the moment, simply says:

    Special type indicating that a function never returns.

In practice, type checkers accept NoReturn as a bottom type in other positions too. We should document this behavior.
msg411301 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-22 23:12
I agree.

Plus, I cannot refrain from saying that it is generally quite hard to teach what "NoReturn" is.

I start by explaining what bottom type and `void` is and then just say that in Python it is called `NoReturn`. I remember that there was a discussion about `Never` alias for it.

Jelle, will you please push it? :)
msg411309 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2022-01-22 23:48
I also agree that documenting this is a great idea. It's already been adopted by large swathes of the typing community for use in this context. The value of having NoReturn act as a "bottom type" is evident. Time to make it official, in my opinion.
msg411347 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-01-23 05:22
Based on feedback here and on typing-sig I'm now leaning towards adding typing.Never along with typing.assert_never. I'll submit a single patch for these as the documentation will be closely linked.
msg412860 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2022-02-08 18:50
New changeset 243436f3779c1e7bed1fd4b23d5a8ec5eff40699 by Jelle Zijlstra in branch 'main':
bpo-46475: Add typing.Never and typing.assert_never (GH-30842)
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90633
2022-02-08 19:07:21JelleZijlstrasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-02-08 18:50:33gvanrossumsetmessages: + msg412860
2022-01-31 02:22:42David Fostersetnosy: + David Foster
2022-01-23 23:40:30JelleZijlstrasetkeywords: + patch
stage: patch review
pull_requests: + pull_request29023
2022-01-23 05:22:07JelleZijlstrasettype: enhancement
title: Document use of NoReturn as a bottom type -> typing.Never and typing.assert_never
messages: + msg411347
versions: - Python 3.9, Python 3.10
2022-01-22 23:48:29AlexWaygoodsetmessages: + msg411309
2022-01-22 23:12:44sobolevnsetmessages: + msg411301
2022-01-22 22:48:28JelleZijlstrasetcomponents: + Library (Lib)
versions: + Python 3.9, Python 3.10, Python 3.11
2022-01-22 22:48:21JelleZijlstracreate