Python 3.13 有什麼新功能¶
- 編輯者:
Adam Turner 和 Thomas Wouters
本文介紹了 Python 3.13 與 3.12 相比多了哪些新功能。Python 3.13 已於 2024 年 10 月 7 日發布。完整詳情請見 changelog。
也參考
PEP 719 -- Python 3.13 發佈時程
發布重點摘要¶
Python 3.13 is a stable release of the Python programming language, with a mix of changes to the language, the implementation and the standard library. The biggest changes include a new interactive interpreter, experimental support for running in a free-threaded mode (PEP 703), and a Just-In-Time compiler (PEP 744).
Error messages continue to improve, with tracebacks now highlighted in color
by default. The locals() builtin now has defined semantics for changing the returned mapping,
and type parameters now support default values.
The library changes contain removal of deprecated APIs and modules, as well as the usual improvements in user-friendliness and correctness. Several legacy standard library modules have now been removed following their deprecation in Python 3.11 (PEP 594).
This article doesn't attempt to provide a complete specification of all new features, but instead gives a convenient overview. For full details refer to the documentation, such as the Library Reference and Language Reference. 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. See Porting to Python 3.13 for guidance on upgrading from earlier versions of Python.
直譯器改進:
A greatly improved interactive interpreter and improved error messages.
PEP 667: The
locals()builtin now has defined semantics when mutating the returned mapping. Python debuggers and similar tools may now more reliably update local variables in optimized scopes even during concurrent code execution.PEP 703: CPython 3.13 has experimental support for running with the global interpreter lock disabled. See Free-threaded CPython for more details.
PEP 744: A basic JIT compiler was added. It is currently disabled by default (though we may turn it on later). Performance improvements are modest -- we expect to improve this over the next few releases.
Color support in the new interactive interpreter, as well as in tracebacks and doctest output. This can be disabled through the
PYTHON_COLORSandNO_COLORenvironment variables.
Python 資料模型改進:
__static_attributes__stores the names of attributes accessed throughself.Xin any function in a class body.__firstlineno__records the first line number of a class definition.
標準函式庫中的顯著改進
Add a new
PythonFinalizationErrorexception, raised when an operation is blocked during finalization.The
argparsemodule now supports deprecating command-line options, positional arguments, and subcommands.The new functions
base64.z85encode()andbase64.z85decode()support encoding and decoding Z85 data.