[Python-Dev] Must objects with __enter__/__exit__ also supply __context__?

Guido van Rossum guido at python.org
Wed Apr 26 06:23:36 CEST 2006


I'm not convinced.

On 4/25/06, Phillip J. Eby <pje at telecommunity.com> wrote:
> At 11:29 PM 4/25/2006 -0400, Phillip J. Eby wrote:
> >See, if @contextfactory functions return a thing *with* a __context__
> >method, how is that usable with "with"?  It isn't, unless the thing also
> >happens to have __enter__/__exit__ methods.  This was the hole in the
> >documentation that caused Nick to seek to revisit the decorator name in the
> >first place.
>
> Argh.  I seem to be tongue-tied this evening.  What I mean is, if
> @contextfactory functions' return value is usable as a "with" expression,
> that means it must have a __context__ method.  But, if you are using
> @contextfactory to *define* a __context__ method, the return value should
> clearly have __enter__ and __exit__ methods.
>
> What this means is that if we describe the one method and the two methods
> as independent things, there is no *single* name we can use to describe the
> return value of a @contextfactory function.  It's a wave and a particle, so
> we either have to start talking about "wavicles" or have some detailed
> explanation of why @contextfactory function return values are both waves
> and particles at the same time.
>
> However, if we say that particles are a kind of wave, and have all the same
> features as waves but just add a few others, then we can simply say
> @contextfactory functions return particles, and the waviness is implied,
> and all is right in the world.  At least, until AMK comes along and asks
> why you can't separate the particleness from the waveness, which was what
> started this whole thing in the first place...  :)
>
>
>


--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list