[Python-ideas] Anonymous blocks (again):

Juancarlo Añez apalala at gmail.com
Mon May 13 17:23:37 CEST 2013


On Mon, May 13, 2013 at 4:52 AM, Lakshmi Vyas <lakshmi.vyas at gmail.com>wrote:

> Here is a place where I really craved for blocks and resorted to using a
> context manager + decorators:
>
> https://github.com/gitbot/gitbot/blob/master/gitbot/lib/s3.py#L140-L169
>

That is a VERY interesting pattern:


      with source.walker as walker:
            def ignore(name):
                return match_pattern(ignore_patterns, name)


            @walker.folder_visitor
            def visit_folder(folder):


Make the context be the source of the decorators, and do the iteration on
__exit__.

This could work for me, but you must admit it is very much twisting context
managers arms to the extreme.

      with self.closure() as c:
             @c
            def *_*(): match_this() match_that()

I'd like the above to be something like (warning:new keyword ahead):

      within self.closure():
match_this()
 match_that()

A clean, anonymous block.

-- 
Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130513/00d8f7ae/attachment-0001.html>


More information about the Python-ideas mailing list