GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — asdict() on dataclass with defaultdict raises TypeError: "first argument must be callable or None " · Issue #106113 · python/cpython Closed as not planned Closed as not planned Copy link Labels type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug reportMinimal working example: from dataclasses import dataclass, field, asdict from typing import DefaultDict from collections import defaultdict def default_list_dict(): return defaultdict(list) @dataclass class Data: metadata: DefaultDict = field(default_factory=default_list_dict) D = Data() # => Data(metadata=defaultdict(<class 'list'>, {})) asdict(D)
Display traceback---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[1], line 13
10 metadata: DefaultDict = field(default_factory=default_list_dict)
12 D = Data()
---> 13 asdict(D)
File ~/miniconda3/lib/python3.10/dataclasses.py:1238, in asdict(obj, dict_factory)
1236 if not _is_dataclass_instance(obj):
1237 raise TypeError("asdict() should be called on dataclass instances")
-> 1238 return _asdict_inner(obj, dict_factory)
File ~/miniconda3/lib/python3.10/dataclasses.py:1245, in _asdict_inner(obj, dict_factory)
1243 result = []
1244 for f in fields(obj):
-> 1245 value = _asdict_inner(getattr(obj, f.name), dict_factory)
1246 result.append((f.name, value))
1247 return dict_factory(result)
File ~/miniconda3/lib/python3.10/dataclasses.py:1275, in _asdict_inner(obj, dict_factory)
1273 return type(obj)(_asdict_inner(v, dict_factory) for v in obj)
1274 elif isinstance(obj, dict):
-> 1275 return type(obj)((_asdict_inner(k, dict_factory),
1276 _asdict_inner(v, dict_factory))
1277 for k, v in obj.items())
1278 else:
1279 return copy.deepcopy(obj)
TypeError: first argument must be callable or NoneYour environment
Activity
MetadataMetadataAssigneesLabelstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |