bpo-43224: Implement substitution of unpacked TypeVarTuple in C (GH-31828)

Co-authored-by: Matthew Rahtz <mrahtz@gmail.com>
This commit is contained in:
Serhiy Storchaka 2022-04-30 08:22:46 +03:00 committed by GitHub
parent a29aa76a3f
commit e8c2f72b94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 152 additions and 41 deletions

View file

@ -1019,7 +1019,7 @@ class TypeVarTuple(_Final, _Immutable, _PickleUsingNameMixin, _root=True):
return self.__name__
def __typing_subst__(self, arg):
raise AssertionError
raise TypeError("Substitution of bare TypeVarTuple is not supported")
class ParamSpecArgs(_Final, _Immutable, _root=True):
@ -1686,11 +1686,15 @@ class _UnpackGenericAlias(_GenericAlias, _root=True):
return '*' + repr(self.__args__[0])
def __getitem__(self, args):
if (len(self.__parameters__) == 1 and
isinstance(self.__parameters__[0], TypeVarTuple)):
if self.__typing_unpacked__():
return args
return super().__getitem__(args)
def __typing_unpacked__(self):
# If x is Unpack[tuple[...]], __parameters__ will be empty.
return bool(self.__parameters__ and
isinstance(self.__parameters__[0], TypeVarTuple))
class Generic:
"""Abstract base class for generic types.