summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-11-22 05:06:51 (GMT)
committerGitHub <noreply@github.com>2020-11-22 05:06:51 (GMT)
commit453bc1da2023d6cbe362637a2e0b06d0521f013c (patch)
treeb872c7850c15ffedf4ec67601743def89689ce18 /Lib/idlelib
parent442746af649cc2c20d690acfabf44ab0e06c36b4 (diff)
downloadcpython-453bc1da2023d6cbe362637a2e0b06d0521f013c.zip
cpython-453bc1da2023d6cbe362637a2e0b06d0521f013c.tar.gz
cpython-453bc1da2023d6cbe362637a2e0b06d0521f013c.tar.bz2
bpo-42426: IDLE: Fix reporting offset of the RE error in searchengine (GH-23447)
Diffstat (limited to 'Lib/idlelib')
-rw-r--r--Lib/idlelib/NEWS.txt2
-rw-r--r--Lib/idlelib/idle_test/test_searchengine.py6
-rw-r--r--Lib/idlelib/searchengine.py11
3 files changed, 10 insertions, 9 deletions
diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index c9f28f6..34f28d6 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -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.
diff --git a/Lib/idlelib/idle_test/test_searchengine.py b/Lib/idlelib/idle_test/test_searchengine.py
index 3d26d62..f8401ce 100644
--- a/Lib/idlelib/idle_test/test_searchengine.py
+++ b/Lib/idlelib/idle_test/test_searchengine.py
@@ -175,11 +175,13 @@ class SearchEngineTest(unittest.TestCase):
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: +')
+ Equal(Mbox.showerror.message,
+ 'Error: nothing to repeat\nPattern: +\nOffset: 0')
def test_report_error(self):
showerror = Mbox.showerror
diff --git a/Lib/idlelib/searchengine.py b/Lib/idlelib/searchengine.py
index 911e7d4..a50038e 100644
--- a/Lib/idlelib/searchengine.py
+++ b/Lib/idlelib/searchengine.py
@@ -84,20 +84,17 @@ class SearchEngine:
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
- self.report_error(pat, msg, col)
+ except re.error as e:
+ 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)