
I use dataclass (with frozen=True) instead of NamedTuple - and I can do mixins. https://docs.python.org/3/library/dataclasses.html

Ben Avrahami <avrahami.ben@gmail.com> wrote 9 Feb 2021, 03:30:
That's the current alternative, but namedtuples (unlike dataclasses) are slotted, which makes them more space-efficient and (slightly) faster.
When I use @dataclass(frozen=True), I manually add a __slots__ attribute. I presume this makes the resulting objects similar in size to NamedTuples, but I haven't done any measurements (and not sure how to measure this anyway). I wonder: is it possible for @dataclass to have an option slots=True? And perhaps frozen=True should imply slots=True (would this cause any backwards compatibility problems?).

https://bugs.python.org/issue42269 Although I haven't done much about it. The problem is that it needs to return a new class, not just inject methods into the existing class you defined. Eric On 2/10/2021 11:13 AM, Peter Ludemann wrote:

Ben Avrahami <avrahami.ben@gmail.com> wrote 9 Feb 2021, 03:30:
That's the current alternative, but namedtuples (unlike dataclasses) are slotted, which makes them more space-efficient and (slightly) faster.
When I use @dataclass(frozen=True), I manually add a __slots__ attribute. I presume this makes the resulting objects similar in size to NamedTuples, but I haven't done any measurements (and not sure how to measure this anyway). I wonder: is it possible for @dataclass to have an option slots=True? And perhaps frozen=True should imply slots=True (would this cause any backwards compatibility problems?).

https://bugs.python.org/issue42269 Although I haven't done much about it. The problem is that it needs to return a new class, not just inject methods into the existing class you defined. Eric On 2/10/2021 11:13 AM, Peter Ludemann wrote:
participants (2)
-
Eric V. Smith
-
Peter Ludemann