summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-06-01 06:43:38 (GMT)
committerGitHub <noreply@github.com>2022-06-01 06:43:38 (GMT)
commit3265ff9ccc870a25dd970a05a778a91cf86ee00a (patch)
treef9e577c12cf342e67f67758bbf443edebc08cff2
parent00f8fe956491816f03f1cc76bc7ed297cd9c0930 (diff)
downloadcpython-3265ff9ccc870a25dd970a05a778a91cf86ee00a.zip
cpython-3265ff9ccc870a25dd970a05a778a91cf86ee00a.tar.gz
cpython-3265ff9ccc870a25dd970a05a778a91cf86ee00a.tar.bz2
gh-93345: Fix a crash in substitution of nested TypeVar after TypeVarTuple (GH-93346)
For example: tuple[*Ts, list[T]][int, str, bool] (cherry picked from commit f545fc955aeb701ae4e73b07ff2283f823d857b8) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
-rw-r--r--Lib/test/test_typing.py8
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2022-05-30-10-22-46.gh-issue-93345.gi1A4L.rst2
-rw-r--r--Objects/genericaliasobject.c2
3 files changed, 10 insertions, 2 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 2afac23..d6cd3d9 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -768,12 +768,18 @@ class GenericAliasSubstitutionTests(BaseTestCase):
('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, ...]]'),
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-05-30-10-22-46.gh-issue-93345.gi1A4L.rst b/Misc/NEWS.d/next/Core and Builtins/2022-05-30-10-22-46.gh-issue-93345.gi1A4L.rst
new file mode 100644
index 0000000..4cdb37c
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-05-30-10-22-46.gh-issue-93345.gi1A4L.rst
@@ -0,0 +1,2 @@
+Fix a crash in substitution of a ``TypeVar`` in nested generic alias after
+``TypeVarTuple``.
diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c
index 39fd709..5942081 100644
--- a/Objects/genericaliasobject.c
+++ b/Objects/genericaliasobject.c
@@ -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];
}