[Python-Dev] PEP 377 - allow __enter__() methods to skip the statement body

Jim Baker jbaker at zyasoft.com
Sun Mar 15 20:43:18 CET 2009


For Jython, this proposal would not present any problems. Exceptions are in
any event of lower cost than for CPython.

Given that we have now adopted Python bytecode for various scenarios where
we cannot compile to Java bytecode, it would be nice to track any changes in
the VM such as the proposed SETUP_WITH opcode. But I'm sure we'll continue
to diff ceval.c, etc. (Consider this request perhaps fodder for the language
summit?)

- Jim

On Sun, Mar 15, 2009 at 12:37 PM, <glyph at divmod.com> wrote:

>
> On 12:56 pm, ncoghlan at gmail.com wrote:
>
>> PEP 377 is a proposal to allow context manager __enter__() methods to
>> skip the body of the with statement by raising a specific (new) flow
>> control exception.
>>
>> Since there is a working reference implementation now, I thought it was
>> time to open it up for broader discussion.
>>
>
> Why not allow a context manager to implement some other method, for the
> sake of argument let's say "__start__", which was invoked with a callable
> object and could choose to evaluate or not evaluate the statement body by
> simply not calling that object (or perhaps iterable, in the case of a
> generator)?
>
> This PEP proposes that we have two ways to deal with the body of a 'with'
> statement: either the body is run or not.  I have always wanted to have
> another option: run the body later.
>
> Passing around an object representing the body of the with statement would
> allow for this use-case, as well as removing the ugly protrusion of yet
> another control-flow exception (which, as has already been noted, creates
> difficulties for some other python implementations).
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/jbaker%40zyasoft.com
>



-- 
Jim Baker
jbaker at zyasoft.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090315/b28ad53b/attachment.htm>


More information about the Python-Dev mailing list