diff options
| author | Jordan Wiens <jordan@psifertex.com> | 2019-09-10 23:32:41 -0400 |
|---|---|---|
| committer | Jordan Wiens <jordan@psifertex.com> | 2019-09-10 23:33:12 -0400 |
| commit | 7819bd21ca32fb2b9a32bf124a99e509be3ce136 (patch) | |
| tree | 755ba99f2cb8c48188d6be33d307ebf48e13ef5a /python/bncompleter.py | |
| parent | 0629e1176e8d9c45cdbffd6db13f2521ca6038b1 (diff) | |
better error handling if inspect fails to generate a function prototype and py2 signature support
Diffstat (limited to 'python/bncompleter.py')
| -rw-r--r-- | python/bncompleter.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/python/bncompleter.py b/python/bncompleter.py index e1dfab1a..d5adfbc1 100644 --- a/python/bncompleter.py +++ b/python/bncompleter.py @@ -41,9 +41,27 @@ Notes: import atexit import __main__ import inspect +import sys __all__ = ["Completer"] +def fnsignature(obj): + if sys.version_info[0:2] >= (3, 5): + try: + sig = str(inspect.signature(obj)) + except: + sig = "()" + return sig + else: + try: + args = inspect.getargspec(obj).args + args.remove('self') + sig = "(" + ','.join(args) + ")" + except: + sig = "()" + return sig + + class Completer: def __init__(self, namespace = None): """Create a new completer for the command line. @@ -100,7 +118,7 @@ class Completer: def _callable_postfix(self, val, word): if callable(val) and not inspect.isclass(val): - word = word + str(inspect.signature(val)) + word = word + fnsignature(val) return word def global_matches(self, text): |
