QVariant.toList returns a list when it contains a python sequence.
This commit is contained in:
parent
956d6fd530
commit
9b338f9857
2 changed files with 21 additions and 0 deletions
|
|
@ -1744,6 +1744,22 @@
|
||||||
%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%CPPSELF.typeName());
|
%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%CPPSELF.typeName());
|
||||||
</inject-code>
|
</inject-code>
|
||||||
</modify-function>
|
</modify-function>
|
||||||
|
<modify-function signature="toList()const">
|
||||||
|
<inject-code class="target" position="beginning">
|
||||||
|
if (%CPPSELF.userType() == qMetaTypeId<PyObjectHolder>()) {
|
||||||
|
PyObject* val = %CPPSELF.value<PyObjectHolder>();
|
||||||
|
if (PySequence_Check(val)) {
|
||||||
|
%PYARG_0 = val;
|
||||||
|
Py_INCREF(val);
|
||||||
|
} else {
|
||||||
|
%PYARG_0 = Py_None;
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%CPPSELF.%FUNCTION_NAME());
|
||||||
|
}
|
||||||
|
</inject-code>
|
||||||
|
</modify-function>
|
||||||
<modify-function signature="toDouble(bool*)const">
|
<modify-function signature="toDouble(bool*)const">
|
||||||
<modify-argument index="1">
|
<modify-argument index="1">
|
||||||
<remove-argument/>
|
<remove-argument/>
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,11 @@ class QVariantConstructor(unittest.TestCase):
|
||||||
self.assertEqual(variant.type(), QVariant.Size)
|
self.assertEqual(variant.type(), QVariant.Size)
|
||||||
self.assertEqual(variant.toSize(), mysize)
|
self.assertEqual(variant.toSize(), mysize)
|
||||||
|
|
||||||
|
def testToList(self):
|
||||||
|
v = QVariant((1,2,3))
|
||||||
|
self.assertEqual(v.toList(), (1, 2, 3))
|
||||||
|
v = QVariant([0,1,2])
|
||||||
|
self.assertEqual(v.toList(), [0, 1, 2])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue