@@ -1614,7 +1614,7 @@ without the dedicated syntax, as documented below.
1614
1614
1615
1615
.. _typevar :
1616
1616
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 )
1618
1618
1619
1619
Type variable.
1620
1620
@@ -1752,15 +1752,35 @@ without the dedicated syntax, as documented below.
1752
1752
the constraints are evaluated only when the attribute is accessed, not when
1753
1753
the type variable is created (see :ref: `lazy-evaluation `).
1754
1754
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
+
1755
1771
.. versionchanged :: 3.12
1756
1772
1757
1773
Type variables can now be declared using the
1758
1774
:ref: `type parameter <type-params >` syntax introduced by :pep: `695 `.
1759
1775
The ``infer_variance `` parameter was added.
1760
1776
1777
+ .. versionchanged :: 3.13
1778
+
1779
+ Support for default values was added.
1780
+
1761
1781
.. _typevartuple :
1762
1782
1763
- .. class :: TypeVarTuple(name)
1783
+ .. class :: TypeVarTuple(name, default=typing.NoDefault )
1764
1784
1765
1785
Type variable tuple. A specialized form of :ref: `type variable <typevar >`
1766
1786
that enables *variadic * generics.
@@ -1870,14 +1890,34 @@ without the dedicated syntax, as documented below.
1870
1890
1871
1891
The name of the type variable tuple.
1872
1892
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
+
1873
1909
.. versionadded :: 3.11
1874
1910
1875
1911
.. versionchanged :: 3.12
1876
1912
1877
1913
Type variable tuples can now be declared using the
1878
1914
:ref: `type parameter <type-params >` syntax introduced by :pep: `695 `.
1879
1915
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)
1881
1921
1882
1922
Parameter specification variable. A specialized version of
1883
1923
:ref: `type variables <typevar >`.
@@ -1946,6 +1986,22 @@ without the dedicated syntax, as documented below.
1946
1986
1947
1987
The name of the parameter specification.
1948
1988
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
+
1949
2005
Parameter specification variables created with ``covariant=True `` or
1950
2006
``contravariant=True `` can be used to declare covariant or contravariant
1951
2007
generic types. The ``bound `` argument is also accepted, similar to
@@ -1959,6 +2015,10 @@ without the dedicated syntax, as documented below.
1959
2015
Parameter specifications can now be declared using the
1960
2016
:ref: `type parameter <type-params >` syntax introduced by :pep: `695 `.
1961
2017
2018
+ .. versionchanged :: 3.13
2019
+
2020
+ Support for default values was added.
2021
+
1962
2022
.. note ::
1963
2023
Only parameter specification variables defined in global scope can
1964
2024
be pickled.
@@ -3171,6 +3231,22 @@ Introspection helpers
3171
3231
3172
3232
.. versionadded :: 3.7.4
3173
3233
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
+
3174
3250
Constant
3175
3251
--------
3176
3252
0 commit comments