aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py2
-rw-r--r--sources/shiboken2/libshiboken/qapp_macro.cpp32
2 files changed, 32 insertions, 2 deletions
diff --git a/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py b/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py
index b38cff68b..c58aba82e 100644
--- a/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py
+++ b/sources/pyside2/tests/pysidetest/qapp_like_a_macro_test.py
@@ -40,7 +40,7 @@ class qAppMacroTest(unittest.TestCase):
except ImportError:
QtWidgets = QtGui = QtCore
# qApp is in the builtins
- qApp
+ self.assertEqual(bool(qApp), False)
# and also in certain PySide modules
QtCore.qApp, QtGui.qApp, QtWidgets.qApp
# and they are all the same
diff --git a/sources/shiboken2/libshiboken/qapp_macro.cpp b/sources/shiboken2/libshiboken/qapp_macro.cpp
index f69d0f937..19e985b20 100644
--- a/sources/shiboken2/libshiboken/qapp_macro.cpp
+++ b/sources/shiboken2/libshiboken/qapp_macro.cpp
@@ -67,7 +67,9 @@ qApp_module_index(PyObject *module)
return ret;
}
-#define Py_NONE_TYPE Py_TYPE(Py_None)
+#define PYTHON_IS_PYTHON3 (PY_VERSION_HEX >= 0x03000000)
+#define PYTHON_IS_PYTHON2 (!PYTHON_IS_PYTHON3)
+#define Py_NONE_TYPE Py_TYPE(Py_None)
#if PYTHON_IS_PYTHON3
# define BRACE_OPEN {
@@ -156,6 +158,31 @@ MakeSingletonQAppWrapper(PyTypeObject *type)
return qApp_content;
}
+#if PYTHON_IS_PYTHON2
+
+// Install support in Py_NONE_TYPE for Python 2: 'bool(qApp) == False'.
+static int
+none_bool(PyObject *v)
+{
+ return 0;
+}
+
+static PyNumberMethods none_as_number = {
+ nullptr, /* nb_add */
+ nullptr, /* nb_subtract */
+ nullptr, /* nb_multiply */
+ nullptr, /* nb_divide */
+ nullptr, /* nb_remainder */
+ nullptr, /* nb_divmod */
+ nullptr, /* nb_power */
+ nullptr, /* nb_negative */
+ nullptr, /* nb_positive */
+ nullptr, /* nb_absolute */
+ reinterpret_cast<inquiry>(none_bool), /* nb_nonzero */
+};
+
+#endif
+
static int
setup_qApp_var(PyObject *module)
{
@@ -163,6 +190,9 @@ setup_qApp_var(PyObject *module)
static int init_done = 0;
if (!init_done) {
+#if PYTHON_IS_PYTHON2
+ Py_NONE_TYPE->tp_as_number = &none_as_number;
+#endif
qApp_var = Py_BuildValue("s", "qApp");
if (qApp_var == NULL)
return -1;