473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Are decorators really that different from metaclasses...

....that they warrant an entirely new syntax? It seems that they are
very similar in a very significant way --- they alter the default
behavior of something. IMO, it's not a stretch to say that they
'parallel' metaclasses; that they are to functions/methods what
metaclasses are to classes. So why don't they share a similar syntax?

class Foo:
""" This is the docstring for class Foo. """
__metaclass__ = M
# body of class goes here
def baz():
""" This is the docstring for function baz. """
__features__ = synchronized, memoized
# body of function goes here.
I personally find the above baz function aesthetically appealing. Does
anyone else feel this way? For contrast, below is the same function
written in the proposed A1 and J2[*] syntaxes (respectively).
@synchronized
@memoized
@doc(""" This is the docstring for function baz. """)
def baz():
# body of function goes here.
decorate:
""" This is the docstring for function baz. """
synchronized
memoized
def baz():
# body of function goes here.
* if J2 is accepted, the name 'decorate' may be replaced with some other
keyword, but I believe that the structure of the syntax would stay the same.

Paul

Jul 18 '05 #1
2 1532
Paul Morrow wrote:
...that they warrant an entirely new syntax? It seems that they are
very similar in a very significant way --- they alter the default
behavior of something. IMO, it's not a stretch to say that they
'parallel' metaclasses; that they are to functions/methods what
metaclasses are to classes. So why don't they share a similar syntax?

class Foo:
""" This is the docstring for class Foo. """
__metaclass__ = M
# body of class goes here
def baz():
""" This is the docstring for function baz. """
__features__ = synchronized, memoized
# body of function goes here.
I personally find the above baz function aesthetically appealing. Does
anyone else feel this way? For contrast, below is the same function
written in the proposed A1 and J2[*] syntaxes (respectively).
@synchronized
@memoized
@doc(""" This is the docstring for function baz. """)
def baz():
# body of function goes here.
decorate:
""" This is the docstring for function baz. """
synchronized
memoized
def baz():
# body of function goes here.
* if J2 is accepted, the name 'decorate' may be replaced with some other
keyword, but I believe that the structure of the syntax would stay the
same.

Paul

Robert Brewer provided an excellent review of the options now on the
table, but he didn't explore the question of whether there is an
existing structure on which these new operations, which are mainly
transformations, can be based.
http://www.aminus.org/rbre/python/pydec.html

There seems to be an artificial deadline which is motivating the push to
implement something, even though the effect can already be achieved, in
a less desirable way, by placing the transformer aka decorator after the
function body.

I like the general thrust of this proposal - let's use existing
structures if this is possible. The idea of putting the modifier
__features__ after the thing named and given a signature also makes sense.

Colin W.

Jul 18 '05 #2
You are asking the same question I asked in a separate
posting to c.l.p (but apparently more clearly).

I thought about using:

class Foo:
""" This is the docstring for class Foo. """
__decorators__ = {'metaclass': 'M'}
# body of class goes here
def baz():
""" This is the docstring for function baz. """
__decorators__= {'features': ['synchronized', 'memoized'],
'docstring':'This is the docstring for function baz. '}
# body of function goes here.

This seems extendable (e.g. you can add keys to __decorators__
dictionary without disturbing existing keys) and "sort of"
parallels __dict__ which everyone understands.

Some of these discussions are so far over my head that I thought
my idea didn't somehow make any sense at all. Then I saw your post.

Thanks,
Larry Bates
Syscon, Inc.
"Paul Morrow" <pm****@yahoo.com> wrote in message
news:ma**************************************@pyth on.org...
...that they warrant an entirely new syntax? It seems that they are
very similar in a very significant way --- they alter the default
behavior of something. IMO, it's not a stretch to say that they
'parallel' metaclasses; that they are to functions/methods what
metaclasses are to classes. So why don't they share a similar syntax?

class Foo:
""" This is the docstring for class Foo. """
__metaclass__ = M
# body of class goes here
def baz():
""" This is the docstring for function baz. """
__features__ = synchronized, memoized
# body of function goes here.
I personally find the above baz function aesthetically appealing. Does
anyone else feel this way? For contrast, below is the same function
written in the proposed A1 and J2[*] syntaxes (respectively).
@synchronized
@memoized
@doc(""" This is the docstring for function baz. """)
def baz():
# body of function goes here.
decorate:
""" This is the docstring for function baz. """
synchronized
memoized
def baz():
# body of function goes here.
* if J2 is accepted, the name 'decorate' may be replaced with some other
keyword, but I believe that the structure of the syntax would stay the same.
Paul

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Sparks | last post by:
Anyway... At Europython Guido discussed with everyone the outstanding issue with decorators and there was a clear majority in favour of having them, which was good. From where I was sitting it...
17
by: daishi | last post by:
For what it's worth: As far as I know, the proposed @decorator syntax will be the first time that two logical lines of python with the same indentation will not be independent of one another....
2
by: Guido van Rossum | last post by:
Robert and Python-dev, I've read the J2 proposal up and down several times, pondered all the issues, and slept on it for a night, and I still don't like it enough to accept it. The only reason...
0
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...
9
by: Bengt Richter | last post by:
;-) We have @deco def foo(): pass as sugar (unless there's an uncaught exception in the decorator) for def foo(): pass foo = deco(foo) The binding of a class name is similar, and class...
0
by: Michael Ekstrand | last post by:
I've been googling around for a bit trying to find some mechanism for doing in Python something like Java's synchronized methods. In the decorators PEP, I see examples using a hypothetical...
13
by: vinjvinj | last post by:
I'm building an application with cherrypy and have started using decorators quite extensively. A lot of my exposed functions look like: @expose @startTransactrionAndBuildPage...
4
by: John Henry | last post by:
I must be very thick. I keep reading about what decorators are and I still don't have a good feel about it. See, for example: http://alex.dojotoolkit.org/?p=564 and: ...
0
by: Gabriel Genellina | last post by:
En Tue, 29 Jul 2008 08:45:02 -0300, Themis Bourdenas <bourdenas@gmail.com> escribi�: In a very strict sense, I'd say that all those references to "method decorators" are wrong - because...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.