summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@protonmail.com>2022-05-10 07:23:42 (GMT)
committerGitHub <noreply@github.com>2022-05-10 07:23:42 (GMT)
commit4bd07d1dbd493fc9b2c2a77e9e905c517682052e (patch)
treee4f46b96456d53a632a141bc9ba9dced036513c2
parentf1bbcba74f77eff2a4c0881f3d529f3bf0664d40 (diff)
downloadcpython-4bd07d1dbd493fc9b2c2a77e9e905c517682052e.zip
cpython-4bd07d1dbd493fc9b2c2a77e9e905c517682052e.tar.gz
cpython-4bd07d1dbd493fc9b2c2a77e9e905c517682052e.tar.bz2
gh-92256: Improve Argument Clinic parser error messages (#92268)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
-rwxr-xr-xTools/clinic/clinic.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index bf0fe5b..5ad4f87 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -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: