typed-json-dataclass icon indicating copy to clipboard operation
typed-json-dataclass copied to clipboard

Attempts to instantiate with Dict in nested list

Open ROpdebee opened this issue 6 years ago • 0 comments
trafficstars

Example program

from typing import List, Dict
from dataclasses import dataclass
from typed_json_dataclass import TypedJsonMixin

@dataclass
class Test(TypedJsonMixin):
    test: List[Dict[str, int]]

Test([{'a': 1}, {'b': 2, 'c': 3}])

Traceback

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    Test([{'a': 1}, {'b': 2, 'c': 3}])
  File "<string>", line 3, in __init__
  File "/Users/ruben/.local/share/virtualenvs/source-dQgmcX_Z/lib/python3.7/site-packages/typed_json_dataclass/typed_json_dataclass.py", line 118, in __post_init__
    )[i] = expected_element_type(**element)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/typing.py", line 668, in __call__
    raise TypeError(f"Type {self._name} cannot be instantiated; "
TypeError: Type Dict cannot be instantiated; use dict() instead

ROpdebee avatar Jun 10 '19 23:06 ROpdebee