[Python-Dev] PEP 343 - next steps

Nick Coghlan ncoghlan at gmail.com
Sun Jun 12 06:52:47 CEST 2005


Barry Warsaw wrote:
> On Fri, 2005-06-10 at 16:23, Guido van Rossum wrote:
> 
>>While there's still some activity in the Wiki, nothing (to me) sounds
>>like signs of serious disagreement or truly better alternatives. So I
>>think I'd like to move forward towards acceptance soon (before
>>EuroPython).
> 
> 
> Well, I finally read PEP 343 in its entirety.  Having not really had the
> time to follow this thread, I have to say "well done".  I like the PEP a
> lot and can see many places in my own code where it would make things
> more readable.
> 
> I have one comment, and I may be too late or may be repeating other
> suggestions (no, I haven't poured through the wiki page yet).  I
> actually don't think "with" reads as well and would propose "when".

The idea behind 'with' is that the block is executed while holding 
(i.e. 'with') the resource.

I think the '-ing' form of the example templates is a holdover from 
the days when the PEP used the 'do' keyword - I find that past tense 
or noun forms tend to read better than present tense for custom built 
with templates named after the action that occurs on entry:

   # Past tense
   with locked(my_lock):
   with opened(my_file, mode):
   with redirected_stdout(my_stream):

   # Noun forms
   with my_lock:
   with open(my_file, mode) as f:
   with extra_precision():
   with decimal.getcontext() as ctx:


The place where the '-ing' form still makes some sense is when the 
template is named after the action that will occur at the *end* of the 
block:

   with closing(some_gen()) as g:
   with releasing(some_rsrc()) as r:

Cheers,
Nick.

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


More information about the Python-Dev mailing list