Author rhettinger
Recipients Ludovic.Gasc, gvanrossum, lukasz.langa, martin.panter, pitrou, rhettinger, scoder, vstinner, yselivanov
Date 2015-04-26.19:37:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1430077069.41.0.368631007048.issue24018@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-04-26 19:37:49rhettingersetrecipients: + rhettinger, gvanrossum, pitrou, scoder, vstinner, lukasz.langa, Ludovic.Gasc, martin.panter, yselivanov
2015-04-26 19:37:49rhettingersetmessageid: <1430077069.41.0.368631007048.issue24018@psf.upfronthosting.co.za>
2015-04-26 19:37:49rhettingerlinkissue24018 messages
2015-04-26 19:37:49rhettingercreate