diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index 7ba44cf..10dd972 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -735,6 +735,9 @@ cdef _to_dict(msg, bint verbose): return ret + if msg_type is _DynamicEnum: + return str(msg) + return msg diff --git a/test/test_struct.py b/test/test_struct.py index ce71f40..c292c6b 100644 --- a/test/test_struct.py +++ b/test/test_struct.py @@ -171,3 +171,11 @@ def test_set_dict_union(addressbook): person = addressbook.Person.new_message(**{'employment': {'employer': {'name': 'foo'}}}) assert person.employment.employer.name == 'foo' + + +def test_to_dict_enum(addressbook): + person = addressbook.Person.new_message(**{'phones': [{'number': '999-9999', 'type': 'mobile'}]}) + + field = person.to_dict()['phones'][0]['type'] + assert isinstance(field, basestring) + assert field == 'mobile'