Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-92256: Improve Argument Clinic parser error messages #92268

Merged
merged 7 commits into from
May 10, 2022

Conversation

erlend-aasland
Copy link
Contributor

No description provided.

@erlend-aasland
Copy link
Contributor Author

(I'm not sure this needs a NEWS item, but I'm happy to add one.)

@erlend-aasland
Copy link
Contributor Author

Details:

- Behaviour pre this change

Whitespace before end line (disallowed with confusing error message):

$ git diff
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 0e903ade5b..5c1f2d4d87 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -32,7 +32,7 @@
 /*[clinic input]
 module _sqlite3
 class _sqlite3.Cursor "pysqlite_Cursor *" "clinic_state()->CursorType"
-[clinic start generated code]*/
+ [clinic start generated code]*/
 /*[clinic end generated code: output=da39a3ee5e6b4b0d input=3c5b8115c5cf30f1]*/
 
 /*
$ python3.11  Tools/clinic/clinic.py -f Modules/_sqlite/cursor.c 
Error in file "Modules/_sqlite/cursor.c" on line 71:
Illegal function name: [clinic start generated code]*/

Whitespace after end line (allowed):

$ git diff
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 0e903ade5b..958891b995 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -32,7 +32,7 @@
 /*[clinic input]
 module _sqlite3
 class _sqlite3.Cursor "pysqlite_Cursor *" "clinic_state()->CursorType"
-[clinic start generated code]*/
+[clinic start generated code]*/ 
 /*[clinic end generated code: output=da39a3ee5e6b4b0d input=3c5b8115c5cf30f1]*/
 
 /*
$ !py
python3.11  Tools/clinic/clinic.py -f Modules/_sqlite/cursor.c 
$

Garbage after end line (fails badly):

$ git diff
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 0e903ade5b..8df423fc80 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -32,7 +32,7 @@
 /*[clinic input]
 module _sqlite3
 class _sqlite3.Cursor "pysqlite_Cursor *" "clinic_state()->CursorType"
-[clinic start generated code]*/
+[clinic start generated code]*/ // this won't work
 /*[clinic end generated code: output=da39a3ee5e6b4b0d input=3c5b8115c5cf30f1]*/
 
 /*
$ python3.11  Tools/clinic/clinic.py -f Modules/_sqlite/cursor.c 
Error in file "Modules/_sqlite/cursor.c" on line 71:
Exception raised during parsing:
Traceback (most recent call last):
  File "/Users/erlendaasland/src/cpython.git/Tools/clinic/clinic.py", line 2025, in parse
    parser.parse(block)
    ^^^^^^^^^^^^^^^^^^^
  File "/Users/erlendaasland/src/cpython.git/Tools/clinic/clinic.py", line 4176, in parse
    self.state(line)
    ^^^^^^^^^^^^^^^^
  File "/Users/erlendaasland/src/cpython.git/Tools/clinic/clinic.py", line 4217, in state_dsl_start
    fields = shlex.split(line)
             ^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/shlex.py", line 315, in split
    return list(lex)
           ^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/shlex.py", line 300, in __next__
    token = self.get_token()
            ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/shlex.py", line 109, in get_token
    raw = self.read_token()
          ^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/shlex.py", line 191, in read_token
    raise ValueError("No closing quotation")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: No closing quotation
- Behaviour post this change

Whitespace before end line (currently disallowed):

$ git diff
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 0e903ade5b..5c1f2d4d87 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -32,7 +32,7 @@
 /*[clinic input]
 module _sqlite3
 class _sqlite3.Cursor "pysqlite_Cursor *" "clinic_state()->CursorType"
-[clinic start generated code]*/
+ [clinic start generated code]*/
 /*[clinic end generated code: output=da39a3ee5e6b4b0d input=3c5b8115c5cf30f1]*/
 
 /*

$ python3.11  Tools/clinic/clinic.py -f Modules/_sqlite/cursor.c 
Error in file "Modules/_sqlite/cursor.c" on line 35:
Whitespace is not allowed before the stop line

Whitespace after end line (allowed):

$ git diff
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 0e903ade5b..8e4889f162 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -32,7 +32,7 @@
 /*[clinic input]
 module _sqlite3
 class _sqlite3.Cursor "pysqlite_Cursor *" "clinic_state()->CursorType"
-[clinic start generated code]*/
+[clinic start generated code]*/    
 /*[clinic end generated code: output=da39a3ee5e6b4b0d input=3c5b8115c5cf30f1]*/
 
 /*
$ python3.11  Tools/clinic/clinic.py -f Modules/_sqlite/cursor.c 

Garbage after end line (disallowed):

$ git diff
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c
index 0e903ade5b..8df423fc80 100644
--- a/Modules/_sqlite/cursor.c
+++ b/Modules/_sqlite/cursor.c
@@ -32,7 +32,7 @@
 /*[clinic input]
 module _sqlite3
 class _sqlite3.Cursor "pysqlite_Cursor *" "clinic_state()->CursorType"
-[clinic start generated code]*/
+[clinic start generated code]*/ // this won't work
 /*[clinic end generated code: output=da39a3ee5e6b4b0d input=3c5b8115c5cf30f1]*/
 
 /*
$ python3.11  Tools/clinic/clinic.py -f Modules/_sqlite/cursor.c 
Error in file "Modules/_sqlite/cursor.c" on line 35:
Garbage after stop line: '// this won't work'

Tools/clinic/clinic.py Outdated Show resolved Hide resolved
Tools/clinic/clinic.py Outdated Show resolved Hide resolved
Erlend Egeberg Aasland and others added 3 commits May 3, 2022 16:13
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Tools/clinic/clinic.py Outdated Show resolved Hide resolved
Tools/clinic/clinic.py Outdated Show resolved Hide resolved
Erlend Egeberg Aasland and others added 2 commits May 4, 2022 08:40
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@erlend-aasland
Copy link
Contributor Author

Thanks for the reviews and suggestions, Serhiy and Victor; highly appreciated.

@erlend-aasland
Copy link
Contributor Author

BTW, I guess we should backport this through 3.9.

@serhiy-storchaka
Copy link
Member

It is an internal tool. No NEWS entry is needed. The change is invisible for users.

@erlend-aasland
Copy link
Contributor Author

It is an internal tool. No NEWS entry is needed. The change is invisible for users.

I'll remove the NEWS entry; thanks again.

@erlend-aasland erlend-aasland added the needs backport to 3.11 only security fixes label May 8, 2022
@erlend-aasland
Copy link
Contributor Author

Serhiy and Victor have approved this change. I'll land this in a day or two.

@erlend-aasland erlend-aasland merged commit 4bd07d1 into python:main May 10, 2022
@miss-islington
Copy link
Contributor

Thanks @erlend-aasland for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10, 3.11.
🐍🍒⛏🤖

@erlend-aasland erlend-aasland deleted the ac-error-messages branch May 10, 2022 07:23
@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label May 10, 2022
@bedevere-bot
Copy link

GH-92614 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label May 10, 2022
@bedevere-bot
Copy link

GH-92615 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label May 10, 2022
@bedevere-bot
Copy link

GH-92616 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 10, 2022
…GH-92268)

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>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 10, 2022
…GH-92268)

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>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 10, 2022
…GH-92268)

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>
miss-islington added a commit that referenced this pull request May 10, 2022
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>
miss-islington added a commit that referenced this pull request May 10, 2022
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>
miss-islington added a commit that referenced this pull request May 10, 2022
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>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
…GH-92268)

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants