Python 3.12 is the latest stable release of the Python programming language, with a mix of changes to the language and the standard library. The library changes focus on cleaning up deprecated APIs, usability, and correctness. Of note, the distutils
package has been removed from the standard library. Filesystem support in os
and pathlib
has seen a number of improvements, and several modules have better performance.
The language changes focus on usability, as f-strings have had many limitations removed and ‘Did you mean …’ suggestions continue to improve. The new type parameter syntax and type
statement improve ergonomics for using generic types and type aliases with static type checkers.
This article doesn’t attempt to provide a complete specification of all new features, but instead gives a convenient overview. For full details, you should refer to the documentation, such as the Library Reference and Language Reference. If you want to understand the complete implementation and design rationale for a change, refer to the PEP for a particular new feature; but note that PEPs usually are not kept up-to-date once a feature has been fully implemented.
New syntax features:
New grammar features:
Interpreter improvements:
- PEP 684, a unique per-interpreter GIL
- PEP 669, low impact monitoring
- Improved ‘Did you mean …’ suggestions for
NameError
,ImportError
, andSyntaxError
exceptions
Python data model improvements:
- PEP 688, using the buffer protocol from Python
Significant improvements in the standard library:
- The
pathlib.Path
class now supports subclassing - The
os
module received several improvements for Windows support - A command-line interface has been added to the
sqlite3
module isinstance()
checks againstruntime-checkable protocols
enjoy a speed up of between two and 20 times- The
asyncio
package has had a number of performance improvements, with some benchmarks showing a 75% speed up. - A command-line interface has been added to the
uuid
module - Due to the changes in PEP 701, producing tokens via the
tokenize
module is up to 64% faster.
Security improvements:
hey nice post