[Python-checkins] r86873 - in python/branches/release27-maint: Lib/_abcoll.py Lib/test/test_collections.py Misc/NEWS
alexander.belopolsky
python-checkins at python.org
Tue Nov 30 02:18:18 CET 2010
Author: alexander.belopolsky
Date: Tue Nov 30 02:18:17 2010
New Revision: 86873
Log:
Merged revisions 86857 via svnmerge from
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__.
........
Modified:
python/branches/release27-maint/ (props changed)
python/branches/release27-maint/Lib/_abcoll.py
python/branches/release27-maint/Lib/test/test_collections.py
python/branches/release27-maint/Misc/NEWS
Modified: python/branches/release27-maint/Lib/_abcoll.py
==============================================================================
--- python/branches/release27-maint/Lib/_abcoll.py (original)
+++ python/branches/release27-maint/Lib/_abcoll.py Tue Nov 30 02:18:17 2010
@@ -82,7 +82,7 @@
@classmethod
def __subclasshook__(cls, C):
if cls is Iterator:
- if _hasattr(C, "next"):
+ if _hasattr(C, "next") and _hasattr(C, "__iter__"):
return True
return NotImplemented
Modified: python/branches/release27-maint/Lib/test/test_collections.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_collections.py (original)
+++ python/branches/release27-maint/Lib/test/test_collections.py Tue Nov 30 02:18:17 2010
@@ -355,8 +355,19 @@
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)
+ class NextOnlyNew(object):
+ def __next__(self):
+ yield 1
+ raise StopIteration
+ self.assertNotIsInstance(NextOnlyNew(), Iterator)
def test_Sized(self):
non_samples = [None, 42, 3.14, 1j,
Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS (original)
+++ python/branches/release27-maint/Misc/NEWS Tue Nov 30 02:18:17 2010
@@ -22,6 +22,9 @@
Library
-------
+- Issue #10565: The collections.Iterator ABC now checks for both
+ ``__iter__`` and ``next``.
+
- Issue #10092: Properly reset locale in calendar.Locale*Calendar classes.
- Issue #10459: Update CJK character names to Unicode 5.2.
More information about the Python-checkins
mailing list