[Python-Dev] More on contextlib - adding back a contextmanager decorator
Nick Coghlan
ncoghlan at gmail.com
Mon May 1 14:15:59 CEST 2006
Nick Coghlan wrote:
> Greg Ewing wrote:
>> Also a thought on terminology. Even though it seems I
>> may have been the person who thought it up originally,
>> I'm not sure I like the term "manager". It seems rather
>> wooly, and it's not clear whether a "context manager"
>> is supposed to manage just one context or multiple
>> contexts.
>
> I think getting rid of __context__ should clear up most of this confusion
> (which is further evidence that Guido is making the right call). Once that
> change is made, the context expression in the with statement produces a
> context manager with __enter__ and __exit__ methods which set up and tear down
> a managed context for the body of the with statement. This is very similar to
> your later suggestion of context guard and guarded context.
Thinking about it a bit further. . .
1. PEP 343, 2.5 alpha 1, 2.5 alpha 2 and the discussions here have no doubt
seriously confused the meaning of the term 'context manager' for a lot of
people (you can certainly put me down as one such person). Anyone not already
confused is likely to *become* confused if we subtly change the meaning in
alpha 3.
2. The phrase "managed context" is unfortunately close to .NET's term "managed
code", and would likely lead to confusion for IronPython folks (and other
programmers with .NET experience)
3. "manager" is an extremely generic term that is already used in a lot of
different ways in various programming contexts
Switching to Greg's suggestion of "context guard" and "guarded context" as the
terms would allow us to hit the reset button and start the documentation
afresh without terminology confusion resulting from the evolution of PEP 343
and its implementation and documentation.
I think context guard also works better in terms of guarding entry to and exit
from the guarded context, whereas I always wanted to call those operations
"set up" and "tear down" for context managers.
The current @contextfactory decorator could be renamed to @guardfactory to
make it explicit that it results in a factory function for context guards.
Cheers,
Nick.
P.S. I think I can hear anguished howls coming from the offices of various
book publishers around the world ;)
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-Dev
mailing list