Skip to content

Commit

Permalink
Upgrade typing_extensions to 4.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg committed Oct 10, 2022
1 parent 99eab68 commit 4ab07c7
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 19 deletions.
1 change: 1 addition & 0 deletions news/typing_extensions.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade typing_extensions to 4.4.0
20 changes: 10 additions & 10 deletions src/pip/_vendor/typing_extensions.LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ software.

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

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

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

3. In the event Licensee prepares a derivative work that is based on
Expand Down
156 changes: 148 additions & 8 deletions src/pip/_vendor/typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import typing


# Please keep __all__ alphabetized within each category.
__all__ = [
# Super-special typing primitives.
'Any',
'ClassVar',
'Concatenate',
'Final',
Expand All @@ -20,6 +20,7 @@
'ParamSpecKwargs',
'Self',
'Type',
'TypeVar',
'TypeVarTuple',
'Unpack',

Expand Down Expand Up @@ -60,6 +61,7 @@
'Literal',
'NewType',
'overload',
'override',
'Protocol',
'reveal_type',
'runtime',
Expand Down Expand Up @@ -149,6 +151,37 @@ def _collect_type_vars(types, typevar_types=None):
T_co = typing.TypeVar('T_co', covariant=True) # Any type covariant containers.
T_contra = typing.TypeVar('T_contra', contravariant=True) # Ditto contravariant.


if sys.version_info >= (3, 11):
from typing import Any
else:

class _AnyMeta(type):
def __instancecheck__(self, obj):
if self is Any:
raise TypeError("typing_extensions.Any cannot be used with isinstance()")
return super().__instancecheck__(obj)

def __repr__(self):
if self is Any:
return "typing_extensions.Any"
return super().__repr__()

class Any(metaclass=_AnyMeta):
"""Special type indicating an unconstrained type.
- Any is compatible with every type.
- Any assumed to have all methods.
- All values assumed to be instances of Any.
Note that all the above statements are true from the point of view of
static type checkers. At runtime, Any should not be used with instance
checks.
"""
def __new__(cls, *args, **kwargs):
if cls is Any:
raise TypeError("Any cannot be instantiated")
return super().__new__(cls, *args, **kwargs)


ClassVar = typing.ClassVar

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

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


class _DefaultMixin:
"""Mixin for TypeVarLike defaults."""

__slots__ = ()

def __init__(self, default):
if isinstance(default, (tuple, list)):
self.__default__ = tuple((typing._type_check(d, "Default must be a type")
for d in default))
elif default:
self.__default__ = typing._type_check(default, "Default must be a type")
else:
self.__default__ = None


# Add default and infer_variance parameters from PEP 696 and 695
class TypeVar(typing.TypeVar, _DefaultMixin, _root=True):
"""Type variable."""

__module__ = 'typing'

def __init__(self, name, *constraints, bound=None,
covariant=False, contravariant=False,
default=None, infer_variance=False):
super().__init__(name, *constraints, bound=bound, covariant=covariant,
contravariant=contravariant)
_DefaultMixin.__init__(self, default)
self.__infer_variance__ = infer_variance

# for pickling:
try:
def_mod = sys._getframe(1).f_globals.get('__name__', '__main__')
except (AttributeError, ValueError):
def_mod = None
if def_mod != 'typing_extensions':
self.__module__ = def_mod


# Python 3.10+ has PEP 612
if hasattr(typing, 'ParamSpecArgs'):
ParamSpecArgs = typing.ParamSpecArgs
Expand Down Expand Up @@ -1179,12 +1250,32 @@ def __eq__(self, other):

# 3.10+
if hasattr(typing, 'ParamSpec'):
ParamSpec = typing.ParamSpec

# Add default Parameter - PEP 696
class ParamSpec(typing.ParamSpec, _DefaultMixin, _root=True):
"""Parameter specification variable."""

__module__ = 'typing'

def __init__(self, name, *, bound=None, covariant=False, contravariant=False,
default=None):
super().__init__(name, bound=bound, covariant=covariant,
contravariant=contravariant)
_DefaultMixin.__init__(self, default)

# for pickling:
try:
def_mod = sys._getframe(1).f_globals.get('__name__', '__main__')
except (AttributeError, ValueError):
def_mod = None
if def_mod != 'typing_extensions':
self.__module__ = def_mod

# 3.7-3.9
else:

# Inherits from list as a workaround for Callable checks in Python < 3.9.2.
class ParamSpec(list):
class ParamSpec(list, _DefaultMixin):
"""Parameter specification variable.
Usage::
Expand Down Expand Up @@ -1242,7 +1333,8 @@ def args(self):
def kwargs(self):
return ParamSpecKwargs(self)

def __init__(self, name, *, bound=None, covariant=False, contravariant=False):
def __init__(self, name, *, bound=None, covariant=False, contravariant=False,
default=None):
super().__init__([self])
self.__name__ = name
self.__covariant__ = bool(covariant)
Expand All @@ -1251,6 +1343,7 @@ def __init__(self, name, *, bound=None, covariant=False, contravariant=False):
self.__bound__ = typing._type_check(bound, 'Bound must be a type.')
else:
self.__bound__ = None
_DefaultMixin.__init__(self, default)

# for pickling:
try:
Expand Down Expand Up @@ -1752,9 +1845,25 @@ def _is_unpack(obj):


if hasattr(typing, "TypeVarTuple"): # 3.11+
TypeVarTuple = typing.TypeVarTuple

# Add default Parameter - PEP 696
class TypeVarTuple(typing.TypeVarTuple, _DefaultMixin, _root=True):
"""Type variable tuple."""

def __init__(self, name, *, default=None):
super().__init__(name)
_DefaultMixin.__init__(self, default)

# for pickling:
try:
def_mod = sys._getframe(1).f_globals.get('__name__', '__main__')
except (AttributeError, ValueError):
def_mod = None
if def_mod != 'typing_extensions':
self.__module__ = def_mod

else:
class TypeVarTuple:
class TypeVarTuple(_DefaultMixin):
"""Type variable tuple.
Usage::
Expand Down Expand Up @@ -1804,8 +1913,9 @@ def get_shape(self) -> Tuple[*Ts]:
def __iter__(self):
yield self.__unpacked__

def __init__(self, name):
def __init__(self, name, *, default=None):
self.__name__ = name
_DefaultMixin.__init__(self, default)

# for pickling:
try:
Expand Down Expand Up @@ -1968,6 +2078,36 @@ def decorator(cls_or_fn):
return decorator


if hasattr(typing, "override"):
override = typing.override
else:
_F = typing.TypeVar("_F", bound=typing.Callable[..., typing.Any])

def override(__arg: _F) -> _F:
"""Indicate that a method is intended to override a method in a base class.
Usage:
class Base:
def method(self) -> None: ...
pass
class Child(Base):
@override
def method(self) -> None:
super().method()
When this decorator is applied to a method, the type checker will
validate that it overrides a method with the same name on a base class.
This helps prevent bugs that may occur when a base class is changed
without an equivalent change to a child class.
See PEP 698 for details.
"""
return __arg


# We have to do some monkey patching to deal with the dual nature of
# Unpack/TypeVarTuple:
# - We want Unpack to be a kind of TypeVar so it gets accepted in
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_vendor/vendor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ requests==2.28.1
urllib3==1.26.12
rich==12.5.1
pygments==2.13.0
typing_extensions==4.3.0
typing_extensions==4.4.0
resolvelib==0.8.1
setuptools==44.0.0
six==1.16.0
Expand Down

0 comments on commit 4ab07c7

Please sign in to comment.