Hi, I ran across this nice article a few days ago -

https://death.andgravity.com/namedtuples

which provides some answers as to why you might consider using named tuples.

best,
—titus

> On Jul 28, 2021, at 3:22 PM, pa...@lexyr.com wrote:
> 
> [Migrating the discussion from https://bugs.python.org/issue44768.]
> 
> 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.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/UQRCDWMFNC5NRLLQCTYPOEGWJOIV7BGJ/
> 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/LGF64BSY7PWY7E7TON2ST2BYZFDJGAVO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to