From 5ae444a49cbfcc07bd7c462cfc75e162dc610aff Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 30 Sep 2021 14:22:56 +0200 Subject: [PATCH] Base: [skip ci] use PyNumber_Check instead of PyFloat_Check/PyLong_Check to check for numbers --- src/Base/VectorPyImp.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Base/VectorPyImp.cpp b/src/Base/VectorPyImp.cpp index c516efb08d..ea024cb3ac 100644 --- a/src/Base/VectorPyImp.cpp +++ b/src/Base/VectorPyImp.cpp @@ -150,15 +150,10 @@ PyObject* VectorPy::number_multiply_handler(PyObject *self, PyObject *other) Py::Float mult(a * b); return Py::new_reference_to(mult); } - - else if (PyFloat_Check(other)) { + else if (PyNumber_Check(other)) { double b = PyFloat_AsDouble(other); return new VectorPy(a * b); } - else if (PyLong_Check(other)) { - long b = PyLong_AsLong(other); - return new VectorPy(a * (double)b); - } else { PyErr_SetString(PyExc_NotImplementedError, "Not implemented"); return 0; @@ -166,14 +161,10 @@ PyObject* VectorPy::number_multiply_handler(PyObject *self, PyObject *other) } else if (PyObject_TypeCheck(other, &(VectorPy::Type))) { Base::Vector3d a = static_cast(other) ->value(); - if (PyFloat_Check(self)) { + if (PyNumber_Check(self)) { double b = PyFloat_AsDouble(self); return new VectorPy(a * b); } - else if (PyLong_Check(self)) { - long b = PyLong_AsLong(self); - return new VectorPy(a * (double)b); - } else { PyErr_SetString(PyExc_TypeError, "A Vector can only be multiplied by Vector or number"); return 0; @@ -216,7 +207,7 @@ int VectorPy::sequence_ass_item(PyObject *self, Py_ssize_t index, PyObject *valu return -1; } - if (PyFloat_Check(value)) { + if (PyNumber_Check(value)) { VectorPy::PointerType ptr = static_cast(self)->getVectorPtr(); (*ptr)[index] = PyFloat_AsDouble(value); }