<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace"><span style="font-family:arial,sans-serif">On Thu, Jul 20, 2017 at 9:58 AM, Nathaniel Smith </span><span dir="ltr" style="font-family:arial,sans-serif"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span><span style="font-family:arial,sans-serif"> wrote:</span><br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
</span>The problem with namedtuple's semantics are that they're perfect for<br>
its original use case (replacing legacy tuple returns without breaking<br>
backwards compatibility), but turn out to be sub-optimal for pretty<br>
much anything else, which is one of the motivations behind stuff like<br>
attrs and Eric's dataclasses PEP:<br>
    <a href="https://github.com/ericvsmith/dataclasses/blob/61bc9354621694a93b215e79a7187ddd82000256/pep-xxxx.rst#why-not-namedtuple" rel="noreferrer" target="_blank">https://github.com/ericvsmith/<wbr>dataclasses/blob/<wbr>61bc9354621694a93b215e79a7187d<wbr>dd82000256/pep-xxxx.rst#why-<wbr>not-namedtuple</a><br>
<br></blockquote><div><br></div><div><div class="gmail_default" style="font-family:monospace,monospace">​Well put! I agree that adding attribute names to elements in a tuple (e.g. return values) in a backwards-compatible way is where namedtuple is great. </div></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
>From the above it sounds like this ntuple literal idea would be giving<br>
us a third independent way to solve this niche use case (ntuple,<br>
namedtuple, structseq). This seems like two too many? Especially given<br>
that namedtuple is already arguably *too* convenient, in the sense<br>
that it's become an attractive nuisance that gets used in places where<br>
it isn't really appropriate.<br>
<br></blockquote><div><br></div><div><div class="gmail_default" style="font-family:monospace,monospace">​I do think it makes sense to add a convenient way to upgrade a function to return named values. Is there any reason why that couldn't replace structseq completely? </div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">These anonymous namedtuple classes could also be made fast to create (and more importantly, cached).</div></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Also, what's the advantage of (x=1, y=2) over ntuple(x=1, y=2)? I.e.,<br>
why does this need to be syntax instead of a library?<br><span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br></div><div><div class="gmail_default" style="font-family:monospace,monospace">Indeed, we might need the syntax (x=1, y=2) later for something different. However, I hope we can forget about 'ntuple', because it suggests a tuple of n elements.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">Maybe something like</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">    return tuple.named(x=foo, y=bar) </div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">which is backwards compatible with </div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">    return foo, bar<br></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div></div><div><div class="gmail_default" style="font-family:monospace,monospace">​-- Koos</div><div class="gmail_default" style="font-family:monospace,monospace">​</div><br></div></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">+ Koos Zevenhoven + <a href="http://twitter.com/k7hoven" target="_blank">http://twitter.com/k7hoven</a> +</div>
</div></div>