]> granicus.if.org Git - python/commitdiff
Merged revisions 86857 via svnmerge from
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Tue, 30 Nov 2010 01:01:02 +0000 (01:01 +0000)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Tue, 30 Nov 2010 01:01:02 +0000 (01:01 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r86857 | raymond.hettinger | 2010-11-28 22:56:12 -0500 (Sun, 28 Nov 2010) | 1 line

  Issue #10565:  Iterator ABC should require both __next__ and __iter__.
........

Lib/_abcoll.py
Lib/test/test_collections.py
Misc/NEWS

index cac06e0825f48bd55cbdb5fddacff0fd116aa128..0957553613b770b9376511f39d0cf02e1e4c49c8 100644 (file)
@@ -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
 
index dc61fa414701e6c8007ed48f3f40cbd291e56efc..988db92e16c0915a04fec9038d5c4c770475e462 100644 (file)
@@ -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,
index 1167fff329b4c9c8d9a8fbf0cd9609ac3b559aae..11a26d4acb13d692bc47d7b47a7ac12e2e1e0311 100644 (file)
--- 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.