Craig Yoshioka wrote:
Ok, I'll go clean them up to try and present them as concisely as possible. The code to skip the with body would have to go in the __enter__ method because wether the body should be executed is dependent on the semantics of the context being used. Imagine a context that looks like:
with uncached('file') as file: # write data to file
Making the context skippable only from __enter__ means the person writing the context can be more confident of the possible code paths. And the person writing the body code could always just 'skip' manually anyways by returning early, i.e. per Michael's suggestion.
with uncached('file') as file: if not file: return
Can you give an example of the code that would be in __enter__? ~Ethan~