fuckingpython.lol

Python errors › SyntaxError

SyntaxError: '(' was never closed

Updated

The Python error "'(' was never closed" points at a bracket with no closing partner. How to find it, and the related "does not match opening parenthesis" error.

What you see

main.py
total = sum(
    [3, 4, 5]

print(total)
Python 3.15 prints
  File "/home/me/project/main.py", line 1
    total = sum(
               ^
SyntaxError: '(' was never closed

What it means

A bracket was opened and never closed. Python 3.10 and later point at the opening bracket itself, which is the one to look at. Before 3.10 the error was a vague "invalid syntax" or "unexpected EOF while parsing", often reported at the end of the file.

The same message comes with [ and {: "'[' was never closed", "'{' was never closed".

Why it happens

  • A closing bracket left off a call that spans several lines, as in the example.
  • One bracket too few in nested calls, such as print(len(items).
  • A closing bracket of the wrong kind. [1, 2) gives a different message: "closing parenthesis ')' does not match opening parenthesis '['".

How to fix it

Go to the bracket the caret marks and close it where the expression ends:

total = sum(
    [3, 4, 5]
)

print(total)

An editor with bracket matching shows the partner of the bracket under the cursor; an unmatched one is highlighted or has no partner.

Example: brackets of the wrong kind

main.py
numbers = [1, 2, 3)
Python 3.15 prints
  File "/home/me/project/main.py", line 1
    numbers = [1, 2, 3)
                      ^
SyntaxError: closing parenthesis ')' does not match opening parenthesis '['
PythonPrints
3.9–3.15SyntaxError: closing parenthesis ')' does not match opening parenthesis '['

Run on CPython 3.9.6, 3.10.22, 3.11.17, 3.12.15, 3.13.17, 3.14.9 and 3.15.1, on October 25, 2026.

How each Python version words it

PythonPrints
3.9SyntaxError: invalid syntax
3.10–3.15SyntaxError: '(' was never closed

Run on CPython 3.9.6, 3.10.22, 3.11.17, 3.12.15, 3.13.17, 3.14.9 and 3.15.1, on October 25, 2026.

3.9 cannot point at the open bracket. 3.10 and later name it and its line.

Questions

Why does the caret point at the start of the expression?

That is where the open bracket is. Python 3.10 and later remember where each bracket opened and report that line, not the end of the file.

Can a missing quote cause this?

An unclosed string gives its own error, "unterminated string literal". The string can contain the closing bracket, though, which then leaves the bracket open.

Sources

Read on October 25, 2026.