[Python-Dev] Must objects with __enter__/__exit__ also supply __context__?
Phillip J. Eby
pje at telecommunity.com
Wed Apr 26 02:35:38 CEST 2006
At 05:20 PM 4/25/2006 -0700, Guido van Rossum wrote:
>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.
Well, requiring the __context__ allows us to ditch the otherwise complex
problem of why @contextfactory functions' return value is usable by "with",
without having to explain it separately. So, I don't think there's any
reason to provide an option; there should be Only One Way To Do It.
Well, actually, two. That is, you can have one method or all three. Two
is right out. :)
(ObMontyPython: Wait, I'll come in again...)
More information about the Python-Dev
mailing list