[Python-Dev] Why are contexts also managers? (was r45544 - peps/trunk/pep-0343.txt) (original) (raw)

A.M. Kuchling amk at amk.ca
Tue Apr 18 22🔞29 CEST 2006


On Tue, Apr 18, 2006 at 08:55:18PM +0200, phillip.eby wrote:

Modified: peps/trunk/pep-0343.txt

+ "context manager" then encompasses all objects with a context() + method that returns a context object. (This means that all contexts + are context managers, but not all context managers are contexts).

This change reminds of another question I had about the parenthetical statement: all contexts are context managers (= 'has a context' method). Why? The context object isn't necessarily available to the Python programmer, so they can't write:

with context_mgr as context: with context: # uses the same context ...

Why do contexts need to have a context() method?

--amk



More information about the Python-Dev mailing list