GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-46475: Add typing.Never and typing.assert_never by JelleZijlstra · Pull Request #30842 · python/cpython

Conversation

@JelleZijlstra

@JelleZijlstra JelleZijlstra commented Jan 23, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Another pending proposal from typing-sig.

  • Add a Never primitive that is semantically identical to NoReturn, but documented explicitly as a bottom type. I chose to make it a separate object instead of a pure alias for NoReturn so that dynamic checkers can distinguish between the two and so that we can document them separately.
  • Add an assert_never() function to statically assert that code is unreachable. Based on @davidfstr's feedback, the error raised by the function does not include the argument.

https://bugs.python.org/issue46475

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

antonagestam and henryiii reacted with hooray emoji
All reactions
  • 🎉 2 reactions
@JelleZijlstra
bpo-46475: Add typing.Never and typing.assert_never
86a868f
@JelleZijlstra
JelleZijlstra requested review from Fidget-Spinner and gvanrossum as code owners January 23, 2022 23:40
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Jan 23, 2022
@bedevere-bot bedevere-bot added the awaiting review label Jan 23, 2022
@JelleZijlstra
JelleZijlstra force-pushed the never branch from e3fe2cb to 86a868f Compare January 23, 2022 23:40
@JelleZijlstra JelleZijlstra added the DO-NOT-MERGE label Jan 23, 2022
sobolevn
sobolevn reviewed Jan 24, 2022
View reviewed changes

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thank you! Awesome features!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
deduplicate tests
4b227f6
Fidget-Spinner
Fidget-Spinner reviewed Jan 24, 2022
View reviewed changes
Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

davidfstr
davidfstr reviewed Jan 31, 2022
View reviewed changes
Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra added 3 commits January 30, 2022 18:20
@JelleZijlstra
Merge branch 'main' into never
403f8e5
@JelleZijlstra
Address David Foster's feedback
d3cc0f5
@JelleZijlstra
Merge branch 'main' into never
9621493
@JelleZijlstra JelleZijlstra removed the DO-NOT-MERGE label Feb 2, 2022
gvanrossum
gvanrossum reviewed Feb 2, 2022
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think we should iterate this until @Fidget-Spinner approves it and then he can merge it. I think the idea is good, and IIRC typing-sig is in agreement. (Though are there folks at Pyre or Google who don't read it but want issues instead? Sigh. :-( )

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
rename BottomTypeTests
1b297fe
@JelleZijlstra

JelleZijlstra commented Feb 2, 2022

Copy link
Copy Markdown
Member Author

Thanks @gvanrossum! I think I addressed all previous comments, so from my perspective this is ready.

https://mail.python.org/archives/list/[email protected]/thread/CGIYKGMF6XLDX3F2JNRCCE7HC6K2XLZ2/ is the typing-sig thread. Nobody opposed it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra JelleZijlstra closed this Feb 2, 2022
@JelleZijlstra JelleZijlstra reopened this Feb 2, 2022
@JelleZijlstra
Merge branch 'main' into never
02a3e89
@gvanrossum

gvanrossum commented Feb 6, 2022

Copy link
Copy Markdown
Member

Should I wait for the tests or are they hanging?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra

JelleZijlstra commented Feb 6, 2022

Copy link
Copy Markdown
Member Author

They just started, I had to fix a merge conflict. It's going to conflict with the Self change too, which is why I pinged you on that one first. I think this is the easiest way forward:

  • We wait for the tests on Self to pass and merge it
  • I fix the conflict here and wait for tests to pass again
  • Then we merge this one
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gvanrossum
gvanrossum reviewed Feb 6, 2022
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Sorry, I've got more...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py
Comment on lines +1984 to +1994
def int_or_str(arg: int | str) -> None:
match arg:
case int():
print("It's an int")
case str():
print("It's a str")
case _:
assert_never(arg)

If a type checker finds that a call to assert_never() is
reachable, it will emit an error.

@gvanrossum gvanrossum Feb 6, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This example is much better than the examples in the main doc. :-) And so is the sentence following the example.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JelleZijlstra JelleZijlstra Feb 7, 2022

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That sentence is also in the docs for assert_never, but not Never. I'm pushing some changes to improve the Never docs according to your feedback.

