diff options
Diffstat (limited to 'sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py')
-rw-r--r-- | sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py index 8d970956b..20c791cc1 100644 --- a/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py +++ b/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py @@ -110,8 +110,15 @@ def _parse_line(line): argstr = ret.arglist.replace("->", ".deref.") arglist = _parse_arglist(argstr) args = [] - for arg in arglist: - name, ann = arg.split(":") + for idx, arg in enumerate(arglist): + tokens = arg.split(":") + if len(tokens) < 2: + if idx == 0 and tokens[0] == "self": + tokens = 2 * tokens # "self: self" + else: + warnings.warn('Invalid argument "{}" in "{}".'.format(arg, line)) + continue + name, ann = tokens if name in keyword.kwlist: if LIST_KEYWORDS: print("KEYWORD", ret) @@ -165,6 +172,11 @@ def try_to_guess(thing, valtype): return ret return None +def get_name(thing): + if isinstance(thing, type): + return getattr(thing, "__qualname__", thing.__name__) + else: + return thing.__name__ def _resolve_value(thing, valtype, line): if thing in ("0", "None") and valtype: @@ -172,7 +184,7 @@ def _resolve_value(thing, valtype, line): return None map = type_map[valtype] # typing.Any: '_SpecialForm' object has no attribute '__name__' - name = map.__name__ if hasattr(map, "__name__") else str(map) + name = get_name(map) if hasattr(map, "__name__") else str(map) thing = "zero({})".format(name) if thing in type_map: return type_map[thing] @@ -212,7 +224,8 @@ def to_string(thing): return thing if hasattr(thing, "__name__"): dot = "." in str(thing) - return thing.__module__ + "." + thing.__name__ if dot else thing.__name__ + name = get_name(thing) + return thing.__module__ + "." + name if dot else name # Note: This captures things from the typing module: return str(thing) @@ -327,15 +340,15 @@ def calculate_props(line): _defaults.append(default) defaults = tuple(_defaults) returntype = parsed.returntype - if returntype is not None: - annotations["return"] = _resolve_type(returntype, line, 0, handle_retvar) + # PYSIDE-1383: We need to handle `None` explicitly. + annotations["return"] = (_resolve_type(returntype, line, 0, handle_retvar) + if returntype is not None else None) props = SimpleNamespace() props.defaults = defaults props.kwdefaults = {} props.annotations = annotations props.varnames = varnames = tuple(tup[0] for tup in arglist) funcname = parsed.funcname - props.fullname = funcname shortname = funcname[funcname.rindex(".")+1:] props.name = shortname props.multi = parsed.multi @@ -352,7 +365,6 @@ def fix_variables(props, line): if retvar and isinstance(retvar, (ResultVariable, ArrayLikeVariable)): # Special case: a ResultVariable which is the result will always be an array! annos["return"] = retvar = typing.List[retvar.type] - fullname = props.fullname varnames = list(props.varnames) defaults = list(props.defaults) diff = len(varnames) - len(defaults) @@ -442,8 +454,7 @@ def pyside_type_init(type_key, sig_strings): multi_props.append(props) if multi > 0: continue - fullname = props.pop("fullname") - multi_props = {"multi": multi_props, "fullname": fullname} + multi_props = {"multi": multi_props} ret[shortname] = multi_props dprint(multi_props) multi_props = [] |