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! 1 1581
> @GuardedClass class Foo:
The functionality can be done using a meta-class, in a similarily
declarative way.
@Transient a = 'a transient field, ignored when serializing'
@Const PI = 22.0 / 7
@TypeSafe(int) count = 10
These are tricky, as the implicitly change the nature of the values -
they become properties. And the decorator protocol has to change, as the
passed value is obviously not a callable, but a random value. So in the
end, you could simply do something like this:
@Const(3.24)
def PI(self):
pass
with Const basically ignoring its callable-argument and simply returning
a get-only-property. I have to admit that I was tempted to use such a
thingy just the other day. But it is not exactly nice, and using
PI = Const(3.14) as you suggested is even more pleasing.
Additionally, the first @Transient-decorator can't be done that way, as
the decorator protocol doesn't know about the _name_ a thing is bound to
later. And you'd need that to actually set up e.g. __getstate__ operate
properly.
And it doesn't mkae much sense anyway, as "a" is a class variable, not a
instance variable.
So - I'm not very much in favour of these enhancements.
It would also be better if multiple decorators could be written on the same line. E.g.: @A @B(x, y) @C def foo(): ...
That one I like.
Diez This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Marco Bubke |
last post by:
Hi
I have read some mail on the dev mailing list about PEP 318 and find the new
Syntax really ugly.
def foo(x, y): pass
I call this foo(1, 2), this isn't really intuitive to me!
Also I...
|
by: Edward K. Ream |
last post by:
Hello all,
First of all, my present state of mind re pep 318 is one of sheepish
confusion. I suspect pep 318 will not affect Leo significantly, but I am
most surprised that an apparently...
|
by: Hallvard B Furuseth |
last post by:
....and opinions:-)
I don't understand some of the arguments in pep-318 (version 1.19),
or what the current syntax has to do with some of the design goals
mentioned there. Could someone...
|
by: Arien Malec |
last post by:
I've been following the decorator debate with some interest, and it's taken
me a reasonably long time to understand what is meant by a decorator. One
of the issues is that the Decorator pattern is...
|
by: Anthony Baxter |
last post by:
To go along with the 2.4a3 release, here's an updated version of
the decorator PEP. It describes the state of decorators as they
are in 2.4a3.
PEP: 318
Title: Decorators for Functions and...
|
by: Brian Sabbey |
last post by:
Here is a first draft of a PEP for thunks. Please let me know what you
think. If there is a positive response, I will create a real PEP.
I made a patch that implements thunks as described here....
|
by: Nicolas Fleury |
last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment
welcomed (even about English mistakes).
PEP: XXX
Title: Specialization Syntax
Version: $Revision: 1.10 $...
|
by: Tony Lownds |
last post by:
(Note: PEPs in the 3xxx number range are intended for Python 3000)
PEP: 3107
Title: Function Annotations
Version: $Revision: 53169 $
Last-Modified: $Date: 2006-12-27 20:59:16 -0800 (Wed, 27 Dec...
|
by: Russ |
last post by:
I just stumbled onto PEP 316: Programming by Contract for Python
(http://www.python.org/dev/peps/pep-0316/). This would be a great
addition to Python, but I see that it was submitted way back in...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |