Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use custom _ConcatenateGenericAlias for 3.10 #870

Merged
merged 2 commits into from Aug 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 40 additions & 39 deletions typing_extensions/src_py3/typing_extensions.py
Expand Up @@ -2387,52 +2387,53 @@ def _get_type_vars(self, tvars):
tvars.append(self)


# Inherits from list as a workaround for Callable checks in Python < 3.9.2.
class _ConcatenateGenericAlias(list):

# Trick Generic into looking into this for __parameters__.
if PEP_560:
__class__ = typing._GenericAlias
elif sys.version_info[:3] == (3, 5, 2):
__class__ = typing.TypingMeta
else:
__class__ = typing._TypingBase
if not hasattr(typing, 'Concatenate'):
# Inherits from list as a workaround for Callable checks in Python < 3.9.2.
class _ConcatenateGenericAlias(list):

# Flag in 3.8.
_special = False
# Attribute in 3.6 and earlier.
if sys.version_info[:3] == (3, 5, 2):
_gorg = typing.GenericMeta
else:
_gorg = typing.Generic
# Trick Generic into looking into this for __parameters__.
if PEP_560:
__class__ = typing._GenericAlias
elif sys.version_info[:3] == (3, 5, 2):
__class__ = typing.TypingMeta
else:
__class__ = typing._TypingBase

def __init__(self, origin, args):
super().__init__(args)
self.__origin__ = origin
self.__args__ = args
# Flag in 3.8.
_special = False
# Attribute in 3.6 and earlier.
if sys.version_info[:3] == (3, 5, 2):
_gorg = typing.GenericMeta
else:
_gorg = typing.Generic

def __repr__(self):
_type_repr = typing._type_repr
return '{origin}[{args}]' \
.format(origin=_type_repr(self.__origin__),
args=', '.join(_type_repr(arg) for arg in self.__args__))
def __init__(self, origin, args):
super().__init__(args)
self.__origin__ = origin
self.__args__ = args

def __hash__(self):
return hash((self.__origin__, self.__args__))
def __repr__(self):
_type_repr = typing._type_repr
return '{origin}[{args}]' \
.format(origin=_type_repr(self.__origin__),
args=', '.join(_type_repr(arg) for arg in self.__args__))

# Hack to get typing._type_check to pass in Generic.
def __call__(self, *args, **kwargs):
pass
def __hash__(self):
return hash((self.__origin__, self.__args__))

@property
def __parameters__(self):
return tuple(tp for tp in self.__args__ if isinstance(tp, (TypeVar, ParamSpec)))
# Hack to get typing._type_check to pass in Generic.
def __call__(self, *args, **kwargs):
pass

if not PEP_560:
# Only required in 3.6 and lower.
def _get_type_vars(self, tvars):
if self.__origin__ and self.__parameters__:
typing._get_type_vars(self.__parameters__, tvars)
@property
def __parameters__(self):
return tuple(tp for tp in self.__args__ if isinstance(tp, (TypeVar, ParamSpec)))

if not PEP_560:
# Only required in 3.6 and lower.
def _get_type_vars(self, tvars):
if self.__origin__ and self.__parameters__:
typing._get_type_vars(self.__parameters__, tvars)


@_tp_cache
Expand Down