App: simplify the logic in PropertyLinkList::getPyValue

This commit is contained in:
wmayer
2020-11-18 18:21:15 +01:00
parent 031619db27
commit e2b58bf3d5

View File

@@ -715,15 +715,18 @@ PyObject *PropertyLinkList::getPyObject(void)
return Py::new_reference_to(sequence);
}
DocumentObject *PropertyLinkList::getPyValue(PyObject *item) const {
DocumentObject *PropertyLinkList::getPyValue(PyObject *item) const
{
if (item == Py_None) {
return nullptr;
} else if (!PyObject_TypeCheck(item, &(DocumentObjectPy::Type))) {
std::string error = std::string("type must be 'DocumentObject', list of 'DocumentObject', or NoneType, not ");
error += item->ob_type->tp_name;
throw Base::TypeError(error);
}
return static_cast<DocumentObjectPy*>(item)->getDocumentObjectPtr();
else if (PyObject_TypeCheck(item, &(DocumentObjectPy::Type))) {
return static_cast<DocumentObjectPy*>(item)->getDocumentObjectPtr();
}
std::string error = std::string("type must be 'DocumentObject', list of 'DocumentObject', or NoneType, not ");
error += item->ob_type->tp_name;
throw Base::TypeError(error);
}
void PropertyLinkList::Save(Base::Writer &writer) const