For Jython, this proposal would not present any problems. Exceptions are in any event of lower cost than for CPython.<br><br>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&#39;m sure we&#39;ll continue to diff ceval.c, etc. (Consider this request perhaps fodder for the language summit?)<br>
<br>- Jim<br><br><div class="gmail_quote">On Sun, Mar 15, 2009 at 12:37 PM,  <span dir="ltr">&lt;<a href="mailto:glyph@divmod.com">glyph@divmod.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br>
On 12:56 pm, <a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
PEP 377 is a proposal to allow context manager __enter__() methods to<br>
skip the body of the with statement by raising a specific (new) flow<br>
control exception.<br>
<br>
Since there is a working reference implementation now, I thought it was<br>
time to open it up for broader discussion.<br>
</blockquote>
<br></div>
Why not allow a context manager to implement some other method, for the sake of argument let&#39;s say &quot;__start__&quot;, 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)?<br>

<br>
This PEP proposes that we have two ways to deal with the body of a &#39;with&#39; statement: either the body is run or not.  I have always wanted to have another option: run the body later.<br>
<br>
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).<div>
<div></div><div class="h5"><br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/jbaker%40zyasoft.com" target="_blank">http://mail.python.org/mailman/options/python-dev/jbaker%40zyasoft.com</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Jim Baker<br><a href="mailto:jbaker@zyasoft.com">jbaker@zyasoft.com</a><br>