From 732eb7fee33dac1569a2fbe67b766a4707a598c3 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 27 Jul 2016 09:23:20 +0200 Subject: [PATCH] support any sequence type in init method of Vector class --- src/Base/GeometryPyCXX.cpp | 6 +++--- src/Base/VectorPyImp.cpp | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Base/GeometryPyCXX.cpp b/src/Base/GeometryPyCXX.cpp index 843cb5bb6..a01fe6ced 100644 --- a/src/Base/GeometryPyCXX.cpp +++ b/src/Base/GeometryPyCXX.cpp @@ -26,7 +26,7 @@ #endif #include "GeometryPyCXX.h" -#include "VectorPy.h" +#include int Py::Vector::Vector_TypeCheck(PyObject * obj) @@ -39,8 +39,8 @@ bool Py::Vector::accepts (PyObject *obj) const if (obj && Vector_TypeCheck (obj)) { return true; } - else if (obj && PyTuple_Check(obj)) { - return (PyTuple_Size(obj) == 3); + else if (obj && PySequence_Check(obj)) { + return (PySequence_Size(obj) == 3); } return false; diff --git a/src/Base/VectorPyImp.cpp b/src/Base/VectorPyImp.cpp index 4eb43b35f..94c7342e8 100644 --- a/src/Base/VectorPyImp.cpp +++ b/src/Base/VectorPyImp.cpp @@ -74,7 +74,7 @@ int VectorPy::PyInit(PyObject* args, PyObject* /*kwd*/) return 0; } PyErr_Clear(); // set by PyArg_ParseTuple() - if (PyArg_ParseTuple(args,"O!",&(PyTuple_Type), &object)) { + if (PyArg_ParseTuple(args,"O", &object)) { try { *ptr = getVectorFromTuple(object); return 0; @@ -238,21 +238,21 @@ PyObject* VectorPy::richCompare(PyObject *v, PyObject *w, int op) Vector3d v2 = static_cast(w)->value(); PyObject *res=0; - if (op != Py_EQ && op != Py_NE) { - PyErr_SetString(PyExc_TypeError, - "no ordering relation is defined for Vector"); - return 0; - } - else if (op == Py_EQ) { - res = (v1 == v2) ? Py_True : Py_False; + if (op != Py_EQ && op != Py_NE) { + PyErr_SetString(PyExc_TypeError, + "no ordering relation is defined for Vector"); + return 0; + } + else if (op == Py_EQ) { + res = (v1 == v2) ? Py_True : Py_False; Py_INCREF(res); return res; - } - else { - res = (v1 != v2) ? Py_True : Py_False; + } + else { + res = (v1 != v2) ? Py_True : Py_False; Py_INCREF(res); return res; - } + } } else { // This always returns False