Skip to content

Commit 753c30b

Browse files
committed
gh-155053: Address review comments
1 parent 16b98b1 commit 753c30b

2 files changed

Lines changed: 3 additions & 29 deletions

File tree

Lib/test/test_genericalias.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""Tests for C-implemented GenericAlias."""
22

33
import unittest
4-
from test import support
5-
from test.support import import_helper
64
import pickle
75
from array import array
86
import copy
@@ -64,11 +62,10 @@
6462
from string.templatelib import Template, Interpolation
6563

6664
import typing
67-
from typing import TypeVar, TypeVarTuple, Unpack
65+
from typing import TypeVar, Unpack
6866
T = TypeVar('T')
6967
K = TypeVar('K')
7068
V = TypeVar('V')
71-
Ts = TypeVarTuple("Ts")
7269

7370
_UNPACKED_TUPLES = [
7471
# Unpacked tuple using `*`
@@ -100,8 +97,6 @@
10097
tuple[*tuple[Unpack[tuple[int, ...]]]],
10198
]
10299

103-
_testcapi = import_helper.import_module("_testcapi")
104-
105100
class BaseTest(unittest.TestCase):
106101
"""Test basics."""
107102
generic_types = [type, tuple, list, dict, frozendict,
@@ -632,29 +627,6 @@ def test_gh150146(self):
632627
with self.assertRaises(TypeError):
633628
x[*typing.Mapping[..., ...]]
634629

635-
@support.nomemtest
636-
def test_subs_tvars_nomemory(self):
637-
alias = dict[str, tuple[*Ts]]
638-
key = (int, str)
639-
640-
# Warm the code path to stabilize the allocation window.
641-
# This injection point was determined experimentally for this build.
642-
try:
643-
dict[str, tuple[int, str]]
644-
except Exception:
645-
pass
646-
647-
_testcapi.set_nomemory(24, 25)
648-
raised = False
649-
try:
650-
alias[key]
651-
except MemoryError:
652-
raised = True
653-
finally:
654-
_testcapi.remove_mem_hooks()
655-
656-
self.assertTrue(raised, "MemoryError not raised")
657-
658630

659631
class TypeIterationTests(unittest.TestCase):
660632
_UNITERABLE_TYPES = (list, tuple)

Objects/genericaliasobject.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ subs_tvars(PyObject *obj, PyObject *params,
302302
PyTuple_GET_SIZE(arg));
303303
if (j < 0) {
304304
Py_DECREF(subparams);
305+
/* tuple_extend() clears subargs on failure, so there is no
306+
reference left to decref here. */
305307
return NULL;
306308
}
307309
continue;

0 commit comments

Comments
 (0)