I've thing I still use NamedTuple for is when I want type safe
heterogeneous iterable unpacking, which is only possible for tuples (and
NamedTuple) eg I'd like to be able to express both:

tx, rx = trio.MemoryChanel[int]()

And:

with trio.MemoryChannel[int]() as channel:
    n.start_soon(worker, channel.recieve_channel.clone())

On Thu, 29 Jul 2021, 00:36 Chris Angelico, <ros...@gmail.com> wrote:

> On Thu, Jul 29, 2021 at 9:28 AM Paul Bryan <pbr...@anode.ca> wrote:
> >
> > I'm with you; since dataclasses were introduced, namedtuple has not see
> any use from me, though none of my uses have demanded ultra-high efficiency
> either.
> >
> > I wonder how many users are currently relying on namedtuple __getitem__
> semantics though. that's functionality dataclasses do not (currently) have.
> >
> > Random thought I don't know the answer to: Any reason __slots__ can't be
> used on a dataclass to improve efficiency?
> >
>
> It can. It still doesn't get efficiency down to where a namedtuple is,
> and it also doesn't make it into a tuple.
>
> Allow me to simplify matters. You could, instead of using a regular
> tuple, just use a dict with keys that are consecutive integers. This
> would behave in a very similar way, and then you could subclass the
> dict to change the iteration behaviour (or even rely on old-style
> fallback iteration). Does that mean that tuples are nothing but
> special-purpose dicts for efficiency? Not even slightly. They are
> different data structures for different purposes.
>
> It's the same with namedtuple, dataclass, and all the other different
> tools we have. They serve very different purposes. And even if one of
> them could truly be described as a higher-performance less-flexible
> version of another, there'd still be very little benefit to
> deprecating it. Remember that breaking people's code is a VERY serious
> concern.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/TWWK23EG3J2MAWDYPDLIIU2FISORYVBR/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/BNJ4JIWBBLFNIMQQVTPI727JATCSCISW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to