[Python-ideas] setting function properties with a decorator syntax

nbv4 nbvfour at gmail.com
Thu Mar 18 07:49:39 CET 2010


Decorators are great, they make this:

def some_func(*args, **kwargs):
    return "sup"
some_func = decorator(some_func)

into this:

@decorator
def some_func(*args, **kwargs):
    return "sup"

which makes the code look more structured. The line at the bottom
looks more like it 'belongs' to the function when it's at the top of
the def block, as opposed to the bottom.

But when it comes to function properties, it'd be nice if that same
pattern was availiable:

def some_func(*args, **kwargs):
    return "sup"
some_func.printable = True

becomes:

@printable=True
def some_func(*args, **kwargs):
    return "sup"

Any thoughts?



More information about the Python-ideas mailing list