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

Nick Coghlan ncoghlan at gmail.com
Wed Apr 19 15:10:55 CEST 2006


Nick Coghlan wrote:
> The second occurrence of "context manager" is meant to say "context":
>> This PEP proposes that the protocol used by the with statement be
> known as the "context management protocol", and that objects that
> implement that protocol be known as "context managers". The term
> "context" then encompasses all objects with a __context__()
> method that returns a context object.
>> And the parenthetical comment was completely backwards and should have read:
>> (This means that all context managers are contexts, but not all contexts are
> context managers).
>> The reason for recommending that context managers should be contexts is 
> similar to the reason that iterators should be iterables - so that doing the 
> __context__() call manually will still give you something that can be used in 
> a with statement.

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) and "context manager" (which meant 'has __enter__ and 
__exit__ methods and a __context__ method that returns self' in the original PEP).
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 :)
Cheers,
Nick.
-- 
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
 http://www.boredomandlaziness.org


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /