diff options
author | Christian Tismer <tismer@stackless.com> | 2021-05-01 14:47:05 +0200 |
---|---|---|
committer | Christian Tismer <tismer@stackless.com> | 2021-05-03 16:31:52 +0200 |
commit | e9b8c4a5cf8c35905ba4c761e931cc4a86dab58f (patch) | |
tree | de83030cbb8b041b01e3c94098e9f84d914096ea | |
parent | 7f346c39f345e7b741ab6d5ce70cb91fd0ff80ad (diff) |
__feature__: Ensure that features are not affected by other imports6.0
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
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
(cherry picked from commit 39ba36db0fb8a3c722cb23e02f38abab9c67592c)
4 files changed, 11 insertions, 9 deletions
diff --git a/sources/pyside6/PySide6/support/generate_pyi.py b/sources/pyside6/PySide6/support/generate_pyi.py index 32f43d804..b55bf4ecd 100644 --- a/sources/pyside6/PySide6/support/generate_pyi.py +++ b/sources/pyside6/PySide6/support/generate_pyi.py @@ -277,7 +277,8 @@ def generate_all_pyi(outpath, options): # now we can import global PySide6, inspect, typing, HintingEnumerator, build_brace_pattern import PySide6 - from PySide6.support.signature import inspect, typing + import inspect + import typing from PySide6.support.signature.lib.enum_sig import HintingEnumerator from PySide6.support.signature.lib.tool import build_brace_pattern diff --git a/sources/pyside6/tests/QtCore/snake_prop_feature_test.py b/sources/pyside6/tests/QtCore/snake_prop_feature_test.py index 5f9328329..fe7de8ab3 100644 --- a/sources/pyside6/tests/QtCore/snake_prop_feature_test.py +++ b/sources/pyside6/tests/QtCore/snake_prop_feature_test.py @@ -89,6 +89,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(QtWidgets.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 0fa58d22f..50ba751c9 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/feature.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/feature.py @@ -103,6 +103,7 @@ Note: This are two imports. def _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-1548: Ensure that features are not affected by other imports. calling_frame = _cf = sys._getframe().f_back importing_module = _cf.f_globals.get("__name__", "__main__") if _cf else "__main__" existing = pyside_feature_dict.get(importing_module, 0) @@ -130,13 +131,11 @@ def _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 original_import(name, *args, **kwargs) _is_initialized = False 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 400c36de5..e09e525fd 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 @@ -49,7 +49,7 @@ by producing a lot of clarity. import sys import types -from shibokensupport.signature import inspect +import inspect from shibokensupport.signature import get_signature as get_sig |