Python 3.6 有什么新变化
***********************

编者:
   Elvis Pranskevichus <elvis@magic.io>, Yury Selivanov
   <yury@magic.io>

本文解释了与3.5相比，Python 3.6中的新功能。 Python 3.6于2016年12月23日
发布。请参阅 changelog 以获取完整的更改列表。

参见: **PEP 494** - Python 3.6 发布计划


摘要 -- 发布重点
================

新的语法特性：

* PEP 498, 格式化字符串字面值

* PEP 515, 数字字面值中的下划线。

* PEP 526 , 变量标注语法。

* PEP 525，异步生成器。

* PEP 530: 异步推导式。

新的库模块：

* "secrets": PEP 506 -- 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" 的标志。 更多信息
  请参阅 相关文档。


新的特性
========


PEP 498: 格式化字符串字面值
---------------------------

**PEP 498** 引入了一种新型的字符串字面值: *f-字符串*，或称 格式化字符
串字面值。

格式化字符串字面值带有 "'f'" 前缀并且类似于 "str.format()" 所接受的格
式字符串。 其中包含由花括号包围的替换字段。 替换字段属于表达式，它们会
在运行时被求值，然后使用 "format()" 协议进行格式化:

   >>> name = "Fred"
   >>> f"He said his name is {name}."
   'He said his name is Fred.'
   >>> width = 10
   >>> precision = 4
   >>> value = decimal.Decimal("12.34567")
   >>> f"result: {value:{width}.{precision}}"  # nested fields
   'result:      12.35'

参见:

  **PEP 498** -- 字符串字面值插值。
     PEP 由 Eric V. Smith 撰写并实现

  特性文档。


PEP 526: 变量标注的语法
-----------------------

**PEP 484** 引入了函数形参类型标注即类型提示的标准。 这个 PEP 为
Python 添加了标注变量类型的语法，包括类变量和实例变量:

   primes: List[int] = []

   captain: str  # Note: no initial value!

   class Starship:
       stats: Dict[str, int] = {}

与函数标注一样，Python 解释器不会为变量标注附加任何特殊含义，仅会将其
保存在类或模块的 "__annotations__" 属性中。

与静态类型语法的变量声明不同，标注语法的目的是通过抽象语法树和
"__annotations__" 属性提供一个简单方式来为第三方工具和库指定结构化类型
元数据。

参见:

  **PEP 526** -- 变量标注的语法。
     PEP 由 Ryan Gonzalez, Philip House, Ivan Levkivskyi, Lisa Roach,
     和 Guido van Rossum 撰写，由 Ivan Levkivskyi 实现。

  使用或将要使用此新语法的工具有: mypy, pytype, PyCharm 等等。


PEP 515: 数字字面值中的下划线。
-------------------------------

**PEP 515** 增加了在数字字面值中使用下划线的能力以改善可读性。 例如:

   >>> 1_000_000_000_000_000
   1000000000000000
   >>> 0x_FF_FF_FF_FF
   4294967295

单个下划线允许用在数码之间和任何数制指示符之后。 一行内不允许有开头、
末尾或多个下划线。

字符串格式化 微语言现在也支持以 "'_'" 选项来表示用下划线作为浮点表示类
型和整数表示类型 "'d'" 的千位分隔符。 对于整数表示类型 "'b'", "'o'",
"'x'" 和 "'X'"，将每隔 4 个数码插入一个下划线:

   >>> '{:_}'.format(1000000)
   '1_000_000'
   >>> '{:_x}'.format(0xFFFFFFFF)
   'ffff_ffff'

参见:

  **PEP 515** -- 数字字面值中的下划线。
     PEP 由 Georg Brandl 和 Serhiy Storchaka 撰写


PEP 525: 异步生成器
-------------------

**PEP 492** 将对原生协程和 "async" / "await" 语法的支持引入到 Python
3.5 中。 但 Python 3.5 实现的一个明显限制是不可能在同一函数体中同时使
用 "await" 和 "yield"。 在 Python 3.6 中此限制已被解除，这样就就能够定
义 *异步生成器*:

   async def ticker(delay, to):
       """Yield numbers from 0 to *to* every *delay* seconds."""
       for i in range(to):
           yield i
           await asyncio.sleep(delay)

这个新语法允许更快速且更精简的代码。

参见:

  **PEP 525** -- 异步生成器
     PEP 由 Yury Selivanov 撰写并实现


PEP 530: 异步推导式
-------------------

**PEP 530** 添加了对在列表、集合与字典推导式和生成器表达式中使用
"async for" 的支持:

   result = [i async for i in aiter() if i % 2]

此外，"await" 表达式也在所有种类的推导式中得到支持:

   result = [await fun() for fun in funcs if await condition()]

参见:

  **PEP 530** -- 异步推导式
     PEP 由 Yury Selivanov 撰写并实现


PEP 487: 更简单的自定义类创建
-----------------------------

现在可以在不使用元类的情况下自定义子类的创建。 当一个新的子类被创建时
将在基类上调用新的 "__init_subclass__" 类方法:

   class PluginBase:
       subclasses = []

       def __init_subclass__(cls, **kwargs):
           super().__init_subclass__(**kwargs)
           cls.subclasses.append(cls)

   class Plugin1(PluginBase):
       pass

   class Plugin2(PluginBase):
       pass

为了让来自 "__init_subclass__()" 实现的零参数 "super()" 调用能正确工作
，自定义元类必须保证新的 "__classcell__" 命名空间入口被传播到
"type.__new__" (如 创建类对象 中所描述)。

参见:

  **PEP 487** -- 更简单的自定义类创建
     PEP 由 Martin Teichmann 撰写并实现。

  特性文档


PEP 487: 描述器协议的增强
-------------------------

**PEP 487** 扩展了描述器协议以包括新的可选方法 "__set_name__()"。 当创
建一个新类时，这个新方法将在定义中包括的所有描述器上被调用，为它们提供
对所定义类的引用以及在类命名中间中给予描述器的名称。 换句话说，描述器
的实例现在能知道描述器在所有者类中的属性名称:

   class IntField:
       def __get__(self, instance, owner):
           return instance.__dict__[self.name]

       def __set__(self, instance, value):
           if not isinstance(value, int):
               raise ValueError(f'expecting integer in {self.name}')
           instance.__dict__[self.name] = value

       # this is the new initializer:
       def __set_name__(self, owner, name):
           self.name = name

   class Model:
       int_field = IntField()

参见:

  **PEP 487** -- 更简单的自定义类创建
     PEP 由 Martin Teichmann 撰写并实现。

  特性文档


PEP 519: 添加文件系统路径协议
-----------------------------

文件系统路径历来被表示为 "str" 或 "bytes" 对象。 这使得编写对文件系统
路径进行操作的代码的人会假定这种对象只能是这两种类型之一（不考虑表示文
件描述符的 "int" 因为它不是文件路径）。 不幸的是，这种假定阻止了像
"pathlib" 这样的文件系统路径的替代对象表示形式与包括 Python 标准库在内
的现有代码协同工作。

为了修正这种情况，一个由 "os.PathLike" 表示的新接口被定义出来。 通过实
现 "__fspath__()" 方法，对象可以表明它代表一个路径。 这样一个对象就能
以 "str" 或 "bytes" 对象的形式提供文件系统路径的低层级表示。 这意味着
如果一个对象实现了 "os.PathLike" 或者是表示文件系统路径的 "str" 或
"bytes" 对象它就会被当作是 *路径型对象*。 代码可以使用 "os.fspath()"、
"os.fsdecode()" 或 "os.fsencode()" 来显式地获取一个路径型对象的 "str"
和/或 "bytes" 表示形式。

内置 "open()" 函数已被更新为接受 "os.PathLike" 对象，就像 "os" 和
"os.path" 模块中的所有相关函数和标准库中的大多数其他函数和类一样。
"os.DirEntry" 类和 "pathlib" 中的相关类也已被更新以实现 "os.PathLike"
。

希望对于针对文件系统路径操作的基本函数的更新将会使得第三方代码都能隐式
地支持所有 *路径型对象* 而无须修改任何代码，或者至少只需极少的修改（例
如当对路径型对象进行操作之前在代码的开头调用 "os.fspath()" 即可）。

下面的这些示例说明了新的接口是如何让 "pathlib.Path" 被更容易、更透明地
用于已有代码的:

   >>> import pathlib
   >>> with open(pathlib.Path("README")) as f:
   ...     contents = f.read()
   ...
   >>> import os.path
   >>> os.path.splitext(pathlib.Path("some_file.txt"))
   ('some_file', '.txt')
   >>> os.path.join("/a/b", pathlib.Path("c"))
   '/a/b/c'
   >>> import os
   >>> os.fspath(pathlib.Path("some_file.txt"))
   'some_file.txt'

（由 Brett Cannon, Ethan Furman, Dusty Phillips 和 Jelle Zijlstra 实现
。）

参见:

  **PEP 519** -- 添加文件系统路径协议
     PEP 由 Brett Cannon 和 Koos Zevenhoven 撰写。


PEP 495: 消除本地时间的歧义
---------------------------

在世界上大多数地方，过去和将来都会存在本地时钟后移的时候。 在这种时候
，本地时钟会在同一天内两次显示相同的时间。 对于这些情况，本地时钟所显
示的（或存储在 Python datetime 实例中的）信息将不足以标识某个特定的时
间点。

