summaryrefslogtreecommitdiff
path: root/Lib/idlelib/calltip.py
diff options
context:
space:
mode:
authorTal Einat <taleinat+github@gmail.com>2020-11-02 05:59:52 +0200
committerGitHub <noreply@github.com>2020-11-01 22:59:52 -0500
commitda7bb7b4d769350c5fd03e6cfb16b23dc265ed72 (patch)
tree90825dd55ad9782a1375e4594fd067ebf665c345 /Lib/idlelib/calltip.py
parent74fa464b81ebf3312ae6efa11e618c00c2a9fd34 (diff)
downloadcpython-git-da7bb7b4d769350c5fd03e6cfb16b23dc265ed72.tar.gz
bpo-40511: Stop unwanted flashing of IDLE calltips (GH-20910)
They were occurring with both repeated 'force-calltip' invocations and by typing parentheses in expressions, strings, and comments in the argument code. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Diffstat (limited to 'Lib/idlelib/calltip.py')
-rw-r--r--Lib/idlelib/calltip.py36
1 files changed, 34 insertions, 2 deletions
diff --git a/Lib/idlelib/calltip.py b/Lib/idlelib/calltip.py
index b02f87207d..549e224015 100644
--- a/Lib/idlelib/calltip.py
+++ b/Lib/idlelib/calltip.py
@@ -55,18 +55,50 @@ class Calltip:
self.open_calltip(False)
def open_calltip(self, evalfuncs):
- self.remove_calltip_window()
+ """Maybe close an existing calltip and maybe open a new calltip.
+ Called from (force_open|try_open|refresh)_calltip_event functions.
+ """
hp = HyperParser(self.editwin, "insert")
sur_paren = hp.get_surrounding_brackets('(')
+
+ # If not inside parentheses, no calltip.
if not sur_paren:
+ self.remove_calltip_window()
return
+
+ # If a calltip is shown for the current parentheses, do
+ # nothing.
+ if self.active_calltip:
+ opener_line, opener_col = map(int, sur_paren[0].split('.'))
+ if (
+ (opener_line, opener_col) ==
+ (self.active_calltip.parenline, self.active_calltip.parencol)
+ ):
+ return
+
hp.set_index(sur_paren[0])
- expression = hp.get_expression()
+ try:
+ expression = hp.get_expression()
+ except ValueError:
+ expression = None
if not expression:
+ # No expression before the opening parenthesis, e.g.
+ # because it's in a string or the opener for a tuple:
+ # Do nothing.
return
+
+ # At this point, the current index is after an opening
+ # parenthesis, in a section of code, preceded by a valid
+ # expression. If there is a calltip shown, it's not for the
+ # same index and should be closed.
+ self.remove_calltip_window()
+
+ # Simple, fast heuristic: If the preceding expression includes
+ # an opening parenthesis, it likely includes a function call.
if not evalfuncs and (expression.find('(') != -1):
return
+
argspec = self.fetch_tip(expression)
if not argspec:
return