@@ -1614,7 +1614,7 @@ without the dedicated syntax, as documented below.
16141614
16151615.. _typevar :
16161616
1617- .. class :: TypeVar(name, *constraints, bound=None, covariant=False, contravariant=False, infer_variance=False)
1617+ .. class :: TypeVar(name, *constraints, bound=None, covariant=False, contravariant=False, infer_variance=False, default=typing.NoDefault )
16181618
16191619 Type variable.
16201620
@@ -1752,15 +1752,35 @@ without the dedicated syntax, as documented below.
17521752 the constraints are evaluated only when the attribute is accessed, not when
17531753 the type variable is created (see :ref: `lazy-evaluation `).
17541754
1755+ .. attribute :: __default__
1756+
1757+ The default value of the type variable, or :data: `typing.NoDefault ` if it
1758+ has no default.
1759+
1760+ .. versionadded :: 3.13
1761+
1762+ .. method :: has_default()
1763+
1764+ Return whether or not the type variable has a default value. This is equivalent
1765+ to checking whether :attr: `__default__ ` is not the :data: `typing.NoDefault `
1766+ singleton, except that it does not force evaluation of the
1767+ :ref: `lazily evaluated <lazy-evaluation >` default value.
1768+
1769+ .. versionadded :: 3.13
1770+
17551771 .. versionchanged :: 3.12
17561772
17571773 Type variables can now be declared using the
17581774 :ref: `type parameter <type-params >` syntax introduced by :pep: `695 `.
17591775 The ``infer_variance `` parameter was added.
17601776
1777+ .. versionchanged :: 3.13
1778+
1779+ Support for default values was added.
1780+
17611781.. _typevartuple :
17621782
1763- .. class :: TypeVarTuple(name)
1783+ .. class :: TypeVarTuple(name, default=typing.NoDefault )
17641784
17651785 Type variable tuple. A specialized form of :ref: `type variable <typevar >`
17661786 that enables *variadic * generics.
@@ -1870,14 +1890,34 @@ without the dedicated syntax, as documented below.
18701890
18711891 The name of the type variable tuple.
18721892
1893+ .. attribute :: __default__
1894+
1895+ The default value of the type variable tuple, or :data: `typing.NoDefault ` if it
1896+ has no default.
1897+
1898+ .. versionadded :: 3.13
1899+
1900+ .. method :: has_default()
1901+
1902+ Return whether or not the type variable tuple has a default value. This is equivalent
1903+ to checking whether :attr: `__default__ ` is not the :data: `typing.NoDefault `
1904+ singleton, except that it does not force evaluation of the
1905+ :ref: `lazily evaluated <lazy-evaluation >` default value.
1906+
1907+ .. versionadded :: 3.13
1908+
18731909 .. versionadded :: 3.11
18741910
18751911 .. versionchanged :: 3.12
18761912
18771913 Type variable tuples can now be declared using the
18781914 :ref: `type parameter <type-params >` syntax introduced by :pep: `695 `.
18791915
1880- .. class :: ParamSpec(name, *, bound=None, covariant=False, contravariant=False)
1916+ .. versionchanged :: 3.13
1917+
1918+ Support for default values was added.
1919+
1920+ .. class :: ParamSpec(name, *, bound=None, covariant=False, contravariant=False, default=typing.NoDefault)
18811921
18821922 Parameter specification variable. A specialized version of
18831923 :ref: `type variables <typevar >`.
@@ -1946,6 +1986,22 @@ without the dedicated syntax, as documented below.
19461986
19471987 The name of the parameter specification.
19481988
1989+ .. attribute :: __default__
1990+
1991+ The default value of the parameter specification, or :data: `typing.NoDefault ` if it
1992+ has no default.
1993+
1994+ .. versionadded :: 3.13
1995+
1996+ .. method :: has_default()
1997+
1998+ Return whether or not the parameter specification has a default value. This is equivalent
1999+ to checking whether :attr: `__default__ ` is not the :data: `typing.NoDefault `
2000+ singleton, except that it does not force evaluation of the
2001+ :ref: `lazily evaluated <lazy-evaluation >` default value.
2002+
2003+ .. versionadded :: 3.13
2004+
19492005 Parameter specification variables created with ``covariant=True `` or
19502006 ``contravariant=True `` can be used to declare covariant or contravariant
19512007 generic types. The ``bound `` argument is also accepted, similar to
@@ -1959,6 +2015,10 @@ without the dedicated syntax, as documented below.
19592015 Parameter specifications can now be declared using the
19602016 :ref: `type parameter <type-params >` syntax introduced by :pep: `695 `.
19612017
2018+ .. versionchanged :: 3.13
2019+
2020+ Support for default values was added.
2021+
19622022 .. note ::
19632023 Only parameter specification variables defined in global scope can
19642024 be pickled.
@@ -3171,6 +3231,22 @@ Introspection helpers
31713231
31723232 .. versionadded :: 3.7.4
31733233
3234+ .. data :: NoDefault
3235+
3236+ A sentinel object used to indicate that a type parameter has no default
3237+ value. For example:
3238+
3239+ .. doctest ::
3240+
3241+ >>> T = TypeVar(" T" )
3242+ >>> T.__default__ is typing.NoDefault
3243+ True
3244+ >>> S = TypeVar(" S" , default = None )
3245+ >>> S.__default__ is None
3246+ True
3247+
3248+ .. versionadded :: 3.13
3249+
31743250Constant
31753251--------
31763252
0 commit comments