Skip to content

Commit de33490

Browse files
gh-92256: Improve Argument Clinic parser error messages (GH-92268)
Co-authored-by: Serhiy Storchaka <[email protected]> Co-authored-by: Victor Stinner <[email protected]> (cherry picked from commit 4bd07d1) Co-authored-by: Erlend Egeberg Aasland <[email protected]>
1 parent 7540a43 commit de33490

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Tools/clinic/clinic.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,10 +1628,16 @@ def parse_clinic_block(self, dsl_name):
16281628
def is_stop_line(line):
16291629
# make sure to recognize stop line even if it
16301630
# doesn't end with EOL (it could be the very end of the file)
1631-
if not line.startswith(stop_line):
1631+
if line.startswith(stop_line):
1632+
remainder = line[len(stop_line):]
1633+
if remainder and not remainder.isspace():
1634+
fail(f"Garbage after stop line: {remainder!r}")
1635+
return True
1636+
else:
1637+
# gh-92256: don't allow incorrectly formatted stop lines
1638+
if line.lstrip().startswith(stop_line):
1639+
fail(f"Whitespace is not allowed before the stop line: {line!r}")
16321640
return False
1633-
remainder = line[len(stop_line):]
1634-
return (not remainder) or remainder.isspace()
16351641

16361642
# consume body of program
16371643
while self.input:

0 commit comments

Comments
 (0)