summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/_abcoll.py3
-rw-r--r--Lib/test/test_collections.py9
-rw-r--r--Misc/NEWS3
3 files changed, 13 insertions, 2 deletions
diff --git a/Lib/_abcoll.py b/Lib/_abcoll.py
index cac06e0..0957553 100644
--- a/Lib/_abcoll.py
+++ b/Lib/_abcoll.py
@@ -90,7 +90,8 @@ class Iterator(Iterable):
@classmethod
def __subclasshook__(cls, C):
if cls is Iterator:
- if any("__next__" in B.__dict__ for B in C.__mro__):
+ if (any("__next__" in B.__dict__ for B in C.__mro__) and
+ any("__iter__" in B.__dict__ for B in C.__mro__)):
return True
return NotImplemented
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index dc61fa4..988db92 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -328,7 +328,14 @@ class TestOneTrickPonyABCs(ABCTestCase):
for x in samples:
self.assertTrue(isinstance(x, Iterator), repr(x))
self.assertTrue(issubclass(type(x), Iterator), repr(type(x)))
- self.validate_abstract_methods(Iterator, '__next__')
+ self.validate_abstract_methods(Iterator, '__next__', '__iter__')
+
+ # Issue 10565
+ class NextOnly:
+ def __next__(self):
+ yield 1
+ raise StopIteration
+ self.assertFalse(isinstance(NextOnly(), Iterator))
def test_Sized(self):
non_samples = [None, 42, 3.14, 1j,
diff --git a/Misc/NEWS b/Misc/NEWS
index 1167fff..11a26d4 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -28,6 +28,9 @@ Core and Builtins
Library
-------
+- Issue #10565: The collections.Iterator ABC now checks for both
+ __iter__ and __next__.
+
- Issue #10561: In pdb, clear the breakpoints by the breakpoint number.
- Issue #10459: Update CJK character names to Unicode 5.1.