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:
With the old implementation in typing_extensions:
If you passed default=None when constructing a TypeVar, the __default__ attribute would be set to types.NoneType
If you did not pass a value to the default= parameter, the __default__ attribute would be set to None
With the new implementation in CPython:
If you pass default=None when constructing a TypeVar, the __default__ attribute is set to None
If you do not pass a value to the default= parameter, the __default__ attribute is set to the new sentinel object typing.NoDefault.
The new implementation at CPython also has added a new has_default() method to TypeVars, ParamSpecs and TypeVarTuples
I backported these changes to the typing_extensions implementation of PEP 696 yesterday, and we realised today that it breaks some tests over at cattrs: https://github.com/python/typing_extensions/issues/381. This PR fixes the tests so that they work if you're using a released version of typing_extensions, but they also work with the CPython implementation of PEP 696 and with the typing_extensions main branch.
I tested the PR locally by making this change to pyproject.toml:
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: https://github.com/python/typing_extensions/issues/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)!