**PEP 495** 为 "datetime.datetime" 和 "datetime.time" 类的实例添加了新
的 *fold* 属性以在本地时间相同的两个时间点之间进行区分:

   >>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc)
   >>> for i in range(4):
   ...     u = u0 + i*HOUR
   ...     t = u.astimezone(Eastern)
   ...     print(u.time(), 'UTC =', t.time(), t.tzname(), t.fold)
   ...
   04:00:00 UTC = 00:00:00 EDT 0
   05:00:00 UTC = 01:00:00 EDT 0
   06:00:00 UTC = 01:00:00 EST 1
   07:00:00 UTC = 02:00:00 EST 0

"fold" 属性的值在大多数实例上均为 "0"，只有在代表存在歧义的时间的第二
个（按发生顺序）实例上例外。

参见:

  **PEP 495** -- 消除本地时间的歧义
     PEP 由 Alexander Belopolsky 和 Tim Peters 撰写，由 Alexander
     Belopolsky 实现。


PEP 529: 将 Windows 文件系统编码格式更改为 UTF-8
------------------------------------------------

在表示文件系统路径时最好是使用 str (Unicode) 而不是 bytes。 不过，在某
些情况下使用 bytes 就是足够而且正确的。

在 Python 3.6 之前，在 Windows 上使用 bytes 路径值可能会导致数据丢失。
有了这一更改，现在 Windows 上将支持使用 bytes 来表示路径，前提是这些
bytes 值是用 "sys.getfilesystemencoding()" 所返回的编码格式来编码的，
现在此编码格式默认为 "'utf-8'"。

不使用 str 来表示路径的应用程序应当使用 "os.fsencode()" 和
"os.fsdecode()" 来确保 bytes 被正确地编码。 要恢复以前的行为，请设置
"PYTHONLEGACYWINDOWSFSENCODING" 或调用
"sys._enablelegacywindowsfsencoding()"。

有关详细信息和可能需要的代码修改的讨论，请参见 **PEP 529** 。


PEP 528: 将 Windows 控制台编码格式更改为 UTF-8
----------------------------------------------

现在，Windows 上的默认控制台将接受所有 Unicode 字符并为 Python 代码提
供正确读取的 str 对象。"sys.stdin", "sys.stdout" 和 "sys.stderr" 现在
默认使用 utf-8 编码格式。

此更改仅在使用交互式控制台时适用，而不适用于重定向文件或管道。 要恢复
以前使用交互式控制台时的行为，请设置 "PYTHONLEGACYWINDOWSSTDIO"。

参见:

  **PEP 528** -- 将 Windows 控制台编码格式更改为 UTF-8
     PEP 由 Steve Dower 撰写并实现。


PEP 520: 保留类属性定义顺序
---------------------------

类定义体中的属性具有自然的排序：与名称在源代码中出现的顺序相同。 现在
此排序会在新类的 "__dict__" 属性中被保留。

并且，实际的默认类 *execution* 命名空间 (从 type.__prepare__() 返回)
现在将是一个保留插入顺序的映射对象。

参见:

  **PEP 520** -- 保留类属性定义顺序
     PEP 由 Eric Snow 撰写并实现


PEP 468: 保留关键字参数顺序
---------------------------

函数签名中的 "**kwargs" 现在将保证是一个保留插入顺序的映射对象。

参见:

  **PEP 468** -- 保留关键字参数顺序
     PEP 由 Eric Snow 撰写并实现


新的 dict 实现
--------------

dict 类型现在会使用一种基于 Raymond Hettinger 的提议 的“紧凑”表示形式
，该表示形式 最初由 PyPy 实现。 新的The memory usage of the new
"dict()" 的内存占用相比 Python 3.5 减少了 20% 到 25%。

这个新实现对原始顺序的保留被认为是一个实现细节而不应当被依赖（这在将来
可能会改变，但我们希望在改变语言规范以强制所有当前和将来的 Python 实现
都使用保留顺序的语义之前先在几个发布版的语言内部使用这个新的 dict 实现
；这也有助于让仍在使用随机迭代顺序的旧版本语言例如 Python 3.5 保持向下
兼容性）。

（由 INADA Naoki 在 bpo-27350 中贡献。 该特性 最初由 Raymond Hettinger
提议。）


PEP 523: 向 CPython 添加帧求值 API
----------------------------------

虽然 Python 为自定义代码执行方式提供了广泛的支持，但有一个地方它没有这
样做，那就是帧对象的求值。 如果您想在 Python 中拦截帧的求值，那么确实
没有除了直接操纵自定义函数的函数指针以外的任何办法。

**PEP 523** 通过提供使帧求值在 C 语言层级上可插入的 API 从而改变了这一
状况。 这将允许调试器和 JIT 等工具在 Python 代码开始执行之前拦截帧求值
。 这样就能允许 Python 代码使用替代性求值实现，跟踪帧求值等做法。

这个 API 并不是受限 C API 的组成部分，它被标记为私有以表明该 API 的使
用受到限制并且只适用于非常少的、低层级的用例。 这个 API 的语义将根据需
要随 Python 的一起发生变化。

参见:

  **PEP 523** -- 向 CPython 添加帧求值 API
     PEP 由 Brett Cannon 和 Dino Viehland 撰写。


PYTHONMALLOC 环境变量
---------------------

新的 "PYTHONMALLOC" 环境变量允许设置 Python 内存分配器并安装调试钩子。

现在将可以使用 "PYTHONMALLOC=debug" 在以发布模式编译的 Python 上为
Python 内存分配器安装调试钩子。 调试钩子的效果:

* 新分配的内存中填充字节 "0xCB"

* 释放的内存中填充了字节 "0xDB"

* 检测违反 Python 内存分配器 API 的操作。 例如，"PyObject_Free()" 在
  "PyMem_Malloc()" 所分配的内存块上被调用。

* 在缓冲区开始之前检测写操作（缓冲区下溢）

* 在缓冲区结束后检测写操作（缓冲区溢出）

* 检测当调用 "PYMEM_DOMAIN_OBJ" (如: "PyObject_Malloc()") 和
  "PYMEM_DOMAIN_MEM" (如: "PyMem_Malloc()") 域的分配器函数时 *GIL* 已
  被持有。

检查是否保留了 GIL 也是Python 3.6 的新特性。

请参阅 "PyMem_SetupDebugHooks()" 函数来了解 Python 内存分配器上的调试
钩子。

现在还可以使用 "PYTHONMALLOC=malloc" 为所有的 Python 内存分配强制使用
C 库的 "malloc()" 分配器。 这在以发布模式编译的 Python 上使用外部内存
调试器如 Valgrind 时会很有用处。

发生错误时，Python 内存分配器上的调试钩子现在会使用 "tracemalloc" 模块
来获取内存块被分配所在位置上的回溯。

使用 "python3.6 -X tracemalloc=5" (在回溯中存储 5 帧) 的缓冲区溢出的致
命错误示例:

   Debug memory block at address p=0x7fbcd41666f8: API 'o'
       4 bytes originally requested
       The 7 pad bytes at p-7 are FORBIDDENBYTE, as expected.
       The 8 pad bytes at tail=0x7fbcd41666fc are not all FORBIDDENBYTE (0xfb):
           at tail+0: 0x02 *** OUCH
           at tail+1: 0xfb
           at tail+2: 0xfb
           at tail+3: 0xfb
           at tail+4: 0xfb
           at tail+5: 0xfb
           at tail+6: 0xfb
           at tail+7: 0xfb
       The block was made by call #1233329 to debug malloc/realloc.
       Data at p: 1a 2b 30 00

   Memory block allocated at (most recent call first):
     File "test/test_bytes.py", line 323
     File "unittest/case.py", line 600
     File "unittest/case.py", line 648
     File "unittest/suite.py", line 122
     File "unittest/suite.py", line 84

   Fatal Python error: bad trailing pad byte

   Current thread 0x00007fbcdbd32700 (most recent call first):
     File "test/test_bytes.py", line 323 in test_hex
     File "unittest/case.py", line 600 in run
     File "unittest/case.py", line 648 in __call__
     File "unittest/suite.py", line 122 in run
     File "unittest/suite.py", line 84 in __call__
     File "unittest/suite.py", line 122 in run
     File "unittest/suite.py", line 84 in __call__
     ...

（由 Victor Stinner 在 bpo-26516 和 bpo-26564 中贡献。）


DTrace 和 SystemTap 探测支持
----------------------------

Python 现在可以附带 "--with-dtrace" 来构建以便为解释器中的下列事件启用
静态标记:

* 函数调用/返回

* 垃圾收集开始/完成

* 执行的代码行。

This can be used to instrument running interpreters in production,
without the need to recompile specific debug builds or providing
application-specific profiling/debugging code.

更多信息，请参见 使用 DTrace 和 SystemTap 检测CPython 。

当前的实现已在 Linux 和 macOS 上进行了测试。将来可能会添加其他标记。

（由 Łukasz Langa 在 bpo-21590 中贡献，基于 Jesús Cea Avión, David
Malcolm 和 Nikhil Benesch 的补丁。）


其他语言特性修改
================

对Python 语言核心进行的小改动：

* 现在 "global" 或 "nonlocal" 语句必须以文本形式出现在同一作用域中首次
  使用受影响的名称之前。 在之前版本中这只是 "SyntaxWarning"。

* 现在可以将某个 特殊方法 设为 "None" 来表示相应操作不可用。 举例来说
  ，如果某个类将 "__iter__()" 设为 "None"，则该类就将不可迭代。 （由
  Andrew Barnert 和 Ivan Levkivskyi 在 bpo-25958 中贡献。）

* 由重复的回溯行组成的长序列现在将被简化为 ""[Previous line repeated
  {count} more times]"" （请参阅 回溯 获取样例）。 （由 Emanuel Barry
  在 bpo-26823 中贡献。）

