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
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)?
On 12:56 pm, ncoghlan@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.
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@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/jbaker%40zyasoft.com