Skip to content

bpo-19903: IDLE: Change to inspect.signature for calltips#1382

Closed
louisom wants to merge 10 commits into
python:masterfrom
louisom:bpo-19903
Closed

bpo-19903: IDLE: Change to inspect.signature for calltips#1382
louisom wants to merge 10 commits into
python:masterfrom
louisom:bpo-19903

Conversation

@louisom

@louisom louisom commented May 2, 2017

Copy link
Copy Markdown
Contributor

This commit change the get_argspec from using inspect.getfullargspec
to inspect.signature. It will improve the tip message for use.

This commit change the get_argspec from using inspect.getfullargspec
to inspect.signature. It will improve the tip message for use.

Also, if object is not callable, now will return this message for
user, not blank tips. If the methods has an invalid method signature,
it will also return message to user.
@mention-bot

Copy link
Copy Markdown

@lulouie, thanks for your PR! By analyzing the history of the files in this pull request, we identified @terryjreedy, @kbkaiser and @serhiy-storchaka to be potential reviewers.

Comment thread Lib/idlelib/calltips.py Outdated
argspec = ""
try:
ob_call = ob.__call__
except AttributeError:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you left this change for separate issue?

Comment thread Lib/idlelib/calltips.py Outdated
if (isinstance(ob, (type, types.MethodType)) or
isinstance(ob_call, types.MethodType)):
argspec = _first_param.sub("", argspec)
if argspec.startswith("(self,"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if the first parameter have a different name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right. I'll still need to figure out how it does different from getfullargspec

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Find out that signature will deal correctly with MethodType, but will not handle __init__ correctly.
Fix the condition of trim first param.

@brettcannon brettcannon added the type-feature A feature request or enhancement label May 2, 2017
@terryjreedy terryjreedy self-assigned this May 2, 2017
@louisom

louisom commented May 3, 2017

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka @terryjreedy Also add the test for first param not self test.

def m2(**kwds): pass
c = C()
for meth, mtip in ((C.m1, '(*args)'), (c.m1, "(*args)"),
(C.m2, "(**kwds)"), (c.m2, "(**kwds)"),):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Remove invalid method signature, move to test_invalid_method_signature


mtip = "This function has an invalid method signature"
self.assertEqual(signature(C().m2), mtip)
self.assertEqual(signature(Test()), mtip)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test borrow from test_signature

raise BaseException
class Call(NoCall):
class CallA(NoCall):
def __call__(oui, a, b, c):

Copy link
Copy Markdown
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

for obj in (0, 0.0, '0', b'0', [], {}):
self.assertEqual(signature(obj), '')


Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PEP8

@terryjreedy terryjreedy self-requested a review May 4, 2017 07:07
Comment thread Lib/idlelib/calltips.py Outdated
@@ -145,10 +148,16 @@ def get_argspec(ob):
else:
fob = ob
if isinstance(fob, (types.FunctionType, types.MethodType)):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove and dedent block.

Comment thread Lib/idlelib/calltips.py Outdated
argspec = inspect.formatargspec(*inspect.getfullargspec(fob))
try:
argspec = str(inspect.signature(fob))
except ValueError:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Must get and test error message.

Comment thread Lib/idlelib/calltips.py Outdated
try:
argspec = str(inspect.signature(fob))
except ValueError:
argspec = "This function has an invalid method signature"

Copy link
Copy Markdown
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.

Comment thread Lib/idlelib/calltips.py Outdated
argspec = inspect.formatargspec(*inspect.getfullargspec(fob))
try:
argspec = str(inspect.signature(fob))
except ValueError:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Condition return on error message

Comment thread Lib/idlelib/calltips.py Outdated
argspec = "This function has an invalid method signature"
return argspec

if (isinstance(ob, (type, types.MethodType)) or

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add argspec != '' to later revised condition

@terryjreedy terryjreedy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See msg292964 on issue for explanations and comment on what test addition is needed.

Comment thread Lib/idlelib/calltips.py Outdated
@@ -1,4 +1,4 @@
"""calltips.py - An IDLE Extension to Jog Your Memory
b"""calltips.py - An IDLE Extension to Jog Your Memory

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

??? Docstrings are not bytes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A typo..., I'm using trackpoint on laptop, sometime when scrolling down, it will unexpectedly
pressing "b"

Comment thread Lib/idlelib/calltips.py
except BaseException:
return argspec
if isinstance(ob, type):
fob = ob.__init__

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why remove this? It worked before. Does signature() do this automatically? Such a change should be explained on the issue with examples, both for Python and C coded classed. And yes, I wish I had added comments here or in test file or, by reference, an issue, when I revised this and and added test file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As you said on msg, this will automatically done by signature.

Comment thread Lib/idlelib/calltips.py Outdated
if '/' in argspec:
"""Argument Clinic positional-only mark, ignore the result of signature
"""
argspec = ''

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why? '/' is used in legitimate signatures, and appear, I believe, in the docs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll use your method in msg293008

@louisom louisom changed the title bpo-19903: Change to inspect.signature for calltips bpo-19903: IDLE: Change to inspect.signature for calltips May 10, 2017
@terryjreedy

terryjreedy commented Jul 24, 2017

Copy link
Copy Markdown
Member

Replaced by #2822 with new account name. LEAVE THIS OPEN FOR NOW. Since it will not be merged, I am using it as one example of not being able to edit the code due to lack permission.

@terryjreedy

Copy link
Copy Markdown
Member

Edit by others being turned off seems to be resolved for now.

@terryjreedy terryjreedy closed this Aug 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants