This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author brad.scarlett@gmail.com
Recipients brad.scarlett@gmail.com
Date 2020-03-11.06:13:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1583907183.73.0.710103063731.issue39929@roundup.psfhosted.org>
In-reply-to
Content
I noticed that dataclasses.asdict seems to incorrectly reconstruct collections.Counter objects with the counter values as tuple keys.

eg: 

In [1]: from collections import Counter
In [2]: from dataclasses import dataclass, asdict
In [3]: c = Counter()
In [4]: c['stuff'] += 1
In [5]: @dataclass
   ...: class Bob:
   ...:     c: Counter
   ...:
In [6]: b = Bob(c)
In [7]: c
Out[7]: Counter({'stuff': 1})
In [9]: b.c
Out[9]: Counter({'stuff': 1})
In [10]: asdict(b)
Out[10]: {'c': Counter({('stuff', 1): 1})}
In [11]: asdict(b)['c']
Out[11]: Counter({('stuff', 1): 1})

The Counter gets reconstructed with its item tuples as keys.

This problem seems to have similar aspects to https://bugs.python.org/issue35540
History
Date User Action Args
2020-03-11 06:13:03brad.scarlett@gmail.comsetrecipients: + brad.scarlett@gmail.com
2020-03-11 06:13:03brad.scarlett@gmail.comsetmessageid: <1583907183.73.0.710103063731.issue39929@roundup.psfhosted.org>
2020-03-11 06:13:03brad.scarlett@gmail.comlinkissue39929 messages
2020-03-11 06:13:03brad.scarlett@gmail.comcreate