diff -r 9a98ff4a2290 Lib/idlelib/CallTips.py --- a/Lib/idlelib/CallTips.py Wed Jan 22 05:49:11 2014 -0800 +++ b/Lib/idlelib/CallTips.py Wed Jan 22 20:48:47 2014 +0200 @@ -9,6 +9,7 @@ import sys import types import inspect +import textwrap from idlelib import CallTipWindow from idlelib.HyperParser import HyperParser @@ -118,7 +119,8 @@ # The following are used in get_argspec and some in tests _MAX_COLS = 79 -_MAX_LINES = 5 # enough for bytes +_SUBS_INDENT = 20 +_MAX_LINES = 9 # enough for dict _first_param = re.compile('(?<=\()\w*\,?\s*') _default_callable_argspec = "See source or doc" @@ -154,15 +156,22 @@ else: doc = getattr(ob, "__doc__", "") if doc: - lines = [argspec] if argspec else [] - for line in doc.split('\n', 5)[:_MAX_LINES]: - line = line.strip() + doc = textwrap.dedent(doc) + lines = [] + for line in doc.split('\n', _MAX_LINES)[:_MAX_LINES]: + line = line.rstrip() if not line: break - if len(line) > _MAX_COLS: - line = line[: _MAX_COLS - 3] + '...' lines.append(line) - argspec = '\n'.join(lines) + wrapped = textwrap.wrap(argspec, width=_MAX_COLS, + subsequent_indent=' ' * _SUBS_INDENT) + for line in lines: + if len(wrapped) >= _MAX_LINES: + break + wrapped.extend(textwrap.wrap(line, width=_MAX_COLS, + subsequent_indent=' ' * _SUBS_INDENT, + max_lines=_MAX_LINES - len(wrapped))) + argspec = '\n'.join(wrapped) if not argspec: argspec = _default_callable_argspec return argspec diff -r 9a98ff4a2290 Lib/idlelib/idle_test/test_calltips.py --- a/Lib/idlelib/idle_test/test_calltips.py Wed Jan 22 05:49:11 2014 -0800 +++ b/Lib/idlelib/idle_test/test_calltips.py Wed Jan 22 20:48:47 2014 +0200 @@ -71,13 +71,30 @@ "list(iterable) -> new list initialized from iterable's items") # Test max lines and line (currently) too long. - self.assertEqual(signature(bytes), -"bytes(iterable_of_ints) -> bytes\n" -"bytes(string, encoding[, errors]) -> bytes\n" -"bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer\n" -#bytes(int) -> bytes object of size given by the parameter initialized with null bytes -"bytes(int) -> bytes object of size given by the parameter initialized with n...\n" -"bytes() -> empty bytes object") + self.assertEqual(signature(bytes), """\ +bytes(iterable_of_ints) -> bytes +bytes(string, encoding[, errors]) -> bytes +bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer +bytes(int) -> bytes object of size given by the parameter initialized with null + bytes +bytes() -> empty bytes object""") + self.assertEqual(signature(dict), """\ +dict() -> new empty dictionary +dict(mapping) -> new dictionary initialized from a mapping object's + (key, value) pairs +dict(iterable) -> new dictionary initialized as if via: + d = {} + for k, v in iterable: + d[k] = v +dict(**kwargs) -> new dictionary initialized with the name=value pairs + in the keyword argument list. For example: dict(one=1, two=2)""") + import textwrap + self.assertEqual(signature(textwrap.TextWrapper), """\ +(width=70, initial_indent='', subsequent_indent='', expand_tabs=True, + replace_whitespace=True, fix_sentence_endings=False, + break_long_words=True, drop_whitespace=True, + break_on_hyphens=True, tabsize=8, *, max_lines=None, + placeholder=' [...]')""") def test_functions(self): def t1(): 'doc'