Skip to content

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

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 11 commits into from
May 3, 2024

Conversation

nineteendo
Copy link
Contributor

@nineteendo nineteendo commented Apr 9, 2024

@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
@nineteendo nineteendo changed the title gh-117492: Clarify documentation of typing.NoReturn & typing.Never gh-117492: Clarify documentation of typing.Never Apr 12, 2024
@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.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

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
Copy link

bedevere-app bot commented Apr 13, 2024

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
Copy link
Contributor Author

nineteendo commented Apr 13, 2024

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
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
Copy link

bedevere-app bot commented Apr 13, 2024

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
Member

I concur with Jelle

@nineteendo
Copy link
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
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
Member

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

@wyattscarpenter
Copy link

wyattscarpenter commented Apr 28, 2024

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
Copy link
Contributor Author

nineteendo commented Apr 28, 2024

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
Copy link
Member

JelleZijlstra commented Apr 28, 2024

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
Contributor Author

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

@wyattscarpenter
Copy link

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

Co-authored-by: Erlend E. Aasland <[email protected]>
@JelleZijlstra JelleZijlstra merged commit 852263e into python:main May 3, 2024
27 checks passed
@JelleZijlstra JelleZijlstra added the needs backport to 3.12 only security fixes label May 3, 2024
@miss-islington-app
Copy link

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 <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Erlend E. Aasland <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented May 3, 2024

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 <[email protected]>
Co-authored-by: Nice Zombies <[email protected]>
Co-authored-by: Erlend E. Aasland <[email protected]>
@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
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