Skip to content

Commit 4ab07c7

Browse files
committed
Upgrade typing_extensions to 4.4.0
1 parent 99eab68 commit 4ab07c7

File tree

4 files changed

+160
-19
lines changed

4 files changed

+160
-19
lines changed

news/typing_extensions.vendor.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade typing_extensions to 4.4.0

src/pip/_vendor/typing_extensions.LICENSE

+10-10
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ software.
1313

1414
In May 2000, Guido and the Python core development team moved to
1515
BeOpen.com to form the BeOpen PythonLabs team. In October of the same
16-
year, the PythonLabs team moved to Digital Creations (now Zope
17-
Corporation, see http://www.zope.com). In 2001, the Python Software
18-
Foundation (PSF, see http://www.python.org/psf/) was formed, a
19-
non-profit organization created specifically to own Python-related
20-
Intellectual Property. Zope Corporation is a sponsoring member of
21-
the PSF.
16+
year, the PythonLabs team moved to Digital Creations, which became
17+
Zope Corporation. In 2001, the Python Software Foundation (PSF, see
18+
https://www.python.org/psf/) was formed, a non-profit organization
19+
created specifically to own Python-related Intellectual Property.
20+
Zope Corporation was a sponsoring member of the PSF.
2221

2322
All Python releases are Open Source (see http://www.opensource.org for
2423
the Open Source Definition). Historically, most, but not all, Python
@@ -74,8 +73,9 @@ analyze, test, perform and/or display publicly, prepare derivative works,
7473
distribute, and otherwise use Python alone or in any derivative version,
7574
provided, however, that PSF's License Agreement and PSF's notice of copyright,
7675
i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
77-
2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved" are
78-
retained in Python alone or in any derivative version prepared by Licensee.
76+
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Python Software Foundation;
77+
All Rights Reserved" are retained in Python alone or in any derivative version
78+
prepared by Licensee.
7979

8080
3. In the event Licensee prepares a derivative work that is based on
8181
or incorporates Python or any part thereof, and wants to make
@@ -180,9 +180,9 @@ version prepared by Licensee. Alternately, in lieu of CNRI's License
180180
Agreement, Licensee may substitute the following text (omitting the
181181
quotes): "Python 1.6.1 is made available subject to the terms and
182182
conditions in CNRI's License Agreement. This Agreement together with
183-
Python 1.6.1 may be located on the Internet using the following
183+
Python 1.6.1 may be located on the internet using the following
184184
unique, persistent identifier (known as a handle): 1895.22/1013. This
185-
Agreement may also be obtained from a proxy server on the Internet
185+
Agreement may also be obtained from a proxy server on the internet
186186
using the following URL: http://hdl.handle.net/1895.22/1013".
187187

188188
3. In the event Licensee prepares a derivative work that is based on

src/pip/_vendor/typing_extensions.py

+148-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import typing
99

1010

11-
# Please keep __all__ alphabetized within each category.
1211
__all__ = [
1312
# Super-special typing primitives.
13+
'Any',
1414
'ClassVar',
1515
'Concatenate',
1616
'Final',
@@ -20,6 +20,7 @@
2020
'ParamSpecKwargs',
2121
'Self',
2222
'Type',
23+
'TypeVar',
2324
'TypeVarTuple',
2425
'Unpack',
2526

@@ -60,6 +61,7 @@
6061
'Literal',
6162
'NewType',
6263
'overload',
64+
'override',
6365
'Protocol',
6466
'reveal_type',
6567
'runtime',
@@ -149,6 +151,37 @@ def _collect_type_vars(types, typevar_types=None):
149151
T_co = typing.TypeVar('T_co', covariant=True) # Any type covariant containers.
150152
T_contra = typing.TypeVar('T_contra', contravariant=True) # Ditto contravariant.
151153

154+
155+
if sys.version_info >= (3, 11):
156+
from typing import Any
157+
else:
158+
159+
class _AnyMeta(type):
160+
def __instancecheck__(self, obj):
161+
if self is Any:
162+
raise TypeError("typing_extensions.Any cannot be used with isinstance()")
163+
return super().__instancecheck__(obj)
164+
165+
def __repr__(self):
166+
if self is Any:
167+
return "typing_extensions.Any"
168+
return super().__repr__()
169+
170+
class Any(metaclass=_AnyMeta):
171+
"""Special type indicating an unconstrained type.
172+
- Any is compatible with every type.
173+
- Any assumed to have all methods.
174+
- All values assumed to be instances of Any.
175+
Note that all the above statements are true from the point of view of
176+
static type checkers. At runtime, Any should not be used with instance
177+
checks.
178+
"""
179+
def __new__(cls, *args, **kwargs):
180+
if cls is Any:
181+
raise TypeError("Any cannot be instantiated")
182+
return super().__new__(cls, *args, **kwargs)
183+
184+
152185
ClassVar = typing.ClassVar
153186

154187
# On older versions of typing there is an internal class named "Final".
@@ -431,7 +464,7 @@ def _no_init(self, *args, **kwargs):
431464
if type(self)._is_protocol:
432465
raise TypeError('Protocols cannot be instantiated')
433466

434-
class _ProtocolMeta(abc.ABCMeta):
467+
class _ProtocolMeta(abc.ABCMeta): # noqa: B024
435468
# This metaclass is a bit unfortunate and exists only because of the lack
436469
# of __instancehook__.
437470
def __instancecheck__(cls, instance):
@@ -1115,6 +1148,44 @@ def __repr__(self):
11151148
above.""")
11161149

11171150

1151+
class _DefaultMixin:
1152+
"""Mixin for TypeVarLike defaults."""
1153+
1154+
__slots__ = ()
1155+
1156+
def __init__(self, default):
1157+
if isinstance(default, (tuple, list)):
1158+
self.__default__ = tuple((typing._type_check(d, "Default must be a type")
1159+
for d in default))
1160+
elif default:
1161+
self.__default__ = typing._type_check(default, "Default must be a type")
1162+
else:
1163+
self.__default__ = None
1164+
1165+
1166+
# Add default and infer_variance parameters from PEP 696 and 695
1167+
class TypeVar(typing.TypeVar, _DefaultMixin, _root=True):
1168+
"""Type variable."""
1169+
1170+
__module__ = 'typing'
1171+
1172+
def __init__(self, name, *constraints, bound=None,
1173+
covariant=False, contravariant=False,
1174+
default=None, infer_variance=False):
1175+
super().__init__(name, *constraints, bound=bound, covariant=covariant,
1176+
contravariant=contravariant)
1177+
_DefaultMixin.__init__(self, default)
1178+
self.__infer_variance__ = infer_variance
1179+
1180+
# for pickling:
1181+
try:
1182+
def_mod = sys._getframe(1).f_globals.get('__name__', '__main__')
1183+
except (AttributeError, ValueError):
1184+
def_mod = None
1185+
if def_mod != 'typing_extensions':
1186+
self.__module__ = def_mod
1187+
1188+
11181189
# Python 3.10+ has PEP 612
11191190
if hasattr(typing, 'ParamSpecArgs'):
11201191
ParamSpecArgs = typing.ParamSpecArgs
@@ -1179,12 +1250,32 @@ def __eq__(self, other):
11791250

11801251
# 3.10+
11811252
if hasattr(typing, 'ParamSpec'):
1182-
ParamSpec = typing.ParamSpec
1253+
1254+
# Add default Parameter - PEP 696
1255+
class ParamSpec(typing.ParamSpec, _DefaultMixin, _root=True):
1256+
"""Parameter specification variable."""
1257+
1258+
__module__ = 'typing'
1259+
1260+
def __init__(self, name, *, bound=None, covariant=False, contravariant=False,
1261+
default=None):
1262+
super().__init__(name, bound=bound, covariant=covariant,
1263+
contravariant=contravariant)
1264+
_DefaultMixin.__init__(self, default)
1265+
1266+
# for pickling:
1267+
try:
1268+
def_mod = sys._getframe(1).f_globals.get('__name__', '__main__')
1269+
except (AttributeError, ValueError):
1270+
def_mod = None
1271+
if def_mod != 'typing_extensions':
1272+
self.__module__ = def_mod
1273+
11831274
# 3.7-3.9
11841275
else:
11851276

11861277
# Inherits from list as a workaround for Callable checks in Python < 3.9.2.
1187-
class ParamSpec(list):
1278+
class ParamSpec(list, _DefaultMixin):
11881279
"""Parameter specification variable.
11891280
11901281
Usage::
@@ -1242,7 +1333,8 @@ def args(self):
12421333
def kwargs(self):
12431334
return ParamSpecKwargs(self)
12441335

1245-
def __init__(self, name, *, bound=None, covariant=False, contravariant=False):
1336+
def __init__(self, name, *, bound=None, covariant=False, contravariant=False,
1337+
default=None):
12461338
super().__init__([self])
12471339
self.__name__ = name
12481340
self.__covariant__ = bool(covariant)
@@ -1251,6 +1343,7 @@ def __init__(self, name, *, bound=None, covariant=False, contravariant=False):
12511343
self.__bound__ = typing._type_check(bound, 'Bound must be a type.')
12521344
else:
12531345
self.__bound__ = None
1346+
_DefaultMixin.__init__(self, default)
12541347

12551348
# for pickling:
12561349
try:
@@ -1752,9 +1845,25 @@ def _is_unpack(obj):
17521845

17531846

17541847
if hasattr(typing, "TypeVarTuple"): # 3.11+
1755-
TypeVarTuple = typing.TypeVarTuple
1848+
1849+
# Add default Parameter - PEP 696
1850+
class TypeVarTuple(typing.TypeVarTuple, _DefaultMixin, _root=True):
1851+
"""Type variable tuple."""
1852+
1853+
def __init__(self, name, *, default=None):
1854+
super().__init__(name)
1855+
_DefaultMixin.__init__(self, default)
1856+
1857+
# for pickling:
1858+
try:
1859+
def_mod = sys._getframe(1).f_globals.get('__name__', '__main__')
1860+
except (AttributeError, ValueError):
1861+
def_mod = None
1862+
if def_mod != 'typing_extensions':
1863+
self.__module__ = def_mod
1864+
17561865
else:
1757-
class TypeVarTuple:
1866+
class TypeVarTuple(_DefaultMixin):
17581867
"""Type variable tuple.
17591868
17601869
Usage::
@@ -1804,8 +1913,9 @@ def get_shape(self) -> Tuple[*Ts]:
18041913
def __iter__(self):
18051914
yield self.__unpacked__
18061915

1807-
def __init__(self, name):
1916+
def __init__(self, name, *, default=None):
18081917
self.__name__ = name
1918+
_DefaultMixin.__init__(self, default)
18091919

18101920
# for pickling:
18111921
try:
@@ -1968,6 +2078,36 @@ def decorator(cls_or_fn):
19682078
return decorator
19692079

19702080

2081+
if hasattr(typing, "override"):
2082+
override = typing.override
2083+
else:
2084+
_F = typing.TypeVar("_F", bound=typing.Callable[..., typing.Any])
2085+
2086+
def override(__arg: _F) -> _F:
2087+
"""Indicate that a method is intended to override a method in a base class.
2088+
2089+
Usage:
2090+
2091+
class Base:
2092+
def method(self) -> None: ...
2093+
pass
2094+
2095+
class Child(Base):
2096+
@override
2097+
def method(self) -> None:
2098+
super().method()
2099+
2100+
When this decorator is applied to a method, the type checker will
2101+
validate that it overrides a method with the same name on a base class.
2102+
This helps prevent bugs that may occur when a base class is changed
2103+
without an equivalent change to a child class.
2104+
2105+
See PEP 698 for details.
2106+
2107+
"""
2108+
return __arg
2109+
2110+
19712111
# We have to do some monkey patching to deal with the dual nature of
19722112
# Unpack/TypeVarTuple:
19732113
# - We want Unpack to be a kind of TypeVar so it gets accepted in

src/pip/_vendor/vendor.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ requests==2.28.1
1414
urllib3==1.26.12
1515
rich==12.5.1
1616
pygments==2.13.0
17-
typing_extensions==4.3.0
17+
typing_extensions==4.4.0
1818
resolvelib==0.8.1
1919
setuptools==44.0.0
2020
six==1.16.0

0 commit comments

Comments
 (0)