A decorator syntax not yet mentioned (I think!)

paolo veronelli paolo_veronelli at yahoo.it
Thu Aug 12 12:31:57 EDT 2004


On Wed, 11 Aug 2004 11:40:32 -0400, Peter Hansen <peter at engcorp.com> wrote:

> John Marshall wrote:
>> 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):
>>         return x
>>
>> -----
>> 1) The decorators clearly apply to a specific method/function,
>>    therefore there is no need to do any stack pushing in memory
>>    until the method/function definition is done.
>
> Problems with that: duplication (since you now have the name
> of the function in two places) and readability (it's harder to
> see the "def" because the name you picked is too close to it
> in length and appearance).
>
> On the other hand, there's no need to have the function name
> there (was anyone complaining about "stack pushing"?), so
> maybe just using "decorate" would be okay, or a different
> keyword:
>
> class Klass:
>      # init set
>
>      decorate:
>          staticmethod
>      def meth0(x):
>          return x
I think 'mutate' is better then 'decorate', and anyway I like to see what 
is mutated and the possibility to explicitate it make possible
to move decorations from this position ,I put them where I like (at least 
if I have to call them decorations) even in another file...

so

class Klass:
	def meth0(x):
		return x
	mutate meth0:
		staticmethod

mutate Klass.meth0:
	debugged


reads good to me.


					Paolino

	

-- 
....lotta dura  per la verdura




More information about the Python-list mailing list