]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-92256: Improve Argument Clinic parser error messages (GH-92268)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 10 May 2022 07:48:34 +0000 (00:48 -0700)
committerGitHub <noreply@github.com>
Tue, 10 May 2022 07:48:34 +0000 (00:48 -0700)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 4bd07d1dbd493fc9b2c2a77e9e905c517682052e)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@protonmail.com>
Tools/clinic/clinic.py

index bf0fe5bed5a765d18e1a9fe2db9205bbab7b2d73..5ad4f879a33f7b76de609910249f0287afe14759 100755 (executable)
@@ -1628,10 +1628,16 @@ class BlockParser:
         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: