<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, May 16, 2017 at 8:14 PM, Juancarlo Añez <span dir="ltr"><<a href="mailto:apalala@gmail.com" target="_blank">apalala@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail-m_4302201392653162647markdown-here-wrapper"><span class="gmail-"></span>What I like about attrs is:
<ul style="margin:1.2em 0px;padding-left:2em">
<li style="margin:0.5em 0px">The class level declaration of instance attributes</li>
<li style="margin:0.5em 0px">That the reasonable <b>init</b>, <b>repr</b>, and <b>eq</b> are generated</li></ul></div></div></blockquote><div>OK, the former should be doable using PEP 526 (the type is stored in __annotations__ and the default in the class dict given to the metaclass), while the latter should be doable using a standard metaclass -- assuming we can agree on what the "reasonable" __init__, __repr__ and __eq__ should do.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail-m_4302201392653162647markdown-here-wrapper"><ul style="margin:1.2em 0px;padding-left:2em">
</ul>
<p style="margin:1.2em 0px">I don’t like the excessive wordiness in attrs,</p></div></div></blockquote><div>Really? @attr.s is wordy? :-) I think it's deadly cute. (The only library I've ever seen that did something worse was "monocle" which used @_o.)<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail-m_4302201392653162647markdown-here-wrapper"><p style="margin:1.2em 0px">and I don’t need “the kitchen sink” be available to have instance attributes declared at the class level. A solution based on the <code style="font-size:0.85em;font-family:consolas,inconsolata,courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border-width:1px;border-style:solid;border-color:rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">typing</code> module would be much better.</p></div></div></blockquote><div>That's what I am hoping, yes. <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail-m_4302201392653162647markdown-here-wrapper">
<p style="margin:1.2em 0px">Basically, Python is lacking a way to declare instance fields with default values away of the initializer. Several of the mainstream OO languages (Java, Swift, Go) provide for that.</p></div></div></blockquote><div>Hm, there are some issues here of course -- while it's simple to set the default to e.g. 0, (1, 2, 3) or '<string>', it's not so easy to set a default to [] or {'foo': 'bar'} unless you just state "do whatever copy.copy() does".<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail-m_4302201392653162647markdown-here-wrapper">
<p style="margin:1.2em 0px">I haven’t thought much about this, except about if there’s indeed a need (and there is), but I can’t know if the solution if through decorators, or inheritance.<br></p></div></div></blockquote></div>I suppose we could do it using either a class decorator or a metaclass -- we'll have to compare the pros and cons and specific use cases to choose. (Example: <a href="https://github.com/python/typing/issues/427">https://github.com/python/typing/issues/427</a>.)<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/%7Eguido" target="_blank">python.org/~guido</a>)</div>
</div></div>