diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2014-01-22 01:45:17 (GMT) |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2014-01-22 01:45:17 (GMT) |
commit | d5710f8b36a456872f3cadd913a26f4aa76afc01 (patch) | |
tree | 9f4f26361dc1e1d50ecae03a2642d5f69993a02e /Lib/idlelib/CallTips.py | |
parent | 758fa5ea819d4301afed5049fa1186f275c4f801 (diff) | |
download | cpython-d5710f8b36a456872f3cadd913a26f4aa76afc01.zip cpython-d5710f8b36a456872f3cadd913a26f4aa76afc01.tar.gz cpython-d5710f8b36a456872f3cadd913a26f4aa76afc01.tar.bz2 |
Issue #16638: Include up to 5 docstring header lines (before first blank) in
Idle calltips. This is needed for builtins, such bytes (which is why 5).
Based on patch by Serhiy Storchaka.
Diffstat (limited to 'Lib/idlelib/CallTips.py')
-rw-r--r-- | Lib/idlelib/CallTips.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/Lib/idlelib/CallTips.py b/Lib/idlelib/CallTips.py index 83bb638..4f88da6 100644 --- a/Lib/idlelib/CallTips.py +++ b/Lib/idlelib/CallTips.py @@ -116,17 +116,21 @@ def get_entity(expression): # exception, especially if user classes are involved. return None -# The following are used in both get_argspec and tests +# The following are used in get_argspec and some in tests +_MAX_COLS = 79 +_MAX_LINES = 5 # enough for bytes _first_param = re.compile('(?<=\()\w*\,?\s*') _default_callable_argspec = "See source or doc" + def get_argspec(ob): '''Return a string describing the signature of a callable object, or ''. For Python-coded functions and methods, the first line is introspected. Delete 'self' parameter for classes (.__init__) and bound methods. - The last line is the first line of the doc string. For builtins, this typically - includes the arguments in addition to the return value. + The next lines are the first lines of the doc string up to the first + empty line or _MAX_LINES. For builtins, this typically includes + the arguments in addition to the return value. ''' argspec = "" try: @@ -150,13 +154,15 @@ def get_argspec(ob): else: doc = getattr(ob, "__doc__", "") if doc: - doc = doc.lstrip() - pos = doc.find("\n") - if pos < 0 or pos > 70: - pos = 70 - if argspec: - argspec += "\n" - argspec += doc[:pos] + lines = [argspec] if argspec else [] + for line in doc.split('\n', 5)[:_MAX_LINES]: + line = line.strip() + if not line: + break + if len(line) > _MAX_COLS: + line = line[: _MAX_COLS - 3] + '...' + lines.append(line) + argspec = '\n'.join(lines) if not argspec: argspec = _default_callable_argspec return argspec |