From 919c05013eaf74a51948531fc5e2b70cdb28d3ee Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 1 Sep 2023 08:36:05 +0200 Subject: shiboken6: Simplify code handling __bool__ It looks like Py_nb_nonzero is also a Python 2 constant. Complements 890db123f72af6093bac085d0a0e33432fb8d8bb. Task-number: PYSIDE-2446 Change-Id: Ifa347716ae9c801be1b923828fd5a26689b423e7 Reviewed-by: Shyamnath Premnadh Reviewed-by: Qt CI Bot (cherry picked from commit 1a19663aa7c19260e7e2d2078a45b474dcc98d3a) Reviewed-by: Adrian Herrmann --- sources/shiboken6/generator/shiboken/cppgenerator.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 961d410a4..e4aaad78b 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -4897,7 +4897,7 @@ static const QHash &nbFuncs() {u"__iand__"_s, u"Py_nb_inplace_and"_s}, {u"__ixor__"_s, u"Py_nb_inplace_xor"_s}, {u"__ior__"_s, u"Py_nb_inplace_or"_s}, - {boolT(), u"Py_nb_nonzero"_s} + {u"__bool__"_s, u"Py_nb_bool"_s} }; return result; } @@ -4916,16 +4916,13 @@ void CppGenerator::writeTypeAsNumberDefinition(TextStream &s, const AbstractMeta QString baseName = cpythonBaseName(metaClass); if (hasBoolCast(metaClass)) - nb.insert(boolT(), baseName + u"___nb_bool"_s); + nb.insert(u"__bool__"_s, baseName + u"___nb_bool"_s); for (auto it = nbFuncs().cbegin(), end = nbFuncs().cend(); it != end; ++it) { const QString &nbName = it.key(); const auto nbIt = nb.constFind(nbName); - if (nbIt != nb.constEnd()) { - const QString fixednbName = nbName == boolT() - ? u"Py_nb_bool"_s : it.value(); - s << pyTypeSlotEntry(fixednbName, nbIt.value()); - } + if (nbIt != nb.constEnd()) + s << pyTypeSlotEntry(it.value(), nbIt.value()); } } -- cgit v1.2.3