Are decorators really that different from metaclasses...

Paul Morrow pm_mon at yahoo.com
Thu Aug 26 19:51:22 EDT 2004


Jess Austin wrote:
> Paul Morrow <pm_mon at yahoo.com> wrote in message news:<mailman.2423.1093527121.5135.python-list at python.org>...
> 
>>Currently, you can change a doc string outside of a function, by 
>>modifying the function's __doc__ attribute
> 
> 
> [snip]
> 
> 
>>IMO, to change it inside of a function def should be (but isn't) as easy 
>>as...
>>
>>   >>> def foo():
>>   ...     """ I am foo """
>>   ...     __doc__ = __doc__ + 'indeed'
> 
> 
> I'm not trying to be mean, but why not use a class for this?

This is a contrived example; we probably wouldn't do this in practice. 
But some of us would like to do something like this

    def foo():
       __features__ = synchronized, memoized

...so that the function foo get's some special abilities from the 
'decorators' (or whatever we end up calling them) assigned to the 
__features__ attribute.

But before anyone is really going to accept that way of specifying a 
function's decorators, they need to be convinced that it's ok to think 
of __features__ as an attribute of the function foo (i.e. foo metadata), 
rather than a local variable.



> Paul: I admit I'm a bit confused by your
> wanting a function to have access to its metadata, because I could
> have sworn that earlier in the thread you defined metadata as data
> about an object that that object would never use itself.  I could be
> thinking of someone else though...
> 

Nope, that was me alright.  I don't want a function to have access to 
it's metadata.  Nothing's changed about that.  I want to be able to 
specify a function's metadata inside the function def, where it seems to 
most appropriately belong.

Others seem to want to specify a function's metadata outside of the 
function def, which just doesn't seem pythonic (IMO).








More information about the Python-list mailing list