FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-41611: IDLE: Catch TclError exceptions in AutoCompleteWindow.winconfig_event() by taleinat · Pull Request #26404 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
63 changes: 36 additions & 27 deletions Lib/idlelib/autocomplete_w.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -242,37 +242,46 @@ def winconfig_event(self, event):
self.is_configuring = True
if not self.is_active():
return
Comment on lines 242 to 244

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I believe it is a bug to leave self.is_configuring True when returning. It seems that not self.active should be added to the condition above. I also remember doing some test that indicated that this function may still be executed past here more than once. But another issue.

taleinat May 27, 2021 •
edited
Loading

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

True, though unrelated to the bug in the bpo issue. Want us to fix this in this PR while we're here?

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Tempted but no. Partly discipline -- we have coherent problem and solution we agree on, lets merge it (when you are ready). We have done really great today with good focus. Partly I want to retry the test I remember to check for any anomaly. Start with just a PR, if you want, after this is merged into you local clone. Or start with wider issue Clean up autocomplete_w code. There is a too-big function that I would like to split. And maybe other things. Oh, and maybe some tests needing review.

# Position the completion list window
text = self.widget
text.see(self.startindex)
x, y, cx, cy = text.bbox(self.startindex)
acw = self.autocompletewindow
if platform.system().startswith('Windows'):
# On Windows an update() call is needed for the completion list
# window to be created, so that we can fetch its width and
# height. However, this is not needed on other platforms (tested
# on Ubuntu and macOS) but at one point began causing freezes on
# macOS. See issues 37849 and 41611.
acw.update()
acw_width, acw_height = acw.winfo_width(), acw.winfo_height()
text_width, text_height = text.winfo_width(), text.winfo_height()
new_x = text.winfo_rootx() + min(x, max(0, text_width - acw_width))
new_y = text.winfo_rooty() + y
if (text_height - (y + cy) >= acw_height # enough height below
or y < acw_height): # not enough height above
# place acw below current line
new_y += cy
else:
# place acw above current line
new_y -= acw_height
acw.wm_geometry("+%d+%d" % (new_x, new_y))
acw.update_idletasks()

# Since the <Configure> event may occur after the completion window is gone,
# catch potential TclError exceptions when accessing acw. See: bpo-41611.
try:
# Position the completion list window
text = self.widget
text.see(self.startindex)

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Heavy-handed? We could move the 'try' down a few lines. I considered whether 'see' is useful even when code below fails, but cannot see that it is. So I am OK with enclosing the entire logical block.

If we caught TclError after 261, what would we do? To return, we would have to duplicate the cleanup code after the new pass. To 'break', we would have to wrap this block with a fake loop. Both are worse.

taleinat May 27, 2021 •
edited
Loading

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Well I did write "somewhat heavy-handed" ;)

But yes, I too believe this is actually a good solution, besides perhaps refactoring to introduce a more consistent mechanism to avoid uncaught exceptions in event handlers.

But that seems out of scope for this fix.

x, y, cx, cy = text.bbox(self.startindex)
acw = self.autocompletewindow
if platform.system().startswith('Windows'):
# On Windows an update() call is needed for the completion
# list window to be created, so that we can fetch its width
# and height. However, this is not needed on other platforms
# (tested on Ubuntu and macOS) but at one point began
# causing freezes on macOS. See issues 37849 and 41611.
acw.update()
acw_width, acw_height = acw.winfo_width(), acw.winfo_height()
text_width, text_height = text.winfo_width(), text.winfo_height()
new_x = text.winfo_rootx() + min(x, max(0, text_width - acw_width))
new_y = text.winfo_rooty() + y
if (text_height - (y + cy) >= acw_height # enough height below
or y < acw_height): # not enough height above
# place acw below current line
new_y += cy
else:
# place acw above current line
new_y -= acw_height
acw.wm_geometry("+%d+%d" % (new_x, new_y))
acw.update_idletasks()
except TclError:
pass

if platform.system().startswith('Windows'):
# See issue 15786. When on Windows platform, Tk will misbehave
# See issue 15786. When on Windows platform, Tk will misbehave
# to call winconfig_event multiple times, we need to prevent this,
# otherwise mouse button double click will not be able to used.
acw.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
try:
acw.unbind(WINCONFIG_SEQUENCE, self.winconfigid)
except TclError:
pass
self.winconfigid = None

self.is_configuring = False
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid uncaught exceptions in ``AutoCompleteWindow.winconfig_event()``.

Back | FazBrowse Home | New Git URL