From: Terry Jan Reedy Date: Tue, 10 Jun 2014 00:02:18 +0000 (-0400) Subject: Closes Issue 21659: Improve Idle calltips for *args, **kwargs in 2.7, where actual X-Git-Tag: v2.7.8~37^2~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d6a0c47db70f56cee73932efe3e565b13488916;p=python Closes Issue 21659: Improve Idle calltips for *args, **kwargs in 2.7, where actual names are not available. Initial patch by Serhiy Storchaka. --- diff --git a/Lib/idlelib/CallTips.py b/Lib/idlelib/CallTips.py index 0662880ff1..3db26362c2 100644 --- a/Lib/idlelib/CallTips.py +++ b/Lib/idlelib/CallTips.py @@ -183,10 +183,16 @@ def get_arg_text(ob): defaults = list(map(lambda name: "=%s" % repr(name), defaults)) defaults = [""] * (len(real_args) - len(defaults)) + defaults items = map(lambda arg, dflt: arg + dflt, real_args, defaults) - if fob.func_code.co_flags & 0x4: - items.append("*args") - if fob.func_code.co_flags & 0x8: - items.append("**kwds") + for flag, pre, name in ((0x4, '*', 'args'), (0x8, '**', 'kwargs')): + if fob.func_code.co_flags & flag: + pre_name = pre + name + if name not in real_args: + items.append(pre_name) + else: + i = 1 + while ((name+'%s') % i) in real_args: + i += 1 + items.append((pre_name+'%s') % i) argspec = ", ".join(items) argspec = "(%s)" % re.sub("(?", argspec) diff --git a/Lib/idlelib/idle_test/test_calltips.py b/Lib/idlelib/idle_test/test_calltips.py index 60b688fa3d..83718090c4 100644 --- a/Lib/idlelib/idle_test/test_calltips.py +++ b/Lib/idlelib/idle_test/test_calltips.py @@ -22,7 +22,7 @@ class TC(object): def t4(self, *args): 'doc' t4.tip = "(self, *args)" def t5(self, ai, b=None, *args, **kw): 'doc' - t5.tip = "(self, ai, b=None, *args, **kwds)" + t5.tip = "(self, ai, b=None, *args, **kwargs)" def t6(no, self): 'doc' t6.tip = "(no, self)" def __call__(self, ci): 'doc' @@ -104,7 +104,7 @@ class Get_signatureTest(unittest.TestCase): def t4(*args): 'doc' t4.tip = "(*args)" def t5(a, b=None, *args, **kwds): 'doc' - t5.tip = "(a, b=None, *args, **kwds)" + t5.tip = "(a, b=None, *args, **kwargs)" for func in (t1, t2, t3, t4, t5, TC): self.assertEqual(signature(func), func.tip + '\ndoc') @@ -126,10 +126,16 @@ class Get_signatureTest(unittest.TestCase): class C: def m1(*args): pass def m2(**kwds): pass + def f1(args, kwargs, *a, **k): pass + def f2(args, kwargs, args1, kwargs1, *a, **k): pass c = C() - for meth, mtip in ((C.m1, '(*args)'), (c.m1, "(*args)"), - (C.m2, "(**kwds)"), (c.m2, "(**kwds)"),): - self.assertEqual(signature(meth), mtip) + self.assertEqual(signature(C.m1), '(*args)') + self.assertEqual(signature(c.m1), '(*args)') + self.assertEqual(signature(C.m2), '(**kwargs)') + self.assertEqual(signature(c.m2), '(**kwargs)') + self.assertEqual(signature(f1), '(args, kwargs, *args1, **kwargs1)') + self.assertEqual(signature(f2), + '(args, kwargs, args1, kwargs1, *args2, **kwargs2)') def test_no_docstring(self): def nd(s): pass