aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/generator
diff options
context:
space:
mode:
authorAlex Hughes <ahughesalex@gmail.com>2018-04-08 13:45:41 -0700
committerChristian Tismer <tismer@stackless.com>2020-09-08 17:57:33 +0200
commitc7904338f8707a30c70f1ddf62ec740cae255f36 (patch)
treea3c6bffb2fdeffc6885bd34a324ae391dbb205e4 /sources/shiboken2/generator
parentc5d47637c7376358a10f0f845e443478058a5430 (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/shiboken2/generator')
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index 73f1a10cf..8465224bb 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -4613,6 +4613,8 @@ void CppGenerator::writeRichCompareFunction(QTextStream &s, const GeneratorConte
s << INDENT << "default:\n";
{
Indentation indent(INDENT);
+ s << INDENT << "// PYSIDE-74: By default, we redirect to object's tp_richcompare (which is `==`, `!=`).\n";
+ s << INDENT << "return FallbackRichCompare(self, " << PYTHON_ARG << ", op);\n";
s << INDENT << "goto " << baseName << "_RichComparison_TypeError;\n";
}
}