New submission from bscarlett <brad.scarl...@gmail.com>:

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

----------
components: Library (Lib)
messages: 363884
nosy: brad.scarl...@gmail.com
priority: normal
severity: normal
status: open
title: dataclasses.asdict will mangle collection.Counter instances
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39929>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to