PEP: Adding decorators for everything
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!
--
http://mail.python.org/mailman/listinfo/python-list
Re: Fire event when variable is Set/Get
You are in luck because Python has "Properties" just like .NET. For details lookup the documentation of the built-in function property(). I'll just paste it here: property( [fget[, fset[, fdel[, doc) Return a property attribute for new-style classes (classes that derive from object). fget is a function for getting an attribute value, likewise fset is a function for setting, and fdel a function for del'ing, an attribute. Typical use is to define a managed attribute x: class C(object): def getx(self): return self.__x def setx(self, value): self.__x = value def delx(self): del self.__x x = property(getx, setx, delx, "I'm the 'x' property.") ... now u can use x like any variable and, python will get & set it through the appropriate methods. Hope this answers your question. -- http://mail.python.org/mailman/listinfo/python-list