Honestly I'm a bit confused about the relationship between the docstring and the RST docs. I end up copying from one to the other.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gvanrossum gvanrossum Feb 8, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Usually the docstring is shorter, since it is often displayed by tools that have limited output space (it's really annoying to get a scroll bar in a tooltip in VS Code :-).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
JelleZijlstra added 2 commits February 6, 2022 16:37
@JelleZijlstra
Guido's feedback
b3f4ccb
@JelleZijlstra
Remove another "Notation for"
2530bd7
@JelleZijlstra

JelleZijlstra commented Feb 7, 2022

Copy link
Copy Markdown
Member Author

Thanks for your feedback! I pushed a round of docs changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AlexWaygood
AlexWaygood reviewed Feb 7, 2022
View reviewed changes
Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
Thanks Alex
c23cc26
AlexWaygood
AlexWaygood reviewed Feb 7, 2022
View reviewed changes
Comment thread Doc/library/typing.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra added 3 commits February 7, 2022 19:35
@JelleZijlstra
remove extra example
4497a26
@JelleZijlstra
Merge branch 'main' into never
c731977
@JelleZijlstra
raise AssertionError
1f6b671
@JelleZijlstra
JelleZijlstra requested a review from gvanrossum February 8, 2022 05:18
AlexWaygood
AlexWaygood approved these changes Feb 8, 2022
View reviewed changes

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM — thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting core review and removed awaiting review labels Feb 8, 2022
AlexWaygood
AlexWaygood reviewed Feb 8, 2022
View reviewed changes
Comment thread Lib/typing.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@antonagestam antonagestam mentioned this pull request Feb 8, 2022
Exhaustiveness checking util python/typing#735
Closed
gvanrossum
gvanrossum approved these changes Feb 8, 2022
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Great! Thanks for being patient with me.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Feb 8, 2022
@gvanrossum
gvanrossum merged commit 243436f into python:main Feb 8, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Feb 8, 2022
@JelleZijlstra
JelleZijlstra deleted the never branch February 8, 2022 18:50
@JelleZijlstra

JelleZijlstra commented Feb 8, 2022

Copy link
Copy Markdown
Member Author

Thank you for the feedback!

AlexWaygood reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra added a commit to JelleZijlstra/typing that referenced this pull request Feb 9, 2022
@JelleZijlstra
Add Never and assert_never
2faa2a8
Backport of python/cpython#30842, with additional tests from @sobolevn's python/cpython#31222.
This was referenced Feb 9, 2022
Add Never and assert_never python/typing#1060
Merged
add new typing features python/typeshed#7169
Merged
Add support for Never python/mypy#12153
Merged
JelleZijlstra added a commit to python/typing that referenced this pull request Feb 11, 2022
@JelleZijlstra
Add Never and assert_never (#1060)
a53957c
Backport of python/cpython#30842, with additional tests from @sobolevn's python/cpython#31222.
@henryiii henryiii mentioned this pull request Feb 14, 2022
refactor: identifiers in a file pypa/cibuildwheel#511
Merged
@johnthagen johnthagen mentioned this pull request Apr 18, 2022
Exhaustiveness Research johnthagen/sealed-typing-pep#4
Closed
@JelleZijlstra JelleZijlstra mentioned this pull request Apr 19, 2022
typing.Never and typing.assert_never #90633
Closed
JelleZijlstra added a commit to python/typing_extensions that referenced this pull request May 19, 2022
@JelleZijlstra
Add Never and assert_never (#1060)
5054b4b
Backport of python/cpython#30842, with additional tests from @sobolevn's python/cpython#31222.
JelleZijlstra added a commit to python/typing_extensions that referenced this pull request May 19, 2022
@JelleZijlstra
Add Never and assert_never (#1060)
039b433
Backport of python/cpython#30842, with additional tests from @sobolevn's python/cpython#31222.
JelleZijlstra added a commit to python/typing_extensions that referenced this pull request May 19, 2022
@JelleZijlstra
Add Never and assert_never (#1060)
ba258bb
Backport of python/cpython#30842, with additional tests from @sobolevn's python/cpython#31222.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gvanrossum gvanrossum gvanrossum approved these changes
@sobolevn sobolevn sobolevn left review comments
@Fidget-Spinner Fidget-Spinner Fidget-Spinner left review comments
@AlexWaygood AlexWaygood AlexWaygood approved these changes
+3 more reviewers
@davidfstr davidfstr davidfstr left review comments
@henryiii henryiii henryiii left review comments
@erictraut erictraut erictraut left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@JelleZijlstra @gvanrossum @davidfstr @henryiii @sobolevn @erictraut @Fidget-Spinner @AlexWaygood @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.