* 现在导入操作在无法找到模块时将引发新的异常 "ModuleNotFoundError"
  ("ImportError" 的子类)。 目前 (在 try-except 中) 检测 ImportError 的
  代码仍将有效。 （由 Eric Snow 在 bpo-15767 中贡献。）

* 现在依赖于零参数形式 "super()" 的类方法在类创建期间从元类方法调用时
  将正确地生效。 （由 Martin Teichmann 在 bpo-23722 中贡献。）


新增模块
========


secrets
-------

新的 "secrets" 模块的主要目的是提供一种直观的方式来可靠地生成适用于密
码管理的高加密强度的伪随机值，如账户验证、安全凭据等等。

警告:

  注意 "random" 模块中的伪随机数发生器 *不应* 被用于安全目的。 请在
  Python 3.6+ 上使用 "secrets" 而在 Python 3.5 及更早的版本上使用
  "os.urandom()"。

参见:

  **PEP 506** -- Secrets模块被加入Python标准库
     PEP 由 Steven D'Aprano 撰写并实现。


改进的模块
==========


array
-----

现在已被耗尽的输出 "array.array" 的迭代器将保持耗尽状态，即使迭代后的
数组被扩展时也是如此。  这将与其他可变序列的行为保持一致。

由 Serhiy Storchaka 在 bpo-26492 中贡献。


ast
---

新增了 "ast.Constant" AST 节点。 它可被外部 AST 优化器用于常量折叠操作
。

由 Victor Stinner 在 bpo-26146 中贡献。


asyncio
-------

从 Python 3.6 开始 "asyncio" 模块不再处于暂定状态，其 API 被认为已经稳
定。

自 Python 3.5.0 以来 "asyncio" 模块中值得注意的变化（由于暂定状态所有
变化都已反向移植到 3.5.x）:

* "get_event_loop()" 函数已更改为当在例程和回调中被调用时始终返回当前
  正在运行的循环。（由 Yury Selivanov 在 bpo-28613 中贡献。）

* "ensure_future()" 函数以及所有用到它的函数，比如
  "loop.run_until_complete()"，现在将接受所有种类的 *可等待对象*。 （
  由 Yury Selivanov 贡献。）

* 新增 "run_coroutine_threadsafe()" 函数用于从其他线程向事件循环提交协
  程。（由 Vincent Michel 贡献。）

* 新增 "Transport.is_closing()" 方法用于检查传输是否正在关闭或已经关闭
  。 （由 Yury Selivanov 贡献。）

* "loop.create_server()" 方法现在可以接受一个主机列表。 （由 Yann
  Sionneau 贡献。）

* 新增 "loop.create_future()" 方法用来创建 Future 对象。 这允许替代性
  的事件循环实现，比如 uvloop，以提供更快速的 "asyncio.Future" 实现。
  （由 Yury Selivanov 在 bpo-27041 中贡献。）

* 新增 "loop.get_exception_handler()" 方法用于获取当前异常处理句柄。
  （由 Yury Selivanov 在 bpo-27040 中贡献。）

* 新增 "StreamReader.readuntil()" 方法用于从流读取数据直到出现作为分隔
  符的字节序列。 （由 Mark Korenberg 贡献。）

* "StreamReader.readexactly()" 的性能已获得提升。 （由 Mark Korenberg
  在 bpo-28370 中贡献。）

* "loop.getaddrinfo()" 方法已获得优化已避免当地址已被解析时调用系统
  "getaddrinfo" 函数。 （由 A. Jesse Jiryu Davis 贡献。）

* "loop.stop()" 方法已被更改为在当前迭代之后立即停止循环。  任何作为上
  次迭代的结果被加入计划任务的新回调都将被丢弃。 （由 Guido van Rossum
  在 bpo-25593 中贡献。）

* 现在 "Future.set_exception" 在传入一个 "StopIteration" 异常的实例时
  将引发 "TypeError"。 （由 Chris Angelico 在 bpo-26221 中贡献。）

* 新增 "loop.connect_accepted_socket()" 方法供接受 asyncio 以外的连接
  ，但使用 asyncio 来处理它们的服务器使用。 （由 Jim Fulton 在
  bpo-27392 中贡献。）

* 现在 "TCP_NODELAY" 旗标将默认针对所有 TCP 传输进行设置。 （由 Yury
  Selivanov 在 bpo-27456 中贡献。）

* 新增 "loop.shutdown_asyncgens()" 用来在结束循环之前正确地关闭现有的
  异步生成器。 （由 Yury Selivanov 在 bpo-28003 中贡献。）

* "Future" 和 "Task" 类现在已有经优化过的 C 实现使得 asyncio 代码加速
  至多 30%。 （由 Yury Selivanov 和 INADA Naoki 在 bpo-26081 和
  bpo-28544 中贡献。）


binascii
--------

"b2a_base64()" 函数现在接受可选的 *newline* 关键字参数用来控制是否要在
返回值中添加换行符。 （由 Victor Stinner 在 bpo-25357 中贡献。）


cmath
-----

新增 "cmath.tau" (*τ*) 常量。 （由 Lisa Roach 在 bpo-12345 中贡献，详
情见 **PEP 628**。）

新增常量: "cmath.inf" 和 "cmath.nan" 用于匹配 "math.inf" 和 "math.nan"
，以及 "cmath.infj" 和 "cmath.nanj" 用于匹配由 complex 的 repr 所使用
的格式。 （由 Mark Dickinson 在 bpo-23229 中贡献。）


collections
-----------

添加了新的 "Collection" 抽象基类用于表示有具体大小的可迭代容器类。 （
由 Ivan Levkivskyi 在 bpo-27598 中贡献并由 Neil Girdhar 撰写文档。）

添加了新的 "Reversible" 抽象基类用于表示同时提供 "__reversed__()" 方法
的可迭代类。 （由 Ivan Levkivskyi 在 bpo-25987 中贡献。）

新增代表异步生成器的 "AsyncGenerator" 抽象基类。 （由 Yury Selivanov
在 bpo-28720 中贡献。）

"namedtuple()" 函数现在接受可选的关键字参数 *module*，当指定该参数时，
它将被用作所返回的具名元组类的 "__module__" 属性。 （由 Raymond
Hettinger 在 bpo-17941 中贡献。）

"namedtuple()" 的 *verbose* 和 *rename* 参数现在是仅限关键字参数。 （
由 Raymond Hettinger 在 bpo-25628 中贡献。）

递归的 "collections.deque" 实例现在可以被 pickle。 （由 Serhiy
Storchaka 在 bpo-26482 中贡献。）


concurrent.futures
------------------

"ThreadPoolExecutor" 类构造器现在接受可选的 *thread_name_prefix* 参数
以便能够自定义由线程池所创建的线程的名称。 （由 Gregory P. Smith 在
bpo-27664 中贡献。）


contextlib
----------

The "contextlib.AbstractContextManager" class has been added to
provide an abstract base class for context managers.  It provides a
sensible default implementation for *__enter__()* which returns "self"
and leaves *__exit__()* an abstract method.  A matching class has been
added to the "typing" module as "typing.ContextManager". (Contributed
by Brett Cannon in bpo-25609.)


datetime
--------

"datetime" 和 "time" 类新增了 "fold" 属性用来在必要时消除本地时间的歧
义。 在 "datetime" 中的许多函数已被更新为支持本地时间的消除歧义。 请参
阅 本地时间消歧义 一节了解更多信息。 （由 Alexander Belopolsky 在
bpo-24773 中贡献。）

现在 "datetime.strftime()" 和 "date.strftime()" 方法将支持 ISO 8601 日
期指令符 "%G", "%u" 和 "%V"。 （由 Ashley Anderson 在 bpo-12006 中贡献
。）.)

"datetime.isoformat()" 函数现在接受可选的 *timespec* 参数用来指定时间
值要包括的额外组件数量。 （由 Alessandro Cucci 和 Alexander Belopolsky
在 bpo-19475 中贡献。）

"datetime.combine()" 现在接受可选的 *tzinfo* 参数。 （由 Alexander
Belopolsky 在 bpo-27661 中贡献。）


decimal
-------

新增 "Decimal.as_integer_ratio()" 方法，它返回一对整数 "(n, d)" 将给定
的 "Decimal" 实例表示为一个最简形式且分母为正值的分数:

   >>> Decimal('-3.14').as_integer_ratio()
   (-157, 50)

（由 Stefan Krah 和 Mark Dickinson  在 bpo-25928 中贡献。）


distutils
---------

The "default_format" attribute has been removed from
"distutils.command.sdist.sdist" and the "formats" attribute defaults
to "['gztar']". Although not anticipated, any code relying on the
presence of "default_format" may need to be adapted. See bpo-27819 for
more details.


email
-----

通过多个构造器的 *policy* 关键字来启用的新 email API 已不再为暂定状态
。 "email" 文档已被重新组织并重新撰写以聚集新 API，同时保留旧式 API 的
原有文档。 （由 R. David Murray 在 bpo-24277 中贡献。）

"email.mime" 中的类现在都接受可选的 *policy* 关键字参数。 （由 Berker
Peksag 在 bpo-27331 中贡献。）.)

"DecodedGenerator" 现在支持 *policy* 关键字。

新增 "policy" 属性，"message_factory" 控制当解析器新建消息对象时默认要
使用的类。 对于 "email.policy.compat32" 策略来说将为 "Message"，对于新
策略来说将为 "EmailMessage"。 （由 R. David Murray 在 bpo-20476 中贡献
。）


encodings
---------

在 Windows 上，增加了 "'oem'" 编码格式用于 "CP_OEMCP"，以及 "'ansi'"
别名用于现有的 "'mbcs'" 编码格式，它使用 "CP_ACP" 代码页。 （由 Steve
Dower 在 bpo-27959 中贡献。）


