PEP: Adding decorators for everything

tharaka tharakawick at gmail.com
Tue Oct 18 01:16:52 EDT 2005


Hi Guys,

This is an idea for a PEP.

How would you guys feel about adding decorator support for
"everything"? Currently, only functions and method are supported.

For example:

@GuardedClass
class Foo:
    @Transient
    a = 'a transient field, ignored when serializing'

    @Const
    PI = 22.0 / 7

    @TypeSafe(int)
    count = 10

    ...



instead of:
class Foo:
    a = Transient('a transient field, ignored when serializing')

    PI = Const(22.0 / 7)

    count = TypeSafe(int)(10)

    ...
Foo = GuardedClass(Foo)


I mean, this would pave the way for a declarative style of programming
(in a more intuitive way).

It would also be better if multiple decorators could be written on the
same line. E.g.:
@A @B(x, y) @C
def foo(): ...

instead of
@A
@B(x, y)
@C
def foo(): ...

(The function definition should start on the next line though).


Suggestions, Comments, flames, anybody?


Cheers!




More information about the Python-list mailing list