[Python-Dev] Pep 318 - new syntax for wrappers

Skip Montanaro skip at pobox.com
Wed Mar 3 10:38:30 EST 2004


    Jim> (1)  Eventually, there will be another good idea.

    Jim> Therefore, we should define a general extension syntax, rather than
    Jim> a special case for this particular extension.

    Jim>     def func(args) [wrapper1, wrapper2]:

    Jim> uses up the syntax forever.

    Jim>     def func(args) mods [wrapper1, wrapper2]:

    Jim> allows later extensions like

    Jim>     def func(args) alias [wrapper1, wrapper2]:
    Jim>     def func(args) compiler_hints [wrapper1, wrapper2]:
    Jim>     def func(args) my_domain_special_use [wrapper1, wrapper2]:

I don't think the second version is needed.  Consider the compiler_hints
extension:

    def func (args) [hint1, hint2]:
        pass

    def hint1(func):
        func.hint1 = True
        return func

    def hint2(func):
        mess_with_func.func_code()
        return func

There's no requirement that the decorations have to return a different
function.  They can return the same function and just operate through side
effects on the input function.

Skip



More information about the Python-Dev mailing list