@@ -56,16 +56,13 @@ namespace python::API
5656 template <typename RetTy>
5757 RetTy convertToCppObject (PyObject* o)
5858 {
59- if constexpr (std::is_same_v<RetTy, int >)
60- {
59+ if constexpr (std::is_same_v<RetTy, int >) {
6160 return PyLong_AsLong (o);
6261 }
63- else if constexpr (std::is_same_v<RetTy, double > || std::is_same_v<RetTy, float >)
64- {
62+ else if constexpr (std::is_same_v<RetTy, double > || std::is_same_v<RetTy, float >) {
6563 return PyFloat_AsDouble (o);
6664 }
67- else if constexpr (std::is_same_v<RetTy, std::string>)
68- {
65+ else if constexpr (std::is_same_v<RetTy, std::string>) {
6966 return PyUnicode_AsUTF8 (o);
7067 }
7168 }
@@ -85,13 +82,11 @@ namespace python::API
8582 // Import the Module (file name)
8683 PyObject* pModule = PyImport_ImportModule (moduleName.c_str ());
8784
88- if (pModule)
89- {
85+ if (pModule) {
9086 // Get the function from the module
9187 PyObject* pFunc = PyObject_GetAttrString (pModule, functionName.c_str ());
9288
93- if (PyCallable_Check (pFunc))
94- {
89+ if (PyCallable_Check (pFunc)) {
9590 // Create an empty Tuple of size len(args)
9691 PyObject* pArgs = PyTuple_New (sizeof ...(args));
9792
@@ -102,27 +97,23 @@ namespace python::API
10297 // Call the function with the tuple containing the arguments
10398 PyObject* pValue = PyObject_CallObject (pFunc, pArgs);
10499
105- if (!pValue)
106- {
100+ if (!pValue) {
107101 Py_Finalize ();
108102 throw Error (" Function '" + functionName + " ' failed." );
109103 }
110104
111- if constexpr (!std::is_same_v<RetTy, void >)
112- {
105+ if constexpr (!std::is_same_v<RetTy, void >) {
113106 RetTy result = convertToCppObject<RetTy>(pValue);
114107 Py_Finalize ();
115108 return result;
116109 }
117110 }
118- else
119- {
111+ else {
120112 Py_Finalize ();
121113 throw Error (" Python function '" + functionName + " ' is not callable." );
122114 }
123115 }
124- else
125- {
116+ else {
126117 Py_Finalize ();
127118 throw Error (" Failed to load Python module: '" + moduleName + " '." );
128119 }
0 commit comments