Update collections from v3.14.3 (#7344)

* Update collections from v3.14.3

* Restore defaultdict fallback and update test markers

---------

Co-authored-by: CPython Developers <>
This commit is contained in:
Jeong, YunWon
2026-03-05 00:32:53 +09:00
committed by GitHub
3 changed files with 17 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
# tests common to dict and UserDict
import unittest
import collections
import sys
from test import support
class BasicTestMappingProtocol(unittest.TestCase):
@@ -70,8 +70,8 @@ class BasicTestMappingProtocol(unittest.TestCase):
if not d: self.fail("Full mapping must compare to True")
# keys(), items(), iterkeys() ...
def check_iterandlist(iter, lst, ref):
self.assertTrue(hasattr(iter, '__next__'))
self.assertTrue(hasattr(iter, '__iter__'))
self.assertHasAttr(iter, '__next__')
self.assertHasAttr(iter, '__iter__')
x = list(iter)
self.assertTrue(set(x)==set(lst)==set(ref))
check_iterandlist(iter(d.keys()), list(d.keys()),
@@ -448,7 +448,7 @@ class TestMappingProtocol(BasicTestMappingProtocol):
class Exc(Exception): pass
class baddict1(self.type2test):
def __init__(self):
def __init__(self, *args, **kwargs):
raise Exc()
self.assertRaises(Exc, baddict1.fromkeys, [1])
@@ -595,12 +595,14 @@ class TestHashMappingProtocol(TestMappingProtocol):
d = self._empty_mapping()
d[1] = 1
try:
count = 0
for i in d:
d[i+1] = 1
if count >= 1:
self.fail("changing dict size during iteration doesn't raise Error")
count += 1
except RuntimeError:
pass
else:
self.fail("changing dict size during iteration doesn't raise Error")
def test_repr(self):
d = self._empty_mapping()
@@ -620,9 +622,12 @@ class TestHashMappingProtocol(TestMappingProtocol):
d = self._full_mapping({1: BadRepr()})
self.assertRaises(Exc, repr, d)
@support.skip_wasi_stack_overflow()
@support.skip_emscripten_stack_overflow()
@support.skip_if_sanitizer("requires deep stack", ub=True)
def test_repr_deep(self):
d = self._empty_mapping()
for i in range(sys.getrecursionlimit() + 100):
for i in range(support.exceeds_recursion_limit()):
d0 = d
d = self._empty_mapping()
d[1] = d0

View File

@@ -262,7 +262,7 @@ class TestChainMap(unittest.TestCase):
d = c.new_child(b=20, c=30)
self.assertEqual(d.maps, [{'b': 20, 'c': 30}, {'a': 1, 'b': 2}])
@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: <class 'test.test_collections.TestChainMap.test_union_operators.<locals>.Subclass'> is not <class 'collections.ChainMap'>
def test_union_operators(self):
cm1 = ChainMap(dict(a=1, b=2), dict(c=3, d=4))
cm2 = ChainMap(dict(a=10, e=5), dict(b=20, d=4))
@@ -2029,7 +2029,7 @@ class TestCollectionABCs(ABCTestCase):
self.assertEqual(len(mss), len(mss2))
self.assertEqual(list(mss), list(mss2))
@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: TypeError not raised
def test_illegal_patma_flags(self):
with self.assertRaises(TypeError):
class Both(Collection):

View File

@@ -726,7 +726,7 @@ class TestBasic(unittest.TestCase):
d.append(1)
gc.collect()
@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: False is not true : Cycle was not collected
def test_container_iterator(self):
# Bug #3680: tp_traverse was not implemented for deque iterator objects
class C(object):
@@ -817,7 +817,7 @@ class TestSubclass(unittest.TestCase):
d.clear()
self.assertEqual(len(d), 0)
@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: 'Deque' object has no attribute 'x'
def test_copy_pickle(self):
for cls in Deque, DequeWithSlots:
for d in cls('abc'), cls('abcde', maxlen=4):
@@ -842,7 +842,7 @@ class TestSubclass(unittest.TestCase):
self.assertEqual(e.z, d.z)
self.assertNotHasAttr(e, 'y')
@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: 'Deque' object has no attribute 'x'
def test_pickle_recursive(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
for d in Deque('abc'), Deque('abc', 3):