Skip to content

Commit 16d8948

Browse files
gh-96385: Correctly raise error on [*T, *V] substitution (GH-96386) (#96407)
(cherry picked from commit 7517735) Co-authored-by: Nikita Sobolev <[email protected]> Co-authored-by: Nikita Sobolev <[email protected]>
1 parent 8e2d347 commit 16d8948

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Lib/test/test_typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ class GenericAliasSubstitutionTests(BaseTestCase):
591591
def test_one_parameter(self):
592592
T = TypeVar('T')
593593
Ts = TypeVarTuple('Ts')
594+
Ts2 = TypeVarTuple('Ts2')
594595

595596
class C(Generic[T]): pass
596597

@@ -616,6 +617,8 @@ class C(Generic[T]): pass
616617
# Should definitely raise TypeError: list only takes one argument.
617618
('list[T, *tuple_type[int, ...]]', '[int]', 'list[int, *tuple_type[int, ...]]'),
618619
('List[T, *tuple_type[int, ...]]', '[int]', 'TypeError'),
620+
# Should raise, because more than one `TypeVarTuple` is not supported.
621+
('generic[*Ts, *Ts2]', '[int]', 'TypeError'),
619622
]
620623

621624
for alias_template, args_template, expected_template in tests:

Lib/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ def __typing_subst__(self, arg):
10711071
def __typing_prepare_subst__(self, alias, args):
10721072
params = alias.__parameters__
10731073
typevartuple_index = params.index(self)
1074-
for param in enumerate(params[typevartuple_index + 1:]):
1074+
for param in params[typevartuple_index + 1:]:
10751075
if isinstance(param, TypeVarTuple):
10761076
raise TypeError(f"More than one TypeVarTuple parameter in {alias}")
10771077

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix ``TypeVarTuple.__typing_prepare_subst__``. ``TypeError`` was not raised
2+
when using more than one ``TypeVarTuple``, like ``[*T, *V]`` in type alias
3+
substitutions.

0 commit comments

Comments
 (0)