Closes Issue 21659: Improve Idle calltips for *args, **kwargs in 2.7, where actual

names are not available. Initial patch by Serhiy Storchaka.
This commit is contained in:
Terry Jan Reedy 2014-06-09 20:02:18 -04:00
parent dd35484662
commit 1d6a0c47db
2 changed files with 21 additions and 9 deletions

View File

@ -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("(?<!\d)\.\d+", "<tuple>", argspec)

View File

@ -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