From 14db1b7c98af271f0adcfc424673879874ce2448 Mon Sep 17 00:00:00 2001 From: marioalexis Date: Wed, 20 Jul 2022 01:19:29 -0300 Subject: [PATCH] Spreadsheet: Check Python types using Base::PyTypeCheck --- src/Mod/Spreadsheet/App/SheetPyImp.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/Mod/Spreadsheet/App/SheetPyImp.cpp b/src/Mod/Spreadsheet/App/SheetPyImp.cpp index c17cf1d2f7..b294663a65 100644 --- a/src/Mod/Spreadsheet/App/SheetPyImp.cpp +++ b/src/Mod/Spreadsheet/App/SheetPyImp.cpp @@ -494,13 +494,8 @@ PyObject* SheetPy::setAlias(PyObject *args) try { address = stringToAddress(strAddress); - if (PyUnicode_Check(value)) - getSheetPtr()->setAlias(address, PyUnicode_AsUTF8(value)); - else if (value == Py_None) - getSheetPtr()->setAlias(address, ""); - else - throw Base::TypeError("String or None expected"); - + Base::PyTypeCheck(&value, &PyUnicode_Type, "String or None expected"); + getSheetPtr()->setAlias(address, value ? PyUnicode_AsUTF8(value) : ""); Py_Return; } catch (const Base::Exception & e) { @@ -523,10 +518,8 @@ PyObject* SheetPy::getAlias(PyObject *args) if (cell && cell->getAlias(alias)) return Py::new_reference_to( Py::String( alias ) ); - else { - Py_INCREF(Py_None); - return Py_None; - } + else + Py_Return; } catch (const Base::Exception & e) { PyErr_SetString(PyExc_ValueError, e.what()); @@ -546,10 +539,8 @@ PyObject* SheetPy::getCellFromAlias(PyObject *args) if (!address.empty()) return Py::new_reference_to( Py::String( address ) ); - else { - Py_INCREF(Py_None); - return Py_None; - } + else + Py_Return; } catch (const Base::Exception & e) { PyErr_SetString(PyExc_ValueError, e.what());