At 09:19 AM 10/23/2005 -0700, Guido van Rossum wrote: >On 10/23/05, Nick Coghlan <[EMAIL PROTECTED]> 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()'. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com