enum
----

在 "enum" 模块中新增了两个枚举基类: "Flag" 和 "IntFlags"。 两者均被用
于定义可使用按位运算符进行组合的常量。 （由 Ethan Furman 在 bpo-23591
中贡献。）

许多标准库模块已被更新以使用 "IntFlags" 类作为其常量。

新增的 "enum.auto" 值可被用于自动为枚举成员赋值:

   >>> from enum import Enum, auto
   >>> class Color(Enum):
   ...     red = auto()
   ...     blue = auto()
   ...     green = auto()
   ...
   >>> list(Color)
   [<Color.red: 1>, <Color.blue: 2>, <Color.green: 3>]


faulthandler
------------

在 Windows 上，"faulthandler" 模块现在会为 Windows 异常安装处理句柄：
参见 "faulthandler.enable()"。 （由 Victor Stinner 在 bpo-23848 中贡献
。）


fileinput
---------

"hook_encoded()" 现在支持 *errors* 参数。 （由 Joseph Hackman 在
bpo-25788 中贡献。）


hashlib
-------

"hashlib" 已支持 OpenSSL 1.1.0。 最低的建议版本为 1.0.2。 （由
Christian Heimes 在 bpo-26470 中贡献。）

本模块增加了 BLAKE2 哈希函数。 "blake2b()" 和 "blake2s()" 将始终可用并
支持 BLAKE2 的完整特性集。 （由 Christian Heimes 在 bpo-26798 中基于
Dmitry Chestnykh 和 Samuel Neves 的代码贡献。 文档由 Dmitry Chestnykh
撰写。）

增加了 SHA-3 哈希函数 "sha3_224()", "sha3_256()", "sha3_384()",
"sha3_512()"，以及 SHAKE 哈希函数 "shake_128()" 和 "shake_256()"。 （
由 Christian Heimes 在 bpo-16113 中贡献。 Keccak 代码包由 Guido
Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche 和 Ronny Van
Keer 编写。）

基于密码的密钥推导函数 "scrypt()" 现可用于 OpenSSL 1.1.0 及更新版本。
（由 Christian Heimes 在 bpo-27928 中贡献。）


http.client
-----------

"HTTPConnection.request()" 和 "endheaders()" 现在都支持分块编码格式请
求体。 （由 Demian Brecht 和 Rolf Krahl 在 bpo-12319 中贡献。）


idlelib 与 IDLE
---------------

对 idlelib 包执行现代化和重构以使 IDLE 的外观和功能更好并使代码更易于
理解、测试和改进。 让 IDLE 外观更好的部分工作，尤其是在 Linux 和 Mac
上，在于使用了 ttk 部件，主要是在对话框中。 因此，IDLE 不再使用 tcl/tk
8.4。 现在它需要 tcl/tk 8.5 或 8.6。 我们建议运行这两个软件的最新发布
版。

‘现代化’包括 idlelib 模块的重命名与合并。 对具有部分大写名称的文件的重
命名类似于 3.0 中将 Tkinter 和 TkFont 重命名为 tkinter 和 tkinter.font
。 因此，在 3.5 中可用的 idlelib 文件导入在 3.6 中通常将不再可用。 至
少需要修改模块名称（参见 idlelib/README.txt），有时还需要更多修改。 （
名称更改由 Al Swiegart 和 Terry Reedy 在 bpo-24225 中贡献。 大多数
idlelib 补丁都是已经是或即将纳入该处理过程。）

作为补偿，最终的结果是一些 idlelib 类将更会易于使用，并有更好的 API 和
文档字符串加以说明。 附加的有用信息准备好后将被添加到 idlelib 中。

在 3.6.2 中新增:

多个对自动补全的修正。 （由 Louie Lu 在 bpo-15786 中贡献。）

在 3.6.3 中新增:

Module Browser (在 File 菜单中，之前称为 Class Browser) 现在会在最高层
级函数和类之外显示嵌套的函数和类。 （由 Guilherme Polo, Cheryl Sabella
和 Terry Jan Reedy 在 bpo-1612262 中贡献。）

之前以扩展形式实现的 IDLE 特性已作为正常特性重新实现。 它们的设置已从
Extensions 选项卡移至其他对话框选项卡。 （由 Charles Wohlganger 和
Terry Jan Reedy 在 bpo-27099 中实现。）

Settings 对话框 (Options 中的 Configure IDLE) 已经被部分重写以改进外观
和功能。 （由 Cheryl Sabella 和 Terry Jan Reedy 在多个问题项中贡献。）

在 3.6.4 中新增:

字体样本现在包括一组非拉丁字符以便用户能更好地查看所选特定字体的效果。
（由 Terry Jan Reedy 在 bpo-13802 中贡献。） 样本可以被修改以包括其他
字符。 （由 Serhiy Storchaka 在 bpo-31860 中贡献。）

在 3.6.6 中新增:

编辑器代码上下文选项已经过修改。 Box 会显示所有上下文行直到最大行数。
点击一个上下文行会使编辑器跳转到该行。 自定义主题的上下文颜色已添加到
Settings 对话框的 Highlights 选项卡。 （由 Cheryl Sabella 和 Terry Jan
Reedy 在 bpo-33642, bpo-33768 和 bpo-33679 中贡献。）

在 Windows 上，会有新的 API 调用将 tk 对 DPI 的调整告知 Windows。 在
Windows 8.1+ 或 10 上，如果 Python 二进制码的 DPI 兼容属性未改变，并且
监视器分辨率大于 96 DPI，这应该会令文本和线条更清晰。 否则的话它应该不
造成影响。 （由 Terry Jan Reedy 在 bpo-33656 中贡献。）

在 3.6.7 中新增:

超过 N 行（默认值为 50）的输出将被折叠为一个按钮。 N 可以在 Settings
对话框的 General 页的 PyShell 部分中进行修改。 数量较少但是超长的行可
以通过在输出上右击来折叠。 被折叠的输出可通过双击按钮来展开，或是通过
右击按钮来放入剪贴板或是单独的窗口。 （由 Tal Einat 在 bpo-1529353 中
贡献。）


importlib
---------

现在导入操作在无法找到模块时将引发新的异常 "ModuleNotFoundError"
("ImportError" 的子类)。 目前 (在 try-except 中) 检测 "ImportError" 的
代码仍将有效。 （由 Eric Snow 在 bpo-15767 中贡献。）

"importlib.util.LazyLoader" 现在将调用被包装的加载器上的
"create_module()"，移除了 "importlib.machinery.BuiltinImporter" 和
"importlib.machinery.ExtensionFileLoader" 不能用于
"importlib.util.LazyLoader" 的限制。

"importlib.util.cache_from_source()",
"importlib.util.source_from_cache()" 和
"importlib.util.spec_from_file_location()" 现在将接受 *path-like
object*。


inspect
-------

"inspect.signature()" 函数现在会报告编译器为推导式和生成器表达式作用域
生成的隐式 ".0" 形参，就像它们是调用``implicit0`` 时的仅限位置形参一样
。 （由 Jelle Zijlstra 在 bpo-19611 中贡献。）

为了减少从 Python 2.7 和旧式 "inspect.getargspec()" API 升级时的代码问
题，先前被写入文档的对 "inspect.getfullargspec()" 的弃用已被撤销。 虽
然这个函数对于单/源 Python 2/3 代码库来说很方便，但对于新代码来说功能
更丰富的 "inspect.signature()" 接口仍然是推荐的方式。 （由 Nick
Coghlan 在 bpo-27172 中贡献。）


json
----

现在 "json.load()" 和 "json.loads()" 均支持二进制输入。 已编码的 JSON
应当使用 UTF-8, UTF-16 或 UTF-32 来表示。 （由 Serhiy Storchaka 在
bpo-17909 中贡献。）


logging
-------

新增 "WatchedFileHandler.reopenIfNeeded()" 方法以添加检测日志文件是否
需要被重新打开的能力。 （由 Marian Horban 在 bpo-24884 中贡献。）.)


math
----

为 "math" 和 "cmath" 模块增加了 tau (*τ*) 常量。 （由 Lisa Roach 在
bpo-12345 中贡献，详情见 **PEP 628**。）


multiprocessing
---------------

由 "multiprocessing.Manager()" 返回的 代理对象 现在可以被嵌套。 （由
Davin Potts 在 bpo-6766 中贡献。）


os
--

请参阅 PEP 519 的概览了解现在 "os" 和 "os.path" 模块如何支持 *路径型对
象* 的详情。

现在 "scandir()" 支持 Windows 上的 "bytes" 路径。

新增的 "close()" 方法允许显式地关闭 "scandir()" 迭代器。 "scandir()"
迭代器现在支持 *context manager* 协议。 如果一个 "scandir()" 迭代器既
没有被耗尽也没有被显式地关闭则会在其析构器中发出 "ResourceWarning"。
（由 Serhiy Storchaka 在 bpo-25994 中贡献。）

在 Linux 上，现在 "os.urandom()" 会阻塞直到系统的 urandom 熵池被初始化
以提升安全性。 其理由参见 **PEP 524**。

Linux "getrandom()" 系统调用（获取随机字节数据）现在被暴露为新的
"os.getrandom()" 函数。 （由 Victor Stinner 贡献，为 **PEP 524** 的一
部分）


pathlib
-------

"pathlib" 现在支持 *路径型对象*。 （由 Brett Cannon 在 bpo-27186 中贡
献。）

请参阅 PEP 519 的概览了解详情。


pdb
---

The "Pdb" class constructor has a new optional *readrc* argument to
control whether ".pdbrc" files should be read.


pickle
------

