[Python-Dev] PEP 343: Context managers a superset of decorators?

Nick Coghlan ncoghlan at gmail.com
Mon Feb 13 12:15:29 CET 2006

Eric Sumner wrote:
> I realize that I made an assumption that may not be valid;
> namely, that a new scope is generated by the 'with' statement.

The with statement uses the existing scope - its just a way of factoring out 
try/finally boilerplate code. No more, and, in fact, fractionally less (the 
'less' being the fact that just like any other Python function, you only get 
to supply one value to be bound to a name in the invoking scope).

Trying to link this with the function definition pipelining provided by 
decorators seems like a bit of a stretch. It certainly isn't a superset of the 
decorator functionality - if you want a statement that manipulates the 
namespace it contains, that's what class statements are for :)


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list