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
Make detection of TypeVar defaults robust to the CPython PEP-696 implementation #9426
Conversation
CodSpeed Performance ReportMerging #9426 will not alter performanceComparing Summary
|
I tested this locally by making this change to --- a/pyproject.toml
+++ b/pyproject.toml
@@ -46,7 +46,7 @@ classifiers = [
]
requires-python = '>=3.8'
dependencies = [
- 'typing-extensions>=4.6.1',
+ 'typing-extensions @ git+https://github.com/python/typing_extensions.git',
'annotated-types>=0.4.0',
"pydantic-core==2.18.2",
] And then rerunning |
please review |
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 looks correct to me. The try
branch would be taken on Python 3.13+ and future versions of typing-extensions.
This PR should fix the "test typing-extensions main" job in pydantic's CI, which is currently failing on your |
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.
Thanks so much for this fix! @JelleZijlstra, thanks a bunch for the review!
Before we merge, could you please add some tests for the behavioral changes you've listed above? Thanks again! |
Sure -- what kind of tests are you looking for? This fixes the failing CI job on |
That sounds great re the additional CI job. Thank you! |
Oh, but it looks like you already have a CI job for testing with your oldest supported version of pydantic/.github/workflows/ci.yml Lines 319 to 327 in 7061f36
So I'm not sure what I could add here @sydney-runkle. It seems like these code paths already have good test coverage (if they didn't, your CI job for testing with the |
Great point. I'm happy to merge this then. Thanks for the awesome work here! |
Brilliant -- thanks @sydney-runkle! :D |
Change Summary
When implementing PEP 696 (default values for TypeVars, ParamSpecs and TypeVarTuples, we decided to implement the PEP slightly differently from the prototype that existed in
typing_extensions
. Specifically:typing_extensions
:default=None
when constructing a TypeVar, the__default__
attribute would be set totypes.NoneType
default=
parameter, the__default__
attribute would be set toNone
default=None
when constructing a TypeVar, the__default__
attribute is set toNone
default=
parameter, the__default__
attribute is set to the new sentinel objecttyping.NoDefault
.has_default()
method to TypeVars, ParamSpecs and TypeVarTuplesI backported these changes to the
typing_extensions
implementation of PEP 696 yesterday, and we realised today that it breaks some tests over at pydantic: python/typing_extensions#381. This PR fixes the tests so that they work if you're using a released version oftyping_extensions
, but they also work with the CPython implementation of PEP 696 and with thetyping_extensions
main branch.Checklist
Selected Reviewer: @sydney-runkle