[Python-Dev] Must objects with enter/exit also supply context? (original) (raw)
Guido van Rossum guido at python.org
Wed Apr 26 02:20:17 CEST 2006
- Previous message: [Python-Dev] Must objects with __enter__/__exit__ also supply __context__?
- Next message: [Python-Dev] Must objects with __enter__/__exit__ also supply __context__?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 4/25/06, Phillip J. Eby <pje at telecommunity.com> wrote:
At 04:18 PM 4/25/2006 -0700, Guido van Rossum wrote: >But the question remains, >under what circumstances is it convenient to call context() >explicit, and pass the result to a with-statement?
Oh. I don't know of any; I previously asked the same question myself. I just eventually answered myself with "I don't care; we need to require self-returning context on execution context objects so that the documentation can appear vaguely sane." :) So, I don't know of any non-self-returning use cases for context on an object that has enter and exit. In fact, I suspect that we could strengthen the requirements to say that: 1. If you have enter and exit, you MUST have a self-returning context 2. If you don't have enter and exit, you MUST NOT have a self-returning context #2 is obvious since you can't use the object with "with" otherwise. #1 reflects the fact that it doesn't make any sense to take the context of a context.
I would augment #1 to clarify that if you have enter and exit you may not have context at all; if you have all three, context must return self.
#2 is unnecessary (already covered elsewhere).
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Must objects with __enter__/__exit__ also supply __context__?
- Next message: [Python-Dev] Must objects with __enter__/__exit__ also supply __context__?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]