[Python-Dev] Must objects with enter/exit also supply context? (original) (raw)

Paul Moore p.f.moore at gmail.com
Mon Apr 24 22:35:01 CEST 2006


The current, alpha 2, documentation insists that objects with enter and exit methods must also define context in such a way that it returns self.

I don't understand why that is necessary.

I can understand that it is convenient, in cases where context doesn't need to create a new object each time, but is it necessary?

Specifically, is there a use case where you need to say "with x" where x is the return value of a context method, or where you call context on something you got from context? I can't find one in the PEP or in the code for contextlib...

By insisting that things with enter and exit methods must implement context, there's a subtype relationship which I think means that Nick's insistence that the concepts are distinct, becomes difficult to support. But the terms are so confused now, that I'm utterly unable to frame my objection clearly.

Can someone clarify this?

Paul.



More information about the Python-Dev mailing list