Raymond Hettinger added the comment:
In the lastest patch, the close() method is now a valid mixin method.
However, the throw() method should be made abstract because it doesn't provide
the required operation (it doesn't even use the "self" argument) or it should
be left out entirely (i.e. Numba only supporting next()) if the presence of
throw() is not required.
Going back to Stefan's original use case, the problem being solved is that
isinstance(g, types.GeneratorType) rejects regular classes that implement
send(), next(), throw(), and close(), presumably because it is going to call
those methods and expect that they work.
If an object tests positive for isinstance(g, collections.abc.Generator), what
can we then assume about the object. It would be weird to pass that test, see
a throw() method, call it and have it do something other than raise an
exception inside the generator.
g = lazy_readline_from_connection('171.0.0.1')
if isinstance(g, collections.abc.Generator):
# We passed the isinstance check, now what does that
# actually mean? What is guaranteed to work?
next(g)
g.close() # Expect this to close the connection
If a working throw() isn't actually required, then the code ought to be
checking for isinstance(obj, collections.abc.Iterator) or somesuch; otherwise,
was is the point of doing any checks for a generator-like object?
I don't think this patch should go in until it is capable of doing something
meaningful. Otherwise, it looks like at attempt to bluff its way past
generator checks that were presumably there for a reason.
----------
_______________________________________
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