[Python-Dev] PEP 343 - Abstract Block Redux

Greg Ewing greg.ewing at canterbury.ac.nz
Mon May 16 06:51:49 CEST 2005


Phillip J. Eby wrote:
> This makes it seem awkward for e.g. "do self.__lock", which doesn't 
> make any sense.  But the extra call needed to make it "do 
> locking(self.__lock)" seems sort of gratuitous.

How about

   do holding(self.__lock):
     ...

> It makes me wonder if "with" or "using" or some similar word that works 
> better with nouns might be more appropriate ...   For
> example, a Decimal Context object might implement __enter__ by setting 
> itself as the thread-local context, and __exit__ by restoring the previous 
> context.    "do aDecimalContext" doesn't make much sense, but "with 
> aDecimalContext" or "using aDecimalContext" reads quite nicely.

It doesn't work so well when you don't already have an
object with one obvious interpretation of what you want
to do 'with' it, e.g. you have a pathname and you want
to open a file. I've already argued against giving file
objects __enter__ and __exit__ methods. And I'm -42 on
giving them to strings. :-)

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+


More information about the Python-Dev mailing list