mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-43224: Implement substitution of unpacked TypeVarTuple in C (GH-31828)
Co-authored-by: Matthew Rahtz <mrahtz@gmail.com>
This commit is contained in:
parent
a29aa76a3f
commit
e8c2f72b94
5 changed files with 152 additions and 41 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue