From f8005fc023d0cfdf00715573c71d84e7b9c140b7 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 30 May 2022 10:22:56 +0300 Subject: [PATCH 1/2] gh-93345: Fix a crash in substitution of nested TypeVar after TypeVarTuple --- Lib/test/test_typing.py | 8 +++++++- .../2022-05-30-10-22-46.gh-issue-93345.gi1A4L.rst | 2 ++ Objects/genericaliasobject.c | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-05-30-10-22-46.gh-issue-93345.gi1A4L.rst diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 2afac235391552..d6cd3d9bdd6a48 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -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, ...]]'), 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 00000000000000..8a11f473252183 --- /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 39fd70999ecbe5..59420816496f09 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]; } From 936f4ac4bf734bb6f7f9bf07db5daaa51fead1a2 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 31 May 2022 07:48:38 +0300 Subject: [PATCH 2/2] Update Misc/NEWS.d/next/Core and Builtins/2022-05-30-10-22-46.gh-issue-93345.gi1A4L.rst Co-authored-by: Ken Jin --- .../2022-05-30-10-22-46.gh-issue-93345.gi1A4L.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index 8a11f473252183..4cdb37cfe46981 100644 --- 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 @@ -1,2 +1,2 @@ -Fix a crash in substitution of a TypeVar in nested generic alias after -TypeVarTuple. +Fix a crash in substitution of a ``TypeVar`` in nested generic alias after +``TypeVarTuple``.