diff --git a/jsonobject/types.py b/jsonobject/types.py index 66ef4a8..8d4b806 100644 --- a/jsonobject/types.py +++ b/jsonobject/types.py @@ -55,6 +55,9 @@ def __property_config__(self, model_class, property_name): if len(annotation.__args__) != 1: raise ValueError('List annotations must be typed') type = annotation.__args__[0] + elif hasattr(annotation, '__origin__') and annotation.__origin__ in (dict, typing.Dict): + is_list = False + type = dict elif issubclass(annotation, (EnumProperty, )): is_list = False type = str diff --git a/setup.py b/setup.py index e4121fb..03fd325 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup name_ = 'jsonobject' -version_ = '1.2.0' +version_ = '1.3.2' packages_ = [ 'jsonobject', ] diff --git a/tests/test_dicts.py b/tests/test_dicts.py index ae78502..9f450cb 100644 --- a/tests/test_dicts.py +++ b/tests/test_dicts.py @@ -2,6 +2,7 @@ import pytest from jsonobject import PropertySet, Property +import typing def test_set_via_constructor(): @@ -118,3 +119,12 @@ class O(PropertySet): o = O() assert type(o.s) is dict + + +def test_via_abstract_hint(): + class O(PropertySet): + s: typing.Dict[str, str] = Property() + + o = O() + + assert type(o.s) is dict