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.) In my previous mail I said I had to think about that one more -- well, I have, and I'm now -1 on it. Very few generators (that aren't used a context manangers) will need the immediate explicit close() call, and it will happen eventually when they are GC'ed anyway. Too much magic is bad for your health. > So how about if type_new simply raises a TypeError if it finds a > generator-iterator function in the __context__ slot? No. type should not bother with understanding what the class is trying to do. __new__ is only special because it is part of the machinery that type itself invokes in order to create a new class. -- --Guido van Rossum (home page: http://www.python.org/~guido/)
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