[Python-Dev] Proposed resolutions for open PEP 343 issues

Guido van Rossum guido at python.org
Mon Oct 24 01:58:48 CEST 2005


On 10/23/05, Phillip J. Eby <pje at telecommunity.com> wrote:
> 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?

Of course it's an error! The translation in the PEP should make that
quite clear (there's no testing for whether __context__, __enter__
and/or __exit__ exist before they are called). It would be an
AttributeError.

> 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()'.

Right. That was my point. Nick's worried about undecorated __context__
because he wants to endow generators with a different default
__context__. I say no to both proposals and the worries cancel each
other out. EIBTI.

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list