From 37a040449b5d475f2c12ab9447965f92fd13dc3a Mon Sep 17 00:00:00 2001 From: Uwe Siems Date: Wed, 24 Sep 2025 17:09:27 +0200 Subject: [PATCH] Set an exception if the required method does not exist Since Python 3.10, Python checks in Debug mode if a slot fails without an exception, or succeeds with an exception set, and aborts in this case. --- src/PythonQtClassWrapper.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/PythonQtClassWrapper.cpp b/src/PythonQtClassWrapper.cpp index f66df0c96..45b4adacf 100644 --- a/src/PythonQtClassWrapper.cpp +++ b/src/PythonQtClassWrapper.cpp @@ -122,9 +122,8 @@ static int PythonQtInstanceWrapper_setitem(PyObject* self, PyObject* index, PyOb { PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)self; bool isSetItem = value; - PythonQtMemberInfo opSlot = isSetItem ? - wrapper->classInfo()->member("__setitem__") - : wrapper->classInfo()->member("__delitem__"); + const char* methodName = isSetItem ? "__setitem__" : "__delitem__"; + PythonQtMemberInfo opSlot = wrapper->classInfo()->member(methodName); if (opSlot._type == PythonQtMemberInfo::Slot) { PyObject* args = PyTuple_New(isSetItem?2:1); @@ -141,6 +140,8 @@ static int PythonQtInstanceWrapper_setitem(PyObject* self, PyObject* index, PyOb Py_DECREF(args); return PyErr_Occurred()?-1:0; } else { + QString e = QString("No method '%1' on class '%2'").arg(methodName).arg(QString(wrapper->classInfo()->className())); + PyErr_SetString(PyExc_AttributeError, QStringToPythonConstCharPointer(e)); return -1; } }