]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-120495: Fix incorrect exception handling in Tab Nanny (#120498)
authorWulian233 <71213467+Wulian233@users.noreply.github.com>
Sat, 15 Jun 2024 11:04:14 +0000 (19:04 +0800)
committerGitHub <noreply@github.com>
Sat, 15 Jun 2024 11:04:14 +0000 (05:04 -0600)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Lib/tabnanny.py
Lib/test/test_tabnanny.py
Misc/ACKS
Misc/NEWS.d/next/Library/2024-06-14-20-05-25.gh-issue-120495.OxgZKB.rst [new file with mode: 0644]

index 7e56d4a48d1d00b0cab54b0aeaf9aa4b83d5cc89..c0097351b269f2c7f3f7425e3fdbe49622c1a5cf 100644 (file)
@@ -105,14 +105,14 @@ def check(file):
         errprint("%r: Token Error: %s" % (file, msg))
         return
 
-    except SyntaxError as msg:
-        errprint("%r: Token Error: %s" % (file, msg))
-        return
-
     except IndentationError as msg:
         errprint("%r: Indentation Error: %s" % (file, msg))
         return
 
+    except SyntaxError as msg:
+        errprint("%r: Syntax Error: %s" % (file, msg))
+        return
+
     except NannyNag as nag:
         badline = nag.get_lineno()
         line = nag.get_line()
index cc122cafc7985cb05d789e8ba52d574c4ef9a890..30dcb3e3c4f4f95b9bc38e89a8dd1f7ba9530029 100644 (file)
@@ -315,7 +315,7 @@ class TestCommandLine(TestCase):
     def test_with_errored_file(self):
         """Should displays error when errored python file is given."""
         with TemporaryPyFile(SOURCE_CODES["wrong_indented"]) as file_path:
-            stderr  = f"{file_path!r}: Token Error: "
+            stderr  = f"{file_path!r}: Indentation Error: "
             stderr += ('unindent does not match any outer indentation level'
                        ' (<string>, line 3)')
             self.validate_cmd(file_path, stderr=stderr, expect_failure=True)
index 2f4c0793437fb6d2da9ef0ae2c079923dd2319c1..a406fca8744a5f47eca184b2c54f5057bd831399 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1099,6 +1099,7 @@ Ivan Levkivskyi
 Ben Lewis
 William Lewis
 Akira Li
+Jiahao Li
 Robert Li
 Xuanji Li
 Zekun Li
diff --git a/Misc/NEWS.d/next/Library/2024-06-14-20-05-25.gh-issue-120495.OxgZKB.rst b/Misc/NEWS.d/next/Library/2024-06-14-20-05-25.gh-issue-120495.OxgZKB.rst
new file mode 100644 (file)
index 0000000..d5114c3
--- /dev/null
@@ -0,0 +1 @@
+Fix incorrect exception handling in Tab Nanny. Patch by Wulian233.