Skip to content

bpo-42426: IDLE: Fix reporting offset of the RE error in searchengine #23447

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/idlelib/NEWS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Released on 2021-10-04?
======================================


bpo-42426: Fix reporting offset of the RE error in searchengine.

bpo-42416: Get docstrings for IDLE calltips more often
by using inspect.getdoc.

Expand Down
6 changes: 4 additions & 2 deletions Lib/idlelib/idle_test/test_searchengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,13 @@ def test_getprog(self):

engine.setpat('')
Equal(engine.getprog(), None)
Equal(Mbox.showerror.message,
'Error: Empty regular expression')
engine.setpat('+')
engine.revar.set(1)
Equal(engine.getprog(), None)
self.assertEqual(Mbox.showerror.message,
'Error: nothing to repeat at position 0\nPattern: +')
Copy link
Member

Choose a reason for hiding this comment

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

When I reviewed this file, written by GSOC student, I missed that this test passes because the buggy expected matches the buggy result of buggy code.

Equal(Mbox.showerror.message,
'Error: nothing to repeat\nPattern: +\nOffset: 0')

def test_report_error(self):
showerror = Mbox.showerror
Expand Down
11 changes: 4 additions & 7 deletions Lib/idlelib/searchengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,17 @@ def getprog(self):
flags = flags | re.IGNORECASE
try:
prog = re.compile(pat, flags)
except re.error as what:
args = what.args
msg = args[0]
col = args[1] if len(args) >= 2 else -1
Copy link
Member

Choose a reason for hiding this comment

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

This was my 'fix' for the original 2020 code that had msg, col = what. Even is args was a 3-tuple as I expected (see issue), that should have been args[2]. Since args is a 1-tuple, this always resulted in -1.

self.report_error(pat, msg, col)
except re.error as e:
Copy link
Member

Choose a reason for hiding this comment

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

I like the change to 'e' and simplification of code.

self.report_error(pat, e.msg, e.pos)
return None
return prog

def report_error(self, pat, msg, col=-1):
def report_error(self, pat, msg, col=None):
# Derived class could override this with something fancier
msg = "Error: " + str(msg)
if pat:
msg = msg + "\nPattern: " + str(pat)
if col >= 0:
if col is not None:
msg = msg + "\nOffset: " + str(col)
tkMessageBox.showerror("Regular expression error",
msg, master=self.root)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix reporting offset of the RE error in searchengine.