[Python-Dev] Why are contexts also managers? (was r45544 - peps/trunk/pep-0343.txt)
p.f.moore at gmail.com
Sat Apr 22 15:23:36 CEST 2006
On 4/22/06, Nick Coghlan <ncoghlan at gmail.com> wrote:
> So I'm going to express my gratitude by asking you to read the same docs all
> over again in a few days time :)
No problem. Remind me if I forget...
> I'll be making a pass through the docs (and PEP) this weekend using the
> - a context manager is a thing with enter/exit methods
> (it sets up and tears down an execution context for a block of code)
> - the with statement delimits the block which is in an execution context
> - the with statement asks a context object for a context manager to set up
> and tear down an execution context when the block runs
> - context objects have a __context__ method to produce context managers
> (hey, it isn't really that much worse than using the __iter__ method to
> ask an iterable for an iterator. . .)
Sorry, but I don't really like this. I find the idea of a context
manager, creating contexts, within which the block in a with statement
runs, much more intuitive. As I said, the only issue I have with it is
the dual use of the contextmanager decorator (and I think that's
fundamental - there are 2 different things going on, and they *should*
have different names).
But I'll do my best to put away my prejudices and read the new docs as
they are written, when they come out.
> If the terminology *still* breaks down with those slightly different
> definitions, we'll have to try to come up with a third option after the 2nd
> alpha. I'm really hoping my planned changes actually work out, because if they
> don't I'm out of ideas for how to make these concepts easier to grok. . .
Presumably, then, my proposal didn't make things clear to you?
I won't comment further on your proposal, as I *want* to avoid
thinking about it before I read the docs...
More information about the Python-Dev