[Python-Dev] PEP 343 update (with statement context terminology)
Nick Coghlan
ncoghlan at gmail.com
Tue Apr 25 05:53:23 CEST 2006
Phillip J. Eby wrote:
> At 04:48 AM 4/25/2006 +1000, Nick Coghlan wrote:
>> Wanting to have two names for the same function tells me there's a
>> problem
>> with the terminology, not that we should actually have two names for
>> the same
>> function :)
>
> It is purely an implementation detail of @contextmanager that it can be
> used to define __context__ methods. It would be perfectly legal to
> implement it in such a way that there were two helper classes, one with
> a __context__ method, and the other with the __enter__/__exit__ methods.
>
> I'm fine, however, with:
>
> 1. Changing the decorator name to @contextfactory
Due to the ambiguity of the term, I'm still strongly resistant to the idea of
calling *any* of the objects involved context objects - so I don't like
contextfactory either (as it implies that this is something which creates
context objects).
> 2. Requiring objects with __enter/__exit__ to also have __context__
Yay, we finally agree on something :)
> The truth is that @contextmanager is a misnomer anyway, because it
> doesn't turn the function into a context manager, it turns the function
> into a context factory - i.e., when called, it returns a context (that's
> also a contextmanager).
A decorated generator function is as much a context manager as a normal
generator function is actually an iterator :)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-Dev
mailing list