Skip to content

Add support for PEP 661 (sentinels)#21454

Open
JelleZijlstra wants to merge 3 commits intopython:masterfrom
JelleZijlstra:sentinels
Open

Add support for PEP 661 (sentinels)#21454
JelleZijlstra wants to merge 3 commits intopython:masterfrom
JelleZijlstra:sentinels

Conversation

@JelleZijlstra
Copy link
Copy Markdown
Member

See PEP 661 and python/typing#2277

@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Copy Markdown
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Great stuff! 👍

def func(x: int | MISSING | SPECIAL) -> None:
# We could reasonably do narrowing here, but currently we're pretty conservative
# about narrowing on ==.
if x == MISSING:
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.

Question: should we add a test case about narrowing types on isinstance(..., Sentinel)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants