Skip to content

Commit 54f6384

Browse files
committed
Upgrade typing_extensions to 4.5.0
1 parent ffac4e4 commit 54f6384

File tree

3 files changed

+113
-9
lines changed

3 files changed

+113
-9
lines changed

news/typing_extensions.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade typing_extensions to 4.5.0

src/pip/_vendor/typing_extensions.py

Lines changed: 111 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
import collections
33
import collections.abc
44
import functools
5+
import inspect
56
import operator
67
import sys
78
import types as _types
89
import typing
10+
import warnings
911

1012

1113
__all__ = [
@@ -51,6 +53,7 @@
5153
'assert_type',
5254
'clear_overloads',
5355
'dataclass_transform',
56+
'deprecated',
5457
'get_overloads',
5558
'final',
5659
'get_args',
@@ -728,6 +731,8 @@ def _typeddict_new(*args, total=True, **kwargs):
728731
_typeddict_new.__text_signature__ = ('($cls, _typename, _fields=None,'
729732
' /, *, total=True, **kwargs)')
730733

734+
_TAKES_MODULE = "module" in inspect.signature(typing._type_check).parameters
735+
731736
class _TypedDictMeta(type):
732737
def __init__(cls, name, bases, ns, total=True):
733738
super().__init__(name, bases, ns)
@@ -753,8 +758,10 @@ def __new__(cls, name, bases, ns, total=True):
753758
annotations = {}
754759
own_annotations = ns.get('__annotations__', {})
755760
msg = "TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a type"
761+
kwds = {"module": tp_dict.__module__} if _TAKES_MODULE else {}
756762
own_annotations = {
757-
n: typing._type_check(tp, msg) for n, tp in own_annotations.items()
763+
n: typing._type_check(tp, msg, **kwds)
764+
for n, tp in own_annotations.items()
758765
}
759766
required_keys = set()
760767
optional_keys = set()
@@ -1157,7 +1164,7 @@ def __init__(self, default):
11571164
if isinstance(default, (tuple, list)):
11581165
self.__default__ = tuple((typing._type_check(d, "Default must be a type")
11591166
for d in default))
1160-
elif default:
1167+
elif default != _marker:
11611168
self.__default__ = typing._type_check(default, "Default must be a type")
11621169
else:
11631170
self.__default__ = None
@@ -1171,7 +1178,7 @@ class TypeVar(typing.TypeVar, _DefaultMixin, _root=True):
11711178

11721179
def __init__(self, name, *constraints, bound=None,
11731180
covariant=False, contravariant=False,
1174-
default=None, infer_variance=False):
1181+
default=_marker, infer_variance=False):
11751182
super().__init__(name, *constraints, bound=bound, covariant=covariant,
11761183
contravariant=contravariant)
11771184
_DefaultMixin.__init__(self, default)
@@ -1258,7 +1265,7 @@ class ParamSpec(typing.ParamSpec, _DefaultMixin, _root=True):
12581265
__module__ = 'typing'
12591266

12601267
def __init__(self, name, *, bound=None, covariant=False, contravariant=False,
1261-
default=None):
1268+
default=_marker):
12621269
super().__init__(name, bound=bound, covariant=covariant,
12631270
contravariant=contravariant)
12641271
_DefaultMixin.__init__(self, default)
@@ -1334,7 +1341,7 @@ def kwargs(self):
13341341
return ParamSpecKwargs(self)
13351342

13361343
def __init__(self, name, *, bound=None, covariant=False, contravariant=False,
1337-
default=None):
1344+
default=_marker):
13381345
super().__init__([self])
13391346
self.__name__ = name
13401347
self.__covariant__ = bool(covariant)
@@ -1850,7 +1857,7 @@ def _is_unpack(obj):
18501857
class TypeVarTuple(typing.TypeVarTuple, _DefaultMixin, _root=True):
18511858
"""Type variable tuple."""
18521859

1853-
def __init__(self, name, *, default=None):
1860+
def __init__(self, name, *, default=_marker):
18541861
super().__init__(name)
18551862
_DefaultMixin.__init__(self, default)
18561863

@@ -1913,7 +1920,7 @@ def get_shape(self) -> Tuple[*Ts]:
19131920
def __iter__(self):
19141921
yield self.__unpacked__
19151922

1916-
def __init__(self, name, *, default=None):
1923+
def __init__(self, name, *, default=_marker):
19171924
self.__name__ = name
19181925
_DefaultMixin.__init__(self, default)
19191926

@@ -1993,14 +2000,16 @@ def int_or_str(arg: int | str) -> None:
19932000
raise AssertionError("Expected code to be unreachable")
19942001

19952002

1996-
if hasattr(typing, 'dataclass_transform'):
2003+
if sys.version_info >= (3, 12):
2004+
# dataclass_transform exists in 3.11 but lacks the frozen_default parameter
19972005
dataclass_transform = typing.dataclass_transform
19982006
else:
19992007
def dataclass_transform(
20002008
*,
20012009
eq_default: bool = True,
20022010
order_default: bool = False,
20032011
kw_only_default: bool = False,
2012+
frozen_default: bool = False,
20042013
field_specifiers: typing.Tuple[
20052014
typing.Union[typing.Type[typing.Any], typing.Callable[..., typing.Any]],
20062015
...
@@ -2057,6 +2066,8 @@ class CustomerModel(ModelBase):
20572066
assumed to be True or False if it is omitted by the caller.
20582067
- ``kw_only_default`` indicates whether the ``kw_only`` parameter is
20592068
assumed to be True or False if it is omitted by the caller.
2069+
- ``frozen_default`` indicates whether the ``frozen`` parameter is
2070+
assumed to be True or False if it is omitted by the caller.
20602071
- ``field_specifiers`` specifies a static list of supported classes
20612072
or functions that describe fields, similar to ``dataclasses.field()``.
20622073
@@ -2071,6 +2082,7 @@ def decorator(cls_or_fn):
20712082
"eq_default": eq_default,
20722083
"order_default": order_default,
20732084
"kw_only_default": kw_only_default,
2085+
"frozen_default": frozen_default,
20742086
"field_specifiers": field_specifiers,
20752087
"kwargs": kwargs,
20762088
}
@@ -2102,12 +2114,103 @@ def method(self) -> None:
21022114
This helps prevent bugs that may occur when a base class is changed
21032115
without an equivalent change to a child class.
21042116
2117+
There is no runtime checking of these properties. The decorator
2118+
sets the ``__override__`` attribute to ``True`` on the decorated object
2119+
to allow runtime introspection.
2120+
21052121
See PEP 698 for details.
21062122
21072123
"""
2124+
try:
2125+
__arg.__override__ = True
2126+
except (AttributeError, TypeError):
2127+
# Skip the attribute silently if it is not writable.
2128+
# AttributeError happens if the object has __slots__ or a
2129+
# read-only property, TypeError if it's a builtin class.
2130+
pass
21082131
return __arg
21092132

21102133

2134+
if hasattr(typing, "deprecated"):
2135+
deprecated = typing.deprecated
2136+
else:
2137+
_T = typing.TypeVar("_T")
2138+
2139+
def deprecated(
2140+
__msg: str,
2141+
*,
2142+
category: typing.Optional[typing.Type[Warning]] = DeprecationWarning,
2143+
stacklevel: int = 1,
2144+
) -> typing.Callable[[_T], _T]:
2145+
"""Indicate that a class, function or overload is deprecated.
2146+
2147+
Usage:
2148+
2149+
@deprecated("Use B instead")
2150+
class A:
2151+
pass
2152+
2153+
@deprecated("Use g instead")
2154+
def f():
2155+
pass
2156+
2157+
@overload
2158+
@deprecated("int support is deprecated")
2159+
def g(x: int) -> int: ...
2160+
@overload
2161+
def g(x: str) -> int: ...
2162+
2163+
When this decorator is applied to an object, the type checker
2164+
will generate a diagnostic on usage of the deprecated object.
2165+
2166+
No runtime warning is issued. The decorator sets the ``__deprecated__``
2167+
attribute on the decorated object to the deprecation message
2168+
passed to the decorator. If applied to an overload, the decorator
2169+
must be after the ``@overload`` decorator for the attribute to
2170+
exist on the overload as returned by ``get_overloads()``.
2171+
2172+
See PEP 702 for details.
2173+
2174+
"""
2175+
def decorator(__arg: _T) -> _T:
2176+
if category is None:
2177+
__arg.__deprecated__ = __msg
2178+
return __arg
2179+
elif isinstance(__arg, type):
2180+
original_new = __arg.__new__
2181+
has_init = __arg.__init__ is not object.__init__
2182+
2183+
@functools.wraps(original_new)
2184+
def __new__(cls, *args, **kwargs):
2185+
warnings.warn(__msg, category=category, stacklevel=stacklevel + 1)
2186+
# Mirrors a similar check in object.__new__.
2187+
if not has_init and (args or kwargs):
2188+
raise TypeError(f"{cls.__name__}() takes no arguments")
2189+
if original_new is not object.__new__:
2190+
return original_new(cls, *args, **kwargs)
2191+
else:
2192+
return original_new(cls)
2193+
2194+
__arg.__new__ = staticmethod(__new__)
2195+
__arg.__deprecated__ = __new__.__deprecated__ = __msg
2196+
return __arg
2197+
elif callable(__arg):
2198+
@functools.wraps(__arg)
2199+
def wrapper(*args, **kwargs):
2200+
warnings.warn(__msg, category=category, stacklevel=stacklevel + 1)
2201+
return __arg(*args, **kwargs)
2202+
2203+
__arg.__deprecated__ = wrapper.__deprecated__ = __msg
2204+
return wrapper
2205+
else:
2206+
raise TypeError(
2207+
"@deprecated decorator with non-None category must be applied to "
2208+
f"a class or callable, not {__arg!r}"
2209+
)
2210+
2211+
return decorator
2212+
2213+
21112214
# We have to do some monkey patching to deal with the dual nature of
21122215
# Unpack/TypeVarTuple:
21132216
# - We want Unpack to be a kind of TypeVar so it gets accepted in

src/pip/_vendor/vendor.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ requests==2.28.2
1414
urllib3==1.26.15
1515
rich==13.3.3
1616
pygments==2.13.0
17-
typing_extensions==4.4.0
17+
typing_extensions==4.5.0
1818
resolvelib==1.0.1
1919
setuptools==65.6.3
2020
six==1.16.0

0 commit comments

Comments
 (0)