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

Phillip J. Eby pje at telecommunity.com
Tue Apr 25 20:59:10 CEST 2006


At 11:37 AM 4/25/2006 -0700, Guido van Rossum wrote:

But what's the use case? Have we actually got an example where it makes sense to use the "thing with enter and exit methods" in a with-statement, other than the (many) examples where the original context method returns "self"?

Objects returned by @contextfactory-decorated functions must have enter and exit (so @contextfactory can be used to define context methods) and they must also have context, so they can be used directly in a "with" statement.

I think that in all cases where you want this (enter/exit implies context method availability), it's going to be the case that you want the context method to return self, just as iterating an object with a next() method normally returns that object.



More information about the Python-Dev mailing list