aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6')
-rw-r--r--sources/pyside6/libpyside/feature_select.cpp48
-rw-r--r--sources/pyside6/tests/pysidetest/CMakeLists.txt1
-rw-r--r--sources/pyside6/tests/pysidetest/snake_case_sub.py22
-rw-r--r--sources/pyside6/tests/pysidetest/snake_case_test.py34
4 files changed, 73 insertions, 32 deletions
diff --git a/sources/pyside6/libpyside/feature_select.cpp b/sources/pyside6/libpyside/feature_select.cpp
index b3117d40d..17c6169af 100644
--- a/sources/pyside6/libpyside/feature_select.cpp
+++ b/sources/pyside6/libpyside/feature_select.cpp
@@ -163,15 +163,6 @@ static inline void setCurrentSelectId(PyTypeObject *type, int id)
SbkObjectType_SetReserved(type, id);
}
-static inline PyObject *getCurrentSelectId(PyTypeObject *type)
-{
- int id = SbkObjectType_GetReserved(type);
- // This can be too early.
- if (id < 0)
- id = 0;
- return fast_id_array[id];
-}
-
static bool replaceClassDict(PyTypeObject *type)
{
/*
@@ -218,7 +209,7 @@ static bool addNewDict(PyTypeObject *type, PyObject *select_id)
return true;
}
-static bool moveToFeatureSet(PyTypeObject *type, PyObject *select_id)
+static inline bool moveToFeatureSet(PyTypeObject *type, PyObject *select_id)
{
/*
* Rotate the ring to the given `select_id` and return `true`.
@@ -227,7 +218,6 @@ static bool moveToFeatureSet(PyTypeObject *type, PyObject *select_id)
auto initial_dict = type->tp_dict;
auto dict = initial_dict;
do {
- dict = nextInCircle(dict);
AutoDecRef current_id(getSelectId(dict));
// This works because small numbers are singleton objects.
if (current_id == select_id) {
@@ -235,6 +225,7 @@ static bool moveToFeatureSet(PyTypeObject *type, PyObject *select_id)
setCurrentSelectId(type, select_id);
return true;
}
+ dict = nextInCircle(dict);
} while (dict != initial_dict);
type->tp_dict = initial_dict;
setCurrentSelectId(type, getSelectId(initial_dict));
@@ -290,7 +281,7 @@ static bool createNewFeatureSet(PyTypeObject *type, PyObject *select_id)
return true;
}
-static bool SelectFeatureSetSubtype(PyTypeObject *type, PyObject *select_id)
+static inline bool SelectFeatureSetSubtype(PyTypeObject *type, PyObject *select_id)
{
/*
* This is the selector for one sublass. We need to call this for
@@ -330,28 +321,21 @@ static inline void SelectFeatureSet(PyTypeObject *type)
return;
}
}
+
PyObject *select_id = getFeatureSelectId(); // borrowed
- PyObject *current_id = getCurrentSelectId(type); // borrowed
- static PyObject *undef = fast_id_array[-1];
-
- // PYSIDE-1019: During import PepType_SOTP is still zero.
- if (current_id == undef)
- current_id = select_id = fast_id_array[0];
-
- if (select_id != current_id) {
- PyObject *mro = type->tp_mro;
- Py_ssize_t idx, n = PyTuple_GET_SIZE(mro);
- // We leave 'Shiboken.Object' and 'object' alone, therefore "n - 2".
- for (idx = 0; idx < n - 2; idx++) {
- auto *sub_type = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, idx));
- // When any subtype is already resolved (false), we can stop.
- if (!SelectFeatureSetSubtype(sub_type, select_id))
- break;
- }
- // PYSIDE-1436: Clear all caches for the type and subtypes.
- PyType_Modified(type);
+
+ // PYSIDE-2029: We are no longer caching extremely, but switching safe.
+ PyObject *mro = type->tp_mro;
+ Py_ssize_t idx, n = PyTuple_GET_SIZE(mro);
+ // We leave 'Shiboken.Object' and 'object' alone, therefore "n - 2".
+ for (idx = 0; idx < n - 2; idx++) {
+ auto *sub_type = reinterpret_cast<PyTypeObject *>(PyTuple_GET_ITEM(mro, idx));
+ // When any subtype is already resolved (false), we can stop.
+ if (!SelectFeatureSetSubtype(sub_type, select_id))
+ break;
}
- return;
+ // PYSIDE-1436: Clear all caches for the type and subtypes.
+ PyType_Modified(type);
}
// For cppgenerator:
diff --git a/sources/pyside6/tests/pysidetest/CMakeLists.txt b/sources/pyside6/tests/pysidetest/CMakeLists.txt
index 3965455c9..eaf748517 100644
--- a/sources/pyside6/tests/pysidetest/CMakeLists.txt
+++ b/sources/pyside6/tests/pysidetest/CMakeLists.txt
@@ -144,6 +144,7 @@ PYSIDE_TEST(new_inherited_functions_test.py)
PYSIDE_TEST(notify_id.py)
PYSIDE_TEST(properties_test.py)
PYSIDE_TEST(property_python_test.py)
+PYSIDE_TEST(snake_case_test.py)
PYSIDE_TEST(true_property_test.py)
PYSIDE_TEST(qapp_like_a_macro_test.py)
PYSIDE_TEST(qvariant_test.py)
diff --git a/sources/pyside6/tests/pysidetest/snake_case_sub.py b/sources/pyside6/tests/pysidetest/snake_case_sub.py
new file mode 100644
index 000000000..5056d50bb
--- /dev/null
+++ b/sources/pyside6/tests/pysidetest/snake_case_sub.py
@@ -0,0 +1,22 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+"""
+PYSIDE-2029: Tests that snake_case is isolated from imported modules
+"""
+
+from PySide6.QtWidgets import QWidget
+
+def test_no_snake_case():
+ print(__name__)
+ widget = QWidget()
+ check = widget.sizeHint
diff --git a/sources/pyside6/tests/pysidetest/snake_case_test.py b/sources/pyside6/tests/pysidetest/snake_case_test.py
new file mode 100644
index 000000000..aaa3d3f2a
--- /dev/null
+++ b/sources/pyside6/tests/pysidetest/snake_case_test.py
@@ -0,0 +1,34 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+"""
+PYSIDE-2029: Tests that snake_case is isolated from imported modules
+"""
+
+from PySide6.QtCore import QSize
+from PySide6.QtWidgets import QWidget, QSpinBox
+from __feature__ import snake_case
+from helper.usesqapplication import UsesQApplication
+
+import snake_case_sub
+
+class SnakeCaseNoPropagateTest(UsesQApplication):
+
+ def testSnakeCase(self):
+ # this worked
+ widget = QWidget()
+ check = widget.size_hint
+
+ snake_case_sub.test_no_snake_case()
+
+if __name__ == '__main__':
+ unittest.main()