-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Comments
@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. |
The PEP has been deferred to Python 3.15, so I don't think that should be added yet. |
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. |
Yes, we usually add experimental versions of not-yet-accepted typing features well in advance of their PEPs being accepted |
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.) |
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.)
The text was updated successfully, but these errors were encountered: