Skip to content

Commit

Permalink
gh-92256: Improve Argument Clinic parser error messages (GH-92268)
Browse files Browse the repository at this point in the history
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
(cherry picked from commit 4bd07d1)

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@protonmail.com>
  • Loading branch information
miss-islington and erlend-aasland committed May 10, 2022
1 parent b7a8786 commit 35d589c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Tools/clinic/clinic.py
Expand Up @@ -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:
Expand Down

0 comments on commit 35d589c

Please sign in to comment.