<br><br><div class="gmail_quote">On Wed, Oct 21, 2009 at 10:19 AM, Arnaud Delobelle <span dir="ltr"><<a href="mailto:arnodel@googlemail.com">arnodel@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im"><br>
On 21 Oct 2009, at 16:56, Bruce Leban wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Reading your code I have no idea what these lines mean<br>
<br>
<br>
    autoassign(function) -> method<br>
    autoassign(*argnames) -> decorator<br>
    autoassign(exclude=argnames) -> decorator<br>
<br>
Reading the code, what I *think* this does<br>
<br>
"""Decorator that assigns all function parameters to attributes of the class.<br>
You can specify a list of parameters to process or a list of parameters to exclude.<br>
Given another function, does something complicated that belongs in another recipe.<br>
"""<br>
<br>
</blockquote>
<br></div>
I don't understand that last sentence.<div class="im"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm only half-joking. It's not obvious what that function parameter does and you don't give any examples of it's use.<br>
</blockquote>
<br></div>
I give two examples.  One in the docstring (first example), the other one in the tests below the definition of the decorator (class Test2).<div class="im"><br></div></blockquote><div><font class="Apple-style-span" color="#990000">I meant there are no examples of using autoassign with a function. </font></div>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Just reading the code with unrelated assignments grouped together was confusing enough -- definitely not my coding style.<br>
</blockquote>
<br></div>
Sorry I confused you :)<div class="im"><br></div></blockquote><div><font class="Apple-style-span" color="#990000">Write once, read many times. :-) Especially for recipes, clear > concise.</font></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
More importantly not at all clear why this is better than<br>
<br>
    self.__dict__.update(locals())<br>
<br>
</blockquote>
<br></div>
It's not a very nice construct. And it doesn't work as is:<br>
<br>
>>> class Foo(object):<div class="im"><br>
...     def __init__(self, a, b, c):<br>
...             self.__dict__.update(locals())<br>
...<br></div>
>>> foo=Foo(1, 2, 3)<br>
>>> foo.self<br>
<__main__.Foo object at 0x10048c790><br>
<br>
Probably not what was intended...  So you can write something like:<br>
<br>
>>> class Foo(object):<div class="im"><br>
...     def __init__(self, a, b, c):<br></div>
...             self.__dict__.update(((n, v) for (n, v) in locals().items() if n!='self'))<br>
...<br>
>>> foo=Foo(1, 2, 3)<br>
>>> foo.self<br>
Traceback (most recent call last):<br>
  File "<stdin>", line 1, in <module><br>
AttributeError: 'Foo' object has no attribute 'self'<br>
<br>
But that reads even worse.<br>
<br>
Also, it's a bit more versatile.<br>
<br></blockquote><div><br></div><div><font class="Apple-style-span" color="#990000">I don't get the function case. And I have no idea what you mean by -> decorator or -> method. I do understand how the other two cases work but those first three lines of the doc don't tell me anything.</font></div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
-- <br><font color="#888888">
Arnaud<br>
<br>
</font></blockquote></div><br>