[Python-Dev] Merging PEP 310 and PEP 340-redux?

Nick Coghlan ncoghlan at gmail.com
Fri May 13 18:43:08 CEST 2005


Guido van Rossum wrote:
> I just read Raymond Chen's rant against control flow macros:
> http://blogs.msdn.com/oldnewthing/archive/2005/01/06/347666.aspx
> 
> I think this pretty much kills PEP 340, as well as Nick Coghlan's
> alternative: both proposals let you write a "template" that can be
> used to hide exception-catching code, which is a form of control flow
> (and a pretty important one if you read Chen's rant against exceptions
> referenced by the former, even if you don't agree with everything he
> says in the latter).

It seems the effect of Raymond's articles on you was similar to their effect on 
me :)

> Straight up-or-down votes in the full senate are appreciated at this point.

PEP 340 redux for me (as you might have guessed) - I think the transaction() use 
case is a genuinely useful one. The ability to access the return value of 
__enter__() is also more useful than simply duplicating what could be achieved 
by an assignment on the line before the user defined statement.

> On to the secondary questions:
> 
> - Today I like the 'do' keyword better; 'with' might confuse folks
> coming from Pascal or VB

I think 'do' can be made to read correctly in more contexts that 'with'. The 
lack of a corresponding 'while' or 'until' should eliminate any temptation to 
see it as a loop.

The 'with' keyword also means I keep wanting the magic methods to be called 
"__acquire__" and "__release__" (and those would be harder to type. . .)

> - I have a more elaborate proposal for __exit__'s arguments. Let the
> translation be as follows:

I plan to rewrite my proposal based on this suggestion, just to explore the 
ramifications. I think it will turn out quite nicely.

The ban on yielding inside try/finally will need to be extended to yielding 
inside user defined statements until such time as an iterator finalisation 
protocol is chosen, though.

> (An alternative would be to always call it with 4 arguments, the last
> three being None in the first two cases.)

The former is probably tidier. __exit__() method implementations which don't 
care about the exception details can still use "*exc_info" in the argument 
signature, while those that want to use the information can just name the three 
parts without needing to specify the "=None" defaults.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.blogspot.com


More information about the Python-Dev mailing list