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. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com