diff options
author | Tal Einat <taleinat+github@gmail.com> | 2020-04-04 03:05:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-04 03:05:58 (GMT) |
commit | 52013e5b6d5ca32eef5a3d65ecdf7db89cefc2fd (patch) | |
tree | b66ad6b00c4ecd03f18bd951d0952ab728f794f9 /Lib/idlelib/calltip.py | |
parent | 6e623ff9d251e0ce86e9b18a01bfd6f067079d7a (diff) | |
download | cpython-52013e5b6d5ca32eef5a3d65ecdf7db89cefc2fd.zip cpython-52013e5b6d5ca32eef5a3d65ecdf7db89cefc2fd.tar.gz cpython-52013e5b6d5ca32eef5a3d65ecdf7db89cefc2fd.tar.bz2 |
bpo-38689: avoid IDLE hanging when calltip fails getting a signature (GH-17152)
Inspect.signature failed on the test case because its isinstance call raised.
Diffstat (limited to 'Lib/idlelib/calltip.py')
-rw-r--r-- | Lib/idlelib/calltip.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Lib/idlelib/calltip.py b/Lib/idlelib/calltip.py index 2e0db60..d4092c7 100644 --- a/Lib/idlelib/calltip.py +++ b/Lib/idlelib/calltip.py @@ -129,20 +129,22 @@ def get_argspec(ob): empty line or _MAX_LINES. For builtins, this typically includes the arguments in addition to the return value. ''' - argspec = default = "" + # Determine function object fob to inspect. try: ob_call = ob.__call__ - except BaseException: - return default - + except BaseException: # Buggy user object could raise anything. + return '' # No popup for non-callables. fob = ob_call if isinstance(ob_call, types.MethodType) else ob + # Initialize argspec and wrap it to get lines. try: argspec = str(inspect.signature(fob)) - except ValueError as err: + except Exception as err: msg = str(err) if msg.startswith(_invalid_method): return _invalid_method + else: + argspec = '' if '/' in argspec and len(argspec) < _MAX_COLS - len(_argument_positional): # Add explanation TODO remove after 3.7, before 3.9. @@ -154,6 +156,7 @@ def get_argspec(ob): lines = (textwrap.wrap(argspec, _MAX_COLS, subsequent_indent=_INDENT) if len(argspec) > _MAX_COLS else [argspec] if argspec else []) + # Augment lines from docstring, if any, and join to get argspec. if isinstance(ob_call, types.MethodType): doc = ob_call.__doc__ else: @@ -167,9 +170,8 @@ def get_argspec(ob): line = line[: _MAX_COLS - 3] + '...' lines.append(line) argspec = '\n'.join(lines) - if not argspec: - argspec = _default_callable_argspec - return argspec + + return argspec or _default_callable_argspec if __name__ == '__main__': |