- Python Home
- About
- News
- Documentation
- Downloads
- Community
- Foundation
- Developer's Guide
- Issue Tracker
- Issues
- Summaries
- User
- Administration
- Help
➜
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 | wrmsr |
|---|---|
| Recipients | wrmsr |
| Date | 2018-12-19.22:06:43 |
| SpamBayes Score | -1.0 |
| Marked as misclassified | Yes |
| Message-id | <1545257204.19.0.788709270274.issue35540@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
|---|
_asdict_inner attempts to manually recursively deepcopy dicts by calling type(obj) with a generator of transformed keyvalue tuples @ https://github.com/python/cpython/blob/b2f642ccd2f65d2f3bf77bbaa103dd2bc2733734/Lib/dataclasses.py#L1080 . defaultdicts are dicts so this runs but unlike other dicts their first arg has to be a callable or None: import collections import dataclasses as dc @dc.dataclass() class C: d: dict c = C(collections.defaultdict(lambda: 3, {})) d = dc.asdict(c) assert isinstance(d['d'], collections.defaultdict) assert d['d']['a'] == 3 => Traceback (most recent call last): File "boom.py", line 9, in <module> d = dc.asdict(c) File "/Users/spinlock/.pyenv/versions/3.7.1/lib/python3.7/dataclasses.py", line 1019, in asdict return _asdict_inner(obj, dict_factory) File "/Users/spinlock/.pyenv/versions/3.7.1/lib/python3.7/dataclasses.py", line 1026, in _asdict_inner value = _asdict_inner(getattr(obj, f.name), dict_factory) File "/Users/spinlock/.pyenv/versions/3.7.1/lib/python3.7/dataclasses.py", line 1058, in _asdict_inner for k, v in obj.items()) TypeError: first argument must be callable or None I understand that it isn't this bit of code's job to support every dict (and list etc.) subclass under the sun but given defaultdict is stdlib it's imo worth supporting explicitly. |
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2018-12-19 22:06:45 | wrmsr | set | recipients: + wrmsr |
| 2018-12-19 22:06:44 | wrmsr | set | messageid: <1545257204.19.0.788709270274.issue35540@psf.upfronthosting.co.za> |
| 2018-12-19 22:06:44 | wrmsr | link | issue35540 messages |
| 2018-12-19 22:06:43 | wrmsr | create |
Powered by Roundup Copyright © 1990-2022, Python Software Foundation
Legal Statements
