[Python-Dev] More concerns about decorators

Bob Ippolito bob at redivi.com
Mon Aug 16 06:52:43 CEST 2004


On Aug 16, 2004, at 12:41 AM, Roman Suzi wrote:

>
> After playing with decorators alittle I found that @-syntax is nearly 
> optimal
> especially that it comes before def, but there are other things to 
> keep in
> mind.
>
> 1. Decorators must transfer __doc__-strings and probably even
> add information about functions
>
> 2. As now functions could have arbitrary attributes, some
> mechanism must be in place to ensure this information is not lost.
> If it is purely up to the decorator to decide, we will end up with
> undocumented functions...

def carryover(new, orig):
     if orig.__doc__:
         new.__doc__ = orig.__doc__
     if orig.__dict__:
         d = dict(orig.__dict__)
         d.update(new.__dict__)
         new.__dict__ = d
     return new

A built-in function like this would make it easy to preserve such 
information...

> Is it possible to change function inplace? Is it even an option?

Not sure what you mean.  Functions have a __doc__ slot and a __dict__ 
slot that are read/write.  __name__ is read-only.  I have no idea if 
that answers your question or not (there are other slots, that is not a 
definitive list, but should cover all of the relevant ones).

-bob


More information about the Python-Dev mailing list