From 0187d123c9d99109af953e61ebea922ac12f5ce9 Mon Sep 17 00:00:00 2001 From: Jason Paryani Date: Wed, 4 Sep 2013 21:53:13 -0700 Subject: [PATCH] Fix from_dict for PyPy --- capnp/capnp.pyx | 7 ++++--- capnp/capnp_cpp.pxd | 1 - capnp/schema_cpp.pxd | 2 +- test/test_serialization.py | 1 - 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/capnp/capnp.pyx b/capnp/capnp.pyx index e45079e..39bd0a5 100644 --- a/capnp/capnp.pyx +++ b/capnp/capnp.pyx @@ -1,7 +1,7 @@ # capnp.pyx # distutils: language = c++ # distutils: extra_compile_args = --std=c++11 -fpermissive -# distutils: libraries = capnpc +# distutils: libraries = capnpc capnp # cython: c_string_type = str # cython: c_string_encoding = default # cython: embedsignature = True @@ -447,12 +447,13 @@ cdef _to_dict(msg): import collections as _collections cdef _from_dict_helper(msg, field, d): - if isinstance(d, dict): + d_type = type(d) + if d_type is dict: sub_msg = getattr(msg, field) for key, val in d.iteritems(): if key != 'which': _from_dict_helper(sub_msg, key, val) - elif isinstance(d, _collections.Iterable) and not isinstance(d, basestring): + elif d_type is list and not isinstance(d, basestring): l = msg.init(field, len(d)) for i in range(len(d)): if isinstance(d[i], dict): diff --git a/capnp/capnp_cpp.pxd b/capnp/capnp_cpp.pxd index d177c83..8fe49b6 100644 --- a/capnp/capnp_cpp.pxd +++ b/capnp/capnp_cpp.pxd @@ -1,7 +1,6 @@ # schema.capnp.cpp.pyx # distutils: language = c++ # distutils: extra_compile_args = --std=c++11 -# distutils: libraries = capnpc from schema_cpp cimport Node, Data, StructNode, EnumNode from libc.stdint cimport * diff --git a/capnp/schema_cpp.pxd b/capnp/schema_cpp.pxd index 669df11..19a73d8 100644 --- a/capnp/schema_cpp.pxd +++ b/capnp/schema_cpp.pxd @@ -1,7 +1,7 @@ # schema.capnp.cpp.pyx # distutils: language = c++ # distutils: extra_compile_args = --std=c++11 -# distutils: libraries = capnp +# distutils: libraries = capnpc capnp from libc.stdint cimport * from capnp_cpp cimport DynamicOrphan diff --git a/test/test_serialization.py b/test/test_serialization.py index 416d54d..8c16f06 100644 --- a/test/test_serialization.py +++ b/test/test_serialization.py @@ -38,7 +38,6 @@ def test_roundtrip_bytes(all_types): msg = all_types.TestAllTypes.from_bytes(message_bytes) test_regression.check_all_types(msg) -@pytest.mark.skipif("platform.python_implementation() == 'PyPy'") def test_roundtrip_dict(all_types): msg = all_types.TestAllTypes.new_message() test_regression.init_all_types(msg)