1704 lines
288 KiB
HTML
1704 lines
288 KiB
HTML
|
||
<!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.6 有什么新变化 — 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.5 有什么新变化" href="3.5.html" />
|
||
<link rel="prev" title="Python 3.7 有什么新变化" href="3.7.html" />
|
||
<link rel="canonical" href="https://docs.python.org/3/whatsnew/3.6.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.6 有什么新变化</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-498-formatted-string-literals">PEP 498: 格式化字符串字面值</a></li>
|
||
<li><a class="reference internal" href="#pep-526-syntax-for-variable-annotations">PEP 526: 变量标注的语法</a></li>
|
||
<li><a class="reference internal" href="#pep-515-underscores-in-numeric-literals">PEP 515: 数字字面值中的下划线。</a></li>
|
||
<li><a class="reference internal" href="#pep-525-asynchronous-generators">PEP 525: 异步生成器</a></li>
|
||
<li><a class="reference internal" href="#pep-530-asynchronous-comprehensions">PEP 530: 异步推导式</a></li>
|
||
<li><a class="reference internal" href="#pep-487-simpler-customization-of-class-creation">PEP 487: 更简单的自定义类创建</a></li>
|
||
<li><a class="reference internal" href="#pep-487-descriptor-protocol-enhancements">PEP 487: 描述器协议的增强</a></li>
|
||
<li><a class="reference internal" href="#pep-519-adding-a-file-system-path-protocol">PEP 519: 添加文件系统路径协议</a></li>
|
||
<li><a class="reference internal" href="#pep-495-local-time-disambiguation">PEP 495: 消除本地时间的歧义</a></li>
|
||
<li><a class="reference internal" href="#pep-529-change-windows-filesystem-encoding-to-utf-8">PEP 529: 将 Windows 文件系统编码格式更改为 UTF-8</a></li>
|
||
<li><a class="reference internal" href="#pep-528-change-windows-console-encoding-to-utf-8">PEP 528: 将 Windows 控制台编码格式更改为 UTF-8</a></li>
|
||
<li><a class="reference internal" href="#pep-520-preserving-class-attribute-definition-order">PEP 520: 保留类属性定义顺序</a></li>
|
||
<li><a class="reference internal" href="#pep-468-preserving-keyword-argument-order">PEP 468: 保留关键字参数顺序</a></li>
|
||
<li><a class="reference internal" href="#new-dict-implementation">新的 <span class="xref std std-ref">dict</span> 实现</a></li>
|
||
<li><a class="reference internal" href="#pep-523-adding-a-frame-evaluation-api-to-cpython">PEP 523: 向 CPython 添加帧求值 API</a></li>
|
||
<li><a class="reference internal" href="#pythonmalloc-environment-variable">PYTHONMALLOC 环境变量</a></li>
|
||
<li><a class="reference internal" href="#dtrace-and-systemtap-probing-support">DTrace 和 SystemTap 探测支持</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="#secrets">secrets</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#improved-modules">改进的模块</a><ul>
|
||
<li><a class="reference internal" href="#array">array</a></li>
|
||
<li><a class="reference internal" href="#ast">ast</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="#cmath">cmath</a></li>
|
||
<li><a class="reference internal" href="#collections">collections</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="#datetime">datetime</a></li>
|
||
<li><a class="reference internal" href="#decimal">decimal</a></li>
|
||
<li><a class="reference internal" href="#distutils">distutils</a></li>
|
||
<li><a class="reference internal" href="#email">email</a></li>
|
||
<li><a class="reference internal" href="#encodings">encodings</a></li>
|
||
<li><a class="reference internal" href="#enum">enum</a></li>
|
||
<li><a class="reference internal" href="#faulthandler">faulthandler</a></li>
|
||
<li><a class="reference internal" href="#fileinput">fileinput</a></li>
|
||
<li><a class="reference internal" href="#hashlib">hashlib</a></li>
|
||
<li><a class="reference internal" href="#http-client">http.client</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="#inspect">inspect</a></li>
|
||
<li><a class="reference internal" href="#json">json</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="#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="#pickle">pickle</a></li>
|
||
<li><a class="reference internal" href="#pickletools">pickletools</a></li>
|
||
<li><a class="reference internal" href="#pydoc">pydoc</a></li>
|
||
<li><a class="reference internal" href="#random">random</a></li>
|
||
<li><a class="reference internal" href="#re">re</a></li>
|
||
<li><a class="reference internal" href="#readline">readline</a></li>
|
||
<li><a class="reference internal" href="#rlcompleter">rlcompleter</a></li>
|
||
<li><a class="reference internal" href="#shlex">shlex</a></li>
|
||
<li><a class="reference internal" href="#site">site</a></li>
|
||
<li><a class="reference internal" href="#sqlite3">sqlite3</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="#ssl">ssl</a></li>
|
||
<li><a class="reference internal" href="#statistics">statistics</a></li>
|
||
<li><a class="reference internal" href="#struct">struct</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="#telnetlib">telnetlib</a></li>
|
||
<li><a class="reference internal" href="#time">time</a></li>
|
||
<li><a class="reference internal" href="#timeit">timeit</a></li>
|
||
<li><a class="reference internal" href="#tkinter">tkinter</a></li>
|
||
<li><a class="reference internal" href="#traceback">回溯</a></li>
|
||
<li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
|
||
<li><a class="reference internal" href="#typing">typing</a></li>
|
||
<li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
|
||
<li><a class="reference internal" href="#unittest-mock">unittest.mock</a></li>
|
||
<li><a class="reference internal" href="#urllib-request">urllib.request</a></li>
|
||
<li><a class="reference internal" href="#urllib-robotparser">urllib.robotparser</a></li>
|
||
<li><a class="reference internal" href="#venv">venv</a></li>
|
||
<li><a class="reference internal" href="#warnings">warnings</a></li>
|
||
<li><a class="reference internal" href="#winreg">winreg</a></li>
|
||
<li><a class="reference internal" href="#winsound">winsound</a></li>
|
||
<li><a class="reference internal" href="#xmlrpc-client">xmlrpc.client</a></li>
|
||
<li><a class="reference internal" href="#zipfile">zipfile</a></li>
|
||
<li><a class="reference internal" href="#zlib">zlib</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#optimizations">性能优化</a></li>
|
||
<li><a class="reference internal" href="#build-and-c-api-changes">构建和 C API 的改变</a></li>
|
||
<li><a class="reference internal" href="#other-improvements">其他改进</a></li>
|
||
<li><a class="reference internal" href="#deprecated">弃用</a><ul>
|
||
<li><a class="reference internal" href="#new-keywords">新关键字</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="#asynchat">asynchat</a></li>
|
||
<li><a class="reference internal" href="#asyncore">asyncore</a></li>
|
||
<li><a class="reference internal" href="#dbm">dbm</a></li>
|
||
<li><a class="reference internal" href="#id2">distutils</a></li>
|
||
<li><a class="reference internal" href="#grp">grp</a></li>
|
||
<li><a class="reference internal" href="#id3">importlib</a></li>
|
||
<li><a class="reference internal" href="#id4">os</a></li>
|
||
<li><a class="reference internal" href="#id5">re</a></li>
|
||
<li><a class="reference internal" href="#id6">ssl</a></li>
|
||
<li><a class="reference internal" href="#id7">tkinter</a></li>
|
||
<li><a class="reference internal" href="#id8">venv</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="#deprecated-build-options">弃用的构建选项</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#removed">移除</a><ul>
|
||
<li><a class="reference internal" href="#api-and-feature-removals">API 与特性的移除</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#porting-to-python-3-6">移植到Python 3.6</a><ul>
|
||
<li><a class="reference internal" href="#changes-in-python-command-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>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-6-2">Python 3.6.2 中的重要变化</a><ul>
|
||
<li><a class="reference internal" href="#new-make-regen-all-build-target">新增 <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> 构建目标</a></li>
|
||
<li><a class="reference internal" href="#removal-of-make-touch-build-target">移除了 <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> 构建目标</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-6-4">Python 3.6.4 中的重要变化</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-6-5">Python 3.6.5 中的重要变化</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-6-7">Python 3.6.7 中的重要变化</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-6-10">Python 3.6.10 中的重要变化</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-6-13">Python 3.6.13 中的重要变化</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="3.7.html"
|
||
title="上一章">Python 3.7 有什么新变化</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="3.5.html"
|
||
title="下一章">Python 3.5 有什么新变化</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.6.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.6.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.5.html" title="Python 3.5 有什么新变化"
|
||
accesskey="N">下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.7.html" title="Python 3.7 有什么新变化"
|
||
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> »</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> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python的新变化</a> »</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-6">
|
||
<h1>Python 3.6 有什么新变化<a class="headerlink" href="#what-s-new-in-python-3-6" title="永久链接至标题">¶</a></h1>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">编者</dt>
|
||
<dd class="field-odd"><p>Elvis Pranskevichus <<a class="reference external" href="mailto:elvis%40magic.io">elvis<span>@</span>magic<span>.</span>io</a>>, Yury Selivanov <<a class="reference external" href="mailto:yury%40magic.io">yury<span>@</span>magic<span>.</span>io</a>></p>
|
||
</dd>
|
||
</dl>
|
||
<p>本文解释了与3.5相比,Python 3.6中的新功能。 Python 3.6于2016年12月23日发布。请参阅 <a class="reference external" href="https://docs.python.org/3.6/whatsnew/changelog.html">changelog</a> 以获取完整的更改列表。</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<p><span class="target" id="index-77"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0494"><strong>PEP 494</strong></a> - Python 3.6 发布计划</p>
|
||
</div>
|
||
<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="#whatsnew36-pep498"><span class="std std-ref">PEP 498</span></a>, 格式化字符串字面值</p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew36-pep515"><span class="std std-ref">PEP 515</span></a>, 数字字面值中的下划线。</p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew36-pep526"><span class="std std-ref">PEP 526</span></a> , 变量标注语法。</p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew36-pep525"><span class="std std-ref">PEP 525</span></a>,异步生成器。</p></li>
|
||
<li><p><a class="reference internal" href="#whatsnew36-pep530"><span class="std std-ref">PEP 530</span></a>: 异步推导式。</p></li>
|
||
</ul>
|
||
<p>新的库模块:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="../library/secrets.html#module-secrets" title="secrets: Generate secure random numbers for managing secrets."><code class="xref py py-mod docutils literal notranslate"><span class="pre">secrets</span></code></a>: <a class="reference internal" href="#whatsnew36-pep506"><span class="std std-ref">PEP 506 -- Python 标准库增加一个密码模块</span></a>。</p></li>
|
||
</ul>
|
||
<p>CPython 实现的改进:</p>
|
||
<ul class="simple">
|
||
<li><p>根据 <a class="reference external" href="https://mail.python.org/pipermail/python-dev/2012-December/123028.html">Raymond Hettinger 的提议</a> 已将 <a class="reference internal" href="../library/stdtypes.html#typesmapping"><span class="std std-ref">dict</span></a> 类型重新实现为使用 <a class="reference internal" href="#whatsnew36-compactdict"><span class="std std-ref">更紧凑的表示形式</span></a> 并类似于 <a class="reference external" href="https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html">PyPy dict implementation</a>。 这使得字典所使用的内存相对于 Python 3.5 版减少了 20% 到 25%。</p></li>
|
||
<li><p>类创建的定制过程通过 <a class="reference internal" href="#whatsnew36-pep487"><span class="std std-ref">新协议</span></a> 得到了简化。</p></li>
|
||
<li><p>类属性的定义顺序 <a class="reference internal" href="#whatsnew36-pep520"><span class="std std-ref">现在会被保留</span></a>。</p></li>
|
||
<li><p>现在 <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> 中的元素会与传给函数的关键字参数 <a class="reference internal" href="#whatsnew36-pep468"><span class="std std-ref">保持对应顺序</span></a>。</p></li>
|
||
<li><p>添加了 DTrace 和 SystemTap <a class="reference internal" href="#whatsnew36-tracing"><span class="std std-ref">探测支持</span></a></p></li>
|
||
<li><p>新的 <a class="reference internal" href="#whatsnew36-pythonmalloc"><span class="std std-ref">PYTHONMALLOC</span></a> 环境变量可被用来调试解释器的内存分配和访问错误。</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> 模块获得了许多新特性,显著的可用性和性能提升,以及大量的问题修正。 从 Python 3.6 开始 <code class="docutils literal notranslate"><span class="pre">asyncio</span></code> 模块不再处于待定状态,它已被视为稳定 API。</p></li>
|
||
<li><p>实现了新的 <a class="reference internal" href="#whatsnew36-pep519"><span class="std std-ref">文件系统路径协议</span></a> 以支持 <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">路径类对象</span></a>。 所有操作路径的标准库函数已被更新为使用新的协议。</p></li>
|
||
<li><p><a class="reference internal" href="../library/datetime.html#module-datetime" title="datetime: Basic date and time types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code></a> 模块已获得对 <a class="reference internal" href="#whatsnew36-pep495"><span class="std std-ref">本地时间消歧义</span></a> 的支持。</p></li>
|
||
<li><p><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> 模块获得了大量的 <a class="reference internal" href="#whatsnew36-typing"><span class="std std-ref">改进</span></a>。</p></li>
|
||
<li><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="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a> 提供更好的输出,并为内存分配错误提供更好的诊断。 请参阅 <a class="reference internal" href="#whatsnew36-pythonmalloc"><span class="std std-ref">PYTHONMALLOC 一节</span></a> 来了解详情。</p></li>
|
||
</ul>
|
||
<p>安全改进:</p>
|
||
<ul class="simple">
|
||
<li><p>添加了 <a class="reference internal" href="../library/secrets.html#module-secrets" title="secrets: Generate secure random numbers for managing secrets."><code class="xref py py-mod docutils literal notranslate"><span class="pre">secrets</span></code></a> 模块以简化适用于密码管理的高加密强度伪随机数的生成,例如账户验证、安全凭据等场景。</p></li>
|
||
<li><p>在 Linux 上,现在 <a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.urandom()</span></code></a> 会阻塞直到系统的 urandom 熵池被初始化以提升安全性。 其理由参见 <span class="target" id="index-78"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0524"><strong>PEP 524</strong></a>。</p></li>
|
||
<li><p><a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> 和 <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.1.0。</p></li>
|
||
<li><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> 模块的默认设置和特性集已得到改进。</p></li>
|
||
<li><p><a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> 模块获得了对 BLAKE2, SHA-3 和 SHAKE 哈希算法以及 <a class="reference internal" href="../library/hashlib.html#hashlib.scrypt" title="hashlib.scrypt"><code class="xref py py-func docutils literal notranslate"><span class="pre">scrypt()</span></code></a> 密钥派生函数的支持。</p></li>
|
||
</ul>
|
||
<p>Windows改进:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="#whatsnew36-pep528"><span class="std std-ref">PEP 528</span></a> 和 <a class="reference internal" href="#whatsnew36-pep529"><span class="std std-ref">PEP 529</span></a>, 将Windows文件系统和控制台的编码更改为UTF-8</p></li>
|
||
<li><p>在交互式地使用 <code class="docutils literal notranslate"><span class="pre">py.exe</span></code> 启动器时,当用户未(通过命令行参数或配置文件)指定版本时不再优先选择 Python 2 而是选择 Python 3。 对声明行的处理则保持不变 —— 在这种情况下 "python" 还是指 Python 2。</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">python.exe</span></code> 和 <code class="docutils literal notranslate"><span class="pre">pythonw.exe</span></code> 已被标记为支持长路径,这意味着不再有 260 个字符的路径长度限制。 详情参见 <a class="reference internal" href="../using/windows.html#max-path"><span class="std std-ref">移除 MAX_PATH 限制</span></a>。</p></li>
|
||
<li><p>可以添加一个 <code class="docutils literal notranslate"><span class="pre">._pth</span></code> 文件来强制使用隔离模式和完整指定所有搜索路径来避免注册表和环境查找。 更多信息请参阅 <a class="reference internal" href="../using/windows.html#finding-modules"><span class="std std-ref">相关文档</span></a>。</p></li>
|
||
<li><p>现在 <code class="docutils literal notranslate"><span class="pre">python36.zip</span></code> 文件可以作为推断 <span class="target" id="index-79"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHOME</span></code></a> 的标志。 更多信息请参阅 <a class="reference internal" href="../using/windows.html#finding-modules"><span class="std std-ref">相关文档</span></a>。</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="new-features">
|
||
<h2>新的特性<a class="headerlink" href="#new-features" title="永久链接至标题">¶</a></h2>
|
||
<section id="pep-498-formatted-string-literals">
|
||
<span id="whatsnew36-pep498"></span><h3>PEP 498: 格式化字符串字面值<a class="headerlink" href="#pep-498-formatted-string-literals" title="永久链接至标题">¶</a></h3>
|
||
<p><span class="target" id="index-80"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0498"><strong>PEP 498</strong></a> 引入了一种新型的字符串字面值: <em>f-字符串</em>,或称 <a class="reference internal" href="../reference/lexical_analysis.html#f-strings"><span class="std std-ref">格式化字符串字面值</span></a>。</p>
|
||
<p>格式化字符串字面值带有 <code class="docutils literal notranslate"><span class="pre">'f'</span></code> 前缀并且类似于 <a class="reference internal" href="../library/stdtypes.html#str.format" title="str.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.format()</span></code></a> 所接受的格式字符串。 其中包含由花括号包围的替换字段。 替换字段属于表达式,它们会在运行时被求值,然后使用 <a class="reference internal" href="../library/functions.html#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a> 协议进行格式化:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">name</span> <span class="o">=</span> <span class="s2">"Fred"</span>
|
||
<span class="gp">>>> </span><span class="sa">f</span><span class="s2">"He said his name is </span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">."</span>
|
||
<span class="go">'He said his name is Fred.'</span>
|
||
<span class="gp">>>> </span><span class="n">width</span> <span class="o">=</span> <span class="mi">10</span>
|
||
<span class="gp">>>> </span><span class="n">precision</span> <span class="o">=</span> <span class="mi">4</span>
|
||
<span class="gp">>>> </span><span class="n">value</span> <span class="o">=</span> <span class="n">decimal</span><span class="o">.</span><span class="n">Decimal</span><span class="p">(</span><span class="s2">"12.34567"</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="sa">f</span><span class="s2">"result: </span><span class="si">{</span><span class="n">value</span><span class="si">:{</span><span class="n">width</span><span class="si">}</span><span class="s2">.</span><span class="si">{</span><span class="n">precision</span><span class="si">}}</span><span class="s2">"</span> <span class="c1"># nested fields</span>
|
||
<span class="go">'result: 12.35'</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-81"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0498"><strong>PEP 498</strong></a> -- 字符串字面值插值。</dt><dd><p>PEP 由 Eric V. Smith 撰写并实现</p>
|
||
</dd>
|
||
</dl>
|
||
<p><a class="reference internal" href="../reference/lexical_analysis.html#f-strings"><span class="std std-ref">特性文档</span></a>。</p>
|
||
</div>
|
||
</section>
|
||
<section id="pep-526-syntax-for-variable-annotations">
|
||
<span id="whatsnew36-pep526"></span><h3>PEP 526: 变量标注的语法<a class="headerlink" href="#pep-526-syntax-for-variable-annotations" title="永久链接至标题">¶</a></h3>
|
||
<p><span class="target" id="index-82"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0484"><strong>PEP 484</strong></a> 引入了函数形参类型标注即类型提示的标准。 这个 PEP 为 Python 添加了标注变量类型的语法,包括类变量和实例变量:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">primes</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
|
||
|
||
<span class="n">captain</span><span class="p">:</span> <span class="nb">str</span> <span class="c1"># Note: no initial value!</span>
|
||
|
||
<span class="k">class</span> <span class="nc">Starship</span><span class="p">:</span>
|
||
<span class="n">stats</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>与函数标注一样,Python 解释器不会为变量标注附加任何特殊含义,仅会将其保存在类或模块的 <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code> 属性中。</p>
|
||
<p>与静态类型语法的变量声明不同,标注语法的目的是通过抽象语法树和 <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code> 属性提供一个简单方式来为第三方工具和库指定结构化类型元数据。</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-83"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0526"><strong>PEP 526</strong></a> -- 变量标注的语法。</dt><dd><p>PEP 由 Ryan Gonzalez, Philip House, Ivan Levkivskyi, Lisa Roach, 和 Guido van Rossum 撰写,由 Ivan Levkivskyi 实现。</p>
|
||
</dd>
|
||
</dl>
|
||
<p>使用或将要使用此新语法的工具有: <a class="reference external" href="http://www.mypy-lang.org/">mypy</a>, <a class="reference external" href="https://github.com/google/pytype">pytype</a>, PyCharm 等等。</p>
|
||
</div>
|
||
</section>
|
||
<section id="pep-515-underscores-in-numeric-literals">
|
||
<span id="whatsnew36-pep515"></span><h3>PEP 515: 数字字面值中的下划线。<a class="headerlink" href="#pep-515-underscores-in-numeric-literals" title="永久链接至标题">¶</a></h3>
|
||
<p><span class="target" id="index-84"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0515"><strong>PEP 515</strong></a> 增加了在数字字面值中使用下划线的能力以改善可读性。 例如:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="mi">1_000_000_000_000_000</span>
|
||
<span class="go">1000000000000000</span>
|
||
<span class="gp">>>> </span><span class="mh">0x_FF_FF_FF_FF</span>
|
||
<span class="go">4294967295</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>单个下划线允许用在数码之间和任何数制指示符之后。 一行内不允许有开头、末尾或多个下划线。</p>
|
||
<p><a class="reference internal" href="../library/string.html#formatspec"><span class="std std-ref">字符串格式化</span></a> 微语言现在也支持以 <code class="docutils literal notranslate"><span class="pre">'_'</span></code> 选项来表示用下划线作为浮点表示类型和整数表示类型 <code class="docutils literal notranslate"><span class="pre">'d'</span></code> 的千位分隔符。 对于整数表示类型 <code class="docutils literal notranslate"><span class="pre">'b'</span></code>, <code class="docutils literal notranslate"><span class="pre">'o'</span></code>, <code class="docutils literal notranslate"><span class="pre">'x'</span></code> 和 <code class="docutils literal notranslate"><span class="pre">'X'</span></code>,将每隔 4 个数码插入一个下划线:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="s1">'{:_}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">1000000</span><span class="p">)</span>
|
||
<span class="go">'1_000_000'</span>
|
||
<span class="gp">>>> </span><span class="s1">'{:_x}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mh">0xFFFFFFFF</span><span class="p">)</span>
|
||
<span class="go">'ffff_ffff'</span>
|
||
</pre></div>
|
||
</div>
|
||
<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-0515"><strong>PEP 515</strong></a> -- 数字字面值中的下划线。</dt><dd><p>PEP 由 Georg Brandl 和 Serhiy Storchaka 撰写</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</section>
|
||
<section id="pep-525-asynchronous-generators">
|
||
<span id="whatsnew36-pep525"></span><h3>PEP 525: 异步生成器<a class="headerlink" href="#pep-525-asynchronous-generators" title="永久链接至标题">¶</a></h3>
|
||
<p><span class="target" id="index-86"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0492"><strong>PEP 492</strong></a> 将对原生协程和 <code class="docutils literal notranslate"><span class="pre">async</span></code> / <code class="docutils literal notranslate"><span class="pre">await</span></code> 语法的支持引入到 Python 3.5 中。 但 Python 3.5 实现的一个明显限制是不可能在同一函数体中同时使用 <code class="docutils literal notranslate"><span class="pre">await</span></code> 和 <code class="docutils literal notranslate"><span class="pre">yield</span></code>。 在 Python 3.6 中此限制已被解除,这样就就能够定义 <em>异步生成器</em>:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">async</span> <span class="k">def</span> <span class="nf">ticker</span><span class="p">(</span><span class="n">delay</span><span class="p">,</span> <span class="n">to</span><span class="p">):</span>
|
||
<span class="w"> </span><span class="sd">"""Yield numbers from 0 to *to* every *delay* seconds."""</span>
|
||
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">to</span><span class="p">):</span>
|
||
<span class="k">yield</span> <span class="n">i</span>
|
||
<span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">delay</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>这个新语法允许更快速且更精简的代码。</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-87"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0525"><strong>PEP 525</strong></a> -- 异步生成器</dt><dd><p>PEP 由 Yury Selivanov 撰写并实现</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</section>
|
||
<section id="pep-530-asynchronous-comprehensions">
|
||
<span id="whatsnew36-pep530"></span><h3>PEP 530: 异步推导式<a class="headerlink" href="#pep-530-asynchronous-comprehensions" title="永久链接至标题">¶</a></h3>
|
||
<p><span class="target" id="index-88"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0530"><strong>PEP 530</strong></a> 添加了对在列表、集合与字典推导式和生成器表达式中使用 <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">for</span></code> 的支持:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">result</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">async</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">aiter</span><span class="p">()</span> <span class="k">if</span> <span class="n">i</span> <span class="o">%</span> <span class="mi">2</span><span class="p">]</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>此外,<code class="docutils literal notranslate"><span class="pre">await</span></code> 表达式也在所有种类的推导式中得到支持:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">result</span> <span class="o">=</span> <span class="p">[</span><span class="k">await</span> <span class="n">fun</span><span class="p">()</span> <span class="k">for</span> <span class="n">fun</span> <span class="ow">in</span> <span class="n">funcs</span> <span class="k">if</span> <span class="k">await</span> <span class="n">condition</span><span class="p">()]</span>
|
||
</pre></div>
|
||
</div>
|
||
<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-0530"><strong>PEP 530</strong></a> -- 异步推导式</dt><dd><p>PEP 由 Yury Selivanov 撰写并实现</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</section>
|
||
<section id="pep-487-simpler-customization-of-class-creation">
|
||
<span id="whatsnew36-pep487"></span><h3>PEP 487: 更简单的自定义类创建<a class="headerlink" href="#pep-487-simpler-customization-of-class-creation" title="永久链接至标题">¶</a></h3>
|
||
<p>现在可以在不使用元类的情况下自定义子类的创建。 当一个新的子类被创建时将在基类上调用新的 <code class="docutils literal notranslate"><span class="pre">__init_subclass__</span></code> 类方法:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">PluginBase</span><span class="p">:</span>
|
||
<span class="n">subclasses</span> <span class="o">=</span> <span class="p">[]</span>
|
||
|
||
<span class="k">def</span> <span class="nf">__init_subclass__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
||
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__init_subclass__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
|
||
<span class="bp">cls</span><span class="o">.</span><span class="n">subclasses</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">cls</span><span class="p">)</span>
|
||
|
||
<span class="k">class</span> <span class="nc">Plugin1</span><span class="p">(</span><span class="n">PluginBase</span><span class="p">):</span>
|
||
<span class="k">pass</span>
|
||
|
||
<span class="k">class</span> <span class="nc">Plugin2</span><span class="p">(</span><span class="n">PluginBase</span><span class="p">):</span>
|
||
<span class="k">pass</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>为了让来自 <a class="reference internal" href="../reference/datamodel.html#object.__init_subclass__" title="object.__init_subclass__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__init_subclass__()</span></code></a> 实现的零参数 <a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a> 调用能正确工作,自定义元类必须保证新的 <code class="docutils literal notranslate"><span class="pre">__classcell__</span></code> 命名空间入口被传播到 <code class="docutils literal notranslate"><span class="pre">type.__new__</span></code> (如 <a class="reference internal" href="../reference/datamodel.html#class-object-creation"><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-90"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0487"><strong>PEP 487</strong></a> -- 更简单的自定义类创建</dt><dd><p>PEP 由 Martin Teichmann 撰写并实现。</p>
|
||
</dd>
|
||
</dl>
|
||
<p><a class="reference internal" href="../reference/datamodel.html#class-customization"><span class="std std-ref">特性文档</span></a></p>
|
||
</div>
|
||
</section>
|
||
<section id="pep-487-descriptor-protocol-enhancements">
|
||
<span id="whatsnew36-pep487-descriptors"></span><h3>PEP 487: 描述器协议的增强<a class="headerlink" href="#pep-487-descriptor-protocol-enhancements" title="永久链接至标题">¶</a></h3>
|
||
<p><span class="target" id="index-91"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0487"><strong>PEP 487</strong></a> 扩展了描述器协议以包括新的可选方法 <a class="reference internal" href="../reference/datamodel.html#object.__set_name__" title="object.__set_name__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__set_name__()</span></code></a>。 当创建一个新类时,这个新方法将在定义中包括的所有描述器上被调用,为它们提供对所定义类的引用以及在类命名中间中给予描述器的名称。 换句话说,描述器的实例现在能知道描述器在所有者类中的属性名称:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">IntField</span><span class="p">:</span>
|
||
<span class="k">def</span> <span class="fm">__get__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">instance</span><span class="p">,</span> <span class="n">owner</span><span class="p">):</span>
|
||
<span class="k">return</span> <span class="n">instance</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
|
||
|
||
<span class="k">def</span> <span class="fm">__set__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">instance</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
|
||
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
|
||
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s1">'expecting integer in </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s1">'</span><span class="p">)</span>
|
||
<span class="n">instance</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
|
||
|
||
<span class="c1"># this is the new initializer:</span>
|
||
<span class="k">def</span> <span class="nf">__set_name__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">owner</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
|
||
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
|
||
|
||
<span class="k">class</span> <span class="nc">Model</span><span class="p">:</span>
|
||
<span class="n">int_field</span> <span class="o">=</span> <span class="n">IntField</span><span class="p">()</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-92"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0487"><strong>PEP 487</strong></a> -- 更简单的自定义类创建</dt><dd><p>PEP 由 Martin Teichmann 撰写并实现。</p>
|
||
</dd>
|
||
</dl>
|
||
<p><a class="reference internal" href="../reference/datamodel.html#descriptors"><span class="std std-ref">特性文档</span></a></p>
|
||
</div>
|
||
</section>
|
||
<section id="pep-519-adding-a-file-system-path-protocol">
|
||
<span id="whatsnew36-pep519"></span><h3>PEP 519: 添加文件系统路径协议<a class="headerlink" href="#pep-519-adding-a-file-system-path-protocol" title="永久链接至标题">¶</a></h3>
|
||
<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/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> 因为它不是文件路径)。 不幸的是,这种假定阻止了像 <a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> 这样的文件系统路径的替代对象表示形式与包括 Python 标准库在内的现有代码协同工作。</p>
|
||
<p>为了修正这种情况,一个由 <a class="reference internal" href="../library/os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a> 表示的新接口被定义出来。 通过实现 <a class="reference internal" href="../library/os.html#os.PathLike.__fspath__" title="os.PathLike.__fspath__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__fspath__()</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> 对象的形式提供文件系统路径的低层级表示。 这意味着如果一个对象实现了 <a class="reference internal" href="../library/os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</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> 对象它就会被当作是 <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">路径型对象</span></a>。 代码可以使用 <a class="reference internal" href="../library/os.html#os.fspath" title="os.fspath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fspath()</span></code></a>、<a class="reference internal" href="../library/os.html#os.fsdecode" title="os.fsdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsdecode()</span></code></a> 或 <a class="reference internal" href="../library/os.html#os.fsencode" title="os.fsencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsencode()</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> 表示形式。</p>
|
||
<p>内置 <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> 函数已被更新为接受 <a class="reference internal" href="../library/os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a> 对象,就像 <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> 和 <a class="reference internal" href="../library/os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> 模块中的所有相关函数和标准库中的大多数其他函数和类一样。 <a class="reference internal" href="../library/os.html#os.DirEntry" title="os.DirEntry"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.DirEntry</span></code></a> 类和 <a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> 中的相关类也已被更新以实现 <a class="reference internal" href="../library/os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a>。</p>
|
||
<p>希望对于针对文件系统路径操作的基本函数的更新将会使得第三方代码都能隐式地支持所有 <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">路径型对象</span></a> 而无须修改任何代码,或者至少只需极少的修改(例如当对路径型对象进行操作之前在代码的开头调用 <a class="reference internal" href="../library/os.html#os.fspath" title="os.fspath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fspath()</span></code></a> 即可)。</p>
|
||
<p>下面的这些示例说明了新的接口是如何让 <a class="reference internal" href="../library/pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> 被更容易、更透明地用于已有代码的:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">pathlib</span>
|
||
<span class="gp">>>> </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s2">"README"</span><span class="p">))</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
|
||
<span class="gp">... </span> <span class="n">contents</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">os.path</span>
|
||
<span class="gp">>>> </span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s2">"some_file.txt"</span><span class="p">))</span>
|
||
<span class="go">('some_file', '.txt')</span>
|
||
<span class="gp">>>> </span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s2">"/a/b"</span><span class="p">,</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s2">"c"</span><span class="p">))</span>
|
||
<span class="go">'/a/b/c'</span>
|
||
<span class="gp">>>> </span><span class="kn">import</span> <span class="nn">os</span>
|
||
<span class="gp">>>> </span><span class="n">os</span><span class="o">.</span><span class="n">fspath</span><span class="p">(</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s2">"some_file.txt"</span><span class="p">))</span>
|
||
<span class="go">'some_file.txt'</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(由 Brett Cannon, Ethan Furman, Dusty Phillips 和 Jelle Zijlstra 实现。)</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-0519"><strong>PEP 519</strong></a> -- 添加文件系统路径协议</dt><dd><p>PEP 由 Brett Cannon 和 Koos Zevenhoven 撰写。</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</section>
|
||
<section id="pep-495-local-time-disambiguation">
|
||
<span id="whatsnew36-pep495"></span><h3>PEP 495: 消除本地时间的歧义<a class="headerlink" href="#pep-495-local-time-disambiguation" title="永久链接至标题">¶</a></h3>
|
||
<p>在世界上大多数地方,过去和将来都会存在本地时钟后移的时候。 在这种时候,本地时钟会在同一天内两次显示相同的时间。 对于这些情况,本地时钟所显示的(或存储在 Python datetime 实例中的)信息将不足以标识某个特定的时间点。</p>
|
||
<p><span class="target" id="index-94"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0495"><strong>PEP 495</strong></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> 和 <a class="reference internal" href="../library/datetime.html#datetime.time" title="datetime.time"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.time</span></code></a> 类的实例添加了新的 <em>fold</em> 属性以在本地时间相同的两个时间点之间进行区分:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">u0</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2016</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="n">tzinfo</span><span class="o">=</span><span class="n">timezone</span><span class="o">.</span><span class="n">utc</span><span class="p">)</span>
|
||
<span class="gp">>>> </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="n">u</span> <span class="o">=</span> <span class="n">u0</span> <span class="o">+</span> <span class="n">i</span><span class="o">*</span><span class="n">HOUR</span>
|
||
<span class="gp">... </span> <span class="n">t</span> <span class="o">=</span> <span class="n">u</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span><span class="n">Eastern</span><span class="p">)</span>
|
||
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">u</span><span class="o">.</span><span class="n">time</span><span class="p">(),</span> <span class="s1">'UTC ='</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">time</span><span class="p">(),</span> <span class="n">t</span><span class="o">.</span><span class="n">tzname</span><span class="p">(),</span> <span class="n">t</span><span class="o">.</span><span class="n">fold</span><span class="p">)</span>
|
||
<span class="gp">...</span>
|
||
<span class="go">04:00:00 UTC = 00:00:00 EDT 0</span>
|
||
<span class="go">05:00:00 UTC = 01:00:00 EDT 0</span>
|
||
<span class="go">06:00:00 UTC = 01:00:00 EST 1</span>
|
||
<span class="go">07:00:00 UTC = 02:00:00 EST 0</span>
|
||
</pre></div>
|
||
</div>
|
||
<p><a class="reference internal" href="../library/datetime.html#datetime.datetime.fold" title="datetime.datetime.fold"><code class="xref py py-attr docutils literal notranslate"><span class="pre">fold</span></code></a> 属性的值在大多数实例上均为 <code class="docutils literal notranslate"><span class="pre">0</span></code>,只有在代表存在歧义的时间的第二个(按发生顺序)实例上例外。</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-95"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0495"><strong>PEP 495</strong></a> -- 消除本地时间的歧义</dt><dd><p>PEP 由 Alexander Belopolsky 和 Tim Peters 撰写,由 Alexander Belopolsky 实现。</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</section>
|
||
<section id="pep-529-change-windows-filesystem-encoding-to-utf-8">
|
||
<span id="whatsnew36-pep529"></span><h3>PEP 529: 将 Windows 文件系统编码格式更改为 UTF-8<a class="headerlink" href="#pep-529-change-windows-filesystem-encoding-to-utf-8" title="永久链接至标题">¶</a></h3>
|
||
<p>在表示文件系统路径时最好是使用 str (Unicode) 而不是 bytes。 不过,在某些情况下使用 bytes 就是足够而且正确的。</p>
|
||
<p>在 Python 3.6 之前,在 Windows 上使用 bytes 路径值可能会导致数据丢失。 有了这一更改,现在 Windows 上将支持使用 bytes 来表示路径,前提是这些 bytes 值是用 <a class="reference internal" href="../library/sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a> 所返回的编码格式来编码的,现在此编码格式默认为 <code class="docutils literal notranslate"><span class="pre">'utf-8'</span></code>。</p>
|
||
<p>不使用 str 来表示路径的应用程序应当使用 <a class="reference internal" href="../library/os.html#os.fsencode" title="os.fsencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsencode()</span></code></a> 和 <a class="reference internal" href="../library/os.html#os.fsdecode" title="os.fsdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsdecode()</span></code></a> 来确保 bytes 被正确地编码。 要恢复以前的行为,请设置 <span class="target" id="index-96"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONLEGACYWINDOWSFSENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONLEGACYWINDOWSFSENCODING</span></code></a> 或调用 <a class="reference internal" href="../library/sys.html#sys._enablelegacywindowsfsencoding" title="sys._enablelegacywindowsfsencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys._enablelegacywindowsfsencoding()</span></code></a>。</p>
|
||
<p>有关详细信息和可能需要的代码修改的讨论,请参见 <span class="target" id="index-97"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0529"><strong>PEP 529</strong></a> 。</p>
|
||
</section>
|
||
<section id="pep-528-change-windows-console-encoding-to-utf-8">
|
||
<span id="whatsnew36-pep528"></span><h3>PEP 528: 将 Windows 控制台编码格式更改为 UTF-8<a class="headerlink" href="#pep-528-change-windows-console-encoding-to-utf-8" title="永久链接至标题">¶</a></h3>
|
||
<p>现在,Windows 上的默认控制台将接受所有 Unicode 字符并为 Python 代码提供正确读取的 str 对象。<code class="docutils literal notranslate"><span class="pre">sys.stdin</span></code>, <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code> 和 <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> 现在默认使用 utf-8 编码格式。</p>
|
||
<p>此更改仅在使用交互式控制台时适用,而不适用于重定向文件或管道。 要恢复以前使用交互式控制台时的行为,请设置 <span class="target" id="index-98"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONLEGACYWINDOWSSTDIO"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONLEGACYWINDOWSSTDIO</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-0528"><strong>PEP 528</strong></a> -- 将 Windows 控制台编码格式更改为 UTF-8</dt><dd><p>PEP 由 Steve Dower 撰写并实现。</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</section>
|
||
<section id="pep-520-preserving-class-attribute-definition-order">
|
||
<span id="whatsnew36-pep520"></span><h3>PEP 520: 保留类属性定义顺序<a class="headerlink" href="#pep-520-preserving-class-attribute-definition-order" title="永久链接至标题">¶</a></h3>
|
||
<p>类定义体中的属性具有自然的排序:与名称在源代码中出现的顺序相同。 现在此排序会在新类的 <a class="reference internal" href="../library/stdtypes.html#object.__dict__" title="object.__dict__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__dict__</span></code></a> 属性中被保留。</p>
|
||
<p>并且,实际的默认类 <em>execution</em> 命名空间 (从 <a class="reference internal" href="../reference/datamodel.html#prepare"><span class="std std-ref">type.__prepare__()</span></a> 返回) 现在将是一个保留插入顺序的映射对象。</p>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-100"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0520"><strong>PEP 520</strong></a> -- 保留类属性定义顺序</dt><dd><p>PEP 由 Eric Snow 撰写并实现</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</section>
|
||
<section id="pep-468-preserving-keyword-argument-order">
|
||
<span id="whatsnew36-pep468"></span><h3>PEP 468: 保留关键字参数顺序<a class="headerlink" href="#pep-468-preserving-keyword-argument-order" title="永久链接至标题">¶</a></h3>
|
||
<p>函数签名中的 <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> 现在将保证是一个保留插入顺序的映射对象。</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-0468"><strong>PEP 468</strong></a> -- 保留关键字参数顺序</dt><dd><p>PEP 由 Eric Snow 撰写并实现</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</section>
|
||
<section id="new-dict-implementation">
|
||
<span id="whatsnew36-compactdict"></span><h3>新的 <a class="reference internal" href="../library/stdtypes.html#typesmapping"><span class="std std-ref">dict</span></a> 实现<a class="headerlink" href="#new-dict-implementation" title="永久链接至标题">¶</a></h3>
|
||
<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/2012-December/123028.html">Raymond Hettinger 的提议</a> 的“紧凑”表示形式,该表示形式 <a class="reference external" href="https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html">最初由 PyPy 实现</a>。 新的The memory usage of the new <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-func docutils literal notranslate"><span class="pre">dict()</span></code></a> 的内存占用相比 Python 3.5 减少了 20% 到 25%。</p>
|
||
<p>这个新实现对原始顺序的保留被认为是一个实现细节而不应当被依赖(这在将来可能会改变,但我们希望在改变语言规范以强制所有当前和将来的 Python 实现都使用保留顺序的语义之前先在几个发布版的语言内部使用这个新的 dict 实现;这也有助于让仍在使用随机迭代顺序的旧版本语言例如 Python 3.5 保持向下兼容性)。</p>
|
||
<p>(由 INADA Naoki 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27350">bpo-27350</a> 中贡献。 该特性 <a class="reference external" href="https://mail.python.org/pipermail/python-dev/2012-December/123028.html">最初由 Raymond Hettinger 提议</a>。)</p>
|
||
</section>
|
||
<section id="pep-523-adding-a-frame-evaluation-api-to-cpython">
|
||
<span id="whatsnew36-pep523"></span><h3>PEP 523: 向 CPython 添加帧求值 API<a class="headerlink" href="#pep-523-adding-a-frame-evaluation-api-to-cpython" title="永久链接至标题">¶</a></h3>
|
||
<p>虽然 Python 为自定义代码执行方式提供了广泛的支持,但有一个地方它没有这样做,那就是帧对象的求值。 如果您想在 Python 中拦截帧的求值,那么确实没有除了直接操纵自定义函数的函数指针以外的任何办法。</p>
|
||
<p><span class="target" id="index-102"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0523"><strong>PEP 523</strong></a> 通过提供使帧求值在 C 语言层级上可插入的 API 从而改变了这一状况。 这将允许调试器和 JIT 等工具在 Python 代码开始执行之前拦截帧求值。 这样就能允许 Python 代码使用替代性求值实现,跟踪帧求值等做法。</p>
|
||
<p>这个 API 并不是受限 C API 的组成部分,它被标记为私有以表明该 API 的使用受到限制并且只适用于非常少的、低层级的用例。 这个 API 的语义将根据需要随 Python 的一起发生变化。</p>
|
||
<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-0523"><strong>PEP 523</strong></a> -- 向 CPython 添加帧求值 API</dt><dd><p>PEP 由 Brett Cannon 和 Dino Viehland 撰写。</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</section>
|
||
<section id="pythonmalloc-environment-variable">
|
||
<span id="whatsnew36-pythonmalloc"></span><h3>PYTHONMALLOC 环境变量<a class="headerlink" href="#pythonmalloc-environment-variable" title="永久链接至标题">¶</a></h3>
|
||
<p>新的 <span class="target" id="index-104"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONMALLOC"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONMALLOC</span></code></a> 环境变量允许设置 Python 内存分配器并安装调试钩子。</p>
|
||
<p>现在将可以使用 <code class="docutils literal notranslate"><span class="pre">PYTHONMALLOC=debug</span></code> 在以发布模式编译的 Python 上为 Python 内存分配器安装调试钩子。 调试钩子的效果:</p>
|
||
<ul class="simple">
|
||
<li><p>新分配的内存中填充字节 <code class="docutils literal notranslate"><span class="pre">0xCB</span></code></p></li>
|
||
<li><p>释放的内存中填充了字节 <code class="docutils literal notranslate"><span class="pre">0xDB</span></code></p></li>
|
||
<li><p>检测违反 Python 内存分配器 API 的操作。 例如,<a class="reference internal" href="../c-api/memory.html#c.PyObject_Free" title="PyObject_Free"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Free()</span></code></a> 在 <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a> 所分配的内存块上被调用。</p></li>
|
||
<li><p>在缓冲区开始之前检测写操作(缓冲区下溢)</p></li>
|
||
<li><p>在缓冲区结束后检测写操作(缓冲区溢出)</p></li>
|
||
<li><p>检测当调用 <a class="reference internal" href="../c-api/memory.html#c.PYMEM_DOMAIN_OBJ" title="PYMEM_DOMAIN_OBJ"><code class="xref c c-data docutils literal notranslate"><span class="pre">PYMEM_DOMAIN_OBJ</span></code></a> (如: <a class="reference internal" href="../c-api/memory.html#c.PyObject_Malloc" title="PyObject_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Malloc()</span></code></a>) 和 <a class="reference internal" href="../c-api/memory.html#c.PYMEM_DOMAIN_MEM" title="PYMEM_DOMAIN_MEM"><code class="xref c c-data docutils literal notranslate"><span class="pre">PYMEM_DOMAIN_MEM</span></code></a> (如: <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a>) 域的分配器函数时 <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">GIL</span></a> 已被持有。</p></li>
|
||
</ul>
|
||
<p>检查是否保留了 GIL 也是Python 3.6 的新特性。</p>
|
||
<p>请参阅 <a class="reference internal" href="../c-api/memory.html#c.PyMem_SetupDebugHooks" title="PyMem_SetupDebugHooks"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_SetupDebugHooks()</span></code></a> 函数来了解 Python 内存分配器上的调试钩子。</p>
|
||
<p>现在还可以使用 <code class="docutils literal notranslate"><span class="pre">PYTHONMALLOC=malloc</span></code> 为所有的 Python 内存分配强制使用 C 库的 <code class="xref c c-func docutils literal notranslate"><span class="pre">malloc()</span></code> 分配器。 这在以发布模式编译的 Python 上使用外部内存调试器如 Valgrind 时会很有用处。</p>
|
||
<p>发生错误时,Python 内存分配器上的调试钩子现在会使用 <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> 模块来获取内存块被分配所在位置上的回溯。</p>
|
||
<p>使用 <code class="docutils literal notranslate"><span class="pre">python3.6</span> <span class="pre">-X</span> <span class="pre">tracemalloc=5</span></code> (在回溯中存储 5 帧) 的缓冲区溢出的致命错误示例:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Debug</span> <span class="n">memory</span> <span class="n">block</span> <span class="n">at</span> <span class="n">address</span> <span class="n">p</span><span class="o">=</span><span class="mh">0x7fbcd41666f8</span><span class="p">:</span> <span class="n">API</span> <span class="s1">'o'</span>
|
||
<span class="mi">4</span> <span class="nb">bytes</span> <span class="n">originally</span> <span class="n">requested</span>
|
||
<span class="n">The</span> <span class="mi">7</span> <span class="n">pad</span> <span class="nb">bytes</span> <span class="n">at</span> <span class="n">p</span><span class="o">-</span><span class="mi">7</span> <span class="n">are</span> <span class="n">FORBIDDENBYTE</span><span class="p">,</span> <span class="k">as</span> <span class="n">expected</span><span class="o">.</span>
|
||
<span class="n">The</span> <span class="mi">8</span> <span class="n">pad</span> <span class="nb">bytes</span> <span class="n">at</span> <span class="n">tail</span><span class="o">=</span><span class="mh">0x7fbcd41666fc</span> <span class="n">are</span> <span class="ow">not</span> <span class="nb">all</span> <span class="n">FORBIDDENBYTE</span> <span class="p">(</span><span class="mh">0xfb</span><span class="p">):</span>
|
||
<span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">0</span><span class="p">:</span> <span class="mh">0x02</span> <span class="o">***</span> <span class="n">OUCH</span>
|
||
<span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">1</span><span class="p">:</span> <span class="mh">0xfb</span>
|
||
<span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">2</span><span class="p">:</span> <span class="mh">0xfb</span>
|
||
<span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">3</span><span class="p">:</span> <span class="mh">0xfb</span>
|
||
<span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">4</span><span class="p">:</span> <span class="mh">0xfb</span>
|
||
<span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">5</span><span class="p">:</span> <span class="mh">0xfb</span>
|
||
<span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">6</span><span class="p">:</span> <span class="mh">0xfb</span>
|
||
<span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">7</span><span class="p">:</span> <span class="mh">0xfb</span>
|
||
<span class="n">The</span> <span class="n">block</span> <span class="n">was</span> <span class="n">made</span> <span class="n">by</span> <span class="n">call</span> <span class="c1">#1233329 to debug malloc/realloc.</span>
|
||
<span class="n">Data</span> <span class="n">at</span> <span class="n">p</span><span class="p">:</span> <span class="mi">1</span><span class="n">a</span> <span class="mi">2</span><span class="n">b</span> <span class="mi">30</span> <span class="mi">00</span>
|
||
|
||
<span class="n">Memory</span> <span class="n">block</span> <span class="n">allocated</span> <span class="n">at</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">first</span><span class="p">):</span>
|
||
<span class="n">File</span> <span class="s2">"test/test_bytes.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">323</span>
|
||
<span class="n">File</span> <span class="s2">"unittest/case.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">600</span>
|
||
<span class="n">File</span> <span class="s2">"unittest/case.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">648</span>
|
||
<span class="n">File</span> <span class="s2">"unittest/suite.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">122</span>
|
||
<span class="n">File</span> <span class="s2">"unittest/suite.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">84</span>
|
||
|
||
<span class="n">Fatal</span> <span class="n">Python</span> <span class="n">error</span><span class="p">:</span> <span class="n">bad</span> <span class="n">trailing</span> <span class="n">pad</span> <span class="n">byte</span>
|
||
|
||
<span class="n">Current</span> <span class="n">thread</span> <span class="mh">0x00007fbcdbd32700</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">first</span><span class="p">):</span>
|
||
<span class="n">File</span> <span class="s2">"test/test_bytes.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">323</span> <span class="ow">in</span> <span class="n">test_hex</span>
|
||
<span class="n">File</span> <span class="s2">"unittest/case.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">600</span> <span class="ow">in</span> <span class="n">run</span>
|
||
<span class="n">File</span> <span class="s2">"unittest/case.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">648</span> <span class="ow">in</span> <span class="fm">__call__</span>
|
||
<span class="n">File</span> <span class="s2">"unittest/suite.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">122</span> <span class="ow">in</span> <span class="n">run</span>
|
||
<span class="n">File</span> <span class="s2">"unittest/suite.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">84</span> <span class="ow">in</span> <span class="fm">__call__</span>
|
||
<span class="n">File</span> <span class="s2">"unittest/suite.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">122</span> <span class="ow">in</span> <span class="n">run</span>
|
||
<span class="n">File</span> <span class="s2">"unittest/suite.py"</span><span class="p">,</span> <span class="n">line</span> <span class="mi">84</span> <span class="ow">in</span> <span class="fm">__call__</span>
|
||
<span class="o">...</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26516">bpo-26516</a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26564">bpo-26564</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="dtrace-and-systemtap-probing-support">
|
||
<span id="whatsnew36-tracing"></span><h3>DTrace 和 SystemTap 探测支持<a class="headerlink" href="#dtrace-and-systemtap-probing-support" title="永久链接至标题">¶</a></h3>
|
||
<p>Python 现在可以附带 <code class="docutils literal notranslate"><span class="pre">--with-dtrace</span></code> 来构建以便为解释器中的下列事件启用静态标记:</p>
|
||
<ul class="simple">
|
||
<li><p>函数调用/返回</p></li>
|
||
<li><p>垃圾收集开始/完成</p></li>
|
||
<li><p>执行的代码行。</p></li>
|
||
</ul>
|
||
<p>This can be used to instrument running interpreters in production,
|
||
without the need to recompile specific debug builds or providing
|
||
application-specific profiling/debugging code.</p>
|
||
<p>更多信息,请参见 <a class="reference internal" href="../howto/instrumentation.html#instrumentation"><span class="std std-ref">使用 DTrace 和 SystemTap 检测CPython</span></a> 。</p>
|
||
<p>当前的实现已在 Linux 和 macOS 上进行了测试。将来可能会添加其他标记。</p>
|
||
<p>(由 Łukasz Langa 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=21590">bpo-21590</a> 中贡献,基于 Jesús Cea Avión, David Malcolm 和 Nikhil Benesch 的补丁。)</p>
|
||
</section>
|
||
</section>
|
||
<section id="other-language-changes">
|
||
<h2>其他语言特性修改<a class="headerlink" href="#other-language-changes" title="永久链接至标题">¶</a></h2>
|
||
<p>对Python 语言核心进行的小改动:</p>
|
||
<ul class="simple">
|
||
<li><p>现在 <code class="docutils literal notranslate"><span class="pre">global</span></code> 或 <code class="docutils literal notranslate"><span class="pre">nonlocal</span></code> 语句必须以文本形式出现在同一作用域中首次使用受影响的名称之前。 在之前版本中这只是 <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a>。</p></li>
|
||
<li><p>现在可以将某个 <a class="reference internal" href="../reference/datamodel.html#specialnames"><span class="std std-ref">特殊方法</span></a> 设为 <code class="docutils literal notranslate"><span class="pre">None</span></code> 来表示相应操作不可用。 举例来说,如果某个类将 <a class="reference internal" href="../reference/datamodel.html#object.__iter__" title="object.__iter__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__iter__()</span></code></a> 设为 <code class="docutils literal notranslate"><span class="pre">None</span></code>,则该类就将不可迭代。 (由 Andrew Barnert 和 Ivan Levkivskyi 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25958">bpo-25958</a> 中贡献。)</p></li>
|
||
<li><p>由重复的回溯行组成的长序列现在将被简化为 <code class="docutils literal notranslate"><span class="pre">"[Previous</span> <span class="pre">line</span> <span class="pre">repeated</span> <span class="pre">{count}</span> <span class="pre">more</span> <span class="pre">times]"</span></code> (请参阅 <a class="reference internal" href="#whatsnew36-traceback"><span class="std std-ref">回溯</span></a> 获取样例)。 (由 Emanuel Barry 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26823">bpo-26823</a> 中贡献。)</p></li>
|
||
<li><p>现在导入操作在无法找到模块时将引发新的异常 <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#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> 的子类)。 目前 (在 try-except 中) 检测 ImportError 的代码仍将有效。 (由 Eric Snow 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=15767">bpo-15767</a> 中贡献。)</p></li>
|
||
<li><p>现在依赖于零参数形式 <code class="docutils literal notranslate"><span class="pre">super()</span></code> 的类方法在类创建期间从元类方法调用时将正确地生效。 (由 Martin Teichmann 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23722">bpo-23722</a> 中贡献。)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="new-modules">
|
||
<h2>新增模块<a class="headerlink" href="#new-modules" title="永久链接至标题">¶</a></h2>
|
||
<section id="secrets">
|
||
<span id="whatsnew36-pep506"></span><h3>secrets<a class="headerlink" href="#secrets" title="永久链接至标题">¶</a></h3>
|
||
<p>新的 <a class="reference internal" href="../library/secrets.html#module-secrets" title="secrets: Generate secure random numbers for managing secrets."><code class="xref py py-mod docutils literal notranslate"><span class="pre">secrets</span></code></a> 模块的主要目的是提供一种直观的方式来可靠地生成适用于密码管理的高加密强度的伪随机值,如账户验证、安全凭据等等。</p>
|
||
<div class="admonition warning">
|
||
<p class="admonition-title">警告</p>
|
||
<p>注意 <a class="reference internal" href="../library/random.html#module-random" title="random: Generate pseudo-random numbers with various common distributions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">random</span></code></a> 模块中的伪随机数发生器 <em>不应</em> 被用于安全目的。 请在 Python 3.6+ 上使用 <a class="reference internal" href="../library/secrets.html#module-secrets" title="secrets: Generate secure random numbers for managing secrets."><code class="xref py py-mod docutils literal notranslate"><span class="pre">secrets</span></code></a> 而在 Python 3.5 及更早的版本上使用 <a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.urandom()</span></code></a>。</p>
|
||
</div>
|
||
<div class="admonition seealso">
|
||
<p class="admonition-title">参见</p>
|
||
<dl class="simple">
|
||
<dt><span class="target" id="index-105"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0506"><strong>PEP 506</strong></a> -- Secrets模块被加入Python标准库</dt><dd><p>PEP 由 Steven D'Aprano 撰写并实现。</p>
|
||
</dd>
|
||
</dl>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
<section id="improved-modules">
|
||
<h2>改进的模块<a class="headerlink" href="#improved-modules" title="永久链接至标题">¶</a></h2>
|
||
<section id="array">
|
||
<h3>array<a class="headerlink" href="#array" title="永久链接至标题">¶</a></h3>
|
||
<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> 的迭代器将保持耗尽状态,即使迭代后的数组被扩展时也是如此。 这将与其他可变序列的行为保持一致。</p>
|
||
<p>由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26492">bpo-26492</a> 中贡献。</p>
|
||
</section>
|
||
<section id="ast">
|
||
<h3>ast<a class="headerlink" href="#ast" title="永久链接至标题">¶</a></h3>
|
||
<p>新增了 <code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Constant</span></code> AST 节点。 它可被外部 AST 优化器用于常量折叠操作。</p>
|
||
<p>由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26146">bpo-26146</a> 中贡献。</p>
|
||
</section>
|
||
<section id="asyncio">
|
||
<h3>asyncio<a class="headerlink" href="#asyncio" title="永久链接至标题">¶</a></h3>
|
||
<p>从 Python 3.6 开始 <code class="docutils literal notranslate"><span class="pre">asyncio</span></code> 模块不再处于暂定状态,其 API 被认为已经稳定。</p>
|
||
<p>自 Python 3.5.0 以来 <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> 模块中值得注意的变化(由于暂定状态所有变化都已反向移植到 3.5.x):</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">get_event_loop()</span></code></a> 函数已更改为当在例程和回调中被调用时始终返回当前正在运行的循环。(由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28613">bpo-28613</a> 中贡献。)</p></li>
|
||
<li><p><a class="reference internal" href="../library/asyncio-future.html#asyncio.ensure_future" title="asyncio.ensure_future"><code class="xref py py-func docutils literal notranslate"><span class="pre">ensure_future()</span></code></a> 函数以及所有用到它的函数,比如 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.run_until_complete" title="asyncio.loop.run_until_complete"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.run_until_complete()</span></code></a>,现在将接受所有种类的 <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">可等待对象</span></a>。 (由 Yury Selivanov 贡献。)</p></li>
|
||
<li><p>新增 <a class="reference internal" href="../library/asyncio-task.html#asyncio.run_coroutine_threadsafe" title="asyncio.run_coroutine_threadsafe"><code class="xref py py-func docutils literal notranslate"><span class="pre">run_coroutine_threadsafe()</span></code></a> 函数用于从其他线程向事件循环提交协程。(由 Vincent Michel 贡献。)</p></li>
|
||
<li><p>新增 <a class="reference internal" href="../library/asyncio-protocol.html#asyncio.BaseTransport.is_closing" title="asyncio.BaseTransport.is_closing"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Transport.is_closing()</span></code></a> 方法用于检查传输是否正在关闭或已经关闭。 (由 Yury Selivanov 贡献。)</p></li>
|
||
<li><p><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> 方法现在可以接受一个主机列表。 (由 Yann Sionneau 贡献。)</p></li>
|
||
<li><p>新增 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_future" title="asyncio.loop.create_future"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_future()</span></code></a> 方法用来创建 Future 对象。 这允许替代性的事件循环实现,比如 <a class="reference external" href="https://github.com/MagicStack/uvloop">uvloop</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?@action=redirect&bpo=27041">bpo-27041</a> 中贡献。)</p></li>
|
||
<li><p>新增 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.get_exception_handler" title="asyncio.loop.get_exception_handler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.get_exception_handler()</span></code></a> 方法用于获取当前异常处理器。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27040">bpo-27040</a> 中贡献。)</p></li>
|
||
<li><p>新增 <a class="reference internal" href="../library/asyncio-stream.html#asyncio.StreamReader.readuntil" title="asyncio.StreamReader.readuntil"><code class="xref py py-meth docutils literal notranslate"><span class="pre">StreamReader.readuntil()</span></code></a> 方法用于从流读取数据直到出现作为分隔符的字节序列。 (由 Mark Korenberg 贡献。)</p></li>
|
||
<li><p><a class="reference internal" href="../library/asyncio-stream.html#asyncio.StreamReader.readexactly" title="asyncio.StreamReader.readexactly"><code class="xref py py-meth docutils literal notranslate"><span class="pre">StreamReader.readexactly()</span></code></a> 的性能已获得提升。 (由 Mark Korenberg 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28370">bpo-28370</a> 中贡献。)</p></li>
|
||
<li><p><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> 方法已获得优化已避免当地址已被解析时调用系统 <code class="docutils literal notranslate"><span class="pre">getaddrinfo</span></code> 函数。 (由 A. Jesse Jiryu Davis 贡献。)</p></li>
|
||
<li><p><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.stop" title="asyncio.loop.stop"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.stop()</span></code></a> 方法已被更改为在当前迭代之后立即停止循环。 任何作为上次迭代的结果被加入计划任务的新回调都将被丢弃。 (由 Guido van Rossum 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25593">bpo-25593</a> 中贡献。)</p></li>
|
||
<li><p>现在 <code class="xref py py-meth docutils literal notranslate"><span class="pre">Future.set_exception</span></code> 在传入一个 <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#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>。 (由 Chris Angelico 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26221">bpo-26221</a> 中贡献。)</p></li>
|
||
<li><p>新增 <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.connect_accepted_socket()</span></code></a> 方法供接受 asyncio 以外的连接,但使用 asyncio 来处理它们的服务器使用。 (由 Jim Fulton 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27392">bpo-27392</a> 中贡献。)</p></li>
|
||
<li><p>现在 <code class="docutils literal notranslate"><span class="pre">TCP_NODELAY</span></code> 旗标将默认针对所有 TCP 传输进行设置。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27456">bpo-27456</a> 中贡献。)</p></li>
|
||
<li><p>新增 <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.shutdown_asyncgens" title="asyncio.loop.shutdown_asyncgens"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.shutdown_asyncgens()</span></code></a> 用来在结束循环之前正确地关闭现有的异步生成器。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28003">bpo-28003</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">Future</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> 类现在已有经优化过的 C 实现使得 asyncio 代码加速至多 30%。 (由 Yury Selivanov 和 INADA Naoki 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26081">bpo-26081</a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28544">bpo-28544</a> 中贡献。)</p></li>
|
||
</ul>
|
||
</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_base64" title="binascii.b2a_base64"><code class="xref py py-func docutils literal notranslate"><span class="pre">b2a_base64()</span></code></a> 函数现在接受可选的 <em>newline</em> 关键字参数用来控制是否要在返回值中添加换行符。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25357">bpo-25357</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="cmath">
|
||
<h3>cmath<a class="headerlink" href="#cmath" title="永久链接至标题">¶</a></h3>
|
||
<p>新增 <a class="reference internal" href="../library/cmath.html#cmath.tau" title="cmath.tau"><code class="xref py py-const docutils literal notranslate"><span class="pre">cmath.tau</span></code></a> (<em>τ</em>) 常量。 (由 Lisa Roach 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=12345">bpo-12345</a> 中贡献,详情见 <span class="target" id="index-106"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0628"><strong>PEP 628</strong></a>。)</p>
|
||
<p>新增常量: <a class="reference internal" href="../library/cmath.html#cmath.inf" title="cmath.inf"><code class="xref py py-const docutils literal notranslate"><span class="pre">cmath.inf</span></code></a> 和 <a class="reference internal" href="../library/cmath.html#cmath.nan" title="cmath.nan"><code class="xref py py-const docutils literal notranslate"><span class="pre">cmath.nan</span></code></a> 用于匹配 <a class="reference internal" href="../library/math.html#math.inf" title="math.inf"><code class="xref py py-const docutils literal notranslate"><span class="pre">math.inf</span></code></a> 和 <a class="reference internal" href="../library/math.html#math.nan" title="math.nan"><code class="xref py py-const docutils literal notranslate"><span class="pre">math.nan</span></code></a>,以及 <a class="reference internal" href="../library/cmath.html#cmath.infj" title="cmath.infj"><code class="xref py py-const docutils literal notranslate"><span class="pre">cmath.infj</span></code></a> 和 <a class="reference internal" href="../library/cmath.html#cmath.nanj" title="cmath.nanj"><code class="xref py py-const docutils literal notranslate"><span class="pre">cmath.nanj</span></code></a> 用于匹配由 complex 的 repr 所使用的格式。 (由 Mark Dickinson 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23229">bpo-23229</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="collections">
|
||
<h3>collections<a class="headerlink" href="#collections" title="永久链接至标题">¶</a></h3>
|
||
<p>添加了新的 <a class="reference internal" href="../library/collections.abc.html#collections.abc.Collection" title="collections.abc.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collection</span></code></a> 抽象基类用于表示有具体大小的可迭代容器类。 (由 Ivan Levkivskyi 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27598">bpo-27598</a> 中贡献并由 Neil Girdhar 撰写文档。)</p>
|
||
<p>添加了新的 <a class="reference internal" href="../library/collections.abc.html#collections.abc.Reversible" title="collections.abc.Reversible"><code class="xref py py-class docutils literal notranslate"><span class="pre">Reversible</span></code></a> 抽象基类用于表示同时提供 <a class="reference internal" href="../reference/datamodel.html#object.__reversed__" title="object.__reversed__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__reversed__()</span></code></a> 方法的可迭代类。 (由 Ivan Levkivskyi 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25987">bpo-25987</a> 中贡献。)</p>
|
||
<p>新增代表异步生成器的 <a class="reference internal" href="../library/collections.abc.html#collections.abc.AsyncGenerator" title="collections.abc.AsyncGenerator"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncGenerator</span></code></a> 抽象基类。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28720">bpo-28720</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">namedtuple()</span></code></a> 函数现在接受可选的关键字参数 <em>module</em>,当指定该参数时,它将被用作所返回的具名元组类的 <code class="docutils literal notranslate"><span class="pre">__module__</span></code> 属性。 (由 Raymond Hettinger 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=17941">bpo-17941</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">namedtuple()</span></code></a> 的 <em>verbose</em> 和 <em>rename</em> 参数现在是仅限关键字参数。 (由 Raymond Hettinger 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25628">bpo-25628</a> 中贡献。)</p>
|
||
<p>递归的 <a class="reference internal" href="../library/collections.html#collections.deque" title="collections.deque"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.deque</span></code></a> 实例现在可以被 pickle。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26482">bpo-26482</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.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ThreadPoolExecutor</span></code></a> 类构造器现在接受可选的 <em>thread_name_prefix</em> 参数以便能够自定义由线程池所创建的线程的名称。 (由 Gregory P. Smith 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27664">bpo-27664</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="contextlib">
|
||
<h3>contextlib<a class="headerlink" href="#contextlib" title="永久链接至标题">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/contextlib.html#contextlib.AbstractContextManager" title="contextlib.AbstractContextManager"><code class="xref py py-class docutils literal notranslate"><span class="pre">contextlib.AbstractContextManager</span></code></a> class has been added to
|
||
provide an abstract base class for context managers. It provides a
|
||
sensible default implementation for <cite>__enter__()</cite> which returns
|
||
<code class="docutils literal notranslate"><span class="pre">self</span></code> and leaves <cite>__exit__()</cite> an abstract method. A matching
|
||
class has been added to the <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> module as
|
||
<a class="reference internal" href="../library/typing.html#typing.ContextManager" title="typing.ContextManager"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.ContextManager</span></code></a>.
|
||
(Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25609">bpo-25609</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" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> 和 <a class="reference internal" href="../library/datetime.html#datetime.time" title="datetime.time"><code class="xref py py-class docutils literal notranslate"><span class="pre">time</span></code></a> 类新增了 <code class="xref py py-attr docutils literal notranslate"><span class="pre">fold</span></code> 属性用来在必要时消除本地时间的歧义。 在 <a class="reference internal" href="../library/datetime.html#module-datetime" title="datetime: Basic date and time types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code></a> 中的许多函数已被更新为支持本地时间的消除歧义。 请参阅 <a class="reference internal" href="#whatsnew36-pep495"><span class="std std-ref">本地时间消歧义</span></a> 一节了解更多信息。 (由 Alexander Belopolsky 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24773">bpo-24773</a> 中贡献。)</p>
|
||
<p>现在 <a class="reference internal" href="../library/datetime.html#datetime.datetime.strftime" title="datetime.datetime.strftime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.strftime()</span></code></a> 和 <a class="reference internal" href="../library/datetime.html#datetime.date.strftime" title="datetime.date.strftime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">date.strftime()</span></code></a> 方法将支持 ISO 8601 日期指令符 <code class="docutils literal notranslate"><span class="pre">%G</span></code>, <code class="docutils literal notranslate"><span class="pre">%u</span></code> 和 <code class="docutils literal notranslate"><span class="pre">%V</span></code>。 (由 Ashley Anderson 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=12006">bpo-12006</a> 中贡献。).)</p>
|
||
<p><a class="reference internal" href="../library/datetime.html#datetime.datetime.isoformat" title="datetime.datetime.isoformat"><code class="xref py py-func docutils literal notranslate"><span class="pre">datetime.isoformat()</span></code></a> 函数现在接受可选的 <em>timespec</em> 参数用来指定时间值要包括的额外组件数量。 (由 Alessandro Cucci 和 Alexander Belopolsky 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=19475">bpo-19475</a> 中贡献。)</p>
|
||
<p><a class="reference internal" href="../library/datetime.html#datetime.datetime.combine" title="datetime.datetime.combine"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.combine()</span></code></a> 现在接受可选的 <em>tzinfo</em> 参数。 (由 Alexander Belopolsky 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27661">bpo-27661</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#decimal.Decimal.as_integer_ratio" title="decimal.Decimal.as_integer_ratio"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Decimal.as_integer_ratio()</span></code></a> 方法,它返回一对整数 <code class="docutils literal notranslate"><span class="pre">(n,</span> <span class="pre">d)</span></code> 将给定的 <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">Decimal</span></code></a> 实例表示为一个最简形式且分母为正值的分数:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">Decimal</span><span class="p">(</span><span class="s1">'-3.14'</span><span class="p">)</span><span class="o">.</span><span class="n">as_integer_ratio</span><span class="p">()</span>
|
||
<span class="go">(-157, 50)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(由 Stefan Krah 和 Mark Dickinson 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25928">bpo-25928</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="distutils">
|
||
<h3>distutils<a class="headerlink" href="#distutils" title="永久链接至标题">¶</a></h3>
|
||
<p>The <code class="docutils literal notranslate"><span class="pre">default_format</span></code> attribute has been removed from
|
||
<code class="xref py py-class docutils literal notranslate"><span class="pre">distutils.command.sdist.sdist</span></code> and the <code class="docutils literal notranslate"><span class="pre">formats</span></code>
|
||
attribute defaults to <code class="docutils literal notranslate"><span class="pre">['gztar']</span></code>. Although not anticipated,
|
||
any code relying on the presence of <code class="docutils literal notranslate"><span class="pre">default_format</span></code> may
|
||
need to be adapted. See <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27819">bpo-27819</a> for more details.</p>
|
||
</section>
|
||
<section id="email">
|
||
<h3>email<a class="headerlink" href="#email" title="永久链接至标题">¶</a></h3>
|
||
<p>通过多个构造器的 <em>policy</em> 关键字来启用的新 email API 已不再为暂定状态。 <a class="reference internal" href="../library/email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a> 文档已被重新组织并重新撰写以聚集新 API,同时保留旧式 API 的原有文档。 (由 R. David Murray 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24277">bpo-24277</a> 中贡献。)</p>
|
||
<p><a class="reference internal" href="../library/email.mime.html#module-email.mime" title="email.mime: Build MIME messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.mime</span></code></a> 中的类现在都接受可选的 <em>policy</em> 关键字参数。 (由 Berker Peksag 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27331">bpo-27331</a> 中贡献。).)</p>
|
||
<p><a class="reference internal" href="../library/email.generator.html#email.generator.DecodedGenerator" title="email.generator.DecodedGenerator"><code class="xref py py-class docutils literal notranslate"><span class="pre">DecodedGenerator</span></code></a> 现在支持 <em>policy</em> 关键字。</p>
|
||
<p>新增 <a class="reference internal" href="../library/email.policy.html#module-email.policy" title="email.policy: Controlling the parsing and generating of messages"><code class="xref py py-mod docutils literal notranslate"><span class="pre">policy</span></code></a> 属性,<a class="reference internal" href="../library/email.policy.html#email.policy.Policy.message_factory" title="email.policy.Policy.message_factory"><code class="xref py py-attr docutils literal notranslate"><span class="pre">message_factory</span></code></a> 控制当解析器新建消息对象时默认要使用的类。 对于 <a class="reference internal" href="../library/email.policy.html#email.policy.compat32" title="email.policy.compat32"><code class="xref py py-attr docutils literal notranslate"><span class="pre">email.policy.compat32</span></code></a> 策略来说将为 <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a>,对于新策略来说将为 <a class="reference internal" href="../library/email.message.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailMessage</span></code></a>。 (由 R. David Murray 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=20476">bpo-20476</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="encodings">
|
||
<h3>encodings<a class="headerlink" href="#encodings" title="永久链接至标题">¶</a></h3>
|
||
<p>在 Windows 上,增加了 <code class="docutils literal notranslate"><span class="pre">'oem'</span></code> 编码格式用于 <code class="docutils literal notranslate"><span class="pre">CP_OEMCP</span></code>,以及 <code class="docutils literal notranslate"><span class="pre">'ansi'</span></code> 别名用于现有的 <code class="docutils literal notranslate"><span class="pre">'mbcs'</span></code> 编码格式,它使用 <code class="docutils literal notranslate"><span class="pre">CP_ACP</span></code> 代码页。 (由 Steve Dower 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27959">bpo-27959</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#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a> 模块中新增了两个枚举基类: <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a> 和 <code class="xref py py-class docutils literal notranslate"><span class="pre">IntFlags</span></code>。 两者均被用于定义可使用按位运算符进行组合的常量。 (由 Ethan Furman 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23591">bpo-23591</a> 中贡献。)</p>
|
||
<p>许多标准库模块已被更新以使用 <code class="xref py py-class docutils literal notranslate"><span class="pre">IntFlags</span></code> 类作为其常量。</p>
|
||
<p>新增的 <a class="reference internal" href="../library/enum.html#enum.auto" title="enum.auto"><code class="xref py py-class docutils literal notranslate"><span class="pre">enum.auto</span></code></a> 值可被用于自动为枚举成员赋值:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="kn">from</span> <span class="nn">enum</span> <span class="kn">import</span> <span class="n">Enum</span><span class="p">,</span> <span class="n">auto</span>
|
||
<span class="gp">>>> </span><span class="k">class</span> <span class="nc">Color</span><span class="p">(</span><span class="n">Enum</span><span class="p">):</span>
|
||
<span class="gp">... </span> <span class="n">red</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span>
|
||
<span class="gp">... </span> <span class="n">blue</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span>
|
||
<span class="gp">... </span> <span class="n">green</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="nb">list</span><span class="p">(</span><span class="n">Color</span><span class="p">)</span>
|
||
<span class="go">[<Color.red: 1>, <Color.blue: 2>, <Color.green: 3>]</span>
|
||
</pre></div>
|
||
</div>
|
||
</section>
|
||
<section id="faulthandler">
|
||
<h3>faulthandler<a class="headerlink" href="#faulthandler" title="永久链接至标题">¶</a></h3>
|
||
<p>在 Windows 上,<a class="reference internal" href="../library/faulthandler.html#module-faulthandler" title="faulthandler: Dump the Python traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code></a> 模块现在会为 Windows 异常安装处理器:参见 <a class="reference internal" href="../library/faulthandler.html#faulthandler.enable" title="faulthandler.enable"><code class="xref py py-func docutils literal notranslate"><span class="pre">faulthandler.enable()</span></code></a>。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23848">bpo-23848</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="fileinput">
|
||
<h3>fileinput<a class="headerlink" href="#fileinput" title="永久链接至标题">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/fileinput.html#fileinput.hook_encoded" title="fileinput.hook_encoded"><code class="xref py py-func docutils literal notranslate"><span class="pre">hook_encoded()</span></code></a> 现在支持 <em>errors</em> 参数。 (由 Joseph Hackman 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25788">bpo-25788</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="hashlib">
|
||
<h3>hashlib<a class="headerlink" href="#hashlib" title="永久链接至标题">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> 已支持 OpenSSL 1.1.0。 最低的建议版本为 1.0.2。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26470">bpo-26470</a> 中贡献。)</p>
|
||
<p>本模块增加了 BLAKE2 哈希函数。 <a class="reference internal" href="../library/hashlib.html#hashlib.blake2b" title="hashlib.blake2b"><code class="xref py py-func docutils literal notranslate"><span class="pre">blake2b()</span></code></a> 和 <a class="reference internal" href="../library/hashlib.html#hashlib.blake2s" title="hashlib.blake2s"><code class="xref py py-func docutils literal notranslate"><span class="pre">blake2s()</span></code></a> 将始终可用并支持 BLAKE2 的完整特性集。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26798">bpo-26798</a> 中基于 Dmitry Chestnykh 和 Samuel Neves 的代码贡献。 文档由 Dmitry Chestnykh 撰写。)</p>
|
||
<p>增加了 SHA-3 哈希函数 <code class="xref py py-func docutils literal notranslate"><span class="pre">sha3_224()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">sha3_256()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">sha3_384()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">sha3_512()</span></code>,以及 SHAKE 哈希函数 <code class="xref py py-func docutils literal notranslate"><span class="pre">shake_128()</span></code> 和 <code class="xref py py-func docutils literal notranslate"><span class="pre">shake_256()</span></code>。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=16113">bpo-16113</a> 中贡献。 Keccak 代码包由 Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche 和 Ronny Van Keer 编写。)</p>
|
||
<p>基于密码的密钥推导函数 <a class="reference internal" href="../library/hashlib.html#hashlib.scrypt" title="hashlib.scrypt"><code class="xref py py-func docutils literal notranslate"><span class="pre">scrypt()</span></code></a> 现可用于 OpenSSL 1.1.0 及更新版本。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27928">bpo-27928</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.request" title="http.client.HTTPConnection.request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HTTPConnection.request()</span></code></a> 和 <a class="reference internal" href="../library/http.client.html#http.client.HTTPConnection.endheaders" title="http.client.HTTPConnection.endheaders"><code class="xref py py-meth docutils literal notranslate"><span class="pre">endheaders()</span></code></a> 现在都支持分块编码格式请求体。 (由 Demian Brecht 和 Rolf Krahl 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=12319">bpo-12319</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="idlelib-and-idle">
|
||
<h3>idlelib 与 IDLE<a class="headerlink" href="#idlelib-and-idle" title="永久链接至标题">¶</a></h3>
|
||
<p>对 idlelib 包执行现代化和重构以使 IDLE 的外观和功能更好并使代码更易于理解、测试和改进。 让 IDLE 外观更好的部分工作,尤其是在 Linux 和 Mac 上,在于使用了 ttk 部件,主要是在对话框中。 因此,IDLE 不再使用 tcl/tk 8.4。 现在它需要 tcl/tk 8.5 或 8.6。 我们建议运行这两个软件的最新发布版。</p>
|
||
<p>‘现代化’包括 idlelib 模块的重命名与合并。 对具有部分大写名称的文件的重命名类似于 3.0 中将 Tkinter 和 TkFont 重命名为 tkinter 和 tkinter.font。 因此,在 3.5 中可用的 idlelib 文件导入在 3.6 中通常将不再可用。 至少需要修改模块名称(参见 idlelib/README.txt),有时还需要更多修改。 (名称更改由 Al Swiegart 和 Terry Reedy 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24225">bpo-24225</a> 中贡献。 大多数 idlelib 补丁都是已经是或即将纳入该处理过程。)</p>
|
||
<p>作为补偿,最终的结果是一些 idlelib 类将更会易于使用,并有更好的 API 和文档字符串加以说明。 附加的有用信息准备好后将被添加到 idlelib 中。</p>
|
||
<p>在 3.6.2 中新增:</p>
|
||
<p>多个对自动补全的修正。 (由 Louie Lu 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=15786">bpo-15786</a> 中贡献。)</p>
|
||
<p>在 3.6.3 中新增:</p>
|
||
<p>Module Browser (在 File 菜单中,之前称为 Class Browser) 现在会在最高层级函数和类之外显示嵌套的函数和类。 (由 Guilherme Polo, Cheryl Sabella 和 Terry Jan Reedy 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=1612262">bpo-1612262</a> 中贡献。)</p>
|
||
<p>之前以扩展形式实现的 IDLE 特性已作为正常特性重新实现。 它们的设置已从 Extensions 选项卡移至其他对话框选项卡。 (由 Charles Wohlganger 和 Terry Jan Reedy 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27099">bpo-27099</a> 中实现。)</p>
|
||
<p>Settings 对话框 (Options 中的 Configure IDLE) 已经被部分重写以改进外观和功能。 (由 Cheryl Sabella 和 Terry Jan Reedy 在多个问题项中贡献。)</p>
|
||
<p>在 3.6.4 中新增:</p>
|
||
<p>字体样本现在包括一组非拉丁字符以便用户能更好地查看所选特定字体的效果。 (由 Terry Jan Reedy 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=13802">bpo-13802</a> 中贡献。) 样本可以被修改以包括其他字符。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=31860">bpo-31860</a> 中贡献。)</p>
|
||
<p>在 3.6.6 中新增:</p>
|
||
<p>编辑器代码上下文选项已经过修改。 Box 会显示所有上下文行直到最大行数。 点击一个上下文行会使编辑器跳转到该行。 自定义主题的上下文颜色已添加到 Settings 对话框的 Highlights 选项卡。 (由 Cheryl Sabella 和 Terry Jan Reedy 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33642">bpo-33642</a>, <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=33768">bpo-33768</a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&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?@action=redirect&bpo=33656">bpo-33656</a> 中贡献。)</p>
|
||
<p>在 3.6.7 中新增:</p>
|
||
<p>超过 N 行(默认值为 50)的输出将被折叠为一个按钮。 N 可以在 Settings 对话框的 General 页的 PyShell 部分中进行修改。 数量较少但是超长的行可以通过在输出上右击来折叠。 被折叠的输出可通过双击按钮来展开,或是通过右击按钮来放入剪贴板或是单独的窗口。 (由 Tal Einat 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=1529353">bpo-1529353</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="importlib">
|
||
<h3>importlib<a class="headerlink" href="#importlib" title="永久链接至标题">¶</a></h3>
|
||
<p>现在导入操作在无法找到模块时将引发新的异常 <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#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> 的子类)。 目前 (在 try-except 中) 检测 <code class="docutils literal notranslate"><span class="pre">ImportError</span></code> 的代码仍将有效。 (由 Eric Snow 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=15767">bpo-15767</a> 中贡献。)</p>
|
||
<p><a class="reference internal" href="../library/importlib.html#importlib.util.LazyLoader" title="importlib.util.LazyLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.util.LazyLoader</span></code></a> 现在将调用被包装的加载器上的 <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.create_module" title="importlib.abc.Loader.create_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_module()</span></code></a>,移除了 <a class="reference internal" href="../library/importlib.html#importlib.machinery.BuiltinImporter" title="importlib.machinery.BuiltinImporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.BuiltinImporter</span></code></a> 和 <a class="reference internal" href="../library/importlib.html#importlib.machinery.ExtensionFileLoader" title="importlib.machinery.ExtensionFileLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.ExtensionFileLoader</span></code></a> 不能用于 <a class="reference internal" href="../library/importlib.html#importlib.util.LazyLoader" title="importlib.util.LazyLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.util.LazyLoader</span></code></a> 的限制。</p>
|
||
<p><a class="reference internal" href="../library/importlib.html#importlib.util.cache_from_source" title="importlib.util.cache_from_source"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.cache_from_source()</span></code></a>, <a class="reference internal" href="../library/importlib.html#importlib.util.source_from_cache" title="importlib.util.source_from_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.source_from_cache()</span></code></a> 和 <a class="reference internal" href="../library/importlib.html#importlib.util.spec_from_file_location" title="importlib.util.spec_from_file_location"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.spec_from_file_location()</span></code></a> 现在将接受 <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>。</p>
|
||
</section>
|
||
<section id="inspect">
|
||
<h3>inspect<a class="headerlink" href="#inspect" title="永久链接至标题">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.signature()</span></code></a> 函数现在会报告编译器为推导式和生成器表达式作用域生成的隐式 <code class="docutils literal notranslate"><span class="pre">.0</span></code> 形参,就像它们是调用``implicit0`` 时的仅限位置形参一样。 (由 Jelle Zijlstra 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=19611">bpo-19611</a> 中贡献。)</p>
|
||
<p>为了减少从 Python 2.7 和旧式 <a class="reference internal" href="../library/inspect.html#inspect.getargspec" title="inspect.getargspec"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getargspec()</span></code></a> API 升级时的代码问题,先前被写入文档的对 <a class="reference internal" href="../library/inspect.html#inspect.getfullargspec" title="inspect.getfullargspec"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getfullargspec()</span></code></a> 的弃用已被撤销。 虽然这个函数对于单/源 Python 2/3 代码库来说很方便,但对于新代码来说功能更丰富的 <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.signature()</span></code></a> 接口仍然是推荐的方式。 (由 Nick Coghlan 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27172">bpo-27172</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="json">
|
||
<h3>json<a class="headerlink" href="#json" title="永久链接至标题">¶</a></h3>
|
||
<p>现在 <a class="reference internal" href="../library/json.html#json.load" title="json.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.load()</span></code></a> 和 <a class="reference internal" href="../library/json.html#json.loads" title="json.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.loads()</span></code></a> 均支持二进制输入。 已编码的 JSON 应当使用 UTF-8, UTF-16 或 UTF-32 来表示。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=17909">bpo-17909</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="logging">
|
||
<h3>logging<a class="headerlink" href="#logging" title="永久链接至标题">¶</a></h3>
|
||
<p>新增 <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.WatchedFileHandler.reopenIfNeeded" title="logging.handlers.WatchedFileHandler.reopenIfNeeded"><code class="xref py py-meth docutils literal notranslate"><span class="pre">WatchedFileHandler.reopenIfNeeded()</span></code></a> 方法以添加检测日志文件是否需要被重新打开的能力。 (由 Marian Horban 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24884">bpo-24884</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#module-math" title="math: Mathematical functions (sin() etc.)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">math</span></code></a> 和 <a class="reference internal" href="../library/cmath.html#module-cmath" title="cmath: Mathematical functions for complex numbers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">cmath</span></code></a> 模块增加了 tau (<em>τ</em>) 常量。 (由 Lisa Roach 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=12345">bpo-12345</a> 中贡献,详情见 <span class="target" id="index-107"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0628"><strong>PEP 628</strong></a>。)</p>
|
||
</section>
|
||
<section id="multiprocessing">
|
||
<h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="永久链接至标题">¶</a></h3>
|
||
<p>由 <code class="xref py py-func docutils literal notranslate"><span class="pre">multiprocessing.Manager()</span></code> 返回的 <a class="reference internal" href="../library/multiprocessing.html#multiprocessing-proxy-objects"><span class="std std-ref">代理对象</span></a> 现在可以被嵌套。 (由 Davin Potts 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=6766">bpo-6766</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="os">
|
||
<h3>os<a class="headerlink" href="#os" title="永久链接至标题">¶</a></h3>
|
||
<p>请参阅 <a class="reference internal" href="#whatsnew36-pep519"><span class="std std-ref">PEP 519</span></a> 的概览了解现在 <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> 和 <a class="reference internal" href="../library/os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> 模块如何支持 <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">路径型对象</span></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">scandir()</span></code></a> 支持 Windows 上的 <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> 路径。</p>
|
||
<p>新增的 <a class="reference internal" href="../library/os.html#os.scandir.close" title="os.scandir.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</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">scandir()</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">scandir()</span></code></a> 迭代器现在支持 <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> 协议。 如果一个 <code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code> 迭代器既没有被耗尽也没有被显式地关闭则会在其析构器中发出 <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a>。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25994">bpo-25994</a> 中贡献。)</p>
|
||
<p>在 Linux 上,现在 <a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.urandom()</span></code></a> 会阻塞直到系统的 urandom 熵池被初始化以提升安全性。 其理由参见 <span class="target" id="index-108"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0524"><strong>PEP 524</strong></a>。</p>
|
||
<p>Linux <code class="docutils literal notranslate"><span class="pre">getrandom()</span></code> 系统调用(获取随机字节数据)现在被暴露为新的 <a class="reference internal" href="../library/os.html#os.getrandom" title="os.getrandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.getrandom()</span></code></a> 函数。 (由 Victor Stinner 贡献,为 <span class="target" id="index-109"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0524"><strong>PEP 524</strong></a> 的一部分)</p>
|
||
</section>
|
||
<section id="pathlib">
|
||
<h3>pathlib<a class="headerlink" href="#pathlib" title="永久链接至标题">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> 现在支持 <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">路径型对象</span></a>。 (由 Brett Cannon 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27186">bpo-27186</a> 中贡献。)</p>
|
||
<p>请参阅 <a class="reference internal" href="#whatsnew36-pep519"><span class="std std-ref">PEP 519</span></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.Pdb" title="pdb.Pdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pdb</span></code></a> 类构造器新增可选的 <em>readrc</em> 参数用来控制是否应当读取 <code class="docutils literal notranslate"><span class="pre">.pdbrc</span></code> 文件。</p>
|
||
</section>
|
||
<section id="pickle">
|
||
<h3>pickle<a class="headerlink" href="#pickle" title="永久链接至标题">¶</a></h3>
|
||
<p>需要附带关键字参数调用 <code class="docutils literal notranslate"><span class="pre">__new__</span></code> 的对象现在可以使用早于协议版本 4 的 <a class="reference internal" href="../library/pickle.html#pickle-protocols"><span class="std std-ref">pickle 协议</span></a> 来 pickle。 协议版本 4 之前已支持此场景。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24164">bpo-24164</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="pickletools">
|
||
<h3>pickletools<a class="headerlink" href="#pickletools" title="永久链接至标题">¶</a></h3>
|
||
<p>现在 <a class="reference internal" href="../library/pickletools.html#pickletools.dis" title="pickletools.dis"><code class="xref py py-func docutils literal notranslate"><span class="pre">pickletools.dis()</span></code></a> 将为 <code class="docutils literal notranslate"><span class="pre">MEMOIZE</span></code> 操作码输出隐式的 memo 索引。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25382">bpo-25382</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="pydoc">
|
||
<h3>pydoc<a class="headerlink" href="#pydoc" title="永久链接至标题">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> 模块将能遵守 <code class="docutils literal notranslate"><span class="pre">MANPAGER</span></code> 环境变量的设置。 (由 Matthias Klose 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=8637">bpo-8637</a> 中贡献。)</p>
|
||
<p><a class="reference internal" href="../library/functions.html#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a> 和 <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> 现在将以具名元组字段被定义的顺序而非字母顺序列出它们。 (由 Raymond Hettinger 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24879">bpo-24879</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="random">
|
||
<h3>random<a class="headerlink" href="#random" title="永久链接至标题">¶</a></h3>
|
||
<p>新增 <a class="reference internal" href="../library/random.html#random.choices" title="random.choices"><code class="xref py py-func docutils literal notranslate"><span class="pre">choices()</span></code></a> 函数用于从给定的总体中返回指定大小的元素列表并有可选权重。 (由 Raymond Hettinger 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=18844">bpo-18844</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="re">
|
||
<h3>re<a class="headerlink" href="#re" title="永久链接至标题">¶</a></h3>
|
||
<p>在正则表达式中增加了对修饰符区段的支持。 示例: <code class="docutils literal notranslate"><span class="pre">'(?i:p)ython'</span></code> 匹配 <code class="docutils literal notranslate"><span class="pre">'python'</span></code> 和 <code class="docutils literal notranslate"><span class="pre">'Python'</span></code>,但不匹配 <code class="docutils literal notranslate"><span class="pre">'PYTHON'</span></code>;<code class="docutils literal notranslate"><span class="pre">'(?i)g(?-i:v)r'</span></code> 匹配 <code class="docutils literal notranslate"><span class="pre">'GvR'</span></code> 和 <code class="docutils literal notranslate"><span class="pre">'gvr'</span></code>,但不匹配 <code class="docutils literal notranslate"><span class="pre">'GVR'</span></code>。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=433028">bpo-433028</a> 中贡献。)</p>
|
||
<p>Match 对象分组可通过 <code class="docutils literal notranslate"><span class="pre">__getitem__</span></code> 来访问,这等价于 <code class="docutils literal notranslate"><span class="pre">group()</span></code>。 因此 <code class="docutils literal notranslate"><span class="pre">mo['name']</span></code> 现在将等价于 <code class="docutils literal notranslate"><span class="pre">mo.group('name')</span></code>。 (由 Eric Smith 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24454">bpo-24454</a> 中贡献。)</p>
|
||
<p><code class="xref py py-class docutils literal notranslate"><span class="pre">Match</span></code> 对象现在支持将 <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> 作为分组索引。 (由 Jeroen Demeyer 和 Xiang Zhang 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27177">bpo-27177</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="readline">
|
||
<h3>readline<a class="headerlink" href="#readline" title="永久链接至标题">¶</a></h3>
|
||
<p>新增 <a class="reference internal" href="../library/readline.html#readline.set_auto_history" title="readline.set_auto_history"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_auto_history()</span></code></a> 来启用或禁用历史列表输入的自动添加。 (由 Tyler Crompton 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26870">bpo-26870</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="rlcompleter">
|
||
<h3>rlcompleter<a class="headerlink" href="#rlcompleter" title="永久链接至标题">¶</a></h3>
|
||
<p>私有和特殊属性名称现在会被省略除非带有以下划线开头的前缀。 在某些已完成的关键字后会加上空格或冒号。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25011">bpo-25011</a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25209">bpo-25209</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="shlex">
|
||
<h3>shlex<a class="headerlink" href="#shlex" title="永久链接至标题">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/shlex.html#shlex.shlex" title="shlex.shlex"><code class="xref py py-class docutils literal notranslate"><span class="pre">shlex</span></code></a> 通过新的 <em>punctuation_chars</em> 参数来控制哪些字符会被当作标点符号大幅度地 <a class="reference internal" href="../library/shlex.html#improved-shell-compatibility"><span class="std std-ref">改进了 shell 兼容性</span></a>。 (由 Vinay Sajip 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=1521950">bpo-1521950</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="site">
|
||
<h3>site<a class="headerlink" href="#site" title="永久链接至标题">¶</a></h3>
|
||
<p>When specifying paths to add to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.path</span></code></a> in a <cite>.pth</cite> file,
|
||
you may now specify file paths on top of directories (e.g. zip files).
|
||
(Contributed by Wolfgang Langner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26587">bpo-26587</a>).</p>
|
||
</section>
|
||
<section id="sqlite3">
|
||
<h3>sqlite3<a class="headerlink" href="#sqlite3" title="永久链接至标题">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/sqlite3.html#sqlite3.Cursor.lastrowid" title="sqlite3.Cursor.lastrowid"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sqlite3.Cursor.lastrowid</span></code></a> 现在支持 <code class="docutils literal notranslate"><span class="pre">REPLACE</span></code> 语句。 (由 Alex LordThorsen 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=16864">bpo-16864</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="socket">
|
||
<h3>socket<a class="headerlink" href="#socket" title="永久链接至标题">¶</a></h3>
|
||
<p>The <a class="reference internal" href="../library/socket.html#socket.socket.ioctl" title="socket.socket.ioctl"><code class="xref py py-func docutils literal notranslate"><span class="pre">ioctl()</span></code></a> function now supports the
|
||
<a class="reference internal" href="../library/socket.html#socket.SIO_LOOPBACK_FAST_PATH" title="socket.SIO_LOOPBACK_FAST_PATH"><code class="xref py py-data docutils literal notranslate"><span class="pre">SIO_LOOPBACK_FAST_PATH</span></code></a> control code.
|
||
(Contributed by Daniel Stokes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26536">bpo-26536</a>.)</p>
|
||
<p><a class="reference internal" href="../library/socket.html#socket.socket.getsockopt" title="socket.socket.getsockopt"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getsockopt()</span></code></a> 常量 <code class="docutils literal notranslate"><span class="pre">SO_DOMAIN</span></code>, <code class="docutils literal notranslate"><span class="pre">SO_PROTOCOL</span></code>, <code class="docutils literal notranslate"><span class="pre">SO_PEERSEC</span></code> 和 <code class="docutils literal notranslate"><span class="pre">SO_PASSSEC</span></code> 现在已得到支持。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26907">bpo-26907</a> 中贡献。)</p>
|
||
<p><a class="reference internal" href="../library/socket.html#socket.socket.setsockopt" title="socket.socket.setsockopt"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setsockopt()</span></code></a> 现在支持 <code class="docutils literal notranslate"><span class="pre">setsockopt(level,</span> <span class="pre">optname,</span> <span class="pre">None,</span> <span class="pre">optlen:</span> <span class="pre">int)</span></code> 的形式。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27744">bpo-27744</a> 中贡献。)</p>
|
||
<p>The socket module now supports the address family
|
||
<a class="reference internal" href="../library/socket.html#socket.AF_ALG" title="socket.AF_ALG"><code class="xref py py-data docutils literal notranslate"><span class="pre">AF_ALG</span></code></a> to interface with Linux Kernel crypto API. <code class="docutils literal notranslate"><span class="pre">ALG_*</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">SOL_ALG</span></code> and <a class="reference internal" href="../library/socket.html#socket.socket.sendmsg_afalg" title="socket.socket.sendmsg_afalg"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sendmsg_afalg()</span></code></a> were added.
|
||
(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27744">bpo-27744</a> with support from
|
||
Victor Stinner.)</p>
|
||
<p>New Linux constants <code class="docutils literal notranslate"><span class="pre">TCP_USER_TIMEOUT</span></code> and <code class="docutils literal notranslate"><span class="pre">TCP_CONGESTION</span></code> were added.
|
||
(Contributed by Omar Sandoval, issue:<cite>26273</cite>).</p>
|
||
</section>
|
||
<section id="socketserver">
|
||
<h3>socketserver<a class="headerlink" href="#socketserver" title="永久链接至标题">¶</a></h3>
|
||
<p>基于 <a class="reference internal" href="../library/socketserver.html#module-socketserver" title="socketserver: A framework for network servers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socketserver</span></code></a> 模块的服务器,包括在 <a class="reference internal" href="../library/http.server.html#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a>、<a class="reference internal" href="../library/xmlrpc.server.html#module-xmlrpc.server" title="xmlrpc.server: Basic XML-RPC server implementations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpc.server</span></code></a> 和 <a class="reference internal" href="../library/wsgiref.html#module-wsgiref.simple_server" title="wsgiref.simple_server: A simple WSGI HTTP server."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.simple_server</span></code></a> 中定义的服务器,现在都支持 <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> 协议。(由 Aviv Palivoda 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26404">bpo-26404</a> 中贡献。)</p>
|
||
<p><a class="reference internal" href="../library/socketserver.html#socketserver.StreamRequestHandler" title="socketserver.StreamRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">StreamRequestHandler</span></code></a> 类的 <code class="xref py py-attr docutils literal notranslate"><span class="pre">wfile</span></code> 属性现在实现了 <a class="reference internal" href="../library/io.html#io.BufferedIOBase" title="io.BufferedIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.BufferedIOBase</span></code></a> 可写接口。 特别地,现在调用 <a class="reference internal" href="../library/io.html#io.BufferedIOBase.write" title="io.BufferedIOBase.write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code></a> 会保证完整地发送数据。 (由 Martin Panter 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26721">bpo-26721</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 1.1.0。 最低的建议版本为 1.0.2。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26470">bpo-26470</a> 中贡献。)</p>
|
||
<p>已从默认的密码套件中删除 3DES 并添加了 ChaCha20 Poly1305 密码套件。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27850">bpo-27850</a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27766">bpo-27766</a> 中贡献。)</p>
|
||
<p><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> 已具有更好的选项和密码配置。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28043">bpo-28043</a> 中贡献。).)</p>
|
||
<p>SSL 会话可以通过新的 <a class="reference internal" href="../library/ssl.html#ssl.SSLSession" title="ssl.SSLSession"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLSession</span></code></a> 类从一个客户端连接复制到另一个。 TLS 会话恢复可以加快初始握手过程、减少延迟并提升性能。 (由 Christian Heimes 根据 Alex Warhawk 的草案在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=19500">bpo-19500</a> 中贡献。)</p>
|
||
<p>新的 <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.get_ciphers" title="ssl.SSLContext.get_ciphers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_ciphers()</span></code></a> 方法可被用来获取按密码优先级排序的已启用密码列表。</p>
|
||
<p>所有常量和旗标都已被转换为 <a class="reference internal" href="../library/enum.html#enum.IntEnum" title="enum.IntEnum"><code class="xref py py-class docutils literal notranslate"><span class="pre">IntEnum</span></code></a> 和 <code class="xref py py-class docutils literal notranslate"><span class="pre">IntFlags</span></code>。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28025">bpo-28025</a> 中贡献。)</p>
|
||
<p>为 <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> 添加了服务器和客户端专属的 TLS 协议。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28085">bpo-28085</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="statistics">
|
||
<h3>statistics<a class="headerlink" href="#statistics" title="永久链接至标题">¶</a></h3>
|
||
<p>新增 <a class="reference internal" href="../library/statistics.html#statistics.harmonic_mean" title="statistics.harmonic_mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">harmonic_mean()</span></code></a> 函数。 (由 Steven D'Aprano 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27181">bpo-27181</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="struct">
|
||
<h3>struct<a class="headerlink" href="#struct" title="永久链接至标题">¶</a></h3>
|
||
<p>现在 <a class="reference internal" href="../library/struct.html#module-struct" title="struct: Interpret bytes as packed binary data."><code class="xref py py-mod docutils literal notranslate"><span class="pre">struct</span></code></a> 可通过 <code class="docutils literal notranslate"><span class="pre">'e'</span></code> 格式说明符支持 IEEE 754 半精度浮点数。 (由 Eli Stevens 和 Mark Dickinson 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=11734">bpo-11734</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.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a> 析构器会在子进程仍然运行时发出 <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a> 警告。 请使用上下文管理器协议 (<code class="docutils literal notranslate"><span class="pre">with</span> <span class="pre">proc:</span> <span class="pre">...</span></code>) 或显式地调用 <a class="reference internal" href="../library/subprocess.html#subprocess.Popen.wait" title="subprocess.Popen.wait"><code class="xref py py-meth docutils literal notranslate"><span class="pre">wait()</span></code></a> 方法来读取子进程的退出状态。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26741">bpo-26741</a> 中贡献。)</p>
|
||
<p><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>encoding</em> 和 <em>errors</em> 参数。 指定这两者中的任何一个都将为 <em>stdin</em>, <em>stdout</em> 和 <em>stderr</em> 流启用文本模式。 (由 Steve Dower 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=6135">bpo-6135</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.getfilesystemencodeerrors" title="sys.getfilesystemencodeerrors"><code class="xref py py-func docutils literal notranslate"><span class="pre">getfilesystemencodeerrors()</span></code></a> 函数可返回在 Unicode 文件名和 bytes 文件名之间进行转换时使用的错误模式的名称。 (由 Steve Dower 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27781">bpo-27781</a> 中贡献。)</p>
|
||
<p>在 Windows 上 <a class="reference internal" href="../library/sys.html#sys.getwindowsversion" title="sys.getwindowsversion"><code class="xref py py-func docutils literal notranslate"><span class="pre">getwindowsversion()</span></code></a> 函数的返回值现在将包括 <em>platform_version</em> 字段,该字段包含当前操作系统准确的主版本、次版本和构建版本号,而不是进行所模拟的版本信息。 (由 Steve Dower 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27932">bpo-27932</a> 中提供贡献。)</p>
|
||
</section>
|
||
<section id="telnetlib">
|
||
<h3>telnetlib<a class="headerlink" href="#telnetlib" title="永久链接至标题">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/telnetlib.html#telnetlib.Telnet" title="telnetlib.Telnet"><code class="xref py py-class docutils literal notranslate"><span class="pre">Telnet</span></code></a> 现在是一个上下文管理器。 (由 Stéphane Wirtel 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25485">bpo-25485</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="time">
|
||
<h3>time<a class="headerlink" href="#time" title="永久链接至标题">¶</a></h3>
|
||
<p>现在 <a class="reference internal" href="../library/time.html#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> 的属性 <code class="xref py py-attr docutils literal notranslate"><span class="pre">tm_gmtoff</span></code> 和 <code class="xref py py-attr docutils literal notranslate"><span class="pre">tm_zone</span></code> 在所有平台上均可用。</p>
|
||
</section>
|
||
<section id="timeit">
|
||
<h3>timeit<a class="headerlink" href="#timeit" title="永久链接至标题">¶</a></h3>
|
||
<p>新增的 <a class="reference internal" href="../library/timeit.html#timeit.Timer.autorange" title="timeit.Timer.autorange"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Timer.autorange()</span></code></a> 便捷方法会重复调用 <a class="reference internal" href="../library/timeit.html#timeit.Timer.timeit" title="timeit.Timer.timeit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Timer.timeit()</span></code></a> 以使总运行时间大于等于 200 毫秒。 (由 Steven D'Aprano 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=6422">bpo-6422</a> 中贡献。)</p>
|
||
<p>现在 <a class="reference internal" href="../library/timeit.html#module-timeit" title="timeit: Measure the execution time of small code snippets."><code class="xref py py-mod docutils literal notranslate"><span class="pre">timeit</span></code></a> 在最佳时间和最差时间之间存在显著(4 倍)差异时将会发出警告。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23552">bpo-23552</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="tkinter">
|
||
<h3>tkinter<a class="headerlink" href="#tkinter" title="永久链接至标题">¶</a></h3>
|
||
<p>在 <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.Variable</span></code> 类中添加了方法 <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_add()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_remove()</span></code> 和 <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_info()</span></code>。 它们取代了使用过时 Tcl 命令的旧方法 <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_variable()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_vdelete()</span></code> 和 <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_vinfo()</span></code>,旧方法在未来版本的 Tcl 中可能会无法使用。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=22115">bpo-22115</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="traceback">
|
||
<span id="whatsnew36-traceback"></span><h3>回溯<a class="headerlink" href="#traceback" title="永久链接至标题">¶</a></h3>
|
||
<p>traceback 模块和解释器的内置异常显示现在都会对回溯中重复行的长序列进行缩写,如下面的例子所示:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="k">def</span> <span class="nf">f</span><span class="p">():</span> <span class="n">f</span><span class="p">()</span>
|
||
<span class="gp">...</span>
|
||
<span class="gp">>>> </span><span class="n">f</span><span class="p">()</span>
|
||
<span class="gt">Traceback (most recent call last):</span>
|
||
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n"><module></span>
|
||
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n">f</span>
|
||
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n">f</span>
|
||
File <span class="nb">"<stdin>"</span>, line <span class="m">1</span>, in <span class="n">f</span>
|
||
<span class="gr"> [Previous line repeated 995 more times]</span>
|
||
<span class="gr">RecursionError</span>: <span class="n">maximum recursion depth exceeded</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>(由 Emanuel Barry在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26823">bpo-26823</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#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a> 模块现在支持跟踪在多个不同地址空间中的内存分配情况。</p>
|
||
<p>新增 <a class="reference internal" href="../library/tracemalloc.html#tracemalloc.DomainFilter" title="tracemalloc.DomainFilter"><code class="xref py py-class docutils literal notranslate"><span class="pre">DomainFilter</span></code></a> 过滤器类用于按地址空间(域)过滤块跟踪信息。</p>
|
||
<p>(由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26588">bpo-26588</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="typing">
|
||
<span id="whatsnew36-typing"></span><h3>typing<a class="headerlink" href="#typing" title="永久链接至标题">¶</a></h3>
|
||
<p>由于 <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> 模块处于 <a class="reference internal" href="../glossary.html#term-provisional-api"><span class="xref std std-term">暂定状态</span></a>,在 Python 3.6 中引入的所有改变都已被反向移植到 Python 3.5.x。</p>
|
||
<p><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> 模块对泛型类别名的支持得到大幅改进。 例如 <code class="docutils literal notranslate"><span class="pre">Dict[str,</span> <span class="pre">Tuple[S,</span> <span class="pre">T]]</span></code> 现在将是有效的类型标注。 (由 Guido van Rossum 在 <a class="reference external" href="https://github.com/python/typing/pull/195">Github #195 中贡献</a>。)</p>
|
||
<p>增加 <a class="reference internal" href="../library/typing.html#typing.ContextManager" title="typing.ContextManager"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.ContextManager</span></code></a> 类用来表示 <a class="reference internal" href="../library/contextlib.html#contextlib.AbstractContextManager" title="contextlib.AbstractContextManager"><code class="xref py py-class docutils literal notranslate"><span class="pre">contextlib.AbstractContextManager</span></code></a>。 (由 Brett Cannon 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25609">bpo-25609</a> 中贡献。)</p>
|
||
<p>增加 <a class="reference internal" href="../library/typing.html#typing.Collection" title="typing.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Collection</span></code></a> 类用来表示 <a class="reference internal" href="../library/collections.abc.html#collections.abc.Collection" title="collections.abc.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Collection</span></code></a>。 (由 Ivan Levkivskyi 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27598">bpo-27598</a> 中贡献。)</p>
|
||
<p>增加 <a class="reference internal" href="../library/typing.html#typing.ClassVar" title="typing.ClassVar"><code class="xref py py-const docutils literal notranslate"><span class="pre">typing.ClassVar</span></code></a> 类型结构体用来标记类变量。 变量标注在 <span class="target" id="index-110"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0526"><strong>PEP 526</strong></a> 中被引入,包装在 ClassVar 中的变量标注表示给定的属性将被用作类变量而不应在该类的实例上设置。 (由 Ivan Levkivskyi 在 <a class="reference external" href="https://github.com/python/typing/pull/280">Github #280 中贡献</a>。)</p>
|
||
<p>新增 <a class="reference internal" href="../library/typing.html#typing.TYPE_CHECKING" title="typing.TYPE_CHECKING"><code class="xref py py-const docutils literal notranslate"><span class="pre">TYPE_CHECKING</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>。 (由 Guido van Rossum 在 <a class="reference external" href="https://github.com/python/typing/issues/230">Github #230 中贡献</a>。)</p>
|
||
<p>新增 <a class="reference internal" href="../library/typing.html#typing.NewType" title="typing.NewType"><code class="xref py py-func docutils literal notranslate"><span class="pre">NewType()</span></code></a> 辅助函数用来创建针对标注的轻量级单独类型:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">NewType</span>
|
||
|
||
<span class="n">UserId</span> <span class="o">=</span> <span class="n">NewType</span><span class="p">(</span><span class="s1">'UserId'</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
|
||
<span class="n">some_id</span> <span class="o">=</span> <span class="n">UserId</span><span class="p">(</span><span class="mi">524313</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>静态类型检查器将把新类型当作原始类型的子类来处理。 (由 Ivan Levkivskyi 在 <a class="reference external" href="https://github.com/python/typing/issues/189">Github #189 中贡献</a>。)</p>
|
||
</section>
|
||
<section id="unicodedata">
|
||
<h3>unicodedata<a class="headerlink" href="#unicodedata" title="永久链接至标题">¶</a></h3>
|
||
<p>The <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> module now uses data from <a class="reference external" href="http://unicode.org/versions/Unicode9.0.0/">Unicode 9.0.0</a>.
|
||
(Contributed by Benjamin Peterson.)</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.Mock" title="unittest.mock.Mock"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mock</span></code></a> 类具有以下改进:</p>
|
||
<ul class="simple">
|
||
<li><p>两个新方法,<a class="reference internal" href="../library/unittest.mock.html#unittest.mock.Mock.assert_called" title="unittest.mock.Mock.assert_called"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Mock.assert_called()</span></code></a> 和 <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.Mock.assert_called_once" title="unittest.mock.Mock.assert_called_once"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Mock.assert_called_once()</span></code></a> 用于检测 mock 对象是否已被调用。 (由 Amit Saha 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26323">bpo-26323</a> 中贡献。)</p></li>
|
||
<li><p><a class="reference internal" href="../library/unittest.mock.html#unittest.mock.Mock.reset_mock" title="unittest.mock.Mock.reset_mock"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Mock.reset_mock()</span></code></a> 方法现在有两个可选的仅限关键字参数: <em>return_value</em> 和 <em>side_effect</em>。 (由 Kushal Das 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=21271">bpo-21271</a> 中贡献。)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="urllib-request">
|
||
<h3>urllib.request<a class="headerlink" href="#urllib-request" title="永久链接至标题">¶</a></h3>
|
||
<p>如果一个 HTTP 请求具有文件或可迭代对象请求体(而不是 bytes 对象)但没有 <code class="docutils literal notranslate"><span class="pre">Content-Length</span></code> 标头,<code class="xref py py-class docutils literal notranslate"><span class="pre">AbstractHTTPHandler</span></code> 现在将不会抛出错误,而是回退为使用分块传输编码格式。 (由 Demian Brecht 和 Rolf Krahl 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=12319">bpo-12319</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="urllib-robotparser">
|
||
<h3>urllib.robotparser<a class="headerlink" href="#urllib-robotparser" title="永久链接至标题">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/urllib.robotparser.html#urllib.robotparser.RobotFileParser" title="urllib.robotparser.RobotFileParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">RobotFileParser</span></code></a> 现在将支持 <code class="docutils literal notranslate"><span class="pre">Crawl-delay</span></code> 和 <code class="docutils literal notranslate"><span class="pre">Request-rate</span></code> 扩展。 (由 Nikolay Bogoychev 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=16099">bpo-16099</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="venv">
|
||
<h3>venv<a class="headerlink" href="#venv" title="永久链接至标题">¶</a></h3>
|
||
<p><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">--prompt</span></code>。 此形参提供了用于虚拟环境的替代前缀。 (由 Łukasz Balcerzak 提议并由 Stéphane Wirtel 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=22829">bpo-22829</a> 中移植到 3.6。)</p>
|
||
</section>
|
||
<section id="warnings">
|
||
<h3>warnings<a class="headerlink" href="#warnings" title="永久链接至标题">¶</a></h3>
|
||
<p>为 <a class="reference internal" href="../library/warnings.html#warnings.warn_explicit" title="warnings.warn_explicit"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.warn_explicit()</span></code></a> 新增可选的 <em>source</em> 形参:被销毁的对象将发出 <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a>。 还为 <code class="xref py py-class docutils literal notranslate"><span class="pre">warnings.WarningMessage</span></code> 增加了 <em>source</em> 属性。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26568">bpo-26568</a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26567">bpo-26567</a> 中贡献。)</p>
|
||
<p>当一个 <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a> 警告被记入日志时,现在会使用 <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> 模块来尝试提取分配给已销毁对象的回溯信息。</p>
|
||
<p>使用 <code class="docutils literal notranslate"><span class="pre">example.py</span></code> 脚本的示例:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">warnings</span>
|
||
|
||
<span class="k">def</span> <span class="nf">func</span><span class="p">():</span>
|
||
<span class="k">return</span> <span class="nb">open</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span>
|
||
|
||
<span class="n">f</span> <span class="o">=</span> <span class="n">func</span><span class="p">()</span>
|
||
<span class="n">f</span> <span class="o">=</span> <span class="kc">None</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>命令 <code class="docutils literal notranslate"><span class="pre">python3.6</span> <span class="pre">-Wd</span> <span class="pre">-X</span> <span class="pre">tracemalloc=5</span> <span class="pre">example.py</span></code> 的输出:</p>
|
||
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">example</span><span class="o">.</span><span class="n">py</span><span class="p">:</span><span class="mi">7</span><span class="p">:</span> <span class="ne">ResourceWarning</span><span class="p">:</span> <span class="n">unclosed</span> <span class="n">file</span> <span class="o"><</span><span class="n">_io</span><span class="o">.</span><span class="n">TextIOWrapper</span> <span class="n">name</span><span class="o">=</span><span class="s1">'example.py'</span> <span class="n">mode</span><span class="o">=</span><span class="s1">'r'</span> <span class="n">encoding</span><span class="o">=</span><span class="s1">'UTF-8'</span><span class="o">></span>
|
||
<span class="n">f</span> <span class="o">=</span> <span class="kc">None</span>
|
||
<span class="n">Object</span> <span class="n">allocated</span> <span class="n">at</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">first</span><span class="p">):</span>
|
||
<span class="n">File</span> <span class="s2">"example.py"</span><span class="p">,</span> <span class="n">lineno</span> <span class="mi">4</span>
|
||
<span class="k">return</span> <span class="nb">open</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span>
|
||
<span class="n">File</span> <span class="s2">"example.py"</span><span class="p">,</span> <span class="n">lineno</span> <span class="mi">6</span>
|
||
<span class="n">f</span> <span class="o">=</span> <span class="n">func</span><span class="p">()</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>"Object allocated at" 回溯信息是新增的并且仅当 <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> 在跟踪 Python 内存分配且 <a class="reference internal" href="../library/warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> 模块已被导入时才会显示。</p>
|
||
</section>
|
||
<section id="winreg">
|
||
<h3>winreg<a class="headerlink" href="#winreg" title="永久链接至标题">¶</a></h3>
|
||
<p>增加了 64 位整数类型 <a class="reference internal" href="../library/winreg.html#winreg.REG_QWORD" title="winreg.REG_QWORD"><code class="xref py py-data docutils literal notranslate"><span class="pre">REG_QWORD</span></code></a>。 (由 Clement Rouault 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23026">bpo-23026</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="winsound">
|
||
<h3>winsound<a class="headerlink" href="#winsound" title="永久链接至标题">¶</a></h3>
|
||
<p>允许将关键字参数传给 <a class="reference internal" href="../library/winsound.html#winsound.Beep" title="winsound.Beep"><code class="xref py py-func docutils literal notranslate"><span class="pre">Beep</span></code></a>, <a class="reference internal" href="../library/winsound.html#winsound.MessageBeep" title="winsound.MessageBeep"><code class="xref py py-func docutils literal notranslate"><span class="pre">MessageBeep</span></code></a> 和 <a class="reference internal" href="../library/winsound.html#winsound.PlaySound" title="winsound.PlaySound"><code class="xref py py-func docutils literal notranslate"><span class="pre">PlaySound</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27982">bpo-27982</a>)。</p>
|
||
</section>
|
||
<section id="xmlrpc-client">
|
||
<h3>xmlrpc.client<a class="headerlink" href="#xmlrpc-client" title="永久链接至标题">¶</a></h3>
|
||
<p><a class="reference internal" href="../library/xmlrpc.client.html#module-xmlrpc.client" title="xmlrpc.client: XML-RPC client access."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpc.client</span></code></a> 模块现在支持反 marshall 由 Apache XML-RPC 的数字和 <code class="docutils literal notranslate"><span class="pre">None</span></code> 实现所使用的附加数据类型。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26885">bpo-26885</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.ZipInfo.from_file" title="zipfile.ZipInfo.from_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ZipInfo.from_file()</span></code></a> 类方法允许基于文件系统中的文件创建 <a class="reference internal" href="../library/zipfile.html#zipfile.ZipInfo" title="zipfile.ZipInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">ZipInfo</span></code></a> 实例。 新增的 <a class="reference internal" href="../library/zipfile.html#zipfile.ZipInfo.is_dir" title="zipfile.ZipInfo.is_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ZipInfo.is_dir()</span></code></a> 方法可被用来检测 <a class="reference internal" href="../library/zipfile.html#zipfile.ZipInfo" title="zipfile.ZipInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">ZipInfo</span></code></a> 实例是否代表一个目录。 (由 Thomas Kluyver 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26039">bpo-26039</a> 中贡献。)</p>
|
||
<p>现在 <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile.open" title="zipfile.ZipFile.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ZipFile.open()</span></code></a> 方法可被用来将数据写入 ZIP 文件,以及提取数据。 (由 Thomas Kluyver 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26039">bpo-26039</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="zlib">
|
||
<h3>zlib<a class="headerlink" href="#zlib" title="永久链接至标题">¶</a></h3>
|
||
<p>现在 <a class="reference internal" href="../library/zlib.html#zlib.compress" title="zlib.compress"><code class="xref py py-func docutils literal notranslate"><span class="pre">compress()</span></code></a> 和 <a class="reference internal" href="../library/zlib.html#zlib.decompress" title="zlib.decompress"><code class="xref py py-func docutils literal notranslate"><span class="pre">decompress()</span></code></a> 函数均可接受关键字参数。 (分别由 Aviv Palivoda 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26243">bpo-26243</a> 以及 Xiang Zhang 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=16764">bpo-16764</a> 中贡献。)</p>
|
||
</section>
|
||
</section>
|
||
<section id="optimizations">
|
||
<h2>性能优化<a class="headerlink" href="#optimizations" title="永久链接至标题">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p>Python 解释器现在使用 16 位字代码而不是字节代码,这使得许多操作码优化成为可能。 (由 Demur Rumed 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26647">bpo-26647</a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28050">bpo-28050</a> 中贡献并得到来自 Serhiy Storchaka 和 Victor Stinner 的协助和评估。)</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> 类已拥有经优化的 C 实现。 (由 Yury Selivanov 和 INADA Naoki 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26081">bpo-26081</a> 中贡献。)</p></li>
|
||
<li><p>现在 <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">asyncio.Task</span></code></a> 类已拥有经优化的 C 实现。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28544">bpo-28544</a> 中贡献。)</p></li>
|
||
<li><p>在 <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> 模块中多项对实现的改进(如泛型类型的缓存)获得至多 30 倍的运行效率提升并降低了内存消耗。</p></li>
|
||
<li><p>现在 ASCII 解码器使用 <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code>, <code class="docutils literal notranslate"><span class="pre">ignore</span></code> 和 <code class="docutils literal notranslate"><span class="pre">replace</span></code> 错误处理器时可提速至多 60 倍。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=24870">bpo-24870</a> 中贡献。)</p></li>
|
||
<li><p>现在 ASCII 和 Latin1 解码器使用 <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code> 错误处理器时可提速至多 3 倍。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25227">bpo-25227</a> 中贡献。)</p></li>
|
||
<li><p>现在 UTF-8 解码器使用 <code class="docutils literal notranslate"><span class="pre">ignore</span></code>, <code class="docutils literal notranslate"><span class="pre">replace</span></code>, <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code>, <code class="docutils literal notranslate"><span class="pre">surrogatepass</span></code> 错误处理器时可提速至多 75 倍。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25267">bpo-25267</a> 中贡献。)</p></li>
|
||
<li><p>现在 UTF-8 解码器使用 <code class="docutils literal notranslate"><span class="pre">ignore</span></code>, <code class="docutils literal notranslate"><span class="pre">replace</span></code> 和 <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code> 错误处理器时可提速至多 15 倍。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25301">bpo-25301</a> 中贡献。)</p></li>
|
||
<li><p>现在 <code class="docutils literal notranslate"><span class="pre">bytes</span> <span class="pre">%</span> <span class="pre">args</span></code> 可提速至多 2 倍。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25349">bpo-25349</a> 中贡献。)</p></li>
|
||
<li><p>现在 <code class="docutils literal notranslate"><span class="pre">bytearray</span> <span class="pre">%</span> <span class="pre">args</span></code> 可提速 2.5 至 5 倍。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25399">bpo-25399</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>: 现在它们获得了 2x 和 3.5x 的提速。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25401">bpo-25401</a> 中贡献。)</p></li>
|
||
<li><p>优化 <code class="docutils literal notranslate"><span class="pre">bytes.replace(b'',</span> <span class="pre">b'.')</span></code> 和 <code class="docutils literal notranslate"><span class="pre">bytearray.replace(b'',</span> <span class="pre">b'.')</span></code>: 提速至多 80%。 (由 Josh Snider 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26574">bpo-26574</a> 中贡献。)</p></li>
|
||
<li><p>Allocator functions of the <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a> domain
|
||
(<a class="reference internal" href="../c-api/memory.html#c.PYMEM_DOMAIN_MEM" title="PYMEM_DOMAIN_MEM"><code class="xref c c-data docutils literal notranslate"><span class="pre">PYMEM_DOMAIN_MEM</span></code></a>) now use the <a class="reference internal" href="../c-api/memory.html#pymalloc"><span class="std std-ref">pymalloc memory allocator</span></a> instead of <code class="xref c c-func docutils literal notranslate"><span class="pre">malloc()</span></code> function of the C library. The
|
||
pymalloc allocator is optimized for objects smaller or equal to 512 bytes
|
||
with a short lifetime, and use <code class="xref c c-func docutils literal notranslate"><span class="pre">malloc()</span></code> for larger memory blocks.
|
||
(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26249">bpo-26249</a>).</p></li>
|
||
<li><p>现在 <a class="reference internal" href="../library/pickle.html#pickle.load" title="pickle.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">pickle.load()</span></code></a> 和 <a class="reference internal" href="../library/pickle.html#pickle.loads" title="pickle.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">pickle.loads()</span></code></a> 在反序列化许多小对象时可提速多至 10%。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27056">bpo-27056</a> 中贡献。)</p></li>
|
||
<li><p>向函数传入 <a class="reference internal" href="../glossary.html#term-keyword-argument"><span class="xref std std-term">关键字参数</span></a> 相比传入 <a class="reference internal" href="../glossary.html#term-positional-argument"><span class="xref std std-term">位置参数</span></a> 会有额外的开销。 现在对于使用 Argument Clinic 实现的扩展函数此开销已显著降低。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27574">bpo-27574</a> 中贡献。)</p></li>
|
||
<li><p>优化了 <a class="reference internal" href="../library/glob.html#module-glob" title="glob: Unix shell style pathname pattern expansion."><code class="xref py py-mod docutils literal notranslate"><span class="pre">glob</span></code></a> 模块中的 <a class="reference internal" href="../library/glob.html#glob.glob" title="glob.glob"><code class="xref py py-func docutils literal notranslate"><span class="pre">glob()</span></code></a> 和 <a class="reference internal" href="../library/glob.html#glob.iglob" title="glob.iglob"><code class="xref py py-func docutils literal notranslate"><span class="pre">iglob()</span></code></a> 函数;现在它们可提速约 3--6 倍。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25596">bpo-25596</a> 中贡献。)</p></li>
|
||
<li><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/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> 中的 glob 操作;现在它可提速约 1.5--4 倍。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26032">bpo-26032</a> 中贡献。)</p></li>
|
||
<li><p><a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code></a> 解析、迭代和深拷贝效率已获得显著提升。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25638">bpo-25638</a>, <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25873">bpo-25873</a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25869">bpo-25869</a> 中贡献。)</p></li>
|
||
<li><p>基于 float 和 decimal 创建 <a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">fractions.Fraction</span></code></a> 实例现已提速 2 至 3 倍。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25971">bpo-25971</a> 中贡献。)</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="build-and-c-api-changes">
|
||
<h2>构建和 C API 的改变<a class="headerlink" href="#build-and-c-api-changes" title="永久链接至标题">¶</a></h2>
|
||
<ul class="simple">
|
||
<li><p>Python 现在需要在工具链中提供一些 C99 支持来进行构建 。 最值得注意的是,Python 现在使用标准的整数类型和宏来代替像 <code class="docutils literal notranslate"><span class="pre">PY_LONG_LONG</span></code> 这样的自定义宏。 要获取更多信息,参见 <span class="target" id="index-111"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0007"><strong>PEP 7</strong></a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=17884">bpo-17884</a>。</p></li>
|
||
<li><p>使用 Android NDK 和将 Android API 设为 21(Android 5.0 Lollipop)或更高级别的交叉编译 CPython 可成功运行。 虽然 Android 还不是一个受支持的平台,但 Python 测试套件在 Android 模拟器上运行时只有约 16 次测试失败。 请参见 Android meta-issue <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26865">bpo-26865</a>。</p></li>
|
||
<li><p>已添加 <code class="docutils literal notranslate"><span class="pre">--enable-optimizations</span></code> 配置旗标 。 打开它将激活 PGO 等高消耗的优化功能。 (原始补丁由 Intel 的 Alecsandru Patrascu 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26359">bpo-26359</a> 中贡献。)</p></li>
|
||
<li><p>The <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">GIL</span></a> must now be held when allocator
|
||
functions of <a class="reference internal" href="../c-api/memory.html#c.PYMEM_DOMAIN_OBJ" title="PYMEM_DOMAIN_OBJ"><code class="xref c c-data docutils literal notranslate"><span class="pre">PYMEM_DOMAIN_OBJ</span></code></a> (ex: <a class="reference internal" href="../c-api/memory.html#c.PyObject_Malloc" title="PyObject_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Malloc()</span></code></a>) and
|
||
<a class="reference internal" href="../c-api/memory.html#c.PYMEM_DOMAIN_MEM" title="PYMEM_DOMAIN_MEM"><code class="xref c c-data docutils literal notranslate"><span class="pre">PYMEM_DOMAIN_MEM</span></code></a> (ex: <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a>) domains are called.</p></li>
|
||
<li><p>新增 <a class="reference internal" href="../c-api/init.html#c.Py_FinalizeEx" title="Py_FinalizeEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_FinalizeEx()</span></code></a> API 用于提示缓冲数据的刷新是否失败。 (由 Martin Panter 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=5319">bpo-5319</a> 中贡献。)</p></li>
|
||
<li><p><a class="reference internal" href="../c-api/arg.html#c.PyArg_ParseTupleAndKeywords" title="PyArg_ParseTupleAndKeywords"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTupleAndKeywords()</span></code></a> 现在支持 <a class="reference internal" href="../glossary.html#positional-only-parameter"><span class="std std-ref">仅限位置形参</span></a>,仅限位置形参是不带名称定义的。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26282">bpo-26282</a> 中贡献。)</p></li>
|
||
<li><p>现在 <code class="docutils literal notranslate"><span class="pre">PyTraceback_Print</span></code> 方法会将由重复行组成的长序列缩写为 <code class="docutils literal notranslate"><span class="pre">"[Previous</span> <span class="pre">line</span> <span class="pre">repeated</span> <span class="pre">{count}</span> <span class="pre">more</span> <span class="pre">times]"</span></code>。 (由 Emanuel Barry 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26823">bpo-26823</a> 中贡献。)</p></li>
|
||
<li><p>新增的 <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetImportErrorSubclass" title="PyErr_SetImportErrorSubclass"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetImportErrorSubclass()</span></code></a> 函数允许指定一个要引发的 <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> 子类。 (由 Eric Snow 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=15767">bpo-15767</a> 中贡献。)</p></li>
|
||
<li><p>新增的 <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_ResourceWarning" title="PyErr_ResourceWarning"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_ResourceWarning()</span></code></a> 函数可被用于生成提供资源分配来源的 <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a>。(由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26567">bpo-26567</a> 中贡献。)</p></li>
|
||
<li><p>新增的 <a class="reference internal" href="../c-api/sys.html#c.PyOS_FSPath" title="PyOS_FSPath"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_FSPath()</span></code></a> 函数可返回一个 <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a> 的文件系统表示形式。 (由 Brett Cannon 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27186">bpo-27186</a> 中贡献。)</p></li>
|
||
<li><p>现在 <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FSConverter" title="PyUnicode_FSConverter"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FSConverter()</span></code></a> 和 <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FSDecoder" title="PyUnicode_FSDecoder"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FSDecoder()</span></code></a> 函数将接受 <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">路径类对象</span></a>。</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="other-improvements">
|
||
<h2>其他改进<a class="headerlink" href="#other-improvements" title="永久链接至标题">¶</a></h2>
|
||
<ul>
|
||
<li><p>当 <a class="reference internal" href="../using/cmdline.html#cmdoption-version"><code class="xref std std-option docutils literal notranslate"><span class="pre">--version</span></code></a> (简短形式: <a class="reference internal" href="../using/cmdline.html#cmdoption-v"><code class="xref std std-option docutils literal notranslate"><span class="pre">-V</span></code></a>) 提供了两次时,Python 将针对细节信息打印 <a class="reference internal" href="../library/sys.html#sys.version" title="sys.version"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.version</span></code></a>。</p>
|
||
<div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>./python<span class="w"> </span>-VV
|
||
<span class="go">Python 3.6.0b4+ (3.6:223967b49e49+, Nov 21 2016, 20:55:04)</span>
|
||
<span class="go">[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]</span>
|
||
</pre></div>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
<section id="deprecated">
|
||
<h2>弃用<a class="headerlink" href="#deprecated" title="永久链接至标题">¶</a></h2>
|
||
<section id="new-keywords">
|
||
<h3>新关键字<a class="headerlink" href="#new-keywords" title="永久链接至标题">¶</a></h3>
|
||
<p>不建议将 <code class="docutils literal notranslate"><span class="pre">async</span></code> 和 <code class="docutils literal notranslate"><span class="pre">await</span></code> 作为变量、类、函数或模块的名称。 它们通过 <span class="target" id="index-112"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0492"><strong>PEP 492</strong></a> 在 Python 3.5 中被引入,并将在 Python 3.7 成为保留关键字。 从 Python 3.6 开始,使用 <code class="docutils literal notranslate"><span class="pre">async</span></code> 或 <code class="docutils literal notranslate"><span class="pre">await</span></code> 作为名称将会产生 <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>
|
||
</section>
|
||
<section id="deprecated-python-behavior">
|
||
<h3>已弃用的 Python 行为<a class="headerlink" href="#deprecated-python-behavior" title="永久链接至标题">¶</a></h3>
|
||
<p>在生成器内部引发 <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#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>,并将在 Python 3.7 中触发 <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="3.5.html#whatsnew-pep-479"><span class="std std-ref">PEP 479:更改生成器内部的 StopIteration 处理</span></a>。</p>
|
||
<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">__aiter__()</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>。 向下兼容将在 Python 3.7 中被移除。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27243">bpo-27243</a> 中贡献。)</p>
|
||
<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#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>,但在近几个 Python 发布版都不会实施。 (由 Emanuel Barry 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27364">bpo-27364</a> 中贡献。)</p>
|
||
<p>当执行相对导入时,现在当 <code class="docutils literal notranslate"><span class="pre">__spec__</span></code> 或 <code class="docutils literal notranslate"><span class="pre">__package__</span></code> 未被定义时从调用方模块回退到 <code class="docutils literal notranslate"><span class="pre">__name__</span></code> 和 <code class="docutils literal notranslate"><span class="pre">__path__</span></code> 会引发 <a class="reference internal" href="../library/exceptions.html#ImportWarning" title="ImportWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportWarning</span></code></a>。 (由 Rose Ames 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25791">bpo-25791</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="deprecated-python-modules-functions-and-methods">
|
||
<h3>已弃用的 Python 模块、函数和方法<a class="headerlink" href="#deprecated-python-modules-functions-and-methods" title="永久链接至标题">¶</a></h3>
|
||
<section id="asynchat">
|
||
<h4>asynchat<a class="headerlink" href="#asynchat" title="永久链接至标题">¶</a></h4>
|
||
<p>The <a class="reference internal" href="../library/asynchat.html#module-asynchat" title="asynchat: Support for asynchronous command/response protocols."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asynchat</span></code></a> has been deprecated in favor of <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>.
|
||
(Contributed by Mariatta in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25002">bpo-25002</a>.)</p>
|
||
</section>
|
||
<section id="asyncore">
|
||
<h4>asyncore<a class="headerlink" href="#asyncore" title="永久链接至标题">¶</a></h4>
|
||
<p>The <a class="reference internal" href="../library/asyncore.html#module-asyncore" title="asyncore: A base class for developing asynchronous socket handling services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncore</span></code></a> has been deprecated in favor of <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>.
|
||
(Contributed by Mariatta in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25002">bpo-25002</a>.)</p>
|
||
</section>
|
||
<section id="dbm">
|
||
<h4>dbm<a class="headerlink" href="#dbm" title="永久链接至标题">¶</a></h4>
|
||
<p>与其他 <a class="reference internal" href="../library/dbm.html#module-dbm" title="dbm: Interfaces to various Unix "database" formats."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm</span></code></a> 实现不同,<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">'rw'</span></code> 模式创建数据库并允许修改以 <code class="docutils literal notranslate"><span class="pre">'r'</span></code> 模式打开的数据库。 此行为现在已被弃用并将在 3.8 中移除。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=21708">bpo-21708</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="id2">
|
||
<h4>distutils<a class="headerlink" href="#id2" title="永久链接至标题">¶</a></h4>
|
||
<p>The undocumented <code class="docutils literal notranslate"><span class="pre">extra_path</span></code> argument to the
|
||
<code class="xref py py-class docutils literal notranslate"><span class="pre">Distribution</span></code> constructor is now considered deprecated
|
||
and will raise a warning if set. Support for this parameter will be
|
||
removed in a future Python release. See <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27919">bpo-27919</a> for details.</p>
|
||
</section>
|
||
<section id="grp">
|
||
<h4>grp<a class="headerlink" href="#grp" title="永久链接至标题">¶</a></h4>
|
||
<p>在 <a class="reference internal" href="../library/grp.html#grp.getgrgid" title="grp.getgrgid"><code class="xref py py-func docutils literal notranslate"><span class="pre">getgrgid()</span></code></a> 中对非整数参数的支持已被弃用。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26129">bpo-26129</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="id3">
|
||
<h4>importlib<a class="headerlink" href="#id3" title="永久链接至标题">¶</a></h4>
|
||
<p>现在 <a class="reference internal" href="../library/importlib.html#importlib.machinery.SourceFileLoader.load_module" title="importlib.machinery.SourceFileLoader.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.SourceFileLoader.load_module()</span></code></a> 和 <a class="reference internal" href="../library/importlib.html#importlib.machinery.SourcelessFileLoader.load_module" title="importlib.machinery.SourcelessFileLoader.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.SourcelessFileLoader.load_module()</span></code></a> 方法已被弃用。 它们是 <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> 中仅存的尚未在之前的 Python 版本中被弃用并改为 <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.exec_module" title="importlib.abc.Loader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.exec_module()</span></code></a> 的 <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.load_module" title="importlib.abc.Loader.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.load_module()</span></code></a> 实现。</p>
|
||
<p>The <a class="reference internal" href="../library/importlib.html#importlib.machinery.WindowsRegistryFinder" title="importlib.machinery.WindowsRegistryFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.WindowsRegistryFinder</span></code></a> class is now
|
||
deprecated. As of 3.6.0, it is still added to <a class="reference internal" href="../library/sys.html#sys.meta_path" title="sys.meta_path"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.meta_path</span></code></a> by
|
||
default (on Windows), but this may change in future releases.</p>
|
||
</section>
|
||
<section id="id4">
|
||
<h4>os<a class="headerlink" href="#id4" title="永久链接至标题">¶</a></h4>
|
||
<p>未写入文档的对于将普通 <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">字节型对象</span></a> 作为 <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> 的函数, <a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> 及类似函数中的路径的支持现已被弃用。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25791">bpo-25791</a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26754">bpo-26754</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="id5">
|
||
<h4>re<a class="headerlink" href="#id5" title="永久链接至标题">¶</a></h4>
|
||
<p>对于在正则表达式中间使用内联旗标 <code class="docutils literal notranslate"><span class="pre">(?letters)</span></code> 的支持已被弃用并将在未来的 Python 版本中移除。 在正则表达式开头的旗标仍然被允许。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=22493">bpo-22493</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="id6">
|
||
<h4>ssl<a class="headerlink" href="#id6" title="永久链接至标题">¶</a></h4>
|
||
<p>OpenSSL 0.9.8, 1.0.0 和 1.0.1 已被弃用并不再受支持。 未来的 <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.0。</p>
|
||
<p><a class="reference internal" href="../library/ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a>, <a class="reference internal" href="../library/http.client.html#module-http.client" title="http.client: HTTP and HTTPS protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.client</span></code></a>, <a class="reference internal" href="../library/imaplib.html#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a>, <a class="reference internal" href="../library/poplib.html#module-poplib" title="poplib: POP3 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code></a> 和 <a class="reference internal" href="../library/smtplib.html#module-smtplib" title="smtplib: SMTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtplib</span></code></a> 中的 SSL 相关参数如 <code class="docutils literal notranslate"><span class="pre">certfile</span></code>, <code class="docutils literal notranslate"><span class="pre">keyfile</span></code> 和 <code class="docutils literal notranslate"><span class="pre">check_hostname</span></code> 已被弃用而应改用 <code class="docutils literal notranslate"><span class="pre">context</span></code>。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28022">bpo-28022</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 版本中将不再可用。 另一些特性则因建议使用不同的 API 而被弃用。 (由 Christian Heimes 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28022">bpo-28022</a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26470">bpo-26470</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="id7">
|
||
<h4>tkinter<a class="headerlink" href="#id7" title="永久链接至标题">¶</a></h4>
|
||
<p><a class="reference internal" href="../library/tkinter.tix.html#module-tkinter.tix" title="tkinter.tix: Tk Extension Widgets for Tkinter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.tix</span></code></a> 模块现已被弃用。 <a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> 用户应当改用 <a class="reference internal" href="../library/tkinter.ttk.html#module-tkinter.ttk" title="tkinter.ttk: Tk themed widget set"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.ttk</span></code></a>。</p>
|
||
</section>
|
||
<section id="id8">
|
||
<h4>venv<a class="headerlink" href="#id8" title="永久链接至标题">¶</a></h4>
|
||
<p><code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> 脚本已被弃用而应改用 <code class="docutils literal notranslate"><span class="pre">python3</span> <span class="pre">-m</span> <span class="pre">venv</span></code>。 这可以避免 <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> 容易混淆所连接的 Python 解释器从而导致弄错虚拟环境所使用的 Python 解释器这样的问题。 (由 Brett Cannon 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25154">bpo-25154</a> 中贡献。)</p>
|
||
</section>
|
||
</section>
|
||
<section id="deprecated-functions-and-types-of-the-c-api">
|
||
<h3>已弃用的 C API 函数和类型<a class="headerlink" href="#deprecated-functions-and-types-of-the-c-api" title="永久链接至标题">¶</a></h3>
|
||
<p>Undocumented functions <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsEncodedObject()</span></code>,
|
||
<code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsDecodedObject()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsEncodedUnicode()</span></code>
|
||
and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsDecodedUnicode()</span></code> are deprecated now.
|
||
Use the <a class="reference internal" href="../c-api/codec.html#codec-registry"><span class="std std-ref">generic codec based API</span></a> instead.</p>
|
||
</section>
|
||
<section id="deprecated-build-options">
|
||
<h3>弃用的构建选项<a class="headerlink" href="#deprecated-build-options" title="永久链接至标题">¶</a></h3>
|
||
<p>现在 <code class="docutils literal notranslate"><span class="pre">--with-system-ffi</span></code> 配置旗标在非 macOS UNIX 平台上将默认启用。 它可以通过 <code class="docutils literal notranslate"><span class="pre">--without-system-ffi</span></code> 来禁用,但该旗标已被弃用并将在 Python 3.7 中不再被接受。 macOS 不会受此变化的影响。 请注意许多 OS 发布方在构建它们的系统 Python 时已经使用了 <code class="docutils literal notranslate"><span class="pre">--with-system-ffi</span></code> 旗标。</p>
|
||
</section>
|
||
</section>
|
||
<section id="removed">
|
||
<h2>移除<a class="headerlink" href="#removed" title="永久链接至标题">¶</a></h2>
|
||
<section id="api-and-feature-removals">
|
||
<h3>API 与特性的移除<a class="headerlink" href="#api-and-feature-removals" title="永久链接至标题">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>正则表达式中由 <code class="docutils literal notranslate"><span class="pre">'\'</span></code> 和一个 ASCII 字母组成的未知转义序列现在将导致报错。 它们在 <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> 的替换模板中仍被允许,但已被弃用。 现在 <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> 旗标只能用于二进制模式。</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">inspect.getmoduleinfo()</span></code> 已被移除(自 CPython 3.3 起已被弃用)。 应当使用 <a class="reference internal" href="../library/inspect.html#inspect.getmodulename" title="inspect.getmodulename"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getmodulename()</span></code></a> 来获取对应于给定路径的模块名称。 (由 Yury Selivanov 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=13248">bpo-13248</a> 中贡献。)</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">traceback.Ignore</span></code> 类和 <code class="docutils literal notranslate"><span class="pre">traceback.usage</span></code>, <code class="docutils literal notranslate"><span class="pre">traceback.modname</span></code>, <code class="docutils literal notranslate"><span class="pre">traceback.fullmodname</span></code>, <code class="docutils literal notranslate"><span class="pre">traceback.find_lines_from_code</span></code>, <code class="docutils literal notranslate"><span class="pre">traceback.find_lines</span></code>, <code class="docutils literal notranslate"><span class="pre">traceback.find_strings</span></code>, <code class="docutils literal notranslate"><span class="pre">traceback.find_executable_lines</span></code> 等方法已从 <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> 模块中移除。 它们是自 Python 3.2 起即已被弃用的未写入文档的方法并可通过私有方法使用等价的功能。</p></li>
|
||
<li><p><a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> 控件类中的 <code class="docutils literal notranslate"><span class="pre">tk_menuBar()</span></code> 和 <code class="docutils literal notranslate"><span class="pre">tk_bindForTraversal()</span></code> 虚拟方法已被移除(相应的 Tk 命令自 Tk 4.0 起即已过时)。</p></li>
|
||
<li><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.ZipFile</span></code></a> 类的 <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile.open" title="zipfile.ZipFile.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">open()</span></code></a> 方法已不再支持 <code class="docutils literal notranslate"><span class="pre">'U'</span></code> 模式(自 Python 3.4 起已被弃用)。 请使用 <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.TextIOWrapper</span></code></a> 以 <a class="reference internal" href="../glossary.html#term-universal-newlines"><span class="xref std std-term">universal newlines</span></a> 模式读取压缩文本文件。</p></li>
|
||
<li><p>The undocumented <code class="docutils literal notranslate"><span class="pre">IN</span></code>, <code class="docutils literal notranslate"><span class="pre">CDROM</span></code>, <code class="docutils literal notranslate"><span class="pre">DLFCN</span></code>, <code class="docutils literal notranslate"><span class="pre">TYPES</span></code>, <code class="docutils literal notranslate"><span class="pre">CDIO</span></code>, and
|
||
<code class="docutils literal notranslate"><span class="pre">STROPTS</span></code> modules have been removed. They had been available in the
|
||
platform specific <code class="docutils literal notranslate"><span class="pre">Lib/plat-*/</span></code> directories, but were chronically out of
|
||
date, inconsistently available across platforms, and unmaintained. The
|
||
script that created these modules is still available in the source
|
||
distribution at <a class="reference external" href="https://github.com/python/cpython/tree/3.8/Tools/scripts/h2py.py">Tools/scripts/h2py.py</a>.</p></li>
|
||
<li><p>已弃用的 <code class="docutils literal notranslate"><span class="pre">asynchat.fifo</span></code> 类现已被移除。</p></li>
|
||
</ul>
|
||
</section>
|
||
</section>
|
||
<section id="porting-to-python-3-6">
|
||
<h2>移植到Python 3.6<a class="headerlink" href="#porting-to-python-3-6" title="永久链接至标题">¶</a></h2>
|
||
<p>本节列出了先前描述的更改以及可能需要更改代码的其他错误修正.</p>
|
||
<section id="changes-in-python-command-behavior">
|
||
<h3> 'python' 命令行为的变化<a class="headerlink" href="#changes-in-python-command-behavior" title="永久链接至标题">¶</a></h3>
|
||
<ul class="simple">
|
||
<li><p>带有 <code class="docutils literal notranslate"><span class="pre">COUNT_ALLOCS</span></code>, <code class="docutils literal notranslate"><span class="pre">SHOW_ALLOC_COUNT</span></code> 或 <code class="docutils literal notranslate"><span class="pre">SHOW_TRACK_COUNT</span></code> 宏定义的特殊 Python 编译版的输出现在默认被关闭。 可以使用 <code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">showalloccount</span></code> 选项重新启用它。 现在它将输出到 <code class="docutils literal notranslate"><span class="pre">stderr</span></code> 而不是 <code class="docutils literal notranslate"><span class="pre">stdout</span></code>。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23034">bpo-23034</a> 中贡献。)</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><a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> 将不再允许组合使用 <code class="docutils literal notranslate"><span class="pre">'U'</span></code> 模式旗标与 <code class="docutils literal notranslate"><span class="pre">'+'</span></code>。 (由 Jeff Balogh 和 John O'Connor 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=2091">bpo-2091</a> 中贡献。)</p></li>
|
||
<li><p><a class="reference internal" href="../library/sqlite3.html#module-sqlite3" title="sqlite3: A DB-API 2.0 implementation using SQLite 3.x."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlite3</span></code></a> 将不再隐式地在 DDL 语句之前提交未完成的事务。</p></li>
|
||
<li><p>在 Linux 上,现在 <a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.urandom()</span></code></a> 会阻塞直到系统的 urandom 熵池被初始化以提升安全性。</p></li>
|
||
<li><p>当 <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.exec_module" title="importlib.abc.Loader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.exec_module()</span></code></a> 被定义时,<a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.create_module" title="importlib.abc.Loader.create_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.create_module()</span></code></a> 也必须被定义。</p></li>
|
||
<li><p>现在 <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetImportError" title="PyErr_SetImportError"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetImportError()</span></code></a> 当其 <strong>msg</strong> 参数未被设置时将设置 <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">NULL</span></code>。</p></li>
|
||
<li><p>The format of the <code class="docutils literal notranslate"><span class="pre">co_lnotab</span></code> attribute of code objects changed to support
|
||
a negative line number delta. By default, Python does not emit bytecode with
|
||
a negative line number delta. Functions using <code class="docutils literal notranslate"><span class="pre">frame.f_lineno</span></code>,
|
||
<code class="docutils literal notranslate"><span class="pre">PyFrame_GetLineNumber()</span></code> or <code class="docutils literal notranslate"><span class="pre">PyCode_Addr2Line()</span></code> are not affected.
|
||
Functions directly decoding <code class="docutils literal notranslate"><span class="pre">co_lnotab</span></code> should be updated to use a signed
|
||
8-bit integer type for the line number delta, but this is only required to
|
||
support applications using a negative line number delta. See
|
||
<code class="docutils literal notranslate"><span class="pre">Objects/lnotab_notes.txt</span></code> for the <code class="docutils literal notranslate"><span class="pre">co_lnotab</span></code> format and how to decode
|
||
it, and see the <span class="target" id="index-36"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0511"><strong>PEP 511</strong></a> for the rationale.</p></li>
|
||
<li><p>现在 <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">1</span></code> 或 <code class="docutils literal notranslate"><span class="pre">0</span></code> 来分别表示成功或失败。 由于布尔值是整数的子类,这应当只有在你对 <code class="docutils literal notranslate"><span class="pre">1</span></code> 或 <code class="docutils literal notranslate"><span class="pre">0</span></code> 执行标识号检测时才会出现问题。 参见 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25768">bpo-25768</a>。</p></li>
|
||
<li><p>现在读取 <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.urlsplit" title="urllib.parse.urlsplit"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.urlsplit()</span></code></a> 和 <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.urlparse" title="urllib.parse.urlparse"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlparse()</span></code></a> 结果的 <code class="xref py py-attr docutils literal notranslate"><span class="pre">port</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>,而不是返回 <a class="reference internal" href="../library/constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>。 参见 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=20059">bpo-20059</a>。</p></li>
|
||
<li><p>The <a class="reference internal" href="../library/imp.html#module-imp" title="imp: Access the implementation of the import statement. (已移除)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code></a> module now raises 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> instead of
|
||
<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>.</p></li>
|
||
<li><p>The following modules have had missing APIs added to their <code class="xref py py-attr docutils literal notranslate"><span class="pre">__all__</span></code>
|
||
attributes to match the documented APIs:
|
||
<a class="reference internal" href="../library/calendar.html#module-calendar" title="calendar: Functions for working with calendars, including some emulation of the Unix cal program."><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code></a>, <a class="reference internal" href="../library/cgi.html#module-cgi" title="cgi: Helpers for running Python scripts via the Common Gateway Interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">cgi</span></code></a>, <a class="reference internal" href="../library/csv.html#module-csv" title="csv: Write and read tabular data to and from delimited files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">csv</span></code></a>,
|
||
<a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ElementTree</span></code></a>, <a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a>,
|
||
<a class="reference internal" href="../library/fileinput.html#module-fileinput" title="fileinput: Loop over standard input or a list of files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">fileinput</span></code></a>, <a class="reference internal" href="../library/ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a>, <a class="reference internal" href="../library/logging.html#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a>, <a class="reference internal" href="../library/mailbox.html#module-mailbox" title="mailbox: Manipulate mailboxes in various formats"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mailbox</span></code></a>,
|
||
<a class="reference internal" href="../library/mimetypes.html#module-mimetypes" title="mimetypes: Mapping of filename extensions to MIME types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">mimetypes</span></code></a>, <a class="reference internal" href="../library/optparse.html#module-optparse" title="optparse: Command-line option parsing library. (已移除)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">optparse</span></code></a>, <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>, <a class="reference internal" href="../library/smtpd.html#module-smtpd" title="smtpd: A SMTP server implementation in Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code></a>,
|
||
<a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a>, <a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a>, <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> and
|
||
<a class="reference internal" href="../library/wave.html#module-wave" title="wave: Provide an interface to the WAV sound format."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wave</span></code></a>. This means they will export new symbols when <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">*</span></code>
|
||
is used.
|
||
(Contributed by Joel Taddei and Jacek Kołodziej in <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23883">bpo-23883</a>.)</p></li>
|
||
<li><p>当执行相对导入时,如果 <code class="docutils literal notranslate"><span class="pre">__package__</span></code> 与 <code class="docutils literal notranslate"><span class="pre">__spec__.parent</span></code> 的比较结果不相等则会引发 <a class="reference internal" href="../library/exceptions.html#ImportWarning" title="ImportWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportWarning</span></code></a>。 (由 Brett Cannon 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25791">bpo-25791</a> 中贡献。)</p></li>
|
||
<li><p>当执行相对导入而上级包未知时,则会引发 <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>。 在之前版本中,可能会引发 <a class="reference internal" href="../library/exceptions.html#SystemError" title="SystemError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemError</span></code></a>。 (由 Brett Cannon 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=18018">bpo-18018</a> 中贡献。)</p></li>
|
||
<li><p>基于 <a class="reference internal" href="../library/socketserver.html#module-socketserver" title="socketserver: A framework for network servers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socketserver</span></code></a> 模块的服务器,包括在 <a class="reference internal" href="../library/http.server.html#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a>, <a class="reference internal" href="../library/xmlrpc.server.html#module-xmlrpc.server" title="xmlrpc.server: Basic XML-RPC server implementations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpc.server</span></code></a> 和 <a class="reference internal" href="../library/wsgiref.html#module-wsgiref.simple_server" title="wsgiref.simple_server: A simple WSGI HTTP server."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.simple_server</span></code></a> 定义的服务器,现在将只捕获派生自 <a class="reference internal" href="../library/exceptions.html#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a> 的异常。 因此如果一个请求处理器引发了 <a class="reference internal" href="../library/exceptions.html#SystemExit" title="SystemExit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemExit</span></code></a> 或 <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> 之类的异常,<a class="reference internal" href="../library/socketserver.html#socketserver.BaseServer.handle_error" title="socketserver.BaseServer.handle_error"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_error()</span></code></a> 不再会被调用,异常将会停止单线程的服务器。 (由 Martin Panter 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23430">bpo-23430</a> 中贡献。)</p></li>
|
||
<li><p>如果用户没有权限, <a class="reference internal" href="../library/spwd.html#spwd.getspnam" title="spwd.getspnam"><code class="xref py py-func docutils literal notranslate"><span class="pre">spwd.getspnam()</span></code></a> 现在会抛出 <a class="reference internal" href="../library/exceptions.html#PermissionError" title="PermissionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PermissionError</span></code></a> 而非之前的 <a class="reference internal" href="../library/exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> 。</p></li>
|
||
<li><p>现在 <a class="reference internal" href="../library/socket.html#socket.socket.close" title="socket.socket.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.socket.close()</span></code></a> 方法当下层系统调用报告错误 (例如 <code class="docutils literal notranslate"><span class="pre">EBADF</span></code>) 时将会引发一个异常。 (由 Martin Panter 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26685">bpo-26685</a> 中贡献。)</p></li>
|
||
<li><p>The <em>decode_data</em> argument for the <a class="reference internal" href="../library/smtpd.html#smtpd.SMTPChannel" title="smtpd.SMTPChannel"><code class="xref py py-class docutils literal notranslate"><span class="pre">smtpd.SMTPChannel</span></code></a> and
|
||
<a class="reference internal" href="../library/smtpd.html#smtpd.SMTPServer" title="smtpd.SMTPServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">smtpd.SMTPServer</span></code></a> constructors is now <code class="docutils literal notranslate"><span class="pre">False</span></code> by default.
|
||
This means that the argument passed to
|
||
<a class="reference internal" href="../library/smtpd.html#smtpd.SMTPServer.process_message" title="smtpd.SMTPServer.process_message"><code class="xref py py-meth docutils literal notranslate"><span class="pre">process_message()</span></code></a> is now a bytes object by
|
||
default, and <code class="docutils literal notranslate"><span class="pre">process_message()</span></code> will be passed keyword arguments.
|
||
Code that has already been updated in accordance with the deprecation
|
||
warning generated by 3.5 will not be affected.</p></li>
|
||
<li><p>现在 <a class="reference internal" href="../library/json.html#module-json" title="json: Encode and decode the JSON format."><code class="xref py py-mod docutils literal notranslate"><span class="pre">json</span></code></a> 模块中 <a class="reference internal" href="../library/json.html#json.dump" title="json.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump()</span></code></a>, <a class="reference internal" href="../library/json.html#json.dumps" title="json.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">dumps()</span></code></a>, <a class="reference internal" href="../library/json.html#json.load" title="json.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">load()</span></code></a> 和 <a class="reference internal" href="../library/json.html#json.loads" title="json.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">loads()</span></code></a> 函数以及 <a class="reference internal" href="../library/json.html#json.JSONEncoder" title="json.JSONEncoder"><code class="xref py py-class docutils literal notranslate"><span class="pre">JSONEncoder</span></code></a> 和 <a class="reference internal" href="../library/json.html#json.JSONDecoder" title="json.JSONDecoder"><code class="xref py py-class docutils literal notranslate"><span class="pre">JSONDecoder</span></code></a> 类构造器的所有可选参数都是 <a class="reference internal" href="../glossary.html#keyword-only-parameter"><span class="std std-ref">仅限关键字参数</span></a>。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=18726">bpo-18726</a> 中贡献。)</p></li>
|
||
<li><p><a class="reference internal" href="../library/functions.html#type" title="type"><code class="xref py py-class docutils literal notranslate"><span class="pre">type</span></code></a> 的子类如果未重载 <code class="docutils literal notranslate"><span class="pre">type.__new__</span></code>,将不再能使用一个参数的形式来获取对象的类型。</p></li>
|
||
<li><p>作为 <span class="target" id="index-113"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0487"><strong>PEP 487</strong></a> 的一部分,对传递给 <a class="reference internal" href="../library/functions.html#type" title="type"><code class="xref py py-class docutils literal notranslate"><span class="pre">type</span></code></a> 的关键字参数的处理(元类提示 <code class="docutils literal notranslate"><span class="pre">metaclass</span></code> 除外)现在统一委托给 <a class="reference internal" href="../reference/datamodel.html#object.__init_subclass__" title="object.__init_subclass__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__init_subclass__()</span></code></a>。 这意味着 <code class="xref py py-meth docutils literal notranslate"><span class="pre">type.__new__()</span></code> 和 <code class="xref py py-meth docutils literal notranslate"><span class="pre">type.__init__()</span></code> 现在都接受任意的关键字参数,但 <a class="reference internal" href="../reference/datamodel.html#object.__init_subclass__" title="object.__init_subclass__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__init_subclass__()</span></code></a> (从 <code class="xref py py-meth docutils literal notranslate"><span class="pre">type.__new__()</span></code> 调用)默认将拒绝它们。 接受额外关键字参数的自定义元类需要相应调整对 <code class="xref py py-meth docutils literal notranslate"><span class="pre">type.__new__()</span></code> 的调用(无论是直接调用还是通过 <a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-class docutils literal notranslate"><span class="pre">super</span></code></a> 间接调用)。</p></li>
|
||
<li><p>In <code class="xref py py-class docutils literal notranslate"><span class="pre">distutils.command.sdist.sdist</span></code>, the <code class="docutils literal notranslate"><span class="pre">default_format</span></code>
|
||
attribute has been removed and is no longer honored. Instead, the
|
||
gzipped tarfile format is the default on all platforms and no
|
||
platform-specific selection is made.
|
||
In environments where distributions are
|
||
built on Windows and zip distributions are required, configure
|
||
the project with a <code class="docutils literal notranslate"><span class="pre">setup.cfg</span></code> file containing the following:</p>
|
||
<div class="highlight-ini notranslate"><div class="highlight"><pre><span></span><span class="k">[sdist]</span>
|
||
<span class="na">formats</span><span class="o">=</span><span class="s">zip</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>此行为已通过 Setuptools 26.0.0 反向移植到更早的 Python 版本中。</p>
|
||
</li>
|
||
<li><p>在 <a class="reference internal" href="../library/urllib.request.html#module-urllib.request" title="urllib.request: Extensible library for opening URLs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request</span></code></a> 模块和 <a class="reference internal" href="../library/http.client.html#http.client.HTTPConnection.request" title="http.client.HTTPConnection.request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">http.client.HTTPConnection.request()</span></code></a> 方法中,如果没有指定 Content-Length 标头字段并且请求体是一个文件对象,现在它将使用 HTTP 1.1 分块编码格式发送。 如果必须要将一个文件对象发送给 HTTP 1.0 服务器,那么现在必须由调用方指定 Content-Length 值。 (由 Demian Brecht 和 Rolf Krahl 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=12319">bpo-12319</a> 中贡献并由 Martin Panter 进行修改。)</p></li>
|
||
<li><p>现在 <a class="reference internal" href="../library/csv.html#csv.DictReader" title="csv.DictReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">DictReader</span></code></a> 将返回类型为 <a class="reference internal" href="../library/collections.html#collections.OrderedDict" title="collections.OrderedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">OrderedDict</span></code></a> 的行。 (由 Steve Holden 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27842">bpo-27842</a> 中贡献。)</p></li>
|
||
<li><p><a class="reference internal" href="../library/crypt.html#crypt.METHOD_CRYPT" title="crypt.METHOD_CRYPT"><code class="xref py py-const docutils literal notranslate"><span class="pre">crypt.METHOD_CRYPT</span></code></a> 如果不受平台支持将不再被添加到 <code class="docutils literal notranslate"><span class="pre">crypt.methods</span></code>。 (由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25287">bpo-25287</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">namedtuple()</span></code></a> 的 <em>verbose</em> 和 <em>rename</em> 参数现在是仅限关键字参数。 (由 Raymond Hettinger 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25628">bpo-25628</a> 中贡献。)</p></li>
|
||
<li><p>在 Linux 上,<a class="reference internal" href="../library/ctypes.html#ctypes.util.find_library" title="ctypes.util.find_library"><code class="xref py py-func docutils literal notranslate"><span class="pre">ctypes.util.find_library()</span></code></a> 现在会到 <code class="docutils literal notranslate"><span class="pre">LD_LIBRARY_PATH</span></code> 中查找共享库。 (由 Vinay Sajip 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=9998">bpo-9998</a> 中贡献。)</p></li>
|
||
<li><p><a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">imaplib.IMAP4</span></code></a> 类现在可以处理服务器发送的消息中包含 <code class="docutils literal notranslate"><span class="pre">']'</span></code> 字符的旗标,以改善在现实世界中的兼容性。 (由 Lita Cho 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=21815">bpo-21815</a> 中贡献。)</p></li>
|
||
<li><p>现在 <code class="xref py py-func docutils literal notranslate"><span class="pre">mmap.write()</span></code> 函数将像其他写入方法一样返回写入的字节数。 (由 Jakub Stasiak 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26335">bpo-26335</a> 中贡献。)</p></li>
|
||
<li><p>现在 <a class="reference internal" href="../library/pkgutil.html#pkgutil.iter_modules" title="pkgutil.iter_modules"><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.iter_modules()</span></code></a> 和 <a class="reference internal" href="../library/pkgutil.html#pkgutil.walk_packages" title="pkgutil.walk_packages"><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.walk_packages()</span></code></a> 函数将返回 <a class="reference internal" href="../library/pkgutil.html#pkgutil.ModuleInfo" title="pkgutil.ModuleInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModuleInfo</span></code></a> 具名元组。 (由 Ramchandra Apte 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=17211">bpo-17211</a> 中贡献。)</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> 即使未在字符串中找到模式也会针对替换模板中无效的数字分组引用引发错误。 针对无效分组引用的错误消息现在将包括分组索引和引用位置。 (由 SilentGhost, Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25953">bpo-25953</a> 中贡献。)</p></li>
|
||
<li><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.ZipFile</span></code></a> 对于无法识别的压缩值将引发 <a class="reference internal" href="../library/exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</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>。 此外,在已关闭的 ZipFile 上调用 <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> 或者在使用 <code class="docutils literal notranslate"><span class="pre">'r'</span></code> 模式创建的 ZipFile 上调用 <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile.write" title="zipfile.ZipFile.write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</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>。 在之前版本中,对于这些场景是引发 <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>。</p></li>
|
||
<li><p>当自定义元类与零参数的 <a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a> 或从方法到隐式的 <code class="docutils literal notranslate"><span class="pre">__class__</span></code> 闭包变量的直接引用相结合时,隐式的 <code class="docutils literal notranslate"><span class="pre">__classcell__</span></code> 命名空间条目现在必须传到 <code class="docutils literal notranslate"><span class="pre">type.__new__</span></code> 进行初始化。 如果不这样做那么在 Python 3.6 中将会导致 <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#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>。</p></li>
|
||
<li><p>随着 <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#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>。 为了在未来向此类消费方提供兼容性,完全取代 <a class="reference internal" href="../library/functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> 的替代导入系统的实现者需要更新其实现以便在完全未找到模块时引发新的子类。 兼容默认导入系统的插件的实现者不需要做任何更改,因为默认导入系统会在适当的时候引发新的子类。</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>
|
||
<ul class="simple">
|
||
<li><p>现在 <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a> 分配器族将使用 <a class="reference internal" href="../c-api/memory.html#pymalloc"><span class="std std-ref">pymalloc 分配器</span></a> 而不是系统 <code class="xref c c-func docutils literal notranslate"><span class="pre">malloc()</span></code>。 调用 <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a> 时未持有 GIL 的应用程序现在可能发生崩溃。 请将 <span class="target" id="index-114"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONMALLOC"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONMALLOC</span></code></a> 环境变量设为 <code class="docutils literal notranslate"><span class="pre">debug</span></code> 以便在你的应用程序中验证内存分配器的使用。 参见 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26249">bpo-26249</a>。</p></li>
|
||
<li><p>现在如果缓冲数据刷新失败 <a class="reference internal" href="../c-api/sys.html#c.Py_Exit" title="Py_Exit"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Exit()</span></code></a> (以及主解释器) 会将退出状态重写为 120。 参见 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=5319">bpo-5319</a>。</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="cpython-bytecode-changes">
|
||
<h3>CPython 字节码的改变<a class="headerlink" href="#cpython-bytecode-changes" title="永久链接至标题">¶</a></h3>
|
||
<p>在 Python 3.6 中对 <a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a> 进行了一些重大修改。</p>
|
||
<ul class="simple">
|
||
<li><p>Python 解释器现在使用 16 位字代码而不是字节代码。 (由 Demur Rumed 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=26647">bpo-26647</a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28050">bpo-28050</a> 中贡献并得到来自 Serhiy Storchaka 和 Victor Stinner 的协助和评估。)</p></li>
|
||
<li><p>新增 <a class="reference internal" href="../library/dis.html#opcode-FORMAT_VALUE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">FORMAT_VALUE</span></code></a> 和 <a class="reference internal" href="../library/dis.html#opcode-BUILD_STRING"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_STRING</span></code></a> 操作码作为 <a class="reference internal" href="#whatsnew36-pep498"><span class="std std-ref">格式化字符串字面值</span></a> 实现的组成部分。 (由 Eric Smith 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=25483">bpo-25483</a> 以及 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27078">bpo-27078</a> 中贡献。)</p></li>
|
||
<li><p>新增的 <a class="reference internal" href="../library/dis.html#opcode-BUILD_CONST_KEY_MAP"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_CONST_KEY_MAP</span></code></a> 操作码用于优化具有常量键的字典的创建。 (由 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27140">bpo-27140</a> 中创建。)</p></li>
|
||
<li><p>函数调用操作码进行了大幅改进以提升效率并简化实现。 <a class="reference internal" href="../library/dis.html#opcode-MAKE_FUNCTION"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">MAKE_FUNCTION</span></code></a>, <a class="reference internal" href="../library/dis.html#opcode-CALL_FUNCTION"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FUNCTION</span></code></a>, <a class="reference internal" href="../library/dis.html#opcode-CALL_FUNCTION_KW"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FUNCTION_KW</span></code></a> 和 <a class="reference internal" href="../library/dis.html#opcode-BUILD_MAP_UNPACK_WITH_CALL"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_MAP_UNPACK_WITH_CALL</span></code></a> 操作码已被修改,新增了 <a class="reference internal" href="../library/dis.html#opcode-CALL_FUNCTION_EX"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FUNCTION_EX</span></code></a> 和 <a class="reference internal" href="../library/dis.html#opcode-BUILD_TUPLE_UNPACK_WITH_CALL"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_TUPLE_UNPACK_WITH_CALL</span></code></a>,并移除了 <code class="docutils literal notranslate"><span class="pre">CALL_FUNCTION_VAR</span></code>, <code class="docutils literal notranslate"><span class="pre">CALL_FUNCTION_VAR_KW</span></code> 和 <code class="docutils literal notranslate"><span class="pre">MAKE_CLOSURE</span></code> 操作码。 (由 Demur Rumed 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27095">bpo-27095</a> 中,以及 Serhiy Storchaka 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27213">bpo-27213</a>, <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=28257">bpo-28257</a> 中贡献。)</p></li>
|
||
<li><p>新增了 <a class="reference internal" href="../library/dis.html#opcode-SETUP_ANNOTATIONS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">SETUP_ANNOTATIONS</span></code></a> 和 <code class="xref std std-opcode docutils literal notranslate"><span class="pre">STORE_ANNOTATION</span></code> 操作码以支持新的 <a class="reference internal" href="../glossary.html#term-variable-annotation"><span class="xref std std-term">variable annotation</span></a> 语法。 (由 Ivan Levkivskyi 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=27985">bpo-27985</a> 中贡献。)</p></li>
|
||
</ul>
|
||
</section>
|
||
</section>
|
||
<section id="notable-changes-in-python-3-6-2">
|
||
<h2>Python 3.6.2 中的重要变化<a class="headerlink" href="#notable-changes-in-python-3-6-2" title="永久链接至标题">¶</a></h2>
|
||
<section id="new-make-regen-all-build-target">
|
||
<h3>新增 <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> 构建目标<a class="headerlink" href="#new-make-regen-all-build-target" title="永久链接至标题">¶</a></h3>
|
||
<p>为了简化交叉编译,并确保 CPython 能够可靠地编译而不需要已存在可用的 Python 版本,基于 autotools 的构建系统将不再尝试根据文件修改时间隐式地重新编译已生成的文件。</p>
|
||
<p>取而代之的是,新增了一个 <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> 命令以便在需要时强制重新生成这些文件(例如在基于预生成版本构建了 Python 的初始版本之后)。</p>
|
||
<p>还定义了其他一些更具选择性的重生成目标 —— 详情参见 <a class="reference external" href="https://github.com/python/cpython/tree/3.8/Makefile.pre.in">Makefile.pre.in</a>。</p>
|
||
<p>(由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23404">bpo-23404</a> 中贡献。)</p>
|
||
<div class="versionadded">
|
||
<p><span class="versionmodified added">3.6.2 新版功能.</span></p>
|
||
</div>
|
||
</section>
|
||
<section id="removal-of-make-touch-build-target">
|
||
<h3>移除了 <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> 构建目标<a class="headerlink" href="#removal-of-make-touch-build-target" title="永久链接至标题">¶</a></h3>
|
||
<p>之前用于通过更新生成文件的修改时间来请求隐式的重新生成这些文件的 <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> 构建目标已被移除。</p>
|
||
<p>它已被新的 <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> 目标所替代。</p>
|
||
<p>(由 Victor Stinner 在 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=23404">bpo-23404</a> 中贡献。)</p>
|
||
<div class="versionchanged">
|
||
<p><span class="versionmodified changed">在 3.6.2 版更改.</span></p>
|
||
</div>
|
||
</section>
|
||
</section>
|
||
<section id="notable-changes-in-python-3-6-4">
|
||
<h2>Python 3.6.4 中的重要变化<a class="headerlink" href="#notable-changes-in-python-3-6-4" title="永久链接至标题">¶</a></h2>
|
||
<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?@action=redirect&bpo=22898">bpo-22898</a> 和 <a class="reference external" href="https://bugs.python.org/issue?@action=redirect&bpo=30697">bpo-30697</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="notable-changes-in-python-3-6-5">
|
||
<h2>Python 3.6.5 中的重要变化<a class="headerlink" href="#notable-changes-in-python-3-6-5" title="永久链接至标题">¶</a></h2>
|
||
<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?@action=redirect&bpo=31900">bpo-31900</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="notable-changes-in-python-3-6-7">
|
||
<h2>Python 3.6.7 中的重要变化<a class="headerlink" href="#notable-changes-in-python-3-6-7" title="永久链接至标题">¶</a></h2>
|
||
<p>在 3.6.7 中当提供不带末尾换行符的输入时 <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?@action=redirect&bpo=33899">bpo-33899</a> 中贡献。)</p>
|
||
</section>
|
||
<section id="notable-changes-in-python-3-6-10">
|
||
<h2>Python 3.6.10 中的重要变化<a class="headerlink" href="#notable-changes-in-python-3-6-10" 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?@action=redirect&bpo=37228">bpo-37228</a> 中贡献。。)</p>
|
||
</section>
|
||
<section id="notable-changes-in-python-3-6-13">
|
||
<h2>Python 3.6.13 中的重要变化<a class="headerlink" href="#notable-changes-in-python-3-6-13" title="永久链接至标题">¶</a></h2>
|
||
<p>早先的 Python 版本允许使用 <code class="docutils literal notranslate"><span class="pre">;</span></code> 和 <code class="docutils literal notranslate"><span class="pre">&</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">&</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?@action=redirect&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.6 有什么新变化</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-498-formatted-string-literals">PEP 498: 格式化字符串字面值</a></li>
|
||
<li><a class="reference internal" href="#pep-526-syntax-for-variable-annotations">PEP 526: 变量标注的语法</a></li>
|
||
<li><a class="reference internal" href="#pep-515-underscores-in-numeric-literals">PEP 515: 数字字面值中的下划线。</a></li>
|
||
<li><a class="reference internal" href="#pep-525-asynchronous-generators">PEP 525: 异步生成器</a></li>
|
||
<li><a class="reference internal" href="#pep-530-asynchronous-comprehensions">PEP 530: 异步推导式</a></li>
|
||
<li><a class="reference internal" href="#pep-487-simpler-customization-of-class-creation">PEP 487: 更简单的自定义类创建</a></li>
|
||
<li><a class="reference internal" href="#pep-487-descriptor-protocol-enhancements">PEP 487: 描述器协议的增强</a></li>
|
||
<li><a class="reference internal" href="#pep-519-adding-a-file-system-path-protocol">PEP 519: 添加文件系统路径协议</a></li>
|
||
<li><a class="reference internal" href="#pep-495-local-time-disambiguation">PEP 495: 消除本地时间的歧义</a></li>
|
||
<li><a class="reference internal" href="#pep-529-change-windows-filesystem-encoding-to-utf-8">PEP 529: 将 Windows 文件系统编码格式更改为 UTF-8</a></li>
|
||
<li><a class="reference internal" href="#pep-528-change-windows-console-encoding-to-utf-8">PEP 528: 将 Windows 控制台编码格式更改为 UTF-8</a></li>
|
||
<li><a class="reference internal" href="#pep-520-preserving-class-attribute-definition-order">PEP 520: 保留类属性定义顺序</a></li>
|
||
<li><a class="reference internal" href="#pep-468-preserving-keyword-argument-order">PEP 468: 保留关键字参数顺序</a></li>
|
||
<li><a class="reference internal" href="#new-dict-implementation">新的 <span class="xref std std-ref">dict</span> 实现</a></li>
|
||
<li><a class="reference internal" href="#pep-523-adding-a-frame-evaluation-api-to-cpython">PEP 523: 向 CPython 添加帧求值 API</a></li>
|
||
<li><a class="reference internal" href="#pythonmalloc-environment-variable">PYTHONMALLOC 环境变量</a></li>
|
||
<li><a class="reference internal" href="#dtrace-and-systemtap-probing-support">DTrace 和 SystemTap 探测支持</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="#secrets">secrets</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#improved-modules">改进的模块</a><ul>
|
||
<li><a class="reference internal" href="#array">array</a></li>
|
||
<li><a class="reference internal" href="#ast">ast</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="#cmath">cmath</a></li>
|
||
<li><a class="reference internal" href="#collections">collections</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="#datetime">datetime</a></li>
|
||
<li><a class="reference internal" href="#decimal">decimal</a></li>
|
||
<li><a class="reference internal" href="#distutils">distutils</a></li>
|
||
<li><a class="reference internal" href="#email">email</a></li>
|
||
<li><a class="reference internal" href="#encodings">encodings</a></li>
|
||
<li><a class="reference internal" href="#enum">enum</a></li>
|
||
<li><a class="reference internal" href="#faulthandler">faulthandler</a></li>
|
||
<li><a class="reference internal" href="#fileinput">fileinput</a></li>
|
||
<li><a class="reference internal" href="#hashlib">hashlib</a></li>
|
||
<li><a class="reference internal" href="#http-client">http.client</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="#inspect">inspect</a></li>
|
||
<li><a class="reference internal" href="#json">json</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="#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="#pickle">pickle</a></li>
|
||
<li><a class="reference internal" href="#pickletools">pickletools</a></li>
|
||
<li><a class="reference internal" href="#pydoc">pydoc</a></li>
|
||
<li><a class="reference internal" href="#random">random</a></li>
|
||
<li><a class="reference internal" href="#re">re</a></li>
|
||
<li><a class="reference internal" href="#readline">readline</a></li>
|
||
<li><a class="reference internal" href="#rlcompleter">rlcompleter</a></li>
|
||
<li><a class="reference internal" href="#shlex">shlex</a></li>
|
||
<li><a class="reference internal" href="#site">site</a></li>
|
||
<li><a class="reference internal" href="#sqlite3">sqlite3</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="#ssl">ssl</a></li>
|
||
<li><a class="reference internal" href="#statistics">statistics</a></li>
|
||
<li><a class="reference internal" href="#struct">struct</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="#telnetlib">telnetlib</a></li>
|
||
<li><a class="reference internal" href="#time">time</a></li>
|
||
<li><a class="reference internal" href="#timeit">timeit</a></li>
|
||
<li><a class="reference internal" href="#tkinter">tkinter</a></li>
|
||
<li><a class="reference internal" href="#traceback">回溯</a></li>
|
||
<li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
|
||
<li><a class="reference internal" href="#typing">typing</a></li>
|
||
<li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
|
||
<li><a class="reference internal" href="#unittest-mock">unittest.mock</a></li>
|
||
<li><a class="reference internal" href="#urllib-request">urllib.request</a></li>
|
||
<li><a class="reference internal" href="#urllib-robotparser">urllib.robotparser</a></li>
|
||
<li><a class="reference internal" href="#venv">venv</a></li>
|
||
<li><a class="reference internal" href="#warnings">warnings</a></li>
|
||
<li><a class="reference internal" href="#winreg">winreg</a></li>
|
||
<li><a class="reference internal" href="#winsound">winsound</a></li>
|
||
<li><a class="reference internal" href="#xmlrpc-client">xmlrpc.client</a></li>
|
||
<li><a class="reference internal" href="#zipfile">zipfile</a></li>
|
||
<li><a class="reference internal" href="#zlib">zlib</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#optimizations">性能优化</a></li>
|
||
<li><a class="reference internal" href="#build-and-c-api-changes">构建和 C API 的改变</a></li>
|
||
<li><a class="reference internal" href="#other-improvements">其他改进</a></li>
|
||
<li><a class="reference internal" href="#deprecated">弃用</a><ul>
|
||
<li><a class="reference internal" href="#new-keywords">新关键字</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="#asynchat">asynchat</a></li>
|
||
<li><a class="reference internal" href="#asyncore">asyncore</a></li>
|
||
<li><a class="reference internal" href="#dbm">dbm</a></li>
|
||
<li><a class="reference internal" href="#id2">distutils</a></li>
|
||
<li><a class="reference internal" href="#grp">grp</a></li>
|
||
<li><a class="reference internal" href="#id3">importlib</a></li>
|
||
<li><a class="reference internal" href="#id4">os</a></li>
|
||
<li><a class="reference internal" href="#id5">re</a></li>
|
||
<li><a class="reference internal" href="#id6">ssl</a></li>
|
||
<li><a class="reference internal" href="#id7">tkinter</a></li>
|
||
<li><a class="reference internal" href="#id8">venv</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="#deprecated-build-options">弃用的构建选项</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#removed">移除</a><ul>
|
||
<li><a class="reference internal" href="#api-and-feature-removals">API 与特性的移除</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#porting-to-python-3-6">移植到Python 3.6</a><ul>
|
||
<li><a class="reference internal" href="#changes-in-python-command-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>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-6-2">Python 3.6.2 中的重要变化</a><ul>
|
||
<li><a class="reference internal" href="#new-make-regen-all-build-target">新增 <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> 构建目标</a></li>
|
||
<li><a class="reference internal" href="#removal-of-make-touch-build-target">移除了 <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> 构建目标</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-6-4">Python 3.6.4 中的重要变化</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-6-5">Python 3.6.5 中的重要变化</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-6-7">Python 3.6.7 中的重要变化</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-6-10">Python 3.6.10 中的重要变化</a></li>
|
||
<li><a class="reference internal" href="#notable-changes-in-python-3-6-13">Python 3.6.13 中的重要变化</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<h4>上一个主题</h4>
|
||
<p class="topless"><a href="3.7.html"
|
||
title="上一章">Python 3.7 有什么新变化</a></p>
|
||
<h4>下一个主题</h4>
|
||
<p class="topless"><a href="3.5.html"
|
||
title="下一章">Python 3.5 有什么新变化</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.6.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.5.html" title="Python 3.5 有什么新变化"
|
||
>下一页</a> |</li>
|
||
<li class="right" >
|
||
<a href="3.7.html" title="Python 3.7 有什么新变化"
|
||
>上一页</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> »</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> »
|
||
</li>
|
||
|
||
<li class="nav-item nav-item-1"><a href="index.html" >Python的新变化</a> »</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">
|
||
© <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> |