From c7904338f8707a30c70f1ddf62ec740cae255f36 Mon Sep 17 00:00:00 2001 From: Alex Hughes Date: Sun, 8 Apr 2018 13:45:41 -0700 Subject: 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 --- sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sources/shiboken2/generator/shiboken2') 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"; } } -- cgit v1.2.3