Guido van Rossum wrote:
@acquire(myLock):
    code
    code
    code

It would certainly solve the problem of which keyword to use! :-) And I think the syntax isn't even ambiguous -- the trailing colon distinguishes this from the function decorator syntax. I guess it would morph '@xxx' into "user-defined-keyword".

How would acquire be defined? I guess it could be this, returning a
function that takes a callable as an argument just like other
decorators:

def acquire(aLock):
   def acquirer(block):
       aLock.acquire()
       try:
           block()
       finally:
           aLock.release()
   return acquirer

and the substitution of

@EXPR:
   CODE

would become something like

def __block():
   CODE
EXPR(__block)

Why not have the block automatically be inserted into acquire's argument list? It would probably get annoying to have to define inner functions like that every time one simply wants to use arguments. For example:


def acquire(block, aLock):
        aLock.acquire()
        try:
                block()
        finally:
                aLock.release()

@acquire(myLock):
        code
        code
        code

Of course, augmenting the argument list in that way would be different than the behavior of decorators as they are now.

-Brian
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to