diff options
author | Alex Hughes <ahughesalex@gmail.com> | 2018-04-08 13:45:41 -0700 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2020-09-08 17:57:33 +0200 |
commit | c7904338f8707a30c70f1ddf62ec740cae255f36 (patch) | |
tree | a3c6bffb2fdeffc6885bd34a324ae391dbb205e4 /sources/pyside2/doc | |
parent | c5d47637c7376358a10f0f845e443478058a5430 (diff) |
Implement default __ne__ and __eq__ for all PySide types
PySide types have been following the Qt implementation of
comparisons, completely.
This is not correct for Python, because the Python default has
the operators `==` and `!=` at least. They are needed for tests
like `obj in collection`.
We fix this by redirecting the default case to
`PyBaseObject_Type.tp_richcompare`.
This is the correct way to fix it, because for types which do not
define `tp_richcompare', this is the default, anyway.
From the original patch, the test case is still in use.
Old message:
Implement __ne__ and __eq__ for QTreeWidgetItem
Testing if a QTreeWidgetItem belongs to a list raises a NotImplementedError.
I have exposed the operator== and the operator!= from C++ to shiboken which has solved our eq operator issue.
Implemented the test from PYSIDE-74 for the QTreeWidgetItem eq operator and the ne operator.
This also allows us to have the behavior "QTreeWidgetItem in ['a']" and "QTreeWidgetItem not in ['a']".
Adding qtreewidgetitem_test.py to CMakeFiles.txt
Fixes: PYSIDE-74
Change-Id: Id221c0163fc8c2d85730c4c26f22db5f61710706
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside2/doc')
-rw-r--r-- | sources/pyside2/doc/considerations.rst | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/sources/pyside2/doc/considerations.rst b/sources/pyside2/doc/considerations.rst index f05d929b5..b5eae7d86 100644 --- a/sources/pyside2/doc/considerations.rst +++ b/sources/pyside2/doc/considerations.rst @@ -133,3 +133,17 @@ Abandoned Alternative We also tried an alternative implementation with a ``qApp()`` function that was more *pythonic* and problem free, but many people liked the ``qApp`` macro better for its brevity, so here it is. + + +Rich Comparison +~~~~~~~~~~~~~~~ + +There was a long-standing bug in the ``tp_richcompare`` implementation of PySide classes. + +* When a class did not implement it, the default implementation of ``object`` is used. + This implements ``==`` and ``!=`` like the ``is`` operator. + +* When a class implements only a single function like ``<``, then the default implementation + was disabled, and expressions like ``obj in sequence`` failed with ``NotImplemented``. + +This oversight was fixed in version 5.15.1 . |