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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4