From 8ffb8f5512f37d8c4cfa99298f853767a996b024 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" <69878+youknowone@users.noreply.github.com> Date: Thu, 5 Feb 2026 20:30:17 +0900 Subject: [PATCH] Update list-related CPython tests to v3.14.2 (#7000) --- Lib/test/test_list.py | 27 ++++++++++++++++++++++++--- Lib/test/test_listcomps.py | 31 ++++++++++++++++++++++++++----- Lib/test/test_userlist.py | 5 +---- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py index ed061384f..6dbe2d7a1 100644 --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -1,8 +1,10 @@ +import signal import sys import textwrap -from test import list_tests +from test import list_tests, support from test.support import cpython_only -from test.support.script_helper import assert_python_ok +from test.support.import_helper import import_module +from test.support.script_helper import assert_python_failure, assert_python_ok import pickle import unittest @@ -48,7 +50,7 @@ class ListTest(list_tests.CommonTest): with self.assertRaisesRegex(TypeError, 'keyword argument'): list(sequence=[]) - @unittest.expectedFailure # TODO: RUSTPYTHON + @unittest.expectedFailure # TODO: RUSTPYTHON def test_keywords_in_subclass(self): class subclass(list): pass @@ -329,6 +331,25 @@ class ListTest(list_tests.CommonTest): a.append(4) self.assertEqual(list(it), []) + @support.cpython_only + def test_no_memory(self): + # gh-118331: Make sure we don't crash if list allocation fails + import_module("_testcapi") + code = textwrap.dedent(""" + import _testcapi, sys + # Prime the freelist + l = [None] + del l + _testcapi.set_nomemory(0) + l = [None] + """) + rc, _, _ = assert_python_failure("-c", code) + if support.MS_WINDOWS: + # STATUS_ACCESS_VIOLATION + self.assertNotEqual(rc, 0xC0000005) + else: + self.assertNotEqual(rc, -int(signal.SIGSEGV)) + def test_deopt_from_append_list(self): # gh-132011: it used to crash, because # of `CALL_LIST_APPEND` specialization failure. diff --git a/Lib/test/test_listcomps.py b/Lib/test/test_listcomps.py index 6c1701dc9..964383966 100644 --- a/Lib/test/test_listcomps.py +++ b/Lib/test/test_listcomps.py @@ -609,7 +609,7 @@ class ListComprehensionTest(unittest.TestCase): result = snapshot = None try: result = [{func}(value) for value in value] - except: + except ValueError: snapshot = value raise """ @@ -643,13 +643,12 @@ class ListComprehensionTest(unittest.TestCase): value = [1, None] try: [v for v in value].sort() - except: + except TypeError: pass """ self._check_in_scopes(code, {"value": [1, None]}) - # TODO: RUSTPYTHON - @unittest.expectedFailure + @unittest.expectedFailure # TODO: RUSTPYTHON def test_frame_locals(self): code = """ val = "a" in [sys._getframe().f_locals for a in [0]][0] @@ -718,7 +717,7 @@ class ListComprehensionTest(unittest.TestCase): def test_exception_locations(self): # The location of an exception raised from __init__ or - # __next__ should should be the iterator expression + # __next__ should be the iterator expression def init_raises(): try: @@ -752,6 +751,28 @@ class ListComprehensionTest(unittest.TestCase): self.assertEqual(f.line[f.colno - indent : f.end_colno - indent], expected) + def test_only_calls_dunder_iter_once(self): + + class Iterator: + + def __init__(self): + self.val = 0 + + def __next__(self): + if self.val == 2: + raise StopIteration + self.val += 1 + return self.val + + # No __iter__ method + + class C: + + def __iter__(self): + return Iterator() + + self.assertEqual([1, 2], [i for i in C()]) + __test__ = {'doctests' : doctests} def load_tests(loader, tests, pattern): diff --git a/Lib/test/test_userlist.py b/Lib/test/test_userlist.py index 312702c8e..d3d9f4cff 100644 --- a/Lib/test/test_userlist.py +++ b/Lib/test/test_userlist.py @@ -3,7 +3,6 @@ from collections import UserList from test import list_tests import unittest -from test import support class UserListTest(list_tests.CommonTest): @@ -69,9 +68,7 @@ class UserListTest(list_tests.CommonTest): # Decorate existing test with recursion limit, because # the test is for C structure, but `UserList` is a Python structure. - test_repr_deep = support.infinite_recursion(25)( - list_tests.CommonTest.test_repr_deep, - ) + test_repr_deep = list_tests.CommonTest.test_repr_deep if __name__ == "__main__": unittest.main()