Skip to content

Commit 7954b66

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 5ed2f11 commit 7954b66

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
@@ -1566,10 +1566,16 @@ def parse_clinic_block(self, dsl_name):
15661566
def is_stop_line(line):
15671567
# make sure to recognize stop line even if it
15681568
# doesn't end with EOL (it could be the very end of the file)
1569-
if not line.startswith(stop_line):
1569+
if line.startswith(stop_line):
1570+
remainder = line[len(stop_line):]
1571+
if remainder and not remainder.isspace():
1572+
fail(f"Garbage after stop line: {remainder!r}")
1573+
return True
1574+
else:
1575+
# gh-92256: don't allow incorrectly formatted stop lines
1576+
if line.lstrip().startswith(stop_line):
1577+
fail(f"Whitespace is not allowed before the stop line: {line!r}")
15701578
return False
1571-
remainder = line[len(stop_line):]
1572-
return (not remainder) or remainder.isspace()
15731579

15741580
# consume body of program
15751581
while self.input:

0 commit comments

Comments
 (0)