aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/shibokenmodule
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2021-05-24 17:23:55 +0200
committerChristian Tismer <tismer@stackless.com>2021-05-26 07:55:29 +0200
commit4060161ba54087328c33c74df23e3352ac9d00a1 (patch)
tree1638c7da116c59ae49941206acd3b105997d493b /sources/shiboken6/shibokenmodule
parent7079bc4ffc63dd42054014b4b78bff78abed962b (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 Pick-to: 6.1 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken6/shibokenmodule')
-rw-r--r--sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py42
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]}")'