AttributeError: type object 'dict' has no attribute '__args__'
See original GitHub issueNote: This issue is somewhat related to: #13, #12, but it wasn’t resolved in #16. I get the same error, but for different input.
My code: @dataclass_json() @dataclass class A: b: dict
@dataclass_json() @dataclass class X: x: List[A]
output = {“x”: [{ "a: {“b”: {“False”: 0.1, “True”: 0.3}}}]}
response = x.from_json(output)
The Error:
when type=_dict, value={“b”: {“False”: 0.1, “True”: 0.3}}
` def decode_generic(type, value, infer_missing): if value is None: res = value elif issubclass_safe(type, Enum): # Convert to an Enum using the type as a constructor. Assumes a direct match is found. res = type_(value) # FIXME this is a hack to fix a deeper underlying issue. A refactor is due. elif is_collection(type): if is_mapping(type):
k_type, v_type = type_.__args__
E AttributeError: type object ‘dict’ has no attribute ‘args’`
My very hacky solution:
To solve my very specific issue, I changed the code of _decode_generic
try:
k_type, v_type = type_.__args__
except:
k_type, v_type = None, None
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:10
I really hope someone fixes this
I just come across this due to a similar issue in another library. From there, I learn the solution is to specify the element type inside the container type e.g.
list[int]
. For @kodekracker’s issueFor OP’s nested structure, I haven’t found good solutions. The code below does not work.