En Sun, 27 Jan 2008 23:51:28 -0200, Arnaud Delobelle
<[EMAIL PROTECTED]> escribió:
> Nice! I've got a slight variation without magic argument names:
>
> class Test(object):
> @autoassign('foo', 'bar')
> def __init__(self, baz):
> print 'baz =', baz
>
En Mon, 28 Jan 2008 00:02:51 -0200, André <[EMAIL PROTECTED]>
escribió:
> Here's a version that
> 1. does not require new syntax
> 2. does not *necessarily* override the "_" prefix convention
> 3. follows the "Explicit is better than implicit" convention when
> being called.
>
> class Test(object):
> @autoassign('self_')
> def __init__(self, self_foo, self_bar, baz):
> print 'baz =', baz
I would like a signature-preserving version. The help system, pydoc, the
inspect module, and likely any other introspection tool see those
decorated methods with a different signature than the original one.
Even if one writes a signature-preserving decorator (maybe along the lines
of this article by M. Simionato [1]), names like "self_foo", "self_bar"
are ugly. Furthermore, argument names are part of the public interfase,
but here they're tied to the implementation: what if later I want to keep
a reference to baz? I must change the argument name to self_baz, breaking
all users of the code.
[1] http://www.phyast.pitt.edu/~micheles/python/documentation.html
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list