Easier debugging: Python 3.14 eliminates unclear error messages

The new Python version brings several improvements, including more meaningful error messages and a more user-friendly REPL console.

listen Print view
Hand taps on "Python" lettering

(Image: Michael Schwarzenberger, gemeinfrei (Creative Commons CC0))

3 min. read
By
  • Manuel Masiero

Following the third and final release candidate, the Python Software Foundation plans to publish the stable version 3.14 of the programming language on 7 October. It will receive support until October 2027 and will be supplied with security patches until October 2030.

Version 3.14 of the open source language comes with new features such as template strings (T-strings) and lazy annotations. There are also numerous error messages that have been improved in terms of comprehensibility. These focus on the most common errors made by Python developers. This should prevent debugging from degenerating into detective work.

In addition, the free-threaded mode introduced in version 3.13 is now officially released with the new version.

The improved error messages in Python 3.14 consider the error message types SyntaxError, ValueError and TypeError, explain what is wrong more precisely than before and also provide suggestions for improvement.

Videos by heise

One example of this is the new elif-after-else error messages: If an elif block follows an else block, Python now explicitly reports that this is not permitted. The error message also indicates the correct sequence of if, elif and else .

The code example:

>>> if x > 0:
...     print("positiv")
... else:
...     print("nicht positiv")
... elif x == 0:  # ungĂĽltig!
...     print("zero")
...

in version 3.13 returns the less meaningful error message

SyntaxError: invalid syntax

in version 3.14 on the other hand:

SyntaxError: 'elif' block follows an 'else' block

Another example: In Python 3.14, missing or incorrectly set inverted commas in strings now lead to a specific question. Instead of being limited to "invalid syntax", the error message now includes the addition "Is this intended to be part of the string?"

Python 3.14 also introduces new functions such as template strings (T-strings), lazy annotations and REPL autocompletion and syntax highlighting.

  • Template Strings: The new string prefix option 't' allows you to define a placeholder that can later be replaced with .substitute() or.format_map() . T-strings are useful for configuration files and templates, for example. They also allow secure processing of user input
  • Lazy annotations: Python 3.14 no longer evaluates type annotations immediately when a module is loaded. Instead, they are saved as strings and only analysed when required, which can counteract import problems, among other things.
  • REPL autocompletion and syntax highlighting: These two functions are activated by default in the REPL console (Read-Evaluate-Print-Loop) in version 3.14 and should make it easier to read the code and programme more efficiently in the interactive shell.

An overview of all the new features of Python 3.14 can be found on the release candidate page.

(vbr)

Don't miss any news – follow us on Facebook, LinkedIn or Mastodon.

This article was originally published in German. It was translated with technical assistance and editorially reviewed before publication.