|
1 | 1 | """Tests for C-implemented GenericAlias.""" |
2 | 2 |
|
3 | 3 | import unittest |
| 4 | +from test import support |
| 5 | +from test.support import import_helper |
4 | 6 | import pickle |
5 | 7 | from array import array |
6 | 8 | import copy |
|
62 | 64 | from string.templatelib import Template, Interpolation |
63 | 65 |
|
64 | 66 | import typing |
65 | | -from typing import TypeVar, Unpack |
| 67 | +from typing import TypeVar, TypeVarTuple, Unpack |
66 | 68 | T = TypeVar('T') |
67 | 69 | K = TypeVar('K') |
68 | 70 | V = TypeVar('V') |
| 71 | +Ts = TypeVarTuple("Ts") |
69 | 72 |
|
70 | 73 | _UNPACKED_TUPLES = [ |
71 | 74 | # Unpacked tuple using `*` |
|
97 | 100 | tuple[*tuple[Unpack[tuple[int, ...]]]], |
98 | 101 | ] |
99 | 102 |
|
| 103 | +_testcapi = import_helper.import_module("_testcapi") |
100 | 104 |
|
101 | 105 | class BaseTest(unittest.TestCase): |
102 | 106 | """Test basics.""" |
@@ -628,6 +632,29 @@ def test_gh150146(self): |
628 | 632 | with self.assertRaises(TypeError): |
629 | 633 | x[*typing.Mapping[..., ...]] |
630 | 634 |
|
| 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 | + |
631 | 658 |
|
632 | 659 | class TypeIterationTests(unittest.TestCase): |
633 | 660 | _UNITERABLE_TYPES = (list, tuple) |
|
0 commit comments