diff options
author | Christian Tismer <tismer@stackless.com> | 2021-05-24 17:23:55 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-05-26 08:00:44 +0000 |
commit | 2f114cfe6235731fb98ea4b60325b3db12d6752b (patch) | |
tree | 2e92948b44f72d616d7af9b66dd79fe387ccdeb0 | |
parent | 8c21021a4e3da7b4ff93224eb9b01a175292107d (diff) |
__feature__: Fix default instances of modified .pyi files
When modified .pyi files are generated, a handful of default
expressions are calling back into PySide functions.
These cases were not handled, yet and created complaints
when switched to snake_case. Although default expressions are
suppressed by "..." in .pyi files, this created error messages
from parser.py .
Task-number: PYSIDE-1019
Change-Id: I30c1cdef34d56fb96ffeac1f40fbf573aa539352
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
(cherry picked from commit 4060161ba54087328c33c74df23e3352ac9d00a1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py index eff73d8a4..32cb10319 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py @@ -47,6 +47,7 @@ from shibokensupport.signature.mapping import (type_map, update_mapping, namespace, typing, _NotCalled, ResultVariable, ArrayLikeVariable) from shibokensupport.signature.lib.tool import (SimpleNamespace, build_brace_pattern) +from shibokensupport import feature _DEBUG = False LIST_KEYWORDS = False @@ -138,7 +139,48 @@ def _parse_line(line): return vars(ret) +def _using_snake_case(): + # Note that this function should stay here where we use snake_case. + if "PySide6.QtCore" not in sys.modules: + return False + from PySide6.QtCore import QDir + return hasattr(QDir, "cd_up") + + +def _handle_instance_fixup(thing): + """ + Default expressions using instance methods like + (...,device=QPointingDevice.primaryPointingDevice()) + need extra handling for snake_case. These are: + QPointingDevice.primaryPointingDevice() + QInputDevice.primaryKeyboard() + QKeyCombination.fromCombined(0) + QSslConfiguration.defaultConfiguration() + """ + match = re.search(r"\w+\(", thing) + if not match: + return thing + start, stop = match.start(), match.end() - 1 + pre, func, args = thing[:start], thing[start : stop], thing[stop:] + if func[0].isupper() or func.startswith("gl") and func[2:3].isupper(): + return thing + # Now convert this string to snake case. + snake_func = "" + for idx, char in enumerate(func): + if char.isupper(): + if idx and func[idx - 1].isupper(): + # two upper chars are forbidden + return things + snake_func += f"_{char.lower()}" + else: + snake_func += char + return f"{pre}{snake_func}{args}" + + def make_good_value(thing, valtype): + # PYSIDE-1019: Handle instance calls (which are really seldom) + if "(" in thing and _using_snake_case(): + thing = _handle_instance_fixup(thing) try: if thing.endswith("()"): thing = f'Default("{thing[:-2]}")' |