Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@lucaswerkmeister

Description

@lucaswerkmeister
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

Reactions are currently unavailable

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.