Skip to content

Ambiguous invalid syntax error for a missing comma #123123

Closed

Description

@ZeroIntensity

Bug report

Bug description:

Trying to run the following code:

dummy_call(
    "dummy value"
    foo="bar",
)

results in a SyntaxError that looks like:

  File "...", line 2
    "dummy value"
    ^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

On 3.13+, the first three characters are also highlighted in red. I would expect the end of the line (where the comma should be) to be marked, the foo=bar line, or possibly the entire line.

Interestingly, if you remove the indentation, then the error looks as expected:

  File "...", line 1
    dummy_call("dummy value" foo="bar",)
               ^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

CPython versions tested on:

3.12, 3.13, CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. hugovk commented on Aug 18, 2024

    @hugovk
    Member
  2. pablogsal commented on Aug 18, 2024

    @pablogsal
    Member

    Oh this may be that some line information is not being propagated properly. Will take a look soon

  3. pablogsal commented on Aug 18, 2024

    @pablogsal
    Member

    Seems that somehow this is a side effect of our change to always use the traceback module as I bisected this to:

    e7331365b488382d906ce6733ab1349ded49c928 is the first bad commit
    commit e7331365b488382d906ce6733ab1349ded49c928 (HEAD)
    Author: Pablo Galindo Salgado <Pablogsal@gmail.com>
    Date:   Thu Oct 12 16:52:14 2023 +0200
    
        gh-110721: Use the traceback module for PyErr_Display() and fallback to the C implementation (#110702)
    
     Include/internal/pycore_traceback.h                                               |   5 +-
     Lib/test/test_sys.py                                                              |   3 +-
     Lib/test/test_traceback.py                                                        |  55 +++--
     Lib/traceback.py                                                                  |  26 ++-
     Misc/NEWS.d/next/Core and Builtins/2023-10-11-16-56-54.gh-issue-110721.afcSsH.rst |   2 +
     Python/pythonrun.c                                                                | 577 ++++++-----------------------------------------------
     Python/traceback.c                                                                | 315 ++---------------------------
     7 files changed, 146 insertions(+), 837 deletions(-)
     create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-10-11-16-56-54.gh-issue-110721.afcSsH.rst
    
    
  4. added 3 commits that reference this issue on Aug 18, 2024
  5. added a commit that references this issue on Aug 19, 2024
  6. added a commit that references this issue on Aug 19, 2024
  7. added a commit that references this issue on Aug 19, 2024
  8. added a commit that references this issue on Aug 22, 2024
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)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions