[Python-Dev] With context, please (original) (raw)

Paul Moore p.f.moore at gmail.com
Sun Apr 23 15:31:30 CEST 2006


On 4/23/06, Nick Coghlan <ncoghlan at gmail.com> wrote:

- contextlib.contextmanager() - is actually used to define contexts according to the current docs - but returns a GeneratorContextManager object

You may just be trying to avoid overcomplicating things by adding too much detail here, but you have missed my point about contextmanager - it's used in two, distinct, ways:

  1. On a simple function, to define a context manager (that's fine, and in line with the docs)
  2. On a context method to define a "function that returns a context"

The sticking point is (2), which is neither a context, nor a context manager. Purely by coincidence, a context manager will do here, but it's more than is needed.

So I still believe that you need 2 separate decorators here (no matter how much implementation they share).

I've not looked at your other examples, as I'm deliberately trying not to understand the details any further until I've read your proposed docs...

Paul.



More information about the Python-Dev mailing list