Make detection of TypeVar defaults robust to the CPython PEP-696 implementation #536
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 cattrs: 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.I tested the PR locally by making this change to
pyproject.toml
:And then re-running
pdm install -d -G :all
andtox
. The tests all passed.I didn't add an entry to
HISTORY.md
, as it looks like cattrs's PEP-696 support is unreleased right now (so it's a bugfix for an unreleased feature)!