Python 3.10 — Better error messages

Developers Group
3 min readApr 12, 2022

Python 3.10.0 is the newest major release of the Python programming language, and it contains many new features and optimizations and today we will explore Better error messages feature.

Better error messages

SyntaxErrors

When parsing code that contains unclosed parentheses or brackets the interpreter now includes the location of the unclosed bracket of parentheses instead of displaying SyntaxError: unexpected EOF while parsing or pointing to some incorrect location. SyntaxError examples:

File "example.py", line 1
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4,
^
SyntaxError: '{' was never closed
File "example.py", line 1
expected = {9: 1, 18: 2, 19: 2, 27: 3, 28: 3, 29: 3, 36: 4, 37: 4,
^
SyntaxError: '{' was never closed
>>> foo(x, z for z in range(10), t, w)
File "<stdin>", line 1
foo(x, z for z in range(10), t, w)
^^^^^^^^^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized

And much more, like:

  • Missing : before blocks

--

--

Developers Group

A Developer is responsible for coding, designing, deploying, and debugging development projects, typically on the server-side (or back-end).