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()'.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4