[issue17584] collections.Iterator __subclasshook__ does not check if next() is callable

Raymond Hettinger report at bugs.python.org
Sun Mar 31 21:39:14 CEST 2013


Raymond Hettinger added the comment:

It's the nature of duck typing in a dynamic language.  You can tell whether something is present but can't tell whether it words correctly until you call it.

For example, in Python 3, all objects have __lt__ defined, but all it does is return NotImplemented.  So, you can't really tell whether something is orderable until you make the less-than call.

In your case, the rule is that if "next" is present, we assume that it is iterable, but it won't be until it is called that we can tell whether it is implemented correctly (i.e. is callable with zero arguments, returns a value, and raises StopIteration when done).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17584>
_______________________________________


More information about the Python-bugs-list mailing list