Skip to content

Commit

Permalink
Allow Dict[] for typing like dict
Browse files Browse the repository at this point in the history
  • Loading branch information
eblade committed May 7, 2019
1 parent 8377a20 commit f7eeafe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions jsonobject/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import setup

name_ = 'jsonobject'
version_ = '1.2.0'
version_ = '1.3.2'
packages_ = [
'jsonobject',
]
Expand Down
10 changes: 10 additions & 0 deletions tests/test_dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from jsonobject import PropertySet, Property
import typing


def test_set_via_constructor():
Expand Down Expand Up @@ -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

0 comments on commit f7eeafe

Please sign in to comment.