https://github.com/python/cpython/commit/16cebe69a87c5c6dcbfd3ba4730574b703963f56
commit: 16cebe69a87c5c6dcbfd3ba4730574b703963f56
branch: 3.13
author: Guilherme Leobas <[email protected]>
committer: sobolevn <[email protected]>
date: 2025-08-08T00:29:45+03:00
summary:

[3.13] gh-137463: Update validate_abstract_methods in test_collections.py 
(GH-137464) (#137521)

gh-137463: Update `validate_abstract_methods` in `test_collections.py` (#137464)

Update `validate_abstract_methods` in `test_collections.py`

The test for missing abstract methods in `validate_abstract_methods` 
incorrectly attempted to instantiate the generated class `C` with an argument 
(`C(name)`), which always raises a `TypeError: C() takes no arguments`. 
Although the test originally passes, it passes for the wrong reason.

This change makes the test correctly validate the enforcement of abstract 
methods in ABCs.

(cherry picked from commit 5be872350d562e6c9987b09ff4b7bda80a2f9cd0)

files:
M Lib/test/test_collections.py

diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index cafc44007d1185..843f4ffcd25aa4 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -736,7 +736,7 @@ def validate_abstract_methods(self, abc, *names):
             stubs = methodstubs.copy()
             del stubs[name]
             C = type('C', (abc,), stubs)
-            self.assertRaises(TypeError, C, name)
+            self.assertRaises(TypeError, C)
 
     def validate_isinstance(self, abc, name):
         stub = lambda s, *args: 0
@@ -963,7 +963,7 @@ class AnextOnly:
             async def __anext__(self):
                 raise StopAsyncIteration
         self.assertNotIsInstance(AnextOnly(), AsyncIterator)
-        self.validate_abstract_methods(AsyncIterator, '__anext__', '__aiter__')
+        self.validate_abstract_methods(AsyncIterator, '__anext__')
 
     def test_Iterable(self):
         # Check some non-iterables
@@ -1160,7 +1160,7 @@ def test_Iterator(self):
         for x in samples:
             self.assertIsInstance(x, Iterator)
             self.assertTrue(issubclass(type(x), Iterator), repr(type(x)))
-        self.validate_abstract_methods(Iterator, '__next__', '__iter__')
+        self.validate_abstract_methods(Iterator, '__next__')
 
         # Issue 10565
         class NextOnly:
@@ -1844,8 +1844,7 @@ def test_Mapping(self):
         for sample in [dict]:
             self.assertIsInstance(sample(), Mapping)
             self.assertTrue(issubclass(sample, Mapping))
-        self.validate_abstract_methods(Mapping, '__contains__', '__iter__', 
'__len__',
-            '__getitem__')
+        self.validate_abstract_methods(Mapping, '__iter__', '__len__', 
'__getitem__')
         class MyMapping(Mapping):
             def __len__(self):
                 return 0
@@ -1860,7 +1859,7 @@ def test_MutableMapping(self):
         for sample in [dict]:
             self.assertIsInstance(sample(), MutableMapping)
             self.assertTrue(issubclass(sample, MutableMapping))
-        self.validate_abstract_methods(MutableMapping, '__contains__', 
'__iter__', '__len__',
+        self.validate_abstract_methods(MutableMapping, '__iter__', '__len__',
             '__getitem__', '__setitem__', '__delitem__')
 
     def test_MutableMapping_subclass(self):
@@ -1899,8 +1898,7 @@ def test_Sequence(self):
         self.assertIsInstance(memoryview(b""), Sequence)
         self.assertTrue(issubclass(memoryview, Sequence))
         self.assertTrue(issubclass(str, Sequence))
-        self.validate_abstract_methods(Sequence, '__contains__', '__iter__', 
'__len__',
-            '__getitem__')
+        self.validate_abstract_methods(Sequence, '__len__', '__getitem__')
 
     def test_Sequence_mixins(self):
         class SequenceSubclass(Sequence):
@@ -1977,8 +1975,8 @@ def test_MutableSequence(self):
             self.assertTrue(issubclass(sample, MutableSequence))
         self.assertTrue(issubclass(array.array, MutableSequence))
         self.assertFalse(issubclass(str, MutableSequence))
-        self.validate_abstract_methods(MutableSequence, '__contains__', 
'__iter__',
-            '__len__', '__getitem__', '__setitem__', '__delitem__', 'insert')
+        self.validate_abstract_methods(MutableSequence, '__len__', 
'__getitem__',
+                                       '__setitem__', '__delitem__', 'insert')
 
     def test_MutableSequence_mixins(self):
         # Test the mixins of MutableSequence by creating a minimal concrete

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to