From efa81882e33e097998094dc7b889c42f378d0ec7 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 17 Apr 2017 17:22:50 -0700 Subject: [PATCH] Also allow numpy arrays for sequence conversions to value types --- etg/colour.py | 28 ++++++-------- etgtools/tweaker_tools.py | 78 +++++++++++++++++---------------------- src/wxpy_api.h | 42 +++++++++++++++++++++ unittests/test_colour.py | 17 +++++++++ unittests/test_gdicmn.py | 28 ++++++++++++-- 5 files changed, 127 insertions(+), 66 deletions(-) diff --git a/etg/colour.py b/etg/colour.py index 25110c79..339c616f 100644 --- a/etg/colour.py +++ b/etg/colour.py @@ -198,17 +198,7 @@ def run(): return 1; if (PyBytes_Check(sipPy) || PyUnicode_Check(sipPy)) return 1; - if (PyTuple_Check(sipPy) || PyList_Check(sipPy)) { - size_t len = PySequence_Size(sipPy); - if (len != 3 && len != 4) - return 0; - // ensure all the items in the sequence are numbers - for (int idx=0; idxob_type->tp_name, "numpy.ndarray") != 0) + return false; + } + + // Bail out here if the length isn't given + if (reqLength == -1) + return true; + + // Now check that the length matches the expected length + if (PySequence_Length(obj) != reqLength) + return false; + + // Check that each item is a number + for (int i=0; i