Skip navigation
Python Alamy

Python 3.12 Advances Open Source Programming Language with New Features

Python 3.12 receives new syntax, grammar, data model, and security updates.

The open source Python programming language is continuing to add new capabilities as its popularity grows.

Python 3.12 was officially released by the Python Software Foundation on Oct. 2, as part of the programming language's normal annual release cycle. The new release is packed with a number of improvements and new features that aim to enhance the Python developer experience.

This latest iteration of the popular programming language also brings significant optimizations under the hood, and the removal of various legacy APIs.

Related: Python Commands Cheat Sheet

Major updates in Python 3.12 include:

  • Syntax features. PEP 695 introduces a new, more compact, and explicit way to create generic classes and functions with type parameter syntax.
  • Grammar updates. PEP 701 formalizes the syntax of f-strings and lifts some restrictions on their usage.
  • Security improvements. The built-in hashlib implementations of SHA1, SHA3, SHA2-384, SHA2-512, and MD5 are replaced with formally verified code.

Python 3.12 Brings Fresh Approach to Syntax and Grammar

Perhaps the most notable change in Python 3.12 comes in the form of new syntax features. 

PEP 695 introduces a compact and explicit way to create generic classes and functions with type parameter syntax. This change is set to make the code more readable and maintainable, a significant boon for developers working on complex projects. In addition, Python 3.12 offers a new way to declare type aliases using the "type" statement. This feature allows for simpler, more expressive code and is likely to be warmly welcomed by the Python community.

PEP 701, another significant update, formalizes the syntax of f-strings, a feature widely appreciated by Python developers for its simplicity and elegance. The new release lifts some restrictions on their usage, allowing expressions inside f-strings to be any valid Python expression, including multi-line expressions, comments, and unicode escape sequences.

Python 3.12 Boosts Performance

Performance enhancements are another core element of the Python 3.12 update.

Related: ITPro Today's Guide to Modern Programming Languages

Dictionary, list, and set comprehensions received a speed boost of up to 2x thanks to PEP 709 inlining them rather than creating temporary function objects. The popular asyncio module benefits from various optimizations, with some benchmarks showing up to 75% faster performance. The tokenizer and inspection modules also see double-digit percentage improvements in certain operations.

Behind the scenes, PEP 684 splits the Global Interpreter Lock (GIL) into separate locks for each interpreter instance. This paves the way for full multi-threading across CPU cores in sub-interpreters, an important milestone for highly parallel Python programs. Other interpreter-level changes like PEP 669 enable low overhead monitoring hooks useful for tools driving Python's growing high performance computing (HPC) adoption.

Looking beyond performance, Python 3.12 also helps to improve developer experience through a series of improved error messages.

About the author

 Sean Michael Kerner headshotSean Michael Kerner is an IT consultant, technology enthusiast and tinkerer. He consults to industry and media organizations on technology issues.
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish