[Python-ideas] add an additional dataclasses.asdict option for non-dataclasses
Christopher Barker
pythonchb at gmail.com
Sat May 11 23:12:59 EDT 2019
On Sat, May 11, 2019 at 3:26 PM Eric V. Smith <eric at trueblade.com> wrote:
> It’s a design goal of dataclasses to not be iterable.
>
> https://www.python.org/dev/peps/pep-0557/#why-not-just-use-namedtuple
>
you would know, but that reference talks about why they are not the same as
NamedTuple.
if dataclasses *were*iterable, they almost certainly wouldn't iterate over
the values alone.
And NamesTuple was designed to BE tuples -- that is a drop in replacement
for tuples -- so they have the features they have partially for that reason.
And my toy code actually adds another decorator to make dataclasses
iterable, so it would be a completely optional feature.
All that being said, I'm not actually advocating doing this with
dataclasses -- I'm simply making the point that there are currretly two
ways to make custom class able to be passed in to the dict constructor --
do we need another?
-CHB
--
Christopher Barker, PhD
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190511/4d010a93/attachment.html>
More information about the Python-ideas
mailing list