GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Confusing SyntaxError for multi-line string concatenation with missing comma · Issue #142236 · python/cpython

Confusing SyntaxError for multi-line string concatenation with missing comma #142236

New issue
Copy link
New issue
Copy link
Closed
Closed
Confusing SyntaxError for multi-line string concatenation with missing comma#142236
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtopic-parsertype-featureA feature request or enhancementA feature request or enhancement

Description

@lucaswerkmeister
lucaswerkmeister
opened on Dec 3, 2025
Issue body actions

Bug report

Bug description:

I just spent a couple of minutes figuring out what was wrong with this code:

import sys

print(
    "\n"
    "Notice: a Git repository with 'main' and 'doc' branches has been set up.\n"
    "You will probably want to amend the initial commit on the 'main' branch.\n"
    file=sys.stderr
)

It produces the following error:

  File "/tmp/tmp.py", line 4
    "\n"
    ^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

Which had me looking at the "\n" line and trying to confirm if Python even has string literal concatenation like I seemed to remember (it does). The error was actually two lines further down, at the end of the concatenated string literal: that line was missing the comma (fix).

Would it be possible to improve the error message, moving it to the last line of the string literal that doesn’t have a comma?

CPython versions tested on:

3.14, 3.13, 3.15

Operating systems tested on:

Linux

Linked PRs

  • gh-142236: Fix incorrect keyword suggestions for syntax errors #142328
  • gh-142236: Improve error location for missing comma in string concatenations #142330

Activity

Next
  1. lucaswerkmeister
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Dec 3, 2025
  2. lucaswerkmeister commented on Dec 3, 2025

    @lucaswerkmeister
    lucaswerkmeister
    on Dec 3, 2025
    Author
    More actions

    (Not sure if “bug” is the right type for this, feel free to re-label – or close, for that matter. But I thought you might want to hear about a confusing error message :))

  3. StanFromIreland
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Dec 3, 2025
  4. johnslavik commented on Dec 3, 2025

    @johnslavik
    johnslavik
    on Dec 3, 2025
    Member
    More actions

    CC @ZeroIntensity (mentorship): That would be topic-parser I think.

    I may give this a shot later this week.

  5. StanFromIreland commented on Dec 3, 2025

    @StanFromIreland
    StanFromIreland
    on Dec 3, 2025
    Member
    More actions

    The suggestion I get on main in the repl is even worse:

      File "<python-input-0>", line 4
        print(
        ^^^^^
    SyntaxError: invalid syntax. Did you mean 'not'?
    
    Reacted by Bartosz Sławecki, Maxim Martynov and Oleksandr Kravets
  6. StanFromIreland commented on Dec 3, 2025

    @StanFromIreland
    StanFromIreland
    on Dec 3, 2025
    Member
    More actions

    It's traceback.py. CC @pablogsal

    Reacted by Bartosz Sławecki
  7. StanFromIreland
    added
    topic-parser
    on Dec 3, 2025
  8. johnslavik commented on Dec 3, 2025

    @johnslavik
    johnslavik
    on Dec 3, 2025
    Member
    More actions

    @StanFromIreland If it's traceback.py, then maybe let's also add stdlib.

  9. StanFromIreland commented on Dec 3, 2025

    @StanFromIreland
    StanFromIreland
    on Dec 3, 2025
    Member
    More actions

    Let's deal with the first issue for now.

  10. StanFromIreland
    added
    type-featureA feature request or enhancementA feature request or enhancement
    and removed
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Dec 3, 2025
  11. lucaswerkmeister commented on Dec 3, 2025

    @lucaswerkmeister
    lucaswerkmeister
    on Dec 3, 2025
    Author
    More actions

    The suggestion I get on main in the repl is even worse:

      File "<python-input-0>", line 4
        print(
        ^^^^^
    SyntaxError: invalid syntax. Did you mean 'not'?
    

    FWIW, I got a similar error earlier when I tried out the input in a REPL, but the previous error when evaluating a .py file.

    shell session
    $ docker run --rm -it --entrypoint=bash python:3.15-rc-trixie
    root@6282dd65901a:/# python
    Python 3.15.0a2 (main, Nov 19 2025, 18:40:55) [GCC 14.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    ... 
    ... print(
    ...     "\n"
    ...     "Notice: a Git repository with 'main' and 'doc' branches has been set up.\n"
    ...     "You will probably want to amend the initial commit on the 'main' branch.\n"
    ...     file=sys.stderr
    ... )
    ... 
      File "<python-input-0>", line 4
        print(
        ^^^^^
    SyntaxError: invalid syntax. Did you mean 'not'?
    >>> 
    root@6282dd65901a:/# cat >| /tmp/tmp.py
    import sys
    
    print(
        "\n"
        "Notice: a Git repository with 'main' and 'doc' branches has been set up.\n"
        "You will probably want to amend the initial commit on the 'main' branch.\n"
        file=sys.stderr
    )
    root@6282dd65901a:/# python /tmp/tmp.py
      File "/tmp/tmp.py", line 4
        "\n"
        ^^^^
    SyntaxError: invalid syntax. Perhaps you forgot a comma?
    
  12. pablogsal
    added 3 commits that reference this issue on Dec 6, 2025

    pythongh-142236: Fix incorrect keyword suggestions for syntax errors

    944b847

    pythongh-142236: Fix incorrect keyword suggestions for syntax errors

    c61b475

    pythongh-142236: Fix incorrect keyword suggestions for syntax errors

    47240cf
  13. 1 remaining item

  14. pablogsal
    added 5 commits that reference this issue on Dec 6, 2025

    pythongh-142236: Improve error location for missing comma in string c…

    e5084f2

    pythongh-142236: Improve error location for missing comma in string c…

    1c45d6c

    pythongh-142236: Improve error location for missing comma in string c…

    fbb59b7

    gh-142236: Fix incorrect keyword suggestions for syntax errors (#142328)

    ed4f78a

    gh-142236: Improve error location for missing comma in string concate…

    c433986
  15. fatelei
    added a commit that references this issue on Dec 12, 2025

    pythongh-142236: Improve error location for missing comma in string c…

    0a23aaa
  16. StanFromIreland commented on Jan 9, 2026

    @StanFromIreland
    StanFromIreland
    on Jan 9, 2026
    Member
    More actions

    @pablogsal do you want to backport the two PRs? Otherwise there is nothing left to do here.

  17. StanFromIreland
    added
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    on Jan 9, 2026
  18. pablogsal commented on Jan 9, 2026

    @pablogsal
    pablogsal
    on Jan 9, 2026
    Member
    More actions

    I am torn. @hugovk what do you think?

  19. hugovk commented on Jan 11, 2026

    @hugovk
    hugovk
    on Jan 11, 2026
    Member
    More actions

    I'm fine with backporting, but what did we do with other similar changes in the past?

  20. pablogsal commented on Jan 11, 2026

    @pablogsal
    pablogsal
    on Jan 11, 2026
    Member
    More actions

    Backport them except when the backport was so different that was risky

  21. hugovk commented on Jan 12, 2026

    @hugovk
    hugovk
    on Jan 12, 2026
    Member
    More actions

    OK, go ahead, unless you think they're risky :)

  22. johnslavik commented on Mar 11, 2026

    @johnslavik
    johnslavik
    on Mar 11, 2026
    Member
    More actions

    If you'd like to backport, go ahead!

  23. johnslavik
    closed this as completedon Mar 11, 2026
  24. StanFromIreland
    marked SyntaxError reports incorrect line number in error message vs displayed code #149007 as a duplicate of this issue on Apr 26, 2026
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)(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtopic-parsertype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.