Guido has said that he is open to considering *one* alternative
decorator syntax. At the moment, (Phillip Eby's suggestion) J4
<URL: http://www.python.org/moin/PythonDecorators > (section 5.21 J4)
looks very good to me -- and it is the only alternative without negatives.
def func(arg1, arg2)
@version("Added in 2.4")
@returns(None)
as:
"""Docstrin g could be here, or in decorator part above"""
# body goes here
(Note the lack of colon on the func line; adding it would be more
consistent and not hurt readability.)
def func(arg1, arg2):
@version("Added in 2.4")
@returns(None)
as:
"""Docstrin g could be here, or in decorator part above"""
# body goes here
While I think this is the best solution so far, I realize that others
have often disagreed with me on this issue -- so I would appreciate
some feedback, particularly from those who don't like the J4 syntax.
Disclosure: I like decorators on their own, but they are enough of
a special case that I worry about cluttering up the language as a
whole. J4 seems the best compromise to me, but I could also make
peace with Guido's current @proposal.
-jJ 17 1708 Ji********@yaho o.com (Jim Jewett) writes: <URL: http://www.python.org/moin/PythonDecorators > (section 5.21 J4)
looks very good to me -- and it is the only alternative without negatives.
def func(arg1, arg2) @version("Added in 2.4") @returns(None) as: """Docstrin g could be here, or in decorator part above""" # body goes here
What was wrong with using . or - instead of @ ? Given that this is
new syntax, just about any character could work. Or what about no
special punctuation at all? Using @ makes me cringe somewhat.
Also, why the need for the "as" keyword? What happens if it's just
eliminated? I.e.:
def func(arg1, arg2)
@version("Added in 2.4")
@returns(None):
"""Docstrin g could be here, or in decorator part above"""
# body goes here
Paul Rubin <http://ph****@nospam.i nvalid> wrote: Also, why the need for the "as" keyword? What happens if it's just eliminated? I.e.:
def func(arg1, arg2) @version("Added in 2.4") @returns(None):
"""Docstrin g could be here, or in decorator part above""" # body goes here
It's really nice to have an outdented marker for when the actual
function body begins.
martin
Martin DeMello <ma***********@ yahoo.com> writes: def func(arg1, arg2) @version("Added in 2.4") @returns(None):
"""Docstrin g could be here, or in decorator part above""" # body goes here
It's really nice to have an outdented marker for when the actual function body begins.
I don't really see why, but the decorators don't have to be indented:
def func(arg1, arg2)
-version("Added in 2.4")
-returns(None):
"""Docstrin g could be here, or in decorator part above"""
# body goes here
I guess that's ugly though.
If docstring can be a special case of a triple quoted
string, I don't see why decorators couldn't be a special
case of a dictionary.
def func(arg1, arg2):
{'version': 'Added in 2.4',
'returns': None,
'docstring': 'Docstring could be here, or in decorator part above'}
"""Docstrin g could be here, or in decorator part above"""
or perhaps:
def func(arg1, arg2):
#
# Similiar to class __dict__
#
__decorators__= __{'version': 'Added in 2.4',
'returns': None,
'docstring': 'Docstring could be here, or in decorator
part above'}
"""Docstrin g could be here, or in decorator part above"""
I'm sure there is a reason, but it would seem to make
"Python"-sense to me. It would then be very extensible
for the meta-data that everyone seems to also want decorators
to support.
"Jim Jewett" <Ji********@yah oo.com> wrote in message
news:ca******** *************** ***@posting.goo gle.com... Guido has said that he is open to considering *one* alternative decorator syntax. At the moment, (Phillip Eby's suggestion) J4
<URL: http://www.python.org/moin/PythonDecorators > (section 5.21 J4)
looks very good to me -- and it is the only alternative without negatives.
def func(arg1, arg2) @version("Added in 2.4") @returns(None) as: """Docstrin g could be here, or in decorator part above""" # body goes here
(Note the lack of colon on the func line; adding it would be more consistent and not hurt readability.)
def func(arg1, arg2): @version("Added in 2.4") @returns(None) as: """Docstrin g could be here, or in decorator part above""" # body goes here
While I think this is the best solution so far, I realize that others have often disagreed with me on this issue -- so I would appreciate some feedback, particularly from those who don't like the J4 syntax.
Disclosure: I like decorators on their own, but they are enough of a special case that I worry about cluttering up the language as a whole. J4 seems the best compromise to me, but I could also make peace with Guido's current @proposal.
-jJ
"Larry Bates" <lb****@swamiso ft.com> writes: If docstring can be a special case of a triple quoted string, I don't see why decorators couldn't be a special case of a dictionary.
I like that. Please add it to the wiki.
Larry Bates wrote: If docstring can be a special case of a triple quoted string, I don't see why decorators couldn't be a special case of a dictionary. [...]
I'm sure there is a reason, but it would seem to make "Python"-sense to me. It would then be very extensible for the meta-data that everyone seems to also want decorators to support.
The biggest reason that I'm aware of is that GvR has declared that he
doesn't think decorators belong inside a function def, and has even been
quoted as having professed a regret for having put docstrings there.
(Personally, I think that having all of this stuff immediately inside
the function def makes great sense, but I'm not a world-famous language
designer, so what do I know? ;) )
In fact, the biggest problem that I can see with the J4 syntax is its
close similarity to all of the decorator-inside-def variations. Since
GvR has spoken strongly against putting decorators in that location, it
seems to me to be a waste of effort to advocate for that. Now, perhaps
having that outdented keyword to indicate the function-body start
*might* make a difference with him... but I would expect that it won't.
Jeff Shannon
Technician/Programmer
Credit International
On Fri, 20 Aug 2004 17:59:18 -0500, rumours say that "Larry Bates"
<lb****@swamiso ft.com> might have written: If docstring can be a special case of a triple quoted string, I don't see why decorators couldn't be a special case of a dictionary.
Why type decorators as a dictionary if you are not going to produce a
dictionary? Cause if you produce a dictionary, the order of the
decorators is no longer guaranteed.
--
TZOTZIOY, I speak England very best,
"Tssss!" --Brad Pitt as Achilles in unprecedented Ancient Greek
Christos "TZOTZIOY" Georgiou <tz**@sil-tec.gr> writes: Why type decorators as a dictionary if you are not going to produce a dictionary? Cause if you produce a dictionary, the order of the decorators is no longer guaranteed.
Does that matter?
Larry Bates wrote: If docstring can be a special case of a triple quoted string, I don't see why decorators couldn't be a special case of a dictionary.
def func(arg1, arg2): {'version': 'Added in 2.4', 'returns': None, 'docstring': 'Docstring could be here, or in decorator part above'} """Docstrin g could be here, or in decorator part above"""
or perhaps:
def func(arg1, arg2): # # Similiar to class __dict__ # __decorators__= __{'version': 'Added in 2.4', 'returns': None, 'docstring': 'Docstring could be here, or in decorator part above'} """Docstrin g could be here, or in decorator part above"""
I'm sure there is a reason, but it would seem to make "Python"-sense to me. It would then be very extensible for the meta-data that everyone seems to also want decorators to support.
Maybe because decorators aren't just function properties but functions that
transform the function they receive in parameter. Therefore, that proposal
doesn't solve the problem at hand. It's a bad solution.
How would you do the staticmethod ou the memoize with that proposal ? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ville Vainio |
last post by:
It might just be that @decorator might not be all that bad. When you
look at code that uses it it's not that ugly after all.
A lot of the furor about this is probably because it happened so
quicly. The situation might have been different if we had seen a
pronouncement a week before, in the vein of "I have chosen this syntax
- it will go in to the next alpha".
My chief worry was throwing away one of the few unused ascii symbols,
but if...
|
by: John Marshall |
last post by:
How about the following, which I am almost positive
has not been suggested:
-----
class Klass:
def __init__(self, name):
self.name = name
deco meth0:
staticmethod
def meth0(x):
|
by: Ron_Adam |
last post by:
I was having some difficulty figuring out just what was going on with
decorators. So after a considerable amount of experimenting I was
able to take one apart in a way. It required me to take a closer look
at function def's and call's, which is something I tend to take for
granted.
I'm not sure this is 100%, or if there are other ways to view it, but
it seems to make sense when viewed this way.
Is there a way to do this same thing...
|
by: Ron_Adam |
last post by:
Hi, Thanks again for all the helping me understand the details of
decorators.
I put together a class to create decorators that could make them a lot
easier to use.
It still has a few glitches in it that needs to be addressed.
(1) The test for the 'function' object needs to not test for a string
but an object type instead.
|
by: Ron_Adam |
last post by:
Ok... it's works! :)
So what do you think?
Look at the last stacked example, it process the preprocess's first in
forward order, then does the postprocess's in reverse order. Which
might be usefull. Interesting in any case.
Making decorators with this class is a snap!
| |
by: Michele Simionato |
last post by:
could ildg wrote:
> I think decorator is a function which return a function, is this
right?
> e.g. The decorator below if from
http://www.python.org/peps/pep-0318.html#id1.
>
> def accepts(*types):
> def check_accepts(f):
> assert len(types) == f.func_code.co_argcount
|
by: Doug |
last post by:
I am looking at using the decorator pattern to create a rudimentary
stored proc generator but am unsure about something. For each class
that identifies a part of the stored proc, what if I want to add a
value dynamically. I'm including some code to show what I mean. This
is real basic on what I want to do:
using System;
namespace ClassLibrary1
{
|
by: thomas.karolski |
last post by:
Hi,
I would like to create a Decorator metaclass, which automatically
turns a class which inherits from the "Decorator" type into a
decorator.
A decorator in this case, is simply a class which has all of its
decorator implementation inside a decorator() method. Every other
attribute access is being proxied to decorator().getParent().
Here's my attempt:
-------------------------------------------------------
|
by: Chris Forone |
last post by:
hello group,
is there a possibility to implement the decorator-pattern without
new/delete (nor smartpt)?
if not, how to ensure correct deletion of the objects?
thanks & hand, chris
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |