Movatterモバイル変換
[0]ホーム
[Python-Dev] Proposed resolutions for open PEP 343 issues
Guido van Rossumguido 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"> yield> print "Neither does this"That's only because of your proposal to endow generators with adefault __context__ manager. Drop that idea and you're golden.(As long as nobody snuck the proposal back in to let thewith-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 acontext manangers) will need the immediate explicit close() call, andit will happen eventually when they are GC'ed anyway. Too much magicis 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 tryingto do. __new__ is only special because it is part of the machinerythat 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-Devmailing list
[8]ページ先頭