<div dir="auto"><div dir="auto">Hi Guido,</div><div dir="auto"><br></div><div dir="auto">Yes indeed, *only* invoked by __init__ .</div><div dir="auto"><br></div><div dir="auto">See my test below.</div><div dir="auto">=====</div><div dir="auto">import attr</div><div dir="auto"><br></div><div dir="auto">@attr.s</div><div dir="auto">class Foo:</div><div dir="auto">    x = attr.ib(convert=str)</div><div dir="auto"><br></div><div dir="auto">foo = Foo(42)</div><div dir="auto">print(repr(foo.x))</div><div dir="auto"># prints '42'</div><div dir="auto">foo.x = 42</div><div dir="auto">print(repr(foo.x))</div><div dir="auto"># prints 42</div><div dir="auto">======</div><div dir="auto"><br></div><div dir="auto">Not sure if this is a good design but it matches the docs.</div><div dir="auto"><br></div><div dir="auto">Stephan</div><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">Op 19 mei 2017 20:36 schreef "Guido van Rossum" <<a href="mailto:guido@python.org">guido@python.org</a>>:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">So it is only called by __init__ and not by __setattr__?<br></div><div class="elided-text"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 19, 2017 at 11:32 AM, Stephan Houben <span dir="ltr"><<a href="mailto:stephanh42@gmail.com" target="_blank">stephanh42@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Let me quote the attrs docs:<div dir="auto"><br></div><div dir="auto"><div dir="auto">""</div><div dir="auto">convert (callable) – callable() that is called by attrs-generated __init__ methods to convert attribute’s value to the desired format. It is given the passed-in value, and the returned value will be used as the new value of the attribute. The value is converted before being passed to the validator, if any.</div><div dir="auto">"""</div><div dir="auto"><br></div><div dir="auto">So the signature is essentially:</div><div dir="auto"><br></div><div dir="auto">self.myattrib = callable (myattrib)</div><div dir="auto"><br></div><div dir="auto">Stephan</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">Op 19 mei 2017 20:25 schreef "Guido van Rossum" <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>>:<div><div class="m_1389707764608867183h5"><br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">For people who don't want to click on links:<br><br><pre>1. Allow hash and equality to be based on object identity, rather than
structural identity,
   this is very important if one wants to store un-hashable objects in
the instance.
  (In my case: mostly dict's and numpy arrays).

2. Not subclassed from tuple. I have been bitten by this subclassing
when trying to set up
   singledispatch on sequences and also on my classes.

3. Easily allow to specify default values. With namedtuple this
requires overriding __new__.

4. Easily allow to specify a conversion function. For example I have
some code like below:
    note that I can store a numpy array while keeping hashability and
I can make it convert
   to a numpy array in the constructor.

 @attr.s(cmp=False, hash=False)
 class SvgTransform(SvgPicture):
     child = attr.ib()
     matrix = attr.ib(convert=numpy.asarray)<br><span style="font-family:arial,helvetica,sans-serif"><br><br></span></pre><pre><span style="font-family:arial,helvetica,sans-serif">I have one question about (4) -- how and when is the conversion function used, and what is its signature?</span><br></pre></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 19, 2017 at 5:42 AM, Eric V. Smith <span dir="ltr"><<a href="mailto:eric@trueblade.com" target="_blank">eric@trueblade.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Could you point me to this 4-point list of Stephan's? I couldn't find<br>
anything in the archive that you might be referring to.<br>
</blockquote>
<br></span>
Never mind, I found them here:<br>
<a href="https://mail.python.org/pipermail/python-ideas/2017-May/045679.html" rel="noreferrer" target="_blank">https://mail.python.org/piperm<wbr>ail/python-ideas/2017-May/0456<wbr>79.html</a><span class="m_1389707764608867183m_1317555631134458797m_-8946858680620826026HOEnZb"><font color="#888888"><br>
<br>
Eric.</font></span><div class="m_1389707764608867183m_1317555631134458797m_-8946858680620826026HOEnZb"><div class="m_1389707764608867183m_1317555631134458797m_-8946858680620826026h5"><br>
<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="m_1389707764608867183m_1317555631134458797m_-8946858680620826026gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>
<br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
<br></blockquote></div></div></div></div>
</blockquote></div><br><br clear="all"><br>-- <br><div class="m_1389707764608867183gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>
</div></blockquote></div><br></div></div>