Skip to content

Commit 7517735

Browse files
authored
gh-96385: Correctly raise error on [*T, *V] substitution (GH-96386)
1 parent d21d2f0 commit 7517735

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
@@ -596,6 +596,7 @@ class GenericAliasSubstitutionTests(BaseTestCase):
596596
def test_one_parameter(self):
597597
T = TypeVar('T')
598598
Ts = TypeVarTuple('Ts')
599+
Ts2 = TypeVarTuple('Ts2')
599600

600601
class C(Generic[T]): pass
601602

@@ -621,6 +622,8 @@ class C(Generic[T]): pass
621622
# Should definitely raise TypeError: list only takes one argument.
622623
('list[T, *tuple_type[int, ...]]', '[int]', 'list[int, *tuple_type[int, ...]]'),
623624
('List[T, *tuple_type[int, ...]]', '[int]', 'TypeError'),
625+
# Should raise, because more than one `TypeVarTuple` is not supported.
626+
('generic[*Ts, *Ts2]', '[int]', 'TypeError'),
624627
]
625628

626629
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
@@ -1074,7 +1074,7 @@ def __typing_subst__(self, arg):
10741074
def __typing_prepare_subst__(self, alias, args):
10751075
params = alias.__parameters__
10761076
typevartuple_index = params.index(self)
1077-
for param in enumerate(params[typevartuple_index + 1:]):
1077+
for param in params[typevartuple_index + 1:]:
10781078
if isinstance(param, TypeVarTuple):
10791079
raise TypeError(f"More than one TypeVarTuple parameter in {alias}")
10801080

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)