py3k feature proposal: field auto-assignment in constructors

Tim Chase python.list at tim.thechases.com
Mon Jan 28 23:27:06 CET 2008


> I've modified my little decorator (see Test1, Test2, Test3 for
> usage).  I'll post it later on the cookbook if there seems to be no
> bugs and noone raises valid point against it:)

One other area that was mentioned obliquely:  preservation of 
docstrings (and other function attributes)

I couldn't tell from your code if it attempted to publish 
function attributes:

   class Foo(object):
     @autoassign
     def __init__(self, alpha, beta, gamma):
       "Do something"
       pass

   f = Foo(3,1,4)
   print f.__init__.__doc__

I can't say I use doc-strings in __init__ methods often, and I 
suspect the autoassign is only helpful most of the time for 
__init__ methods, but if it's slated for the cookbook, 
completeness would be worth aspiring to.

-tkc






More information about the Python-list mailing list