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?
On Wed, 2021-07-28 at 22:22 +0000, pavel@lexyr.com wrote:
PEP 20 says:
There should be one-- and preferably only one --obvious way to do it.
There are two ways to create a simple named type to store data: collections.namedtuple and dataclasses.dataclass. I propose deprecating namedtuple.
As far as the interface is concerned, the namedtuple is almost completely equivalent to a frozen dataclass - with some iterability syntactic sugar thrown in. I don't think there are use cases for namedtuple that would not be trivial to rewrite with dataclasses.
As far as the implementation is concerned, the namedtuple is faster. If efficiency is a concern, why do we make our users decide? We can choose the most efficient one on the library's end. C++ does something similar with bool vectors - the library has a special case for where it would be more optimal to use a different data structure underneath.
TL;DR: If dataclass is so good, why keep namedtuple around?
_______________________________________________
_______________________________________________Python-ideas mailing list -- python-ideas@python.orgTo unsubscribe send an email to python-ideas-leave@python.orghttps://mail.python.org/mailman3/lists/python-ideas.python.org/Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/4NOUPTLNNJJMM3XSN3WEK32NWRJDAVRD/Code of Conduct: http://python.org/psf/codeofconduct/