Skip to content

Ambiguous invalid syntax error for a missing comma #123123

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

Closed
ZeroIntensity opened this issue Aug 18, 2024 · 3 comments · Fixed by #123131
Closed

Ambiguous invalid syntax error for a missing comma #123123

ZeroIntensity opened this issue Aug 18, 2024 · 3 comments · Fixed by #123131
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ZeroIntensity
Copy link
Member

ZeroIntensity commented Aug 18, 2024

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

@ZeroIntensity ZeroIntensity added the type-bug An unexpected behavior, bug, or error label Aug 18, 2024
@hugovk hugovk added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Aug 18, 2024
@hugovk
Copy link
Member

hugovk commented Aug 18, 2024

cc @pablogsal

@pablogsal
Copy link
Member

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

@pablogsal
Copy link
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 <[email protected]>
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

pablogsal added a commit to pablogsal/cpython that referenced this issue Aug 19, 2024
pablogsal added a commit that referenced this issue Aug 19, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 19, 2024
…pythonGH-123131)

(cherry picked from commit 48856ea)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
Signed-off-by: Pablo Galindo <[email protected]>
pablogsal added a commit that referenced this issue Aug 19, 2024
GH-123131) (#123147)

gh-123123: Fix display of syntax errors covering multiple lines (GH-123131)
(cherry picked from commit 48856ea)

Signed-off-by: Pablo Galindo <[email protected]>
Co-authored-by: Pablo Galindo Salgado <[email protected]>
jeremyhylton pushed a commit to jeremyhylton/cpython that referenced this issue Aug 19, 2024
blhsing pushed a commit to blhsing/cpython that referenced this issue Aug 22, 2024
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) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants