-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-19903: IDLE: Calltips changed to use inspect.signature #2822
Conversation
@mlouielu, 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. |
Louie, I cannot add commits to this issue, and a few others of yours and others. Please follow the instructions at https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/#enabling-repository-maintainer-permissions-on-existing-pull-requests to make sure "Allow edits from maintainers." is checked for this and other IDLE issues. Please let me know what you found. If that is already checked, then I have some other problem with github. |
@terryjreedy The check is on now. Hmmm, I thought that is default to check-up? FWIR this has been discussed on python-committers before? |
There seems to have been a problem with a robot unchecking the edit switch under some circumstances. Since patched. |
I want to make a few minor changes, do some live tests, and merge. But when I tried to make a local PR, git trapped my clone in a loop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote minor changes I planned to write, to make code slightly clearer. The should not affect tests.
PR also needs a blurb added. The title line might be enough. In any case, web edit works well for blurbs.
Lib/idlelib/calltips.py
Outdated
@@ -139,17 +141,31 @@ def get_argspec(ob): | |||
ob_call = ob.__call__ | |||
except BaseException: | |||
return argspec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/argspec = ""/argspec = default = ""/ above
/argspec/default/ here
-- done
Lib/idlelib/calltips.py
Outdated
if isinstance(ob, type): | ||
fob = ob.__init__ | ||
elif isinstance(ob_call, types.MethodType): | ||
if isinstance(ob_call, types.MethodType): | ||
fob = ob_call | ||
else: | ||
fob = ob |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with conditional expression.
-- done
Lib/idlelib/calltips.py
Outdated
pass | ||
else: | ||
"""Callable is not supported by signature""" | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace body with conditional expression:
return _invalid_method if str(err).startswith(_invalid_method) else default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do this, it will break the unittest, for e.g. range
will not able to return argspec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, in these cases, we still look for docstring.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am doing some manual checking while waiting for CI, but expect to merge.
@terryjreedy Can this be backported to 3.5 and 3.6? |
Funny you should ask. When 3.6.0b1 came out, I stopped backporting to anything before 3.6: too much work and too much danger of regressions. In testing this, I noticed that ')' no longer closes calltips -- a bad regression since 3.6.2. Since repository 3.6.2+ has the same problem, it is definitely not this patch. I suspect bpo-30723. Of course, there is no test of such behaviors. That aside, this patch would have less effect in 3.5 (pre-Arg Clinic, I believe), and the too dangerousCurrently, everything is backported to 3.6, and only 3.6. The last 3.5 maintenance release candidate was issued a week ago, so it is effectively in security-only mode. |
Lib/idlelib/calltips.py
Outdated
@@ -123,6 +123,8 @@ def get_entity(expression): | |||
_INDENT = ' '*4 # for wrapped signatures | |||
_first_param = re.compile(r'(?<=\()\w*\,?\s*') | |||
_default_callable_argspec = "See source or doc" | |||
_invalid_method = "invalid method signature" | |||
_argument_positional = "('/' marks preceding arguments as positional-only)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon seeing a real example, I don't like the clash between () as call operator and comment marker in tips such as
(object, /)
('/' marks preceding arguments as positional-only)
Append object to the end of the list.
I prefer either [] or # as the comment marker. What think you?
(object, /)
['/' marks preceding arguments as positional-only]
Append object to the end of the list.
(object, /)
# '/' marks preceding arguments as positional-only
Append object to the end of the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll prefer ['/' marks preceding arguments as positional-only]
style, it has more conspicuous when the text was end at the box margin.
Also, I think the word is OK, using google to search will got this stackoverflow post at the top, it should not be a problem for newbie.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By 'word', I presume you meant 'positional-only'. Nice check. We'll go with your preference.
Lib/idlelib/calltips.py
Outdated
|
||
if '/' in argspec: | ||
"""Using AC's positional argument should add the explain""" | ||
argspec = '\n'.join([argspec, _argument_positional]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argspec += '\n' + _argument_positional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix _argument_positional
to "\n['/' marks preceding arguments as positional-only]\n"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even better.
non-overlapping occurrences of the pattern in string by the | ||
replacement repl. repl can be either a string or a callable; | ||
if a string, backslash escapes in it are processed. If it is | ||
a callable, it's passed the match object and must return''') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer that this be truncated also. We allowed up to 5 docstring lines for builtins to get the signature (bytes needs 5), but if we already have signature, only 1 should be allowed, as below. However, after checking the code and the docstring, I decided that the source of the problem is that the re.sub docstring is defective in not having an overly long summary sentence and then not having a blank line after the first '.', as it should. We could check for '.', but not worth the effort now. Instead I would like to add a comment so it is clear that this case was thought about. This is a good additional test case.
# Comment runs on because of long first sentence and missing blank thereafter. Display as above.
This PR should be block until the regression of not closing tipbox been fixed. I don't think the problem came from #2306, I test it on mac first |
Block fixed by 8922587 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requested changes made, some with improvements.
GH-3053 is a backport of this pull request to the 3.6 branch. |
…honGH-2822) Idlelib.calltips.get_argspec now uses inspect.signature instead of inspect.getfullargspec, like help() does. This improves the signature in the call tip in a few different cases, including builtins converted to provide a signature. A message is added if the object is not callable, has an invalid signature, or if it has positional-only parameters. Patch by Louie Lu.. (cherry picked from commit 3b0f620)
…2822) (#3053) Idlelib.calltips.get_argspec now uses inspect.signature instead of inspect.getfullargspec, like help() does. This improves the signature in the call tip in a few different cases, including builtins converted to provide a signature. A message is added if the object is not callable, has an invalid signature, or if it has positional-only parameters. Patch by Louie Lu.. (cherry picked from commit 3b0f620)
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.
Re-open from #1382
https://bugs.python.org/issue19903