<div dir="ltr">My only motivation for this idea is so that I can forget about namedtuple.  Thinking about it again today, I withdraw my suggestion until I one day see a need for it.<br><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 10, 2018 at 10:14 PM Eric V. Smith <<a href="mailto:eric@trueblade.com">eric@trueblade.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 8/10/2018 7:01 PM, Neil Girdhar wrote:<br>
> It would be nice if dataclasses <br>
> (<a href="https://docs.python.org/3/library/dataclasses.html#dataclasses.dataclass" rel="noreferrer" target="_blank">https://docs.python.org/3/library/dataclasses.html#dataclasses.dataclass</a>) <br>
> had an option to make them a sequence.  This would make<br>
> <br>
> dataclass(frozen=True, order=True, sequence=True)<br>
> <br>
> an optionally-typed version of namedtuple.  It would almost totally <br>
> supplant it except that namedtuples have a smaller memory footprint.<br>
<br>
Note that type.NamedTuple already gives you typed namedtuples. <br>
Admittedly the feature set is different from dataclasses, though.<br>
<br>
> sequence would simply inherit from collections.abc.Sequence and <br>
> implement the two methods __len__ and __getitme__.<br>
<br>
Unless I'm misunderstanding you, this falls in to the same problem as <br>
setting __slots__: you need to return a new class, in this case since <br>
you can't add inheritance after the fact. I don't think <br>
__isinstancecheck__ helps you here, but maybe I'm missing something (I'm <br>
not a big user of inheritance or ABCs).<br>
<br>
Not that returning a new class is impossible, it's just that I didn't <br>
want to do it in the first go-round with dataclasses.<br></blockquote><div><br></div><div>That's a fair point.  I'm sure you know that your decorator could always return a new class that inherits from both Sequence and the original class.  As a user of dataclass, I never assumed that it wouldn't do this.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
For slots, I have a sample @add_slots() at <br>
<a href="https://github.com/ericvsmith/dataclasses/blob/master/dataclass_tools.py" rel="noreferrer" target="_blank">https://github.com/ericvsmith/dataclasses/blob/master/dataclass_tools.py</a>. <br>
Maybe we could do something similar with @add_sequence() and test it <br>
out? It would have to be a little more sophisticated than @add_slots(), <br>
since it would need to iterate over __dataclass_fields__, etc.<br>
<br>
I'm on vacation next week, maybe I'll play around with this.<br></blockquote><div><br></div><div>Cool, have a great vacation. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Eric<br>
_______________________________________________<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/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
<br>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.<br>
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/python-ideas/8C9iVJsba5A/unsubscribe" rel="noreferrer" target="_blank">https://groups.google.com/d/topic/python-ideas/8C9iVJsba5A/unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href="mailto:python-ideas%2Bunsubscribe@googlegroups.com" target="_blank">python-ideas+unsubscribe@googlegroups.com</a>.<br>
For more options, visit <a href="https://groups.google.com/d/optout" rel="noreferrer" target="_blank">https://groups.google.com/d/optout</a>.<br>
</blockquote></div></div>