diff -r bcfbab86f49a Lib/idlelib/CallTips.py --- a/Lib/idlelib/CallTips.py Thu Jan 23 00:36:37 2014 -0500 +++ b/Lib/idlelib/CallTips.py Sun Jan 26 02:58:28 2014 -0500 @@ -5,14 +5,15 @@ which disappear when you type a closing parenthesis. """ +import __main__ import re import sys +import textwrap import types from idlelib import CallTipWindow from idlelib.HyperParser import HyperParser -import __main__ class CallTips: @@ -131,8 +132,9 @@ return None # The following are used in get_arg_text -_MAX_COLS = 79 +_MAX_COLS = 85 _MAX_LINES = 5 # enough for bytes +_INDENT = ' ' # for wrapped signatures def get_arg_text(ob): '''Return a string describing the signature of a callable object, or ''. @@ -147,11 +149,15 @@ try: ob_call = ob.__call__ except BaseException: - return argspec + if type(ob) is types.ClassType: # old-style + ob_call = ob + else: + return argspec arg_offset = 0 if type(ob) in (types.ClassType, types.TypeType): - # Look for the highest __init__ in the class chain. + # Look for the first __init__ in the class chain with .im_func. + # Slot wrappers (builtins, classes defined in funcs) do not. fob = _find_constructor(ob) if fob is None: fob = lambda: None @@ -183,14 +189,16 @@ items.append("**kwds") argspec = ", ".join(items) argspec = "(%s)" % re.sub("(?", argspec) - # See if we can use the docstring + + lines = (textwrap.wrap(argspec, _MAX_COLS, subsequent_indent=_INDENT) + if len(argspec) > _MAX_COLS else [argspec] if argspec else []) + if isinstance(ob_call, types.MethodType): doc = ob_call.__doc__ else: doc = getattr(ob, "__doc__", "") if doc: - lines = [argspec] if argspec else [] - for line in doc.split('\n', 5)[:_MAX_LINES]: + for line in doc.split('\n', _MAX_LINES)[:_MAX_LINES]: line = line.strip() if not line: break diff -r bcfbab86f49a Lib/idlelib/idle_test/test_calltips.py --- a/Lib/idlelib/idle_test/test_calltips.py Thu Jan 23 00:36:37 2014 -0500 +++ b/Lib/idlelib/idle_test/test_calltips.py Sun Jan 26 02:58:28 2014 -0500 @@ -1,6 +1,7 @@ import unittest import idlelib.CallTips as ct CTi = ct.CallTips() # needed for get_entity test in 2.7 +import textwrap import types default_tip = '' @@ -66,6 +67,18 @@ gtest(types.MethodType, '()\ninstancemethod(function, instance, class)') gtest(SB(), default_tip) + def test_signature_wrap(self): + # This is also a test of an old-style class + 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)''') + + def test_docline_truncation(self): + def f(): pass + f.__doc__ = 'a'*300 + self.assertEqual(signature(f), '()\n' + 'a' * (ct._MAX_COLS-3) + '...') + def test_multiline_docstring(self): # Test fewer lines than max. self.assertEqual(signature(list),