[Python-Dev] PEP 318 trial balloon (wrappers)

Jewett, Jim J jim.jewett at eds.com
Thu Mar 11 15:11:51 EST 2004


I am hoping to post a new draft of PEP318 soon.

Unfortunately, the solution that currently looks 
best to me has not been mentioned before.

I wanted to give a heads up, so that people will
be able to read the rest of the PEP too.  (And
so that I can change it if everyone else hates
the new syntax.)

The most common use case is

    class Foo:
        def bar():
            pass
        bar = transform(bar)

Because the name bar is immediately rebound, it
effectively never references the original 
function directly.  That function is hidden from
the namespace where it is defined.  

This is similar to nested functions.

def foo():
    def bar():
        pass

bar is never visible (at least under that name) at 
the global level.  To indicate this, it is nested 
inside the foo() block.

I would like to do the same with decorators.

class Foo:
    [transform] from:
        def bar():
            pass

The bar() function is now defined exactly as it was before,
except that it is an extra indent to the right.

[transform] can be treated as a completely ordinary list.

The "from:" indicates that each member of this (just evaluated) 
list should be applied to the contained block, and the final
result should be bound to the name (that would otherwise be)
assigned to that internal block.

-jJ



More information about the Python-Dev mailing list