[Python-Dev] PEP 343 update (with statement context terminology) (original) (raw)

Phillip J. Eby pje at telecommunity.com
Mon Apr 24 22:50:32 CEST 2006


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

  2. Requiring objects with __enter/exit to also have context (i.e., keep "context" as a subtype of "contextmanager")

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).



More information about the Python-Dev mailing list