__autoinit__ (Was: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code)
Bengt Richter
bokr at oz.net
Mon Jul 11 12:01:23 EDT 2005
On Mon, 11 Jul 2005 15:37:35 +0200, Reinhold Birkenfeld <reinhold-birkenfeld-nospam at wolke7.net> wrote:
>Dan Sommers wrote:
>
>> Without thinking it all the way through, I suppose these:
>>
>> def method_1(self, *self.l):
>> pass
>> def method_2(self, **self.d):
>> pass
>>
>> could act as if they were these:
>>
>> def method_1(self, *args):
>> self.l = args
>> del args
>> def method_2(self, **kw):
>> self.d = kw
>> del kw
>
>I still think it's too specialized. What would, hypothetically, this do?
>
>class Bar: pass
>
>class Foo:
> x = Bar()
> def method_1(self, x.y):
> pass
>
>It's hard to explain that you can autoassign self.y but not x.y.
>
No, that limitation wouldn't exist, so you wouldn't have to explain it ;-)
I.e., the above would act like
class Foo:
x = Bar()
def method_1(self, _anonymous_arg_1):
x.y = _anonymous_arg_1
and would do whatever it would do now (probably look for a global x or a closure cell x, but
it wouldn't find the class variable in a normal method call)
Regards,
Bengt Richter
More information about the Python-list
mailing list