diff options
author | Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2018-04-25 17:49:25 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2018-06-21 14:42:51 +0000 |
commit | aa75437f9119d997dd290471ac3e2cc88ca88bf1 (patch) | |
tree | 25bd1488cde8b60c14190d40dd03725f11f8d537 /sources/shiboken2 | |
parent | 27a3402507364e15c37fcabfa025c2fed36146f0 (diff) |
Fix QVariant conversions when using PySequences
Currently we transform QVariant arguments to internal
types, starting from the Python ones, to others
related to shiboken.
After checking if the current object is a PyDict
we proceed to check if it's a PySequence.
PySequence is the complementary 'sequence-like' type of PyDict,
and allows finite and infinite sequences,
like lists or generators.
The problem is that when one implements a class
which includes the __getitem__ method, Python already
thinks that it correspond to a PySequence, then
we try to get the elements to transform into
a QList<QVariant> but it fails at the first attempt.
The solution was to not assume that all PySequences
have finite length (or a length), and also to have
a fallback case similarly to the PyDict treatment,
wrapping the PyObject as a QVariant.
Task-number: PYSIDE-641
Change-Id: I3b755f47ed076147024de38e5e0a86932d981f88
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2')
-rw-r--r-- | sources/shiboken2/libshiboken/sbkconverter.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/sources/shiboken2/libshiboken/sbkconverter.cpp b/sources/shiboken2/libshiboken/sbkconverter.cpp index d4d3ac899..f1be99a36 100644 --- a/sources/shiboken2/libshiboken/sbkconverter.cpp +++ b/sources/shiboken2/libshiboken/sbkconverter.cpp @@ -391,8 +391,11 @@ bool checkSequenceTypes(PyTypeObject* type, PyObject* pyIn) { assert(type); assert(pyIn); - if (!PySequence_Check(pyIn)) + if (PySequence_Size(pyIn) < 0) { + // clear the error if < 0 which means no length at all + PyErr_Clear(); return false; + } const Py_ssize_t size = PySequence_Size(pyIn); for (Py_ssize_t i = 0; i < size; ++i) { if (!PyObject_TypeCheck(AutoDecRef(PySequence_GetItem(pyIn, i)), type)) |