[Python-Dev] Why are contexts also managers? (was r45544 - peps/trunk/pep-0343.txt)

Phillip J. Eby pje at telecommunity.com
Wed Apr 19 17:30:00 CEST 2006


At 11:10 PM 4/19/2006 +1000, Nick Coghlan wrote:
>Ah, all is explained by svn blame, with a little help from svn log.
>
>When Phillip went through to make the terminology consistent he actually
>swapped the meanings of "context" (which meant 'has a __context__ method' in
>the original PEP)

At least AMK and I thought that it was obvious that "context manager" means 
"has a context method", and it's the only way to have the PEP read 
consistently.

Note that the decorator is called @contextmanager, not @context, for example.


>  and "context manager" (which meant 'has __enter__ and
>__exit__ methods and a __context__ method that returns self' in the 
>original PEP).

That's true - *before* there was a __context__ method.  Now that there *is* 
a context method, it makes more sense to say that the thing that has it is 
the context manager, and the thing with the __enter__/__exit__ methods is 
the context.


>I clearly wasn't paying attention when that diff went past on the checkins
>list, but I'd humbly request that we change it back :)

The change made the PEP self-consistent in its terminology, if you are 
encountering it for the first time, and don't already have it in your head 
that it's one way or the other.  If we change it the other way, we'll have 
to rename @contextmanager.



More information about the Python-Dev mailing list