aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2020-08-20 17:48:25 +0200
committerChristian Tismer <tismer@stackless.com>2020-08-24 12:24:35 +0200
commitacb54ac2235199cbb710799d7934e56737bacfbb (patch)
treeda9dcc722e7d52331e64983f1543571bfaea3e73
parentb8663129f275e2a1648090cf42c3bc673fad956c (diff)
signature: pass `self` directly from parser
The signature module took the info from the PyCFunction flags for a long time to check if something is a function, method or staticmethod. It turned out that there are functions with multiple signatures where the method/staticmethod info varies in the signatures. This invalidated the PyCFunction flag usage. Instead, we now compute that info directly from abstractmetalang.cpp which has access to the correct info. Fixes: PYSIDE-1328 Change-Id: I6ba7237efcc486de014184b1787d05d87bee5a5e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/pyside2/PySide2/support/generate_pyi.py12
-rw-r--r--sources/shiboken2/generator/shiboken2/cppgenerator.cpp4
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py21
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py13
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py5
-rw-r--r--sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py29
6 files changed, 46 insertions, 38 deletions
diff --git a/sources/pyside2/PySide2/support/generate_pyi.py b/sources/pyside2/PySide2/support/generate_pyi.py
index af9f4d4f5..d71ee338e 100644
--- a/sources/pyside2/PySide2/support/generate_pyi.py
+++ b/sources/pyside2/PySide2/support/generate_pyi.py
@@ -171,7 +171,7 @@ class Formatter(Writer):
yield
@contextmanager
- def function(self, func_name, signature, modifier=None):
+ def function(self, func_name, signature):
if self.after_enum() or func_name == "__init__":
self.print()
key = func_name
@@ -179,16 +179,16 @@ class Formatter(Writer):
if type(signature) == type([]):
for sig in signature:
self.print('{spaces}@typing.overload'.format(**locals()))
- self._function(func_name, sig, modifier, spaces)
+ self._function(func_name, sig, spaces)
else:
- self._function(func_name, signature, modifier, spaces)
+ self._function(func_name, signature, spaces)
if func_name == "__init__":
self.print()
yield key
- def _function(self, func_name, signature, modifier, spaces):
- if modifier:
- self.print('{spaces}@{modifier}'.format(**locals()))
+ def _function(self, func_name, signature, spaces):
+ if "self" not in tuple(signature.parameters.keys()):
+ self.print('{spaces}@staticmethod'.format(**locals()))
signature = self.optional_replacer(signature)
self.print('{spaces}def {func_name}{signature}: ...'.format(**locals()))
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
index 260607479..73f1a10cf 100644
--- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
+++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp
@@ -4683,6 +4683,10 @@ void CppGenerator::writeSignatureInfo(QTextStream &s, const AbstractMetaFunction
for (const AbstractMetaFunction *f : overloads) {
QStringList args;
+ // PYSIDE-1328: `self`-ness cannot be computed in Python because there are mixed cases.
+ // Toplevel functions like `PySide2.QtCore.QEnum` are always self-less.
+ if (!(f->isStatic()) && f->ownerClass())
+ args << QLatin1String("self");
const AbstractMetaArgumentList &arguments = f->arguments();
for (const AbstractMetaArgument *arg : arguments) {
QString strArg = arg->type()->pythonSignature();
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py
index 384273d92..51ce60bfa 100644
--- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/layout.py
@@ -231,17 +231,14 @@ def create_signature(props, key):
# this is the basic layout of a signature
varnames = props["varnames"]
if layout.definition:
- if sig_kind == "function":
- pass
- elif sig_kind == "method":
- varnames = ("self",) + varnames
- elif sig_kind == "staticmethod":
- pass
- elif sig_kind == "classmethod":
- varnames = ("klass",) + varnames
- else:
- raise SystemError("Methods must be function, method, staticmethod"
- " or classmethod")
+ # PYSIDE-1328: We no longer use info from the sig_kind which is
+ # more complex for multiple signatures. We now get `self` from the
+ # parser.
+ pass
+ else:
+ if "self" in varnames[:1]:
+ varnames = varnames[1:]
+
# calculate the modifications
defaults = props["defaults"][:]
if not layout.defaults:
@@ -259,6 +256,8 @@ def create_signature(props, key):
elif name.startswith("*"):
kind = _VAR_POSITIONAL
ann = annotations.get(name, _empty)
+ if ann == "self":
+ ann = _empty
name = name.lstrip("*")
defpos = idx - len(varnames) + len(defaults)
default = defaults[defpos] if defpos >= 0 else _empty
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
index fa4d5e77c..371b3ca4a 100644
--- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py
@@ -154,14 +154,11 @@ class ExactEnumerator(object):
self.fmt.class_name = class_name
ret.update(self.function("__init__", klass))
for func_name, func in functions:
- func_kind = get_signature(func, "__func_kind__")
- modifier = func_kind if func_kind in (
- "staticmethod", "classmethod") else None
- ret.update(self.function(func_name, func, modifier))
+ ret.update(self.function(func_name, func))
self.fmt.level -= 1
return ret
- def function(self, func_name, func, modifier=None):
+ def function(self, func_name, func):
self.fmt.level += 1
ret = self.result_type()
signature = func.__signature__
@@ -192,7 +189,7 @@ class SimplifyingEnumerator(ExactEnumerator):
is desired.
"""
- def function(self, func_name, func, modifier=None):
+ def function(self, func_name, func):
ret = self.result_type()
signature = get_signature(func, 'existence')
sig = stringify(signature) if signature is not None else None
@@ -209,11 +206,11 @@ class HintingEnumerator(ExactEnumerator):
hinting stubs. Only default values are replaced by "...".
"""
- def function(self, func_name, func, modifier=None):
+ def function(self, func_name, func):
ret = self.result_type()
signature = get_signature(func, 'hintingstub')
if signature is not None:
- with self.fmt.function(func_name, signature, modifier) as key:
+ with self.fmt.function(func_name, signature) as key:
ret[key] = signature
return ret
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
index c6d67c4f4..bafea4343 100644
--- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/mapping.py
@@ -345,6 +345,11 @@ type_map.update({
"QStringList*" : ResultVariable(StringList),
})
+# PYSIDE-1328: We need to handle "self" explicitly.
+type_map.update({
+ "self" : "self",
+ })
+
# The Shiboken Part
def init_Shiboken():
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
index bfc5b3a30..9dd7608b3 100644
--- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
+++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py
@@ -110,22 +110,25 @@ def _parse_line(line):
argstr = ret.arglist.replace("->", ".deref.")
arglist = _parse_arglist(argstr)
args = []
- for arg in arglist:
+ for idx, arg in enumerate(arglist):
tokens = arg.split(":")
if len(tokens) < 2:
- warnings.warn('Invalid argument "{}" in "{}".'.format(arg, line))
- else:
- name, ann = tokens
- if name in keyword.kwlist:
- if LIST_KEYWORDS:
- print("KEYWORD", ret)
- name = name + "_"
- if "=" in ann:
- ann, default = ann.split("=", 1)
- tup = name, ann, default
+ if idx == 0 and tokens[0] == "self":
+ tokens = 2 * tokens # "self: self"
else:
- tup = name, ann
- args.append(tup)
+ warnings.warn('Invalid argument "{}" in "{}".'.format(arg, line))
+ continue
+ name, ann = tokens
+ if name in keyword.kwlist:
+ if LIST_KEYWORDS:
+ print("KEYWORD", ret)
+ name = name + "_"
+ if "=" in ann:
+ ann, default = ann.split("=", 1)
+ tup = name, ann, default
+ else:
+ tup = name, ann
+ args.append(tup)
ret.arglist = args
multi = ret.multi
if multi is not None: