Python 3.14 有什麼新功能¶
- 編輯者:
Adam Turner 和 Hugo van Kemenade
本文介紹了 Python 3.14 與 3.13 相比多了哪些新功能。Python 3.14 已於 2025 年 10 月 7 日發布。完整詳情請見 changelog。
也參考
PEP 745 - Python 3.14 發佈時程
發布重點摘要¶
Python 3.14 是 Python 程式語言的最新穩定版本,包含了語言、實作和標準函式庫的各種變更。最大的變更包括模板字串字面值、延遲型別註解的求值,以及標準函式庫中對子直譯器的支援。
The library changes include significantly improved capabilities for
introspection in asyncio,
support for Zstandard via a new
compression.zstd module, syntax highlighting in the REPL,
as well as the usual deprecations and removals,
and improvements in user-friendliness and correctness.
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.14 for guidance on upgrading from earlier versions of Python.
直譯器的改進:
標準函式庫中的顯著改進
Syntax highlighting in the default interactive shell, and color output in several standard library CLIs
C API 改進:
平台支援:
PEP 776: Emscripten is now an officially supported platform, at tier 3.
Release changes:
新增功能¶
PEP 649 & PEP 749: Deferred evaluation of annotations¶
The annotations on functions, classes, and modules are no
longer evaluated eagerly. Instead, annotations are stored in special-purpose
annotate functions and evaluated only when
necessary (except if from __future__ import annotations is used).
This change is designed to improve performance and usability of annotations in Python in most circumstances. The runtime cost for defining annotations is minimized, but it remains possible to introspect annotations at runtime. It is no longer necessary to enclose annotations in strings if they contain forward references.
The new annotationlib module provides tools for inspecting deferred
annotations. Annotations may be evaluated in the VALUE
format (which evaluates annotations to runtime values, similar to the behavior in
earlier Python versions), the FORWARDREF format
(which replaces undefined names with special markers), and the
STRING format (which returns annotations as strings).
This example shows how these formats behave:
>>> from annotationlib import get_annotations, Format
>>> def func(arg: Undefined):
... pass
>>> get_annotations(func, format=Format.VALUE)
Traceback (most recent call last):
...
NameError: name 'Undefined' is not defined
>>> get_annotations(func, format=Format.FORWARDREF)
{'arg': ForwardRef('Undefined', owner=<function func at 0x...>)}
>>> get_annotations(func, format=Format.STRING)
{'arg': 'Undefined'}
The