[Python-Dev] Proposed resolutions for open PEP 343 issues
Guido van Rossum
guido at python.org
Sun Oct 23 18:19:40 CEST 2005
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"
> 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/)
More information about the Python-Dev