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 |
JelleZijlstra
left a comment
There was a problem hiding this comment.
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 |
sydney-runkle
left a comment
There was a problem hiding this comment.
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=Nonewhen constructing a TypeVar, the__default__attribute would be set totypes.NoneTypedefault=parameter, the__default__attribute would be set toNonedefault=Nonewhen constructing a TypeVar, the__default__attribute is set toNonedefault=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_extensionsimplementation 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_extensionsmain branch.Checklist
Selected Reviewer: @sydney-runkle