[Python-Dev] Proposed resolutions for open PEP 343 issues

Phillip J. Eby pje at telecommunity.com
Sun Oct 23 18:51:27 CEST 2005


At 09:19 AM 10/23/2005 -0700, Guido van Rossum wrote:
>On 10/23/05, Nick Coghlan <ncoghlan at gmail.com> wrote:
> > However, I'm still concerned about the fact that the following class has a
> > context manager that doesn't actually work:
> >
> >    class Broken(object):
> >      def __context__(self):
> >          print "This never gets executed"
> >          yield
> >          print "Neither does this"
>
>That's only because of your proposal to endow generators with a
>default __context__ manager. Drop that idea and you're golden.
>
>(As long as nobody snuck the proposal back in to let the
>with-statement silently ignore objects that don't have a __context__
>method -- that was rejected long ago on.)

Actually, you've just pointed out a new complication introduced by having 
__context__.  The return value of __context__ is supposed to have an 
__enter__ and an __exit__.  Is it a type error if it doesn't?  How do we 
handle that, exactly?

That is, assuming generators don't have enter/exit/context methods, then 
the above code is broken because its __context__ returns an object without 
enter/exit, sort of like an __iter__ that returns something without a 'next()'.



More information about the Python-Dev mailing list