Skip to content

Commit 6ee542d

Browse files
tungolAlexWaygood
andauthored
pythongh-126417: validate ABC methods on multiprocessing proxy types (python#126454)
Checks that appropriate dunder __ methods exist on the dict and list proxy types. Co-authored-by: Alex Waygood <[email protected]>
1 parent 82269c7 commit 6ee542d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Lib/test/_test_multiprocessing.py

+22
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,19 @@ def test_list_isinstance(self):
24642464
a = self.list()
24652465
self.assertIsInstance(a, collections.abc.MutableSequence)
24662466

2467+
# MutableSequence also has __iter__, but we can iterate over
2468+
# ListProxy using __getitem__ instead. Adding __iter__ to ListProxy
2469+
# would change the behavior of a list modified during iteration.
2470+
mutable_sequence_methods = (
2471+
'__contains__', '__delitem__', '__getitem__', '__iadd__',
2472+
'__len__', '__reversed__', '__setitem__', 'append',
2473+
'clear', 'count', 'extend', 'index', 'insert', 'pop', 'remove',
2474+
'reverse',
2475+
)
2476+
for name in mutable_sequence_methods:
2477+
with self.subTest(name=name):
2478+
self.assertTrue(callable(getattr(a, name)))
2479+
24672480
def test_list_iter(self):
24682481
a = self.list(list(range(10)))
24692482
it = iter(a)
@@ -2508,6 +2521,15 @@ def test_dict_isinstance(self):
25082521
a = self.dict()
25092522
self.assertIsInstance(a, collections.abc.MutableMapping)
25102523

2524+
mutable_mapping_methods = (
2525+
'__contains__', '__delitem__', '__eq__', '__getitem__', '__iter__',
2526+
'__len__', '__ne__', '__setitem__', 'clear', 'get', 'items',
2527+
'keys', 'pop', 'popitem', 'setdefault', 'update', 'values',
2528+
)
2529+
for name in mutable_mapping_methods:
2530+
with self.subTest(name=name):
2531+
self.assertTrue(callable(getattr(a, name)))
2532+
25112533
def test_dict_iter(self):
25122534
d = self.dict()
25132535
indices = list(range(65, 70))

0 commit comments

Comments
 (0)