Skip to content

Different error triggered for soft keyword prefixes #130077

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

Open
thatbirdguythatuknownot opened this issue Feb 13, 2025 · 0 comments
Open

Different error triggered for soft keyword prefixes #130077

thatbirdguythatuknownot opened this issue Feb 13, 2025 · 0 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-parser type-bug An unexpected behavior, bug, or error

Comments

@thatbirdguythatuknownot
Copy link
Contributor

thatbirdguythatuknownot commented Feb 13, 2025

Bug report

Bug description:

In the grammar file, a soft keyword being the start of an expression makes it fail the path where the error message has this appended: "Perhaps you forgot a comma?"
However, it also apparently does the same thing for any identifer that is a prefix of any soft keyword.

>>> # multi-letter cases
>>> # fine, expected behavior
>>> (test x)
  File "<stdin>", line 1
    (test x)
     ^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>>> (match_ x)
  File "<stdin>", line 1
    (match_ x)
     ^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>>> (match x)
  File "<stdin>", line 1
    (match x)
           ^
SyntaxError: invalid syntax
>>> # unexpected behavior
>>> (ma x)
  File "<stdin>", line 1
    (ma x)
        ^
SyntaxError: invalid syntax
>>> # single-letter bugs
>>> # expected behavior
>>> (f x)
  File "<stdin>", line 1
    (f x)
     ^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>>> # unexpected behavior
>>> (m x)
  File "<stdin>", line 1
    (m x)
       ^
SyntaxError: invalid syntax

Since m is a prefix of match, "forgetting a comma" (i.e. being in a situation that normally triggers that specific error) doesn't provide the same error message as other "normal" identifiers.

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Linked PRs

@thatbirdguythatuknownot thatbirdguythatuknownot added the type-bug An unexpected behavior, bug, or error label Feb 13, 2025
@picnixz picnixz added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Feb 14, 2025
isatyamks added a commit to isatyamks/cpython that referenced this issue Feb 15, 2025
isatyamks added a commit to isatyamks/cpython that referenced this issue Feb 16, 2025
isatyamks added a commit to isatyamks/cpython that referenced this issue Jun 9, 2025
pablogsal added a commit to pablogsal/cpython that referenced this issue Jun 9, 2025
pablogsal added a commit to pablogsal/cpython that referenced this issue Jun 9, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 10, 2025
…honGH-135317)

(cherry picked from commit ff2b5f4)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit that referenced this issue Jun 11, 2025
…-135317) (#135348)

gh-130077: Properly match full soft keywords in the parser (GH-135317)
(cherry picked from commit ff2b5f4)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit to pablogsal/cpython that referenced this issue Jun 11, 2025
…er (pythonGH-135317)

(cherry picked from commit ff2b5f4)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit to pablogsal/cpython that referenced this issue Jun 11, 2025
…er (pythonGH-135317)

(cherry picked from commit ff2b5f4)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-parser type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants