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__. ........
This commit is contained in:
parent
34cc202559
commit
fdb32c15e4
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue