Stay Updated Icon

Subscribe to Our Tech & Career Digest

Join thousands of readers getting the latest insights on tech trends, career tips, and exclusive updates delivered straight to their inbox.

Python 3.14: New Features and Improvements

11:29 PM   |   10 May 2025

Python 3.14: New Features and Improvements

Python 3.14: A Deep Dive into the Latest Features and Improvements

The first beta release of Python 3.14 is now available, marking a significant step forward in the evolution of this popular programming language. This article provides an in-depth look at the most important new features and improvements in Python 3.14, explaining what they mean for Python developers and how they can enhance their coding experience.

Python in alphabet letters

Image credit: eamesBot/Shutterstock

Major New Features in Python 3.14

Python 3.14 brings a host of new capabilities designed to make development more efficient and the language more powerful. Here's a rundown of the key features:

  • Template strings
  • Deferred evaluation of annotations
  • Better error messages
  • A safe external debugger interface to CPython
  • A C API for Python runtime configuration
  • “Tail-call-compiled” interpreter

Template Strings: Advanced String Formatting

Python has long offered f-strings for convenient variable formatting within strings. Python 3.14 elevates this with template strings (PEP 750), providing a more advanced and flexible approach.

Template strings, or t-strings, allow you to combine a template with a function that operates on the template's structure, not just its output. This opens up possibilities for:

  • Variable Manipulation: Implement template handlers that allow or restrict variables based on type or other criteria, manipulating them at output time.
  • Separated Handling: Treat variables and interpolating text as distinct, typed objects, enabling specific transformations on each.

For example, with the template t"My name is {user_name}, and I'm from {user_locale}", you could automatically sanitize user_name and user_locale to remove HTML before display. You could also transform the surrounding text (My name is and and I'm from) by tagging them with a special Interpolation type.

Template strings simplify the creation of template engines like Jinja2 or duplicating their functionality directly in Python, reducing the need for external libraries.

Deferred Evaluation of Annotations: Enhanced Type Hinting

In previous Python versions, type annotations were evaluated eagerly, meaning they were processed as soon as they were encountered. This created challenges, such as forward references where a type was used before it was defined:


class Thing:
 def frob(self, other:OtherThing):
 ...
class OtherThing:
 ...

This code would often fail linting. Workarounds included using string literals for type hints:


class Thing:
 def frob(self, other:"OtherThing"):
 ...
class OtherThing:
 ...

Or using from __future__ import annotations.

Python 3.14 addresses this by storing annotations in “annotate functions,” accessible via the __annotate__ attribute. This allows lazy evaluation of annotations by linters or at runtime.

The annotationlib module provides tools for inspecting these annotations during runtime or linting.

While from __future__ import annotations still works, it is now deprecated and will be removed in future versions (likely after 2029).

Better Error Messages: Improved Debugging Experience

Python 3.14 continues the trend of improving error messages, making debugging more intuitive. Key improvements include:

  • Keyword Suggestions: Unknown terms that closely resemble Python keywords now suggest the correct keyword.

forr a in b:
^^^^
SyntaxError: invalid syntax. Did you mean 'for'?

Other enhancements include:

  • More detailed errors for unpacking mismatches.
  • Specific error messages for misplaced elif blocks.
  • Detailed error messages for illegal combinations of ternary assignment and control flow (e.g., x = a if b else pass).
  • Suggestions for completing incorrectly closed strings.

A Safe External Debugger Interface to CPython

Attaching external debuggers to CPython traditionally involves runtime overhead and potential safety issues, requiring CPython to be launched with the debugger pre-attached.

Python 3.14 introduces a new debugger interface that provides hooks into the CPython interpreter, allowing debuggers to attach without altering execution. This enables the use of Python's pdb module to attach to another Python process (via its process ID) for interactive debugging without restarting the process.

This interface simplifies debugger development and enhances robustness by eliminating the need to inject custom code into the interpreter.

A C API for Python Runtime Configuration

The Python configuration C API offers a C API for setting or retrieving information about the Python interpreter's configuration using Python objects instead of C structures. This allows direct configuration from Python, facilitating the creation of Python-level tools for runtime behavior changes.

This API is part of a broader effort to clean up CPython internals and APIs, including initialization APIs. C users can still access lower-level APIs when needed.

Easier Ways to Use `except` for Multiple Exceptions

Previously, catching multiple exceptions required grouping them with parentheses:


try:
 flaky_function()
except (BigProblem, SmallProblem):
 ...

Python 3.14 simplifies this by allowing a comma-separated list of exceptions:


try:
 flaky_function()
except BigProblem, SmallProblem:
 ...

The original syntax remains valid, but the new syntax reduces typing for common scenarios.

‘Tail-Call-Compiled’ Interpreter

CPython in Python 3.14 can leverage tail calls between functions in C code. When compiled with a supporting C compiler, CPython runs slightly faster. This is an internal optimization for the CPython interpreter, not a language-level feature.

While initial estimates suggested significant performance improvements, a compiler bug in Clang/LLVM19 (now fixed) reduced the gains to between 3% and 5%. As with any optimization, benchmarking is recommended to assess the impact on specific applications.