Python版本说明

Python版本说明

更新于 2023-10-07

参考网址:

  1. https://devguide.python.org/versions/
  2. 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.12

编者
Adam Turner

This article explains the new features in Python 3.12, compared to 3.11. Python 3.12 was released on October 2, 2023. For full details, see the changelog.

参见 PEP 693 -- Python 3.12 发布计划
摘要 -- 发布重点
Python 3.12 是 Python 编程语言的最新稳定发布版,包含一系列对语言和标准库的改变。 库的改变主要集中在清理已弃用的 API、可用性和正确性等方面。 值得注意的是,distutils 包已从标准库中移除。 os 和 pathlib 中的文件系统支持增加了许多改进,而且部分模块的性能也获得了提升。

语言的改变主要集中在可用性方面,如 f-字符串 的许多限制已被移除,而 'Did you mean ...' 提示消息继续得到改进。 新的 类型形参语法 和 type 语句提升了 泛型类型 和 类型别名 配合静态类型检查器使用时的效率。

本文并不试图提供所有新功能的完整规范说明,而是提供一个方便的概览。 如需了解完整细节,请参阅相应文档,如 标准库参考 和 语言参考。 如果你想了解某项改变的完整实现和设计理念,请参阅相应新特性的 PEP;但请注意一旦某项特性已完全实现则相应 PEP 通常不会再继续更新。

新的语法特性:

  • PEP 695,类型形参语法和 type 语句

新的语法特性:

  • PEP 701,f-字符串 语法的改进

解释器的改进:

  • PEP 684,解释器级的单独 GIL

  • PEP 669,低开销的监控

  • 针对 NameError, ImportError 和 SyntaxError 异常 改进了 'Did you mean ...' 提示消息。

对 Python 数据模型的改进:

  • PEP 688,使用 Python 的 缓冲区协议

标准库中的重大改进:

  • pathlib.Path 类现在支持子类化

  • os 模块获得了多项针对 Windows 支持的改进

  • 在 sqlite3 模块中添加了 命令行界面。

  • 基于 运行时可检测协议 的 isinstance() 检测获得了 2 至 20 倍的提速

  • asyncio 包的性能获得了多项改进,一些基准测试显示有 75% 的提速。

  • 在 uuid 模块中添加了 命令行界面。

  • Due to the changes in PEP 701, producing tokens via the tokenize module is up to 64% faster.

安全改进:

  • 用来自 HACL* 项目的经过正式验证的代码替代 SHA1, SHA3, SHA2-384, SHA2-512 和 MD5 的内置 hashlib 实现。 这些内置实现保留作为仅在当 OpenSSL 未提供它们时使用的回退选项。

C API 的改进:

  • PEP 697,不稳定 C API 层

  • PEP 683,永生对象

CPython 实现的改进:

  • PEP 709,推导式内联化

  • 对 Linux perf 性能分析器的 CPython 支持

  • 在受支持的平台上实现栈溢出保护

新的类型标注特性:

  • PEP 692,使用 TypedDict 来标注 **kwargs

  • PEP 698,typing.override() 装饰器

重要的弃用、移除或限制:

  • PEP 623: 在 Python 的 C API 中移除 Unicode 对象中的 wstr,使每个 str 对象的大小缩减至少 8 个字节。

P- EP 632: 移除 distutils 包。 请参阅 迁移指南 了解有关替换其所提供的 API 的建议。 第三方 Setuptools 包将继续提供 distutils,如果你在 Python 3.12 及更高版本中仍然需要它的话。

  • gh-95299: 不在使用 venv 创建的虚拟环境中预装 setuptools。 这意味着 distutils、setuptools、pkg_resources 和 easy_install 默认将不再可用;要访问这些工具请在 激活的 虚拟环境中运行 pip install setuptools。

移除了 asynchat、asyncore 和 imp 模块,以及一些 unittest.TestCase 方法别名。

Python 3.11

Python 3.11 的速度比 Python 3.10 快 10-60%。在平均状况下,在标准基准测试(standard benchmark suite)中可见1.25倍的加速效果。

新的语法特性:

新的内置特性:

新的标准库模块:

解释器的改进:

新的类型标注特性:

重要的弃用、移除或限制:

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 模块(_abcaudioop_bz2_codecs_contextvars_crypt_functools_json_localemathoperatorresourcetime_weakref)现已使用 PEP 489 中定义的多段初始化;
  • 一些标准库模块 (audioopastgrp_hashlibpwd_posixsubprocessrandomselectstructtermioszlib) 现已使用 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,类型标注延迟求值。

向后不兼容的语法更改:

新的库模块:

新的内置特性:

对 Python 数据模型的改进:

  • PEP 562, 自定义可访问的模块属性。
  • PEP 560, typing模块和泛型类型的核心支持。
  • dict 对象会保持插入时的顺序这个特性 正式宣布 成为 Python 语言官方规范的一部分。

标准库中的重大改进:

CPython 实现的改进:

C API 的改进:

  • PEP 539,用于线程本地存储的新 C API

文档的改进:

此版本在诸多方面有显著的性能改进。性能优化 章节详细列出了它们。

和之前的 Python 版本存在兼容性的更改列表

Python 3.6

新的语法特性:

新的库模块:

CPython 实现的改进:

标准库中的重大改进:

安全改进:

  • 添加了 secrets 模块以简化适用于密码管理的高加密强度伪随机数的生成,例如账户验证、安全凭据等场景。
  • 在 Linux 上,现在 os.urandom() 会阻塞直到系统的 urandom 熵池被初始化以提升安全性。 其理由参见 PEP 524
  • hashlibssl 模块现在支持 OpenSSL 1.1.0。
  • ssl 模块的默认设置和特性集已得到改进。
  • hashlib 模块获得了对 BLAKE2, SHA-3 和 SHAKE 哈希算法以及 scrypt() 密钥派生函数的支持。

Windows改进:

  • PEP 528PEP 529, 将Windows文件系统和控制台的编码更改为UTF-8
  • 在交互式地使用 py.exe 启动器时,当用户未(通过命令行参数或配置文件)指定版本时不再优先选择 Python 2 而是选择 Python 3。 对声明行的处理则保持不变 —— 在这种情况下 “python” 还是指 Python 2。
  • python.exepythonw.exe 已被标记为支持长路径,这意味着不再有 260 个字符的路径长度限制。 详情参见 移除 MAX_PATH 限制
  • 可以添加一个 ._pth 文件来强制使用隔离模式和完整指定所有搜索路径来避免注册表和环境查找。 更多信息请参阅 相关文档
  • 现在 python36.zip 文件可以作为推断 PYTHONHOME 的标志

Python 3.5

官网就翻译成了这样...

新的语法特性:

  • PEP 492, 使用 async 和 await 语法实现协程。
  • PEP 465, 新的矩阵乘法运算符: a @ b.
  • PEP 448, additional unpacking generalizations.

新的库模块:

新的内置特性:

  • bytes % args, bytearray % args: PEP 461 – Adding % formatting to bytes and bytearray.
  • New bytes.hex(), bytearray.hex() and memoryview.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 by yield 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 and sys.stdout now use the surrogateescape error handler, instead of the strict 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.)

标准库中的重大改进:

安全改进:

  • 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.
posted @ 2023-08-10 10:32  博客已废弃  阅读(138)  评论(0编辑  收藏  举报