<div dir="auto"><div><br><div class="gmail_extra"><br><div class="gmail_quote">2017. ápr. 25. de. 10:04 ezt írta ("Paul Moore" <<a href="mailto:p.f.moore@gmail.com">p.f.moore@gmail.com</a>>):<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="quoted-text">On 25 April 2017 at 03:53, Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br>
> On Tue, Apr 25, 2017 at 02:08:05AM +0100, Erik wrote:<br>
><br>
>> I often find myself writing __init__ methods of the form:<br>
>><br>
>> def __init__(self, foo, bar, baz, spam, ham):<br>
>>   self.foo = foo<br>
>>   self.bar = bar<br>
>>   self.baz = baz<br>
>>   self.spam = spam<br>
>>   self.ham = ham<br>
>><br>
>> This seems a little wordy and uses a lot of vertical space on the<br>
>> screen.<br>
><br>
> It does, and while both are annoying, in the grand scheme of things<br>
> they're a very minor annoyance. After all, this is typically only an<br>
> issue once per class, and not even every class, and vertical space is<br>
> quite cheap. In general, the barrier for accepting new syntax is quite<br>
> high, and "minor annoyance" generally doesn't reach it.<br>
<br>
</div>I suspect that with a suitably creative use of inspect.signature() you<br>
could write a decorator for this:<br>
<br>
@auto_attrs<br>
def __init__(self, a, b, c):<br>
    # Remaining init code, called with self.a, self.b and self.c set<br>
<br>
I don't have time to experiment right now, but will try to find time<br>
later. If nothing else, such a decorator would be a good prototype for<br>
the proposed functionality, and may well be sufficient for the likely<br>
use cases without needing a syntax change.<br>
<font color="#888888"><br>
Paul<br>
</font><div class="elided-text">______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</div></blockquote></div><br></div></div><div class="gmail_extra" dir="auto"><br></div><div class="gmail_extra" dir="auto">Hi, such a decorator would be very grateful ;-) in the standard as for example I use class parameters this way too in more than 90% of the cases.</div><div class="gmail_extra" dir="auto"><br></div><div class="gmail_extra" dir="auto">BR</div><div class="gmail_extra" dir="auto">George</div></div>