From aa75437f9119d997dd290471ac3e2cc88ca88bf1 Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Wed, 25 Apr 2018 17:49:25 +0200 Subject: 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 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 --- sources/shiboken2/libshiboken/sbkconverter.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sources/shiboken2/libshiboken') 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)) -- cgit v1.2.3