Skip to content

Commit

Permalink
pythongh-93345: Fix a crash in substitution of nested TypeVar after T…
Browse files Browse the repository at this point in the history
…ypeVarTuple
  • Loading branch information
serhiy-storchaka committed May 30, 2022
1 parent dec1e93 commit f8005fc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,12 +768,18 @@ class C(Generic[*Ts]): pass
('generic[T, *Ts]', '[int]', 'generic[int]'),
('generic[T, *Ts]', '[int, str]', 'generic[int, str]'),
('generic[T, *Ts]', '[int, str, bool]', 'generic[int, str, bool]'),
('generic[list[T], *Ts]', '[int]', 'generic[list[int]]'),
('generic[list[T], *Ts]', '[int, str]', 'generic[list[int], str]'),
('generic[list[T], *Ts]', '[int, str, bool]', 'generic[list[int], str, bool]'),

('generic[T, *Ts]', '[*tuple[int, ...]]', 'TypeError'), # Should be generic[int, *tuple[int, ...]]

('generic[*Ts, T]', '[int]', 'generic[int]'),
('generic[*Ts, T]', '[int, str]', 'generic[int, str]'),
('generic[*Ts, T]', '[int, str, bool]', 'generic[int, str, bool]'),
('generic[*Ts, T]', '[int, str, bool]', 'generic[int, str, bool]'),
('generic[*Ts, list[T]]', '[int]', 'generic[list[int]]'),
('generic[*Ts, list[T]]', '[int, str]', 'generic[int, list[str]]'),
('generic[*Ts, list[T]]', '[int, str, bool]', 'generic[int, str, list[bool]]'),

('generic[T, *tuple_type[int, ...]]', '[str]', 'generic[str, *tuple_type[int, ...]]'),
('generic[T1, T2, *tuple_type[int, ...]]', '[str, bool]', 'generic[str, bool, *tuple_type[int, ...]]'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash in substitution of a TypeVar in nested generic alias after
TypeVarTuple.
2 changes: 1 addition & 1 deletion Objects/genericaliasobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ subs_tvars(PyObject *obj, PyObject *params,
else {
if (iparam >= 0) {
if (iparam > varparam) {
iparam += nargs - nsubargs;
iparam += nargs - nparams;
}
arg = argitems[iparam];
}
Expand Down

0 comments on commit f8005fc

Please sign in to comment.