App: Fix linter warnings

This commit is contained in:
wmayer
2026-02-23 10:12:38 +01:00
committed by Ladislav Michl
parent 05ef4153f5
commit 26c2d7a77c
3 changed files with 95 additions and 91 deletions
+90 -87
View File
@@ -48,6 +48,7 @@ using namespace App;
//**************************************************************************
// Python stuff
// NOLINTBEGIN
// Application methods structure
PyMethodDef ApplicationPy::Methods[] = {
{"ParamGet", (PyCFunction)ApplicationPy::sGetParam, METH_VARARGS, "Get parameters by path"},
@@ -158,9 +159,6 @@ PyMethodDef ApplicationPy::Methods[] = {
" In this case the document is kept alive.\n"
"hidden: whether to hide document 3D view.\n"
"temporary: whether to hide document in the tree view."},
// {"saveDocument", (PyCFunction) ApplicationPy::sSaveDocument, METH_VARARGS,
// "saveDocument(string) -- Save the document to a file."},
// {"saveDocumentAs", (PyCFunction) ApplicationPy::sSaveDocumentAs, METH_VARARGS},
{"newDocument",
reinterpret_cast<PyCFunction>(reinterpret_cast<void (*)()>(ApplicationPy::sNewDocument)),
METH_VARARGS | METH_KEYWORDS,
@@ -268,11 +266,12 @@ PyMethodDef ApplicationPy::Methods[] = {
"trigger a Base.FreeCADAbort exception."},
{nullptr, nullptr, 0, nullptr} /* Sentinel */
};
// NOLINTEND
// NOLINTBEGIN(cppcoreguidelines-pro-type-*)
PyObject* ApplicationPy::sLoadFile(PyObject* /*self*/, PyObject* args)
{
const char* path;
const char* path = "";
const char* doc = "";
const char* mod = "";
if (!PyArg_ParseTuple(args, "s|ss", &path, &doc, &mod)) {
@@ -293,9 +292,8 @@ PyObject* ApplicationPy::sLoadFile(PyObject* /*self*/, PyObject* args)
PyErr_Format(PyExc_IOError, "Filetype %s is not supported.", ext.c_str());
return nullptr;
}
else {
module = modules.front();
}
module = modules.front();
}
// path could contain characters that need escaping, such as quote signs
@@ -340,7 +338,7 @@ PyObject* ApplicationPy::sIsRestoring(PyObject* /*self*/, PyObject* args)
PyObject* ApplicationPy::sOpenDocument(PyObject* /*self*/, PyObject* args, PyObject* kwd)
{
char* Name;
char* Name {};
PyObject* hidden = Py_False;
PyObject* temporary = Py_False;
static const std::array<const char*, 4> kwlist {"name", "hidden", "temporary", nullptr};
@@ -486,7 +484,7 @@ PyObject* ApplicationPy::sCloseDocument(PyObject* /*self*/, PyObject* args)
PyObject* ApplicationPy::sSaveDocument(PyObject* /*self*/, PyObject* args)
{
char* pDoc;
char* pDoc {};
if (!PyArg_ParseTuple(args, "s", &pDoc)) {
return nullptr;
}
@@ -516,10 +514,9 @@ PyObject* ApplicationPy::sActiveDocument(PyObject* /*self*/, PyObject* args)
if (doc) {
return doc->getPyObject();
}
else {
Py_INCREF(Py_None);
return Py_None;
}
Py_INCREF(Py_None);
return Py_None;
}
PyObject* ApplicationPy::sGetDocument(PyObject* /*self*/, PyObject* args)
@@ -568,7 +565,7 @@ PyObject* ApplicationPy::sSaveParameter(PyObject* /*self*/, PyObject* args)
PyErr_SetString(PyExc_ValueError, str.str().c_str());
return nullptr;
}
else if (!param->HasSerializer()) {
if (!param->HasSerializer()) {
std::stringstream str;
str << "Parameter set cannot be serialized: " << pstr;
PyErr_SetString(PyExc_RuntimeError, str.str().c_str());
@@ -585,21 +582,21 @@ PyObject* ApplicationPy::sSaveParameter(PyObject* /*self*/, PyObject* args)
PyObject* ApplicationPy::sGetConfig(PyObject* /*self*/, PyObject* args)
{
char* pstr;
char* pstr {};
if (!PyArg_ParseTuple(args, "s", &pstr)) {
return nullptr;
}
const std::map<std::string, std::string>& Map = GetApplication().Config();
std::map<std::string, std::string>::const_iterator it = Map.find(pstr);
const std::map<std::string, std::string>& Map = Application::Config();
auto it = Map.find(pstr);
if (it != Map.end()) {
return Py_BuildValue("s", it->second.c_str());
}
else {
// do not set an error because this may break existing python code
return PyUnicode_FromString("");
}
// do not set an error because this may break existing python code
return PyUnicode_FromString("");
}
PyObject* ApplicationPy::sDumpConfig(PyObject* /*self*/, PyObject* args)
@@ -609,7 +606,7 @@ PyObject* ApplicationPy::sDumpConfig(PyObject* /*self*/, PyObject* args)
}
PyObject* dict = PyDict_New();
for (const auto& It : GetApplication().Config()) {
for (const auto& It : Application::Config()) {
PyDict_SetItemString(dict, It.first.c_str(), PyUnicode_FromString(It.second.c_str()));
}
return dict;
@@ -617,13 +614,14 @@ PyObject* ApplicationPy::sDumpConfig(PyObject* /*self*/, PyObject* args)
PyObject* ApplicationPy::sSetConfig(PyObject* /*self*/, PyObject* args)
{
char *pstr, *pstr2;
char *pstr {};
char *pstr2 {};
if (!PyArg_ParseTuple(args, "ss", &pstr, &pstr2)) {
return nullptr;
}
GetApplication().Config()[pstr] = pstr2;
Application::Config()[pstr] = pstr2;
Py_INCREF(Py_None);
return Py_None;
@@ -672,7 +670,8 @@ PyObject* ApplicationPy::sGetVersion(PyObject* /*self*/, PyObject* args)
PyObject* ApplicationPy::sAddImportType(PyObject* /*self*/, PyObject* args)
{
char *psKey, *psMod;
char *psKey {};
char *psMod {};
if (!PyArg_ParseTuple(args, "ss", &psKey, &psMod)) {
return nullptr;
@@ -685,7 +684,9 @@ PyObject* ApplicationPy::sAddImportType(PyObject* /*self*/, PyObject* args)
PyObject* ApplicationPy::sChangeImportModule(PyObject* /*self*/, PyObject* args)
{
char *key, *oldMod, *newMod;
char *key {};
char *oldMod {};
char *newMod {};
if (!PyArg_ParseTuple(args, "sss", &key, &oldMod, &newMod)) {
return nullptr;
@@ -713,33 +714,33 @@ PyObject* ApplicationPy::sGetImportType(PyObject* /*self*/, PyObject* args)
return Py::new_reference_to(list);
}
else {
Py::Dict dict;
std::vector<std::string> types = GetApplication().getImportTypes();
for (const auto& it : types) {
std::vector<std::string> modules = GetApplication().getImportModules(it.c_str());
if (modules.empty()) {
dict.setItem(it.c_str(), Py::None());
}
else if (modules.size() == 1) {
dict.setItem(it.c_str(), Py::String(modules.front()));
}
else {
Py::List list;
for (const auto& jt : modules) {
list.append(Py::String(jt));
}
dict.setItem(it.c_str(), list);
}
}
return Py::new_reference_to(dict);
Py::Dict dict;
std::vector<std::string> types = GetApplication().getImportTypes();
for (const auto& it : types) {
std::vector<std::string> modules = GetApplication().getImportModules(it.c_str());
if (modules.empty()) {
dict.setItem(it.c_str(), Py::None());
}
else if (modules.size() == 1) {
dict.setItem(it.c_str(), Py::String(modules.front()));
}
else {
Py::List list;
for (const auto& jt : modules) {
list.append(Py::String(jt));
}
dict.setItem(it.c_str(), list);
}
}
return Py::new_reference_to(dict);
}
PyObject* ApplicationPy::sAddExportType(PyObject* /*self*/, PyObject* args)
{
char *psKey, *psMod;
char *psKey {};
char *psMod {};
if (!PyArg_ParseTuple(args, "ss", &psKey, &psMod)) {
return nullptr;
@@ -752,7 +753,9 @@ PyObject* ApplicationPy::sAddExportType(PyObject* /*self*/, PyObject* args)
PyObject* ApplicationPy::sChangeExportModule(PyObject* /*self*/, PyObject* args)
{
char *key, *oldMod, *newMod;
char *key {};
char *oldMod {};
char *newMod {};
if (!PyArg_ParseTuple(args, "sss", &key, &oldMod, &newMod)) {
return nullptr;
@@ -780,28 +783,27 @@ PyObject* ApplicationPy::sGetExportType(PyObject* /*self*/, PyObject* args)
return Py::new_reference_to(list);
}
else {
Py::Dict dict;
std::vector<std::string> types = GetApplication().getExportTypes();
for (const auto& it : types) {
std::vector<std::string> modules = GetApplication().getExportModules(it);
if (modules.empty()) {
dict.setItem(it.c_str(), Py::None());
}
else if (modules.size() == 1) {
dict.setItem(it.c_str(), Py::String(modules.front()));
}
else {
Py::List list;
for (const auto& jt : modules) {
list.append(Py::String(jt));
}
dict.setItem(it.c_str(), list);
}
}
return Py::new_reference_to(dict);
Py::Dict dict;
std::vector<std::string> types = GetApplication().getExportTypes();
for (const auto& it : types) {
std::vector<std::string> modules = GetApplication().getExportModules(it.c_str());
if (modules.empty()) {
dict.setItem(it.c_str(), Py::None());
}
else if (modules.size() == 1) {
dict.setItem(it.c_str(), Py::String(modules.front()));
}
else {
Py::List list;
for (const auto& jt : modules) {
list.append(Py::String(jt));
}
dict.setItem(it.c_str(), list);
}
}
return Py::new_reference_to(dict);
}
PyObject* ApplicationPy::sGetResourcePath(PyObject* /*self*/, PyObject* args)
@@ -912,8 +914,8 @@ PyObject* ApplicationPy::sListDocuments(PyObject* /*self*/, PyObject* args)
PY_TRY
{
PyObject* pDict = PyDict_New();
PyObject* pKey;
Base::PyObjectBase* pValue;
PyObject* pKey {};
Base::PyObjectBase* pValue {};
std::vector<Document*> docs = GetApplication().getDocuments();
;
@@ -937,7 +939,7 @@ PyObject* ApplicationPy::sListDocuments(PyObject* /*self*/, PyObject* args)
PyObject* ApplicationPy::sAddDocObserver(PyObject* /*self*/, PyObject* args)
{
PyObject* o;
PyObject* o {};
if (!PyArg_ParseTuple(args, "O", &o)) {
return nullptr;
}
@@ -951,7 +953,7 @@ PyObject* ApplicationPy::sAddDocObserver(PyObject* /*self*/, PyObject* args)
PyObject* ApplicationPy::sRemoveDocObserver(PyObject* /*self*/, PyObject* args)
{
PyObject* o;
PyObject* o {};
if (!PyArg_ParseTuple(args, "O", &o)) {
return nullptr;
}
@@ -965,14 +967,14 @@ PyObject* ApplicationPy::sRemoveDocObserver(PyObject* /*self*/, PyObject* args)
PyObject* ApplicationPy::sSetLogLevel(PyObject* /*self*/, PyObject* args)
{
char* tag;
PyObject* pcObj;
char* tag {};
PyObject* pcObj {};
if (!PyArg_ParseTuple(args, "sO", &tag, &pcObj)) {
return nullptr;
}
PY_TRY
{
int l;
int l {};
if (PyUnicode_Check(pcObj)) {
const char* pstr = PyUnicode_AsUTF8(pcObj);
if (strcmp(pstr, "Log") == 0) {
@@ -1001,7 +1003,7 @@ PyObject* ApplicationPy::sSetLogLevel(PyObject* /*self*/, PyObject* args)
}
}
else {
l = PyLong_AsLong(pcObj);
l = static_cast<int>(PyLong_AsLong(pcObj));
}
GetApplication()
.GetParameterGroupByPath("User parameter:BaseApp/LogLevels")
@@ -1031,7 +1033,7 @@ PyObject* ApplicationPy::sSetLogLevel(PyObject* /*self*/, PyObject* args)
PyObject* ApplicationPy::sGetLogLevel(PyObject* /*self*/, PyObject* args)
{
char* tag;
char* tag {};
if (!PyArg_ParseTuple(args, "s", &tag)) {
return nullptr;
}
@@ -1041,7 +1043,7 @@ PyObject* ApplicationPy::sGetLogLevel(PyObject* /*self*/, PyObject* args)
int l = -1;
if (strcmp(tag, "Default") == 0) {
#ifdef FC_DEBUG
l = GetApplication().GetUserParameter().GetGroup("BaseApp/LogLevels")->GetInt(tag, -1);
l = static_cast<int>(GetApplication().GetUserParameter().GetGroup("BaseApp/LogLevels")->GetInt(tag, -1));
#endif
}
else if (strcmp(tag, "DebugDefault") == 0) {
@@ -1094,7 +1096,7 @@ PyObject* ApplicationPy::sGetLinksTo(PyObject* /*self*/, PyObject* args)
}
auto links = GetApplication().getLinksTo(obj, options, count);
Py::Tuple ret(links.size());
Py::Tuple ret(static_cast<int>(links.size()));
int i = 0;
for (auto o : links) {
ret.setItem(i++, Py::Object(o->getPyObject(), true));
@@ -1107,7 +1109,7 @@ PyObject* ApplicationPy::sGetLinksTo(PyObject* /*self*/, PyObject* args)
PyObject* ApplicationPy::sGetDependentObjects(PyObject* /*self*/, PyObject* args)
{
PyObject* obj;
PyObject* obj {};
int options = 0;
if (!PyArg_ParseTuple(args, "O|i", &obj, &options)) {
return nullptr;
@@ -1116,13 +1118,13 @@ PyObject* ApplicationPy::sGetDependentObjects(PyObject* /*self*/, PyObject* args
std::vector<App::DocumentObject*> objs;
if (PySequence_Check(obj)) {
Py::Sequence seq(obj);
for (Py_ssize_t i = 0; i < seq.size(); ++i) {
if (!PyObject_TypeCheck(seq[i].ptr(), &DocumentObjectPy::Type)) {
for (const auto& py : seq) {
if (!PyObject_TypeCheck(py.ptr(), &DocumentObjectPy::Type)) {
PyErr_SetString(PyExc_TypeError,
"Expect element in sequence to be of type document object");
return nullptr;
}
objs.push_back(static_cast<DocumentObjectPy*>(seq[i].ptr())->getDocumentObjectPtr());
objs.push_back(static_cast<DocumentObjectPy*>(py.ptr())->getDocumentObjectPtr());
}
}
else if (!PyObject_TypeCheck(obj, &DocumentObjectPy::Type)) {
@@ -1139,9 +1141,9 @@ PyObject* ApplicationPy::sGetDependentObjects(PyObject* /*self*/, PyObject* args
{
auto ret = App::Document::getDependencyList(objs, options);
Py::Tuple tuple(ret.size());
Py::Tuple tuple(static_cast<int>(ret.size()));
for (size_t i = 0; i < ret.size(); ++i) {
tuple.setItem(i, Py::Object(ret[i]->getPyObject(), true));
tuple.setItem(static_cast<int>(i), Py::Object(ret[i]->getPyObject(), true));
}
return Py::new_reference_to(tuple);
}
@@ -1151,7 +1153,7 @@ PyObject* ApplicationPy::sGetDependentObjects(PyObject* /*self*/, PyObject* args
PyObject* ApplicationPy::sSetActiveTransaction(PyObject* /*self*/, PyObject* args)
{
char* name;
char* name {};
PyObject* persist = Py_False;
if (!PyArg_ParseTuple(args, "s|O!", &name, &PyBool_Type, &persist)) {
return nullptr;
@@ -1215,3 +1217,4 @@ PyObject* ApplicationPy::sCheckAbort(PyObject* /*self*/, PyObject* args)
}
PY_CATCH
}
// NOLINTEND(cppcoreguidelines-pro-type-*)