cpython: eea379307efa (original) (raw)
--- a/Lib/idlelib/CallTips.py +++ b/Lib/idlelib/CallTips.py @@ -117,7 +117,7 @@ def get_entity(expression): return None
The following are used in both get_argspec and tests
-_self_pat = re.compile('self,?\s*') +_first_param = re.compile('(?<=()\w,?\s') _default_callable_argspec = "No docstring, see docs." def get_argspec(ob): @@ -141,7 +141,7 @@ def get_argspec(ob): argspec = inspect.formatargspec(*inspect.getfullargspec(fob)) if (isinstance(ob, (type, types.MethodType)) or isinstance(ob.call, types.MethodType)):
argspec = _self_pat.sub("", argspec)[](#l1.16)
argspec = _first_param.sub("", argspec)[](#l1.17)
if isinstance(ob.call, types.MethodType): doc = ob.call.doc @@ -169,8 +169,7 @@ def main(): def t2(a, b=None): "(a, b=None)" def t3(a, *args): "(a, *args)" def t4(*args): "(*args)"
class TC(object): "(ai=None, *b)" @@ -179,13 +178,13 @@ def main(): def t2(self, ai, b=None): "(self, ai, b=None)" def t3(self, ai, *args): "(self, ai, *args)" def t4(self, *args): "(self, *args)"
def t5(self, ai, *args): "(self, ai, *args)"[](#l1.35)
def t6(self, ai, b=None, *args, **kw): "(self, ai, b=None, *args, **kw)"[](#l1.36)
def t5(self, ai, b=None, *args, **kw): "(self, ai, b=None, *args, **kw)"[](#l1.37)
def t6(no, self): "(no, self)"[](#l1.38) @classmethod[](#l1.39) def cm(cls, a): "(cls, a)"[](#l1.40) @staticmethod[](#l1.41) def sm(b): "(b)"[](#l1.42)
def __call__(self, ci): "(ci)"[](#l1.43)
def __call__(self, ci): "(self, ci)"[](#l1.44)
tc = TC() @@ -228,19 +227,26 @@ def main(): test('SB()', _default_callable_argspec) def test_funcs():
for func in (t1, t2, t3, t4, t5, t6, TC,):[](#l1.52)
for func in (t1, t2, t3, t4, t5, TC,):[](#l1.53) fdoc = func.__doc__[](#l1.54) test(func.__name__, fdoc + "\n" + fdoc)[](#l1.55)
for func in (TC.t1, TC.t2, TC.t3, TC.t4, TC.t5, TC.t6, TC.cm, TC.sm):[](#l1.56)
for func in (TC.t1, TC.t2, TC.t3, TC.t4, TC.t5, TC.t6, TC.sm,[](#l1.57)
TC.__call__):[](#l1.58) fdoc = func.__doc__[](#l1.59) test('TC.'+func.__name__, fdoc + "\n" + fdoc)[](#l1.60)
fdoc = TC.cm.__func__.__doc__[](#l1.61)
test('TC.cm.__func__', fdoc + "\n" + fdoc)[](#l1.62)
for func in (tc.t1, tc.t2, tc.t3, tc.t4, tc.t5, tc.t6):[](#l1.65)
fdoc = func.__doc__[](#l1.66)
test('tc.'+func.__name__, _self_pat.sub("", fdoc) + "\n" + fdoc)[](#l1.67)
fdoc = tc.__call__.__doc__[](#l1.68)
test('tc', fdoc + "\n" + fdoc)[](#l1.69)
# test that first parameter is correctly removed from argspec[](#l1.70)
# using _first_param re to calculate expected masks re errors[](#l1.71)
for meth, mdoc in ((tc.t1, "()"), (tc.t4, "(*args)"), (tc.t6, "(self)"),[](#l1.72)
(TC.cm, "(a)"),):[](#l1.73)
test('tc.'+meth.__name__, mdoc + "\n" + meth.__doc__)[](#l1.74)
test('tc', "(ci)" + "\n" + tc.__call__.__doc__)[](#l1.75)
# directly test that re works to delete unicode parameter name[](#l1.76)
uni = "(A\u0391\u0410\u05d0\u0627\u0905\u1e00\u3042, a)" # various As[](#l1.77)
assert _first_param.sub('', uni) == '(a)'[](#l1.78)
def test_non_callables(): # expression evaluates, but not to a callable