Skip to content

gh-117492: Clarify documentation of typing.Never#117678

Merged
JelleZijlstra merged 11 commits into
python:mainfrom
nineteendo:improve-typing.never-docs
May 3, 2024
Merged

gh-117492: Clarify documentation of typing.Never#117678
JelleZijlstra merged 11 commits into
python:mainfrom
nineteendo:improve-typing.never-docs

Conversation

@nineteendo

@nineteendo nineteendo commented Apr 9, 2024

Copy link
Copy Markdown
Contributor

@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news labels Apr 9, 2024
@nineteendo
nineteendo marked this pull request as ready for review April 9, 2024 14:37
Comment thread Doc/library/typing.rst Outdated
nineteendo and others added 2 commits April 9, 2024 16:41
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@nineteendo nineteendo changed the title gh-117492: Clarify documentation of typing.NoReturn & typing.Never gh-117492: Clarify documentation of typing.Never Apr 12, 2024
Comment thread Doc/library/typing.rst Outdated
@nineteendo nineteendo changed the title gh-117492: Clarify documentation of typing.Never gh-117492: Deprecate typing.NoReturn Apr 13, 2024
@nineteendo

This comment was marked as resolved.

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm definitely going to oppose deprecating NoReturn, sorry! Perhaps if we were inventing it from scratch we wouldn't give it that name, but I haven't seen anything that would justify the huge disruption for users that would be caused by a deprecation

@bedevere-app

bedevere-app Bot commented Apr 13, 2024

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@nineteendo

nineteendo commented Apr 13, 2024

Copy link
Copy Markdown
Contributor Author

OK, but if we keep it, we should say that NoReturn is preferred for return types or that it's kept for backwards compatibility and won't be removed. But the latter kind of sounds like deprecation to me, which you don't want.

This reverts commit 1b3c55c.
@nineteendo

Copy link
Copy Markdown
Contributor Author

Alex, I have made the requested changes; please review again, but what do we do then instead? Opinions seem to be somewhat divided.

@bedevere-app

bedevere-app Bot commented Apr 13, 2024

Copy link
Copy Markdown

Thanks for making the requested changes!

@AlexWaygood: please review the changes made to this pull request.

@bedevere-app
bedevere-app Bot requested a review from AlexWaygood April 13, 2024 10:34
@AlexWaygood
AlexWaygood dismissed their stale review April 13, 2024 10:35

No longer proposes deprecation

@AlexWaygood

Copy link
Copy Markdown
Member

I concur with Jelle

@nineteendo

Copy link
Copy Markdown
Contributor Author

I've removed the style suggestion, but just to clarify, this still holds right?

NoReturn can also be used as a bottom type, a type that has no values. Starting in Python 3.11, the Never type should be used for this concept instead.

So, you shouldn't do this in 3.11 (if you're not aiming for backwards compatibility):

from typing import NoReturn

def never_call_me(arg: NoReturn) -> None:
    pass

@JelleZijlstra
JelleZijlstra self-requested a review April 13, 2024 17:53
@nineteendo

Copy link
Copy Markdown
Contributor Author

Sorry for my impatience, but do we merge the documentation of Never & NoReturn or is it clear now?
I would like to finish this pull request.

@JelleZijlstra

Copy link
Copy Markdown
Member

I'll take a look soon. I might indeed want to document the two together.

@wyattscarpenter

wyattscarpenter commented Apr 28, 2024

Copy link
Copy Markdown

By the way, @nineteendo, thanks for taking charge of this concern and making a pull request. I might have done it myself eventually, but concluded I wasn't yet up to the task given the ambiguous nature of the subject matter. So, thanks!

@nineteendo

nineteendo commented Apr 28, 2024

Copy link
Copy Markdown
Contributor Author

I am afraid it will take at least until May 16 for this to be reviewed (1 month before pinging the issue + 1 week waiting for a response). @JelleZijlstra seems to be quite busy. https://devguide.python.org/getting-started/pull-request-lifecycle/#reviewing

@JelleZijlstra

JelleZijlstra commented Apr 28, 2024

Copy link
Copy Markdown
Member

I pushed some changes:

  • There is (conceptually) only a single bottom type; Never and NoReturn both represent that single conceptual type.
  • Mention the use as a return type case first, as it is by far more common in user code.
  • Mention common examples of functions that would use Never in their annotations.
  • Mention that the two are equivalent without unnecessary further verbiage.

I'll give other maintainers some time for a review.

@nineteendo

Copy link
Copy Markdown
Contributor Author

Thanks for taking some time, this looks a lot cleaner.

@wyattscarpenter

Copy link
Copy Markdown

Thanks for your work, @JelleZijlstra; it looks great.

Comment thread Doc/library/typing.rst Outdated
Comment thread Doc/library/typing.rst Outdated
Comment thread Doc/library/typing.rst Outdated
Comment thread Doc/library/typing.rst Outdated
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@JelleZijlstra
JelleZijlstra merged commit 852263e into python:main May 3, 2024
@JelleZijlstra JelleZijlstra added the needs backport to 3.12 only security fixes label May 3, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @nineteendo for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 3, 2024
…7678)

(cherry picked from commit 852263e)

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@bedevere-app

bedevere-app Bot commented May 3, 2024

Copy link
Copy Markdown

GH-118547 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label May 3, 2024
JelleZijlstra added a commit that referenced this pull request May 3, 2024
…#118547)

(cherry picked from commit 852263e)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@nineteendo
nineteendo deleted the improve-typing.never-docs branch May 3, 2024 13:53
SonicField pushed a commit to SonicField/cpython that referenced this pull request May 8, 2024
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants