8000 Add support for PEP 661 sentinels · Issue #591 · python/typing_extensions · GitHub
[go: up one dir, main page]

Skip to content

Add support for PEP 661 sentinels #591

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

Closed
JelleZijlstra opened this issue May 5, 2025 · 5 comments · Fixed by #594
Closed

Add support for PEP 661 sentinels #591

JelleZijlstra opened this issue May 5, 2025 · 5 comments · Fixed by #594

Comments

@JelleZijlstra
Copy link
Member

We should add a PEP 661-style Sentinel class; see https://discuss.python.org/t/pep-661-sentinel-values/9126/243

cc @Viicos @taleinat.

(For clarity: I won't work on this myself but I'll review a PR.)

@Viicos
Copy link
Contributor
Viicos commented May 5, 2025

@taleinat I can look at it this week (or when it will be decided whether the module registry is kept) and port your draft implementation linked in the PEP there.

@taleinat
Copy link
taleinat commented May 8, 2025

The PEP has been deferred to Python 3.15, so I don't think that should be added yet.

@Viicos
Copy link
Contributor
Viicos commented May 8, 2025

Yes, but as with typing PEPs, we don't necessarily have to wait for 3.15 to be released (assuming the PEP would be accepted) to have it included in typing-extensions.

To give more context, having it added here early (even if the PEP is still in draft) can allow users/libraries (such as in Pydantic) to experiment with it, and potentially catch issues or provide valuable feedback. Of course, this won't be added in Pydantic as a stable feature until the PEP gets accepted.

@AlexWaygood
Copy link
Member

Yes, we usually add experimental versions of not-yet-accepted typing features well in advance of their PEPs being accepted

@taleinat
Copy link
taleinat commented May 8, 2025

I wasn't aware of that, cool! In that case, feel free to go ahead.

I'll mention that it seems likely that the internal registry of sentinels will be removed, to be replaced by attribute lookup on the relevant module (perhaps with a mechanism to avoid threading race conditions). In this case, sentinels may be required to be set as module-level attributes.

And in any case, the name of a sentinel will be required to exactly match the name of the variable it is assigned to; a mismatch should be considered an error. (This is similar to namedtuple, I believe, though the requirement in this case should be considered even more strict, since it could affect the singleton identity of the sentinel object.)

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 a pull request may close this issue.

4 participants
0