Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Lib/test/test_genericalias.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@
from unittest.case import _AssertRaisesContext
from queue import Queue, SimpleQueue
from weakref import WeakSet, ReferenceType, ref
import typing
from typing import Unpack
try:
from tkinter import Event
except ImportError:
Event = None
from string.templatelib import Template, Interpolation

from typing import TypeVar
import typing
from typing import TypeVar, Unpack
T = TypeVar('T')
K = TypeVar('K')
V = TypeVar('V')
Expand Down Expand Up @@ -621,6 +620,14 @@ def test_nested_paramspec_specialization(self):
self.assertEqual(deeply_nested_specialized.__args__, ([str, [float], int], float))
self.assertEqual(deeply_nested_specialized.__parameters__, ())

def test_gh150146(self):
# It used to crash:
for container in [memoryview, list, tuple]:
with self.subTest(container=container):
x = container[TypeVar("")]
with self.assertRaises(TypeError):
x[*typing.Mapping[..., ...]]


class TypeIterationTests(unittest.TestCase):
_UNITERABLE_TYPES = (list, tuple)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fix a crash on a complex type variable substitution.

``from typing import TypeVar; memoryview[TypeVar("")][*typing.Mapping[...,
...]]`` used to fail due to missing ``NULL`` check on ``_unpack_args`` C
function call.
3 changes: 3 additions & 0 deletions Objects/genericaliasobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ _Py_subs_parameters(PyObject *self, PyObject *args, PyObject *parameters, PyObje
self);
}
item = _unpack_args(item);
if (item == NULL) {
return NULL;
}
for (Py_ssize_t i = 0; i < nparams; i++) {
PyObject *param = PyTuple_GET_ITEM(parameters, i);
PyObject *prepare, *tmp;
Expand Down
Loading