aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpysideqml
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2025-11-03 20:24:45 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2025-11-14 18:14:56 +0100
commit71745091ed3fc637a046c0d02c193bcbc7f5b565 (patch)
treecfa2f61b34bd4c16988b8204b45f30e51b33015e /sources/pyside6/libpysideqml
parentd5a52173d34137ed3ac7ceb3e91bb6dcc20b75a7 (diff)
libpyside/libpysideqml: Refactor property argument parsing
Take over arguments only if they are neither null nor Py_None and simplify checks accordingly. Make the error message more precise. With that 2aff6a35a9aa2f233c9801456daa6986437d2647, can be partially reverted. Task-number: PYSIDE-3227 Change-Id: I335db395e969415022581e1ec95a7e3715725bf1 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/libpysideqml')
-rw-r--r--sources/pyside6/libpysideqml/pysideqmllistproperty.cpp44
1 files changed, 21 insertions, 23 deletions
diff --git a/sources/pyside6/libpysideqml/pysideqmllistproperty.cpp b/sources/pyside6/libpysideqml/pysideqmllistproperty.cpp
index 91bfaf044..2beffdedf 100644
--- a/sources/pyside6/libpysideqml/pysideqmllistproperty.cpp
+++ b/sources/pyside6/libpysideqml/pysideqmllistproperty.cpp
@@ -58,19 +58,15 @@ static int propListTpInit(PyObject *self, PyObject *args, PyObject *kwds)
auto *data = static_cast<QmlListPropertyPrivate *>(pySelf->d);
char *doc{};
+ PyObject *append{}, *count{}, *at{}, *clear{}, *replace{}, *removeLast{}, *notify{};
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O|OOOOOOsObbbbbb:QtQml.ListProperty",
const_cast<char **>(kwlist),
&data->type,
- &data->append,
- &data->count,
- &data->at,
- &data->clear,
- &data->replace,
- &data->removeLast,
+ &append, &count, &at, &clear, &replace, &removeLast,
/*s*/ &doc,
- /*O*/ &(data->notify), // PySideProperty
+ /*O*/ &notify, // PySideProperty
/*bbb*/ &(data->designable),
&(data->scriptable),
&(data->stored),
@@ -80,6 +76,18 @@ static int propListTpInit(PyObject *self, PyObject *args, PyObject *kwds)
return -1;
}
+ if (!PySidePropertyPrivate::assignCheckCallable(append, "append", &data->append)
+ || !PySidePropertyPrivate::assignCheckCallable(count, "count", &data->count)
+ || !PySidePropertyPrivate::assignCheckCallable(at, "at", &data->at)
+ || !PySidePropertyPrivate::assignCheckCallable(clear, "clear", &data->clear)
+ || !PySidePropertyPrivate::assignCheckCallable(replace, "replace", &data->replace)
+ || !PySidePropertyPrivate::assignCheckCallable(removeLast, "removeLast", &data->removeLast)) {
+ return -1;
+ }
+
+ if (notify != nullptr && notify != Py_None)
+ data->notify = notify;
+
if (doc)
data->doc = doc;
else
@@ -93,16 +101,6 @@ static int propListTpInit(PyObject *self, PyObject *args, PyObject *kwds)
return -1;
}
- if ((data->append && data->append != Py_None && !PyCallable_Check(data->append)) ||
- (data->count && data->count != Py_None && !PyCallable_Check(data->count)) ||
- (data->at && data->at != Py_None && !PyCallable_Check(data->at)) ||
- (data->clear && data->clear != Py_None && !PyCallable_Check(data->clear)) ||
- (data->replace && data->replace != Py_None && !PyCallable_Check(data->replace)) ||
- (data->removeLast && data->removeLast != Py_None && !PyCallable_Check(data->removeLast))) {
- PyErr_Format(PyExc_TypeError, "Non-callable parameter given");
- return -1;
- }
-
data->typeName = QByteArrayLiteral("QQmlListProperty<QObject>");
return 0;
@@ -274,12 +272,12 @@ void QmlListPropertyPrivate::metaCall(PyObject *source, QMetaObject::Call call,
Shiboken::Conversions::pythonToCppPointer(qobjectType, source, &qobj);
QQmlListProperty<QObject> declProp(
qobj, this,
- append && append != Py_None ? &propListAppender : nullptr,
- count && count != Py_None ? &propListCount : nullptr,
- at && at != Py_None ? &propListAt : nullptr,
- clear && clear != Py_None ? &propListClear : nullptr,
- replace && replace != Py_None ? &propListReplace : nullptr,
- removeLast && removeLast != Py_None ? &propListRemoveLast : nullptr);
+ append != nullptr ? &propListAppender : nullptr,
+ count != nullptr ? &propListCount : nullptr,
+ at != nullptr ? &propListAt : nullptr,
+ clear != nullptr ? &propListClear : nullptr,
+ replace != nullptr ? &propListReplace : nullptr,
+ removeLast != nullptr ? &propListRemoveLast : nullptr);
// Copy the data to the memory location requested by the meta call
void *v = args[0];