Raymond Hettinger added the comment:
For the other ABCs, if you define the required abstract methods, you get
working versions of all the mixin methods.
In the case of the Generator ABC, throw() and close() are useless empty stub
methods. In the other ABCs, we leave optional methods out entirely. A user
should expect that if isinstance(g, Generator) is true that all of the ABC
methods will work.
Also, the return StopIteration in throw() doesn't seem correct. Shouldn't it
raise the exception that was thrown?
>>> def f():
yield x
>>> g = f()
>>> g.throw(KeyError)
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
g.throw(KeyError)
File "<pyshell#9>", line 1, in f
def f():
KeyError
Ideally, there should be a practical example of where this ABC would be useful
with anything other than a real generator.
----------
nosy: +rhettinger
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue24018>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com