[Python-ideas] Anonymous blocks (again):
Juancarlo Añez
apalala at gmail.com
Sun May 12 06:10:49 CEST 2013
Hello,
I've banged my self against the wall, and there simply isn't a pythonic way
to make a context manager iterate over the yielded-to block of code.
I've had to resource to this in Grako[*]:
def block():
self.rule()
self.ast['rules'] = self.last_node
closure(block)
But what I think would be more pythonic is:
closure(
def:
self.rule()
self.ast['rules'] = self.last_node
)
Or, better yet (though I know I can't have it):
with positive_closure():
self.rule()
self.ast['rules'] = self.last_node
The thing is that a "closure" needs to call the given block repeatedly,
while remaining in control of the context of each invocation. The examples
given above would signal the closure to be over with an exception.
The convoluted handling of exceptions on context manager's __exit__ make it
impossible (for me) to construct a context manager that can call the
yield-to block several times.
Anyway, the anonymous def syntax, with or without parameters, is a given,
and a solution for many qualms about the Python way of things.
[*] https://bitbucket.org/apalala/grako
--
Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130511/68f8b842/attachment.html>
More information about the Python-ideas
mailing list