Skip to content
Prev Previous commit
Next Next commit
Fix first param trim condition
  • Loading branch information
louisom committed May 3, 2017
commit f1cf2c2256821efebebd16fa2cd41d80ecc80c6c
6 changes: 2 additions & 4 deletions Lib/idlelib/calltips.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,8 @@ def get_argspec(ob):
argspec = "This function has an invalid method signature"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add _invalid_signature to global defs before function so can access for testing without repeating string.

return argspec

if (isinstance(ob, (type, types.MethodType)) or
isinstance(ob_call, types.MethodType)):
if argspec.startswith("(self,"):
argspec = _first_param.sub("", argspec)
if isinstance(ob, type):
argspec = _first_param.sub("", argspec)

lines = (textwrap.wrap(argspec, _MAX_COLS, subsequent_indent=_INDENT)
if len(argspec) > _MAX_COLS else [argspec] if argspec else [])
Expand Down
10 changes: 7 additions & 3 deletions Lib/idlelib/idle_test/test_calltips.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,15 @@ def test_attribute_exception(self):
class NoCall:
def __getattr__(self, name):
raise BaseException
class Call(NoCall):
class CallA(NoCall):
def __call__(oui, a, b, c):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add corner case for first param not self

pass
class CallB(NoCall):
def __call__(self, ci):
pass
for meth, mtip in ((NoCall, default_tip), (Call, default_tip),
(NoCall(), ''), (Call(), '(ci)')):
for meth, mtip in ((NoCall, default_tip), (CallA, default_tip),
(NoCall(), ''), (CallA(), '(a, b, c)'),
(CallB(), '(ci)')):
self.assertEqual(signature(meth), mtip)


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8

Expand Down