Objects that need "__new__" called with keyword arguments can now be
pickled using pickle protocols older than protocol version 4. Protocol
version 4 already supports this case.  (Contributed by Serhiy
Storchaka in bpo-24164.)


pickletools
-----------

"pickletools.dis()" now outputs the implicit memo index for the
"MEMOIZE" opcode. (Contributed by Serhiy Storchaka in bpo-25382.)


pydoc
-----

The "pydoc" module has learned to respect the "MANPAGER" environment
variable. (Contributed by Matthias Klose in bpo-8637.)

"help()" and "pydoc" can now list named tuple fields in the order they
were defined rather than alphabetically. (Contributed by Raymond
Hettinger in bpo-24879.)


random
------

The new "choices()" function returns a list of elements of specified
size from the given population with optional weights. (Contributed by
Raymond Hettinger in bpo-18844.)


re
--

Added support of modifier spans in regular expressions.  Examples:
"'(?i:p)ython'" matches "'python'" and "'Python'", but not "'PYTHON'";
"'(?i)g(?-i:v)r'" matches "'GvR'" and "'gvr'", but not "'GVR'".
(Contributed by Serhiy Storchaka in bpo-433028.)

Match object groups can be accessed by "__getitem__", which is
equivalent to "group()".  So "mo['name']" is now equivalent to
"mo.group('name')".  (Contributed by Eric Smith in bpo-24454.)

"Match" objects now support "index-like objects" as group indices.
(Contributed by Jeroen Demeyer and Xiang Zhang in bpo-27177.)


readline
--------

Added "set_auto_history()" to enable or disable automatic addition of
input to the history list.  (Contributed by Tyler Crompton in
bpo-26870.)


rlcompleter
-----------

Private and special attribute names now are omitted unless the prefix
starts with underscores.  A space or a colon is added after some
completed keywords. (Contributed by Serhiy Storchaka in bpo-25011 and
bpo-25209.)


shlex
-----

The "shlex" has much improved shell compatibility through the new
*punctuation_chars* argument to control which characters are treated
as punctuation. (Contributed by Vinay Sajip in bpo-1521950.)


site
----

When specifying paths to add to "sys.path" in a *.pth* file, you may
now specify file paths on top of directories (e.g. zip files).
(Contributed by Wolfgang Langner in bpo-26587).


sqlite3
-------

"sqlite3.Cursor.lastrowid" now supports the "REPLACE" statement.
(Contributed by Alex LordThorsen in bpo-16864.)


socket
------

The "ioctl()" function now supports the "SIO_LOOPBACK_FAST_PATH"
control code. (Contributed by Daniel Stokes in bpo-26536.)

The "getsockopt()" constants "SO_DOMAIN", "SO_PROTOCOL", "SO_PEERSEC",
and "SO_PASSSEC" are now supported. (Contributed by Christian Heimes
in bpo-26907.)

The "setsockopt()" now supports the "setsockopt(level, optname, None,
optlen: int)" form. (Contributed by Christian Heimes in bpo-27744.)

The socket module now supports the address family "AF_ALG" to
interface with Linux Kernel crypto API. "ALG_*", "SOL_ALG" and
"sendmsg_afalg()" were added. (Contributed by Christian Heimes in
bpo-27744 with support from Victor Stinner.)

New Linux constants "TCP_USER_TIMEOUT" and "TCP_CONGESTION" were
added. (Contributed by Omar Sandoval, issue:*26273*).


socketserver
------------

Servers based on the "socketserver" module, including those defined in
"http.server", "xmlrpc.server" and "wsgiref.simple_server", now
support the *context manager* protocol. (Contributed by Aviv Palivoda
in bpo-26404.)

The "wfile" attribute of "StreamRequestHandler" classes now implements
the "io.BufferedIOBase" writable interface.  In particular, calling
"write()" is now guaranteed to send the data in full.  (Contributed by
Martin Panter in bpo-26721.)


ssl
---

"ssl" supports OpenSSL 1.1.0.  The minimum recommend version is 1.0.2.
(Contributed by Christian Heimes in bpo-26470.)

3DES has been removed from the default cipher suites and ChaCha20
Poly1305 cipher suites have been added. (Contributed by Christian
Heimes in bpo-27850 and bpo-27766.)

"SSLContext" has better default configuration for options and ciphers.
(Contributed by Christian Heimes in bpo-28043.)

SSL session can be copied from one client-side connection to another
with the new "SSLSession" class.  TLS session resumption can speed up
the initial handshake, reduce latency and improve performance
(Contributed by Christian Heimes in bpo-19500 based on a draft by Alex
Warhawk.)

The new "get_ciphers()" method can be used to get a list of enabled
ciphers in order of cipher priority.

All constants and flags have been converted to "IntEnum" and
"IntFlags". (Contributed by Christian Heimes in bpo-28025.)

Server and client-side specific TLS protocols for "SSLContext" were
added. (Contributed by Christian Heimes in bpo-28085.)


statistics
----------

