On 12:56 pm, ncoghlan at gmail.com wrote: >PEP 377 is a proposal to allow context manager __enter__() methods to >skip the body of the with statement by raising a specific (new) flow >control exception. > >Since there is a working reference implementation now, I thought it was >time to open it up for broader discussion. Why not allow a context manager to implement some other method, for the sake of argument let's say "__start__", which was invoked with a callable object and could choose to evaluate or not evaluate the statement body by simply not calling that object (or perhaps iterable, in the case of a generator)? This PEP proposes that we have two ways to deal with the body of a 'with' statement: either the body is run or not. I have always wanted to have another option: run the body later. Passing around an object representing the body of the with statement would allow for this use-case, as well as removing the ugly protrusion of yet another control-flow exception (which, as has already been noted, creates difficulties for some other python implementations).
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