[Python-checkins] r86857 - in python/branches/py3k: Lib/_abcoll.py Lib/test/test_collections.py Misc/NEWS
raymond.hettinger
python-checkins at python.org
Mon Nov 29 04:56:12 CET 2010
Author: raymond.hettinger
Date: Mon Nov 29 04:56:12 2010
New Revision: 86857
Log:
Issue #10565: Iterator ABC should require both __next__ and __iter__.
Modified:
python/branches/py3k/Lib/_abcoll.py
python/branches/py3k/Lib/test/test_collections.py
python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Lib/_abcoll.py
==============================================================================
--- python/branches/py3k/Lib/_abcoll.py (original)
+++ python/branches/py3k/Lib/_abcoll.py Mon Nov 29 04:56:12 2010
@@ -90,7 +90,8 @@
@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
Modified: python/branches/py3k/Lib/test/test_collections.py
==============================================================================
--- python/branches/py3k/Lib/test/test_collections.py (original)
+++ python/branches/py3k/Lib/test/test_collections.py Mon Nov 29 04:56:12 2010
@@ -356,8 +356,14 @@
for x in samples:
self.assertIsInstance(x, Iterator)
self.assertTrue(issubclass(type(x), Iterator), repr(type(x)))
- self.validate_abstract_methods(Iterator, '__next__')
- self.validate_isinstance(Iterator, '__next__')
+ self.validate_abstract_methods(Iterator, '__next__', '__iter__')
+
+ # Issue 10565
+ class NextOnly:
+ def __next__(self):
+ yield 1
+ raise StopIteration
+ self.assertNotIsInstance(NextOnly(), Iterator)
def test_Sized(self):
non_samples = [None, 42, 3.14, 1j,
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Mon Nov 29 04:56:12 2010
@@ -43,6 +43,9 @@
Library
-------
+- Issue #10565: The collections.Iterator ABC now checks for both
+ __iter__ and __next__.
+
- Issue #10242: Fixed implementation of unittest.ItemsEqual and gave it
a new more informative name, unittest.CountEqual.
More information about the Python-checkins
mailing list