Skip to content

Different error triggered for soft keyword prefixes #130077

Closed

Description

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

Activity

  1. added 3 commits that reference this issue on Jun 9, 2025
  2. added a commit that references this issue on Jun 10, 2025
  3. added 3 commits that reference this issue on Jun 11, 2025
  4. added a commit that references this issue on Jun 19, 2025
  5. added a commit that references this issue on Jul 8, 2025
  6. added a commit that references this issue on Jul 12, 2025
  7. added a commit that references this issue on Aug 4, 2025
  8. added a commit that references this issue on Aug 4, 2025
  9. added a commit that references this issue on Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-parsertype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions