https://github.com/python/cpython/commit/1242c2739a0b8161d2a4ded1e0e595b2db962ccb
commit: 1242c2739a0b8161d2a4ded1e0e595b2db962ccb
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: hugovk <[email protected]>
date: 2024-06-15T11:21:05Z
summary:

[3.12] gh-120495: Fix incorrect exception handling in Tab Nanny (GH-120498) 
(#120549)

gh-120495: Fix incorrect exception handling in Tab Nanny (GH-120498)
(cherry picked from commit c501261c919ceb97c850ef9427a93326f06a8f2e)

Co-authored-by: Wulian233 <[email protected]>
Co-authored-by: Hugo van Kemenade <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-06-14-20-05-25.gh-issue-120495.OxgZKB.rst
M Lib/tabnanny.py
M Lib/test/test_tabnanny.py
M Misc/ACKS

diff --git a/Lib/tabnanny.py b/Lib/tabnanny.py
index e2ac6837f157d5..d06c4c221e9341 100755
--- a/Lib/tabnanny.py
+++ b/Lib/tabnanny.py
@@ -107,14 +107,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()
diff --git a/Lib/test/test_tabnanny.py b/Lib/test/test_tabnanny.py
index cc122cafc7985c..30dcb3e3c4f4f9 100644
--- a/Lib/test/test_tabnanny.py
+++ b/Lib/test/test_tabnanny.py
@@ -315,7 +315,7 @@ def validate_cmd(self, *args, stdout="", stderr="", 
partial=False, expect_failur
     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)
diff --git a/Misc/ACKS b/Misc/ACKS
index 88bac0a8749f9f..f6285ca23f32a8 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1086,6 +1086,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
index 00000000000000..d5114c3d3c904c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-06-14-20-05-25.gh-issue-120495.OxgZKB.rst
@@ -0,0 +1 @@
+Fix incorrect exception handling in Tab Nanny. Patch by Wulian233.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to