aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2022-06-21 10:22:04 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-07-14 15:07:52 +0000
commit02412cd6c3ad0453c2610b6bc03b35c58f298530 (patch)
tree2a8ac23992bcba903872f26d816e542a56b1d0fa
parent252d8bc9a738804fa64196dccde2533bc71dc5e6 (diff)
PyEnum: make forgiving duplicates work with Python 3.11
There was a silent change in PyEnums that turns Enum attributes into properties. This does not harm the Python interface but needed some change in the duplication emulation. Furthermore, new internal enums are created with an underscore name. The meta class was changed from EnumMeta to EnumType. [ChangeLog][shiboken6] The new Python Enums are now compatible with Python 3.11 Change-Id: I3b1ab63dc5eed15a75ebd0f42dddf4001f640c00 Task-number: PYSIDE-1735 Fixes: PYSIDE-1960 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> (cherry picked from commit da2cf031521815a9559ca784beadb70c7a2852d9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--build_scripts/config.py1
-rw-r--r--sources/pyside6/tests/QtCore/qenum_test.py7
-rw-r--r--sources/shiboken6/libshiboken/pep384impl.h2
-rw-r--r--sources/shiboken6/libshiboken/sbkfeature_base.cpp21
-rw-r--r--sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py3
5 files changed, 21 insertions, 13 deletions
diff --git a/build_scripts/config.py b/build_scripts/config.py
index 2342eb1a1..1a7f34b1c 100644
--- a/build_scripts/config.py
+++ b/build_scripts/config.py
@@ -101,6 +101,7 @@ class Config(object):
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
+ 'Programming Language :: Python :: 3.11',
]
self.setup_script_dir = None
diff --git a/sources/pyside6/tests/QtCore/qenum_test.py b/sources/pyside6/tests/QtCore/qenum_test.py
index 4bc92ed86..4b4226064 100644
--- a/sources/pyside6/tests/QtCore/qenum_test.py
+++ b/sources/pyside6/tests/QtCore/qenum_test.py
@@ -207,14 +207,15 @@ class SomeClass(QObject):
QEnum(SomeEnum) # works even without the decorator assignment
-@unittest.skipUnless(HAVE_ENUM, "requires 'enum' module (use 'pip install enum34' for Python 2)")
class TestQEnumMacro(unittest.TestCase):
+ meta_name = "EnumType" if sys.version_info[:2] >= (3, 11) else "EnumMeta"
+
def testTopLevel(self):
- self.assertEqual(type(OuterEnum).__name__, "EnumMeta")
+ self.assertEqual(type(OuterEnum).__name__, self.meta_name)
self.assertEqual(len(OuterEnum.__members__), 2)
def testSomeClass(self):
- self.assertEqual(type(SomeClass.SomeEnum).__name__, "EnumMeta")
+ self.assertEqual(type(SomeClass.SomeEnum).__name__, self.meta_name)
self.assertEqual(len(SomeClass.SomeEnum.__members__), 3)
with self.assertRaises(TypeError):
int(SomeClass.SomeEnum.C) == 6
diff --git a/sources/shiboken6/libshiboken/pep384impl.h b/sources/shiboken6/libshiboken/pep384impl.h
index b3e930202..6fcb3af56 100644
--- a/sources/shiboken6/libshiboken/pep384impl.h
+++ b/sources/shiboken6/libshiboken/pep384impl.h
@@ -342,7 +342,7 @@ LIBSHIBOKEN_API PyObject *PyRun_String(const char *, int, PyObject *, PyObject *
// But this is no problem as we check it's validity for every version.
#define PYTHON_BUFFER_VERSION_COMPATIBLE (PY_VERSION_HEX >= 0x03030000 && \
- PY_VERSION_HEX < 0x030AFFFF)
+ PY_VERSION_HEX < 0x030C0000)
#if !PYTHON_BUFFER_VERSION_COMPATIBLE
# error Please check the buffer compatibility for this python version!
#endif
diff --git a/sources/shiboken6/libshiboken/sbkfeature_base.cpp b/sources/shiboken6/libshiboken/sbkfeature_base.cpp
index af119734c..2348a5d81 100644
--- a/sources/shiboken6/libshiboken/sbkfeature_base.cpp
+++ b/sources/shiboken6/libshiboken/sbkfeature_base.cpp
@@ -122,9 +122,12 @@ PyObject *mangled_type_getattro(PyTypeObject *type, PyObject *name)
* with the complex `tp_getattro` of `QObject` and other instances.
* What we change here is the meta class of `QObject`.
*/
- static getattrofunc type_getattro = PyType_Type.tp_getattro;
- static PyObject *ignAttr1 = PyName::qtStaticMetaObject();
- static PyObject *ignAttr2 = PyMagicName::get();
+ static getattrofunc const type_getattro = PyType_Type.tp_getattro;
+ static PyObject *const ignAttr1 = PyName::qtStaticMetaObject();
+ static PyObject *const ignAttr2 = PyMagicName::get();
+ static PyTypeObject *const EnumMeta = getPyEnumMeta();
+ static PyObject *const _member_map_ = String::createStaticString("_member_map_");
+
if (SelectFeatureSet != nullptr)
type->tp_dict = SelectFeatureSet(type);
auto *ret = type_getattro(reinterpret_cast<PyObject *>(type), name);
@@ -157,13 +160,15 @@ PyObject *mangled_type_getattro(PyTypeObject *type, PyObject *name)
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(dict, &pos, &key, &value)) {
- static auto *EnumMeta = getPyEnumMeta();
if (Py_TYPE(value) == EnumMeta) {
auto *valtype = reinterpret_cast<PyTypeObject *>(value);
- auto *result = PyDict_GetItem(valtype->tp_dict, name);
- if (result) {
- Py_INCREF(result);
- return result;
+ auto *member_map = PyDict_GetItem(valtype->tp_dict, _member_map_);
+ if (member_map && PyDict_Check(member_map)) {
+ auto *result = PyDict_GetItem(member_map, name);
+ if (result) {
+ Py_INCREF(result);
+ return result;
+ }
}
}
}
diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
index a0d430bc4..e7184fa25 100644
--- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
+++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
@@ -166,7 +166,8 @@ class ExactEnumerator(object):
functions.append((func_name, thing))
elif type(type(thing)) is EnumMeta:
# take the real enum name, not what is in the dict
- enums.append((thing_name, type(thing).__qualname__, thing))
+ if not thing_name.startswith("_"):
+ enums.append((thing_name, type(thing).__qualname__, thing))
elif isinstance(thing, property):
properties.append((thing_name, thing))