Get ready for the new Python 3.13!

Learn key strategies to create an environment that fosters a mentally healthier and more productive workplace.

Unlocking tech talent stories

October 3, 2024

Known by many in the tech world, the Python language has been around for 33 years and its one of the most sought-after programming languages.

Now, Python is releasing its latest update, Python 3.13, scheduled for October 7th! With exciting new features and improvements, here’s a look at what’s new:

New features

1) A better interactive interpreter

Python has upgraded its interactive shell (REPL) to offer a more powerful and user-friendly experience, inspired by the PyPy project. Here are the key new features:

  • Multiline editing with history preservation: Users can now edit multiline code blocks while maintaining history, making corrections and edits easier.
  • Direct commands for common actions: Commands like help, exit, and quit are now directly supported without needing parentheses, making the REPL more intuitive.
  • Colorized prompts and tracebacks: The REPL now has coloured prompts and error messages by default, improving readability and the debugging experience.
  • Interactive help with F1: Pressing F1 enables interactive help browsing, including a dedicated history for help commands.
  • Improved history browsing with F2: Browsing through command history is now easier with F2, skipping output and prompts for quicker navigation.
  • Paste mode with F3: A new paste mode (activated with F3) makes it easier to paste and execute larger blocks of code. Pressing F3 again returns to the regular prompt.
  • Easily disable the new shell: To revert to the previous shell behaviour, set the PYTHON_BASIC_REPL environment variable. 

2) Improved error messages:

  • Colorized tracebacks by default: The interpreter now uses color by default for tracebacks in the terminal, improving readability. 
  • Better error messages for conflicting script names: If a script is named after a standard library or third-party module, Python now displays more helpful error messages, suggesting a rename to avoid conflicts.
  • Keyword argument suggestions: The error message now suggests the correct argument when an incorrect keyword argument is passed to a function. This makes it easier to fix mistakes in function calls. 

3) Free-threaded CPython

Python now has experimental support for running without the Global Interpreter Lock (GIL), allowing for better multi-core utilization. Note: This feature requires a special build (e.g., python3.13t) and is not enabled by default.

  • Developers can control GIL behavior at runtime using the PYTHON_GIL environment variable or -X gil options.
  • Support for C extensions: C-API extensions must be rebuilt for the free-threaded version. New APIs (Py_mod_gil and PyUnstable_Module_SetGIL()) indicate support for this feature.
  • Improved multi-core utilization: The free-threaded mode allows threads to run in parallel on available CPU cores.
  • Experimental nature and limitations: Developers can control GIL behavior at runtime using the PYTHON_GIL environment variable or -X gil options. 

4) Experimental just-in-time (JIT) compiler:

  • Enabling JIT compilation: A JIT compiler can be enabled by configuring CPython with –enable-experimental-jit. Windows users can enable JIT using PCbuild/build.bat –experimental-jit.
  • JIT option values: The –enable-experimental-jit option has various settings to enable or disable different levels of JIT and interpreter functionality. 

5) Tiered compilation architecture:

  • Tier 1 Bytecode: Starts with specialized Tier 1 bytecode.
  • Tier 2 Intermediate Representation (IR): “Heated up” Tier 1 bytecode is translated to Tier 2 IR, optimized for efficient machine code translation.
  • Optimizations and execution: Tier 2 IR can be interpreted by a Tier 2 interpreter or compiled to machine code using LLVM.
  • Tier 2 Interpreter: Primarily for debugging, with machine code generated using a “copy-and-patch” JIT compilation technique. 

6) Defined Mutation Semantics for locals() (PEP 667):

  • Standardized behaviour: Starting in Python 3.13, locals() now consistently returns independent snapshots in optimized scopes (functions, generators, etc.).
  • Changes in Optimised scopes: Code execution functions (exec(), eval()) now operate on snapshots of local variables, requiring an explicit namespace to reflect changes.
  • Impact on debuggers: FrameType.f_locals now returns a write-through proxy, ensuring debuggers can reliably update local variables. 

7) Support for mobile platforms:

PEP 730 – iOS platform and PEP 738 – Android support:
Python is now officially supports  iPhones and iPads (2013 and later), the Xcode iOS simulator on Apple silicon. Android devices are also supported and will receive the best-effort support. 

8) New Typing Features:

The typing system in Python has new features that make type annotations more flexible:

  • PEP 696: Default values for type parameters.
  • PEP 702: warnings.deprecated() decorator.
  • PEP 705: typing.ReadOnly for TypedDict.
  • PEP 742: typing.TypeIs for type narrowing. 

Improvements: 

1)  Interpreter improvements

Now you can find an enhanced interactive interpreter with color support, clearer error messages, standardized
locals() behavior (PEP 667), experimental GIL-free execution (PEP 703), and an initial version of a JIT compiler (PEP 744).

2) Standard Library

The standard library has received several new features and enhancements, including:

  • New PythonFinalizationError Exception: Better control during shutdown.
  • Deprecation Support in argparse: Easily mark options as deprecated.
  • Enhancements in base64: Added z85encode() and z85decode() functions.
  • copy.replace() Function: Modify copies of objects conveniently. 

3) Security Improvements

SSL Module Enhancements: Stricter default verification for improved security.

4) C API Improvements

Added GIL support indicator for extension modules (Py_mod_gil), the new PyTime C API, PyMutex, and functions for monitoring events.

5) Important Removals

Python 3.13 removes several legacy components, including:

  • Legacy Modules: 19 outdated  modules, including aifc, telnetlib, and pipes.
  • 2to3 Tool and lib2to3: Removed due to the end of Python 2 support.
  • tkinter.tix Module: Deprecated since Python 3.6.
  • locale.resetlocale() Function.
  • typing.io and typing.re Namespaces.
  • Chained classmethod Descriptors. 

What’s the 3.13 version lifespan?

Python 3.13 will get bugfix updates every two months for about two years. When version 3.15.0 is released, the last bugfix update for 3.13 will be issued. Until october 2029, only security updates (in source form) are planned.

In short, Python 3.13 is all about making coding easier, faster, and more accessible. With a focus on clearer errors and improved compatibility with new devices and platforms, developers can start working with this newer version on the 7th of october

0 Comments
Submit a Comment

Your email address will not be published. Required fields are marked *

Share This