gh-116126: Implement PEP 696#116129
Conversation
|
This should be ready for review now, I'll take it out of draft once the tests pass. Notes:
|
|
Will review this weekend |
|
@pablogsal have you had a chance to look at this? The grammar changes should be quite straightforward, so hopefully it's not complicated to review. I'll spend some time today trying to make it so the field is called "default" not "default_" in Python, because having "default_" in the Python-visible APIs would be ugly. |
Co-authored-by: Alex Waygood <[email protected]>
AlexWaygood
left a comment
There was a problem hiding this comment.
I would say "is not the typing.NoDefault singleton" rather than "is not equal to typing.NoDefault", since we usually argue that an identity check is more idiomatic for singleton objects such as None, NotImplemented and Ellipsis
| >>> T.__default__ is typing.NoDefault | ||
| True | ||
| >>> S = TypeVar("S", default=None) | ||
| >>> S.__default__ is None | ||
| True |
There was a problem hiding this comment.
| >>> T.__default__ is typing.NoDefault | |
| True | |
| >>> S = TypeVar("S", default=None) | |
| >>> S.__default__ is None | |
| True | |
| >>> T.has_default() | |
| False | |
| >>> T.__default__ is typing.NoDefault | |
| True | |
| >>> S = TypeVar("S", default=None) | |
| >>> S.has_default() | |
| True | |
| >>> S.__default__ is None | |
| True |
There was a problem hiding this comment.
I thought of that but it felt out of place in the docs for NoDefault, since the cases you added don't use NoDefault at all.
There was a problem hiding this comment.
Fair enough -- I thought it was quite nice to see together in one example how the two concepts interrelate, but I definitely don't feel strongly!
Co-authored-by: Alex Waygood <[email protected]>
|
@ericsnowcurrently the C globals check is failing because this PR now adds a new static type and global singleton, |
|
For now let's just whitelist the new singleton, as long as it is stateless and immortal. We can circle back later if the whitelist is a problem. |
|
🤖 New build scheduled with the buildbot fleet by @JelleZijlstra for commit 5f6fdfd 🤖 If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
The previous logic would add the size of the pointer target to the pointer value, which might point to another pointer being used as a scope key. Now, we increment the value as an integer instead, which means it can never be a valid pointer.
Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Shantanu <[email protected]>
This implements both the grammar and compiler changes and changes to
typing.pybehavior (the latter copied from typing-extensions).