Python版本说明
Python版本说明
更新于 2023-08-10
参考网址:
- https://devguide.python.org/versions/
- https://docs.python.org/
Python Release Cycle
当前支持的版本
Branch | Schedule | Status | First release | End of life | Release manager |
---|---|---|---|---|---|
main | PEP 719 | feature | 2024-10-01 | 2029-10 | Thomas Wouters |
3.12 | PEP 693 | prerelease | 2023-10-02 | 2028-10 | Thomas Wouters |
3.11 | PEP 664 | bugfix | 2022-10-24 | 2027-10 | Pablo Galindo Salgado |
3.10 | PEP 619 | security | 2021-10-04 | 2026-10 | Pablo Galindo Salgado |
3.9 | PEP 596 | security | 2020-10-05 | 2025-10 | Łukasz Langa |
3.8 | PEP 569 | security | 2019-10-14 | 2024-10 | Łukasz Langa |
不支持的版本
Branch | Schedule | Status | First release | End of life | Release manager |
---|---|---|---|---|---|
3.7 | PEP 537 | end-of-life | 2018-06-27 | 2023-06-27 | Ned Deily |
3.6 | PEP 494 | end-of-life | 2016-12-23 | 2021-12-23 | Ned Deily |
3.5 | PEP 478 | end-of-life | 2015-09-13 | 2020-09-30 | Larry Hastings |
3.4 | PEP 429 | end-of-life | 2014-03-16 | 2019-03-18 | Larry Hastings |
3.3 | PEP 398 | end-of-life | 2012-09-29 | 2017-09-29 | Georg Brandl, Ned Deily (3.3.7+) |
3.2 | PEP 392 | end-of-life | 2011-02-20 | 2016-02-20 | Georg Brandl |
3.1 | PEP 375 | end-of-life | 2009-06-27 | 2012-04-09 | Benjamin Peterson |
3.0 | PEP 361 | end-of-life | 2008-12-03 | 2009-06-27 | Barry Warsaw |
2.7 | PEP 373 | end-of-life | 2010-07-03 | 2020-01-01 | Benjamin Peterson |
2.6 | PEP 361 | end-of-life | 2008-10-01 | 2013-10-29 | Barry Warsaw |
版本状态说明
版本状态 | 说明 |
---|---|
feature | new features, bugfixes, and security fixes are accepted. |
prerelease | feature fixes, bugfixes, and security fixes are accepted for the upcoming feature release. |
bugfix | bugfixes and security fixes are accepted, new binaries are still released. (Also called maintenance mode or stable release) |
security | only security fixes are accepted and no more binaries are released, but new source-only versions can be released |
end-of-life | release cycle is frozen; no further changes can be pushed to it |
版本变更
相比上一个版本
Python 3.11
Python 3.11 的速度比 Python 3.10 快 10-60%。在平均状况下,在标准基准测试(standard benchmark suite)中可见1.25倍的加速效果。
新的语法特性:
- PEP 654:异常组与 except*
新的内置特性:
- PEP 678:可用注释丰富异常
新的标准库模块:
- PEP 680:
tomllib
— 标准库中对解析 TOML 的支持
解释器的改进:
- PEP 657:回溯信息中标注更详细的错误位置
- 新增
-P
命令行选项以及PYTHONSAFEPATH
环境变量来 禁止自动将潜在的不安全路径前置 到sys.path
新的类型标注特性:
- PEP 646:可变参数泛型
- PEP 655:将单个 TypedDict 项标记为必填或非必填项
- PEP 673:Self 类型
- PEP 675:任意字面值字符串类型
- PEP 681:数据类变换
重要的弃用、移除或限制:
- PEP 594: 许多旧标准库模块已被弃用,并将在 Python 3.13 中移除
- PEP 624: Py_UNICODE 编码器 API 已被移除
- PEP 670: 转换为静态内联函数的宏
Python 3.10
新的语法特性:
- PEP 634, 结构化模式匹配: 规范说明
- PEP 635, 结构化模式匹配: 动机与理由
- PEP 636, 结构化模式匹配: 教程
- bpo-12782,加圆括号的上下文管理器现在正式被允许使用。
标准库中的新特性:
- PEP 618,向 zip 添加可选的长度检查。
解释器的改进:
- PEP 626,在调试和其他工具中使用精确的行号。
新的类型标注特性:
- PEP 604,允许 X | Y 形式的联合类型写法
- PEP 612,形参规格变量
- PEP 613,显式类型别名
- PEP 647, User-Defined Type Guards
重要的弃用、移除或限制:
- PEP 644,要求 OpenSSL 1.1.1 或更新的版本
- PEP 632,弃用 distutils 模块。
- PEP 623,弃用并准备移除 PyUnicodeObject 中的 wstr 成员。
- PEP 624,移除 Py_UNICODE 编码器 API
- PEP 597,增加可选的 EncodingWarning
Python 3.9
新的语法特性:
- PEP 584,为
dict
增加合并运算符; - PEP 585,标准多项集中的类型标注泛型。
- PEP 614,放宽对装饰器的语法限制。
新的内置特性:
- PEP 616,移除前缀和后缀的字符串方法。
标准库中的新特性:
- PEP 593,灵活函数和变量注解;
- 添加了
os.pidfd_open()
以允许不带竞争和信号的进程管理。
解释器的改进:
- PEP 573,从 C 扩展类型的方法快速访问模块状态;
- PEP 617,CPython 现在使用基于 PEG 的新解析器;
- 一些 Python 内置类型(range、tuple、set、frozenset、list、dict)现已使用 PEP 590 vectorcall 加速;
- 垃圾回收不会因恢复的对象而阻塞;
- 一些 Python 模块(
_abc
、audioop
、_bz2
、_codecs
、_contextvars
、_crypt
、_functools
、_json
、_locale
、math
、operator
、resource
、time
、_weakref
)现已使用 PEP 489 中定义的多段初始化; - 一些标准库模块 (
audioop
、ast
、grp
、_hashlib
、pwd
、_posixsubprocess
、random
、select
、struct
、termios
、zlib
) 现已使用 PEP 384 中定义的稳定 ABI。
新的库模块:
- PEP 615,标准库的
zoneinfo
模块现已支持 IANA 时区数据库; - 图的拓扑排序实现现在已由新的
graphlib
模块提供。
发布进程的变化:
- PEP 602,CPython 采用年度发布周期。
Python 3.8
这个作者与众不同,格式跟前后不一致,稍微调整下,只列出新的语法特性
新的语法特性
-
赋值表达式,海象运算符 PEP 572
-
仅限位置形参
/
PEP 570 -
用于已编译字节码文件的并行文件系统缓存
-
调试构建使用与发布构建相同的 ABI
-
f-字符串支持
=
用于自动记录表达式和调试文档 -
PEP 578 : Python 运行时审核钩子
-
PEP 587 : Python 初始化配置
-
Vectorcall: 用于 CPython 的快速调用协议 PEP 590
-
具有外部数据缓冲区的 pickle 协议 5 PEP 574
其他语言特性修改
新增模块
- 新增的
importlib.metadata
模块提供了从第三方包读取元数据的(临时)支持
改进的模块
性能优化
构建与C API的改变
弃用
API与特性的移除
移植到 Python3.8
Python 3.7
新的语法特性:
- PEP 563,类型标注延迟求值。
向后不兼容的语法更改:
async
和await
现在是保留的关键字。
新的库模块:
contextvars
: PEP 567 -- 上下文变量dataclasses
: PEP 557 -- 数据类- importlib.resources
新的内置特性:
- PEP 553, 新的
breakpoint()
函数。
对 Python 数据模型的改进:
- PEP 562, 自定义可访问的模块属性。
- PEP 560, typing模块和泛型类型的核心支持。
- dict 对象会保持插入时的顺序这个特性 正式宣布 成为 Python 语言官方规范的一部分。
标准库中的重大改进:
asyncio
模块添加了新的功能,重大改进请参阅 可用性与性能提升。time
模块现在提供 纳秒级精度函数 的支持。
CPython 实现的改进:
- 避免使用 ASCII 作为默认的文本编码:
- PEP 538,传统 C 区域强制转换
- PEP 540,强制 UTF-8 运行时模式
- PEP 552,确定性的 .pyc 文件
- 新的开发运行时模式
- PEP 565,改进的
DeprecationWarning
处理
C API 的改进:
- PEP 539,用于线程本地存储的新 C API
文档的改进:
- PEP 545, Python 文档翻译
- 新的文档翻译:Japanese,French 和 Korean。
此版本在诸多方面有显著的性能改进。性能优化 章节详细列出了它们。
和之前的 Python 版本存在兼容性的更改列表
Python 3.6
新的语法特性:
- PEP 498, 格式化的字符串文字
- PEP 515, 数字文字中的下划线。
- PEP 526 , 变量注释的语法。
- PEP 525, 异步生成器。
- PEP 530: 异步推导。
新的库模块:
secrets
: PEP 506 – Secrets模块被加入Python标准库。
CPython 实现的改进:
- 根据 Raymond Hettinger 的提议 已将 dict 类型重新实现为使用 更紧凑的表示形式 并类似于 PyPy dict implementation。 这使得字典所使用的内存相对于 Python 3.5 版减少了 20% 到 25%。
- 类创建的定制过程通过 新协议 得到了简化。
- 类属性的定义顺序 现在会被保留。
- 现在
**kwargs
中的元素会与传给函数的关键字参数 保持对应顺序。 - 添加了 DTrace 和 SystemTap 探测支持
- 新的 PYTHONMALLOC 环境变量可被用来调试解释器的内存分配和访问错误。
标准库中的重大改进:
asyncio
模块获得了许多新特性,显著的可用性和性能提升,以及大量的问题修正。 从 Python 3.6 开始asyncio
模块不再处于待定状态,它已被视为稳定 API。- 实现了新的 文件系统路径协议 以支持 路径类对象。 所有操作路径的标准库函数已被更新为使用新的协议。
datetime
模块已获得对 本地时间消歧义 的支持。typing
模块获得了大量的 改进。tracemalloc
模块已被大幅重写,现在将被用于为ResourceWarning
提供更好的输出,并为内存分配错误提供更好的诊断。 请参阅 PYTHONMALLOC 一节 来了解详情。
安全改进:
- 添加了
secrets
模块以简化适用于密码管理的高加密强度伪随机数的生成,例如账户验证、安全凭据等场景。 - 在 Linux 上,现在
os.urandom()
会阻塞直到系统的 urandom 熵池被初始化以提升安全性。 其理由参见 PEP 524。 hashlib
和ssl
模块现在支持 OpenSSL 1.1.0。ssl
模块的默认设置和特性集已得到改进。hashlib
模块获得了对 BLAKE2, SHA-3 和 SHAKE 哈希算法以及scrypt()
密钥派生函数的支持。
Windows改进:
- PEP 528 和 PEP 529, 将Windows文件系统和控制台的编码更改为UTF-8
- 在交互式地使用
py.exe
启动器时,当用户未(通过命令行参数或配置文件)指定版本时不再优先选择 Python 2 而是选择 Python 3。 对声明行的处理则保持不变 —— 在这种情况下 “python” 还是指 Python 2。 python.exe
和pythonw.exe
已被标记为支持长路径,这意味着不再有 260 个字符的路径长度限制。 详情参见 移除 MAX_PATH 限制。- 可以添加一个
._pth
文件来强制使用隔离模式和完整指定所有搜索路径来避免注册表和环境查找。 更多信息请参阅 相关文档。 - 现在
python36.zip
文件可以作为推断PYTHONHOME
的标志
Python 3.5
官网就翻译成了这样...
新的语法特性:
- PEP 492, 使用 async 和 await 语法实现协程。
- PEP 465, 新的矩阵乘法运算符:
a @ b
. - PEP 448, additional unpacking generalizations.
新的库模块:
typing
: PEP 484 – 类型提示.zipapp
: PEP 441 改进Python ZIP应用程序支持.
新的内置特性:
bytes % args
,bytearray % args
: PEP 461 – Adding%
formatting to bytes and bytearray.- New
bytes.hex()
,bytearray.hex()
andmemoryview.hex()
methods. (Contributed by Arnon Yaari in bpo-9951.) memoryview
now supports tuple indexing (including multi-dimensional). (Contributed by Antoine Pitrou in bpo-23632.)- Generators have a new
gi_yieldfrom
attribute, which returns the object being iterated byyield from
expressions. (Contributed by Benno Leslie and Yury Selivanov in bpo-24450.) - A new
RecursionError
exception is now raised when maximum recursion depth is reached. (Contributed by Georg Brandl in bpo-19235.)
CPython 实现的改进:
- When the
LC_TYPE
locale is the POSIX locale (C
locale),sys.stdin
andsys.stdout
now use thesurrogateescape
error handler, instead of thestrict
error handler. (Contributed by Victor Stinner in bpo-19977.) .pyo
files are no longer used and have been replaced by a more flexible scheme that includes the optimization level explicitly in.pyc
name. (See PEP 488 overview.)- Builtin and extension modules are now initialized in a multi-phase process, which is similar to how Python modules are loaded. (See PEP 489 overview.)
标准库中的重大改进:
collections.OrderedDict
is now implemented in C, which makes it 4 to 100 times faster.- The
ssl
module gained support for Memory BIO, which decouples SSL protocol handling from network IO. - The new
os.scandir()
function provides a better and significantly faster way of directory traversal. functools.lru_cache()
has been mostly reimplemented in C, yielding much better performance.- The new
subprocess.run()
function provides a streamlined way to run subprocesses. - The
traceback
module has been significantly enhanced for improved performance and developer convenience.
安全改进:
- SSLv3 is now disabled throughout the standard library. It can still be enabled by instantiating a
ssl.SSLContext
manually. (See bpo-22638 for more details; this change was backported to CPython 3.4 and 2.7.) - HTTP cookie parsing is now stricter, in order to protect against potential injection attacks. (Contributed by Antoine Pitrou in bpo-22796.)
Windows改进:
- A new installer for Windows has replaced the old MSI. See 在Windows上使用 Python for more information.
- Windows builds now use Microsoft Visual C++ 14.0, and extension modules should use the same.