A new "harmonic_mean()" function has been added. (Contributed by
Steven D'Aprano in bpo-27181.)


struct
------

"struct" now supports IEEE 754 half-precision floats via the "'e'"
format specifier. (Contributed by Eli Stevens, Mark Dickinson in
bpo-11734.)


subprocess
----------

"subprocess.Popen" destructor now emits a "ResourceWarning" warning if
the child process is still running. Use the context manager protocol
("with proc: ...") or explicitly call the "wait()" method to read the
exit status of the child process. (Contributed by Victor Stinner in
bpo-26741.)

The "subprocess.Popen" constructor and all functions that pass
arguments through to it now accept *encoding* and *errors* arguments.
Specifying either of these will enable text mode for the *stdin*,
*stdout* and *stderr* streams. (Contributed by Steve Dower in
bpo-6135.)


sys
---

The new "getfilesystemencodeerrors()" function returns the name of the
error mode used to convert between Unicode filenames and bytes
filenames. (Contributed by Steve Dower in bpo-27781.)

On Windows the return value of the "getwindowsversion()" function now
includes the *platform_version* field which contains the accurate
major version, minor version and build number of the current operating
system, rather than the version that is being emulated for the process
(Contributed by Steve Dower in bpo-27932.)


telnetlib
---------

"Telnet" is now a context manager (contributed by Stéphane Wirtel in
bpo-25485).


time
----

The "struct_time" attributes "tm_gmtoff" and "tm_zone" are now
available on all platforms.


timeit
------

The new "Timer.autorange()" convenience method has been added to call
"Timer.timeit()" repeatedly so that the total run time is greater or
equal to 200 milliseconds. (Contributed by Steven D'Aprano in
bpo-6422.)

"timeit" now warns when there is substantial (4x) variance between
best and worst times. (Contributed by Serhiy Storchaka in bpo-23552.)


tkinter
-------

Added methods "trace_add()", "trace_remove()" and "trace_info()" in
the "tkinter.Variable" class.  They replace old methods
"trace_variable()", "trace()", "trace_vdelete()" and "trace_vinfo()"
that use obsolete Tcl commands and might not work in future versions
of Tcl. (Contributed by Serhiy Storchaka in bpo-22115).


回溯
----

Both the traceback module and the interpreter's builtin exception
display now abbreviate long sequences of repeated lines in tracebacks
as shown in the following example:

   >>> def f(): f()
   ...
   >>> f()
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "<stdin>", line 1, in f
     File "<stdin>", line 1, in f
     File "<stdin>", line 1, in f
     [Previous line repeated 995 more times]
   RecursionError: maximum recursion depth exceeded

（由  Emanuel Barry在 bpo-26823 中贡献。）


tracemalloc
-----------

The "tracemalloc" module now supports tracing memory allocations in
multiple different address spaces.

The new "DomainFilter" filter class has been added to filter block
traces by their address space (domain).

（由 Victor Stinner 在 bpo-26588 中贡献。）


typing
------

Since the "typing" module is *provisional*, all changes introduced in
Python 3.6 have also been backported to Python 3.5.x.

The "typing" module has a much improved support for generic type
aliases.  For example "Dict[str, Tuple[S, T]]" is now a valid type
annotation. (Contributed by Guido van Rossum in Github #195.)

The "typing.ContextManager" class has been added for representing
"contextlib.AbstractContextManager". (Contributed by Brett Cannon in
bpo-25609.)

The "typing.Collection" class has been added for representing
"collections.abc.Collection". (Contributed by Ivan Levkivskyi in
bpo-27598.)

The "typing.ClassVar" type construct has been added to mark class
variables.  As introduced in **PEP 526**, a variable annotation
wrapped in ClassVar indicates that a given attribute is intended to be
used as a class variable and should not be set on instances of that
class. (Contributed by Ivan Levkivskyi in Github #280.)

A new "TYPE_CHECKING" constant that is assumed to be "True" by the
static type checkers, but is "False" at runtime. (Contributed by Guido
van Rossum in Github #230.)

A new "NewType()" helper function has been added to create lightweight
distinct types for annotations:

   from typing import NewType

   UserId = NewType('UserId', int)
   some_id = UserId(524313)

The static type checker will treat the new type as if it were a
subclass of the original type.  (Contributed by Ivan Levkivskyi in
Github #189.)


unicodedata
-----------

The "unicodedata" module now uses data from Unicode 9.0.0.
(Contributed by Benjamin Peterson.)


unittest.mock
-------------

The "Mock" class has the following improvements:

* Two new methods, "Mock.assert_called()" and
  "Mock.assert_called_once()" to check if the mock object was called.
  (Contributed by Amit Saha in bpo-26323.)

* The "Mock.reset_mock()" method now has two optional keyword only
  arguments: *return_value* and *side_effect*. (Contributed by Kushal
  Das in bpo-21271.)


urllib.request
--------------

If a HTTP request has a file or iterable body (other than a bytes
object) but no "Content-Length" header, rather than throwing an error,
"AbstractHTTPHandler" now falls back to use chunked transfer encoding.
(Contributed by Demian Brecht and Rolf Krahl in bpo-12319.)


urllib.robotparser
------------------

"RobotFileParser" now supports the "Crawl-delay" and "Request-rate"
extensions. (Contributed by Nikolay Bogoychev in bpo-16099.)


venv
----

"venv" accepts a new parameter "--prompt". This parameter provides an
alternative prefix for the virtual environment. (Proposed by Łukasz
Balcerzak and ported to 3.6 by Stéphane Wirtel in bpo-22829.)


warnings
--------

A new optional *source* parameter has been added to the
"warnings.warn_explicit()" function: the destroyed object which
emitted a "ResourceWarning". A *source* attribute has also been added
to "warnings.WarningMessage" (contributed by Victor Stinner in
bpo-26568 and bpo-26567).

When a "ResourceWarning" warning is logged, the "tracemalloc" module
is now used to try to retrieve the traceback where the destroyed
object was allocated.

Example with the script "example.py":

   import warnings

   def func():
       return open(__file__)

   f = func()
   f = None

Output of the command "python3.6 -Wd -X tracemalloc=5 example.py":

   example.py:7: ResourceWarning: unclosed file <_io.TextIOWrapper name='example.py' mode='r' encoding='UTF-8'>
     f = None
   Object allocated at (most recent call first):
     File "example.py", lineno 4
       return open(__file__)
     File "example.py", lineno 6
       f = func()

The "Object allocated at" traceback is new and is only displayed if
"tracemalloc" is tracing Python memory allocations and if the
"warnings" module was already imported.


winreg
------

Added the 64-bit integer type "REG_QWORD". (Contributed by Clement
Rouault in bpo-23026.)


winsound
--------

Allowed keyword arguments to be passed to "Beep", "MessageBeep", and
"PlaySound" (bpo-27982).


xmlrpc.client
-------------

The "xmlrpc.client" module now supports unmarshalling additional data
types used by the Apache XML-RPC implementation for numerics and
"None". (Contributed by Serhiy Storchaka in bpo-26885.)


zipfile
-------

A new "ZipInfo.from_file()" class method allows making a "ZipInfo"
instance from a filesystem file. A new "ZipInfo.is_dir()" method can
be used to check if the "ZipInfo" instance represents a directory.
(Contributed by Thomas Kluyver in bpo-26039.)

The "ZipFile.open()" method can now be used to write data into a ZIP
file, as well as for extracting data. (Contributed by Thomas Kluyver
in bpo-26039.)


zlib
----

The "compress()" and "decompress()" functions now accept keyword
arguments. (Contributed by Aviv Palivoda in bpo-26243 and Xiang Zhang
in bpo-16764 respectively.)


性能优化
========

* The Python interpreter now uses a 16-bit wordcode instead of
  bytecode which made a number of opcode optimizations possible.
  (Contributed by Demur Rumed with input and reviews from Serhiy
  Storchaka and Victor Stinner in bpo-26647 and bpo-28050.)

* The "asyncio.Future" class now has an optimized C implementation.
  (Contributed by Yury Selivanov and INADA Naoki in bpo-26081.)

* The "asyncio.Task" class now has an optimized C implementation.
  (Contributed by Yury Selivanov in bpo-28544.)

* Various implementation improvements in the "typing" module (such as
  caching of generic types) allow up to 30 times performance
  improvements and reduced memory footprint.

* The ASCII decoder is now up to 60 times as fast for error handlers
  "surrogateescape", "ignore" and "replace" (Contributed by Victor
  Stinner in bpo-24870).

* The ASCII and the Latin1 encoders are now up to 3 times as fast for
  the error handler "surrogateescape" (Contributed by Victor Stinner
  in bpo-25227).

* The UTF-8 encoder is now up to 75 times as fast for error handlers
  "ignore", "replace", "surrogateescape", "surrogatepass" (Contributed
  by Victor Stinner in bpo-25267).

* The UTF-8 decoder is now up to 15 times as fast for error handlers
  "ignore", "replace" and "surrogateescape" (Contributed by Victor
  Stinner in bpo-25301).

* "bytes % args" is now up to 2 times faster. (Contributed by Victor
  Stinner in bpo-25349).

* "bytearray % args" is now between 2.5 and 5 times faster.
  (Contributed by Victor Stinner in bpo-25399).

* Optimize "bytes.fromhex()" and "bytearray.fromhex()": they are now
  between 2x and 3.5x faster. (Contributed by Victor Stinner in
  bpo-25401).

* Optimize "bytes.replace(b'', b'.')" and "bytearray.replace(b'',
  b'.')": up to 80% faster. (Contributed by Josh Snider in bpo-26574).

* Allocator functions of the "PyMem_Malloc()" domain
  ("PYMEM_DOMAIN_MEM") now use the pymalloc memory allocator instead
  of "malloc()" function of the C library. The pymalloc allocator is
  optimized for objects smaller or equal to 512 bytes with a short
  lifetime, and use "malloc()" for larger memory blocks. (Contributed
  by Victor Stinner in bpo-26249).

* "pickle.load()" and "pickle.loads()" are now up to 10% faster when
  deserializing many small objects (Contributed by Victor Stinner in
  bpo-27056).

* Passing *keyword arguments* to a function has an overhead in
  comparison with passing *positional arguments*.  Now in extension
  functions implemented with using Argument Clinic this overhead is
  significantly decreased. (Contributed by Serhiy Storchaka in
  bpo-27574).

* Optimized "glob()" and "iglob()" functions in the "glob" module;
  they are now about 3--6 times faster. (Contributed by Serhiy
  Storchaka in bpo-25596).

* Optimized globbing in "pathlib" by using "os.scandir()"; it is now
  about 1.5--4 times faster. (Contributed by Serhiy Storchaka in
  bpo-26032).

* "xml.etree.ElementTree" parsing, iteration and deepcopy performance
  has been significantly improved. (Contributed by Serhiy Storchaka in
  bpo-25638, bpo-25873, and bpo-25869.)

* Creation of "fractions.Fraction" instances from floats and decimals
  is now 2 to 3 times faster. (Contributed by Serhiy Storchaka in
  bpo-25971.)


构建和 C API 的改变
===================

* Python now requires some C99 support in the toolchain to build. Most
  notably, Python now uses standard integer types and macros in place
  of custom macros like "PY_LONG_LONG". For more information, see
  **PEP 7** and bpo-17884.

* Cross-compiling CPython with the Android NDK and the Android API
  level set to 21 (Android 5.0 Lollipop) or greater runs successfully.
  While Android is not yet a supported platform, the Python test suite
  runs on the Android emulator with only about 16 tests failures. See
  the Android meta-issue bpo-26865.

* The "--enable-optimizations" configure flag has been added. Turning
  it on will activate expensive optimizations like PGO. (Original
  patch by Alecsandru Patrascu of Intel in bpo-26359.)

* The *GIL* must now be held when allocator functions of
  "PYMEM_DOMAIN_OBJ" (ex: "PyObject_Malloc()") and "PYMEM_DOMAIN_MEM"
  (ex: "PyMem_Malloc()") domains are called.

* New "Py_FinalizeEx()" API which indicates if flushing buffered data
  failed. (Contributed by Martin Panter in bpo-5319.)

* "PyArg_ParseTupleAndKeywords()" now supports positional-only
  parameters.  Positional-only parameters are defined by empty names.
  (Contributed by Serhiy Storchaka in bpo-26282).

* "PyTraceback_Print" method now abbreviates long sequences of
  repeated lines as ""[Previous line repeated {count} more times]"".
  (Contributed by Emanuel Barry in bpo-26823.)

* The new "PyErr_SetImportErrorSubclass()" function allows for
  specifying a subclass of "ImportError" to raise. (Contributed by
  Eric Snow in bpo-15767.)

* The new "PyErr_ResourceWarning()" function can be used to generate a
  "ResourceWarning" providing the source of the resource allocation.
  (Contributed by Victor Stinner in bpo-26567.)

* The new "PyOS_FSPath()" function returns the file system
  representation of a *path-like object*. (Contributed by Brett Cannon
  in bpo-27186.)

* 现在 "PyUnicode_FSConverter()" 和 "PyUnicode_FSDecoder()" 函数将接受
  *路径类对象*。


其他改进
========

* 当 "--version" (简短形式: "-V") 提供了两次时，Python 将针对细节信息
  打印 "sys.version"。

     $ ./python -VV
     Python 3.6.0b4+ (3.6:223967b49e49+, Nov 21 2016, 20:55:04)
     [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]


弃用
====


新关键字
--------

"async" and "await" are not recommended to be used as variable, class,
function or module names.  Introduced by **PEP 492** in Python 3.5,
they will become proper keywords in Python 3.7.  Starting in Python
3.6, the use of "async" or "await" as names will generate a
"DeprecationWarning".


已弃用的 Python 行为
--------------------

Raising the "StopIteration" exception inside a generator will now
generate a "DeprecationWarning", and will trigger a "RuntimeError" in
Python 3.7.  See PEP 479: Change StopIteration handling inside
generators for details.

The "__aiter__()" method is now expected to return an asynchronous
iterator directly instead of returning an awaitable as previously.
Doing the former will trigger a "DeprecationWarning".  Backward
compatibility will be removed in Python 3.7. (Contributed by Yury
Selivanov in bpo-27243.)

A backslash-character pair that is not a valid escape sequence now
generates a "DeprecationWarning".  Although this will eventually
become a "SyntaxError", that will not be for several Python releases.
(Contributed by Emanuel Barry in bpo-27364.)

When performing a relative import, falling back on "__name__" and
"__path__" from the calling module when "__spec__" or "__package__"
are not defined now raises an "ImportWarning". (Contributed by Rose
Ames in bpo-25791.)


已弃用的 Python 模块、函数和方法
--------------------------------


asynchat
~~~~~~~~

The "asynchat" has been deprecated in favor of "asyncio". (Contributed
by Mariatta in bpo-25002.)


asyncore
~~~~~~~~

The "asyncore" has been deprecated in favor of "asyncio". (Contributed
by Mariatta in bpo-25002.)


dbm
~~~

Unlike other "dbm" implementations, the "dbm.dumb" module creates
databases with the "'rw'" mode and allows modifying the database
opened with the "'r'" mode.  This behavior is now deprecated and will
be removed in 3.8. (Contributed by Serhiy Storchaka in bpo-21708.)


distutils
~~~~~~~~~

The undocumented "extra_path" argument to the "Distribution"
constructor is now considered deprecated and will raise a warning if
set.   Support for this parameter will be removed in a future Python
release.  See bpo-27919 for details.


grp
~~~

The support of non-integer arguments in "getgrgid()" has been
deprecated. (Contributed by Serhiy Storchaka in bpo-26129.)


importlib
~~~~~~~~~

The "importlib.machinery.SourceFileLoader.load_module()" and
"importlib.machinery.SourcelessFileLoader.load_module()" methods are
now deprecated. They were the only remaining implementations of
"importlib.abc.Loader.load_module()" in "importlib" that had not been
deprecated in previous versions of Python in favour of
"importlib.abc.Loader.exec_module()".

The "importlib.machinery.WindowsRegistryFinder" class is now
deprecated. As of 3.6.0, it is still added to "sys.meta_path" by
default (on Windows), but this may change in future releases.


os
~~

Undocumented support of general *bytes-like objects* as paths in "os"
functions, "compile()" and similar functions is now deprecated.
(Contributed by Serhiy Storchaka in bpo-25791 and bpo-26754.)


re
~~

Support for inline flags "(?letters)" in the middle of the regular
expression has been deprecated and will be removed in a future Python
version.  Flags at the start of a regular expression are still
allowed. (Contributed by Serhiy Storchaka in bpo-22493.)


ssl
~~~

OpenSSL 0.9.8, 1.0.0 and 1.0.1 are deprecated and no longer supported.
In the future the "ssl" module will require at least OpenSSL 1.0.2 or
1.1.0.

SSL-related arguments like "certfile", "keyfile" and "check_hostname"
in "ftplib", "http.client", "imaplib", "poplib", and "smtplib" have
been deprecated in favor of "context". (Contributed by Christian
Heimes in bpo-28022.)

A couple of protocols and functions of the "ssl" module are now
deprecated. Some features will no longer be available in future
versions of OpenSSL. Other features are deprecated in favor of a
different API. (Contributed by Christian Heimes in bpo-28022 and
bpo-26470.)


tkinter
~~~~~~~

The "tkinter.tix" module is now deprecated.  "tkinter" users should
use "tkinter.ttk" instead.


venv
~~~~

The "pyvenv" script has been deprecated in favour of "python3 -m
venv". This prevents confusion as to what Python interpreter "pyvenv"
is connected to and thus what Python interpreter will be used by the
virtual environment.  (Contributed by Brett Cannon in bpo-25154.)


已弃用的 C API 函数和类型
-------------------------

Undocumented functions "PyUnicode_AsEncodedObject()",
"PyUnicode_AsDecodedObject()", "PyUnicode_AsEncodedUnicode()" and
"PyUnicode_AsDecodedUnicode()" are deprecated now. Use the generic
codec based API instead.


弃用的构建选项
--------------

The "--with-system-ffi" configure flag is now on by default on non-
macOS UNIX platforms.  It may be disabled by using "--without-system-
ffi", but using the flag is deprecated and will not be accepted in
Python 3.7. macOS is unaffected by this change.  Note that many OS
distributors already use the "--with-system-ffi" flag when building
their system Python.


移除
====


API 与特性的移除
----------------

* Unknown escapes consisting of "'\'" and an ASCII letter in regular
  expressions will now cause an error.  In replacement templates for
  "re.sub()" they are still allowed, but deprecated. The "re.LOCALE"
  flag can now only be used with binary patterns.

* "inspect.getmoduleinfo()" was removed (was deprecated since CPython
  3.3). "inspect.getmodulename()" should be used for obtaining the
  module name for a given path. (Contributed by Yury Selivanov in
  bpo-13248.)

* "traceback.Ignore" class and "traceback.usage", "traceback.modname",
  "traceback.fullmodname", "traceback.find_lines_from_code",
  "traceback.find_lines", "traceback.find_strings",
  "traceback.find_executable_lines" methods were removed from the
  "traceback" module. They were undocumented methods deprecated since
  Python 3.2 and equivalent functionality is available from private
  methods.

* The "tk_menuBar()" and "tk_bindForTraversal()" dummy methods in
  "tkinter" widget classes were removed (corresponding Tk commands
  were obsolete since Tk 4.0).

* The "open()" method of the "zipfile.ZipFile" class no longer
  supports the "'U'" mode (was deprecated since Python 3.4). Use
  "io.TextIOWrapper" for reading compressed text files in *universal
  newlines* mode.

* The undocumented "IN", "CDROM", "DLFCN", "TYPES", "CDIO", and
  "STROPTS" modules have been removed.  They had been available in the
  platform specific "Lib/plat-*/" directories, but were chronically
  out of date, inconsistently available across platforms, and
  unmaintained.  The script that created these modules is still
  available in the source distribution at Tools/scripts/h2py.py.

* The deprecated "asynchat.fifo" class has been removed.


移植到Python 3.6
================

本节列出了先前描述的更改以及可能需要更改代码的其他错误修正.


 'python' 命令行为的变化
------------------------

* The output of a special Python build with defined "COUNT_ALLOCS",
  "SHOW_ALLOC_COUNT" or "SHOW_TRACK_COUNT" macros is now off by
  default.  It can be re-enabled using the "-X showalloccount" option.
  It now outputs to "stderr" instead of "stdout". (Contributed by
  Serhiy Storchaka in bpo-23034.)


Python API 的变化
-----------------

* "open()" will no longer allow combining the "'U'" mode flag with
  "'+'". (Contributed by Jeff Balogh and John O'Connor in bpo-2091.)

* "sqlite3" no longer implicitly commits an open transaction before
  DDL statements.

* On Linux, "os.urandom()" now blocks until the system urandom entropy
  pool is initialized to increase the security.

* When "importlib.abc.Loader.exec_module()" is defined,
  "importlib.abc.Loader.create_module()" must also be defined.

* "PyErr_SetImportError()" now sets "TypeError" when its **msg**
  argument is not set. Previously only "NULL" was returned.

* The format of the "co_lnotab" attribute of code objects changed to
  support a negative line number delta. By default, Python does not
  emit bytecode with a negative line number delta. Functions using
  "frame.f_lineno", "PyFrame_GetLineNumber()" or "PyCode_Addr2Line()"
  are not affected. Functions directly decoding "co_lnotab" should be
  updated to use a signed 8-bit integer type for the line number
  delta, but this is only required to support applications using a
  negative line number delta. See "Objects/lnotab_notes.txt" for the
  "co_lnotab" format and how to decode it, and see the **PEP 511** for
  the rationale.

* The functions in the "compileall" module now return booleans instead
  of "1" or "0" to represent success or failure, respectively. Thanks
  to booleans being a subclass of integers, this should only be an
  issue if you were doing identity checks for "1" or "0". See
  bpo-25768.

* Reading the "port" attribute of "urllib.parse.urlsplit()" and
  "urlparse()" results now raises "ValueError" for out-of-range
  values, rather than returning "None".  See bpo-20059.

* The "imp" module now raises a "DeprecationWarning" instead of
  "PendingDeprecationWarning".

* The following modules have had missing APIs added to their "__all__"
  attributes to match the documented APIs: "calendar", "cgi", "csv",
  "ElementTree", "enum", "fileinput", "ftplib", "logging", "mailbox",
  "mimetypes", "optparse", "plistlib", "smtpd", "subprocess",
  "tarfile", "threading" and "wave".  This means they will export new
  symbols when "import *" is used. (Contributed by Joel Taddei and
  Jacek Kołodziej in bpo-23883.)

* When performing a relative import, if "__package__" does not compare
  equal to "__spec__.parent" then "ImportWarning" is raised.
  (Contributed by Brett Cannon in bpo-25791.)

* When a relative import is performed and no parent package is known,
  then "ImportError" will be raised. Previously, "SystemError" could
  be raised. (Contributed by Brett Cannon in bpo-18018.)

* Servers based on the "socketserver" module, including those defined
  in "http.server", "xmlrpc.server" and "wsgiref.simple_server", now
  only catch exceptions derived from "Exception". Therefore if a
  request handler raises an exception like "SystemExit" or
  "KeyboardInterrupt", "handle_error()" is no longer called, and the
  exception will stop a single-threaded server. (Contributed by Martin
  Panter in bpo-23430.)

* 如果用户没有权限， "spwd.getspnam()" 现在会抛出 "PermissionError" 而
  非之前的 "KeyError" 。

* The "socket.socket.close()" method now raises an exception if an
  error (e.g. "EBADF") was reported by the underlying system call.
  (Contributed by Martin Panter in bpo-26685.)

* The *decode_data* argument for the "smtpd.SMTPChannel" and
  "smtpd.SMTPServer" constructors is now "False" by default. This
  means that the argument passed to "process_message()" is now a bytes
  object by default, and "process_message()" will be passed keyword
  arguments. Code that has already been updated in accordance with the
  deprecation warning generated by 3.5 will not be affected.

* All optional arguments of the "dump()", "dumps()", "load()" and
  "loads()" functions and "JSONEncoder" and "JSONDecoder" class
  constructors in the "json" module are now keyword-only. (Contributed
  by Serhiy Storchaka in bpo-18726.)

* "type" 的子类如果未重载 "type.__new__"，将不再能使用一个参数的形式来
  获取对象的类型。

* As part of **PEP 487**, the handling of keyword arguments passed to
  "type" (other than the metaclass hint, "metaclass") is now
  consistently delegated to "object.__init_subclass__()". This means
  that "type.__new__()" and "type.__init__()" both now accept
  arbitrary keyword arguments, but "object.__init_subclass__()" (which
  is called from "type.__new__()") will reject them by default. Custom
  metaclasses accepting additional keyword arguments will need to
  adjust their calls to "type.__new__()" (whether direct or via
  "super") accordingly.

* In "distutils.command.sdist.sdist", the "default_format" attribute
  has been removed and is no longer honored. Instead, the gzipped
  tarfile format is the default on all platforms and no platform-
  specific selection is made. In environments where distributions are
  built on Windows and zip distributions are required, configure the
  project with a "setup.cfg" file containing the following:

     [sdist]
     formats=zip

  This behavior has also been backported to earlier Python versions by
  Setuptools 26.0.0.

* In the "urllib.request" module and the
  "http.client.HTTPConnection.request()" method, if no Content-Length
  header field has been specified and the request body is a file
  object, it is now sent with HTTP 1.1 chunked encoding. If a file
  object has to be sent to a HTTP 1.0 server, the Content-Length value
  now has to be specified by the caller. (Contributed by Demian Brecht
  and Rolf Krahl with tweaks from Martin Panter in bpo-12319.)

* The "DictReader" now returns rows of type "OrderedDict".
  (Contributed by Steve Holden in bpo-27842.)

* The "crypt.METHOD_CRYPT" will no longer be added to "crypt.methods"
  if unsupported by the platform. (Contributed by Victor Stinner in
  bpo-25287.)

* "namedtuple()" 的 *verbose* 和 *rename* 参数现在是仅限关键字参数。
  （由 Raymond Hettinger 在 bpo-25628 中贡献。）

* On Linux, "ctypes.util.find_library()" now looks in
  "LD_LIBRARY_PATH" for shared libraries. (Contributed by Vinay Sajip
  in bpo-9998.)

* The "imaplib.IMAP4" class now handles flags containing the "']'"
  character in messages sent from the server to improve real-world
  compatibility. (Contributed by Lita Cho in bpo-21815.)

* The "mmap.write()" function now returns the number of bytes written
  like other write methods. (Contributed by Jakub Stasiak in
  bpo-26335.)

* The "pkgutil.iter_modules()" and "pkgutil.walk_packages()" functions
  now return "ModuleInfo" named tuples. (Contributed by Ramchandra
  Apte in bpo-17211.)

* "re.sub()" now raises an error for invalid numerical group
  references in replacement templates even if the pattern is not found
  in the string.  The error message for invalid group references now
  includes the group index and the position of the reference.
  (Contributed by SilentGhost, Serhiy Storchaka in bpo-25953.)

* "zipfile.ZipFile" will now raise "NotImplementedError" for
  unrecognized compression values.  Previously a plain "RuntimeError"
  was raised.  Additionally, calling "ZipFile" methods on a closed
  ZipFile or calling the "write()" method on a ZipFile created with
  mode "'r'" will raise a "ValueError". Previously, a "RuntimeError"
  was raised in those scenarios.

* when custom metaclasses are combined with zero-argument "super()" or
  direct references from methods to the implicit "__class__" closure
  variable, the implicit "__classcell__" namespace entry must now be
  passed up to "type.__new__" for initialisation. Failing to do so
  will result in a "DeprecationWarning" in Python 3.6 and a
  "RuntimeError" in Python 3.8.

* With the introduction of "ModuleNotFoundError", import system
  consumers may start expecting import system replacements to raise
  that more specific exception when appropriate, rather than the less-
  specific "ImportError". To provide future compatibility with such
  consumers, implementors of alternative import systems that
  completely replace "__import__()" will need to update their
  implementations to raise the new subclass when a module can't be
  found at all. Implementors of compliant plugins to the default
  import system shouldn't need to make any changes, as the default
  import system will raise the new subclass when appropriate.


C API 的变化
------------

* The "PyMem_Malloc()" allocator family now uses the pymalloc
  allocator rather than the system "malloc()". Applications calling
  "PyMem_Malloc()" without holding the GIL can now crash. Set the
  "PYTHONMALLOC" environment variable to "debug" to validate the usage
  of memory allocators in your application. See bpo-26249.

* "Py_Exit()" (and the main interpreter) now override the exit status
  with 120 if flushing buffered data failed.  See bpo-5319.


CPython 字节码的改变
--------------------

There have been several major changes to the *bytecode* in Python 3.6.

* The Python interpreter now uses a 16-bit wordcode instead of
  bytecode. (Contributed by Demur Rumed with input and reviews from
  Serhiy Storchaka and Victor Stinner in bpo-26647 and bpo-28050.)

* The new "FORMAT_VALUE" and "BUILD_STRING" opcodes as part of the
  formatted string literal implementation. (Contributed by Eric Smith
  in bpo-25483 and Serhiy Storchaka in bpo-27078.)

* The new "BUILD_CONST_KEY_MAP" opcode to optimize the creation of
  dictionaries with constant keys. (Contributed by Serhiy Storchaka in
  bpo-27140.)

* The function call opcodes have been heavily reworked for better
  performance and simpler implementation. The "MAKE_FUNCTION",
  "CALL_FUNCTION", "CALL_FUNCTION_KW" and "BUILD_MAP_UNPACK_WITH_CALL"
  opcodes have been modified, the new "CALL_FUNCTION_EX" and
  "BUILD_TUPLE_UNPACK_WITH_CALL" have been added, and
  "CALL_FUNCTION_VAR", "CALL_FUNCTION_VAR_KW" and "MAKE_CLOSURE"
  opcodes have been removed. (Contributed by Demur Rumed in bpo-27095,
  and Serhiy Storchaka in bpo-27213, bpo-28257.)

* The new "SETUP_ANNOTATIONS" and "STORE_ANNOTATION" opcodes have been
  added to support the new *variable annotation* syntax. (Contributed
  by Ivan Levkivskyi in bpo-27985.)


Python 3.6.2 中的重要变化
=========================


New "make regen-all" build target
---------------------------------

To simplify cross-compilation, and to ensure that CPython can reliably
be compiled without requiring an existing version of Python to already
be available, the autotools-based build system no longer attempts to
implicitly recompile generated files based on file modification times.

Instead, a new "make regen-all" command has been added to force
regeneration of these files when desired (e.g. after an initial
version of Python has already been built based on the pregenerated
versions).

More selective regeneration targets are also defined - see
Makefile.pre.in for details.

（由 Victor Stinner 在 bpo-23404 中贡献。）

3.6.2 新版功能.


Removal of "make touch" build target
------------------------------------

The "make touch" build target previously used to request implicit
regeneration of generated files by updating their modification times
has been removed.

它已被新的 "make regen-all" 目标所替代。

（由 Victor Stinner 在 bpo-23404 中贡献。）

在 3.6.2 版更改.


Python 3.6.4 中的重要变化
=========================

曾经作为 API 一部分的 "PyExc_RecursionErrorInst" 单例已被移除，因为它
的成员永远不会被清理，可能在解释器的最终化过程中导致段错误。 （由
Xavier de Gaye 在 bpo-22898 和 bpo-30697 中贡献。）


Python 3.6.5 中的重要变化
=========================

在某些情况下 "locale.localeconv()" 函数现在会临时将 "LC_CTYPE" 语言区
域设为 "LC_NUMERIC" 语言区域。 （由 Victor Stinner 在 bpo-31900 中贡献
。）


Python 3.6.7 中的重要变化
=========================

在 3.6.7 中当提供不带末尾换行符的输入时 "tokenize" 模块现在会隐式地发
出 "NEWLINE" 形符。 此行为现在已与 C 分词器的内部行为相匹配。 （由
Ammar Askar 在 bpo-33899 中贡献。）


Python 3.6.10 中的重要变化
==========================

出于重要的安全性考量，"asyncio.loop.create_datagram_endpoint()" 的
*reuse_address* 形参不再被支持。 这是由 UDP 中的套接字选项
"SO_REUSEADDR" 的行为导致的。 更多细节请参阅
"loop.create_datagram_endpoint()" 的文档。 （由 Kyle Stanley, Antoine
Pitrou 和 Yury Selivanov 在 bpo-37228 中贡献。。）


Python 3.6.13 中的重要变化
==========================

早先的 Python 版本允许使用 ";" 和 "&" 作为 "urllib.parse.parse_qs()"
和 "urllib.parse.parse_qsl()" 中 query 形参的分隔键。 出于安全考虑，也
为了遵循更新的 W3C 推荐设置，这已被改为只允许单个分隔键，默认为 "&"。
这一改变还会影响 "cgi.parse()" 和 "cgi.parse_multipart()" 因为它们在内
部使用了受影响的函数。 要了解更多细节，请查看它们各自的文档。 （由
Adam Goldschmidt, Senthil Kumaran 和 Ken Jin 在 bpo-42967 中贡献。）
