[New-bugs-announce] [issue44768] dataclasses.dataclass and collections.namedtuple do the same thing
pavel-lexyr
report at bugs.python.org
Wed Jul 28 16:42:31 EDT 2021
New submission from pavel-lexyr <pavel at lexyr.com>:
PEP 20 states:
> There should be one-- and preferably only one --obvious way to do it.
As of right now, two very similar constructions for making a lightweight dataclass exist in Python.
collections.namedtuple is one of them. dataclasses.dataclass is the other*.
The behaviour they provide is very similar. And with the functions .astuple() and the `frozen` constructor argument of the dataclass, one could consider it to be almost a direct superset of the namedtuple.
Having two different classes with very similar behaviour is not considered a good practice. I propose merging the two classes' features into one and to deprecate the other, to prevent unnecessary ambiguity.
* To get deeper into semantics, we might consider types.SimpleNamespace to be the third. This is out of this issue's scope - the reader is welcome to follow up in another one.
----------
components: Library (Lib)
messages: 398421
nosy: eric.smith, pavel-lexyr, rhettinger
priority: normal
severity: normal
status: open
title: dataclasses.dataclass and collections.namedtuple do the same thing
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44768>
_______________________________________
More information about the New-bugs-announce
mailing list