Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ead22227
Commit
ead22227
authored
Nov 29, 2010
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10565: Iterator ABC should require both __next__ and __iter__.
parent
263cbdfd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
3 deletions
+13
-3
Lib/_abcoll.py
Lib/_abcoll.py
+2
-1
Lib/test/test_collections.py
Lib/test/test_collections.py
+8
-2
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/_abcoll.py
View file @
ead22227
...
...
@@ -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
...
...
Lib/test/test_collections.py
View file @
ead22227
...
...
@@ -356,8 +356,14 @@ class TestOneTrickPonyABCs(ABCTestCase):
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
,
...
...
Misc/NEWS
View file @
ead22227
...
...
@@ -43,6 +43,9 @@ Core and Builtins
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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment