Repository navigation
Confusing SyntaxError for multi-line string concatenation with missing comma #142236
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Dec 3, 2025 (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 :))
- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Dec 3, 2025 CC @ZeroIntensity (mentorship): That would betopic-parserI think.I may give this a shot later this week.
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 KravetsIt's
traceback.py. CC @pablogsalReacted by Bartosz Sławecki@StanFromIreland If it's
traceback.py, then maybe let's also addstdlib.Let's deal with the first issue for now.
- addedtype-featureA feature request or enhancementA feature request or enhancementand removedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Dec 3, 2025 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
.pyfile.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?1 remaining item
- added 5 commits that reference this issue
on Dec 6, 2025 @pablogsal do you want to backport the two PRs? Otherwise there is nothing left to do here.
- addedpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
on Jan 9, 2026 I am torn. @hugovk what do you think?
I'm fine with backporting, but what did we do with other similar changes in the past?
Backport them except when the backport was so different that was risky
OK, go ahead, unless you think they're risky :)
If you'd like to backport, go ahead!
- marked SyntaxError reports incorrect line number in error message vs displayed code #149007 as a duplicate of this issue
on Apr 26, 2026
Bug report
Bug description:
I just spent a couple of minutes figuring out what was wrong with this code:
It produces the following error:
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