mirror of
https://github.com/thp/pyotherside.git
synced 2025-01-28 23:52:55 +08:00
Error handling when using call() without a parameter list
This commit is contained in:
parent
2642910c08
commit
6567f9e8b9
@ -186,7 +186,15 @@ QPython::call_sync(QString func, QVariant args)
|
||||
QVariant v;
|
||||
|
||||
PyObject *argl = convertQVariantToPyObject(args);
|
||||
assert(PyList_Check(argl));
|
||||
if (!PyList_Check(argl)) {
|
||||
Py_DECREF(callable);
|
||||
Py_XDECREF(argl);
|
||||
emit error(QString("Not a parameter list in call to %1: %2")
|
||||
.arg(func).arg(args.toString()));
|
||||
priv->leave();
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
PyObject *argt = PyList_AsTuple(argl);
|
||||
Py_DECREF(argl);
|
||||
PyObject *o = PyObject_Call(callable, argt, NULL);
|
||||
|
27
tests/test_callparam/test_callparam.qml
Normal file
27
tests/test_callparam/test_callparam.qml
Normal file
@ -0,0 +1,27 @@
|
||||
import QtQuick 2.0
|
||||
import io.thp.pyotherside 1.0
|
||||
|
||||
Rectangle {
|
||||
id: page
|
||||
width: 300
|
||||
height: 300
|
||||
|
||||
Python {
|
||||
Component.onCompleted: {
|
||||
// We use call_sync() instead of call() in order
|
||||
// to guarantee the right ordering of Python's output
|
||||
// and the output of the JS engine for the error
|
||||
|
||||
// This should fail with an error:
|
||||
// "Not a parameter list in call to print: 123"
|
||||
call_sync('print', 123);
|
||||
|
||||
// This should work and print "123" on the console
|
||||
call_sync('print', [123]);
|
||||
}
|
||||
|
||||
onError: {
|
||||
console.log('Received error: ' + traceback);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user