Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempts to instantiate with Dict in nested list #9

Open
ROpdebee opened this issue Jun 10, 2019 · 0 comments
Open

Attempts to instantiate with Dict in nested list #9

ROpdebee opened this issue Jun 10, 2019 · 0 comments

Comments

@ROpdebee
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant