aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-05-01 14:47:05 +0200
committerChristian Tismer <tismer@stackless.com>2021-05-03 09:31:02 +0200
commit39ba36db0fb8a3c722cb23e02f38abab9c67592c (patch)
tree031b852de76e723a62e21a8018fcd96775c56b31
parent9dc33d2aa2809efe5548896568907eada85eb3c5 (diff)
__feature__: Ensure that features are not affected by other imports
Imports should not touch the feature dict unless they are feature imports. This was a small error in the import logic. Change-Id: I16045fffb4b770861ff2efba674667894e0798e5 Fixes: PYSIDE-1548 Pick-to: 5.15 Pick-to: 6.0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--sources/pyside6/tests/QtCore/snake_prop_feature_test.py2
-rw-r--r--sources/shiboken6/shibokenmodule/files.dir/shibokensupport/feature.py12
2 files changed, 7 insertions, 7 deletions
diff --git a/sources/pyside6/tests/QtCore/snake_prop_feature_test.py b/sources/pyside6/tests/QtCore/snake_prop_feature_test.py
index 6bfcddec0..7925c4c0c 100644
--- a/sources/pyside6/tests/QtCore/snake_prop_feature_test.py
+++ b/sources/pyside6/tests/QtCore/snake_prop_feature_test.py
@@ -91,6 +91,8 @@ class FeatureTest(unittest.TestCase):
window.modal
from __feature__ import snake_case, true_property
+ #PYSIDE-1548: Make sure that another import does not clear the features.
+ import sys
self.assertTrue(isinstance(QWidget.modal, property))
self.assertTrue(isinstance(window.modal, bool))
diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/feature.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/feature.py
index 2ee12a6b4..b6d6657fe 100644
--- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/feature.py
+++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/feature.py
@@ -118,6 +118,7 @@ def feature_import(name, *args, **kwargs):
# PYSIDE-1368: The `__name__` attribute does not need to exist in all modules.
# PYSIDE-1398: sys._getframe(1) may not exist when embedding.
# PYSIDE-1338: The "1" below is the redirection in loader.py .
+ # PYSIDE-1548: Ensure that features are not affected by other imports.
calling_frame = _cf = sys._getframe(1).f_back
importing_module = _cf.f_globals.get("__name__", "__main__") if _cf else "__main__"
existing = pyside_feature_dict.get(importing_module, 0)
@@ -145,13 +146,10 @@ def feature_import(name, *args, **kwargs):
sys.modules["PySide6.QtCore"].__init_feature__()
return sys.modules["__feature__"]
- if name.split(".")[0] == "PySide6":
- # This is a module that imports PySide6.
- flag = existing if isinstance(existing, int) else 0
- else:
- # This is some other module. Ignore it in switching.
- flag = -1
- pyside_feature_dict[importing_module] = flag
+ if importing_module not in pyside_feature_dict:
+ # Ignore new modules if not from PySide.
+ default = 0 if name.split(".")[0] == "PySide6" else -1
+ pyside_feature_dict[importing_module] = default
# Redirect to the original import
return None