From d774a0bb271a4e67f9ac1d24f4f51d4cc7cd870d Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 3 May 2022 15:40:58 -0600 Subject: [PATCH 1/7] gh-92256: Improve Argument Clinic parser error messages --- Tools/clinic/clinic.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index bf0fe5bed5a765..d01b7d24e6c964 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1628,10 +1628,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): - return False - remainder = line[len(stop_line):] - return (not remainder) or remainder.isspace() + if line.startswith(stop_line): + remainder = line[len(stop_line):] + if remainder.isspace(): + return True + else: + fail(f"Garbage after stop line: '{remainder.strip()}'") + # gh-92256: don't allow incorrectly formatted stop lines + elif line.lstrip().startswith(stop_line): + fail("Whitespace is not allowed before the stop line") + return False # consume body of program while self.input: From f4392f0871a5a2749dd50975ca54466af68d53aa Mon Sep 17 00:00:00 2001 From: Erlend Egeberg Aasland Date: Tue, 3 May 2022 16:13:29 -0600 Subject: [PATCH 2/7] Address review: show raw string instead of strip()'d string Co-authored-by: Victor Stinner --- Tools/clinic/clinic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index d01b7d24e6c964..2ffa29bf76dffa 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1633,7 +1633,7 @@ def is_stop_line(line): if remainder.isspace(): return True else: - fail(f"Garbage after stop line: '{remainder.strip()}'") + fail(f"Garbage after stop line: {remainder!r}") # gh-92256: don't allow incorrectly formatted stop lines elif line.lstrip().startswith(stop_line): fail("Whitespace is not allowed before the stop line") From 9fc5c95d8517db4d4c3acc989a3f03f007961bf1 Mon Sep 17 00:00:00 2001 From: Erlend Egeberg Aasland Date: Tue, 3 May 2022 16:15:10 -0600 Subject: [PATCH 3/7] Address review: improve error message Co-authored-by: Victor Stinner --- Tools/clinic/clinic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 2ffa29bf76dffa..2cdcb9ba27f7be 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1636,7 +1636,7 @@ def is_stop_line(line): fail(f"Garbage after stop line: {remainder!r}") # gh-92256: don't allow incorrectly formatted stop lines elif line.lstrip().startswith(stop_line): - fail("Whitespace is not allowed before the stop line") + fail("Whitespace is not allowed before the stop line: {stop_line!r}") return False # consume body of program From 53b4016bebe8588b7621a4ccff431df86cc2a62d Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 3 May 2022 16:24:15 -0600 Subject: [PATCH 4/7] Add NEWS --- .../Tools-Demos/2022-05-03-16-24-12.gh-issue-92268.CMP6Xm.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Tools-Demos/2022-05-03-16-24-12.gh-issue-92268.CMP6Xm.rst diff --git a/Misc/NEWS.d/next/Tools-Demos/2022-05-03-16-24-12.gh-issue-92268.CMP6Xm.rst b/Misc/NEWS.d/next/Tools-Demos/2022-05-03-16-24-12.gh-issue-92268.CMP6Xm.rst new file mode 100644 index 00000000000000..0dc9a09c92bbef --- /dev/null +++ b/Misc/NEWS.d/next/Tools-Demos/2022-05-03-16-24-12.gh-issue-92268.CMP6Xm.rst @@ -0,0 +1,2 @@ +Improve Argument Clinic error messages for wrongly formatted clinic end +lines. Patch by Erlend E. Aasland. From a7c5b178ce9eb4dc182d5c97964c42e56f58edda Mon Sep 17 00:00:00 2001 From: Erlend Egeberg Aasland Date: Wed, 4 May 2022 08:40:56 -0600 Subject: [PATCH 5/7] Apply Serhiy's suggestion Co-authored-by: Serhiy Storchaka --- Tools/clinic/clinic.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index 2cdcb9ba27f7be..f4144d75df658a 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1630,14 +1630,14 @@ def is_stop_line(line): # doesn't end with EOL (it could be the very end of the file) if line.startswith(stop_line): remainder = line[len(stop_line):] - if remainder.isspace(): - return True - else: + if remainder and not remainder.isspace(): fail(f"Garbage after stop line: {remainder!r}") - # gh-92256: don't allow incorrectly formatted stop lines - elif line.lstrip().startswith(stop_line): - fail("Whitespace is not allowed before the stop line: {stop_line!r}") - return False + return True + else: + # gh-92256: don't allow incorrectly formatted stop lines + if line.lstrip().startswith(stop_line): + fail("Whitespace is not allowed before the stop line: {stop_line!r}") + return False # consume body of program while self.input: From 650392841091e62be25aafab7e43a031af6cdab0 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 4 May 2022 08:50:22 -0600 Subject: [PATCH 6/7] Fixup a7c5b178ce9eb4dc182d5c97964c42e56f58edda --- Tools/clinic/clinic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index f4144d75df658a..5ad4f879a33f7b 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -1636,7 +1636,7 @@ def is_stop_line(line): else: # gh-92256: don't allow incorrectly formatted stop lines if line.lstrip().startswith(stop_line): - fail("Whitespace is not allowed before the stop line: {stop_line!r}") + fail(f"Whitespace is not allowed before the stop line: {line!r}") return False # consume body of program From 899fd12073fd8894165087f22dad20df451baa5b Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Thu, 5 May 2022 14:20:20 +0200 Subject: [PATCH 7/7] Address review: Remove NEWS entry --- .../Tools-Demos/2022-05-03-16-24-12.gh-issue-92268.CMP6Xm.rst | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Misc/NEWS.d/next/Tools-Demos/2022-05-03-16-24-12.gh-issue-92268.CMP6Xm.rst diff --git a/Misc/NEWS.d/next/Tools-Demos/2022-05-03-16-24-12.gh-issue-92268.CMP6Xm.rst b/Misc/NEWS.d/next/Tools-Demos/2022-05-03-16-24-12.gh-issue-92268.CMP6Xm.rst deleted file mode 100644 index 0dc9a09c92bbef..00000000000000 --- a/Misc/NEWS.d/next/Tools-Demos/2022-05-03-16-24-12.gh-issue-92268.CMP6Xm.rst +++ /dev/null @@ -1,2 +0,0 @@ -Improve Argument Clinic error messages for wrongly formatted clinic end -lines. Patch by Erlend E. Aasland.