support any sequence type in init method of Vector class

This commit is contained in:
wmayer 2016-07-27 09:23:20 +02:00
parent 67458d5bd2
commit 732eb7fee3
2 changed files with 15 additions and 15 deletions

View File

@ -26,7 +26,7 @@
#endif #endif
#include "GeometryPyCXX.h" #include "GeometryPyCXX.h"
#include "VectorPy.h" #include <Base/VectorPy.h>
int Py::Vector::Vector_TypeCheck(PyObject * obj) int Py::Vector::Vector_TypeCheck(PyObject * obj)
@ -39,8 +39,8 @@ bool Py::Vector::accepts (PyObject *obj) const
if (obj && Vector_TypeCheck (obj)) { if (obj && Vector_TypeCheck (obj)) {
return true; return true;
} }
else if (obj && PyTuple_Check(obj)) { else if (obj && PySequence_Check(obj)) {
return (PyTuple_Size(obj) == 3); return (PySequence_Size(obj) == 3);
} }
return false; return false;

View File

@ -74,7 +74,7 @@ int VectorPy::PyInit(PyObject* args, PyObject* /*kwd*/)
return 0; return 0;
} }
PyErr_Clear(); // set by PyArg_ParseTuple() PyErr_Clear(); // set by PyArg_ParseTuple()
if (PyArg_ParseTuple(args,"O!",&(PyTuple_Type), &object)) { if (PyArg_ParseTuple(args,"O", &object)) {
try { try {
*ptr = getVectorFromTuple<double>(object); *ptr = getVectorFromTuple<double>(object);
return 0; return 0;
@ -238,21 +238,21 @@ PyObject* VectorPy::richCompare(PyObject *v, PyObject *w, int op)
Vector3d v2 = static_cast<VectorPy*>(w)->value(); Vector3d v2 = static_cast<VectorPy*>(w)->value();
PyObject *res=0; PyObject *res=0;
if (op != Py_EQ && op != Py_NE) { if (op != Py_EQ && op != Py_NE) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"no ordering relation is defined for Vector"); "no ordering relation is defined for Vector");
return 0; return 0;
} }
else if (op == Py_EQ) { else if (op == Py_EQ) {
res = (v1 == v2) ? Py_True : Py_False; res = (v1 == v2) ? Py_True : Py_False;
Py_INCREF(res); Py_INCREF(res);
return res; return res;
} }
else { else {
res = (v1 != v2) ? Py_True : Py_False; res = (v1 != v2) ? Py_True : Py_False;
Py_INCREF(res); Py_INCREF(res);
return res; return res;
} }
} }
else { else {
// This always returns False // This always returns False