diff options
| author | Christian Tismer <tismer@stackless.com> | 2022-11-21 12:06:18 +0100 |
|---|---|---|
| committer | Christian Tismer <tismer@stackless.com> | 2022-11-29 17:57:32 +0100 |
| commit | 7377d2b8130ce7290775cd8a343e75c0561fc854 (patch) | |
| tree | cbf0c9f8e005f0e61d7959950da7fc255ccf7d55 /sources/pyside6/tests/pysidetest/snake_case_test.py | |
| parent | 916bae507f76f4f063af81439f17cf11c914b4bd (diff) | |
__feature__: heavily rework the context switching
The example of the issue shows the qasync.py module which
fails miserably when using snake_case.
The reason:
-----------
Reason is the way how feature switching is implemented.
Modules like qasync get a default switching of "ignore".
This ignores that the qasync module itself imports QtCore,
and feature switching is of course relevant, suggesting
a default setting of "normal" (explicitly no features).
The real problem:
-----------------
Testing the simple approach showed a serious problem with
feature switching: The functions get switched when a certain
function (getattr etc.) is called.
But the switching is sometimes not done due to a caching problem.
This fix removes caching that was wrong. Optimization will
be done in a different step with a different approach.
This Change was not qasync specific, but happens with PySide imports.
Actions done:
- adjust the inline structure
- implement a feature_imported callback
- identify Python functions that use PySide during import
[ChangeLog][PySide6] __feature__ switching now works even with
recursive imports like in the qasync module.
Fixes: PYSIDE-2029
Change-Id: I3340f54f293083a09fb509383688f73bbd9b60ae
Pick-to: 6.4
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6/tests/pysidetest/snake_case_test.py')
| -rw-r--r-- | sources/pyside6/tests/pysidetest/snake_case_test.py | 34 |
1 files changed, 34 insertions, 0 deletions
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() |
