From b2a09c05e9cc2503f1609f720060558c0db2fe03 Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Thu, 7 Feb 2019 14:19:53 +0100 Subject: Fix Shiboken.ObjectType.__new__ for Python 2.7 type(QtWidgets.QWidget).__new__(type(QtWidgets.QWidget), "", (), {}) gave a problem in Python 2.7 after transition to PEP 384. The reason for the problem is a check in Python 2.7 that tries to find out if the function used to create a new object is a secure (builtin) one. Therefore, all new types that are generated by a Python function are filtered out. Unfortunately, Python 2.7 did that assuming that only Python classes are heap types. This is at least no longer true since Python 3 migrated to the new type API where all new types are heap types. The internal check was therefore changed to do the test for a builtin "new" function differently. But not in Python 2.7 . The workaround was to create the Shiboken.ObjectType as a heap type and then remove that flag from the type. This seems to have no bad effects, probably because the types did barely change when doing the transition. Anyway, I will stay tuned and watch out if this later creates a problem. Task-number: PYSIDE-816 Change-Id: Ia596716b0e5dff3f1a7155ab6765186ef0b9d179 Reviewed-by: Cristian Maureira-Fredes --- sources/pyside2/tests/QtWidgets/qwidget_test.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'sources/pyside2/tests') diff --git a/sources/pyside2/tests/QtWidgets/qwidget_test.py b/sources/pyside2/tests/QtWidgets/qwidget_test.py index 028751ba7..d0a4a8dfa 100644 --- a/sources/pyside2/tests/QtWidgets/qwidget_test.py +++ b/sources/pyside2/tests/QtWidgets/qwidget_test.py @@ -1,6 +1,6 @@ ############################################################################# ## -## Copyright (C) 2016 The Qt Company Ltd. +## Copyright (C) 2019 The Qt Company Ltd. ## Contact: https://www.qt.io/licensing/ ## ## This file is part of the test suite of Qt for Python. @@ -52,6 +52,11 @@ class QWidgetTest(UsesQApplication): def testInheritance(self): self.assertRaises(TypeError, QWidgetInherit) + if sys.version_info[0] < 3: + def testCallType_Issue_816(self): + thing = type(QWidget).__new__(type(QWidget), "", (), {}) + self.assertEqual(repr(thing), "") + class QWidgetVisible(UsesQApplication): def testBasic(self): -- cgit v1.2.3