At 10:04 AM 4/18/2006 -0400, A.M. Kuchling wrote: >PEP 343 says: > > 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 manager (this means that all context managers > are contexts, but not all contexts are context managers). > >I read this paragraph as meaning: > > context = 'thing with __context__()' > context manager = 'thing returned by __context__()' > >So in a 'with' statement: > >with A as B: > ... > >A is a context; the context manager is internal and unavailable.
I believe this is backwards. But then again, I would think that, since I wrote the documentation that takes the opposite tack. :) Partly, that's because I agree with your intuition about long-livedness of "manager", but mostly it's because the PEP is where the "contextmanager" decorator originated, and because it doesn't make any sense to call the method __context__() if it returns a context *manager*. :) > 1) Am I misunderstanding the PEP? Is > 'context = 'thing with __context__()' really the PEP's > meaning? > > 2) If the answer to 1) is 'yes', can we change the PEP? > > My intuition is that a 'manager' keeps track of multiple > entities being managed; to have a single 'context' produce > multiple 'context managers' over time seems exactly > backwards. > > I think I understand the logic behind the name -- that the > context manager *manages* the entry to and exit from the > block -- but think 'Manager' is the wrong term for this > because the object is really encapsulating a > procedure/algorithm, not managing a set of objects. The > closest GoF pattern name might be 'Strategy', which is > still a bit of a stretch. I think we should correct the PEP. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com