aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/QtCore
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2022-06-21 10:22:04 +0200
committerChristian Tismer <tismer@stackless.com>2022-07-14 17:21:31 +0200
commitf92b7dcac9537fb091dc15d3ee218f1984d8abef (patch)
tree1bad4ea3cfa9d7c5eeb88450df38a103a7402e99 /sources/pyside6/tests/QtCore
parentda2cf031521815a9559ca784beadb70c7a2852d9 (diff)
PyEnum: Increase compatibility by allowing defaults and old flag names
This patch supports to write Qt.Alignment() instead of Qt.AlignmentFlag(0) Also supported is Qt.AlignmentFlag() which is mapped to Qt.AlignmentFlag(0) This trickery was quite involved since the Python opcodes needed to be analyzed if we have a parameterless call. Only in that case, we insert a partial object which supplies the missing value=0 default. Changing the implementation of PyEnum was not desired because this is highly complicated, not portable and even not possible. The change has been tested with Python 3.6 to 3.11.0b3 . [ChangeLog][shiboken6] The new Python enums are made as compatible to the old ones as possible. It is again allowed to use Qt.Alignment() instead of Qt.AlignmentFlag(0), and a default of 0 is always allowed. Change-Id: If6a93f8210ff6cae4e38251420e1ad5fffbe42cb Pick-to: 6.3 Task-number: PYSIDE-1735 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6/tests/QtCore')
-rw-r--r--sources/pyside6/tests/QtCore/qflags_test.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/sources/pyside6/tests/QtCore/qflags_test.py b/sources/pyside6/tests/QtCore/qflags_test.py
index e38166fb9..a0a543ad4 100644
--- a/sources/pyside6/tests/QtCore/qflags_test.py
+++ b/sources/pyside6/tests/QtCore/qflags_test.py
@@ -110,5 +110,24 @@ class QFlagsWrongType(unittest.TestCase):
self.assertEqual(operator.or_(Qt.NoItemFlags, 43), 43)
+class QEnumFlagDefault(unittest.TestCase):
+ """
+ Check that old flag and enum syntax can be used.
+ The signatures of these surrogate functions intentionally do not exist
+ because people should learn to use the new Enums correctly.
+ """
+ def testOldQFlag(self):
+ self.assertEqual(Qt.AlignmentFlag(), Qt.AlignmentFlag(0))
+ oldFlag = Qt.Alignment()
+ oldEnum = Qt.AlignmentFlag()
+ self.assertEqual(type(oldFlag), Qt.Alignment)
+ self.assertEqual(type(oldEnum), Qt.AlignmentFlag)
+ if sys.pyside63_option_python_enum:
+ self.assertEqual(type(oldFlag), type(oldEnum))
+ else:
+ with self.assertRaises(AssertionError):
+ self.assertEqual(type(oldFlag), type(oldEnum))
+
+
if __name__ == '__main__':
unittest.main()