[Python-checkins] bpo-42426: IDLE: Fix reporting offset of the RE error in searchengine (GH-23447)

miss-islington webhook-mailer at python.org
Sun Nov 22 00:30:58 EST 2020


https://github.com/python/cpython/commit/dd20643b144d1c81989d235c3ec51f18fda618c2
commit: dd20643b144d1c81989d235c3ec51f18fda618c2
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2020-11-21T21:30:46-08:00
summary:

bpo-42426: IDLE: Fix reporting offset of the RE error in searchengine (GH-23447)

(cherry picked from commit 453bc1da2023d6cbe362637a2e0b06d0521f013c)

Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>

files:
A Misc/NEWS.d/next/IDLE/2020-11-21-17-21-21.bpo-42426.kNnPoC.rst
M Lib/idlelib/NEWS.txt
M Lib/idlelib/idle_test/test_searchengine.py
M Lib/idlelib/searchengine.py

diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index 6eacde95d908d..e257ee9fdeb32 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -3,6 +3,8 @@ Released on 2020-12-07?
 ======================================
 
 
+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 3d26d62a95a87..f8401ce9380f2 100644
--- a/Lib/idlelib/idle_test/test_searchengine.py
+++ b/Lib/idlelib/idle_test/test_searchengine.py
@@ -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: +')
+        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 911e7d4691cac..a50038e282ba6 100644
--- a/Lib/idlelib/searchengine.py
+++ b/Lib/idlelib/searchengine.py
@@ -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
-            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)
diff --git a/Misc/NEWS.d/next/IDLE/2020-11-21-17-21-21.bpo-42426.kNnPoC.rst b/Misc/NEWS.d/next/IDLE/2020-11-21-17-21-21.bpo-42426.kNnPoC.rst
new file mode 100644
index 0000000000000..0ab7972aad982
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2020-11-21-17-21-21.bpo-42426.kNnPoC.rst
@@ -0,0 +1 @@
+Fix reporting offset of the RE error in searchengine.



More information about the Python-checkins mailing list