Fix from_dict for PyPy

This commit is contained in:
Jason Paryani
2013-09-04 21:53:13 -07:00
parent a57a99f7fc
commit 0187d123c9
4 changed files with 5 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
# capnp.pyx # capnp.pyx
# distutils: language = c++ # distutils: language = c++
# distutils: extra_compile_args = --std=c++11 -fpermissive # distutils: extra_compile_args = --std=c++11 -fpermissive
# distutils: libraries = capnpc # distutils: libraries = capnpc capnp
# cython: c_string_type = str # cython: c_string_type = str
# cython: c_string_encoding = default # cython: c_string_encoding = default
# cython: embedsignature = True # cython: embedsignature = True
@@ -447,12 +447,13 @@ cdef _to_dict(msg):
import collections as _collections import collections as _collections
cdef _from_dict_helper(msg, field, d): 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) sub_msg = getattr(msg, field)
for key, val in d.iteritems(): for key, val in d.iteritems():
if key != 'which': if key != 'which':
_from_dict_helper(sub_msg, key, val) _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)) l = msg.init(field, len(d))
for i in range(len(d)): for i in range(len(d)):
if isinstance(d[i], dict): if isinstance(d[i], dict):

View File

@@ -1,7 +1,6 @@
# schema.capnp.cpp.pyx # schema.capnp.cpp.pyx
# distutils: language = c++ # distutils: language = c++
# distutils: extra_compile_args = --std=c++11 # distutils: extra_compile_args = --std=c++11
# distutils: libraries = capnpc
from schema_cpp cimport Node, Data, StructNode, EnumNode from schema_cpp cimport Node, Data, StructNode, EnumNode
from libc.stdint cimport * from libc.stdint cimport *

View File

@@ -1,7 +1,7 @@
# schema.capnp.cpp.pyx # schema.capnp.cpp.pyx
# distutils: language = c++ # distutils: language = c++
# distutils: extra_compile_args = --std=c++11 # distutils: extra_compile_args = --std=c++11
# distutils: libraries = capnp # distutils: libraries = capnpc capnp
from libc.stdint cimport * from libc.stdint cimport *
from capnp_cpp cimport DynamicOrphan from capnp_cpp cimport DynamicOrphan

View File

@@ -38,7 +38,6 @@ def test_roundtrip_bytes(all_types):
msg = all_types.TestAllTypes.from_bytes(message_bytes) msg = all_types.TestAllTypes.from_bytes(message_bytes)
test_regression.check_all_types(msg) test_regression.check_all_types(msg)
@pytest.mark.skipif("platform.python_implementation() == 'PyPy'")
def test_roundtrip_dict(all_types): def test_roundtrip_dict(all_types):
msg = all_types.TestAllTypes.new_message() msg = all_types.TestAllTypes.new_message()
test_regression.init_all_types(msg) test_regression.init_all_types(msg)