From b31b53b6a7a22f3dba0e7d75ffd8abbcf57b8bfa Mon Sep 17 00:00:00 2001 From: Kamal Marhubi Date: Sat, 30 May 2015 19:38:40 -0400 Subject: [PATCH 1/2] Add test for setting a field from a list --- test/test_struct.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test_struct.py b/test/test_struct.py index 563ba02..14aaca2 100644 --- a/test/test_struct.py +++ b/test/test_struct.py @@ -107,6 +107,14 @@ def test_builder_set(addressbook): person.foo = 'test' +def test_builder_set_from_list(all_types): + msg = all_types.TestAllTypes.new_message() + + msg.int32List = [0, 1, 2] + + assert list(msg.int32List) == [0, 1, 2] + + def test_null_str(all_types): msg = all_types.TestAllTypes.new_message() From 211192f235bbad77775097cd40204229a4049eaa Mon Sep 17 00:00:00 2001 From: Kamal Marhubi Date: Sat, 30 May 2015 19:42:27 -0400 Subject: [PATCH 2/2] Tidy up _from_list - remove unused variable - switch from `range` to `enumerate` for indexed iteration --- capnp/lib/capnp.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index 41f7b50..1f9ab02 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -873,10 +873,10 @@ cdef _to_dict(msg, bint verbose, bint ordered): return msg + cdef _from_list(_DynamicListBuilder msg, list d): - cdef size_t count = 0 - for i in range(len(d)): - msg._set(i, d[i]) + for i, x in enumerate(d): + msg._set(i, x) cdef class _DynamicEnum: