[Python-checkins] gh-92256: Improve Argument Clinic parser error messages (GH-92268)

miss-islington webhook-mailer at python.org
Tue May 10 03:43:30 EDT 2022


https://github.com/python/cpython/commit/7954b664d4c5db56ec28da57e783186f4d713517
commit: 7954b664d4c5db56ec28da57e783186f4d713517
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-05-10T00:43:26-07:00
summary:

gh-92256: Improve Argument Clinic parser error messages (GH-92268)


Co-authored-by: Serhiy Storchaka <storchaka at gmail.com>
Co-authored-by: Victor Stinner <vstinner at python.org>
(cherry picked from commit 4bd07d1dbd493fc9b2c2a77e9e905c517682052e)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland at protonmail.com>

files:
M Tools/clinic/clinic.py

diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index b442c494d31d4..9ea2784085aac 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -1566,10 +1566,16 @@ def parse_clinic_block(self, dsl_name):
         def is_stop_line(line):
             # make sure to recognize stop line even if it
             # doesn't end with EOL (it could be the very end of the file)
-            if not line.startswith(stop_line):
+            if line.startswith(stop_line):
+                remainder = line[len(stop_line):]
+                if remainder and not remainder.isspace():
+                    fail(f"Garbage after stop line: {remainder!r}")
+                return True
+            else:
+                # gh-92256: don't allow incorrectly formatted stop lines
+                if line.lstrip().startswith(stop_line):
+                    fail(f"Whitespace is not allowed before the stop line: {line!r}")
                 return False
-            remainder = line[len(stop_line):]
-            return (not remainder) or remainder.isspace()
 
         # consume body of program
         while self.input:



More information about the Python-checkins mailing list