Files
hustoj/web/python-docs/whatsnew/3.7.html
2025-03-09 17:10:56 +08:00

1510 lines
303 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Python 3.7 有什么新变化 &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="next" title="Python 3.6 有什么新变化" href="3.6.html" />
<link rel="prev" title="Python 3.8 有什么新变化" href="3.8.html" />
<link rel="canonical" href="https://docs.python.org/3/whatsnew/3.7.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero"
d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">Python 3.7 有什么新变化</a><ul>
<li><a class="reference internal" href="#summary-release-highlights">摘要 - 发布重点</a></li>
<li><a class="reference internal" href="#new-features">新的特性</a><ul>
<li><a class="reference internal" href="#pep-563-postponed-evaluation-of-annotations">PEP 563延迟的标注求值</a></li>
<li><a class="reference internal" href="#pep-538-legacy-c-locale-coercion">PEP 538: 传统 C 区域强制转换</a></li>
<li><a class="reference internal" href="#pep-540-forced-utf-8-runtime-mode">PEP 540: 强制 UTF-8 运行时模式</a></li>
<li><a class="reference internal" href="#pep-553-built-in-breakpoint">PEP 553: 内置的 <code class="docutils literal notranslate"><span class="pre">breakpoint()</span></code></a></li>
<li><a class="reference internal" href="#pep-539-new-c-api-for-thread-local-storage">PEP 539: 用于线程局部存储的新 C API</a></li>
<li><a class="reference internal" href="#pep-562-customization-of-access-to-module-attributes">PEP 562: 定制对模块属性的访问</a></li>
<li><a class="reference internal" href="#pep-564-new-time-functions-with-nanosecond-resolution">PEP 564: 具有纳秒级精度的新时间函数</a></li>
<li><a class="reference internal" href="#pep-565-show-deprecationwarning-in-main">PEP 565: 在 <code class="docutils literal notranslate"><span class="pre">__main__</span></code> 中显示 DeprecationWarning</a></li>
<li><a class="reference internal" href="#pep-560-core-support-for-typing-module-and-generic-types">PEP 560: 对 <code class="docutils literal notranslate"><span class="pre">typing</span></code> 模块和泛型类型的核心支持</a></li>
<li><a class="reference internal" href="#pep-552-hash-based-pyc-files">PEP 552: 基于哈希值的 .pyc 文件</a></li>
<li><a class="reference internal" href="#pep-545-python-documentation-translations">PEP 545: Python 文档翻译</a></li>
<li><a class="reference internal" href="#development-runtime-mode-x-dev">开发运行时模式: -X dev</a></li>
</ul>
</li>
<li><a class="reference internal" href="#other-language-changes">其他语言特性修改</a></li>
<li><a class="reference internal" href="#new-modules">新增模块</a><ul>
<li><a class="reference internal" href="#contextvars">contextvars</a></li>
<li><a class="reference internal" href="#dataclasses">dataclasses</a></li>
<li><a class="reference internal" href="#importlib-resources">importlib.resources</a></li>
</ul>
</li>
<li><a class="reference internal" href="#improved-modules">改进的模块</a><ul>
<li><a class="reference internal" href="#argparse">argparse</a></li>
<li><a class="reference internal" href="#asyncio">asyncio</a></li>
<li><a class="reference internal" href="#binascii">binascii</a></li>
<li><a class="reference internal" href="#calendar">calendar</a></li>
<li><a class="reference internal" href="#collections">collections</a></li>
<li><a class="reference internal" href="#compileall">compileall</a></li>
<li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li>
<li><a class="reference internal" href="#contextlib">contextlib</a></li>
<li><a class="reference internal" href="#cprofile">cProfile</a></li>
<li><a class="reference internal" href="#crypt">crypt</a></li>
<li><a class="reference internal" href="#datetime">datetime</a></li>
<li><a class="reference internal" href="#dbm">dbm</a></li>
<li><a class="reference internal" href="#decimal">decimal</a></li>
<li><a class="reference internal" href="#dis">dis</a></li>
<li><a class="reference internal" href="#distutils">distutils</a></li>
<li><a class="reference internal" href="#enum">enum</a></li>
<li><a class="reference internal" href="#functools">functools</a></li>
<li><a class="reference internal" href="#gc">gc</a></li>
<li><a class="reference internal" href="#hmac">hmac</a></li>
<li><a class="reference internal" href="#http-client">http.client</a></li>
<li><a class="reference internal" href="#http-server">http.server</a></li>
<li><a class="reference internal" href="#idlelib-and-idle">idlelib 与 IDLE</a></li>
<li><a class="reference internal" href="#importlib">importlib</a></li>
<li><a class="reference internal" href="#io">io</a></li>
<li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
<li><a class="reference internal" href="#itertools">itertools</a></li>
<li><a class="reference internal" href="#locale">locale</a></li>
<li><a class="reference internal" href="#logging">logging</a></li>
<li><a class="reference internal" href="#math">math</a></li>
<li><a class="reference internal" href="#mimetypes">mimetypes</a></li>
<li><a class="reference internal" href="#msilib">msilib</a></li>
<li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
<li><a class="reference internal" href="#os">os</a></li>
<li><a class="reference internal" href="#pathlib">pathlib</a></li>
<li><a class="reference internal" href="#pdb">pdb</a></li>
<li><a class="reference internal" href="#py-compile">py_compile</a></li>
<li><a class="reference internal" href="#pydoc">pydoc</a></li>
<li><a class="reference internal" href="#queue">queue</a></li>
<li><a class="reference internal" href="#re">re</a></li>
<li><a class="reference internal" href="#signal">signal</a></li>
<li><a class="reference internal" href="#socket">socket</a></li>
<li><a class="reference internal" href="#socketserver">socketserver</a></li>
<li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
<li><a class="reference internal" href="#ssl">ssl</a></li>
<li><a class="reference internal" href="#string">string</a></li>
<li><a class="reference internal" href="#subprocess">subprocess</a></li>
<li><a class="reference internal" href="#sys">sys</a></li>
<li><a class="reference internal" href="#time">time</a></li>
<li><a class="reference internal" href="#tkinter">tkinter</a></li>
<li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
<li><a class="reference internal" href="#types">types</a></li>
<li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
<li><a class="reference internal" href="#unittest">unittest</a></li>
<li><a class="reference internal" href="#unittest-mock">unittest.mock</a></li>
<li><a class="reference internal" href="#urllib-parse">urllib.parse</a></li>
<li><a class="reference internal" href="#uu">uu</a></li>
<li><a class="reference internal" href="#uuid">uuid</a></li>
<li><a class="reference internal" href="#warnings">warnings</a></li>
<li><a class="reference internal" href="#xml-etree">xml.etree</a></li>
<li><a class="reference internal" href="#xmlrpc-server">xmlrpc.server</a></li>
<li><a class="reference internal" href="#zipapp">zipapp</a></li>
<li><a class="reference internal" href="#zipfile">zipfile</a></li>
</ul>
</li>
<li><a class="reference internal" href="#c-api-changes">C API 的改变</a></li>
<li><a class="reference internal" href="#build-changes">构建的改变</a></li>
<li><a class="reference internal" href="#optimizations">性能优化</a></li>
<li><a class="reference internal" href="#other-cpython-implementation-changes">其他 CPython 实现的改变</a></li>
<li><a class="reference internal" href="#deprecated-python-behavior">已弃用的 Python 行为</a></li>
<li><a class="reference internal" href="#deprecated-python-modules-functions-and-methods">已弃用的 Python 模块、函数和方法</a><ul>
<li><a class="reference internal" href="#aifc">aifc</a></li>
<li><a class="reference internal" href="#whatsnew37-asyncio-deprecated">asyncio</a></li>
<li><a class="reference internal" href="#id3">collections</a></li>
<li><a class="reference internal" href="#id4">dbm</a></li>
<li><a class="reference internal" href="#id5">enum</a></li>
<li><a class="reference internal" href="#gettext">gettext</a></li>
<li><a class="reference internal" href="#id6">importlib</a></li>
<li><a class="reference internal" href="#id7">locale</a></li>
<li><a class="reference internal" href="#macpath">macpath</a></li>
<li><a class="reference internal" href="#threading">threading</a></li>
<li><a class="reference internal" href="#id8">socket</a></li>
<li><a class="reference internal" href="#id9">ssl</a></li>
<li><a class="reference internal" href="#sunau">sunau</a></li>
<li><a class="reference internal" href="#id10">sys</a></li>
<li><a class="reference internal" href="#wave">wave</a></li>
</ul>
</li>
<li><a class="reference internal" href="#deprecated-functions-and-types-of-the-c-api">已弃用的 C API 函数和类型</a></li>
<li><a class="reference internal" href="#platform-support-removals">平台支持的移除</a></li>
<li><a class="reference internal" href="#api-and-feature-removals">API 与特性的移除</a></li>
<li><a class="reference internal" href="#module-removals">移除的模块</a></li>
<li><a class="reference internal" href="#windows-only-changes">Windows 专属的改变</a></li>
<li><a class="reference internal" href="#porting-to-python-3-7">移植到 Python 3.7</a><ul>
<li><a class="reference internal" href="#changes-in-python-behavior">Python 行为的更改</a></li>
<li><a class="reference internal" href="#changes-in-the-python-api">Python API 的变化</a></li>
<li><a class="reference internal" href="#changes-in-the-c-api">C API 的变化</a></li>
<li><a class="reference internal" href="#cpython-bytecode-changes">CPython 字节码的改变</a></li>
<li><a class="reference internal" href="#id12">Windows 专属的改变</a></li>
<li><a class="reference internal" href="#id13">其他 CPython 实现的改变</a></li>
</ul>
</li>
<li><a class="reference internal" href="#notable-changes-in-python-3-7-1">Python 3.7.1 中的重要变化</a></li>
<li><a class="reference internal" href="#notable-changes-in-python-3-7-2">Python 3.7.2 中的重要变化</a></li>
<li><a class="reference internal" href="#notable-changes-in-python-3-7-6">Python 3.7.6 中的重要变化</a></li>
<li><a class="reference internal" href="#notable-changes-in-python-3-7-10">Python 3.7.10 中的重要变化</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="3.8.html"
title="上一章">Python 3.8 有什么新变化</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="3.6.html"
title="下一章">Python 3.6 有什么新变化</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/whatsnew/3.7.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/whatsnew/3.7.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="3.6.html" title="Python 3.6 有什么新变化"
accesskey="N">下一页</a> |</li>
<li class="right" >
<a href="3.8.html" title="Python 3.8 有什么新变化"
accesskey="P">上一页</a> |</li>
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python的新变化</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="what-s-new-in-python-3-7">
<h1>Python 3.7 有什么新变化<a class="headerlink" href="#what-s-new-in-python-3-7" title="永久链接至标题"></a></h1>
<dl class="field-list simple">
<dt class="field-odd">编者</dt>
<dd class="field-odd"><p>Elvis Pranskevichus &lt;<a class="reference external" href="mailto:elvis&#37;&#52;&#48;magic&#46;io">elvis<span>&#64;</span>magic<span>&#46;</span>io</a>&gt;</p>
</dd>
</dl>
<p>本文解释了 Python 3.7 相比 3.6 的新增特性。Python 3.7 于 2018 年 6 月 27 日发布。完整的详情可参阅 <a class="reference internal" href="changelog.html#changelog"><span class="std std-ref">更新日志</span></a></p>
<section id="summary-release-highlights">
<h2>摘要 - 发布重点<a class="headerlink" href="#summary-release-highlights" title="永久链接至标题"></a></h2>
<p>新的语法特性:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#whatsnew37-pep563"><span class="std std-ref">PEP 563</span></a>,类型标注延迟求值。</p></li>
</ul>
<p>向后不兼容的语法更改:</p>
<ul class="simple">
<li><p><a class="reference internal" href="../reference/compound_stmts.html#async"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span></code></a><a class="reference internal" href="../reference/expressions.html#await"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">await</span></code></a> 现在是保留的关键字。</p></li>
</ul>
<p>新的库模块:</p>
<ul class="simple">
<li><p><a class="reference internal" href="../library/contextvars.html#module-contextvars" title="contextvars: Context Variables"><code class="xref py py-mod docutils literal notranslate"><span class="pre">contextvars</span></code></a>: <a class="reference internal" href="#whatsnew37-pep567"><span class="std std-ref">PEP 567 -- 上下文变量</span></a></p></li>
<li><p><a class="reference internal" href="../library/dataclasses.html#module-dataclasses" title="dataclasses: Generate special methods on user-defined classes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dataclasses</span></code></a>: <a class="reference internal" href="#whatsnew37-pep557"><span class="std std-ref">PEP 557 -- 数据类</span></a></p></li>
<li><p><a class="reference internal" href="#whatsnew37-importlib-resources"><span class="std std-ref">importlib.resources</span></a></p></li>
</ul>
<p>新的内置特性:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#whatsnew37-pep553"><span class="std std-ref">PEP 553</span></a>, 新的 <a class="reference internal" href="../library/functions.html#breakpoint" title="breakpoint"><code class="xref py py-func docutils literal notranslate"><span class="pre">breakpoint()</span></code></a> 函数。</p></li>
</ul>
<p>对 Python 数据模型的改进:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#whatsnew37-pep562"><span class="std std-ref">PEP 562</span></a>, 自定义可访问的模块属性。</p></li>
<li><p><a class="reference internal" href="#whatsnew37-pep560"><span class="std std-ref">PEP 560</span></a>, typing模块和泛型类型的核心支持。</p></li>
<li><p><a class="reference internal" href="../library/stdtypes.html#typesmapping"><span class="std std-ref">dict</span></a> 对象会保持插入时的顺序这个特性 <a class="reference external" href="https://mail.python.org/pipermail/python-dev/2017-December/151283.html">正式宣布</a> 成为 Python 语言官方规范的一部分。</p></li>
</ul>
<p>标准库中的重大改进:</p>
<ul class="simple">
<li><p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> 模块添加了新的功能,重大改进请参阅 <a class="reference internal" href="#whatsnew37-asyncio"><span class="std std-ref">可用性与性能提升</span></a></p></li>
<li><p><a class="reference internal" href="../library/time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> 模块现在提供 <a class="reference internal" href="#whatsnew37-pep564"><span class="std std-ref">纳秒级精度函数</span></a> 的支持。</p></li>
</ul>
<p>CPython 实现的改进:</p>
<ul class="simple">
<li><p>避免使用 ASCII 作为默认的文本编码:</p>
<ul>
<li><p><a class="reference internal" href="#whatsnew37-pep538"><span class="std std-ref">PEP 538</span></a>,传统 C 区域强制转换</p></li>
<li><p><a class="reference internal" href="#whatsnew37-pep540"><span class="std std-ref">PEP 540</span></a>,强制 UTF-8 运行时模式</p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#whatsnew37-pep552"><span class="std std-ref">PEP 552</span></a>,确定性的 .pyc 文件</p></li>
<li><p><a class="reference internal" href="#whatsnew37-devmode"><span class="std std-ref">新的开发运行时模式</span></a></p></li>
<li><p><a class="reference internal" href="#whatsnew37-pep565"><span class="std std-ref">PEP 565</span></a>,改进的 <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> 处理</p></li>
</ul>
<p>C API 的改进:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#whatsnew37-pep539"><span class="std std-ref">PEP 539</span></a>,用于线程本地存储的新 C API</p></li>
</ul>
<p>文档的改进:</p>
<ul class="simple">
<li><p><a class="reference internal" href="#whatsnew37-pep545"><span class="std std-ref">PEP 545</span></a>, Python 文档翻译</p></li>
<li><p>新的文档翻译:<a class="reference external" href="https://docs.python.org/ja/">Japanese</a><a class="reference external" href="https://docs.python.org/fr/">French</a><a class="reference external" href="https://docs.python.org/ko/">Korean</a></p></li>
</ul>
<p>此版本在诸多方面有显著的性能改进。<a class="reference internal" href="#whatsnew37-perf"><span class="std std-ref">性能优化</span></a> 章节详细列出了它们。</p>
<p>和之前的 Python 版本存在兼容性的更改列表,请参阅 <a class="reference internal" href="#porting-to-python-37"><span class="std std-ref">移植到 Python 3.7</span></a> 章节。</p>
</section>
<section id="new-features">
<h2>新的特性<a class="headerlink" href="#new-features" title="永久链接至标题"></a></h2>
<section id="pep-563-postponed-evaluation-of-annotations">
<span id="whatsnew37-pep563"></span><h3>PEP 563延迟的标注求值<a class="headerlink" href="#pep-563-postponed-evaluation-of-annotations" title="永久链接至标题"></a></h3>
<p>随着 <span class="target" id="index-78"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-3107"><strong>PEP 3107</strong></a> 加入标注功能并在 <span class="target" id="index-79"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0526"><strong>PEP 526</strong></a> 进一步细化Python 中类型提示的出现揭示了两个明显的可用性问题:</p>
<ul class="simple">
<li><p>标注只能使用在当前作用域中已经存在的名称,也就是说,它们不支持任何形式的前向引用;而且——</p></li>
<li><p>标注源码对 Python 程序的启动时间有不利的影响。</p></li>
</ul>
<p>这两个问题都可以通过延迟标注求值来解决。在定义标注的时候,编译器并不会编译执行相应表达式的代码,而是保存与相应表达式的 AST 等价的字符串形式。如果有需要,标注可以在运行时使用 <a class="reference internal" href="../library/typing.html#typing.get_type_hints" title="typing.get_type_hints"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_type_hints()</span></code></a> 进行解析。在不需要这种解析的通常情况下,标注的存储成本更低(因为解析器只需处理较短的字符串)且启动时间更短。</p>
<p>在可用性方面,标注现在支持向前引用,以使以下句法有效:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">C</span><span class="p">:</span>
<span class="nd">@classmethod</span>
<span class="k">def</span> <span class="nf">from_string</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">source</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">C</span><span class="p">:</span>
<span class="o">...</span>
<span class="k">def</span> <span class="nf">validate_b</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">:</span> <span class="n">B</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
<span class="o">...</span>
<span class="k">class</span> <span class="nc">B</span><span class="p">:</span>
<span class="o">...</span>
</pre></div>
</div>
<p>由于此修改会破坏兼容性,在 Python 3.7 中此种新的行为需要在每个模块层级上使用 <a class="reference internal" href="../library/__future__.html#module-__future__" title="__future__: Future statement definitions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">__future__</span></code></a> 导入来启用:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">annotations</span>
</pre></div>
</div>
<p>它将在 Python 3.10 中成为默认行为。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-80"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0563"><strong>PEP 563</strong></a> -- 延迟的标注求值</dt><dd><p>PEP 由 Łukasz Langa 撰写并实现。</p>
</dd>
</dl>
</div>
</section>
<section id="pep-538-legacy-c-locale-coercion">
<span id="whatsnew37-pep538"></span><h3>PEP 538: 传统 C 区域强制转换<a class="headerlink" href="#pep-538-legacy-c-locale-coercion" title="永久链接至标题"></a></h3>
<p>Python 3 系列有一个持续的挑战就是为处理 7 比特位 ASCII 文本的假定编码确定合理的默认策略,目前的设定是在非 Windows 平台上使用默认的 C 或 POSIX 区域设置。</p>
<p><span class="target" id="index-81"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0538"><strong>PEP 538</strong></a> 更新了默认的解释器命令行接口,以自动将上述区域强制转换为可用的基于 UTF-8 的区域,具体描述可参见有关新增环境变量 <span class="target" id="index-82"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONCOERCECLOCALE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONCOERCECLOCALE</span></code></a> 的文档。 以这种方式自动设置 <code class="docutils literal notranslate"><span class="pre">LC_CTYPE</span></code> 意味着核心解释器和能感知区域的 C 扩展 (例如 <a class="reference internal" href="../library/readline.html#module-readline" title="readline: GNU readline support for Python. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code></a>) 都将会假定 UTF-8 已被用作默认的文本编码,而不再是 ASCII。</p>
<p><span class="target" id="index-83"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0011"><strong>PEP 11</strong></a> 中的平台支持定义也已被更新以限制完整文本处理支持适当配置的基于非 ASCII 的语言区域。</p>
<p>作为此更改的一部分,当使用任何已定义的强制转换目标区域时 (目前为 <code class="docutils literal notranslate"><span class="pre">C.UTF-8</span></code>, <code class="docutils literal notranslate"><span class="pre">C.utf8</span></code><code class="docutils literal notranslate"><span class="pre">UTF-8</span></code>) <a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">stdin</span></code></a><a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">stdout</span></code></a> 默认的处理器现在将为 <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code> (而不是 <code class="docutils literal notranslate"><span class="pre">strict</span></code>)。 而无论是什么区域,<a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">stderr</span></code></a> 默认的处理器仍为 <code class="docutils literal notranslate"><span class="pre">backslashreplace</span></code></p>
<p>默认情况下区域强制转换会静默进行,但为了辅助调试潜在的区域相关集成问题,可以通过设置 <code class="docutils literal notranslate"><span class="pre">PYTHONCOERCECLOCALE=warn</span></code> 来请求显式地启用警告信息(直接在 <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">stderr</span></code></a> 上发出)。 此设置还会使得 Python 运行时在核心解释器初始化时如果传统 C 区域仍然处于激活状态时发出警告。</p>
<p>虽然 <span class="target" id="index-84"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0538"><strong>PEP 538</strong></a> 的区域强制转换的好处在于它还会同时影响扩展模块 (例如 GNU <code class="docutils literal notranslate"><span class="pre">readline</span></code>) 以及子进程 (包括运行非 Python 应用和旧版本 Python 的子进程),但它也存在需要所运行系统必须存在适合的目标区域的缺点。 为了更好地处理没有可用适合的目标区域的情况 (例如在 RHEL/CentOS 7 上就会出现此情况)Python 3.7 还实现了 <a class="reference internal" href="#whatsnew37-pep540"><span class="std std-ref">PEP 540: 强制 UTF-8 运行时模式</span></a></p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-85"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0538"><strong>PEP 538</strong></a> -- 强制转换传统 C 区域到基于 UTF-8 的区域</dt><dd><p>PEP 由 Nick Coghlan 撰写并实现。</p>
</dd>
</dl>
</div>
</section>
<section id="pep-540-forced-utf-8-runtime-mode">
<span id="whatsnew37-pep540"></span><h3>PEP 540: 强制 UTF-8 运行时模式<a class="headerlink" href="#pep-540-forced-utf-8-runtime-mode" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../using/cmdline.html#id5"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> <code class="docutils literal notranslate"><span class="pre">utf8</span></code> 命令行选项和 <span class="target" id="index-86"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONUTF8"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONUTF8</span></code></a> 环境变量可被用来启用 CPython 的 <em>UTF-8 模式</em></p>
<p>当处于 UTF-8 模式时CPython 会忽略区域设置,并默认使用 UTF-8 编码。 用于 <a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a><a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a> 流的错误处理器将设置为 <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code></p>
<p>强制 UTF-8 模式可被用来在嵌入的 Python 解释器中改变文本处理行为,而不会改变嵌入方应用的区域设置。</p>
<p><span class="target" id="index-87"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0540"><strong>PEP 540</strong></a> 的 UTF-8 模式的好处是不必关心运行所在系统中有哪些可用区域即可工作,但它也存在对扩展模块 (例如 GNU <code class="docutils literal notranslate"><span class="pre">readline</span></code>)、运行非 Python 应用的子进程以及运行旧版本 Python 的子进程不起作用的缺点。 为了减小与这些组件通信时破坏文本数据的风险Python 3.7 还实现了 <a class="reference internal" href="#whatsnew37-pep540"><span class="std std-ref">PEP 540: 强制 UTF-8 运行时模式</span></a>)。</p>
<p>UTF-8 模式在语言区域为 <code class="docutils literal notranslate"><span class="pre">C</span></code><code class="docutils literal notranslate"><span class="pre">POSIX</span></code> 并且 <span class="target" id="index-88"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0538"><strong>PEP 538</strong></a> 区域强制转换特性无法将其修改为某种基于 UTF-8 的替代项时会被默认启用(无论修改失败是由于设置了 <code class="docutils literal notranslate"><span class="pre">PYTHONCOERCECLOCALE=0</span></code>, <code class="docutils literal notranslate"><span class="pre">LC_ALL</span></code> 还是由于缺少适合的目标区域)。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-89"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0540"><strong>PEP 540</strong></a> -- 增加了新的 UTF-8 模式</dt><dd><p>PEP 由 Victor Stinner 撰写并实现</p>
</dd>
</dl>
</div>
</section>
<section id="pep-553-built-in-breakpoint">
<span id="whatsnew37-pep553"></span><h3>PEP 553: 内置的 <code class="docutils literal notranslate"><span class="pre">breakpoint()</span></code><a class="headerlink" href="#pep-553-built-in-breakpoint" title="永久链接至标题"></a></h3>
<p>Python 3.7 包含了新的内置 <a class="reference internal" href="../library/functions.html#breakpoint" title="breakpoint"><code class="xref py py-func docutils literal notranslate"><span class="pre">breakpoint()</span></code></a> 函数,作为一种简单方便地进入 Python 调试器的方式。</p>
<p>内置 <code class="docutils literal notranslate"><span class="pre">breakpoint()</span></code> 会调用 <a class="reference internal" href="../library/sys.html#sys.breakpointhook" title="sys.breakpointhook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.breakpointhook()</span></code></a>。 在默认情况下后者会导入 <a class="reference internal" href="../library/pdb.html#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a> 然后再调用 <code class="docutils literal notranslate"><span class="pre">pdb.set_trace()</span></code>,但是通过将 <code class="docutils literal notranslate"><span class="pre">sys.breakpointhook()</span></code> 绑定到你选定的函数,<code class="docutils literal notranslate"><span class="pre">breakpoint()</span></code> 可以进入任何调试器。 此外,环境变量 <span class="target" id="index-90"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONBREAKPOINT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONBREAKPOINT</span></code></a> 可被设置为你选定的调试器的可调用对象。 设置 <code class="docutils literal notranslate"><span class="pre">PYTHONBREAKPOINT=0</span></code> 会完全禁用内置 <code class="docutils literal notranslate"><span class="pre">breakpoint()</span></code></p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-91"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0553"><strong>PEP 553</strong></a> -- 内置的 breakpoint()</dt><dd><p>PEP 由 Barry Warsaw 撰写并实现</p>
</dd>
</dl>
</div>
</section>
<section id="pep-539-new-c-api-for-thread-local-storage">
<span id="whatsnew37-pep539"></span><h3>PEP 539: 用于线程局部存储的新 C API<a class="headerlink" href="#pep-539-new-c-api-for-thread-local-storage" title="永久链接至标题"></a></h3>
<p>虽然 Python 已提供了用于线程局部存储支持的 C API但原有的 <a class="reference internal" href="../c-api/init.html#thread-local-storage-api"><span class="std std-ref">线程局部存储 (TLS) API</span></a> 使用 <code class="xref c c-type docutils literal notranslate"><span class="pre">int</span></code> 来表示所有平台上的 TLS 密钥。 对于官方支持的平台而言这通常不是问题,但这既不符合 POSIX 标准,也不具备任何实际意义上的可移植性。</p>
<p><span class="target" id="index-92"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0539"><strong>PEP 539</strong></a> 通过向 CPython 提供了一个新的 <a class="reference internal" href="../c-api/init.html#thread-specific-storage-api"><span class="std std-ref">线程特定存储 (TSS) API</span></a> 来改变这一点,它取代了原有的 CPython 内部 TLS API 的使用,并且原有 API 已弃用。 TSS API 使用一种新类型 <a class="reference internal" href="../c-api/init.html#c.Py_tss_t" title="Py_tss_t"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_tss_t</span></code></a> 而非 <code class="xref c c-type docutils literal notranslate"><span class="pre">int</span></code> 来表示 TSS 密钥 -- 这是一种不透明类型,其定义可能依赖于下层的 TLS 实现。 因此,这将允许在以无法安全地转换为 <code class="xref c c-type docutils literal notranslate"><span class="pre">int</span></code> 的方式定义原生 TLS 密钥的平台上构建 CPython。</p>
<p>请注意在原生 TLS 密钥定义方式无法被安全地转换为 <code class="xref c c-type docutils literal notranslate"><span class="pre">int</span></code> 的平台上,原有 TLS API 中的全部函数将无法执行并会立即返回失败信息。 这样能清楚地表明原有 API 在无法可靠使用的平台上不受支持,并且不会再尝试添加此类支持。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-93"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0539"><strong>PEP 539</strong></a> -- 在 CPython 中用于线程局部存储的新 C-API</dt><dd><p>PEP 由 Erik M. Bray 撰写;由 Masayuki Yamamoto 实现。</p>
</dd>
</dl>
</div>
</section>
<section id="pep-562-customization-of-access-to-module-attributes">
<span id="whatsnew37-pep562"></span><h3>PEP 562: 定制对模块属性的访问<a class="headerlink" href="#pep-562-customization-of-access-to-module-attributes" title="永久链接至标题"></a></h3>
<p>Python 3.7 允许在模块上定义 <a class="reference internal" href="../reference/datamodel.html#object.__getattr__" title="object.__getattr__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getattr__()</span></code></a> 并且当以其他方式找不到某个模块属性时将会调用它。 在模块上定义 <a class="reference internal" href="../reference/datamodel.html#object.__dir__" title="object.__dir__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__dir__()</span></code></a> 现在也是允许的。</p>
<p>一个典型的可能有用的例子是已弃用模块属性和惰性加载。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-94"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0562"><strong>PEP 562</strong></a> -- 模块的 <code class="docutils literal notranslate"><span class="pre">__getattr__</span></code><code class="docutils literal notranslate"><span class="pre">__dir__</span></code></dt><dd><p>PEP 由 Ivan Levkivskyi 撰写并实现</p>
</dd>
</dl>
</div>
</section>
<section id="pep-564-new-time-functions-with-nanosecond-resolution">
<span id="whatsnew37-pep564"></span><h3>PEP 564: 具有纳秒级精度的新时间函数<a class="headerlink" href="#pep-564-new-time-functions-with-nanosecond-resolution" title="永久链接至标题"></a></h3>
<p>现代系统的时钟精度可以超过由 <a class="reference internal" href="../library/time.html#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.time()</span></code></a> 函数及其变化形式所返回的浮点数的有限精度。 为了避免精度损失,<span class="target" id="index-95"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0564"><strong>PEP 564</strong></a><a class="reference internal" href="../library/time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> 模块中增加了原有计时器函数的六个新“纳秒版”变化形式:</p>
<ul class="simple">
<li><p><a class="reference internal" href="../library/time.html#time.clock_gettime_ns" title="time.clock_gettime_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.clock_gettime_ns()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/time.html#time.clock_settime_ns" title="time.clock_settime_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.clock_settime_ns()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/time.html#time.monotonic_ns" title="time.monotonic_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.monotonic_ns()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/time.html#time.perf_counter_ns" title="time.perf_counter_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.perf_counter_ns()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/time.html#time.process_time_ns" title="time.process_time_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.process_time_ns()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/time.html#time.time_ns" title="time.time_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.time_ns()</span></code></a></p></li>
</ul>
<p>这些新函数会以整数值的形式返回纳秒数。</p>
<p><a class="reference external" href="https://www.python.org/dev/peps/pep-0564/#annex-clocks-resolution-in-python">测量</a> 表明在 Linux 和 Windows 上 <a class="reference internal" href="../library/time.html#time.time_ns" title="time.time_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.time_ns()</span></code></a> 的精度大约比 <a class="reference internal" href="../library/time.html#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.time()</span></code></a> 要高 3 倍。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-96"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0564"><strong>PEP 564</strong></a> -- 增加具有纳秒级精度的新时间函数</dt><dd><p>PEP 由 Victor Stinner 撰写并实现</p>
</dd>
</dl>
</div>
</section>
<section id="pep-565-show-deprecationwarning-in-main">
<span id="whatsnew37-pep565"></span><h3>PEP 565: 在 <code class="docutils literal notranslate"><span class="pre">__main__</span></code> 中显示 DeprecationWarning<a class="headerlink" href="#pep-565-show-deprecationwarning-in-main" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> 的默认处理方式已经被更改,这此警告默认只显示一次,仅有当直接在 <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where the top-level script is run."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> 模块中运行的代码触发它们时才会再次显示。 因此,单文件脚本开发者以及 Python 交互模式使用者应该会再次开始看到针对他们所使用 API 的已弃用警告,但被导入应用、库和框架模块所触发的已弃用警告默认将继续隐藏。</p>
<p>作为此项更改的结果,标准库现在允许开发者在三种不同的已弃用警告行为之间进行选择:</p>
<ul class="simple">
<li><p><a class="reference internal" href="../library/exceptions.html#FutureWarning" title="FutureWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FutureWarning</span></code></a>: 默认情况下总是会显示,建议用于应用程序最终用户应该看到的警告信息(例如对于已弃用的应用程序配置的设置选项)。</p></li>
<li><p><a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>: 默认情况下仅在 <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where the top-level script is run."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> 中以及当运行测试时会显示,建议用于其他 Python 开发者应该看到的警告信息,提示版本升级可能导致行为改变或者错误。</p></li>
<li><p><a class="reference internal" href="../library/exceptions.html#PendingDeprecationWarning" title="PendingDeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PendingDeprecationWarning</span></code></a>: 默认情况下仅在运行测试时会显示,可用于提示未来版本升级将会改变警告类别为 <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a><a class="reference internal" href="../library/exceptions.html#FutureWarning" title="FutureWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FutureWarning</span></code></a> 的情况。</p></li>
</ul>
<p>在此之前 <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a><a class="reference internal" href="../library/exceptions.html#PendingDeprecationWarning" title="PendingDeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PendingDeprecationWarning</span></code></a> 都仅在运行测试时可见,这意味着主要编写单文件脚本或使用 Python 交互模式的开发者可能会因他们所用 API 突然出现的改变而感到惊讶。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-97"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0565"><strong>PEP 565</strong></a> -- 在 <code class="docutils literal notranslate"><span class="pre">__main__</span></code> 中显示 DeprecationWarning</dt><dd><p>PEP 由 Nick Coghlan 撰写并实现</p>
</dd>
</dl>
</div>
</section>
<section id="pep-560-core-support-for-typing-module-and-generic-types">
<span id="whatsnew37-pep560"></span><h3>PEP 560: 对 <code class="docutils literal notranslate"><span class="pre">typing</span></code> 模块和泛型类型的核心支持<a class="headerlink" href="#pep-560-core-support-for-typing-module-and-generic-types" title="永久链接至标题"></a></h3>
<p><span class="target" id="index-98"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0484"><strong>PEP 484</strong></a> 最初的设计方式使其不会向核心 CPython 解释器引入 <em>任何</em> 更改。 现在类型提示和 <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> 模块已被社区广泛使用,因此这个限制已被取消。 这个 PEP 引入了两个特殊方法 <a class="reference internal" href="../reference/datamodel.html#object.__class_getitem__" title="object.__class_getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__class_getitem__()</span></code></a><code class="docutils literal notranslate"><span class="pre">__mro_entries__</span></code>,这些方法现在被 <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> 中的大多数类和特殊构造所使用。 结果就是与类型相关的各类操作的速度提升了 7 倍,泛型类型可以在没有元类冲突的情况下被使用,而 <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> 模块中几个长期存在的错误也已被修正。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-99"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0560"><strong>PEP 560</strong></a> -- 对 typing 模块和泛型类型的核心支持</dt><dd><p>PEP 由 Ivan Levkivskyi 撰写并实现</p>
</dd>
</dl>
</div>
</section>
<section id="pep-552-hash-based-pyc-files">
<span id="whatsnew37-pep552"></span><h3>PEP 552: 基于哈希值的 .pyc 文件<a class="headerlink" href="#pep-552-hash-based-pyc-files" title="永久链接至标题"></a></h3>
<p>传统上 Python 检查字节码缓存文件 (即 <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> 文件) 是否最新的方式是通过对源码元数据 (最后更改的时间戳和大小)和生成缓存时保存在其文件头中的源码元数据进行比较。 这种检查方法虽然有效,但也存在缺点。 当文件系统的时间戳太粗糙时Python 有可能错过源码更新,导致用户感到困惑。 此外,在缓存文件中存在时间戳对于 <a class="reference external" href="https://reproducible-builds.org/">构建可再现</a> 并且基于内容的构建系统来说是有问题的。</p>
<p><span class="target" id="index-100"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0552"><strong>PEP 552</strong></a> 扩展了 pyc 格式以允许使用源文件的哈希值而非源文件的时间戳来检查有效性。 这种 <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> 文件就称为“基于哈希值的”。 默认情况下Python 仍然使用基于时间戳的有效性检查,不会在运行时生成基于哈希值的 <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> 文件。 基于哈希值的 <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> 文件可以使用 <a class="reference internal" href="../library/py_compile.html#module-py_compile" title="py_compile: Generate byte-code files from Python source files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code></a><a class="reference internal" href="../library/compileall.html#module-compileall" title="compileall: Tools for byte-compiling all Python source files in a directory tree."><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code></a> 来生成。</p>
<p>基于哈希值的 <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> 文件包含两种变体:已选定和未选定。 Python 会在运行时针对相应源码文件验证已选定基于哈希值的 <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> 文件,但对未选定基于哈希值的 pyc 文件则不会这样做。 未选定基于哈希值的 <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> 文件对于需要由 Python 外部的系统(例如构建系统)负责使 <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> 文件保持最新的环境来说是一种有用的性能优化。</p>
<p>请参阅 <a class="reference internal" href="../reference/import.html#pyc-invalidation"><span class="std std-ref">已缓存字节码的失效</span></a> 了解更多信息。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-101"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0552"><strong>PEP 552</strong></a> -- 确定性的 pyc 文件</dt><dd><p>PEP 由 Benjamin Peterson 撰写并实现</p>
</dd>
</dl>
</div>
</section>
<section id="pep-545-python-documentation-translations">
<span id="whatsnew37-pep545"></span><h3>PEP 545: Python 文档翻译<a class="headerlink" href="#pep-545-python-documentation-translations" title="永久链接至标题"></a></h3>
<p><span class="target" id="index-102"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0545"><strong>PEP 545</strong></a> 描述了创建和维护 Python 文档翻译的整个过程。</p>
<p>新增了三个新的翻译版本:</p>
<ul class="simple">
<li><p>日语: <a class="reference external" href="https://docs.python.org/ja/">https://docs.python.org/ja/</a></p></li>
<li><p>法语: <a class="reference external" href="https://docs.python.org/fr/">https://docs.python.org/fr/</a></p></li>
<li><p>韩语: <a class="reference external" href="https://docs.python.org/ko/">https://docs.python.org/ko/</a></p></li>
</ul>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-103"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0545"><strong>PEP 545</strong></a> -- Python 文档翻译</dt><dd><p>PEP 由 Julien Palard, Inada Naoki 和 Victor Stinner 撰写并实现。</p>
</dd>
</dl>
</div>
</section>
<section id="development-runtime-mode-x-dev">
<span id="whatsnew37-devmode"></span><h3>开发运行时模式: -X dev<a class="headerlink" href="#development-runtime-mode-x-dev" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../using/cmdline.html#id5"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> <code class="docutils literal notranslate"><span class="pre">dev</span></code> 命令行选项或新的 <span class="target" id="index-104"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONDEVMODE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONDEVMODE</span></code></a> 环境变量可被用来启用 CPython 的 <em>开发模式</em>。 在开发模式下CPython 会执行额外的在默认情况下开销过大的运行时检查。 请参阅 <a class="reference internal" href="../using/cmdline.html#id5"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> <code class="docutils literal notranslate"><span class="pre">dev</span></code> 文档查看对于此模式效果的完整描述。</p>
</section>
</section>
<section id="other-language-changes">
<h2>其他语言特性修改<a class="headerlink" href="#other-language-changes" title="永久链接至标题"></a></h2>
<ul class="simple">
<li><p><a class="reference internal" href="../reference/expressions.html#await"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">await</span></code></a> 表达式和包含 <a class="reference internal" href="../reference/compound_stmts.html#async-for"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">for</span></code></a> 子句的推导式不允许在 <a class="reference internal" href="../reference/lexical_analysis.html#f-strings"><span class="std std-ref">格式化字符串字面值</span></a> 的表达式中使用。 在 Python 3.7 中此限制已被取消。</p></li>
<li><p>现在可以将超过 255 个参数传递给一个函数,而现在一个函数也可以拥有超过 255 个形参。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12844">bpo-12844</a><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18896">bpo-18896</a> 中贡献。)</p></li>
<li><p>现在 <a class="reference internal" href="../library/stdtypes.html#bytes.fromhex" title="bytes.fromhex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytes.fromhex()</span></code></a><a class="reference internal" href="../library/stdtypes.html#bytearray.fromhex" title="bytearray.fromhex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytearray.fromhex()</span></code></a> 会忽略所有 ASCII 空白符,而非仅是空格符. (由 Robert Xiao 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28927">bpo-28927</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a><a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> 获得了对新 <a class="reference internal" href="../library/stdtypes.html#str.isascii" title="str.isascii"><code class="xref py py-meth docutils literal notranslate"><span class="pre">isascii()</span></code></a> 方法的支持,该方法可被用来测试是个字符串或字节串是否仅包含 ASCII 字符。 (由 INADA Naoki 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32677">bpo-32677</a> 中贡献。)</p></li>
<li><p>现在当 <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">...</span> <span class="pre">import</span> <span class="pre">...</span></code> 失败时 <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> 会显示模块名称和模块 <code class="docutils literal notranslate"><span class="pre">__file__</span></code> 路径。 (由 Matthias Bussonnier 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29546">bpo-29546</a> 中贡献。)</p></li>
<li><p>现在已支持涉及将子模块绑定到一个名称的绝对导入的循环导入。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30024">bpo-30024</a> 中贡献。)</p></li>
<li><p>现在 <code class="docutils literal notranslate"><span class="pre">object.__format__(x,</span> <span class="pre">'')</span></code> 等价于 <code class="docutils literal notranslate"><span class="pre">str(x)</span></code> 而非 <code class="docutils literal notranslate"><span class="pre">format(str(self),</span> <span class="pre">'')</span></code>。 (由 Serhiy Storchaka d <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28974">bpo-28974</a> 中贡献。)</p></li>
<li><p>为更好地支持栈跟踪的动态创建,现在 <a class="reference internal" href="../library/types.html#types.TracebackType" title="types.TracebackType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.TracebackType</span></code></a> 可以从 Python 代码中被实例化,并且 <a class="reference internal" href="../reference/datamodel.html#traceback-objects"><span class="std std-ref">回溯对象</span></a><code class="docutils literal notranslate"><span class="pre">tb_next</span></code> 属性现在是可写的。 (由 Nathaniel J. Smith 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30579">bpo-30579</a> 中贡献。)</p></li>
<li><p>当使用 <a class="reference internal" href="../using/cmdline.html#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a> 开关时,现在 <code class="docutils literal notranslate"><span class="pre">sys.path[0]</span></code> 会主动扩展为完整的起始目录路径,而不是保持为空目录(这将允许在发生导入时从 <em>当前</em> 工作目录导入) (由 Nick Coghlan 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33053">bpo-33053</a> 中贡献。)</p></li>
<li><p>新的 <a class="reference internal" href="../using/cmdline.html#id5"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> <code class="docutils literal notranslate"><span class="pre">importtime</span></code> 选项或 <span class="target" id="index-105"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPROFILEIMPORTTIME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPROFILEIMPORTTIME</span></code></a> 环境变量可被用来显示每次模块导入的时间。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31415">bpo-31415</a> 中贡献。)</p></li>
</ul>
</section>
<section id="new-modules">
<h2>新增模块<a class="headerlink" href="#new-modules" title="永久链接至标题"></a></h2>
<section id="contextvars">
<span id="whatsnew37-pep567"></span><h3>contextvars<a class="headerlink" href="#contextvars" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/contextvars.html#module-contextvars" title="contextvars: Context Variables"><code class="xref py py-mod docutils literal notranslate"><span class="pre">contextvars</span></code></a> 模块和一组 <a class="reference internal" href="../c-api/contextvars.html#contextvarsobjects"><span class="std std-ref">新的 C API</span></a> 引入了对 <em>上下文变量</em> 的支持。 上下文变量在概念上类似于线程局部变量。 与 TLS 不同,上下文变量能正确地支持异步代码。</p>
<p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a><a class="reference internal" href="../library/decimal.html#module-decimal" title="decimal: Implementation of the General Decimal Arithmetic Specification."><code class="xref py py-mod docutils literal notranslate"><span class="pre">decimal</span></code></a> 已得到更新以使用和支持开箱即用的上下文变量。 特别是激活的 decimal 上下文现在将存储在上下文变量中,它允许十进制运算在异步代码中使用正确的上下文。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-106"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0567"><strong>PEP 567</strong></a> -- 上下文变量</dt><dd><p>PEP 由 Yury Selivanov 撰写并实现</p>
</dd>
</dl>
</div>
</section>
<section id="dataclasses">
<span id="whatsnew37-pep557"></span><h3>dataclasses<a class="headerlink" href="#dataclasses" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/dataclasses.html#dataclasses.dataclass" title="dataclasses.dataclass"><code class="xref py py-func docutils literal notranslate"><span class="pre">dataclass()</span></code></a> 装饰器提供了一种声明 <em>数据类</em> 的方式。 数据类使用变量标注来描述其属性。 它的构造器和其他魔术方法例如 <a class="reference internal" href="../reference/datamodel.html#object.__repr__" title="object.__repr__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__repr__()</span></code></a>, <a class="reference internal" href="../reference/datamodel.html#object.__eq__" title="object.__eq__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__eq__()</span></code></a> 以及 <a class="reference internal" href="../reference/datamodel.html#object.__hash__" title="object.__hash__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__hash__()</span></code></a> 会自动地生成。</p>
<p>示例:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nd">@dataclass</span>
<span class="k">class</span> <span class="nc">Point</span><span class="p">:</span>
<span class="n">x</span><span class="p">:</span> <span class="nb">float</span>
<span class="n">y</span><span class="p">:</span> <span class="nb">float</span>
<span class="n">z</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.0</span>
<span class="n">p</span> <span class="o">=</span> <span class="n">Point</span><span class="p">(</span><span class="mf">1.5</span><span class="p">,</span> <span class="mf">2.5</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="c1"># produces &quot;Point(x=1.5, y=2.5, z=0.0)&quot;</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><span class="target" id="index-107"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0557"><strong>PEP 557</strong></a> -- 数据类</dt><dd><p>PEP 由 Eric V. Smith 撰写并实现</p>
</dd>
</dl>
</div>
</section>
<section id="importlib-resources">
<span id="whatsnew37-importlib-resources"></span><h3>importlib.resources<a class="headerlink" href="#importlib-resources" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/importlib.html#module-importlib.resources" title="importlib.resources: Package resource reading, opening, and access"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources</span></code></a> 模块提供了一些新的 API 和一个新的 ABC 用于访问、打开和读取包内的 <em>资源</em>。 资源基本上类似于包内的文件,但它们不一定是物理文件系统中实际的文件。 模块加载器可以提供 <code class="xref py py-meth docutils literal notranslate"><span class="pre">get_resource_reader()</span></code> 函数,它会返回一个 <a class="reference internal" href="../library/importlib.html#importlib.abc.ResourceReader" title="importlib.abc.ResourceReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.ResourceReader</span></code></a> 实例来支持这个新 API。 内置的文件路径加载器和 zip 文件加载器都支持此特性。</p>
<p>由 Barry Warsaw 和 Brett Cannon 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32248">bpo-32248</a> 中贡献。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<p><a class="reference external" href="http://importlib-resources.readthedocs.io/en/latest/">importlib_resources</a> -- 用于先前 Python 版本的 PyPI 下层接口。</p>
</div>
</section>
</section>
<section id="improved-modules">
<h2>改进的模块<a class="headerlink" href="#improved-modules" title="永久链接至标题"></a></h2>
<section id="argparse">
<h3>argparse<a class="headerlink" href="#argparse" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/argparse.html#argparse.ArgumentParser.parse_intermixed_args" title="argparse.ArgumentParser.parse_intermixed_args"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ArgumentParser.parse_intermixed_args()</span></code></a> 方法允许混合选项与位置参数。 (由 paul.j3 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14191">bpo-14191</a> 中提供。)</p>
</section>
<section id="asyncio">
<span id="whatsnew37-asyncio"></span><h3>asyncio<a class="headerlink" href="#asyncio" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> 模块获得了许多新的特性、可用性和 <a class="reference internal" href="#whatsnew37-asyncio-perf"><span class="std std-ref">性能提升</span></a>。 重要的改变包括:</p>
<ul>
<li><p>新的 <a class="reference internal" href="../glossary.html#term-provisional-api"><span class="xref std std-term">暂定</span></a> <a class="reference internal" href="../library/asyncio-task.html#asyncio.run" title="asyncio.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.run()</span></code></a> 函数可被用于通过自动创建和销毁事件循环来基于同步代码运行协程。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32314">bpo-32314</a> 中贡献。)</p></li>
<li><p>asyncio 增加支持 <a class="reference internal" href="../library/contextvars.html#module-contextvars" title="contextvars: Context Variables"><code class="xref py py-mod docutils literal notranslate"><span class="pre">contextvars</span></code></a>. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.call_soon" title="asyncio.loop.call_soon"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.call_soon()</span></code></a>, <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.call_soon_threadsafe" title="asyncio.loop.call_soon_threadsafe"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.call_soon_threadsafe()</span></code></a>, <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.call_later" title="asyncio.loop.call_later"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.call_later()</span></code></a>, <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.call_at" title="asyncio.loop.call_at"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.call_at()</span></code></a> 并且 <a class="reference internal" href="../library/asyncio-future.html#asyncio.Future.add_done_callback" title="asyncio.Future.add_done_callback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Future.add_done_callback()</span></code></a> 具有新的可选仅关键字参数 <em>context</em>。 现在 <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">Tasks</span></code></a> 会自动跟踪其上下文。 详情参见 <span class="target" id="index-108"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0567"><strong>PEP 567</strong></a>。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32436">bpo-32436</a> 中贡献。)</p></li>
<li><p>增加了新的 <a class="reference internal" href="../library/asyncio-task.html#asyncio.create_task" title="asyncio.create_task"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.create_task()</span></code></a> 函数作为 <code class="docutils literal notranslate"><span class="pre">asyncio.get_event_loop().create_task()</span></code> 的快捷方式。 (由 Andrew Svetlov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32311">bpo-32311</a> 中贡献。)</p></li>
<li><p>新的 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.start_tls" title="asyncio.loop.start_tls"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.start_tls()</span></code></a> 方法可用于升级现有的 TLS 连接。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23749">bpo-23749</a> 中贡献。)</p></li>
<li><p>新的 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_recv_into" title="asyncio.loop.sock_recv_into"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.sock_recv_into()</span></code></a> 方法允许直接从套接字读取数据放入所提供的缓冲区,从而可以减少数据复制。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31819">bpo-31819</a> 中贡献。)</p></li>
<li><p>新的 <a class="reference internal" href="../library/asyncio-task.html#asyncio.current_task" title="asyncio.current_task"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.current_task()</span></code></a> 函数可返回当前运行的 <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">Task</span></code></a> 实例,以及新的 <a class="reference internal" href="../library/asyncio-task.html#asyncio.all_tasks" title="asyncio.all_tasks"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.all_tasks()</span></code></a> 函数可返回给定循环中所有现存 <code class="docutils literal notranslate"><span class="pre">Task</span></code> 实例的集合。 <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.current_task" title="asyncio.Task.current_task"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Task.current_task()</span></code></a><a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.all_tasks" title="asyncio.Task.all_tasks"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Task.all_tasks()</span></code></a> 方法已弃用。 (由 Andrew Svetlov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32250">bpo-32250</a> 中贡献。)</p></li>
<li><p>新的 <em>暂定</em> <a class="reference internal" href="../library/asyncio-protocol.html#asyncio.BufferedProtocol" title="asyncio.BufferedProtocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">BufferedProtocol</span></code></a> 类允许通过手动控制接收缓冲区来实现流式协议。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32251">bpo-32251</a> 中贡献。)</p></li>
<li><p>新的 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.get_running_loop" title="asyncio.get_running_loop"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.get_running_loop()</span></code></a> 函数可返回当前运行的循环,如果没有循环在运行则引发 <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>。 这与 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.get_event_loop" title="asyncio.get_event_loop"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.get_event_loop()</span></code></a> 不同,后者在没有循环在运行时将 <em>创建</em> 一个新的事件循环。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32269">bpo-32269</a> 中提供。)</p></li>
<li><p>新的 <a class="reference internal" href="../library/asyncio-stream.html#asyncio.StreamWriter.wait_closed" title="asyncio.StreamWriter.wait_closed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">StreamWriter.wait_closed()</span></code></a> 协程方法允许执行等待直到流写入器被关闭。 新的 <a class="reference internal" href="../library/asyncio-stream.html#asyncio.StreamWriter.is_closing" title="asyncio.StreamWriter.is_closing"><code class="xref py py-meth docutils literal notranslate"><span class="pre">StreamWriter.is_closing()</span></code></a> 方法可用于确定写入器是否被关闭。 (由 Andrew Svetlov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32391">bpo-32391</a> 中贡献。)</p></li>
<li><p>新的 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_sendfile" title="asyncio.loop.sock_sendfile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.sock_sendfile()</span></code></a> 协程方法允许在可能的情况下使用 <a class="reference internal" href="../library/os.html#os.sendfile" title="os.sendfile"><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.sendfile</span></code></a> 发送文件。 (由 Andrew Svetlov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32410">bpo-32410</a> 中贡献。)</p></li>
<li><p>新的 <a class="reference internal" href="../library/asyncio-future.html#asyncio.Future.get_loop" title="asyncio.Future.get_loop"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Future.get_loop()</span></code></a><code class="docutils literal notranslate"><span class="pre">Task.get_loop()</span></code> 方法会返回创建 task 或 future 对象的事件循环的实例。 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.Server.get_loop" title="asyncio.Server.get_loop"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Server.get_loop()</span></code></a> 允许为 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.Server" title="asyncio.Server"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Server</span></code></a> 对象执行同样操作。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32415">bpo-32415</a> 中,以及由 Srinivas Reddy Thatiparthy 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32418">bpo-32418</a> 中贡献。)</p></li>
<li><p>现在可以控制 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.Server" title="asyncio.Server"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Server</span></code></a> 的实例如何开启服务。 之前,服务在创建后将立即开启服务。 新的 <em>start_serving</em> 关键字参数已添加到 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_server" title="asyncio.loop.create_server"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_server()</span></code></a><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_unix_server" title="asyncio.loop.create_unix_server"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_unix_server()</span></code></a>,并且 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.Server.start_serving" title="asyncio.Server.start_serving"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Server.start_serving()</span></code></a>, 和 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.Server.serve_forever" title="asyncio.Server.serve_forever"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Server.serve_forever()</span></code></a> 可被用来分离服务的实例化和服务的开启。 新的 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.Server.is_serving" title="asyncio.Server.is_serving"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Server.is_serving()</span></code></a> 方法会在服务开启时返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>。 现在 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.Server" title="asyncio.Server"><code class="xref py py-class docutils literal notranslate"><span class="pre">Server</span></code></a> 对象已是异步上下文管理器:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">srv</span> <span class="o">=</span> <span class="k">await</span> <span class="n">loop</span><span class="o">.</span><span class="n">create_server</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>
<span class="k">async</span> <span class="k">with</span> <span class="n">srv</span><span class="p">:</span>
<span class="c1"># some code</span>
<span class="c1"># At this point, srv is closed and no longer accepts new connections.</span>
</pre></div>
</div>
<p>(由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32662">bpo-32662</a> 中贡献。)</p>
</li>
<li><p><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.call_later" title="asyncio.loop.call_later"><code class="xref py py-func docutils literal notranslate"><span class="pre">loop.call_later()</span></code></a> 所返回的回调对象已获得新的 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.TimerHandle.when" title="asyncio.TimerHandle.when"><code class="xref py py-meth docutils literal notranslate"><span class="pre">when()</span></code></a> 方法,该方法会返回一个排入计划日程的绝对时间戳。 (由 Andrew Svetlov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32741">bpo-32741</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_datagram_endpoint" title="asyncio.loop.create_datagram_endpoint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_datagram_endpoint()</span> </code></a> 方法已获得对 Unix 套接字的支持。 (由 Quentin Dawans 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31245">bpo-31245</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/asyncio-stream.html#asyncio.open_connection" title="asyncio.open_connection"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.open_connection()</span></code></a>, <a class="reference internal" href="../library/asyncio-stream.html#asyncio.start_server" title="asyncio.start_server"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.start_server()</span></code></a> functions, <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_connection" title="asyncio.loop.create_connection"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_connection()</span></code></a>, <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_server" title="asyncio.loop.create_server"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_server()</span></code></a>, <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.connect_accepted_socket" title="asyncio.loop.connect_accepted_socket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_accepted_socket()</span></code></a> 方法及其对应的 UNIX 套接字变体现在接受 <em>ssl_handshake_timeout</em> 关键字参数。 (由 Neil Aspinall 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29970">bpo-29970</a> 中贡献。)</p></li>
<li><p>新的 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.Handle.cancelled" title="asyncio.Handle.cancelled"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Handle.cancelled()</span></code></a> 方法会在回调被取消时返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>。 (由 Marat Sharafutdinov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31943">bpo-31943</a> 中贡献。)</p></li>
<li><p>asyncio 源已被转换为使用 <a class="reference internal" href="../reference/compound_stmts.html#async"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span></code></a>/<a class="reference internal" href="../reference/expressions.html#await"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">await</span></code></a> 语法。 (由 Andrew Svetlov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32193">bpo-32193</a> 中贡献。)</p></li>
<li><p>新的 <a class="reference internal" href="../library/asyncio-protocol.html#asyncio.ReadTransport.is_reading" title="asyncio.ReadTransport.is_reading"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ReadTransport.is_reading()</span></code></a> 方法可用于确定传输的读取状态。 此外,对 <a class="reference internal" href="../library/asyncio-protocol.html#asyncio.ReadTransport.resume_reading" title="asyncio.ReadTransport.resume_reading"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ReadTransport.resume_reading()</span></code></a><a class="reference internal" href="../library/asyncio-protocol.html#asyncio.ReadTransport.pause_reading" title="asyncio.ReadTransport.pause_reading"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ReadTransport.pause_reading()</span></code></a> 的调用现在是幂等的。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32356">bpo-32356</a> 中贡献。)</p></li>
<li><p>接受套接字路径的循环方法现在支持传入 <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">路径类对象</span></a>。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32066">bpo-32066</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a>Linux 上的 TCP 套接字现在创建时默认带有 <code class="docutils literal notranslate"><span class="pre">TCP_NODELAY</span></code> 旗标设置。 (由 Yury Selivanov 和 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27456">bpo-27456</a> 中贡献。)</p></li>
<li><p>在被取消任务中发生的异常不会再被记录。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30508">bpo-30508</a> 中贡献。)</p></li>
<li><p>新的 <code class="docutils literal notranslate"><span class="pre">WindowsSelectorEventLoopPolicy</span></code><code class="docutils literal notranslate"><span class="pre">WindowsProactorEventLoopPolicy</span></code> 类。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33792">bpo-33792</a> 中贡献。)</p></li>
</ul>
<p>部分 <code class="docutils literal notranslate"><span class="pre">asyncio</span></code> API 改为 <a class="reference internal" href="#whatsnew37-asyncio-deprecated"><span class="std std-ref">已弃用</span></a></p>
</section>
<section id="binascii">
<h3>binascii<a class="headerlink" href="#binascii" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/binascii.html#binascii.b2a_uu" title="binascii.b2a_uu"><code class="xref py py-func docutils literal notranslate"><span class="pre">b2a_uu()</span></code></a> 函数现在接受可选的 <em>backtick</em> 关键字参数。 当其为真值时,零会以 <code class="docutils literal notranslate"><span class="pre">'`'</span></code> 而非空格来表示。 (由 Xiang Zhang 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30103">bpo-30103</a> 中贡献。)</p>
</section>
<section id="calendar">
<h3>calendar<a class="headerlink" href="#calendar" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/calendar.html#calendar.HTMLCalendar" title="calendar.HTMLCalendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLCalendar</span></code></a> 类具有新的类属性,可以简化所生成 HTML 日历中 CSS 类的自定义。 (由 Oz Tiram 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30095">bpo-30095</a> 中贡献。)</p>
</section>
<section id="collections">
<h3>collections<a class="headerlink" href="#collections" title="永久链接至标题"></a></h3>
<p><code class="docutils literal notranslate"><span class="pre">collections.namedtuple()</span></code> 现在支持默认值。 (由 Raymond Hettinger 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32320">bpo-32320</a> 中贡献。)</p>
</section>
<section id="compileall">
<h3>compileall<a class="headerlink" href="#compileall" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/compileall.html#compileall.compile_dir" title="compileall.compile_dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">compileall.compile_dir()</span></code></a> 增加了新的 <em>invalidation_mode</em> 形参,可用于启用 <a class="reference internal" href="#whatsnew37-pep552"><span class="std std-ref">基于哈希值的 .pyc 有效性检测</span></a>。 失效模式也可以在命令行中使用新的 <code class="docutils literal notranslate"><span class="pre">--invalidation-mode</span></code> 参数来指定。 (由 Benjamin Peterson 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31650">bpo-31650</a> 中贡献。)</p>
</section>
<section id="concurrent-futures">
<h3>concurrent.futures<a class="headerlink" href="#concurrent-futures" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor" title="concurrent.futures.ProcessPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProcessPoolExecutor</span></code></a><a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ThreadPoolExecutor</span></code></a> 现在支持新的 <em>初始化器</em> 以及 <em>initargs</em> 构造器参数。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21423">bpo-21423</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor" title="concurrent.futures.ProcessPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProcessPoolExecutor</span></code></a> 现在能通过新的 <em>mp_context</em> 参数来接受多进程上下文。 (由 Thomas Moreau 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31540">bpo-31540</a> 中贡献。)</p>
</section>
<section id="contextlib">
<h3>contextlib<a class="headerlink" href="#contextlib" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/contextlib.html#contextlib.nullcontext" title="contextlib.nullcontext"><code class="xref py py-func docutils literal notranslate"><span class="pre">nullcontext()</span></code></a> 是一个比 <a class="reference internal" href="../library/contextlib.html#contextlib.ExitStack" title="contextlib.ExitStack"><code class="xref py py-class docutils literal notranslate"><span class="pre">ExitStack</span></code></a> 更简单和快速的无操作上下文管理器。 (由 Jesse-Bakker 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10049">bpo-10049</a> 中贡献。)</p>
<p>增加了新的 <a class="reference internal" href="../library/contextlib.html#contextlib.asynccontextmanager" title="contextlib.asynccontextmanager"><code class="xref py py-func docutils literal notranslate"><span class="pre">asynccontextmanager()</span></code></a>, <a class="reference internal" href="../library/contextlib.html#contextlib.AbstractAsyncContextManager" title="contextlib.AbstractAsyncContextManager"><code class="xref py py-class docutils literal notranslate"><span class="pre">AbstractAsyncContextManager</span></code></a><a class="reference internal" href="../library/contextlib.html#contextlib.AsyncExitStack" title="contextlib.AsyncExitStack"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncExitStack</span></code></a> 以补充它们所对应的同步项。 (由 Jelle Zijlstra 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29679">bpo-29679</a><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30241">bpo-30241</a> 中,以及由 Alexander Mohr 和 Ilya Kulakov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29302">bpo-29302</a> 中贡献。)</p>
</section>
<section id="cprofile">
<h3>cProfile<a class="headerlink" href="#cprofile" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/profile.html#module-cProfile" title="cProfile"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cProfile</span></code></a> 命令行现在接受 <code class="docutils literal notranslate"><span class="pre">-m</span> <span class="pre">module_name</span></code> 作为脚本路径的替代。 (由 Sanyam Khurana 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21862">bpo-21862</a> 中贡献。)</p>
</section>
<section id="crypt">
<h3>crypt<a class="headerlink" href="#crypt" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/crypt.html#module-crypt" title="crypt: The crypt() function used to check Unix passwords. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">crypt</span></code></a> 模块现在支持 Blowfish 哈希方法。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31664">bpo-31664</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/crypt.html#crypt.mksalt" title="crypt.mksalt"><code class="xref py py-func docutils literal notranslate"><span class="pre">mksalt()</span></code></a> 函数现在允许指定哈希操作的轮数。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31702">bpo-31702</a> 中贡献。)</p>
</section>
<section id="datetime">
<h3>datetime<a class="headerlink" href="#datetime" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/datetime.html#datetime.datetime.fromisoformat" title="datetime.datetime.fromisoformat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.fromisoformat()</span></code></a> 方法会基于由 <code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.isoformat()</span></code> 所输出的某一特定格式字符串构建 <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> 对象。 (由 Paul Ganssle 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15873">bpo-15873</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/datetime.html#datetime.tzinfo" title="datetime.tzinfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">tzinfo</span></code></a> 类现在支持小于一分钟的偏移量。 (由 Alexander Belopolsky 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5288">bpo-5288</a> 中贡献。)</p>
</section>
<section id="dbm">
<h3>dbm<a class="headerlink" href="#dbm" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/dbm.html#module-dbm.dumb" title="dbm.dumb: Portable implementation of the simple DBM interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.dumb</span></code></a> 现在支持读取只读文件,并且在其未改变时不再写入索引文件。</p>
</section>
<section id="decimal">
<h3>decimal<a class="headerlink" href="#decimal" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/decimal.html#module-decimal" title="decimal: Implementation of the General Decimal Arithmetic Specification."><code class="xref py py-mod docutils literal notranslate"><span class="pre">decimal</span></code></a> 模块现在使用 <a class="reference internal" href="#whatsnew37-pep567"><span class="std std-ref">上下文变量</span></a> 来储存十进制值上下文。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32630">bpo-32630</a> 中贡献。)</p>
</section>
<section id="dis">
<h3>dis<a class="headerlink" href="#dis" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/dis.html#dis.dis" title="dis.dis"><code class="xref py py-func docutils literal notranslate"><span class="pre">dis()</span></code></a> 函数现在能够反汇编嵌套的代码对象(推导式、生成器表达式和嵌套函数的代码,以及用于构建嵌套类的代码)。 反汇编递归的最大深度由新的 <em>depth</em> 形参来控制。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11822">bpo-11822</a> 中贡献。)</p>
</section>
<section id="distutils">
<h3>distutils<a class="headerlink" href="#distutils" title="永久链接至标题"></a></h3>
<p><code class="docutils literal notranslate"><span class="pre">README.rst</span></code> 现在包含在 distutils 的标准 README 列表之中,因而也包含在源码发布之中。 (由 Ryan Gonzalez 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11913">bpo-11913</a> 中贡献。)</p>
</section>
<section id="enum">
<h3>enum<a class="headerlink" href="#enum" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/enum.html#enum.Enum" title="enum.Enum"><code class="xref py py-class docutils literal notranslate"><span class="pre">Enum</span></code></a> 增加了新的 <code class="docutils literal notranslate"><span class="pre">_ignore_</span></code> 类特征属性,该属性允许列出不应当成为枚举成员的特征属性名称。 (由 Ethan Furman 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31801">bpo-31801</a> 中贡献。)</p>
<p>在 Python 3.8 中,尝试在 <code class="xref py py-class docutils literal notranslate"><span class="pre">Enum</span></code> 类中检查非 Enum 对象将引发 <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> (例如 <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">in</span> <span class="pre">Color</span></code>);类似地,尝试在 <code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code> 成员中检查非 Flag 对象也将引发 <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> (例如 <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">in</span> <span class="pre">Perm.RW</span></code>);目前,两种操作均会返回 <a class="reference internal" href="../library/constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a> 并且已弃用。 (由 Ethan Furman 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33217">bpo-33217</a> 中贡献。)</p>
</section>
<section id="functools">
<h3>functools<a class="headerlink" href="#functools" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/functools.html#functools.singledispatch" title="functools.singledispatch"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.singledispatch()</span></code></a> 现在支持使用类型标注来注册实现。 (由 Łukasz Langa 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32227">bpo-32227</a> 中贡献。)</p>
</section>
<section id="gc">
<h3>gc<a class="headerlink" href="#gc" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/gc.html#gc.freeze" title="gc.freeze"><code class="xref py py-func docutils literal notranslate"><span class="pre">gc.freeze()</span></code></a> 函数允许冻结由垃圾回收器所跟踪的所有对象,并将它们从未来的集合中排除。 这可以在 POSIX <code class="docutils literal notranslate"><span class="pre">fork()</span></code> 调用之前使用以令 GC 友好地进行写入时复制或加速收集。 新的 <a class="reference internal" href="../library/gc.html#gc.unfreeze" title="gc.unfreeze"><code class="xref py py-func docutils literal notranslate"><span class="pre">gc.unfreeze()</span></code></a> 函数会反转此操作。 此外,<a class="reference internal" href="../library/gc.html#gc.get_freeze_count" title="gc.get_freeze_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">gc.get_freeze_count()</span></code></a> 可被用于获取冻结对象的数量。 (由 Li Zekun 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31558">bpo-31558</a> 中贡献。)</p>
</section>
<section id="hmac">
<h3>hmac<a class="headerlink" href="#hmac" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/hmac.html#module-hmac" title="hmac: Keyed-Hashing for Message Authentication (HMAC) implementation"><code class="xref py py-mod docutils literal notranslate"><span class="pre">hmac</span></code></a> 现在具有经优化的一次性 <a class="reference internal" href="../library/hmac.html#hmac.digest" title="hmac.digest"><code class="xref py py-func docutils literal notranslate"><span class="pre">digest()</span></code></a> 函数,其速度比 <code class="xref py py-func docutils literal notranslate"><span class="pre">HMAC()</span></code> 要快三倍。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32433">bpo-32433</a> 中贡献。)</p>
</section>
<section id="http-client">
<h3>http.client<a class="headerlink" href="#http-client" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/http.client.html#http.client.HTTPConnection" title="http.client.HTTPConnection"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPConnection</span></code></a><a class="reference internal" href="../library/http.client.html#http.client.HTTPSConnection" title="http.client.HTTPSConnection"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPSConnection</span></code></a> 现在支持新的 <em>blocksize</em> 参数以提升上传吞吐量。 (由 Nir Soffer 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31945">bpo-31945</a> 中贡献。)</p>
</section>
<section id="http-server">
<h3>http.server<a class="headerlink" href="#http-server" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/http.server.html#http.server.SimpleHTTPRequestHandler" title="http.server.SimpleHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleHTTPRequestHandler</span></code></a> 现在支持 HTTP <code class="docutils literal notranslate"><span class="pre">If-Modified-Since</span></code> 标头。 如果目标文件在该标点指定的时间之后未被修改则服务器会返回 304 响应状态。 (由 Pierre Quentel 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29654">bpo-29654</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/http.server.html#http.server.SimpleHTTPRequestHandler" title="http.server.SimpleHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleHTTPRequestHandler</span></code></a> 接受新的 <em>directory</em> 参数并增加了新的 <code class="docutils literal notranslate"><span class="pre">--directory</span></code> 命令行参数。 通过此形参,服务器可以对服务指定目录,默认情况下它使用当前工作目录。 (由 Stéphane Wirtel 和 Julien Palard 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28707">bpo-28707</a> 中贡献。)</p>
<p>新的 <a class="reference internal" href="../library/http.server.html#http.server.ThreadingHTTPServer" title="http.server.ThreadingHTTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">ThreadingHTTPServer</span></code></a> 类使用线程来处理使用 <code class="xref py py-class docutils literal notranslate"><span class="pre">ThreadingMixin</span></code> 的请求。 它会在 <code class="docutils literal notranslate"><span class="pre">http.server</span></code> 附带 <code class="docutils literal notranslate"><span class="pre">-m</span></code> 运行时被使用。 (由 Julien Palard 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31639">bpo-31639</a> 中贡献。)</p>
</section>
<section id="idlelib-and-idle">
<h3>idlelib 与 IDLE<a class="headerlink" href="#idlelib-and-idle" title="永久链接至标题"></a></h3>
<p>多个对自动补全的修正。 (由 Louie Lu 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15786">bpo-15786</a> 中贡献。)</p>
<p>Module Browser (在 File 菜单中,之前称为 Class Browser) 现在会在最高层级函数和类之外显示嵌套的函数和类。 (由 Guilherme Polo, Cheryl Sabella 和 Terry Jan Reedy 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1612262">bpo-1612262</a> 中贡献。)</p>
<p>Settings 对话框 (Options 中的 Configure IDLE) 已经被部分重写以改进外观和功能。 (由 Cheryl Sabella 和 Terry Jan Reedy 在多个问题项中贡献。)</p>
<p>字体样本现在包括一组非拉丁字符以便用户能更好地查看所选特定字体的效果。 (由 Terry Jan Reedy 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13802">bpo-13802</a> 中贡献。) 样本可以被修改以包括其他字符。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31860">bpo-31860</a> 中贡献。)</p>
<p>之前以扩展形式实现的 IDLE 特性已作为正常特性重新实现。 它们的设置已从 Extensions 选项卡移至其他对话框选项卡。 (由 Charles Wohlganger 和 Terry Jan Reedy 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27099">bpo-27099</a> 中实现。)</p>
<p>编辑器代码上下文选项已经过修改。 Box 会显示所有上下文行直到最大行数。 点击一个上下文行会使编辑器跳转到该行。 自定义主题的上下文颜色已添加到 Settings 对话框的 Highlights 选项卡。 (由 Cheryl Sabella 和 Terry Jan Reedy 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33642">bpo-33642</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33768">bpo-33768</a><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33679">bpo-33679</a> 中贡献。)</p>
<p>在 Windows 上,会有新的 API 调用将 tk 对 DPI 的调整告知 Windows。 在 Windows 8.1+ 或 10 上,如果 Python 二进制码的 DPI 兼容属性未改变,并且监视器分辨率大于 96 DPI这应该会令文本和线条更清晰。 否则的话它应该不造成影响。 (由 Terry Jan Reedy 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33656">bpo-33656</a> 中贡献。)</p>
<p>在 3.7.1 中新增:</p>
<p>超过 N 行(默认值为 50的输出将被折叠为一个按钮。 N 可以在 Settings 对话框的 General 页的 PyShell 部分中进行修改。 数量较少但是超长的行可以通过在输出上右击来折叠。 被折叠的输出可通过双击按钮来展开,或是通过右击按钮来放入剪贴板或是单独的窗口。 (由 Tal Einat 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1529353">bpo-1529353</a> 中贡献。)</p>
<p>上述修改已被反向移植到 3.6 维护发行版中。</p>
<p>在 3.7.4 中新增:</p>
<p>在 Run 菜单中增加了 &quot;Run Customized&quot; 以使用自定义设置来运行模块。 输入的任何命令行参数都会被加入 sys.argv。 它们在下次自定义运行时会再次显示在窗体中。 用户也可以禁用通常的 Shell 主模块重启。 (由 Cheryl Sabella, Terry Jan Reedy 等人在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5680">bpo-5680</a><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37627">bpo-37627</a> 中贡献。)</p>
<p>在 3.7.5 中新增:</p>
<p>在 IDLE 编辑器窗口中增加了可选的行序号。 窗口打开时默认不带行序号,除非在配置对话框的 General 选项卡中进行设置。 已打开窗口中的行序号可以在 Options 菜单中显示和隐藏。 (由 Tal Einat 和 Saimadhav Heblikar 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17535">bpo-17535</a> 中贡献。)</p>
</section>
<section id="importlib">
<h3>importlib<a class="headerlink" href="#importlib" title="永久链接至标题"></a></h3>
<p>引入了 <a class="reference internal" href="../library/importlib.html#importlib.abc.ResourceReader" title="importlib.abc.ResourceReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.ResourceReader</span></code></a> ABC 以支持从包中加载资源。 另请参阅 <a class="reference internal" href="#whatsnew37-importlib-resources"><span class="std std-ref">importlib.resources</span></a>。 (由 Barry Warsaw, Brett Cannon 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32248">bpo-32248</a> 中贡献。)</p>
<p>如果模块缺少规格描述 <a class="reference internal" href="../library/importlib.html#importlib.reload" title="importlib.reload"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.reload()</span></code></a> 现在会引发 <a class="reference internal" href="../library/exceptions.html#ModuleNotFoundError" title="ModuleNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ModuleNotFoundError</span></code></a>。 (由 Garvit Khatri 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29851">bpo-29851</a> 中贡献。)</p>
<p>如果指定的父模块不是一个包 (即缺少 <code class="docutils literal notranslate"><span class="pre">__path__</span></code> 属性) <code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.find_spec()</span></code> 现在会引发 <a class="reference internal" href="../library/exceptions.html#ModuleNotFoundError" title="ModuleNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ModuleNotFoundError</span></code></a> 而非 <a class="reference internal" href="../library/exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a>。 (由 Milan Oberkirch 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30436">bpo-30436</a> 中贡献。)</p>
<p>新的 <code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.source_hash()</span></code> 可被用来计算传入源的哈希值。 <a class="reference internal" href="#whatsnew37-pep552"><span class="std std-ref">基于哈希值的 .pyc 文件</span></a> 会嵌入此函数所返回的值。</p>
</section>
<section id="io">
<h3>io<a class="headerlink" href="#io" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/io.html#io.TextIOWrapper.reconfigure" title="io.TextIOWrapper.reconfigure"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TextIOWrapper.reconfigure()</span></code></a> 方法可用于根据新的设置重新配置文本流。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30526">bpo-30526</a> 以及 INADA Naoki 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15216">bpo-15216</a> 中贡献。)</p>
</section>
<section id="ipaddress">
<h3>ipaddress<a class="headerlink" href="#ipaddress" title="永久链接至标题"></a></h3>
<p>methods of <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">ipaddress.IPv6Network</span></code></a><a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">ipaddress.IPv4Network</span></code></a> 中新的 <code class="docutils literal notranslate"><span class="pre">subnet_of()</span></code> 以及 <code class="docutils literal notranslate"><span class="pre">supernet_of()</span></code> 方法可用于网络包含测试。 (由 Michel Albert 和 Cheryl Sabella 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20825">bpo-20825</a> 中贡献。)</p>
</section>
<section id="itertools">
<h3>itertools<a class="headerlink" href="#itertools" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/itertools.html#itertools.islice" title="itertools.islice"><code class="xref py py-func docutils literal notranslate"><span class="pre">itertools.islice()</span></code></a> 现在接受 <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">类整数对象</span></code></a> 作为 start, stop 和 slice 参数。 (由 Will Roberts 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30537">bpo-30537</a> 中贡献。)</p>
</section>
<section id="locale">
<h3>locale<a class="headerlink" href="#locale" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/locale.html#locale.format_string" title="locale.format_string"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.format_string()</span></code></a> 中新的 <em>monetary</em> 参数可用于转换所使用的千位分隔符和分组字符串。 (由 Garvit 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10379">bpo-10379</a> 中贡献。)</p>
<p>现在 <a class="reference internal" href="../library/locale.html#locale.getpreferredencoding" title="locale.getpreferredencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getpreferredencoding()</span></code></a> 函数在 Android 上或是在 <a class="reference internal" href="#whatsnew37-pep540"><span class="std std-ref">强制 UTF-8 模式</span></a> 下总是返回 <code class="docutils literal notranslate"><span class="pre">'UTF-8'</span></code></p>
</section>
<section id="logging">
<h3>logging<a class="headerlink" href="#logging" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/logging.html#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> 实例现在可以被 pickle。 (由 Vinay Sajip 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30520">bpo-30520</a> 中贡献。)</p>
<p>新的 <a class="reference internal" href="../library/logging.handlers.html#logging.StreamHandler.setStream" title="logging.StreamHandler.setStream"><code class="xref py py-meth docutils literal notranslate"><span class="pre">StreamHandler.setStream()</span></code></a> 方法可用于在句柄创建之后替换日志流。 (由 Vinay Sajip 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30522">bpo-30522</a> 中创建。)</p>
<p>现在可以在传递给 <a class="reference internal" href="../library/logging.config.html#logging.config.fileConfig" title="logging.config.fileConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">logging.config.fileConfig()</span></code></a> 的配置信息中对句柄构造器指定关键字参数。 (由 Preston Landers 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31080">bpo-31080</a> 中贡献。)</p>
</section>
<section id="math">
<h3>math<a class="headerlink" href="#math" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/math.html#math.remainder" title="math.remainder"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.remainder()</span></code></a> 函数实现了 IEEE 754 风格的余数运算。 (由 Mark Dickinson 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29962">bpo-29962</a> 中贡献。)</p>
</section>
<section id="mimetypes">
<h3>mimetypes<a class="headerlink" href="#mimetypes" title="永久链接至标题"></a></h3>
<p>.bmp 的 MIME type 从 <code class="docutils literal notranslate"><span class="pre">'image/x-ms-bmp'</span></code> 改为 <code class="docutils literal notranslate"><span class="pre">'image/bmp'</span></code>。 (由 Nitish Chandra 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22589">bpo-22589</a> 中贡献。)</p>
</section>
<section id="msilib">
<h3>msilib<a class="headerlink" href="#msilib" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/msilib.html#msilib.Database.Close" title="msilib.Database.Close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Database.Close()</span></code></a> 方法可用于关闭 <abbr title="last-in, first-out">MSI</abbr> 数据库。 (由 Berker Peksag 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20486">bpo-20486</a> 中贡献。)</p>
</section>
<section id="multiprocessing">
<h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.Process.close" title="multiprocessing.Process.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Process.close()</span></code></a> 方法会显式地关闭进程对象并释放与其关联的所有资源。 如果底层进程仍在运行则将引发 <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30596">bpo-30596</a> 中贡献。)</p>
<p>新的 <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.Process.kill" title="multiprocessing.Process.kill"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Process.kill()</span></code></a> 方法可用于在 Unix 上使用 <code class="xref py py-data docutils literal notranslate"><span class="pre">SIGKILL</span></code> 信号来终止进程。 (由 Vitor Pereira 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30794">bpo-30794</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/multiprocessing.html#multiprocessing.Process" title="multiprocessing.Process"><code class="xref py py-class docutils literal notranslate"><span class="pre">Process</span></code></a> 所创建的非守护线程现在会在进程退出时被合并。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18966">bpo-18966</a> 中贡献。)</p>
</section>
<section id="os">
<h3>os<a class="headerlink" href="#os" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/os.html#os.fwalk" title="os.fwalk"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fwalk()</span></code></a> 现在接受 <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> 类型的 <em>path</em> 参数。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28682">bpo-28682</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/os.html#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.scandir()</span></code></a> 已获得对 <a class="reference internal" href="../library/os.html#path-fd"><span class="std std-ref">文件描述器</span></a> 的支持。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25996">bpo-25996</a> 中贡献。)</p>
<p>新的 <a class="reference internal" href="../library/os.html#os.register_at_fork" title="os.register_at_fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">register_at_fork()</span></code></a> 函数允许注册 Python 回调以便在进程分叉中执行。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16500">bpo-16500</a> 中贡献。)</p>
<p>增加了 <a class="reference internal" href="../library/os.html#os.preadv" title="os.preadv"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.preadv()</span></code></a> (结合了 <a class="reference internal" href="../library/os.html#os.readv" title="os.readv"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.readv()</span></code></a><a class="reference internal" href="../library/os.html#os.pread" title="os.pread"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pread()</span></code></a> 的功能) 以及 <a class="reference internal" href="../library/os.html#os.pwritev" title="os.pwritev"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pwritev()</span></code></a> 函数 (结合了 <a class="reference internal" href="../library/os.html#os.writev" title="os.writev"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.writev()</span></code></a><a class="reference internal" href="../library/os.html#os.pwrite" title="os.pwrite"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pwrite()</span></code></a> 的功能)。 (由 Pablo Galindo 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31368">bpo-31368</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/os.html#os.makedirs" title="os.makedirs"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.makedirs()</span></code></a> 的 mode 参数不再影响新创建的中间层级目录的文件权限。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19930">bpo-19930</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/os.html#os.dup2" title="os.dup2"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.dup2()</span></code></a> 现在会返回新的文件描述器。 之前,返回的总是 <code class="docutils literal notranslate"><span class="pre">None</span></code>。 (由 Benjamin Peterson 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32441">bpo-32441</a> 中贡献。)</p>
<p>在 Solaris 及其派生系统上 <a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> 所返回的结构现在会包含 <a class="reference internal" href="../library/os.html#os.stat_result.st_fstype" title="os.stat_result.st_fstype"><code class="xref py py-attr docutils literal notranslate"><span class="pre">st_fstype</span></code></a> 属性。 (由 Jesús Cea Avión 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32659">bpo-32659</a> 中贡献。)</p>
</section>
<section id="pathlib">
<h3>pathlib<a class="headerlink" href="#pathlib" title="永久链接至标题"></a></h3>
<p>在 POSIX 类系统上新的 <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_mount" title="pathlib.Path.is_mount"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.is_mount()</span></code></a> 方法现在可用于确定一个路径是否为挂载点。 (由 Cooper Ry Lees 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30897">bpo-30897</a> 中贡献。)</p>
</section>
<section id="pdb">
<h3>pdb<a class="headerlink" href="#pdb" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/pdb.html#pdb.set_trace" title="pdb.set_trace"><code class="xref py py-func docutils literal notranslate"><span class="pre">pdb.set_trace()</span></code></a> 现在接受一个可选的限关键字参数 <em>header</em>。 如果给出,它会在调试开始之前被打印到控制台。 (由 Barry Warsaw 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31389">bpo-31389</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/pdb.html#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a> 命令行现在接受 <code class="docutils literal notranslate"><span class="pre">-m</span> <span class="pre">module_name</span></code> 作为对脚本文件的替代。 (由 Mario Corchero 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32206">bpo-32206</a> 中贡献。)</p>
</section>
<section id="py-compile">
<h3>py_compile<a class="headerlink" href="#py-compile" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/py_compile.html#py_compile.compile" title="py_compile.compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">py_compile.compile()</span></code></a> -- 及其扩展形式 <a class="reference internal" href="../library/compileall.html#module-compileall" title="compileall: Tools for byte-compiling all Python source files in a directory tree."><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code></a> -- 现在会通过无条件地为基于哈希值的有效性验证创建 <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> 文件来支持 <span class="target" id="index-109"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">SOURCE_DATE_EPOCH</span></code> 环境变量。 这样可以确保当 <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> 文件被主动创建时 <a class="reference external" href="https://reproducible-builds.org/">可重现的生成</a>。 (由 Bernhard M. Wiedemann 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29708">bpo-29708</a> 中贡献。)</p>
</section>
<section id="pydoc">
<h3>pydoc<a class="headerlink" href="#pydoc" title="永久链接至标题"></a></h3>
<p>pydoc 服务器现在可以绑定到由新的 <code class="docutils literal notranslate"><span class="pre">-n</span></code> 命令行参数所指定的任意主机名。 (由 Feanil Patel 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31128">bpo-31128</a> 中贡献。)</p>
</section>
<section id="queue">
<h3>queue<a class="headerlink" href="#queue" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/queue.html#queue.SimpleQueue" title="queue.SimpleQueue"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleQueue</span></code></a> 类是一个无界的 <abbr title="last-in, first-out">FIFO</abbr> 队列。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14976">bpo-14976</a> 中贡献。)</p>
</section>
<section id="re">
<h3>re<a class="headerlink" href="#re" title="永久链接至标题"></a></h3>
<p>旗标 <a class="reference internal" href="../library/re.html#re.ASCII" title="re.ASCII"><code class="xref py py-const docutils literal notranslate"><span class="pre">re.ASCII</span></code></a>, <a class="reference internal" href="../library/re.html#re.LOCALE" title="re.LOCALE"><code class="xref py py-const docutils literal notranslate"><span class="pre">re.LOCALE</span></code></a><code class="xref py py-const docutils literal notranslate"><span class="pre">re.UNICODE</span></code> 可以在组的范围内设置。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31690">bpo-31690</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/re.html#re.split" title="re.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.split()</span></code></a> 现在支持基于匹配一个空字符串的模式例如 <code class="docutils literal notranslate"><span class="pre">r'\b'</span></code>, <code class="docutils literal notranslate"><span class="pre">'^$'</span></code><code class="docutils literal notranslate"><span class="pre">(?=-)</span></code> 进行拆分。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25054">bpo-25054</a> 中贡献。)</p>
<p>使用 <a class="reference internal" href="../library/re.html#re.LOCALE" title="re.LOCALE"><code class="xref py py-const docutils literal notranslate"><span class="pre">re.LOCALE</span></code></a> 旗标编译的正则表达式不再依赖于编译时的区域设置。 区域设置仅在已编译正则表达式被使用时才被应用。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30215">bpo-30215</a> 中贡献。)</p>
<p>现在如果一个正则表达式包含语义将在未来发生改变的字符集构造,则会引发 <a class="reference internal" href="../library/exceptions.html#FutureWarning" title="FutureWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FutureWarning</span></code></a>,例如嵌套集与集合操作等。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30349">bpo-30349</a> 中贡献。)</p>
<p>已编译正则表达式和匹配对象现在可以使用 <a class="reference internal" href="../library/copy.html#copy.copy" title="copy.copy"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy.copy()</span></code></a><a class="reference internal" href="../library/copy.html#copy.deepcopy" title="copy.deepcopy"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy.deepcopy()</span></code></a> 进行拷贝。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10076">bpo-10076</a> 中贡献。)</p>
</section>
<section id="signal">
<h3>signal<a class="headerlink" href="#signal" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/signal.html#signal.set_wakeup_fd" title="signal.set_wakeup_fd"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.set_wakeup_fd()</span></code></a> 函数新增的 <em>warn_on_full_buffer</em> 参数可以指定当唤醒缓冲区溢出时 Python 是否要在 stderr 上打印警告信息。 (由 Nathaniel J. Smith 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30050">bpo-30050</a> 中贡献。)</p>
</section>
<section id="socket">
<h3>socket<a class="headerlink" href="#socket" title="永久链接至标题"></a></h3>
<p>新增的 <a class="reference internal" href="../library/socket.html#socket.socket.getblocking" title="socket.socket.getblocking"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.getblocking()</span></code></a> 方法会在套接字处于阻塞模式时返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>,否则返回 <code class="docutils literal notranslate"><span class="pre">False</span></code>。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32373">bpo-32373</a> 中贡献。)</p>
<p>新的 <a class="reference internal" href="../library/socket.html#socket.close" title="socket.close"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.close()</span></code></a> 函数可关闭所传入的套接字文件描述符。 应该用此函数来代替 <a class="reference internal" href="../library/os.html#os.close" title="os.close"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.close()</span></code></a> 以获得更好的跨平台兼容性。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32454">bpo-32454</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socket</span></code></a> 模块现在会公开 <code class="xref py py-data docutils literal notranslate"><span class="pre">socket.TCP_CONGESTION</span></code> (Linux 2.6.13), <code class="xref py py-data docutils literal notranslate"><span class="pre">socket.TCP_USER_TIMEOUT</span></code> (Linux 2.6.37) 以及 <code class="xref py py-data docutils literal notranslate"><span class="pre">socket.TCP_NOTSENT_LOWAT</span></code> (Linux 3.12) 常量。 (由 Omar Sandoval 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26273">bpo-26273</a> 以及 Nathaniel J. Smith 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29728">bpo-29728</a> 中贡献。)</p>
<p>已加入对 <a class="reference internal" href="../library/socket.html#socket.AF_VSOCK" title="socket.AF_VSOCK"><code class="xref py py-data docutils literal notranslate"><span class="pre">socket.AF_VSOCK</span></code></a> 套接字的支持以允许在虚拟机及其宿主机之间进行通讯。 (由 Cathy Avery 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27584">bpo-27584</a> 中贡献。)</p>
<p>套接字现在默认会根据文件描述符自动检测所属族、类型和协议。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28134">bpo-28134</a> 中贡献。)</p>
</section>
<section id="socketserver">
<h3>socketserver<a class="headerlink" href="#socketserver" title="永久链接至标题"></a></h3>
<p><code class="xref py py-meth docutils literal notranslate"><span class="pre">socketserver.ThreadingMixIn.server_close()</span></code> 现在会等待所有非守护线程完成。 <code class="xref py py-meth docutils literal notranslate"><span class="pre">socketserver.ForkingMixIn.server_close()</span></code> 现在会等待所有子进程完成。</p>
<p><a class="reference internal" href="../library/socketserver.html#socketserver.ForkingMixIn" title="socketserver.ForkingMixIn"><code class="xref py py-class docutils literal notranslate"><span class="pre">socketserver.ForkingMixIn</span></code></a><a class="reference internal" href="../library/socketserver.html#socketserver.ThreadingMixIn" title="socketserver.ThreadingMixIn"><code class="xref py py-class docutils literal notranslate"><span class="pre">socketserver.ThreadingMixIn</span></code></a> 类增加了新的 <code class="xref py py-attr docutils literal notranslate"><span class="pre">socketserver.ForkingMixIn.block_on_close</span></code> 类属性。 该类属性值设为 <code class="docutils literal notranslate"><span class="pre">False</span></code> 以保持 3.7 之前的行为。</p>
</section>
<section id="sqlite3">
<h3>sqlite3<a class="headerlink" href="#sqlite3" title="永久链接至标题"></a></h3>
<p>现在当下层的 SQLite 库版本为 3.6.11 及以上时 <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection" title="sqlite3.Connection"><code class="xref py py-class docutils literal notranslate"><span class="pre">sqlite3.Connection</span></code></a> 会开放 <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.backup" title="sqlite3.Connection.backup"><code class="xref py py-meth docutils literal notranslate"><span class="pre">backup()</span></code></a> 方法。 (由 Lele Gaifax 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27645">bpo-27645</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/sqlite3.html#sqlite3.connect" title="sqlite3.connect"><code class="xref py py-func docutils literal notranslate"><span class="pre">sqlite3.connect()</span></code></a><em>database</em> 参数现在接受任何 <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>,而不是只接受字符串。 (由 Anders Lorentsen 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31843">bpo-31843</a> 中贡献。)</p>
</section>
<section id="ssl">
<h3>ssl<a class="headerlink" href="#ssl" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a> 模块现在使用 OpenSSL 的内置 API 代替 <a class="reference internal" href="../library/ssl.html#ssl.match_hostname" title="ssl.match_hostname"><code class="xref py py-func docutils literal notranslate"><span class="pre">match_hostname()</span></code></a> 来检查主机名或 IP 地址。 值的验证会在 TLS 握手期间进行。 任何证书验证错误包括主机名检查失败现在将引发 <a class="reference internal" href="../library/ssl.html#ssl.SSLCertVerificationError" title="ssl.SSLCertVerificationError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SSLCertVerificationError</span></code></a> 并使用正确的 TLS Alert 消息中止握手过程。 这个新异常包含有额外的信息。 主机名验证可通过 <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.hostname_checks_common_name" title="ssl.SSLContext.hostname_checks_common_name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">SSLContext.hostname_checks_common_name</span></code></a> 进行自定义。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31399">bpo-31399</a> 中贡献。)</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>改进的主机名检测需要有兼容 OpenSSL 1.0.2 或 1.1 的 <em>libssl</em> 实现。 因此OpenSSL 0.9.8 和 1.0.1 不再被支持(请参阅 <a class="reference internal" href="#platform-support-removals"><span class="std std-ref">平台支持的移除</span></a> 了解详情)。 目前 ssl 模块主要兼容 LibreSSL 2.7.2 及更高版本。</p>
</div>
<p><code class="docutils literal notranslate"><span class="pre">ssl</span></code> 模块不再以 SNI TLS 扩展发送 IP 地址。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32185">bpo-32185</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/ssl.html#ssl.match_hostname" title="ssl.match_hostname"><code class="xref py py-func docutils literal notranslate"><span class="pre">match_hostname()</span></code></a> 不再支持部分通配符例如 <code class="docutils literal notranslate"><span class="pre">www*.example.org</span></code>。 (由 Mandeep Singh 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23033">bpo-23033</a> 以及 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31399">bpo-31399</a> 中贡献。)</p>
<p><code class="docutils literal notranslate"><span class="pre">ssl</span></code> 模块默认的加密套件选择现在是使用黑名单方式而非硬编码的白名单。 Python 不会再重新启用已经被 OpenSSL 安全更新所阻止的加密。 默认的加密套件选择可以在编译时进行配置。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31429">bpo-31429</a> 中贡献。)</p>
<p>现在已支持包含国际化域名 (IDN) 的服务器证书验证。 作为此更改的一部分,<a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.server_hostname" title="ssl.SSLSocket.server_hostname"><code class="xref py py-attr docutils literal notranslate"><span class="pre">SSLSocket.server_hostname</span></code></a> 属性现在会以预期的 A 标签形式 (<code class="docutils literal notranslate"><span class="pre">&quot;xn--pythn-mua.org&quot;</span></code>) 而不是以 U 标签形式 (<code class="docutils literal notranslate"><span class="pre">&quot;pythön.org&quot;</span></code>) 存储。 (由 Nathaniel J. Smith 与 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28414">bpo-28414</a> 中贡献。)</p>
<p><code class="docutils literal notranslate"><span class="pre">ssl</span></code> 模块对 TLS 1.3 和 OpenSSL 1.1.1 具有初步和实验性的支持。 在 Python 3.7.0 发布的时刻OpenSSL 1.1.1 仍在开发中,而 TLS 1.3 尚未最终确定。 TLS 1.3 握手和协议行为与 TLS 1.2 及更早的版本略有差异,请参阅 <a class="reference internal" href="../library/ssl.html#ssl-tlsv1-3"><span class="std std-ref">TLS 1.3</span></a>。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32947">bpo-32947</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20995">bpo-20995</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29136">bpo-29136</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30622">bpo-30622</a> 以及 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33618">bpo-33618</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/ssl.html#ssl.SSLSocket" title="ssl.SSLSocket"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLSocket</span></code></a><a class="reference internal" href="../library/ssl.html#ssl.SSLObject" title="ssl.SSLObject"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLObject</span></code></a> 不再具有公共构造器。 直接实例化从未成为有文档和受支持的特性。 实际必须通过 <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLContext</span></code></a> 的方法 <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.wrap_socket" title="ssl.SSLContext.wrap_socket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">wrap_socket()</span></code></a><a class="reference internal" href="../library/ssl.html#ssl.SSLContext.wrap_bio" title="ssl.SSLContext.wrap_bio"><code class="xref py py-meth docutils literal notranslate"><span class="pre">wrap_bio()</span></code></a> 来创建。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32951">bpo-32951</a> 中贡献。)</p>
<p>用于设置最小和最大 TLS 协议版本的 OpenSSL 1.1 API 现已可用,名称分别为 <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.minimum_version" title="ssl.SSLContext.minimum_version"><code class="xref py py-attr docutils literal notranslate"><span class="pre">SSLContext.minimum_version</span></code></a><a class="reference internal" href="../library/ssl.html#ssl.SSLContext.maximum_version" title="ssl.SSLContext.maximum_version"><code class="xref py py-attr docutils literal notranslate"><span class="pre">SSLContext.maximum_version</span></code></a>。 受支持的协议由几个新增旗标指定,例如 <a class="reference internal" href="../library/ssl.html#ssl.HAS_TLSv1_1" title="ssl.HAS_TLSv1_1"><code class="xref py py-data docutils literal notranslate"><span class="pre">HAS_TLSv1_1</span></code></a>。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32609">bpo-32609</a> 中贡献。)</p>
</section>
<section id="string">
<h3>string<a class="headerlink" href="#string" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/string.html#string.Template" title="string.Template"><code class="xref py py-class docutils literal notranslate"><span class="pre">string.Template</span></code></a> 现在允许你有选择地分别修改带大括号的占位符和不带大括号的占位符所对应的正则表达式模式。 (由 Barry Warsaw 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1198569">bpo-1198569</a> 中贡献。)</p>
</section>
<section id="subprocess">
<h3>subprocess<a class="headerlink" href="#subprocess" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/subprocess.html#subprocess.run" title="subprocess.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">subprocess.run()</span></code></a> 函数接受新的 <em>capture_output</em> 关键字参数。 当其为真值时,将会捕获 stdout 和 stderr。 这相当于将 <a class="reference internal" href="../library/subprocess.html#subprocess.PIPE" title="subprocess.PIPE"><code class="xref py py-data docutils literal notranslate"><span class="pre">subprocess.PIPE</span></code></a> 作为 <em>stdout</em><em>stderr</em> 参数传入。 (由 Bo Bayles 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32102">bpo-32102</a> 中贡献。)</p>
<p><code class="docutils literal notranslate"><span class="pre">subprocess.run</span></code> 函数和 <a class="reference internal" href="../library/subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a> 构造器现在接受 <em>text</em> 关键字参数作为 <em>universal_newlines</em> 的别名。 (由 Andrew Clegg 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31756">bpo-31756</a> 中贡献。)</p>
<p>在 Windows 中当重定向标准句柄时 <em>close_fds</em> 的默认值由 <code class="docutils literal notranslate"><span class="pre">False</span></code> 改为 <code class="docutils literal notranslate"><span class="pre">True</span></code>。 现在可以在重定向标准句柄时将 <em>close_fds</em> 设为真值。 参阅 <a class="reference internal" href="../library/subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a>。 这意味着现在 <em>close_fds</em> 在所有受支持的平台上默认值均为 <code class="docutils literal notranslate"><span class="pre">True</span></code>。 (由 Segev Finer 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19764">bpo-19764</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/subprocess.html#subprocess.call" title="subprocess.call"><code class="xref py py-func docutils literal notranslate"><span class="pre">subprocess.call()</span></code></a>, <a class="reference internal" href="../library/subprocess.html#subprocess.run" title="subprocess.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">subprocess.run()</span></code></a> 期间或在 <a class="reference internal" href="../library/subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">Popen</span></code></a> 上下文管理器中subprocess 模块现在能更优雅地处理 <a class="reference internal" href="../library/exceptions.html#KeyboardInterrupt" title="KeyboardInterrupt"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyboardInterrupt</span></code></a>。 它现在会等待一小段时间以便子进程退出,然后再继续处理 <code class="docutils literal notranslate"><span class="pre">KeyboardInterrupt</span></code> 异常。 (由 Gregory P. Smith 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25942">bpo-25942</a> 中贡献。)</p>
</section>
<section id="sys">
<h3>sys<a class="headerlink" href="#sys" title="永久链接至标题"></a></h3>
<p>新增 <a class="reference internal" href="../library/sys.html#sys.breakpointhook" title="sys.breakpointhook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.breakpointhook()</span></code></a> 钩子函数,供内置的 <a class="reference internal" href="../library/functions.html#breakpoint" title="breakpoint"><code class="xref py py-func docutils literal notranslate"><span class="pre">breakpoint()</span></code></a> 进行调用。 (由 Barry Warsaw 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31353">bpo-31353</a> 中贡献。)</p>
<p>在 Android 中新增的 <a class="reference internal" href="../library/sys.html#sys.getandroidapilevel" title="sys.getandroidapilevel"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getandroidapilevel()</span></code></a> 会返回构建时的 Android API 版本。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28740">bpo-28740</a> 中贡献。)</p>
<p>新的 <a class="reference internal" href="../library/sys.html#sys.get_coroutine_origin_tracking_depth" title="sys.get_coroutine_origin_tracking_depth"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.get_coroutine_origin_tracking_depth()</span></code></a> 函数会返回当前协程的由新的 <a class="reference internal" href="../library/sys.html#sys.set_coroutine_origin_tracking_depth" title="sys.set_coroutine_origin_tracking_depth"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.set_coroutine_origin_tracking_depth()</span></code></a> 所设定的原始跟踪深度。 <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> 已转换为使用这个新 API 代替已弃用的 <code class="xref py py-func docutils literal notranslate"><span class="pre">sys.set_coroutine_wrapper()</span></code>。 (由 Nathaniel J. Smith 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32591">bpo-32591</a> 中贡献。)</p>
</section>
<section id="time">
<h3>time<a class="headerlink" href="#time" title="永久链接至标题"></a></h3>
<p><span class="target" id="index-110"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0564"><strong>PEP 564</strong></a><a class="reference internal" href="../library/time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> 模块增加六个具有纳秒级精度的新函数:</p>
<ul class="simple">
<li><p><a class="reference internal" href="../library/time.html#time.clock_gettime_ns" title="time.clock_gettime_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.clock_gettime_ns()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/time.html#time.clock_settime_ns" title="time.clock_settime_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.clock_settime_ns()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/time.html#time.monotonic_ns" title="time.monotonic_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.monotonic_ns()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/time.html#time.perf_counter_ns" title="time.perf_counter_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.perf_counter_ns()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/time.html#time.process_time_ns" title="time.process_time_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.process_time_ns()</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/time.html#time.time_ns" title="time.time_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.time_ns()</span></code></a></p></li>
</ul>
<p>增加了新的时钟标识符:</p>
<ul class="simple">
<li><p><a class="reference internal" href="../library/time.html#time.CLOCK_BOOTTIME" title="time.CLOCK_BOOTTIME"><code class="xref py py-data docutils literal notranslate"><span class="pre">time.CLOCK_BOOTTIME</span></code></a> (Linux): 与 <a class="reference internal" href="../library/time.html#time.CLOCK_MONOTONIC" title="time.CLOCK_MONOTONIC"><code class="xref py py-data docutils literal notranslate"><span class="pre">time.CLOCK_MONOTONIC</span></code></a> 相似,不同点在于它还包括任何系统挂起的时间。</p></li>
<li><p><a class="reference internal" href="../library/time.html#time.CLOCK_PROF" title="time.CLOCK_PROF"><code class="xref py py-data docutils literal notranslate"><span class="pre">time.CLOCK_PROF</span></code></a> (FreeBSD, NetBSD 和 OpenBSD): 高精度的分进程 CPU 计时器。</p></li>
<li><p><a class="reference internal" href="../library/time.html#time.CLOCK_UPTIME" title="time.CLOCK_UPTIME"><code class="xref py py-data docutils literal notranslate"><span class="pre">time.CLOCK_UPTIME</span></code></a> (FreeBSD, OpenBSD): 该时间的绝对值是系统运行且未挂起的时间,提供准确的正常运行时间度量。</p></li>
</ul>
<p>新的 <a class="reference internal" href="../library/time.html#time.thread_time" title="time.thread_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.thread_time()</span></code></a><a class="reference internal" href="../library/time.html#time.thread_time_ns" title="time.thread_time_ns"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.thread_time_ns()</span></code></a> 函数可用于获取每线程的 CPU 时间度量。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32025">bpo-32025</a> 中贡献。)</p>
<p>新的 <a class="reference internal" href="../library/time.html#time.pthread_getcpuclockid" title="time.pthread_getcpuclockid"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.pthread_getcpuclockid()</span></code></a> 函数会返回特定线程中 CPU 时钟的时钟 ID。</p>
</section>
<section id="tkinter">
<h3>tkinter<a class="headerlink" href="#tkinter" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/tkinter.ttk.html#tkinter.ttk.Spinbox" title="tkinter.ttk.Spinbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.ttk.Spinbox</span></code></a> 类现已可用。 (由 Alan Moore 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32585">bpo-32585</a> 中贡献。)</p>
</section>
<section id="tracemalloc">
<h3>tracemalloc<a class="headerlink" href="#tracemalloc" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/tracemalloc.html#tracemalloc.Traceback" title="tracemalloc.Traceback"><code class="xref py py-class docutils literal notranslate"><span class="pre">tracemalloc.Traceback</span></code></a> 的行为更接近正规的回溯,会对所有帧按从最旧到最新来排序。 <a class="reference internal" href="../library/tracemalloc.html#tracemalloc.Traceback.format" title="tracemalloc.Traceback.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Traceback.format()</span></code></a> 现在接受负的 <em>limit</em>,并会将结果截短至排在第 <code class="docutils literal notranslate"><span class="pre">abs(limit)</span></code> 位的旧帧。 如果要获得旧的行为,请在 <code class="docutils literal notranslate"><span class="pre">Traceback.format()</span></code> 中使用新的 <em>most_recent_first</em> 参数。 (由 Jesse Bakker 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32121">bpo-32121</a> 中贡献。)</p>
</section>
<section id="types">
<h3>types<a class="headerlink" href="#types" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/types.html#types.WrapperDescriptorType" title="types.WrapperDescriptorType"><code class="xref py py-class docutils literal notranslate"><span class="pre">WrapperDescriptorType</span></code></a>, <a class="reference internal" href="../library/types.html#types.MethodWrapperType" title="types.MethodWrapperType"><code class="xref py py-class docutils literal notranslate"><span class="pre">MethodWrapperType</span></code></a>, <a class="reference internal" href="../library/types.html#types.MethodDescriptorType" title="types.MethodDescriptorType"><code class="xref py py-class docutils literal notranslate"><span class="pre">MethodDescriptorType</span></code></a><a class="reference internal" href="../library/types.html#types.ClassMethodDescriptorType" title="types.ClassMethodDescriptorType"><code class="xref py py-class docutils literal notranslate"><span class="pre">ClassMethodDescriptorType</span></code></a> 类现已可用。 (由 Manuel Krebber 和 Guido van Rossum 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29377">bpo-29377</a> 以及 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32265">bpo-32265</a> 中贡献。)</p>
<p>新的 <a class="reference internal" href="../library/types.html#types.resolve_bases" title="types.resolve_bases"><code class="xref py py-func docutils literal notranslate"><span class="pre">types.resolve_bases()</span></code></a> 函数会以 <span class="target" id="index-111"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0560"><strong>PEP 560</strong></a> 所规定的方式动态解析 MRO 条目。 (由 Ivan Levkivskyi 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32717">bpo-32717</a> 中贡献。)</p>
</section>
<section id="unicodedata">
<h3>unicodedata<a class="headerlink" href="#unicodedata" title="永久链接至标题"></a></h3>
<p>内部的 <a class="reference internal" href="../library/unicodedata.html#module-unicodedata" title="unicodedata: Access the Unicode Database."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unicodedata</span></code></a> 数据库已升级为使用 <a class="reference external" href="http://www.unicode.org/versions/Unicode11.0.0/">Unicode 11</a>。 (由 Benjamin Peterson 贡献。)</p>
</section>
<section id="unittest">
<h3>unittest<a class="headerlink" href="#unittest" title="永久链接至标题"></a></h3>
<p>新的 <code class="docutils literal notranslate"><span class="pre">-k</span></code> 命令行选项允许通过名称子字符串或类似于 Unix shell 的模式来筛选测试项。 例如,<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">unittest</span> <span class="pre">-k</span> <span class="pre">foo</span></code> 将运行 <code class="docutils literal notranslate"><span class="pre">foo_tests.SomeTest.test_something</span></code>, <code class="docutils literal notranslate"><span class="pre">bar_tests.SomeTest.test_foo</span></code>,但不会运行 <code class="docutils literal notranslate"><span class="pre">bar_tests.FooTest.test_something</span></code>。 (由 Jonas Haag 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32071">bpo-32071</a> 中贡献。)</p>
</section>
<section id="unittest-mock">
<h3>unittest.mock<a class="headerlink" href="#unittest-mock" title="永久链接至标题"></a></h3>
<p>现在 <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.sentinel" title="unittest.mock.sentinel"><code class="xref py py-const docutils literal notranslate"><span class="pre">sentinel</span></code></a> 属性会在它们被 <a class="reference internal" href="../library/copy.html#module-copy" title="copy: Shallow and deep copy operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">复制</span></code></a><a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">封存</span></code></a> 时保存其标识。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20804">bpo-20804</a> 中贡献。)</p>
<p>新的 <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.seal" title="unittest.mock.seal"><code class="xref py py-func docutils literal notranslate"><span class="pre">seal()</span></code></a> 函数允许 <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.Mock" title="unittest.mock.Mock"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mock</span></code></a> 对实例进行密封,这将禁止进一步创建属性模拟。 密封会以递归方式应用于自身模拟的所有属性。 (由 Mario Corchero 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30541">bpo-30541</a> 中贡献。)</p>
</section>
<section id="urllib-parse">
<h3>urllib.parse<a class="headerlink" href="#urllib-parse" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/urllib.parse.html#urllib.parse.quote" title="urllib.parse.quote"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.quote()</span></code></a> 已经从 <span class="target" id="index-112"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2396.html"><strong>RFC 2396</strong></a> 更新为 <span class="target" id="index-113"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc3986.html"><strong>RFC 3986</strong></a>,将 <code class="docutils literal notranslate"><span class="pre">~</span></code> 添加到默认情况下从未引用的字符集。 (由 Christian Theune 和 Ratnadeep Debnath 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16285">bpo-16285</a> 中贡献。)</p>
</section>
<section id="uu">
<h3>uu<a class="headerlink" href="#uu" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/uu.html#uu.encode" title="uu.encode"><code class="xref py py-func docutils literal notranslate"><span class="pre">uu.encode()</span></code></a> 函数现在接受可选的 <em>backtick</em> 关键字参数。 当其为真时,零会以 <code class="docutils literal notranslate"><span class="pre">'`'</span></code> 而非空格来表示。 (由 Xiang Zhang 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30103">bpo-30103</a> 中贡献。)</p>
</section>
<section id="uuid">
<h3>uuid<a class="headerlink" href="#uuid" title="永久链接至标题"></a></h3>
<p>新的 <a class="reference internal" href="../library/uuid.html#uuid.UUID.is_safe" title="uuid.UUID.is_safe"><code class="xref py py-attr docutils literal notranslate"><span class="pre">UUID.is_safe</span></code></a> 属性会从平台中继有关是否使用多进程安全模式来生成所需 UUID 的信息。 (由 Barry Warsaw 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22807">bpo-22807</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/uuid.html#uuid.getnode" title="uuid.getnode"><code class="xref py py-func docutils literal notranslate"><span class="pre">uuid.getnode()</span></code></a> 现在更倾向于统一管理的 MAC 地址而不是本地管理的 MAC 地址。 这样可以更好地保证从 <a class="reference internal" href="../library/uuid.html#uuid.uuid1" title="uuid.uuid1"><code class="xref py py-func docutils literal notranslate"><span class="pre">uuid.uuid1()</span></code></a> 返回的 UUID 的全局唯一性。 如果只有本地管理的 MAC 地址可用,则返回首个找到的此类地址。 (由 Barry Warsaw 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32107">bpo-32107</a> 中贡献。)</p>
</section>
<section id="warnings">
<h3>warnings<a class="headerlink" href="#warnings" title="永久链接至标题"></a></h3>
<p>默认警告过滤器的初始化已进行以下更改:</p>
<ul>
<li><p>通过命令行选项(包括 <a class="reference internal" href="../using/cmdline.html#cmdoption-b"><code class="xref std std-option docutils literal notranslate"><span class="pre">-b</span></code></a> 以及新的 CPython 专属的 <a class="reference internal" href="../using/cmdline.html#id5"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> <code class="docutils literal notranslate"><span class="pre">dev</span></code> 选项)启用的警告总是会通过 <a class="reference internal" href="../library/sys.html#sys.warnoptions" title="sys.warnoptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.warnoptions</span></code></a> 属性被传递给警告机制。</p></li>
<li><p>通过命令行或环境变量启用的警告过滤器现在具有以下优先顺序:</p>
<blockquote>
<div><ul class="simple">
<li><p>用于 <a class="reference internal" href="../using/cmdline.html#cmdoption-b"><code class="xref std std-option docutils literal notranslate"><span class="pre">-b</span></code></a> (或 <code class="docutils literal notranslate"><span class="pre">-bb</span></code>) 的 <code class="docutils literal notranslate"><span class="pre">BytesWarning</span></code> 过滤器</p></li>
<li><p>通过 <a class="reference internal" href="../using/cmdline.html#cmdoption-w"><code class="xref std std-option docutils literal notranslate"><span class="pre">-W</span></code></a> 选项指定的任何过滤器</p></li>
<li><p>通过 <span class="target" id="index-114"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONWARNINGS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONWARNINGS</span></code></a> 环境变量指定的任何过滤器</p></li>
<li><p>任何其他 CPython 专属过滤器(例如 <code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">dev</span></code> 模式中新增的 <code class="docutils literal notranslate"><span class="pre">default</span></code> 过滤器)</p></li>
<li><p>由警告机制所定义的任何隐式过滤器</p></li>
</ul>
</div></blockquote>
</li>
<li><p>在 CPython 调试版本中,现在默认情况下会显示所有警告(隐式过滤器列表为空)</p></li>
</ul>
<p>(由 Nick Coghlan 和 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20361">bpo-20361</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32043">bpo-32043</a> 以及 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32230">bpo-32230</a> 中贡献。)</p>
<p>在单文件脚本和交互式提示符中,默认情况下会再次显示已弃用警告。 详情参见 <a class="reference internal" href="#whatsnew37-pep565"><span class="std std-ref">PEP 565: 在 __main__ 中显示 DeprecationWarning</span></a>。 (由 Nick Coghlan 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31975">bpo-31975</a> 中贡献。)</p>
</section>
<section id="xml-etree">
<h3>xml.etree<a class="headerlink" href="#xml-etree" title="永久链接至标题"></a></h3>
<p><code class="xref py py-meth docutils literal notranslate"><span class="pre">find()</span></code> 方法中的 <a class="reference internal" href="../library/xml.etree.elementtree.html#elementtree-xpath"><span class="std std-ref">ElementPath</span></a> 描述词现在可以将当前节点文本与 <code class="docutils literal notranslate"><span class="pre">[.</span> <span class="pre">=</span> <span class="pre">&quot;text&quot;]</span></code> 进行比较,而不仅是子节点中的文本。 描述词还允许添加空格以提高可读性。 (由 Stefan Behnel 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31648">bpo-31648</a> 中贡献。)</p>
</section>
<section id="xmlrpc-server">
<h3>xmlrpc.server<a class="headerlink" href="#xmlrpc-server" title="永久链接至标题"></a></h3>
<p><code class="xref py py-meth docutils literal notranslate"><span class="pre">SimpleXMLRPCDispatcher.register_function</span></code> 现在可以被用作装饰器。 (由 Xiang Zhang 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=7769">bpo-7769</a> 中贡献。)</p>
</section>
<section id="zipapp">
<h3>zipapp<a class="headerlink" href="#zipapp" title="永久链接至标题"></a></h3>
<p>函数 <a class="reference internal" href="../library/zipapp.html#zipapp.create_archive" title="zipapp.create_archive"><code class="xref py py-func docutils literal notranslate"><span class="pre">create_archive()</span></code></a> 现在接受可选的 <em>filter</em> 参数,以允许用户选择哪些文件应被加入归档包。 (由 Irmen de Jong 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31072">bpo-31072</a> 中贡献。)</p>
<p>函数 <a class="reference internal" href="../library/zipapp.html#zipapp.create_archive" title="zipapp.create_archive"><code class="xref py py-func docutils literal notranslate"><span class="pre">create_archive()</span></code></a> 现在接受可选的 <em>compressed</em> 参数,以生成压缩归档包。 另外也加入了命令行选项 <code class="docutils literal notranslate"><span class="pre">--compress</span></code> 以支持压缩。 (由 Zhiming Wang 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31638">bpo-31638</a> 中贡献。)</p>
</section>
<section id="zipfile">
<h3>zipfile<a class="headerlink" href="#zipfile" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile" title="zipfile.ZipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">ZipFile</span></code></a> 现在接受新的 <em>compresslevel</em> 形参,以控制压缩级别。 (由 Bo Bayles 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21417">bpo-21417</a> 中贡献。)</p>
<p><code class="docutils literal notranslate"><span class="pre">ZipFile</span></code> 所创建的归档包中的子目录现在会按字母表顺序保存。 (由 Bernhard M. Wiedemann 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30693">bpo-30693</a> 中贡献。)</p>
</section>
</section>
<section id="c-api-changes">
<h2>C API 的改变<a class="headerlink" href="#c-api-changes" title="永久链接至标题"></a></h2>
<p>已实现了用于线程本地存储的新 API。 相关概述请参阅 <a class="reference internal" href="#whatsnew37-pep539"><span class="std std-ref">PEP 539: 用于线程局部存储的新 C API</span></a>,完整参考文档请查看 <a class="reference internal" href="../c-api/init.html#thread-specific-storage-api"><span class="std std-ref">线程专属存储 (TSS) API</span></a>。 (由 Masayuki Yamamoto 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25658">bpo-25658</a> 中贡献。)</p>
<p>新的 <a class="reference internal" href="#whatsnew37-pep567"><span class="std std-ref">上下文变量</span></a> 功能开放了许多 <a class="reference internal" href="../c-api/contextvars.html#contextvarsobjects"><span class="std std-ref">新的 C API</span></a></p>
<p>新的 <a class="reference internal" href="../c-api/import.html#c.PyImport_GetModule" title="PyImport_GetModule"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_GetModule()</span></code></a> 函数会返回之前所导入的具有给定名称的模块。 (由 Eric Snow 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28411">bpo-28411</a> 中贡献。)</p>
<p>新的 <a class="reference internal" href="../c-api/typeobj.html#c.Py_RETURN_RICHCOMPARE" title="Py_RETURN_RICHCOMPARE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_RETURN_RICHCOMPARE</span></code></a> 宏可以简化丰富比较函数的编写。 (由 Petr Victorin 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23699">bpo-23699</a> 中贡献。)</p>
<p>新的 <a class="reference internal" href="../c-api/intro.html#c.Py_UNREACHABLE" title="Py_UNREACHABLE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNREACHABLE</span></code></a> 宏可用于标记不可到达的代码路径。 (由 Barry Warsaw 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31338">bpo-31338</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a> 现在通过新的 <a class="reference internal" href="../c-api/memory.html#c.PyTraceMalloc_Track" title="PyTraceMalloc_Track"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTraceMalloc_Track()</span></code></a><a class="reference internal" href="../c-api/memory.html#c.PyTraceMalloc_Untrack" title="PyTraceMalloc_Untrack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTraceMalloc_Untrack()</span></code></a> 函数公开了一个 C API。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30054">bpo-30054</a> 中贡献。)</p>
<p>新的 <code class="xref c c-func docutils literal notranslate"><span class="pre">import__find__load__start()</span></code><code class="xref c c-func docutils literal notranslate"><span class="pre">import__find__load__done()</span></code> 静态标记可用于跟踪模块导入。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31574">bpo-31574</a> 中贡献。)</p>
<p>结构体 <a class="reference internal" href="../c-api/structures.html#c.PyMemberDef" title="PyMemberDef"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyMemberDef</span></code></a>, <a class="reference internal" href="../c-api/structures.html#c.PyGetSetDef" title="PyGetSetDef"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyGetSetDef</span></code></a>, <a class="reference internal" href="../c-api/tuple.html#c.PyStructSequence_Field" title="PyStructSequence_Field"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyStructSequence_Field</span></code></a>, <a class="reference internal" href="../c-api/tuple.html#c.PyStructSequence_Desc" title="PyStructSequence_Desc"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyStructSequence_Desc</span></code></a><code class="xref c c-type docutils literal notranslate"><span class="pre">wrapperbase</span></code> 的字段 <code class="xref c c-member docutils literal notranslate"><span class="pre">name</span></code><code class="xref c c-member docutils literal notranslate"><span class="pre">doc</span></code> 现在的类型为 <code class="docutils literal notranslate"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></code> 而不是 <code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*</span></code>。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28761">bpo-28761</a> 中贡献。)</p>
<p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUTF8AndSize" title="PyUnicode_AsUTF8AndSize"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUTF8AndSize()</span></code></a><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUTF8" title="PyUnicode_AsUTF8"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUTF8()</span></code></a> 的结果类型现在是 <code class="docutils literal notranslate"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></code> 而非 <code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*</span></code>。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28769">bpo-28769</a> 中贡献。)</p>
<p><a class="reference internal" href="../c-api/mapping.html#c.PyMapping_Keys" title="PyMapping_Keys"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMapping_Keys()</span></code></a>, <a class="reference internal" href="../c-api/mapping.html#c.PyMapping_Values" title="PyMapping_Values"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMapping_Values()</span></code></a><a class="reference internal" href="../c-api/mapping.html#c.PyMapping_Items" title="PyMapping_Items"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMapping_Items()</span></code></a> 的结果现在肯定是列表,而非可能是列表也可能是元组。 (由 Oren Milman 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28280">bpo-28280</a> 中贡献。)</p>
<p>添加了函数 <a class="reference internal" href="../c-api/slice.html#c.PySlice_Unpack" title="PySlice_Unpack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_Unpack()</span></code></a><a class="reference internal" href="../c-api/slice.html#c.PySlice_AdjustIndices" title="PySlice_AdjustIndices"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_AdjustIndices()</span></code></a>。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27867">bpo-27867</a> 中贡献。)</p>
<p><a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork" title="PyOS_AfterFork"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork()</span></code></a> 已弃用,建议改用新的 functions <a class="reference internal" href="../c-api/sys.html#c.PyOS_BeforeFork" title="PyOS_BeforeFork"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_BeforeFork()</span></code></a>, <a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork_Parent" title="PyOS_AfterFork_Parent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Parent()</span></code></a><a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork_Child" title="PyOS_AfterFork_Child"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Child()</span></code></a>。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16500">bpo-16500</a> 中贡献。)</p>
<p>曾经作为公共 API 一部分的 <code class="docutils literal notranslate"><span class="pre">PyExc_RecursionErrorInst</span></code> 单例已被移除,因为它的成员永远不会被清理,可能在解释器的最终化过程中导致段错误。 由 Xavier de Gaye 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22898">bpo-22898</a><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30697">bpo-30697</a> 中贡献。</p>
<p>添加 C API 对使用 timezone 的构造器 <a class="reference internal" href="../c-api/datetime.html#c.PyTimeZone_FromOffset" title="PyTimeZone_FromOffset"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTimeZone_FromOffset()</span></code></a><a class="reference internal" href="../c-api/datetime.html#c.PyTimeZone_FromOffsetAndName" title="PyTimeZone_FromOffsetAndName"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTimeZone_FromOffsetAndName()</span></code></a> 的时区的支持,以及通常 <a class="reference internal" href="../c-api/datetime.html#c.PyDateTime_TimeZone_UTC" title="PyDateTime_TimeZone_UTC"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyDateTime_TimeZone_UTC</span></code></a> 使用 UTC 单例。 由 Paul Ganssle 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10381">bpo-10381</a> 中贡献。</p>
<p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_start_new_thread()</span></code><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_get_thread_ident()</span></code> 的结果类型以及 <a class="reference internal" href="../c-api/init.html#c.PyThreadState_SetAsyncExc" title="PyThreadState_SetAsyncExc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_SetAsyncExc()</span></code></a><em>id</em> 参数类型由 <code class="xref c c-type docutils literal notranslate"><span class="pre">long</span></code> 改为 <code class="xref c c-type docutils literal notranslate"><span class="pre">unsigned</span> <span class="pre">long</span></code>。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6532">bpo-6532</a> 中贡献。)</p>
<p>现在 <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsWideCharString" title="PyUnicode_AsWideCharString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsWideCharString()</span></code></a> 如果第二个参数为 <code class="docutils literal notranslate"><span class="pre">NULL</span></code> 并且 <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t*</span></code> 字符串包含空字符则会引发 <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30708">bpo-30708</a> 中贡献。)</p>
<p>对启动顺序以及动态内存分配器管理的更改意味着早已记录在案的,对在调用大多数 C API 函数之前调用 <a class="reference internal" href="../c-api/init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code></a> 的要求的依赖现在变得更加强烈,未遵循此要求可能导致嵌入式应用程序中的段错误。 请参阅此文档的 <a class="reference internal" href="#porting-to-python-37"><span class="std std-ref">移植到 Python 3.7</span></a> 一节以及 C API 文档的 <a class="reference internal" href="../c-api/init.html#pre-init-safe"><span class="std std-ref">在Python初始化之前</span></a> 一节了解更多细节。</p>
<p>新的 <a class="reference internal" href="../c-api/init.html#c.PyInterpreterState_GetID" title="PyInterpreterState_GetID"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyInterpreterState_GetID()</span></code></a> 会返回给定解释器的唯一 ID。 (由 Eric Snow 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29102">bpo-29102</a> 中贡献。)</p>
<p>现在当启用 <a class="reference internal" href="#whatsnew37-pep540"><span class="std std-ref">UTF-8 模式</span></a><a class="reference internal" href="../c-api/sys.html#c.Py_DecodeLocale" title="Py_DecodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DecodeLocale()</span></code></a>, <a class="reference internal" href="../c-api/sys.html#c.Py_EncodeLocale" title="Py_EncodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_EncodeLocale()</span></code></a> 会使用 UTF-8 编码。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29240">bpo-29240</a> 中贡献。)</p>
<p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_DecodeLocaleAndSize" title="PyUnicode_DecodeLocaleAndSize"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_DecodeLocaleAndSize()</span></code></a><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EncodeLocale" title="PyUnicode_EncodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeLocale()</span></code></a> 现在会为 <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code> 错误句柄使用当前区域编码。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29240">bpo-29240</a> 中贡献。)</p>
<p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FindChar" title="PyUnicode_FindChar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FindChar()</span></code></a><em>start</em><em>end</em> 形参的行为现在调整为与字符串切片类似。 (由 Xiang Zhang 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28822">bpo-28822</a> 中贡献。)</p>
</section>
<section id="build-changes">
<h2>构建的改变<a class="headerlink" href="#build-changes" title="永久链接至标题"></a></h2>
<p>对于 <code class="docutils literal notranslate"><span class="pre">--without-threads</span></code> 构建的支持已被移除。 <a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a> 模块现在将总是可用。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31370">bpo-31370</a> 中贡献。)</p>
<p>在非 OSX UNIX 平台上已不再包含用于构建 <a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">_ctypes</span></code></a> 模块的完整 libffi 副本。 现在当在此类平台上构建 <code class="docutils literal notranslate"><span class="pre">_ctypes</span></code> 时需要事先装有 libffi 的副本。 (由 Zachary Ware 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27979">bpo-27979</a> 中贡献。)</p>
<p>Windows 构建过程不再依赖 Subversion 来拉取外部源码,而是改用一段 Python 脚本从 GitHub 下载 zip 文件。 如果未在系统中找到 Python 3.6 (通过 <code class="docutils literal notranslate"><span class="pre">py</span> <span class="pre">-3.6</span></code>),则会使用 NuGet 下载一份 32 位的 Python 副本用于此目的。 (由 Zachary Ware 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30450">bpo-30450</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a> 模块需要兼容 OpenSSL 1.0.2 或 1.1 的 libssl。 OpenSSL 1.0.1 的生命期已于 2016-12-31 终止且不再受支持。 LibreSSL 暂时也不受支持。 LibreSSL 发布版直到 2.6.4 版还缺少所需的 OpenSSL 1.0.2 API。</p>
</section>
<section id="optimizations">
<span id="whatsnew37-perf"></span><h2>性能优化<a class="headerlink" href="#optimizations" title="永久链接至标题"></a></h2>
<p>通过移植更多代码来使用 <code class="docutils literal notranslate"><span class="pre">METH_FASTCALL</span></code> 的约定,可以显著地减少调用 C 代码中实现的各类标准库的很多方法的开销。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29300">bpo-29300</a><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29507">bpo-29507</a><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29452">bpo-29452</a> 以及 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29286">bpo-29286</a> 中贡献。)</p>
<p>通过各种优化方式,使 Python 在 Linux 上的启动时间缩短了 10%,在 macOS 上缩短了 30%。 (由 Victor Stinner, INADA Naoki 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29585">bpo-29585</a> 中,以及 Ivan Levkivskyi 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31333">bpo-31333</a> 中贡献。)</p>
<p>由于避免创建绑定方法案例的字节码更改,方法调用速度现在加快了 20%。 (由 Yury Selivanov 和 INADA Naoki 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26110">bpo-26110</a> 中贡献。)</p>
<p id="whatsnew37-asyncio-perf"><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> 模块里面的一些常用函数做了显著的性能优化。</p>
<ul class="simple">
<li><p><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.get_event_loop" title="asyncio.get_event_loop"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.get_event_loop()</span></code></a> 函数已经改用 C 重新实现,使其执行速度加快了 15 倍。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32296">bpo-32296</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/asyncio-future.html#asyncio.Future" title="asyncio.Future"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Future</span></code></a> 回调管理已经过优化。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32348">bpo-32348</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/asyncio-task.html#asyncio.gather" title="asyncio.gather"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.gather()</span></code></a> 的执行速度现在加快了 15%。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32355">bpo-32355</a> 中贡献。)</p></li>
<li><p><em>delay</em> 参数为零或负值时 <a class="reference internal" href="../library/asyncio-task.html#asyncio.sleep" title="asyncio.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.sleep()</span></code></a> 的执行速度现在加快了 2 倍。 (由 Andrew Svetlov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32351">bpo-32351</a> 中贡献。)</p></li>
<li><p>asyncio 调试模式的执行开销已获减轻。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31970">bpo-31970</a> 中贡献。)</p></li>
</ul>
<p>作为 <a class="reference internal" href="#whatsnew37-pep560"><span class="std std-ref">PEP 560 工作</span></a> 的结果,<a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> 的导入时间已减少了 7 倍,许多与类型相关的操作现在会执行得更快。 (由 Ivan Levkivskyi 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32226">bpo-32226</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/functions.html#sorted" title="sorted"><code class="xref py py-func docutils literal notranslate"><span class="pre">sorted()</span></code></a><a class="reference internal" href="../library/stdtypes.html#list.sort" title="list.sort"><code class="xref py py-meth docutils literal notranslate"><span class="pre">list.sort()</span></code></a> 已经过优化,在通常情况下执行速度可提升 40-75%。 (由 Elliot Gorokhovsky 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28685">bpo-28685</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/stdtypes.html#dict.copy" title="dict.copy"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.copy()</span></code></a> 的执行速度现在加快了 5.5 倍。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31179">bpo-31179</a> 中贡献。)</p>
<p><em>name</em> 未找到并且 <em>obj</em> 未重载 <a class="reference internal" href="../reference/datamodel.html#object.__getattr__" title="object.__getattr__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__getattr__()</span></code></a><a class="reference internal" href="../reference/datamodel.html#object.__getattribute__" title="object.__getattribute__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__getattribute__()</span></code></a><a class="reference internal" href="../library/functions.html#hasattr" title="hasattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">hasattr()</span></code></a><a class="reference internal" href="../library/functions.html#getattr" title="getattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">getattr()</span></code></a> 现在会比原来快大约 4 倍。 (由 INADA Naoki 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32544">bpo-32544</a> 中贡献。)</p>
<p>在字符串中搜索特定的 Unicode 字符(例如乌克兰语字母“Є”)会比搜索其他字符慢上 25 倍。 而现在最坏情况下也只会慢上 3 倍。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24821">bpo-24821</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">collections.namedtuple()</span></code></a> 工厂对象已经重写实现,使得创建具名元组的速度加快了 4 到 6 倍。 (由 Jelle Zijlstra 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28638">bpo-28638</a> 中贡献,进一步的改进由 INADA Naoki, Serhiy Storchaka 和 Raymond Hettinger 贡献。)</p>
<p>现在 <code class="xref py py-meth docutils literal notranslate"><span class="pre">date.fromordinal()</span></code><code class="xref py py-meth docutils literal notranslate"><span class="pre">date.fromtimestamp()</span></code> 在通常情况下执行速度可提升 30%。 (由 Paul Ganssle 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32403">bpo-32403</a> 中贡献。)</p>
<p>由于使用了 <a class="reference internal" href="../library/os.html#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.scandir()</span></code></a>,现在 <a class="reference internal" href="../library/os.html#os.fwalk" title="os.fwalk"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fwalk()</span></code></a> 函数执行速度提升了 2 倍。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25996">bpo-25996</a> 中贡献。)</p>
<p>由于使用了 <a class="reference internal" href="../library/os.html#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.scandir()</span></code></a> 函数,<a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.rmtree()</span></code></a> 函数的执行速度已经提升了 20--40%。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28564">bpo-28564</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">正则表达式</span></code></a> 忽略大小写的匹配和搜索已获得优化。 现在搜索某些模式的速度提升了 20 倍。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30285">bpo-30285</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/re.html#re.compile" title="re.compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.compile()</span></code></a> 现在会将 <code class="docutils literal notranslate"><span class="pre">flags</span></code> 形参转换为 int 对象,如果它是 <code class="docutils literal notranslate"><span class="pre">RegexFlag</span></code> 的话。 它现在会和 Python 3.5 一样快,而比 Python 3.6 快大约 10%,实际速度取决于具体的模式。 (由 INADA Naoki 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31671">bpo-31671</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/selectors.html#selectors.EpollSelector" title="selectors.EpollSelector"><code class="xref py py-class docutils literal notranslate"><span class="pre">selectors.EpollSelector</span></code></a>, <a class="reference internal" href="../library/selectors.html#selectors.PollSelector" title="selectors.PollSelector"><code class="xref py py-class docutils literal notranslate"><span class="pre">selectors.PollSelector</span></code></a><a class="reference internal" href="../library/selectors.html#selectors.DevpollSelector" title="selectors.DevpollSelector"><code class="xref py py-class docutils literal notranslate"><span class="pre">selectors.DevpollSelector</span></code></a> 这几个类的 <a class="reference internal" href="../library/selectors.html#selectors.BaseSelector.modify" title="selectors.BaseSelector.modify"><code class="xref py py-meth docutils literal notranslate"><span class="pre">modify()</span></code></a> 方法在重负载下可以加快 10% 左右。 (由 Giampaolo Rodola' 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30014">bpo-30014</a> 中贡献。)</p>
<p>常量折叠已经从窥孔优化器迁移至新的 AST 优化器,后者可以以更高的一致性来执行优化。 (由 Eugene Toder 和 INADA Naoki 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29469">bpo-29469</a><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11549">bpo-11549</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/abc.html#module-abc" title="abc: Abstract base classes according to :pep:`3119`."><code class="xref py py-mod docutils literal notranslate"><span class="pre">abc</span></code></a> 中的大部分函数和方法已经用 C 重写。 这使得创建抽像基类以及调用其 <a class="reference internal" href="../library/functions.html#isinstance" title="isinstance"><code class="xref py py-func docutils literal notranslate"><span class="pre">isinstance()</span></code></a><a class="reference internal" href="../library/functions.html#issubclass" title="issubclass"><code class="xref py py-func docutils literal notranslate"><span class="pre">issubclass()</span></code></a> 的速度加快了 1.5 倍。 这也使得 Python 启动耗时减少了 10%。 (由 Ivan Levkivskyi 和 INADA Naoki 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31333">bpo-31333</a> 中贡献。)</p>
<p>在不构造子类时,通过使用快速路径构造器使得 <a class="reference internal" href="../library/datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a><a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.datetime</span></code></a> 的替代构造器获得了显著的速度提升。 (由 Paul Ganssle 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32403">bpo-32403</a> 中贡献。)</p>
<p>在特定情况下 <a class="reference internal" href="../library/array.html#array.array" title="array.array"><code class="xref py py-class docutils literal notranslate"><span class="pre">array.array</span></code></a> 实例的比较速度已获得很大提升。 现在当比较存放相同的整数类型的值的数组时会比原来快 10 到 70 倍。 (由 Adrian Wielgosik 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24700">bpo-24700</a> 中贡献。)</p>
<p>在大多数平台上 <a class="reference internal" href="../library/math.html#math.erf" title="math.erf"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.erf()</span></code></a><a class="reference internal" href="../library/math.html#math.erfc" title="math.erfc"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.erfc()</span></code></a> 函数现在使用更快的C 库实现。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26121">bpo-26121</a> 中贡献。)</p>
</section>
<section id="other-cpython-implementation-changes">
<h2>其他 CPython 实现的改变<a class="headerlink" href="#other-cpython-implementation-changes" title="永久链接至标题"></a></h2>
<ul class="simple">
<li><p>跟踪钩子现在可以选择不接收 <code class="docutils literal notranslate"><span class="pre">line</span></code> 而是选择从解释器接收 <code class="docutils literal notranslate"><span class="pre">opcode</span></code> 事件,具体做法是在被跟踪的帧上相应地设置新的 <code class="docutils literal notranslate"><span class="pre">f_trace_lines</span></code><code class="docutils literal notranslate"><span class="pre">f_trace_opcodes</span></code> 属性。 (由 Nick Coghlan 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31344">bpo-31344</a> 中贡献。)</p></li>
<li><p>修复了一些命名空间包模块属性的一致性问题。 命名空间模块对象的 <code class="docutils literal notranslate"><span class="pre">__file__</span></code> 被设置为 <code class="docutils literal notranslate"><span class="pre">None</span></code> (原先未设置),对象的 <code class="docutils literal notranslate"><span class="pre">__spec__.origin</span></code> 也被设置为 <code class="docutils literal notranslate"><span class="pre">None</span></code> (之前为字符串 <code class="docutils literal notranslate"><span class="pre">&quot;namespace&quot;</span></code>)。 参见 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32305">bpo-32305</a>。 而且,命名空间模块对象的 <code class="docutils literal notranslate"><span class="pre">__spec__.loader</span></code> 被设置的值与 <code class="docutils literal notranslate"><span class="pre">__loader__</span></code> 相同 (原先前者被设置为 <code class="docutils literal notranslate"><span class="pre">None</span></code>)。 参见 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32303">bpo-32303</a></p></li>
<li><p><a class="reference internal" href="../library/functions.html#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> 字典现在以变量定义的词法顺序显示。 原先未定义顺序。 (由 Raymond Hettinger 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32690">bpo-32690</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/distutils.html#module-distutils" title="distutils: Support for building and installing Python modules into an existing Python installation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code></a> <code class="docutils literal notranslate"><span class="pre">upload</span></code> 命令不会再试图将行结束字符 CR 改为 CRLF。 这修复了 sdists 的一个以与 CR 等价的字节结束的数据损坏问题。 (由 Bo Bayles 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32304">bpo-32304</a> 中贡献。)</p></li>
</ul>
</section>
<section id="deprecated-python-behavior">
<h2>已弃用的 Python 行为<a class="headerlink" href="#deprecated-python-behavior" title="永久链接至标题"></a></h2>
<p>在推导式和生成器表达式中的 yield 语句(包括 <code class="docutils literal notranslate"><span class="pre">yield</span></code><code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> 子句)现在已弃用(最左端的 <code class="xref std std-keyword docutils literal notranslate"><span class="pre">for</span></code> 子句中的可迭代对象表达式除外)。 这确保了推导式总是立即返回适当类型的容器(而不是有可能返回 <a class="reference internal" href="../glossary.html#term-generator-iterator"><span class="xref std std-term">generator iterator</span></a> 对象),这样生成器表达式不会试图将它们的隐式输出与任何来自显式 yield 表达式的输出交错起来。 在 Python 3.7 中,这样的表达式会在编译时引发 <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>,在 Python 3.8 中则将引发 <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10544">bpo-10544</a> 中贡献。)</p>
<p><a class="reference internal" href="../reference/datamodel.html#object.__complex__" title="object.__complex__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__complex__()</span></code></a> 返回一个 <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a> 的子类的行为已弃用并将在未来的 Python 版本中引发错误。 这使得 <code class="docutils literal notranslate"><span class="pre">__complex__()</span></code> 的行为与 <a class="reference internal" href="../reference/datamodel.html#object.__int__" title="object.__int__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__int__()</span></code></a><a class="reference internal" href="../reference/datamodel.html#object.__float__" title="object.__float__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__float__()</span></code></a> 保持一致。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28894">bpo-28894</a> 中贡献。)</p>
</section>
<section id="deprecated-python-modules-functions-and-methods">
<h2>已弃用的 Python 模块、函数和方法<a class="headerlink" href="#deprecated-python-modules-functions-and-methods" title="永久链接至标题"></a></h2>
<section id="aifc">
<h3>aifc<a class="headerlink" href="#aifc" title="永久链接至标题"></a></h3>
<p><code class="xref py py-func docutils literal notranslate"><span class="pre">aifc.openfp()</span></code> 已弃用并将在 Python 3.9 中被移除。 请改用 <a class="reference internal" href="../library/aifc.html#aifc.open" title="aifc.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">aifc.open()</span></code></a>。 (由 Brian Curtin 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31985">bpo-31985</a> 中贡献。)</p>
</section>
<section id="whatsnew37-asyncio-deprecated">
<span id="id2"></span><h3>asyncio<a class="headerlink" href="#whatsnew37-asyncio-deprecated" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/asyncio-sync.html#asyncio.Lock" title="asyncio.Lock"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Lock</span></code></a> 和其他 asyncio 同步原语的 <code class="docutils literal notranslate"><span class="pre">await</span></code> 实例的直接支持已弃用。 想要获取并释放同步资源必须使用异步上下文管理器。 (由 Andrew Svetlov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32253">bpo-32253</a> 中贡献。)</p>
<p><a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.current_task" title="asyncio.Task.current_task"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.Task.current_task()</span></code></a><a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.all_tasks" title="asyncio.Task.all_tasks"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.Task.all_tasks()</span></code></a> 方法已弃用。 (由 Andrew Svetlov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32250">bpo-32250</a> 中贡献。)</p>
</section>
<section id="id3">
<h3>collections<a class="headerlink" href="#id3" title="永久链接至标题"></a></h3>
<p>在 Python 3.8 中,<a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a> 内的抽象基类将不会再通过常规的 <a class="reference internal" href="../library/collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a> 模块公开。 这有助于更清晰地区别具体类与抽象基类。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25988">bpo-25988</a> 中贡献。)</p>
</section>
<section id="id4">
<h3>dbm<a class="headerlink" href="#id4" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/dbm.html#module-dbm.dumb" title="dbm.dumb: Portable implementation of the simple DBM interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.dumb</span></code></a> 现在支持读取只读文件,且当其未被更改时不会再写入索引文件。 现在如果索引文件丢失并在 <code class="docutils literal notranslate"><span class="pre">'r'</span></code><code class="docutils literal notranslate"><span class="pre">'w'</span></code> 模式下被重新创建,则会发出已弃用警告(在未来的 Python 发布版中将改为错误)。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28847">bpo-28847</a> 中贡献。)</p>
</section>
<section id="id5">
<h3>enum<a class="headerlink" href="#id5" title="永久链接至标题"></a></h3>
<p>在 Python 3.8 中,尝试在 <code class="xref py py-class docutils literal notranslate"><span class="pre">Enum</span></code> 类中检查非 Enum 对象将引发 <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> (例如 <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">in</span> <span class="pre">Color</span></code>);类似地,尝试在 <code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code> 成员中检查非 Flag 对象也将引发 <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> (例如 <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">in</span> <span class="pre">Perm.RW</span></code>);目前,两种操作均会返回 <a class="reference internal" href="../library/constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a>。 (由 Ethan Furman 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33217">bpo-33217</a> 中贡献。)</p>
</section>
<section id="gettext">
<h3>gettext<a class="headerlink" href="#gettext" title="永久链接至标题"></a></h3>
<p>使用非整数值在 <a class="reference internal" href="../library/gettext.html#module-gettext" title="gettext: Multilingual internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gettext</span></code></a> 中选择复数形式现在已弃用。 它从未正确地发挥作用。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28692">bpo-28692</a> 中贡献。)</p>
</section>
<section id="id6">
<h3>importlib<a class="headerlink" href="#id6" title="永久链接至标题"></a></h3>
<p>下列方法 <a class="reference internal" href="../library/importlib.html#importlib.abc.MetaPathFinder.find_module" title="importlib.abc.MetaPathFinder.find_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MetaPathFinder.find_module()</span></code></a> (被 <a class="reference internal" href="../library/importlib.html#importlib.abc.MetaPathFinder.find_spec" title="importlib.abc.MetaPathFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">MetaPathFinder.find_spec()</span> <span class="pre">替代</span></code></a>) 和 <a class="reference internal" href="../library/importlib.html#importlib.abc.PathEntryFinder.find_loader" title="importlib.abc.PathEntryFinder.find_loader"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PathEntryFinder.find_loader()</span></code></a> (被 <a class="reference internal" href="../library/importlib.html#importlib.abc.PathEntryFinder.find_spec" title="importlib.abc.PathEntryFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">PathEntryFinder.find_spec()</span> <span class="pre">替代</span></code></a>) 都在 Python 3.4 中已弃用,现在会引发 <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>。 (由 Matthias Bussonnier 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29576">bpo-29576</a> 中贡献)</p>
<p><a class="reference internal" href="../library/importlib.html#importlib.abc.ResourceLoader" title="importlib.abc.ResourceLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.ResourceLoader</span></code></a> ABC 已弃用,推荐改用 <a class="reference internal" href="../library/importlib.html#importlib.abc.ResourceReader" title="importlib.abc.ResourceReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.ResourceReader</span></code></a></p>
</section>
<section id="id7">
<h3>locale<a class="headerlink" href="#id7" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/locale.html#locale.format" title="locale.format"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.format()</span></code></a> 已弃用,请改用 <a class="reference internal" href="../library/locale.html#locale.format_string" title="locale.format_string"><code class="xref py py-meth docutils literal notranslate"><span class="pre">locale.format_string()</span></code></a>。 (由 Garvit 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10379">bpo-10379</a> 中贡献。)</p>
</section>
<section id="macpath">
<h3>macpath<a class="headerlink" href="#macpath" title="永久链接至标题"></a></h3>
<p><code class="xref py py-mod docutils literal notranslate"><span class="pre">macpath</span></code> 现在已弃用,将在 Python 3.8 中被移除。 (由 Chi Hsuan Yen 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9850">bpo-9850</a> 中贡献。)</p>
</section>
<section id="threading">
<h3>threading<a class="headerlink" href="#threading" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/dummy_threading.html#module-dummy_threading" title="dummy_threading: Drop-in replacement for the threading module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dummy_threading</span></code></a><a class="reference internal" href="../library/_dummy_thread.html#module-_dummy_thread" title="_dummy_thread: Drop-in replacement for the _thread module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">_dummy_thread</span></code></a> 已弃用。 构建禁用线程的 Python 已不再可能。 请改用 <a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a>。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31370">bpo-31370</a> 中贡献。)</p>
</section>
<section id="id8">
<h3>socket<a class="headerlink" href="#id8" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/socket.html#socket.htons" title="socket.htons"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.htons()</span></code></a><a class="reference internal" href="../library/socket.html#socket.ntohs" title="socket.ntohs"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.ntohs()</span></code></a> 中的静默参数截断已弃用。 在未来的 Python 版本中,如果传入的参数长度大于 16 比特位,将会引发异常。 (由 Oren Milman 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28332">bpo-28332</a> 中贡献。)</p>
</section>
<section id="id9">
<h3>ssl<a class="headerlink" href="#id9" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/ssl.html#ssl.wrap_socket" title="ssl.wrap_socket"><code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.wrap_socket()</span></code></a> 已弃用。 请改用 <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.wrap_socket" title="ssl.SSLContext.wrap_socket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLContext.wrap_socket()</span></code></a>。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28124">bpo-28124</a> 中贡献。)</p>
</section>
<section id="sunau">
<h3>sunau<a class="headerlink" href="#sunau" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/sunau.html#sunau.openfp" title="sunau.openfp"><code class="xref py py-func docutils literal notranslate"><span class="pre">sunau.openfp()</span></code></a> 已弃用并将在 Python 3.9 中被移除。 请改用 <a class="reference internal" href="../library/sunau.html#sunau.open" title="sunau.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">sunau.open()</span></code></a>。 (由 Brian Curtin 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31985">bpo-31985</a> 中贡献。)</p>
</section>
<section id="id10">
<h3>sys<a class="headerlink" href="#id10" title="永久链接至标题"></a></h3>
<p>已弃用 <code class="xref py py-func docutils literal notranslate"><span class="pre">sys.set_coroutine_wrapper()</span></code><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.get_coroutine_wrapper()</span></code></p>
<p>未写入文档的 <code class="docutils literal notranslate"><span class="pre">sys.callstats()</span></code> 函数已弃用并将在未来的 Python 版本中被移除。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28799">bpo-28799</a> 中贡献。)</p>
</section>
<section id="wave">
<h3>wave<a class="headerlink" href="#wave" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="../library/wave.html#wave.openfp" title="wave.openfp"><code class="xref py py-func docutils literal notranslate"><span class="pre">wave.openfp()</span></code></a> 已弃用并将在 Python 3.9 中被移除。 请改用 <a class="reference internal" href="../library/wave.html#wave.open" title="wave.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">wave.open()</span></code></a>。 (由 Brian Curtin 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31985">bpo-31985</a> 中贡献。)</p>
</section>
</section>
<section id="deprecated-functions-and-types-of-the-c-api">
<h2>已弃用的 C API 函数和类型<a class="headerlink" href="#deprecated-functions-and-types-of-the-c-api" title="永久链接至标题"></a></h2>
<p>如果 <code class="docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code> 未设定或设定为范围在 <code class="docutils literal notranslate"><span class="pre">0x03050400</span></code><code class="docutils literal notranslate"><span class="pre">0x03060000</span></code> (不含) 之间,或为 <code class="docutils literal notranslate"><span class="pre">0x03060100</span></code> 或更高的值,函数 <a class="reference internal" href="../c-api/slice.html#c.PySlice_GetIndicesEx" title="PySlice_GetIndicesEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_GetIndicesEx()</span></code></a> 已弃用并被一个宏所替代。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27867">bpo-27867</a> 中贡献。)</p>
<p><a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork" title="PyOS_AfterFork"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork()</span></code></a> 已弃用。 请改用 <a class="reference internal" href="../c-api/sys.html#c.PyOS_BeforeFork" title="PyOS_BeforeFork"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_BeforeFork()</span></code></a>, <a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork_Parent" title="PyOS_AfterFork_Parent"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Parent()</span></code></a><a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork_Child" title="PyOS_AfterFork_Child"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Child()</span></code></a>。 (由 Antoine Pitrou 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16500">bpo-16500</a> 中贡献。)</p>
</section>
<section id="platform-support-removals">
<span id="id11"></span><h2>平台支持的移除<a class="headerlink" href="#platform-support-removals" title="永久链接至标题"></a></h2>
<ul>
<li><p>官方已不再支持 FreeBSD 9 及更旧的版本。</p></li>
<li><p>为了完整的 Unicode 支持,包括在扩展模块之内,*nix 平台现在至少应当提供 <code class="docutils literal notranslate"><span class="pre">C.UTF-8</span></code> (完整区域), <code class="docutils literal notranslate"><span class="pre">C.utf8</span></code> (完整区域) 或 <code class="docutils literal notranslate"><span class="pre">UTF-8</span></code> (<code class="docutils literal notranslate"><span class="pre">LC_CTYPE</span></code> 专属区域) 中的一个作为基于 <code class="docutils literal notranslate"><span class="pre">ASCII</span></code> 的传统 <code class="docutils literal notranslate"><span class="pre">C</span></code> 区域的替代。</p></li>
<li><p>OpenSSL 0.9.8 和 1.0.1 已不再受支持,这意味着在仍然使用这些版本的旧平台上构建带有 SSL/TLS 支持的 CPython 3.7 时,需要自定义构建选项以链接到更新的 OpenSSL 版本。</p>
<p>注意,此问题会影响到 Debian 8 (代号“jessie”) 和 Ubuntu 14.04 (代号“Trusty”) 等长期支持 Linux 发行版,因为它们默认仍然使用 OpenSSL 1.0.1。</p>
<p>Debian 9 (“stretch”) 和 Ubuntu 16.04 (“xenial”) 以及其他最新的长期支持 Linux 发行版 (例如 RHEL/CentOS 7.5, SLES 12-SP3) 都使用 OpenSSL 1.0.2 或更新的版本,因此继续在默认的构建配置中受到支持。</p>
<p>CPython 自己的 <a class="reference external" href="https://github.com/python/cpython/tree/3.8/.travis.yml">CI 配置文件</a> 提供了一个使用 CPython 测试套件中的 SSL <a class="reference external" href="https://github.com/python/cpython/tree/3.8/Tools/ssl/multissltests.py">兼容性测试架构</a> 基于 OpenSSL 1.1.0 进行构建和链接的例子,而不是使用过时的系统所提供的 OpenSSL。</p>
</li>
</ul>
</section>
<section id="api-and-feature-removals">
<h2>API 与特性的移除<a class="headerlink" href="#api-and-feature-removals" title="永久链接至标题"></a></h2>
<p>下列特性与 API 已从 Python 3.7 中移除:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">os.stat_float_times()</span></code> 函数已被移除。 它在 Python 2.3 中被引入用于向下兼容 Python 2.2,并自 Python 3.1 起就已弃用。</p></li>
<li><p><a class="reference internal" href="../library/re.html#re.sub" title="re.sub"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.sub()</span></code></a> 的替换模块中由 <code class="docutils literal notranslate"><span class="pre">'\'</span></code> 与一个 ASCII 字母构成的未知转义在 Python 3.5 中已弃用,现在将会引发错误。</p></li>
<li><p><a class="reference internal" href="../library/tarfile.html#tarfile.TarFile.add" title="tarfile.TarFile.add"><code class="xref py py-meth docutils literal notranslate"><span class="pre">tarfile.TarFile.add()</span></code></a> 中移除了对 <em>exclude</em> 参数的支持。 它在 Python 2.7 和 3.2 中已弃用。 请改用 <em>filter</em> 参数。</p></li>
<li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">ntpath</span></code> 模块中的 <code class="docutils literal notranslate"><span class="pre">splitunc()</span></code> 函数在 Python 3.1 中已弃用,现在已被移除。 请改用 <a class="reference internal" href="../library/os.path.html#os.path.splitdrive" title="os.path.splitdrive"><code class="xref py py-func docutils literal notranslate"><span class="pre">splitdrive()</span></code></a> 函数。</p></li>
<li><p><a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">collections.namedtuple()</span></code></a> 不再支持 <em>verbose</em> 形参或 <code class="docutils literal notranslate"><span class="pre">_source</span></code> 属性,该属性会显示为具名元组类所生成的源代码。 这是加速类创建的设计优化的一部分。 (由 Jelle Zijlstra 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28638">bpo-28638</a> 中贡献,进一步的改进由 INADA Naoki, Serhiy Storchaka 和 Raymond Hettinger 贡献。)</p></li>
<li><p>函数 <a class="reference internal" href="../library/functions.html#bool" title="bool"><code class="xref py py-func docutils literal notranslate"><span class="pre">bool()</span></code></a>, <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-func docutils literal notranslate"><span class="pre">float()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-func docutils literal notranslate"><span class="pre">list()</span></code></a><a class="reference internal" href="../library/stdtypes.html#tuple" title="tuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">tuple()</span></code></a> 不再接受关键字参数。 <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-func docutils literal notranslate"><span class="pre">int()</span></code></a> 的第一个参数现在只能作为位置参数传入。</p></li>
<li><p>移除了之前在 Python 2.4 中已弃用的 <a class="reference internal" href="../library/plistlib.html#module-plistlib" title="plistlib: Generate and parse Mac OS X plist files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code></a> 模块的类 <code class="docutils literal notranslate"><span class="pre">Plist</span></code>, <code class="docutils literal notranslate"><span class="pre">Dict</span></code><code class="docutils literal notranslate"><span class="pre">_InternalDict</span></code>。 作为函数 <a class="reference internal" href="../library/plistlib.html#plistlib.readPlist" title="plistlib.readPlist"><code class="xref py py-func docutils literal notranslate"><span class="pre">readPlist()</span></code></a><a class="reference internal" href="../library/plistlib.html#plistlib.readPlistFromBytes" title="plistlib.readPlistFromBytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">readPlistFromBytes()</span></code></a> 返回结果的 Dict 值现在为普通 dict。 你不能再使用属性访问来获取这些字典的项。</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">asyncio.windows_utils.socketpair()</span></code> 函数已被移除。 请改用 <a class="reference internal" href="../library/socket.html#socket.socketpair" title="socket.socketpair"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.socketpair()</span></code></a> 函数,它自 Python 3.5 起就在所有平台上可用。 <code class="docutils literal notranslate"><span class="pre">asyncio.windows_utils.socketpair</span></code> 在 Python 3.5 及更新版本上只是 <code class="docutils literal notranslate"><span class="pre">socket.socketpair</span></code> 的别名。</p></li>
<li><p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> 不再将 <a class="reference internal" href="../library/selectors.html#module-selectors" title="selectors: High-level I/O multiplexing."><code class="xref py py-mod docutils literal notranslate"><span class="pre">selectors</span></code></a><code class="xref py py-mod docutils literal notranslate"><span class="pre">_overlapped</span></code> 模块导出为 <code class="docutils literal notranslate"><span class="pre">asyncio.selectors</span></code><code class="docutils literal notranslate"><span class="pre">asyncio._overlapped</span></code>。 请将 <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">asyncio</span> <span class="pre">import</span> <span class="pre">selectors</span></code> 替换为 <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">selectors</span></code></p></li>
<li><p>现在已禁止直接实例化 <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket" title="ssl.SSLSocket"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLSocket</span></code></a><a class="reference internal" href="../library/ssl.html#ssl.SSLObject" title="ssl.SSLObject"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLObject</span></code></a> 对象。 相应构造器从未写入文档、也从未作为公有构造器进行测试或设计。 用户应当使用 <a class="reference internal" href="../library/ssl.html#ssl.wrap_socket" title="ssl.wrap_socket"><code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.wrap_socket()</span></code></a><a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a>。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32951">bpo-32951</a> 中贡献。)</p></li>
<li><p>未被使用的 <a class="reference internal" href="../library/distutils.html#module-distutils" title="distutils: Support for building and installing Python modules into an existing Python installation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code></a> <code class="docutils literal notranslate"><span class="pre">install_misc</span></code> 命令已被移除。 (由 Eric N. Vander Weele 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29218">bpo-29218</a> 中贡献。)</p></li>
</ul>
</section>
<section id="module-removals">
<h2>移除的模块<a class="headerlink" href="#module-removals" title="永久链接至标题"></a></h2>
<p><code class="docutils literal notranslate"><span class="pre">fpectl</span></code> 模块已被移除。 它从未被默认启用,从未在 x86-64 上正确发挥效果,并且它对 Python ABI 的改变会导致 C 扩展的意外损坏。 (由 Nathaniel J. Smith 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29137">bpo-29137</a> 中贡献。)</p>
</section>
<section id="windows-only-changes">
<h2>Windows 专属的改变<a class="headerlink" href="#windows-only-changes" title="永久链接至标题"></a></h2>
<p>Python 启动器py.exe可以接受 32 位或 64 位标记而 <strong>不必</strong> 同时指定一个小版本。 因此 <code class="docutils literal notranslate"><span class="pre">py</span> <span class="pre">-3-32</span></code><code class="docutils literal notranslate"><span class="pre">py</span> <span class="pre">-3-64</span></code><code class="docutils literal notranslate"><span class="pre">py</span> <span class="pre">-3.7-32</span></code> 均为有效,并且现在还接受 -<em>m</em>-64 和 -<em>m.n</em>-64 来强制使用 64 位 python 命令,即使是本应使用 32 位的时候。 如果指定版本不可用则 py.exe 将报错退出。 (由 Steve Barnes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30291">bpo-30291</a> 中贡献。)</p>
<p>启动器可以运行 <code class="docutils literal notranslate"><span class="pre">py</span> <span class="pre">-0</span></code> 来列出已安装的所有 python<em>默认版本会以星号标出</em>。 运行 <code class="docutils literal notranslate"><span class="pre">py</span> <span class="pre">-0p</span></code> 将同时列出相应的路径。 如果运行 py 时指定了无法匹配的版本,它将显示 <em>简短形式</em> 的可用版本列表。 (由 Steve Barnes 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30362">bpo-30362</a> 中贡献。)</p>
</section>
<section id="porting-to-python-3-7">
<span id="porting-to-python-37"></span><h2>移植到 Python 3.7<a class="headerlink" href="#porting-to-python-3-7" title="永久链接至标题"></a></h2>
<p>本节列出了先前描述的更改以及可能需要更改代码的其他错误修正.</p>
<section id="changes-in-python-behavior">
<h3>Python 行为的更改<a class="headerlink" href="#changes-in-python-behavior" title="永久链接至标题"></a></h3>
<ul>
<li><p><a class="reference internal" href="../reference/compound_stmts.html#async"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span></code></a><a class="reference internal" href="../reference/expressions.html#await"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">await</span></code></a> 现在是保留关键字。 使用了这些名称作为标识符的代码现在将引发 <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>。 (由 Jelle Zijlstra 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30406">bpo-30406</a> 中贡献。)</p></li>
<li><p><span class="target" id="index-115"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0479"><strong>PEP 479</strong></a> 在 Python 3.7 中对所有代码启用,在协程和生成器中直接或间接引发的 <a class="reference internal" href="../library/exceptions.html#StopIteration" title="StopIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code></a> 异常会被转换为 <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> 异常。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32670">bpo-32670</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../reference/datamodel.html#object.__aiter__" title="object.__aiter__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__aiter__()</span></code></a> 方法不再能被声明为异步的。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31709">bpo-31709</a> 中贡献。)</p></li>
<li><p>由于一个疏忽,之前的 Python 版本会错误地接受以下语法:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">f</span><span class="p">(</span><span class="mi">1</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">],)</span>
<span class="k">class</span> <span class="nc">C</span><span class="p">(</span><span class="mi">1</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
<span class="k">pass</span>
</pre></div>
</div>
<p>现在 Python 3.7 会正确地引发 <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>,因为生成器表达式总是必须直接包含于一对括号之内, 且前后都不能有逗号,仅在调用时可以忽略重复的括号。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32012">bpo-32012</a><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32023">bpo-32023</a> 中贡献。)</p>
</li>
<li><p>现在当使用 <a class="reference internal" href="../using/cmdline.html#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a> 开关时,会将初始工作目录添加到 <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>,而不再是一个空字符串(即在每次导入时动态地指明当前工作目录)。 任何会检测该空字符串,或是以其他方式依赖之前行为的的程序将需要进行相应的更新(例如改为还要检测 <code class="docutils literal notranslate"><span class="pre">os.getcwd()</span></code><code class="docutils literal notranslate"><span class="pre">os.path.dirname(__main__.__file__)</span></code>,具体做法首先要取决于为何要对代码执行空字符串检测)。</p></li>
</ul>
</section>
<section id="changes-in-the-python-api">
<h3>Python API 的变化<a class="headerlink" href="#changes-in-the-python-api" title="永久链接至标题"></a></h3>
<ul>
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">socketserver.ThreadingMixIn.server_close()</span></code> 现在会等待所有非守护线程完成。 将新增的 <code class="xref py py-attr docutils literal notranslate"><span class="pre">socketserver.ThreadingMixIn.block_on_close</span></code> 类属性设为 <code class="docutils literal notranslate"><span class="pre">False</span></code> 可获得 3.7 之前版本的行为。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31233">bpo-31233</a><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33540">bpo-33540</a> 中贡献。)</p></li>
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">socketserver.ForkingMixIn.server_close()</span></code> 现在会等等所有子进程完成。 将新增的 <code class="xref py py-attr docutils literal notranslate"><span class="pre">socketserver.ForkingMixIn.block_on_close</span></code> 类属性设为 <code class="docutils literal notranslate"><span class="pre">False</span></code> 可获得 3.7 之前版本的行为。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31151">bpo-31151</a><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33540">bpo-33540</a> 中贡献。)</p></li>
<li><p>某些情况下 <a class="reference internal" href="../library/locale.html#locale.localeconv" title="locale.localeconv"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.localeconv()</span></code></a> 函数现在会临时将 <code class="docutils literal notranslate"><span class="pre">LC_CTYPE</span></code> 区域设置为 <code class="docutils literal notranslate"><span class="pre">LC_NUMERIC</span></code> 的值。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31900">bpo-31900</a> 中贡献。)</p></li>
<li><p>如果 <em>path</em> 为字符串 <a class="reference internal" href="../library/pkgutil.html#pkgutil.walk_packages" title="pkgutil.walk_packages"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pkgutil.walk_packages()</span></code></a> 现在会引发 <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>。 之前则是返回一个空列表。 (由 Sanyam Khurana 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24744">bpo-24744</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/string.html#string.Formatter.format" title="string.Formatter.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">string.Formatter.format()</span></code></a> 的格式字符串参数现在为 <a class="reference internal" href="../glossary.html#positional-only-parameter"><span class="std std-ref">仅限位置</span></a> 参数。 将其作为关键字参数传入的方式自 Python 3.5 起已弃用。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29193">bpo-29193</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel" title="http.cookies.Morsel"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.cookies.Morsel</span></code></a> 的属性 <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.key" title="http.cookies.Morsel.key"><code class="xref py py-attr docutils literal notranslate"><span class="pre">key</span></code></a>, <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.value" title="http.cookies.Morsel.value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">value</span></code></a><a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.coded_value" title="http.cookies.Morsel.coded_value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">coded_value</span></code></a> 现在均为只读。 对其赋值的操作自 Python 3.5 起已弃用。 要设置它们的值请使用 <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.set" title="http.cookies.Morsel.set"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set()</span></code></a> 方法。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29192">bpo-29192</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/os.html#os.makedirs" title="os.makedirs"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.makedirs()</span></code></a><em>mode</em> 参数不会再影响新建中间层级目录的文件权限位。 要设置它们的文件权限位你可以在发起调用 <code class="docutils literal notranslate"><span class="pre">makedirs()</span></code> 之前设置 umask。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19930">bpo-19930</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/struct.html#struct.Struct.format" title="struct.Struct.format"><code class="xref py py-attr docutils literal notranslate"><span class="pre">struct.Struct.format</span></code></a> 的类型现在是 <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> 而非 <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21071">bpo-21071</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/cgi.html#cgi.parse_multipart" title="cgi.parse_multipart"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse_multipart()</span></code></a> 现在接受 <em>encoding</em><em>errors</em> 参数并返回与 <code class="xref py py-class docutils literal notranslate"><span class="pre">FieldStorage</span></code> 同样的结果:对于非文件字段,与键相关联的值是一个字符串列表,而非字节串。 (由 Pierre Quentel 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29979">bpo-29979</a> 中贡献。)</p></li>
<li><p>由于 <a class="reference internal" href="../library/socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socket</span></code></a> 中的内部更改,在由旧版 Python 中的 <a class="reference internal" href="../library/socket.html#socket.socket.share" title="socket.socket.share"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.share</span></code></a> 所创建的套接字上调用 <a class="reference internal" href="../library/socket.html#socket.fromshare" title="socket.fromshare"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.fromshare()</span></code></a> 已不受支持。</p></li>
<li><p><a class="reference internal" href="../library/exceptions.html#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a><code class="docutils literal notranslate"><span class="pre">repr</span></code> 已更改为不包含末尾的逗号。 大多数异常都会受此更改影响。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30399">bpo-30399</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/datetime.html#datetime.timedelta" title="datetime.timedelta"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.timedelta</span></code></a><code class="docutils literal notranslate"><span class="pre">repr</span></code> 已更改为在输出中包含关键字参数。 (由 Utkarsh Upadhyay 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30302">bpo-30302</a> 中贡献。)</p></li>
<li><p>因为 <a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.rmtree()</span></code></a> 现在是使用 <a class="reference internal" href="../library/os.html#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.scandir()</span></code></a> 函数实现的,用户指定的句柄 <em>onerror</em> 现在被调用时如果列目录失败会附带第一个参数 <code class="docutils literal notranslate"><span class="pre">os.scandir</span></code> 而不是 <code class="docutils literal notranslate"><span class="pre">os.listdir</span></code></p></li>
<li><p>未来可能加入在正则表达式中对 <a class="reference external" href="https://unicode.org/reports/tr18/">Unicode 技术标准 #18</a> 中嵌套集合与集合操作的支持。 这会改变现有语法。 为了推动这项未来的改变,目前在有歧义的情况下会引发 <a class="reference internal" href="../library/exceptions.html#FutureWarning" title="FutureWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FutureWarning</span></code></a>。 这包括以字面值 <code class="docutils literal notranslate"><span class="pre">'['</span></code> 开头或包含字面值字符序列 <code class="docutils literal notranslate"><span class="pre">'--'</span></code>, <code class="docutils literal notranslate"><span class="pre">'&amp;&amp;'</span></code>, <code class="docutils literal notranslate"><span class="pre">'~~'</span></code> 以及 <code class="docutils literal notranslate"><span class="pre">'||'</span></code> 的集合。 要避免警告,请用反斜杠对其进行转义。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30349">bpo-30349</a> 中贡献。)</p>
</li>
<li><p>基于可以匹配空字符串的 <a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">正则表达式</span></code></a> 对字符串进行拆分的结果已被更改。 例如基于 <code class="docutils literal notranslate"><span class="pre">r'\s*'</span></code> 的拆分现在不仅会像原先那样拆分空格符,而且会拆分所有非空格字符之前和字符串结尾处的空字符串。 通过将模式修改为 <code class="docutils literal notranslate"><span class="pre">r'\s+'</span></code> 可以恢复原先的行为。 自 Python 3.5 开始此类模式将会引发 <a class="reference internal" href="../library/exceptions.html#FutureWarning" title="FutureWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FutureWarning</span></code></a></p>
<p>对于同时匹配空字符串和非空字符串的模式,在其他情况下搜索所有匹配的结果也可能会被更改。 例如在字符串 <code class="docutils literal notranslate"><span class="pre">'a\n\n'</span></code> 中,模式 <code class="docutils literal notranslate"><span class="pre">r'(?m)^\s*?$'</span></code> 将不仅会匹配位置 2 和 3 上的空字符串,还会匹配位置 2--3 上的字符串 <code class="docutils literal notranslate"><span class="pre">'\n'</span></code>。 想要只匹配空行,模式应当改写为 <code class="docutils literal notranslate"><span class="pre">r'(?m)^[^\S\n]*$'</span></code></p>
<p><a class="reference internal" href="../library/re.html#re.sub" title="re.sub"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.sub()</span></code></a> 现在会替换与前一个的非空匹配相邻的空匹配。 例如 <code class="docutils literal notranslate"><span class="pre">re.sub('x*',</span> <span class="pre">'-',</span> <span class="pre">'abxd')</span></code> 现在会返回 <code class="docutils literal notranslate"><span class="pre">'-a-b--d-'</span></code> 而不是 <code class="docutils literal notranslate"><span class="pre">'-a-b-d-'</span></code> ('b' 和 'd' 之间的第一个减号是替换 'x',而第二个减号则是替换 'x' 和 'd' 之间的空字符串)。</p>
<p>(由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25054">bpo-25054</a><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32308">bpo-32308</a> 中贡献。)</p>
</li>
<li><p><a class="reference internal" href="../library/re.html#re.escape" title="re.escape"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.escape()</span></code></a> 更改为只转义正则表达式特殊字符,而不转义 ASCII 字母、数字和 <code class="docutils literal notranslate"><span class="pre">'_'</span></code> 以外的所有字符。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29995">bpo-29995</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/tracemalloc.html#tracemalloc.Traceback" title="tracemalloc.Traceback"><code class="xref py py-class docutils literal notranslate"><span class="pre">tracemalloc.Traceback</span></code></a> 帧现在是按从最旧到最新排序,以便与 <a class="reference internal" href="../library/traceback.html#module-traceback" title="traceback: Print or retrieve a stack traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">traceback</span></code></a> 更为一致。 (由 Jesse Bakker 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32121">bpo-32121</a> 中贡献。)</p></li>
<li><p>在支持 <a class="reference internal" href="../library/socket.html#socket.SOCK_NONBLOCK" title="socket.SOCK_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">socket.SOCK_NONBLOCK</span></code></a><a class="reference internal" href="../library/socket.html#socket.SOCK_CLOEXEC" title="socket.SOCK_CLOEXEC"><code class="xref py py-const docutils literal notranslate"><span class="pre">socket.SOCK_CLOEXEC</span></code></a> 标志位的操作系统上,<a class="reference internal" href="../library/socket.html#socket.socket.type" title="socket.socket.type"><code class="xref py py-attr docutils literal notranslate"><span class="pre">socket.type</span></code></a> 不再应用它们。 因此,像 <code class="docutils literal notranslate"><span class="pre">if</span> <span class="pre">sock.type</span> <span class="pre">==</span> <span class="pre">socket.SOCK_STREAM</span></code> 之类的检测会在所有平台上按预期的方式工作。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32331">bpo-32331</a> 中贡献。)</p></li>
<li><p>在 Windows 上当重定向标准句柄时,<a class="reference internal" href="../library/subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a><em>close_fds</em> 参数的默认值从 <a class="reference internal" href="../library/constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a> 更改为 <a class="reference internal" href="../library/constants.html#True" title="True"><code class="xref py py-const docutils literal notranslate"><span class="pre">True</span></code></a>。 如果你以前依赖于在使用带有标准 io 重定向的 <a class="reference internal" href="../library/subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a> 时所继承的句柄,则必须传入 <code class="docutils literal notranslate"><span class="pre">close_fds=False</span></code> 以保留原先的行为,或是使用 <a class="reference internal" href="../library/subprocess.html#subprocess.STARTUPINFO.lpAttributeList" title="subprocess.STARTUPINFO.lpAttributeList"><code class="xref py py-attr docutils literal notranslate"><span class="pre">STARTUPINFO.lpAttributeList</span></code></a></p></li>
<li><p><a class="reference internal" href="../library/importlib.html#importlib.machinery.PathFinder.invalidate_caches" title="importlib.machinery.PathFinder.invalidate_caches"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.PathFinder.invalidate_caches()</span></code></a> -- 此方法隐式地影响 <a class="reference internal" href="../library/importlib.html#importlib.invalidate_caches" title="importlib.invalidate_caches"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.invalidate_caches()</span></code></a> -- 现在会删除 <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a> 中被设为 <code class="docutils literal notranslate"><span class="pre">None</span></code> 的条目。 (由 Brett Cannon 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33169">bpo-33169</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> 中,<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_recv" title="asyncio.loop.sock_recv"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.sock_recv()</span></code></a>, <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_sendall" title="asyncio.loop.sock_sendall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.sock_sendall()</span></code></a>, <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_accept" title="asyncio.loop.sock_accept"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.sock_accept()</span></code></a>, <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.getaddrinfo" title="asyncio.loop.getaddrinfo"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.getaddrinfo()</span></code></a>, <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.getnameinfo" title="asyncio.loop.getnameinfo"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.getnameinfo()</span></code></a> 已被更改为正确的协程方法以与培训五日文档相匹配。 之前,这些方法会返回 <a class="reference internal" href="../library/asyncio-future.html#asyncio.Future" title="asyncio.Future"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Future</span></code></a> 实例。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32327">bpo-32327</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.Server.sockets" title="asyncio.Server.sockets"><code class="xref py py-attr docutils literal notranslate"><span class="pre">asyncio.Server.sockets</span></code></a> 现在会返回服务器套接字列表的副本,而不是直接地返回它。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32662">bpo-32662</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/struct.html#struct.Struct.format" title="struct.Struct.format"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Struct.format</span></code></a> 现在是一个 <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> 实例而非 <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> 实例。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21071">bpo-21071</a> 中贡献。)</p></li>
<li><p>现在可以通过将 <code class="docutils literal notranslate"><span class="pre">required=True</span></code> 传给 <a class="reference internal" href="../library/argparse.html#argparse.ArgumentParser.add_subparsers" title="argparse.ArgumentParser.add_subparsers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ArgumentParser.add_subparsers()</span></code></a> 使得 <a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a> 子解析器成为必需的。 (由 Anthony Sottile 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26510">bpo-26510</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/ast.html#ast.literal_eval" title="ast.literal_eval"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ast.literal_eval()</span></code></a> 现在更为严格。 任意地加减数字已不再被允许。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31778">bpo-31778</a> 中贡献。)</p></li>
<li><p>当一个日期超出 <code class="docutils literal notranslate"><span class="pre">0001-01-01</span></code><code class="docutils literal notranslate"><span class="pre">9999-12-31</span></code> 范围时 <a class="reference internal" href="../library/calendar.html#calendar.Calendar.itermonthdates" title="calendar.Calendar.itermonthdates"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Calendar.itermonthdates</span></code></a> 现在将始终如一地引发异常,以便支持不能容忍此类异常的应用程序,可以使用新增的 <a class="reference internal" href="../library/calendar.html#calendar.Calendar.itermonthdays3" title="calendar.Calendar.itermonthdays3"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Calendar.itermonthdays3</span></code></a><a class="reference internal" href="../library/calendar.html#calendar.Calendar.itermonthdays4" title="calendar.Calendar.itermonthdays4"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Calendar.itermonthdays4</span></code></a>。 这些新方法返回元组,并且其不受 <a class="reference internal" href="../library/datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a> 所支持的范围限制。 (由 Alexander Belopolsky 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28292">bpo-28292</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/collections.html#collections.ChainMap" title="collections.ChainMap"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.ChainMap</span></code></a> 现在会保留底层映射的顺序。 (由 Raymond Hettinger 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32792">bpo-32792</a> 中贡献。)</p></li>
<li><p>如果在解释器关闭期间被调用,<a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.ThreadPoolExecutor</span></code></a><a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor" title="concurrent.futures.ProcessPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.ProcessPoolExecutor</span></code></a><code class="docutils literal notranslate"><span class="pre">submit()</span></code> 方法现在会引发 <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>。 (由 Mark Nemec 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33097">bpo-33097</a> 中贡献。)</p></li>
<li><p><a class="reference internal" href="../library/configparser.html#configparser.ConfigParser" title="configparser.ConfigParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.ConfigParser</span></code></a> 构造器现在使用 <code class="docutils literal notranslate"><span class="pre">read_dict()</span></code> 来处理默认值,以使其行为与解析器的其余部分保持致。 在默认字典中的非字符串键和值现在会被隐式地转换为字符串。 (由 James Tocknell 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23835">bpo-23835</a> 中贡献。)</p></li>
<li><p>一些未写入文档的内部导入已被移除。 一个例子是 <code class="docutils literal notranslate"><span class="pre">os.errno</span></code> 已不再可用;应改为直接使用 <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">errno</span></code>。 请注意此类未写入文档的内部导入可能未经通知地随时被移除,甚至是在微版本号发行版中移除。</p></li>
</ul>
</section>
<section id="changes-in-the-c-api">
<h3>C API 的变化<a class="headerlink" href="#changes-in-the-c-api" title="永久链接至标题"></a></h3>
<p>函数 <a class="reference internal" href="../c-api/slice.html#c.PySlice_GetIndicesEx" title="PySlice_GetIndicesEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_GetIndicesEx()</span></code></a> 被认为对于大小可变的序列来说并不安全。 如果切片索引不是 <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> 的实例,而是实现了 <code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code> 方法的对象,则序列可以在其长度被传给 <code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_GetIndicesEx()</span></code> 之后调整大小。 这可能导致返回超出序列长度的索引号。 为了避免可能的问题,请使用新增的函数 <a class="reference internal" href="../c-api/slice.html#c.PySlice_Unpack" title="PySlice_Unpack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_Unpack()</span></code></a><a class="reference internal" href="../c-api/slice.html#c.PySlice_AdjustIndices" title="PySlice_AdjustIndices"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_AdjustIndices()</span></code></a>。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27867">bpo-27867</a> 中贡献。)</p>
</section>
<section id="cpython-bytecode-changes">
<h3>CPython 字节码的改变<a class="headerlink" href="#cpython-bytecode-changes" title="永久链接至标题"></a></h3>
<p>新增了两个操作码: <a class="reference internal" href="../library/dis.html#opcode-LOAD_METHOD"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_METHOD</span></code></a><a class="reference internal" href="../library/dis.html#opcode-CALL_METHOD"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_METHOD</span></code></a>。 (由 Yury Selivanov 和 INADA Naoki 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26110">bpo-26110</a> 中贡献。)</p>
<p><code class="xref std std-opcode docutils literal notranslate"><span class="pre">STORE_ANNOTATION</span></code> 操作码已被移除。 (由 Mark Shannon 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32550">bpo-32550</a> 中贡献。)</p>
</section>
<section id="id12">
<h3>Windows 专属的改变<a class="headerlink" href="#id12" title="永久链接至标题"></a></h3>
<p>用于重载 <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> 的文件现在命名为 <code class="docutils literal notranslate"><span class="pre">&lt;python-executable&gt;._pth</span></code> 而不是 <code class="docutils literal notranslate"><span class="pre">'sys.path'</span></code>。 请参阅 <a class="reference internal" href="../using/windows.html#finding-modules"><span class="std std-ref">查找模块</span></a> 了解更多信息。 (由 Steve Dower 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28137">bpo-28137</a> 中贡献。)</p>
</section>
<section id="id13">
<h3>其他 CPython 实现的改变<a class="headerlink" href="#id13" title="永久链接至标题"></a></h3>
<p>为了准备在未来对公开的 CPython 运行时初始化 API 进行潜在更改(请参阅 <span class="target" id="index-116"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0432"><strong>PEP 432</strong></a> 获取最初但略为过时的文稿CPython 内部的启动和配置管理逻辑已经过大幅重构。 虽然这些更新旨在对嵌入式应用程序和常规的 CPython CLI 用户都完全透明,但它们在这里被提及是因为重构会改变解释器启动期间许多操作的内部顺序,因此可能提示出原先隐藏的缺陷,这可能存在于嵌入式应用程序中,或是在 CPython 自身内部。 (最初由 Nick Coghlan 和 Eric Snow 作为 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22257">bpo-22257</a> 的一部分贡献,并由 Nick, Eric 和 Victor Stinner 在一系列其他问题报告中进一步更新)。 已知会受到影响的一些细节:</p>
<ul class="simple">
<li><p><a class="reference internal" href="../c-api/sys.html#c.PySys_AddWarnOptionUnicode" title="PySys_AddWarnOptionUnicode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddWarnOptionUnicode()</span></code></a> 目前对嵌入式应用程序不可用,因为在调用 <cite>Py_Initialize</cite> 之前需要创建 Unicode 对象。 请改用 <a class="reference internal" href="../c-api/sys.html#c.PySys_AddWarnOption" title="PySys_AddWarnOption"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddWarnOption()</span></code></a></p></li>
<li><p>嵌入式应用程序通过 <a class="reference internal" href="../c-api/sys.html#c.PySys_AddWarnOption" title="PySys_AddWarnOption"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddWarnOption()</span></code></a> 所添加的警告过滤器现在应该以更高的一致性优先于由解释器所设置的默认过滤器</p></li>
</ul>
<p>由于默认警告过滤器的配置方式发生了变化,将 <a class="reference internal" href="../c-api/init.html#c.Py_BytesWarningFlag" title="Py_BytesWarningFlag"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_BytesWarningFlag</span></code></a> 设置为大于一的值不再足以在发出 <a class="reference internal" href="../library/exceptions.html#BytesWarning" title="BytesWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BytesWarning</span></code></a> 消息的同时将其转换为异常。 而是改为必须设置旗标(以便首先发出警告),以及添加显式的 <code class="docutils literal notranslate"><span class="pre">error::BytesWarning</span></code> 警告过滤器来将其转换为异常。</p>
<p>由于编译器处理文档字符串的方式发生了变化,一个仅由文档字符串构成的函数体中隐式的 <code class="docutils literal notranslate"><span class="pre">return</span> <span class="pre">None</span></code> 现在被标记为在与文档字符串相同的行,而不是在函数的标题行。</p>
<p>当前异常状态已从帧对象移到协程对象。 这会简化解释器并修正由于在进入或退出生成器时具有交换异常状态而导致的一些模糊错误。 (由 Mark Shannon 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25612">bpo-25612</a> 中贡献。)</p>
</section>
</section>
<section id="notable-changes-in-python-3-7-1">
<h2>Python 3.7.1 中的重要变化<a class="headerlink" href="#notable-changes-in-python-3-7-1" title="永久链接至标题"></a></h2>
<p>从 3.7.1 开始,<a class="reference internal" href="../c-api/init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code></a> 现在始终会读取并遵循与 <a class="reference internal" href="../c-api/veryhigh.html#c.Py_Main" title="Py_Main"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Main()</span></code></a> 相同的环境设置(在更早的 Python 版本中,它会遵循一个错误定义的环境变量子集,而在 Python 3.7.0 中则会由于 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34247">bpo-34247</a> 而完全不读取它们)。 如果不想要此行为,请在调用 <a class="reference internal" href="../c-api/init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code></a> 之前将 <a class="reference internal" href="../c-api/init.html#c.Py_IgnoreEnvironmentFlag" title="Py_IgnoreEnvironmentFlag"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_IgnoreEnvironmentFlag</span></code></a> 设为 1。</p>
<p>在 3.7.1 中,上下文变量的 C API 已 <a class="reference internal" href="../c-api/contextvars.html#contextvarsobjects-pointertype-change"><span class="std std-ref">获得更新</span></a> 以使用 <a class="reference internal" href="../c-api/structures.html#c.PyObject" title="PyObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyObject</span></code></a> 指针。 另请参阅 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34762">bpo-34762</a></p>
<p>在 3.7.1 中,当提供不带末尾新行的输入时 <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> 模块现在会隐式地添加 <code class="docutils literal notranslate"><span class="pre">NEWLINE</span></code> 形符。 此行为现在已与 C 词法分析器的内部行为相匹配。 (由 Ammar Askar 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33899">bpo-33899</a> 中贡献。)</p>
</section>
<section id="notable-changes-in-python-3-7-2">
<h2>Python 3.7.2 中的重要变化<a class="headerlink" href="#notable-changes-in-python-3-7-2" title="永久链接至标题"></a></h2>
<p>在 3.7.2 中Windows 下的 <a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a> 不再复制原来的二进制文件,而是改为创建名为 <code class="docutils literal notranslate"><span class="pre">python.exe</span></code><code class="docutils literal notranslate"><span class="pre">pythonw.exe</span></code> 的重定向脚本。 这解决了一个长期存在的问题,即所有虚拟环境在每次 Python 升级后都必须进行升级或是重新创建。 然而,要注意此发布版仍然要求重新创建虚拟环境以获得新的脚本。</p>
</section>
<section id="notable-changes-in-python-3-7-6">
<h2>Python 3.7.6 中的重要变化<a class="headerlink" href="#notable-changes-in-python-3-7-6" title="永久链接至标题"></a></h2>
<p>出于重要的安全性考量,<a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_datagram_endpoint" title="asyncio.loop.create_datagram_endpoint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.create_datagram_endpoint()</span></code></a><em>reuse_address</em> 形参不再被支持。 这是由 UDP 中的套接字选项 <code class="docutils literal notranslate"><span class="pre">SO_REUSEADDR</span></code> 的行为导致的。 更多细节请参阅 <code class="docutils literal notranslate"><span class="pre">loop.create_datagram_endpoint()</span></code> 的文档。 (由 Kyle Stanley, Antoine Pitrou 和 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37228">bpo-37228</a> 中贡献。。)</p>
</section>
<section id="notable-changes-in-python-3-7-10">
<h2>Python 3.7.10 中的重要变化<a class="headerlink" href="#notable-changes-in-python-3-7-10" title="永久链接至标题"></a></h2>
<p>早先的 Python 版本允许使用 <code class="docutils literal notranslate"><span class="pre">;</span></code><code class="docutils literal notranslate"><span class="pre">&amp;</span></code> 作为 <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.parse_qs" title="urllib.parse.parse_qs"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.parse_qs()</span></code></a><a class="reference internal" href="../library/urllib.parse.html#urllib.parse.parse_qsl" title="urllib.parse.parse_qsl"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.parse_qsl()</span></code></a> 中 query 形参的分隔键。 出于安全考虑,也为了遵循更新的 W3C 推荐设置,这已被改为只允许单个分隔键,默认为 <code class="docutils literal notranslate"><span class="pre">&amp;</span></code>。 这一改变还会影响 <a class="reference internal" href="../library/cgi.html#cgi.parse" title="cgi.parse"><code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.parse()</span></code></a><a class="reference internal" href="../library/cgi.html#cgi.parse_multipart" title="cgi.parse_multipart"><code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.parse_multipart()</span></code></a> 因为它们在内部使用了受影响的函数。 要了解更多细节,请查看它们各自的文档。 (由 Adam Goldschmidt, Senthil Kumaran 和 Ken Jin 在 <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42967">bpo-42967</a> 中贡献。)</p>
</section>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">Python 3.7 有什么新变化</a><ul>
<li><a class="reference internal" href="#summary-release-highlights">摘要 - 发布重点</a></li>
<li><a class="reference internal" href="#new-features">新的特性</a><ul>
<li><a class="reference internal" href="#pep-563-postponed-evaluation-of-annotations">PEP 563延迟的标注求值</a></li>
<li><a class="reference internal" href="#pep-538-legacy-c-locale-coercion">PEP 538: 传统 C 区域强制转换</a></li>
<li><a class="reference internal" href="#pep-540-forced-utf-8-runtime-mode">PEP 540: 强制 UTF-8 运行时模式</a></li>
<li><a class="reference internal" href="#pep-553-built-in-breakpoint">PEP 553: 内置的 <code class="docutils literal notranslate"><span class="pre">breakpoint()</span></code></a></li>
<li><a class="reference internal" href="#pep-539-new-c-api-for-thread-local-storage">PEP 539: 用于线程局部存储的新 C API</a></li>
<li><a class="reference internal" href="#pep-562-customization-of-access-to-module-attributes">PEP 562: 定制对模块属性的访问</a></li>
<li><a class="reference internal" href="#pep-564-new-time-functions-with-nanosecond-resolution">PEP 564: 具有纳秒级精度的新时间函数</a></li>
<li><a class="reference internal" href="#pep-565-show-deprecationwarning-in-main">PEP 565: 在 <code class="docutils literal notranslate"><span class="pre">__main__</span></code> 中显示 DeprecationWarning</a></li>
<li><a class="reference internal" href="#pep-560-core-support-for-typing-module-and-generic-types">PEP 560: 对 <code class="docutils literal notranslate"><span class="pre">typing</span></code> 模块和泛型类型的核心支持</a></li>
<li><a class="reference internal" href="#pep-552-hash-based-pyc-files">PEP 552: 基于哈希值的 .pyc 文件</a></li>
<li><a class="reference internal" href="#pep-545-python-documentation-translations">PEP 545: Python 文档翻译</a></li>
<li><a class="reference internal" href="#development-runtime-mode-x-dev">开发运行时模式: -X dev</a></li>
</ul>
</li>
<li><a class="reference internal" href="#other-language-changes">其他语言特性修改</a></li>
<li><a class="reference internal" href="#new-modules">新增模块</a><ul>
<li><a class="reference internal" href="#contextvars">contextvars</a></li>
<li><a class="reference internal" href="#dataclasses">dataclasses</a></li>
<li><a class="reference internal" href="#importlib-resources">importlib.resources</a></li>
</ul>
</li>
<li><a class="reference internal" href="#improved-modules">改进的模块</a><ul>
<li><a class="reference internal" href="#argparse">argparse</a></li>
<li><a class="reference internal" href="#asyncio">asyncio</a></li>
<li><a class="reference internal" href="#binascii">binascii</a></li>
<li><a class="reference internal" href="#calendar">calendar</a></li>
<li><a class="reference internal" href="#collections">collections</a></li>
<li><a class="reference internal" href="#compileall">compileall</a></li>
<li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li>
<li><a class="reference internal" href="#contextlib">contextlib</a></li>
<li><a class="reference internal" href="#cprofile">cProfile</a></li>
<li><a class="reference internal" href="#crypt">crypt</a></li>
<li><a class="reference internal" href="#datetime">datetime</a></li>
<li><a class="reference internal" href="#dbm">dbm</a></li>
<li><a class="reference internal" href="#decimal">decimal</a></li>
<li><a class="reference internal" href="#dis">dis</a></li>
<li><a class="reference internal" href="#distutils">distutils</a></li>
<li><a class="reference internal" href="#enum">enum</a></li>
<li><a class="reference internal" href="#functools">functools</a></li>
<li><a class="reference internal" href="#gc">gc</a></li>
<li><a class="reference internal" href="#hmac">hmac</a></li>
<li><a class="reference internal" href="#http-client">http.client</a></li>
<li><a class="reference internal" href="#http-server">http.server</a></li>
<li><a class="reference internal" href="#idlelib-and-idle">idlelib 与 IDLE</a></li>
<li><a class="reference internal" href="#importlib">importlib</a></li>
<li><a class="reference internal" href="#io">io</a></li>
<li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
<li><a class="reference internal" href="#itertools">itertools</a></li>
<li><a class="reference internal" href="#locale">locale</a></li>
<li><a class="reference internal" href="#logging">logging</a></li>
<li><a class="reference internal" href="#math">math</a></li>
<li><a class="reference internal" href="#mimetypes">mimetypes</a></li>
<li><a class="reference internal" href="#msilib">msilib</a></li>
<li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
<li><a class="reference internal" href="#os">os</a></li>
<li><a class="reference internal" href="#pathlib">pathlib</a></li>
<li><a class="reference internal" href="#pdb">pdb</a></li>
<li><a class="reference internal" href="#py-compile">py_compile</a></li>
<li><a class="reference internal" href="#pydoc">pydoc</a></li>
<li><a class="reference internal" href="#queue">queue</a></li>
<li><a class="reference internal" href="#re">re</a></li>
<li><a class="reference internal" href="#signal">signal</a></li>
<li><a class="reference internal" href="#socket">socket</a></li>
<li><a class="reference internal" href="#socketserver">socketserver</a></li>
<li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
<li><a class="reference internal" href="#ssl">ssl</a></li>
<li><a class="reference internal" href="#string">string</a></li>
<li><a class="reference internal" href="#subprocess">subprocess</a></li>
<li><a class="reference internal" href="#sys">sys</a></li>
<li><a class="reference internal" href="#time">time</a></li>
<li><a class="reference internal" href="#tkinter">tkinter</a></li>
<li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
<li><a class="reference internal" href="#types">types</a></li>
<li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
<li><a class="reference internal" href="#unittest">unittest</a></li>
<li><a class="reference internal" href="#unittest-mock">unittest.mock</a></li>
<li><a class="reference internal" href="#urllib-parse">urllib.parse</a></li>
<li><a class="reference internal" href="#uu">uu</a></li>
<li><a class="reference internal" href="#uuid">uuid</a></li>
<li><a class="reference internal" href="#warnings">warnings</a></li>
<li><a class="reference internal" href="#xml-etree">xml.etree</a></li>
<li><a class="reference internal" href="#xmlrpc-server">xmlrpc.server</a></li>
<li><a class="reference internal" href="#zipapp">zipapp</a></li>
<li><a class="reference internal" href="#zipfile">zipfile</a></li>
</ul>
</li>
<li><a class="reference internal" href="#c-api-changes">C API 的改变</a></li>
<li><a class="reference internal" href="#build-changes">构建的改变</a></li>
<li><a class="reference internal" href="#optimizations">性能优化</a></li>
<li><a class="reference internal" href="#other-cpython-implementation-changes">其他 CPython 实现的改变</a></li>
<li><a class="reference internal" href="#deprecated-python-behavior">已弃用的 Python 行为</a></li>
<li><a class="reference internal" href="#deprecated-python-modules-functions-and-methods">已弃用的 Python 模块、函数和方法</a><ul>
<li><a class="reference internal" href="#aifc">aifc</a></li>
<li><a class="reference internal" href="#whatsnew37-asyncio-deprecated">asyncio</a></li>
<li><a class="reference internal" href="#id3">collections</a></li>
<li><a class="reference internal" href="#id4">dbm</a></li>
<li><a class="reference internal" href="#id5">enum</a></li>
<li><a class="reference internal" href="#gettext">gettext</a></li>
<li><a class="reference internal" href="#id6">importlib</a></li>
<li><a class="reference internal" href="#id7">locale</a></li>
<li><a class="reference internal" href="#macpath">macpath</a></li>
<li><a class="reference internal" href="#threading">threading</a></li>
<li><a class="reference internal" href="#id8">socket</a></li>
<li><a class="reference internal" href="#id9">ssl</a></li>
<li><a class="reference internal" href="#sunau">sunau</a></li>
<li><a class="reference internal" href="#id10">sys</a></li>
<li><a class="reference internal" href="#wave">wave</a></li>
</ul>
</li>
<li><a class="reference internal" href="#deprecated-functions-and-types-of-the-c-api">已弃用的 C API 函数和类型</a></li>
<li><a class="reference internal" href="#platform-support-removals">平台支持的移除</a></li>
<li><a class="reference internal" href="#api-and-feature-removals">API 与特性的移除</a></li>
<li><a class="reference internal" href="#module-removals">移除的模块</a></li>
<li><a class="reference internal" href="#windows-only-changes">Windows 专属的改变</a></li>
<li><a class="reference internal" href="#porting-to-python-3-7">移植到 Python 3.7</a><ul>
<li><a class="reference internal" href="#changes-in-python-behavior">Python 行为的更改</a></li>
<li><a class="reference internal" href="#changes-in-the-python-api">Python API 的变化</a></li>
<li><a class="reference internal" href="#changes-in-the-c-api">C API 的变化</a></li>
<li><a class="reference internal" href="#cpython-bytecode-changes">CPython 字节码的改变</a></li>
<li><a class="reference internal" href="#id12">Windows 专属的改变</a></li>
<li><a class="reference internal" href="#id13">其他 CPython 实现的改变</a></li>
</ul>
</li>
<li><a class="reference internal" href="#notable-changes-in-python-3-7-1">Python 3.7.1 中的重要变化</a></li>
<li><a class="reference internal" href="#notable-changes-in-python-3-7-2">Python 3.7.2 中的重要变化</a></li>
<li><a class="reference internal" href="#notable-changes-in-python-3-7-6">Python 3.7.6 中的重要变化</a></li>
<li><a class="reference internal" href="#notable-changes-in-python-3-7-10">Python 3.7.10 中的重要变化</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="3.8.html"
title="上一章">Python 3.8 有什么新变化</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="3.6.html"
title="下一章">Python 3.6 有什么新变化</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/whatsnew/3.7.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="3.6.html" title="Python 3.6 有什么新变化"
>下一页</a> |</li>
<li class="right" >
<a href="3.8.html" title="Python 3.8 有什么新变化"
>上一页</a> |</li>
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python的新变化</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>