diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-11-27 17:01:22 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-11-27 17:01:22 +0100 |
| commit | 1c9e0d95263480a5ae5d645cabb41f835d1dbb70 (patch) | |
| tree | 25f46dc18d8f8430d46ad365452ce0d8a7c9d9d0 /sources/pyside2/PySide2/support/signature/parser.py | |
| parent | ad14f64972d182fca3e180c08750ca020a91b84e (diff) | |
| parent | 2490c34325bb1b39922582090a4cb69c01726999 (diff) | |
Merge remote-tracking branch 'origin/5.6' into 5.9
Change-Id: I79637555fbfbd596dee4313baf80149d03bb5206
Diffstat (limited to 'sources/pyside2/PySide2/support/signature/parser.py')
| -rw-r--r-- | sources/pyside2/PySide2/support/signature/parser.py | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/sources/pyside2/PySide2/support/signature/parser.py b/sources/pyside2/PySide2/support/signature/parser.py index 0224095b5..0b81dba54 100644 --- a/sources/pyside2/PySide2/support/signature/parser.py +++ b/sources/pyside2/PySide2/support/signature/parser.py @@ -117,45 +117,46 @@ def _parse_line(line): ret["multi"] = int(multi) return ret -def _resolve_number(thing): +def make_good_value(thing, valtype): try: + if thing.endswith("()"): + thing = 'Default("{}")'.format(thing[:-2]) + else: + ret = eval(thing, namespace) + if valtype and repr(ret).startswith("<"): + thing = 'Instance("{}")'.format(thing) return eval(thing, namespace) - except Exception: - return None + except (SyntaxError, TypeError, NameError): + pass def try_to_guess(thing, valtype): - res = _resolve_number(thing) - if res is not None: - return res if "." not in thing and "(" not in thing: text = "{}.{}".format(valtype, thing) - try: - return eval(text, namespace) - except Exception: - pass + ret = make_good_value(text, valtype) + if ret is not None: + return ret typewords = valtype.split(".") valwords = thing.split(".") - braceless = valwords[0] + braceless = valwords[0] # Yes, not -1. Relevant is the overlapped word. if "(" in braceless: braceless = braceless[:braceless.index("(")] for idx, w in enumerate(typewords): if w == braceless: text = ".".join(typewords[:idx] + valwords) - try: - return eval(text, namespace) - except Exception: - pass + ret = make_good_value(text, valtype) + if ret is not None: + return ret return None def _resolve_value(thing, valtype, line): + if thing in ("0", "None") and valtype: + thing = "zero({})".format(valtype) if thing in type_map: return type_map[thing] - try: - res = eval(thing, namespace) + res = make_good_value(thing, valtype) + if res is not None: type_map[thing] = res return res - except Exception: - pass res = try_to_guess(thing, valtype) if valtype else None if res is not None: type_map[thing] = res |
