gooderp18绿色标准版
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

2690 lines
322KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="What’s New In Python 3.5" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/whatsnew/3.5.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Editors, Elvis Pranskevichus < elvis@magic.io>, Yury Selivanov < yury@magic.io>,. This article explains the new features in Python 3.5, compared to 3.4. Python 3.5 was released on September 13, 201..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Editors, Elvis Pranskevichus < elvis@magic.io>, Yury Selivanov < yury@magic.io>,. This article explains the new features in Python 3.5, compared to 3.4. Python 3.5 was released on September 13, 201..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>What’s New In Python 3.5 &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="What’s New In Python 3.4" href="3.4.html" />
  33. <link rel="prev" title="What’s New In Python 3.6" href="3.6.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/whatsnew/3.5.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" 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"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#">What’s New In Python 3.5</a><ul>
  86. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  87. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  88. <li><a class="reference internal" href="#pep-492-coroutines-with-async-and-await-syntax">PEP 492 - Coroutines with async and await syntax</a></li>
  89. <li><a class="reference internal" href="#pep-465-a-dedicated-infix-operator-for-matrix-multiplication">PEP 465 - A dedicated infix operator for matrix multiplication</a></li>
  90. <li><a class="reference internal" href="#pep-448-additional-unpacking-generalizations">PEP 448 - Additional Unpacking Generalizations</a></li>
  91. <li><a class="reference internal" href="#pep-461-percent-formatting-support-for-bytes-and-bytearray">PEP 461 - percent formatting support for bytes and bytearray</a></li>
  92. <li><a class="reference internal" href="#pep-484-type-hints">PEP 484 - Type Hints</a></li>
  93. <li><a class="reference internal" href="#pep-471-os-scandir-function-a-better-and-faster-directory-iterator">PEP 471 - os.scandir() function – a better and faster directory iterator</a></li>
  94. <li><a class="reference internal" href="#pep-475-retry-system-calls-failing-with-eintr">PEP 475: Retry system calls failing with EINTR</a></li>
  95. <li><a class="reference internal" href="#pep-479-change-stopiteration-handling-inside-generators">PEP 479: Change StopIteration handling inside generators</a></li>
  96. <li><a class="reference internal" href="#pep-485-a-function-for-testing-approximate-equality">PEP 485: A function for testing approximate equality</a></li>
  97. <li><a class="reference internal" href="#pep-486-make-the-python-launcher-aware-of-virtual-environments">PEP 486: Make the Python Launcher aware of virtual environments</a></li>
  98. <li><a class="reference internal" href="#pep-488-elimination-of-pyo-files">PEP 488: Elimination of PYO files</a></li>
  99. <li><a class="reference internal" href="#pep-489-multi-phase-extension-module-initialization">PEP 489: Multi-phase extension module initialization</a></li>
  100. </ul>
  101. </li>
  102. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  103. <li><a class="reference internal" href="#new-modules">New Modules</a><ul>
  104. <li><a class="reference internal" href="#typing">typing</a></li>
  105. <li><a class="reference internal" href="#zipapp">zipapp</a></li>
  106. </ul>
  107. </li>
  108. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  109. <li><a class="reference internal" href="#argparse">argparse</a></li>
  110. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  111. <li><a class="reference internal" href="#bz2">bz2</a></li>
  112. <li><a class="reference internal" href="#cgi">cgi</a></li>
  113. <li><a class="reference internal" href="#cmath">cmath</a></li>
  114. <li><a class="reference internal" href="#code">code</a></li>
  115. <li><a class="reference internal" href="#collections">collections</a></li>
  116. <li><a class="reference internal" href="#collections-abc">collections.abc</a></li>
  117. <li><a class="reference internal" href="#compileall">compileall</a></li>
  118. <li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li>
  119. <li><a class="reference internal" href="#configparser">configparser</a></li>
  120. <li><a class="reference internal" href="#contextlib">contextlib</a></li>
  121. <li><a class="reference internal" href="#csv">csv</a></li>
  122. <li><a class="reference internal" href="#curses">curses</a></li>
  123. <li><a class="reference internal" href="#dbm">dbm</a></li>
  124. <li><a class="reference internal" href="#difflib">difflib</a></li>
  125. <li><a class="reference internal" href="#distutils">distutils</a></li>
  126. <li><a class="reference internal" href="#doctest">doctest</a></li>
  127. <li><a class="reference internal" href="#email">email</a></li>
  128. <li><a class="reference internal" href="#enum">enum</a></li>
  129. <li><a class="reference internal" href="#faulthandler">faulthandler</a></li>
  130. <li><a class="reference internal" href="#functools">functools</a></li>
  131. <li><a class="reference internal" href="#glob">glob</a></li>
  132. <li><a class="reference internal" href="#gzip">gzip</a></li>
  133. <li><a class="reference internal" href="#heapq">heapq</a></li>
  134. <li><a class="reference internal" href="#http">http</a></li>
  135. <li><a class="reference internal" href="#http-client">http.client</a></li>
  136. <li><a class="reference internal" href="#idlelib-and-idle">idlelib and IDLE</a></li>
  137. <li><a class="reference internal" href="#imaplib">imaplib</a></li>
  138. <li><a class="reference internal" href="#imghdr">imghdr</a></li>
  139. <li><a class="reference internal" href="#importlib">importlib</a></li>
  140. <li><a class="reference internal" href="#inspect">inspect</a></li>
  141. <li><a class="reference internal" href="#io">io</a></li>
  142. <li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
  143. <li><a class="reference internal" href="#json">json</a></li>
  144. <li><a class="reference internal" href="#linecache">linecache</a></li>
  145. <li><a class="reference internal" href="#locale">locale</a></li>
  146. <li><a class="reference internal" href="#logging">logging</a></li>
  147. <li><a class="reference internal" href="#lzma">lzma</a></li>
  148. <li><a class="reference internal" href="#math">math</a></li>
  149. <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
  150. <li><a class="reference internal" href="#operator">operator</a></li>
  151. <li><a class="reference internal" href="#os">os</a></li>
  152. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  153. <li><a class="reference internal" href="#pickle">pickle</a></li>
  154. <li><a class="reference internal" href="#poplib">poplib</a></li>
  155. <li><a class="reference internal" href="#re">re</a></li>
  156. <li><a class="reference internal" href="#readline">readline</a></li>
  157. <li><a class="reference internal" href="#selectors">selectors</a></li>
  158. <li><a class="reference internal" href="#shutil">shutil</a></li>
  159. <li><a class="reference internal" href="#signal">signal</a></li>
  160. <li><a class="reference internal" href="#smtpd">smtpd</a></li>
  161. <li><a class="reference internal" href="#smtplib">smtplib</a></li>
  162. <li><a class="reference internal" href="#sndhdr">sndhdr</a></li>
  163. <li><a class="reference internal" href="#socket">socket</a></li>
  164. <li><a class="reference internal" href="#ssl">ssl</a><ul>
  165. <li><a class="reference internal" href="#memory-bio-support">Memory BIO Support</a></li>
  166. <li><a class="reference internal" href="#application-layer-protocol-negotiation-support">Application-Layer Protocol Negotiation Support</a></li>
  167. <li><a class="reference internal" href="#other-changes">Other Changes</a></li>
  168. </ul>
  169. </li>
  170. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  171. <li><a class="reference internal" href="#subprocess">subprocess</a></li>
  172. <li><a class="reference internal" href="#sys">sys</a></li>
  173. <li><a class="reference internal" href="#sysconfig">sysconfig</a></li>
  174. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  175. <li><a class="reference internal" href="#threading">threading</a></li>
  176. <li><a class="reference internal" href="#time">time</a></li>
  177. <li><a class="reference internal" href="#timeit">timeit</a></li>
  178. <li><a class="reference internal" href="#tkinter">tkinter</a></li>
  179. <li><a class="reference internal" href="#traceback">traceback</a></li>
  180. <li><a class="reference internal" href="#types">types</a></li>
  181. <li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
  182. <li><a class="reference internal" href="#unittest">unittest</a></li>
  183. <li><a class="reference internal" href="#unittest-mock">unittest.mock</a></li>
  184. <li><a class="reference internal" href="#urllib">urllib</a></li>
  185. <li><a class="reference internal" href="#wsgiref">wsgiref</a></li>
  186. <li><a class="reference internal" href="#xmlrpc">xmlrpc</a></li>
  187. <li><a class="reference internal" href="#xml-sax">xml.sax</a></li>
  188. <li><a class="reference internal" href="#zipfile">zipfile</a></li>
  189. </ul>
  190. </li>
  191. <li><a class="reference internal" href="#other-module-level-changes">Other module-level changes</a></li>
  192. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  193. <li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
  194. <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
  195. <li><a class="reference internal" href="#new-keywords">New Keywords</a></li>
  196. <li><a class="reference internal" href="#deprecated-python-behavior">Deprecated Python Behavior</a></li>
  197. <li><a class="reference internal" href="#unsupported-operating-systems">Unsupported Operating Systems</a></li>
  198. <li><a class="reference internal" href="#deprecated-python-modules-functions-and-methods">Deprecated Python modules, functions and methods</a></li>
  199. </ul>
  200. </li>
  201. <li><a class="reference internal" href="#removed">Removed</a><ul>
  202. <li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
  203. </ul>
  204. </li>
  205. <li><a class="reference internal" href="#porting-to-python-3-5">Porting to Python 3.5</a><ul>
  206. <li><a class="reference internal" href="#changes-in-python-behavior">Changes in Python behavior</a></li>
  207. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  208. <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
  209. </ul>
  210. </li>
  211. <li><a class="reference internal" href="#notable-changes-in-python-3-5-4">Notable changes in Python 3.5.4</a><ul>
  212. <li><a class="reference internal" href="#new-make-regen-all-build-target">New <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> build target</a></li>
  213. <li><a class="reference internal" href="#removal-of-make-touch-build-target">Removal of <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> build target</a></li>
  214. </ul>
  215. </li>
  216. </ul>
  217. </li>
  218. </ul>
  219. </div>
  220. <div>
  221. <h4>Previous topic</h4>
  222. <p class="topless"><a href="3.6.html"
  223. title="previous chapter">What’s New In Python 3.6</a></p>
  224. </div>
  225. <div>
  226. <h4>Next topic</h4>
  227. <p class="topless"><a href="3.4.html"
  228. title="next chapter">What’s New In Python 3.4</a></p>
  229. </div>
  230. <div role="note" aria-label="source link">
  231. <h3>This Page</h3>
  232. <ul class="this-page-menu">
  233. <li><a href="../bugs.html">Report a Bug</a></li>
  234. <li>
  235. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.5.rst"
  236. rel="nofollow">Show Source
  237. </a>
  238. </li>
  239. </ul>
  240. </div>
  241. </nav>
  242. </div>
  243. </div>
  244. <div class="related" role="navigation" aria-label="related navigation">
  245. <h3>Navigation</h3>
  246. <ul>
  247. <li class="right" style="margin-right: 10px">
  248. <a href="../genindex.html" title="General Index"
  249. accesskey="I">index</a></li>
  250. <li class="right" >
  251. <a href="../py-modindex.html" title="Python Module Index"
  252. >modules</a> |</li>
  253. <li class="right" >
  254. <a href="3.4.html" title="What’s New In Python 3.4"
  255. accesskey="N">next</a> |</li>
  256. <li class="right" >
  257. <a href="3.6.html" title="What’s New In Python 3.6"
  258. accesskey="P">previous</a> |</li>
  259. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  260. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  261. <li class="switchers">
  262. <div class="language_switcher_placeholder"></div>
  263. <div class="version_switcher_placeholder"></div>
  264. </li>
  265. <li>
  266. </li>
  267. <li id="cpython-language-and-version">
  268. <a href="../index.html">3.12.3 Documentation</a> &#187;
  269. </li>
  270. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> &#187;</li>
  271. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.5</a></li>
  272. <li class="right">
  273. <div class="inline-search" role="search">
  274. <form class="inline-search" action="../search.html" method="get">
  275. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  276. <input type="submit" value="Go" />
  277. </form>
  278. </div>
  279. |
  280. </li>
  281. <li class="right">
  282. <label class="theme-selector-label">
  283. Theme
  284. <select class="theme-selector" oninput="activateTheme(this.value)">
  285. <option value="auto" selected>Auto</option>
  286. <option value="light">Light</option>
  287. <option value="dark">Dark</option>
  288. </select>
  289. </label> |</li>
  290. </ul>
  291. </div>
  292. <div class="document">
  293. <div class="documentwrapper">
  294. <div class="bodywrapper">
  295. <div class="body" role="main">
  296. <section id="what-s-new-in-python-3-5">
  297. <h1>What’s New In Python 3.5<a class="headerlink" href="#what-s-new-in-python-3-5" title="Link to this heading">¶</a></h1>
  298. <dl class="field-list simple">
  299. <dt class="field-odd">Editors<span class="colon">:</span></dt>
  300. <dd class="field-odd"><p>Elvis Pranskevichus &lt;<a class="reference external" href="mailto:elvis&#37;&#52;&#48;magic&#46;io">elvis<span>&#64;</span>magic<span>&#46;</span>io</a>&gt;, Yury Selivanov &lt;<a class="reference external" href="mailto:yury&#37;&#52;&#48;magic&#46;io">yury<span>&#64;</span>magic<span>&#46;</span>io</a>&gt;</p>
  301. </dd>
  302. </dl>
  303. <p>This article explains the new features in Python 3.5, compared to 3.4.
  304. Python 3.5 was released on September 13, 2015.  See the
  305. <a class="reference external" href="https://docs.python.org/3.5/whatsnew/changelog.html">changelog</a> for a full
  306. list of changes.</p>
  307. <div class="admonition seealso">
  308. <p class="admonition-title">See also</p>
  309. <p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0478/"><strong>PEP 478</strong></a> - Python 3.5 Release Schedule</p>
  310. </div>
  311. <section id="summary-release-highlights">
  312. <h2>Summary – Release highlights<a class="headerlink" href="#summary-release-highlights" title="Link to this heading">¶</a></h2>
  313. <p>New syntax features:</p>
  314. <ul class="simple">
  315. <li><p><a class="reference internal" href="#whatsnew-pep-492"><span class="std std-ref">PEP 492</span></a>, coroutines with async and await syntax.</p></li>
  316. <li><p><a class="reference internal" href="#whatsnew-pep-465"><span class="std std-ref">PEP 465</span></a>, a new matrix multiplication operator: <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">&#64;</span> <span class="pre">b</span></code>.</p></li>
  317. <li><p><a class="reference internal" href="#whatsnew-pep-448"><span class="std std-ref">PEP 448</span></a>, additional unpacking generalizations.</p></li>
  318. </ul>
  319. <p>New library modules:</p>
  320. <ul class="simple">
  321. <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="#whatsnew-pep-484"><span class="std std-ref">PEP 484 – Type Hints</span></a>.</p></li>
  322. <li><p><a class="reference internal" href="../library/zipapp.html#module-zipapp" title="zipapp: Manage executable Python zip archives"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipapp</span></code></a>: <a class="reference internal" href="#whatsnew-zipapp"><span class="std std-ref">PEP 441 Improving Python ZIP Application Support</span></a>.</p></li>
  323. </ul>
  324. <p>New built-in features:</p>
  325. <ul class="simple">
  326. <li><p><code class="docutils literal notranslate"><span class="pre">bytes</span> <span class="pre">%</span> <span class="pre">args</span></code>, <code class="docutils literal notranslate"><span class="pre">bytearray</span> <span class="pre">%</span> <span class="pre">args</span></code>: <a class="reference internal" href="#whatsnew-pep-461"><span class="std std-ref">PEP 461</span></a> –
  327. Adding <code class="docutils literal notranslate"><span class="pre">%</span></code> formatting to bytes and bytearray.</p></li>
  328. <li><p>New <a class="reference internal" href="../library/stdtypes.html#bytes.hex" title="bytes.hex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytes.hex()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#bytearray.hex" title="bytearray.hex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytearray.hex()</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#memoryview.hex" title="memoryview.hex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">memoryview.hex()</span></code></a>
  329. methods. (Contributed by Arnon Yaari in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9951">bpo-9951</a>.)</p></li>
  330. <li><p><a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-class docutils literal notranslate"><span class="pre">memoryview</span></code></a> now supports tuple indexing (including multi-dimensional).
  331. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23632">bpo-23632</a>.)</p></li>
  332. <li><p>Generators have a new <code class="docutils literal notranslate"><span class="pre">gi_yieldfrom</span></code> attribute, which returns the
  333. object being iterated by <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> expressions. (Contributed
  334. by Benno Leslie and Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24450">bpo-24450</a>.)</p></li>
  335. <li><p>A new <a class="reference internal" href="../library/exceptions.html#RecursionError" title="RecursionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RecursionError</span></code></a> exception is now raised when maximum
  336. recursion depth is reached. (Contributed by Georg Brandl
  337. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19235">bpo-19235</a>.)</p></li>
  338. </ul>
  339. <p>CPython implementation improvements:</p>
  340. <ul class="simple">
  341. <li><p>When the <code class="docutils literal notranslate"><span class="pre">LC_TYPE</span></code> locale is the POSIX locale (<code class="docutils literal notranslate"><span class="pre">C</span></code> locale),
  342. <a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a> now use the
  343. <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code> error handler, instead of the <code class="docutils literal notranslate"><span class="pre">strict</span></code> error handler.
  344. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19977">bpo-19977</a>.)</p></li>
  345. <li><p><code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files are no longer used and have been replaced by a more flexible
  346. scheme that includes the optimization level explicitly in <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> name.
  347. (See <a class="reference internal" href="#whatsnew-pep-488"><span class="std std-ref">PEP 488 overview</span></a>.)</p></li>
  348. <li><p>Builtin and extension modules are now initialized in a multi-phase process,
  349. which is similar to how Python modules are loaded.
  350. (See <a class="reference internal" href="#whatsnew-pep-489"><span class="std std-ref">PEP 489 overview</span></a>.)</p></li>
  351. </ul>
  352. <p>Significant improvements in the standard library:</p>
  353. <ul class="simple">
  354. <li><p><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">collections.OrderedDict</span></code></a> is now
  355. <a class="reference internal" href="#whatsnew-ordereddict"><span class="std std-ref">implemented in C</span></a>, which makes it
  356. 4 to 100 times faster.</p></li>
  357. <li><p>The <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> module gained
  358. <a class="reference internal" href="#whatsnew-sslmemorybio"><span class="std std-ref">support for Memory BIO</span></a>, which decouples SSL
  359. protocol handling from network IO.</p></li>
  360. <li><p>The new <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> function provides a
  361. <a class="reference internal" href="#whatsnew-pep-471"><span class="std std-ref">better and significantly faster way</span></a>
  362. of directory traversal.</p></li>
  363. <li><p><a class="reference internal" href="../library/functools.html#functools.lru_cache" title="functools.lru_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.lru_cache()</span></code></a> has been mostly
  364. <a class="reference internal" href="#whatsnew-lrucache"><span class="std std-ref">reimplemented in C</span></a>, yielding much better
  365. performance.</p></li>
  366. <li><p>The new <a class="reference internal" href="../library/subprocess.html#subprocess.run" title="subprocess.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">subprocess.run()</span></code></a> function provides a
  367. <a class="reference internal" href="#whatsnew-subprocess"><span class="std std-ref">streamlined way to run subprocesses</span></a>.</p></li>
  368. <li><p>The <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> module has been significantly
  369. <a class="reference internal" href="#whatsnew-traceback"><span class="std std-ref">enhanced</span></a> for improved
  370. performance and developer convenience.</p></li>
  371. </ul>
  372. <p>Security improvements:</p>
  373. <ul class="simple">
  374. <li><p>SSLv3 is now disabled throughout the standard library.
  375. It can still be enabled by instantiating a <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a>
  376. manually. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22638">bpo-22638</a> for more details; this change was
  377. backported to CPython 3.4 and 2.7.)</p></li>
  378. <li><p>HTTP cookie parsing is now stricter, in order to protect
  379. against potential injection attacks. (Contributed by Antoine Pitrou
  380. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22796">bpo-22796</a>.)</p></li>
  381. </ul>
  382. <p>Windows improvements:</p>
  383. <ul class="simple">
  384. <li><p>A new installer for Windows has replaced the old MSI.
  385. See <a class="reference internal" href="../using/windows.html#using-on-windows"><span class="std std-ref">Using Python on Windows</span></a> for more information.</p></li>
  386. <li><p>Windows builds now use Microsoft Visual C++ 14.0, and extension modules
  387. should use the same.</p></li>
  388. </ul>
  389. <p>Please read on for a comprehensive list of user-facing changes, including many
  390. other smaller improvements, CPython optimizations, deprecations, and potential
  391. porting issues.</p>
  392. </section>
  393. <section id="new-features">
  394. <h2>New Features<a class="headerlink" href="#new-features" title="Link to this heading">¶</a></h2>
  395. <section id="pep-492-coroutines-with-async-and-await-syntax">
  396. <span id="whatsnew-pep-492"></span><h3>PEP 492 - Coroutines with async and await syntax<a class="headerlink" href="#pep-492-coroutines-with-async-and-await-syntax" title="Link to this heading">¶</a></h3>
  397. <p><span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0492/"><strong>PEP 492</strong></a> greatly improves support for asynchronous programming in Python
  398. by adding <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitable objects</span></a>,
  399. <a class="reference internal" href="../glossary.html#term-coroutine-function"><span class="xref std std-term">coroutine functions</span></a>,
  400. <a class="reference internal" href="../glossary.html#term-asynchronous-iterable"><span class="xref std std-term">asynchronous iteration</span></a>,
  401. and <a class="reference internal" href="../glossary.html#term-asynchronous-context-manager"><span class="xref std std-term">asynchronous context managers</span></a>.</p>
  402. <p>Coroutine functions are declared using the new <a class="reference internal" href="../reference/compound_stmts.html#async-def"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">def</span></code></a> syntax:</p>
  403. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">async</span> <span class="k">def</span> <span class="nf">coro</span><span class="p">():</span>
  404. <span class="gp">... </span> <span class="k">return</span> <span class="s1">&#39;spam&#39;</span>
  405. </pre></div>
  406. </div>
  407. <p>Inside a coroutine function, the new <a class="reference internal" href="../reference/expressions.html#await"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">await</span></code></a> expression can be used
  408. to suspend coroutine execution until the result is available. Any object
  409. can be <em>awaited</em>, as long as it implements the <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitable</span></a> protocol by
  410. defining the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__await__()</span></code> method.</p>
  411. <p>PEP 492 also adds <a class="reference internal" href="../reference/compound_stmts.html#async-for"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">for</span></code></a> statement for convenient iteration
  412. over asynchronous iterables.</p>
  413. <p>An example of a rudimentary HTTP client written using the new syntax:</p>
  414. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">asyncio</span>
  415. <span class="k">async</span> <span class="k">def</span> <span class="nf">http_get</span><span class="p">(</span><span class="n">domain</span><span class="p">):</span>
  416. <span class="n">reader</span><span class="p">,</span> <span class="n">writer</span> <span class="o">=</span> <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">open_connection</span><span class="p">(</span><span class="n">domain</span><span class="p">,</span> <span class="mi">80</span><span class="p">)</span>
  417. <span class="n">writer</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\r\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span>
  418. <span class="sa">b</span><span class="s1">&#39;GET / HTTP/1.1&#39;</span><span class="p">,</span>
  419. <span class="sa">b</span><span class="s1">&#39;Host: %b&#39;</span> <span class="o">%</span> <span class="n">domain</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;latin-1&#39;</span><span class="p">),</span>
  420. <span class="sa">b</span><span class="s1">&#39;Connection: close&#39;</span><span class="p">,</span>
  421. <span class="sa">b</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="sa">b</span><span class="s1">&#39;&#39;</span>
  422. <span class="p">]))</span>
  423. <span class="k">async</span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">reader</span><span class="p">:</span>
  424. <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;&gt;&gt;&gt;&#39;</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
  425. <span class="n">writer</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
  426. <span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>
  427. <span class="k">try</span><span class="p">:</span>
  428. <span class="n">loop</span><span class="o">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">http_get</span><span class="p">(</span><span class="s1">&#39;example.com&#39;</span><span class="p">))</span>
  429. <span class="k">finally</span><span class="p">:</span>
  430. <span class="n">loop</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
  431. </pre></div>
  432. </div>
  433. <p>Similarly to asynchronous iteration, there is a new syntax for asynchronous
  434. context managers. The following script:</p>
  435. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">asyncio</span>
  436. <span class="k">async</span> <span class="k">def</span> <span class="nf">coro</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">lock</span><span class="p">):</span>
  437. <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;coro </span><span class="si">{}</span><span class="s1">: waiting for lock&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
  438. <span class="k">async</span> <span class="k">with</span> <span class="n">lock</span><span class="p">:</span>
  439. <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;coro </span><span class="si">{}</span><span class="s1">: holding the lock&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
  440. <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="mi">1</span><span class="p">)</span>
  441. <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;coro </span><span class="si">{}</span><span class="s1">: releasing the lock&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
  442. <span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_event_loop</span><span class="p">()</span>
  443. <span class="n">lock</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">Lock</span><span class="p">()</span>
  444. <span class="n">coros</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">gather</span><span class="p">(</span><span class="n">coro</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">lock</span><span class="p">),</span> <span class="n">coro</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">lock</span><span class="p">))</span>
  445. <span class="k">try</span><span class="p">:</span>
  446. <span class="n">loop</span><span class="o">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">coros</span><span class="p">)</span>
  447. <span class="k">finally</span><span class="p">:</span>
  448. <span class="n">loop</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
  449. </pre></div>
  450. </div>
  451. <p>will output:</p>
  452. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">coro</span> <span class="mi">2</span><span class="p">:</span> <span class="n">waiting</span> <span class="k">for</span> <span class="n">lock</span>
  453. <span class="n">coro</span> <span class="mi">2</span><span class="p">:</span> <span class="n">holding</span> <span class="n">the</span> <span class="n">lock</span>
  454. <span class="n">coro</span> <span class="mi">1</span><span class="p">:</span> <span class="n">waiting</span> <span class="k">for</span> <span class="n">lock</span>
  455. <span class="n">coro</span> <span class="mi">2</span><span class="p">:</span> <span class="n">releasing</span> <span class="n">the</span> <span class="n">lock</span>
  456. <span class="n">coro</span> <span class="mi">1</span><span class="p">:</span> <span class="n">holding</span> <span class="n">the</span> <span class="n">lock</span>
  457. <span class="n">coro</span> <span class="mi">1</span><span class="p">:</span> <span class="n">releasing</span> <span class="n">the</span> <span class="n">lock</span>
  458. </pre></div>
  459. </div>
  460. <p>Note that both <a class="reference internal" href="../reference/compound_stmts.html#async-for"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">for</span></code></a> and <a class="reference internal" href="../reference/compound_stmts.html#async-with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">with</span></code></a> can only
  461. be used inside a coroutine function declared with <a class="reference internal" href="../reference/compound_stmts.html#async-def"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">def</span></code></a>.</p>
  462. <p>Coroutine functions are intended to be run inside a compatible event loop,
  463. such as the <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio-event-loop"><span class="std std-ref">asyncio loop</span></a>.</p>
  464. <div class="admonition note">
  465. <p class="admonition-title">Note</p>
  466. <div class="versionchanged">
  467. <p><span class="versionmodified changed">Changed in version 3.5.2: </span>Starting with CPython 3.5.2, <code class="docutils literal notranslate"><span class="pre">__aiter__</span></code> can directly return
  468. <a class="reference internal" href="../glossary.html#term-asynchronous-iterator"><span class="xref std std-term">asynchronous iterators</span></a>. Returning
  469. an <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitable</span></a> object will result in a
  470. <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>
  471. <p>See more details in the <a class="reference internal" href="../reference/datamodel.html#async-iterators"><span class="std std-ref">Asynchronous Iterators</span></a> documentation
  472. section.</p>
  473. </div>
  474. </div>
  475. <div class="admonition seealso">
  476. <p class="admonition-title">See also</p>
  477. <dl class="simple">
  478. <dt><span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0492/"><strong>PEP 492</strong></a> – Coroutines with async and await syntax</dt><dd><p>PEP written and implemented by Yury Selivanov.</p>
  479. </dd>
  480. </dl>
  481. </div>
  482. </section>
  483. <section id="pep-465-a-dedicated-infix-operator-for-matrix-multiplication">
  484. <span id="whatsnew-pep-465"></span><h3>PEP 465 - A dedicated infix operator for matrix multiplication<a class="headerlink" href="#pep-465-a-dedicated-infix-operator-for-matrix-multiplication" title="Link to this heading">¶</a></h3>
  485. <p><span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0465/"><strong>PEP 465</strong></a> adds the <code class="docutils literal notranslate"><span class="pre">&#64;</span></code> infix operator for matrix multiplication.
  486. Currently, no builtin Python types implement the new operator, however, it
  487. can be implemented by defining <code class="xref py py-meth docutils literal notranslate"><span class="pre">__matmul__()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">__rmatmul__()</span></code>,
  488. and <code class="xref py py-meth docutils literal notranslate"><span class="pre">__imatmul__()</span></code> for regular, reflected, and in-place matrix
  489. multiplication. The semantics of these methods is similar to that of
  490. methods defining other infix arithmetic operators.</p>
  491. <p>Matrix multiplication is a notably common operation in many fields of
  492. mathematics, science, engineering, and the addition of <code class="docutils literal notranslate"><span class="pre">&#64;</span></code> allows writing
  493. cleaner code:</p>
  494. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">S</span> <span class="o">=</span> <span class="p">(</span><span class="n">H</span> <span class="o">@</span> <span class="n">beta</span> <span class="o">-</span> <span class="n">r</span><span class="p">)</span><span class="o">.</span><span class="n">T</span> <span class="o">@</span> <span class="n">inv</span><span class="p">(</span><span class="n">H</span> <span class="o">@</span> <span class="n">V</span> <span class="o">@</span> <span class="n">H</span><span class="o">.</span><span class="n">T</span><span class="p">)</span> <span class="o">@</span> <span class="p">(</span><span class="n">H</span> <span class="o">@</span> <span class="n">beta</span> <span class="o">-</span> <span class="n">r</span><span class="p">)</span>
  495. </pre></div>
  496. </div>
  497. <p>instead of:</p>
  498. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">S</span> <span class="o">=</span> <span class="n">dot</span><span class="p">((</span><span class="n">dot</span><span class="p">(</span><span class="n">H</span><span class="p">,</span> <span class="n">beta</span><span class="p">)</span> <span class="o">-</span> <span class="n">r</span><span class="p">)</span><span class="o">.</span><span class="n">T</span><span class="p">,</span>
  499. <span class="n">dot</span><span class="p">(</span><span class="n">inv</span><span class="p">(</span><span class="n">dot</span><span class="p">(</span><span class="n">dot</span><span class="p">(</span><span class="n">H</span><span class="p">,</span> <span class="n">V</span><span class="p">),</span> <span class="n">H</span><span class="o">.</span><span class="n">T</span><span class="p">)),</span> <span class="n">dot</span><span class="p">(</span><span class="n">H</span><span class="p">,</span> <span class="n">beta</span><span class="p">)</span> <span class="o">-</span> <span class="n">r</span><span class="p">))</span>
  500. </pre></div>
  501. </div>
  502. <p>NumPy 1.10 has support for the new operator:</p>
  503. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">numpy</span>
  504. <span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
  505. <span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
  506. <span class="go">array([ 1., 1., 1.])</span>
  507. <span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
  508. <span class="gp">&gt;&gt;&gt; </span><span class="n">m</span>
  509. <span class="go">array([[ 1., 0., 0.],</span>
  510. <span class="go"> [ 0., 1., 0.],</span>
  511. <span class="go"> [ 0., 0., 1.]])</span>
  512. <span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">@</span> <span class="n">m</span>
  513. <span class="go">array([ 1., 1., 1.])</span>
  514. </pre></div>
  515. </div>
  516. <div class="admonition seealso">
  517. <p class="admonition-title">See also</p>
  518. <dl class="simple">
  519. <dt><span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0465/"><strong>PEP 465</strong></a> – A dedicated infix operator for matrix multiplication</dt><dd><p>PEP written by Nathaniel J. Smith; implemented by Benjamin Peterson.</p>
  520. </dd>
  521. </dl>
  522. </div>
  523. </section>
  524. <section id="pep-448-additional-unpacking-generalizations">
  525. <span id="whatsnew-pep-448"></span><h3>PEP 448 - Additional Unpacking Generalizations<a class="headerlink" href="#pep-448-additional-unpacking-generalizations" title="Link to this heading">¶</a></h3>
  526. <p><span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0448/"><strong>PEP 448</strong></a> extends the allowed uses of the <code class="docutils literal notranslate"><span class="pre">*</span></code> iterable unpacking
  527. operator and <code class="docutils literal notranslate"><span class="pre">**</span></code> dictionary unpacking operator. It is now possible
  528. to use an arbitrary number of unpackings in <a class="reference internal" href="../reference/expressions.html#calls"><span class="std std-ref">function calls</span></a>:</p>
  529. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="o">*</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="o">*</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="mi">3</span><span class="p">,</span> <span class="o">*</span><span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">])</span>
  530. <span class="go">1 2 3 4 5</span>
  531. <span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">fn</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
  532. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">)</span>
  533. <span class="gp">...</span>
  534. <span class="gp">&gt;&gt;&gt; </span><span class="n">fn</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">},</span> <span class="o">**</span><span class="p">{</span><span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;d&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">})</span>
  535. <span class="go">1 2 3 4</span>
  536. </pre></div>
  537. </div>
  538. <p>Similarly, tuple, list, set, and dictionary displays allow multiple
  539. unpackings (see <a class="reference internal" href="../reference/expressions.html#exprlists"><span class="std std-ref">Expression lists</span></a> and <a class="reference internal" href="../reference/expressions.html#dict"><span class="std std-ref">Dictionary displays</span></a>):</p>
  540. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="o">*</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span> <span class="mi">4</span>
  541. <span class="go">(0, 1, 2, 3, 4)</span>
  542. <span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="o">*</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span> <span class="mi">4</span><span class="p">]</span>
  543. <span class="go">[0, 1, 2, 3, 4]</span>
  544. <span class="gp">&gt;&gt;&gt; </span><span class="p">{</span><span class="o">*</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span> <span class="mi">4</span><span class="p">,</span> <span class="o">*</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">7</span><span class="p">)}</span>
  545. <span class="go">{0, 1, 2, 3, 4, 5, 6, 7}</span>
  546. <span class="gp">&gt;&gt;&gt; </span><span class="p">{</span><span class="s1">&#39;x&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="o">**</span><span class="p">{</span><span class="s1">&#39;y&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">}}</span>
  547. <span class="go">{&#39;x&#39;: 1, &#39;y&#39;: 2}</span>
  548. </pre></div>
  549. </div>
  550. <div class="admonition seealso">
  551. <p class="admonition-title">See also</p>
  552. <dl class="simple">
  553. <dt><span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0448/"><strong>PEP 448</strong></a> – Additional Unpacking Generalizations</dt><dd><p>PEP written by Joshua Landau; implemented by Neil Girdhar,
  554. Thomas Wouters, and Joshua Landau.</p>
  555. </dd>
  556. </dl>
  557. </div>
  558. </section>
  559. <section id="pep-461-percent-formatting-support-for-bytes-and-bytearray">
  560. <span id="whatsnew-pep-461"></span><h3>PEP 461 - percent formatting support for bytes and bytearray<a class="headerlink" href="#pep-461-percent-formatting-support-for-bytes-and-bytearray" title="Link to this heading">¶</a></h3>
  561. <p><span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0461/"><strong>PEP 461</strong></a> adds support for the <code class="docutils literal notranslate"><span class="pre">%</span></code>
  562. <a class="reference internal" href="../library/stdtypes.html#bytes-formatting"><span class="std std-ref">interpolation operator</span></a> to <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>
  563. and <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a>.</p>
  564. <p>While interpolation is usually thought of as a string operation, there are
  565. cases where interpolation on <code class="docutils literal notranslate"><span class="pre">bytes</span></code> or <code class="docutils literal notranslate"><span class="pre">bytearrays</span></code> makes sense, and the
  566. work needed to make up for this missing functionality detracts from the
  567. overall readability of the code. This issue is particularly important when
  568. dealing with wire format protocols, which are often a mixture of binary
  569. and ASCII compatible text.</p>
  570. <p>Examples:</p>
  571. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="sa">b</span><span class="s1">&#39;Hello %b!&#39;</span> <span class="o">%</span> <span class="sa">b</span><span class="s1">&#39;World&#39;</span>
  572. <span class="go">b&#39;Hello World!&#39;</span>
  573. <span class="gp">&gt;&gt;&gt; </span><span class="sa">b</span><span class="s1">&#39;x=</span><span class="si">%i</span><span class="s1"> y=</span><span class="si">%f</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mf">2.5</span><span class="p">)</span>
  574. <span class="go">b&#39;x=1 y=2.500000&#39;</span>
  575. </pre></div>
  576. </div>
  577. <p>Unicode is not allowed for <code class="docutils literal notranslate"><span class="pre">%b</span></code>, but it is accepted by <code class="docutils literal notranslate"><span class="pre">%a</span></code> (equivalent of
  578. <code class="docutils literal notranslate"><span class="pre">repr(obj).encode('ascii',</span> <span class="pre">'backslashreplace')</span></code>):</p>
  579. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="sa">b</span><span class="s1">&#39;Hello %b!&#39;</span> <span class="o">%</span> <span class="s1">&#39;World&#39;</span>
  580. <span class="gt">Traceback (most recent call last):</span>
  581. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  582. <span class="gr">TypeError</span>: <span class="n">%b requires bytes, or an object that implements __bytes__, not &#39;str&#39;</span>
  583. <span class="gp">&gt;&gt;&gt; </span><span class="sa">b</span><span class="s1">&#39;price: </span><span class="si">%a</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="s1">&#39;10€&#39;</span>
  584. <span class="go">b&quot;price: &#39;10\\u20ac&#39;&quot;</span>
  585. </pre></div>
  586. </div>
  587. <p>Note that <code class="docutils literal notranslate"><span class="pre">%s</span></code> and <code class="docutils literal notranslate"><span class="pre">%r</span></code> conversion types, although supported, should
  588. only be used in codebases that need compatibility with Python 2.</p>
  589. <div class="admonition seealso">
  590. <p class="admonition-title">See also</p>
  591. <dl class="simple">
  592. <dt><span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0461/"><strong>PEP 461</strong></a> – Adding % formatting to bytes and bytearray</dt><dd><p>PEP written by Ethan Furman; implemented by Neil Schemenauer and
  593. Ethan Furman.</p>
  594. </dd>
  595. </dl>
  596. </div>
  597. </section>
  598. <section id="pep-484-type-hints">
  599. <span id="whatsnew-pep-484"></span><h3>PEP 484 - Type Hints<a class="headerlink" href="#pep-484-type-hints" title="Link to this heading">¶</a></h3>
  600. <p>Function annotation syntax has been a Python feature since version 3.0
  601. (<span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-3107/"><strong>PEP 3107</strong></a>), however the semantics of annotations has been left undefined.</p>
  602. <p>Experience has shown that the majority of function annotation
  603. uses were to provide type hints to function parameters and return values. It
  604. became evident that it would be beneficial for Python users, if the
  605. standard library included the base definitions and tools for type annotations.</p>
  606. <p><span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> introduces a <a class="reference internal" href="../glossary.html#term-provisional-API"><span class="xref std std-term">provisional module</span></a> to
  607. provide these standard definitions and tools, along with some conventions
  608. for situations where annotations are not available.</p>
  609. <p>For example, here is a simple function whose argument and return type
  610. are declared in the annotations:</p>
  611. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">greeting</span><span class="p">(</span><span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
  612. <span class="k">return</span> <span class="s1">&#39;Hello &#39;</span> <span class="o">+</span> <span class="n">name</span>
  613. </pre></div>
  614. </div>
  615. <p>While these annotations are available at runtime through the usual
  616. <code class="xref py py-attr docutils literal notranslate"><span class="pre">__annotations__</span></code> attribute, <em>no automatic type checking happens at
  617. runtime</em>. Instead, it is assumed that a separate off-line type checker
  618. (e.g. <a class="reference external" href="https://mypy-lang.org">mypy</a>) will be used for on-demand
  619. source code analysis.</p>
  620. <p>The type system supports unions, generic types, and a special type
  621. named <a class="reference internal" href="../library/typing.html#typing.Any" title="typing.Any"><code class="xref py py-class docutils literal notranslate"><span class="pre">Any</span></code></a> which is consistent with (i.e. assignable to
  622. and from) all types.</p>
  623. <div class="admonition seealso">
  624. <p class="admonition-title">See also</p>
  625. <ul class="simple">
  626. <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> module documentation</p></li>
  627. <li><dl class="simple">
  628. <dt><span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> – Type Hints</dt><dd><p>PEP written by Guido van Rossum, Jukka Lehtosalo, and Łukasz Langa;
  629. implemented by Guido van Rossum.</p>
  630. </dd>
  631. </dl>
  632. </li>
  633. <li><dl class="simple">
  634. <dt><span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0483/"><strong>PEP 483</strong></a> – The Theory of Type Hints</dt><dd><p>PEP written by Guido van Rossum</p>
  635. </dd>
  636. </dl>
  637. </li>
  638. </ul>
  639. </div>
  640. </section>
  641. <section id="pep-471-os-scandir-function-a-better-and-faster-directory-iterator">
  642. <span id="whatsnew-pep-471"></span><h3>PEP 471 - os.scandir() function – a better and faster directory iterator<a class="headerlink" href="#pep-471-os-scandir-function-a-better-and-faster-directory-iterator" title="Link to this heading">¶</a></h3>
  643. <p><span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0471/"><strong>PEP 471</strong></a> adds a new directory iteration function, <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>,
  644. to the standard library. Additionally, <a class="reference internal" href="../library/os.html#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.walk()</span></code></a> is now
  645. implemented using <code class="docutils literal notranslate"><span class="pre">scandir</span></code>, which makes it 3 to 5 times faster
  646. on POSIX systems and 7 to 20 times faster on Windows systems. This is
  647. largely achieved by greatly reducing the number of calls to <a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a>
  648. required to walk a directory tree.</p>
  649. <p>Additionally, <code class="docutils literal notranslate"><span class="pre">scandir</span></code> returns an iterator, as opposed to returning
  650. a list of file names, which improves memory efficiency when iterating
  651. over very large directories.</p>
  652. <p>The following example shows a simple use of <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> to display all
  653. the files (excluding directories) in the given <em>path</em> that don’t start with
  654. <code class="docutils literal notranslate"><span class="pre">'.'</span></code>. The <a class="reference internal" href="../library/os.html#os.DirEntry.is_file" title="os.DirEntry.is_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">entry.is_file()</span></code></a> call will generally
  655. not make an additional system call:</p>
  656. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">scandir</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
  657. <span class="k">if</span> <span class="ow">not</span> <span class="n">entry</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">entry</span><span class="o">.</span><span class="n">is_file</span><span class="p">():</span>
  658. <span class="nb">print</span><span class="p">(</span><span class="n">entry</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
  659. </pre></div>
  660. </div>
  661. <div class="admonition seealso">
  662. <p class="admonition-title">See also</p>
  663. <dl class="simple">
  664. <dt><span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0471/"><strong>PEP 471</strong></a> – os.scandir() function – a better and faster directory iterator</dt><dd><p>PEP written and implemented by Ben Hoyt with the help of Victor Stinner.</p>
  665. </dd>
  666. </dl>
  667. </div>
  668. </section>
  669. <section id="pep-475-retry-system-calls-failing-with-eintr">
  670. <span id="whatsnew-pep-475"></span><h3>PEP 475: Retry system calls failing with EINTR<a class="headerlink" href="#pep-475-retry-system-calls-failing-with-eintr" title="Link to this heading">¶</a></h3>
  671. <p>An <a class="reference internal" href="../library/errno.html#errno.EINTR" title="errno.EINTR"><code class="xref py py-const docutils literal notranslate"><span class="pre">errno.EINTR</span></code></a> error code is returned whenever a system call, that
  672. is waiting for I/O, is interrupted by a signal. Previously, Python would
  673. raise <a class="reference internal" href="../library/exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a> in such cases. This meant that, when writing a
  674. Python application, the developer had two choices:</p>
  675. <ol class="arabic simple">
  676. <li><p>Ignore the <code class="docutils literal notranslate"><span class="pre">InterruptedError</span></code>.</p></li>
  677. <li><p>Handle the <code class="docutils literal notranslate"><span class="pre">InterruptedError</span></code> and attempt to restart the interrupted
  678. system call at every call site.</p></li>
  679. </ol>
  680. <p>The first option makes an application fail intermittently.
  681. The second option adds a large amount of boilerplate that makes the
  682. code nearly unreadable. Compare:</p>
  683. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Hello World&quot;</span><span class="p">)</span>
  684. </pre></div>
  685. </div>
  686. <p>and:</p>
  687. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
  688. <span class="k">try</span><span class="p">:</span>
  689. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Hello World&quot;</span><span class="p">)</span>
  690. <span class="k">break</span>
  691. <span class="k">except</span> <span class="ne">InterruptedError</span><span class="p">:</span>
  692. <span class="k">continue</span>
  693. </pre></div>
  694. </div>
  695. <p><span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> implements automatic retry of system calls on
  696. <code class="docutils literal notranslate"><span class="pre">EINTR</span></code>. This removes the burden of dealing with <code class="docutils literal notranslate"><span class="pre">EINTR</span></code>
  697. or <a class="reference internal" href="../library/exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a> in user code in most situations and makes
  698. Python programs, including the standard library, more robust. Note that
  699. the system call is only retried if the signal handler does not raise an
  700. exception.</p>
  701. <p>Below is a list of functions which are now retried when interrupted
  702. by a signal:</p>
  703. <ul class="simple">
  704. <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> and <a class="reference internal" href="../library/io.html#io.open" title="io.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">io.open()</span></code></a>;</p></li>
  705. <li><p>functions of the <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> module;</p></li>
  706. <li><p><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> functions: <a class="reference internal" href="../library/os.html#os.fchdir" title="os.fchdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">fchdir()</span></code></a>, <a class="reference internal" href="../library/os.html#os.fchmod" title="os.fchmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">fchmod()</span></code></a>,
  707. <a class="reference internal" href="../library/os.html#os.fchown" title="os.fchown"><code class="xref py py-func docutils literal notranslate"><span class="pre">fchown()</span></code></a>, <a class="reference internal" href="../library/os.html#os.fdatasync" title="os.fdatasync"><code class="xref py py-func docutils literal notranslate"><span class="pre">fdatasync()</span></code></a>, <a class="reference internal" href="../library/os.html#os.fstat" title="os.fstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstat()</span></code></a>,
  708. <a class="reference internal" href="../library/os.html#os.fstatvfs" title="os.fstatvfs"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstatvfs()</span></code></a>, <a class="reference internal" href="../library/os.html#os.fsync" title="os.fsync"><code class="xref py py-func docutils literal notranslate"><span class="pre">fsync()</span></code></a>, <a class="reference internal" href="../library/os.html#os.ftruncate" title="os.ftruncate"><code class="xref py py-func docutils literal notranslate"><span class="pre">ftruncate()</span></code></a>,
  709. <a class="reference internal" href="../library/os.html#os.mkfifo" title="os.mkfifo"><code class="xref py py-func docutils literal notranslate"><span class="pre">mkfifo()</span></code></a>, <a class="reference internal" href="../library/os.html#os.mknod" title="os.mknod"><code class="xref py py-func docutils literal notranslate"><span class="pre">mknod()</span></code></a>, <a class="reference internal" href="../library/os.html#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>,
  710. <a class="reference internal" href="../library/os.html#os.posix_fadvise" title="os.posix_fadvise"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_fadvise()</span></code></a>, <a class="reference internal" href="../library/os.html#os.posix_fallocate" title="os.posix_fallocate"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_fallocate()</span></code></a>, <a class="reference internal" href="../library/os.html#os.pread" title="os.pread"><code class="xref py py-func docutils literal notranslate"><span class="pre">pread()</span></code></a>,
  711. <a class="reference internal" href="../library/os.html#os.pwrite" title="os.pwrite"><code class="xref py py-func docutils literal notranslate"><span class="pre">pwrite()</span></code></a>, <a class="reference internal" href="../library/os.html#os.read" title="os.read"><code class="xref py py-func docutils literal notranslate"><span class="pre">read()</span></code></a>, <a class="reference internal" href="../library/os.html#os.readv" title="os.readv"><code class="xref py py-func docutils literal notranslate"><span class="pre">readv()</span></code></a>, <a class="reference internal" href="../library/os.html#os.sendfile" title="os.sendfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">sendfile()</span></code></a>,
  712. <a class="reference internal" href="../library/os.html#os.wait3" title="os.wait3"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait3()</span></code></a>, <a class="reference internal" href="../library/os.html#os.wait4" title="os.wait4"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait4()</span></code></a>, <a class="reference internal" href="../library/os.html#os.wait" title="os.wait"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait()</span></code></a>,
  713. <a class="reference internal" href="../library/os.html#os.waitid" title="os.waitid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitid()</span></code></a>, <a class="reference internal" href="../library/os.html#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitpid()</span></code></a>, <a class="reference internal" href="../library/os.html#os.write" title="os.write"><code class="xref py py-func docutils literal notranslate"><span class="pre">write()</span></code></a>,
  714. <a class="reference internal" href="../library/os.html#os.writev" title="os.writev"><code class="xref py py-func docutils literal notranslate"><span class="pre">writev()</span></code></a>;</p></li>
  715. <li><p>special cases: <a class="reference internal" href="../library/os.html#os.close" title="os.close"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.close()</span></code></a> and <a class="reference internal" href="../library/os.html#os.dup2" title="os.dup2"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.dup2()</span></code></a> now ignore
  716. <a class="reference internal" href="../library/errno.html#errno.EINTR" title="errno.EINTR"><code class="xref py py-const docutils literal notranslate"><span class="pre">EINTR</span></code></a> errors; the syscall is not retried (see the PEP
  717. for the rationale);</p></li>
  718. <li><p><a class="reference internal" href="../library/select.html#module-select" title="select: Wait for I/O completion on multiple streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code></a> functions: <a class="reference internal" href="../library/select.html#select.devpoll.poll" title="select.devpoll.poll"><code class="xref py py-func docutils literal notranslate"><span class="pre">devpoll.poll()</span></code></a>,
  719. <a class="reference internal" href="../library/select.html#select.epoll.poll" title="select.epoll.poll"><code class="xref py py-func docutils literal notranslate"><span class="pre">epoll.poll()</span></code></a>,
  720. <a class="reference internal" href="../library/select.html#select.kqueue.control" title="select.kqueue.control"><code class="xref py py-func docutils literal notranslate"><span class="pre">kqueue.control()</span></code></a>,
  721. <a class="reference internal" href="../library/select.html#select.poll.poll" title="select.poll.poll"><code class="xref py py-func docutils literal notranslate"><span class="pre">poll.poll()</span></code></a>, <a class="reference internal" href="../library/select.html#select.select" title="select.select"><code class="xref py py-func docutils literal notranslate"><span class="pre">select()</span></code></a>;</p></li>
  722. <li><p>methods of the <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket</span></code></a> class: <a class="reference internal" href="../library/socket.html#socket.socket.accept" title="socket.socket.accept"><code class="xref py py-meth docutils literal notranslate"><span class="pre">accept()</span></code></a>,
  723. <a class="reference internal" href="../library/socket.html#socket.socket.connect" title="socket.socket.connect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">connect()</span></code></a> (except for non-blocking sockets),
  724. <a class="reference internal" href="../library/socket.html#socket.socket.recv" title="socket.socket.recv"><code class="xref py py-meth docutils literal notranslate"><span class="pre">recv()</span></code></a>, <a class="reference internal" href="../library/socket.html#socket.socket.recvfrom" title="socket.socket.recvfrom"><code class="xref py py-meth docutils literal notranslate"><span class="pre">recvfrom()</span></code></a>,
  725. <a class="reference internal" href="../library/socket.html#socket.socket.recvmsg" title="socket.socket.recvmsg"><code class="xref py py-meth docutils literal notranslate"><span class="pre">recvmsg()</span></code></a>, <a class="reference internal" href="../library/socket.html#socket.socket.send" title="socket.socket.send"><code class="xref py py-meth docutils literal notranslate"><span class="pre">send()</span></code></a>,
  726. <a class="reference internal" href="../library/socket.html#socket.socket.sendall" title="socket.socket.sendall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sendall()</span></code></a>, <a class="reference internal" href="../library/socket.html#socket.socket.sendmsg" title="socket.socket.sendmsg"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sendmsg()</span></code></a>,
  727. <a class="reference internal" href="../library/socket.html#socket.socket.sendto" title="socket.socket.sendto"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sendto()</span></code></a>;</p></li>
  728. <li><p><a class="reference internal" href="../library/signal.html#signal.sigtimedwait" title="signal.sigtimedwait"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.sigtimedwait()</span></code></a> and <a class="reference internal" href="../library/signal.html#signal.sigwaitinfo" title="signal.sigwaitinfo"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.sigwaitinfo()</span></code></a>;</p></li>
  729. <li><p><a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.sleep()</span></code></a>.</p></li>
  730. </ul>
  731. <div class="admonition seealso">
  732. <p class="admonition-title">See also</p>
  733. <dl class="simple">
  734. <dt><span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a> – Retry system calls failing with EINTR</dt><dd><p>PEP and implementation written by Charles-François Natali and
  735. Victor Stinner, with the help of Antoine Pitrou (the French connection).</p>
  736. </dd>
  737. </dl>
  738. </div>
  739. </section>
  740. <section id="pep-479-change-stopiteration-handling-inside-generators">
  741. <span id="whatsnew-pep-479"></span><h3>PEP 479: Change StopIteration handling inside generators<a class="headerlink" href="#pep-479-change-stopiteration-handling-inside-generators" title="Link to this heading">¶</a></h3>
  742. <p>The interaction of generators and <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> in Python 3.4 and
  743. earlier was sometimes surprising, and could conceal obscure bugs. Previously,
  744. <code class="docutils literal notranslate"><span class="pre">StopIteration</span></code> raised accidentally inside a generator function was
  745. interpreted as the end of the iteration by the loop construct driving the
  746. generator.</p>
  747. <p><span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0479/"><strong>PEP 479</strong></a> changes the behavior of generators: when a <code class="docutils literal notranslate"><span class="pre">StopIteration</span></code>
  748. exception is raised inside a generator, it is replaced with a
  749. <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> before it exits the generator frame. The main goal of
  750. this change is to ease debugging in the situation where an unguarded
  751. <a class="reference internal" href="../library/functions.html#next" title="next"><code class="xref py py-func docutils literal notranslate"><span class="pre">next()</span></code></a> call raises <code class="docutils literal notranslate"><span class="pre">StopIteration</span></code> and causes the iteration controlled
  752. by the generator to terminate silently. This is particularly pernicious in
  753. combination with the <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> construct.</p>
  754. <p>This is a backwards incompatible change, so to enable the new behavior,
  755. a <a class="reference internal" href="../glossary.html#term-__future__"><span class="xref std std-term">__future__</span></a> import is necessary:</p>
  756. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">generator_stop</span>
  757. <span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">gen</span><span class="p">():</span>
  758. <span class="gp">... </span> <span class="nb">next</span><span class="p">(</span><span class="nb">iter</span><span class="p">([]))</span>
  759. <span class="gp">... </span> <span class="k">yield</span>
  760. <span class="gp">...</span>
  761. <span class="gp">&gt;&gt;&gt; </span><span class="nb">next</span><span class="p">(</span><span class="n">gen</span><span class="p">())</span>
  762. <span class="gt">Traceback (most recent call last):</span>
  763. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">2</span>, in <span class="n">gen</span>
  764. <span class="gr">StopIteration</span>
  765. <span class="gt">The above exception was the direct cause of the following exception:</span>
  766. <span class="gt">Traceback (most recent call last):</span>
  767. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  768. <span class="gr">RuntimeError</span>: <span class="n">generator raised StopIteration</span>
  769. </pre></div>
  770. </div>
  771. <p>Without a <code class="docutils literal notranslate"><span class="pre">__future__</span></code> import, a <a class="reference internal" href="../library/exceptions.html#PendingDeprecationWarning" title="PendingDeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PendingDeprecationWarning</span></code></a> will be
  772. raised whenever a <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> exception is raised inside a generator.</p>
  773. <div class="admonition seealso">
  774. <p class="admonition-title">See also</p>
  775. <dl class="simple">
  776. <dt><span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0479/"><strong>PEP 479</strong></a> – Change StopIteration handling inside generators</dt><dd><p>PEP written by Chris Angelico and Guido van Rossum. Implemented by
  777. Chris Angelico, Yury Selivanov and Nick Coghlan.</p>
  778. </dd>
  779. </dl>
  780. </div>
  781. </section>
  782. <section id="pep-485-a-function-for-testing-approximate-equality">
  783. <span id="whatsnew-pep-485"></span><h3>PEP 485: A function for testing approximate equality<a class="headerlink" href="#pep-485-a-function-for-testing-approximate-equality" title="Link to this heading">¶</a></h3>
  784. <p><span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0485/"><strong>PEP 485</strong></a> adds the <a class="reference internal" href="../library/math.html#math.isclose" title="math.isclose"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.isclose()</span></code></a> and <a class="reference internal" href="../library/cmath.html#cmath.isclose" title="cmath.isclose"><code class="xref py py-func docutils literal notranslate"><span class="pre">cmath.isclose()</span></code></a>
  785. functions which tell whether two values are approximately equal or
  786. “close” to each other. Whether or not two values are considered
  787. close is determined according to given absolute and relative tolerances.
  788. Relative tolerance is the maximum allowed difference between <code class="docutils literal notranslate"><span class="pre">isclose</span></code>
  789. arguments, relative to the larger absolute value:</p>
  790. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">math</span>
  791. <span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="mf">5.0</span>
  792. <span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="mf">4.99998</span>
  793. <span class="gp">&gt;&gt;&gt; </span><span class="n">math</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">rel_tol</span><span class="o">=</span><span class="mf">1e-5</span><span class="p">)</span>
  794. <span class="go">True</span>
  795. <span class="gp">&gt;&gt;&gt; </span><span class="n">math</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">rel_tol</span><span class="o">=</span><span class="mf">1e-6</span><span class="p">)</span>
  796. <span class="go">False</span>
  797. </pre></div>
  798. </div>
  799. <p>It is also possible to compare two values using absolute tolerance, which
  800. must be a non-negative value:</p>
  801. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">math</span>
  802. <span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="mf">5.0</span>
  803. <span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="mf">4.99998</span>
  804. <span class="gp">&gt;&gt;&gt; </span><span class="n">math</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">abs_tol</span><span class="o">=</span><span class="mf">0.00003</span><span class="p">)</span>
  805. <span class="go">True</span>
  806. <span class="gp">&gt;&gt;&gt; </span><span class="n">math</span><span class="o">.</span><span class="n">isclose</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">abs_tol</span><span class="o">=</span><span class="mf">0.00001</span><span class="p">)</span>
  807. <span class="go">False</span>
  808. </pre></div>
  809. </div>
  810. <div class="admonition seealso">
  811. <p class="admonition-title">See also</p>
  812. <dl class="simple">
  813. <dt><span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0485/"><strong>PEP 485</strong></a> – A function for testing approximate equality</dt><dd><p>PEP written by Christopher Barker; implemented by Chris Barker and
  814. Tal Einat.</p>
  815. </dd>
  816. </dl>
  817. </div>
  818. </section>
  819. <section id="pep-486-make-the-python-launcher-aware-of-virtual-environments">
  820. <span id="whatsnew-pep-486"></span><h3>PEP 486: Make the Python Launcher aware of virtual environments<a class="headerlink" href="#pep-486-make-the-python-launcher-aware-of-virtual-environments" title="Link to this heading">¶</a></h3>
  821. <p><span class="target" id="index-21"></span><a class="pep reference external" href="https://peps.python.org/pep-0486/"><strong>PEP 486</strong></a> makes the Windows launcher (see <span class="target" id="index-22"></span><a class="pep reference external" href="https://peps.python.org/pep-0397/"><strong>PEP 397</strong></a>) aware of an active
  822. virtual environment. When the default interpreter would be used and the
  823. <code class="docutils literal notranslate"><span class="pre">VIRTUAL_ENV</span></code> environment variable is set, the interpreter in the virtual
  824. environment will be used.</p>
  825. <div class="admonition seealso">
  826. <p class="admonition-title">See also</p>
  827. <dl class="simple">
  828. <dt><span class="target" id="index-23"></span><a class="pep reference external" href="https://peps.python.org/pep-0486/"><strong>PEP 486</strong></a> – Make the Python Launcher aware of virtual environments</dt><dd><p>PEP written and implemented by Paul Moore.</p>
  829. </dd>
  830. </dl>
  831. </div>
  832. </section>
  833. <section id="pep-488-elimination-of-pyo-files">
  834. <span id="whatsnew-pep-488"></span><h3>PEP 488: Elimination of PYO files<a class="headerlink" href="#pep-488-elimination-of-pyo-files" title="Link to this heading">¶</a></h3>
  835. <p><span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0488/"><strong>PEP 488</strong></a> does away with the concept of <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files. This means that
  836. <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files represent both unoptimized and optimized bytecode. To prevent the
  837. need to constantly regenerate bytecode files, <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files now have an
  838. optional <code class="docutils literal notranslate"><span class="pre">opt-</span></code> tag in their name when the bytecode is optimized. This has the
  839. side-effect of no more bytecode file name clashes when running under either
  840. <a class="reference internal" href="../using/cmdline.html#cmdoption-O"><code class="xref std std-option docutils literal notranslate"><span class="pre">-O</span></code></a> or <a class="reference internal" href="../using/cmdline.html#cmdoption-OO"><code class="xref std std-option docutils literal notranslate"><span class="pre">-OO</span></code></a>. Consequently, bytecode files generated from
  841. <a class="reference internal" href="../using/cmdline.html#cmdoption-O"><code class="xref std std-option docutils literal notranslate"><span class="pre">-O</span></code></a>, and <a class="reference internal" href="../using/cmdline.html#cmdoption-OO"><code class="xref std std-option docutils literal notranslate"><span class="pre">-OO</span></code></a> may now exist simultaneously.
  842. <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> has an updated API to help with
  843. this change.</p>
  844. <div class="admonition seealso">
  845. <p class="admonition-title">See also</p>
  846. <dl class="simple">
  847. <dt><span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-0488/"><strong>PEP 488</strong></a> – Elimination of PYO files</dt><dd><p>PEP written and implemented by Brett Cannon.</p>
  848. </dd>
  849. </dl>
  850. </div>
  851. </section>
  852. <section id="pep-489-multi-phase-extension-module-initialization">
  853. <span id="whatsnew-pep-489"></span><h3>PEP 489: Multi-phase extension module initialization<a class="headerlink" href="#pep-489-multi-phase-extension-module-initialization" title="Link to this heading">¶</a></h3>
  854. <p><span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-0489/"><strong>PEP 489</strong></a> updates extension module initialization to take advantage of the
  855. two step module loading mechanism introduced by <span class="target" id="index-27"></span><a class="pep reference external" href="https://peps.python.org/pep-0451/"><strong>PEP 451</strong></a> in Python 3.4.</p>
  856. <p>This change brings the import semantics of extension modules that opt-in to
  857. using the new mechanism much closer to those of Python source and bytecode
  858. modules, including the ability to use any valid identifier as a module name,
  859. rather than being restricted to ASCII.</p>
  860. <div class="admonition seealso">
  861. <p class="admonition-title">See also</p>
  862. <dl class="simple">
  863. <dt><span class="target" id="index-28"></span><a class="pep reference external" href="https://peps.python.org/pep-0489/"><strong>PEP 489</strong></a> – Multi-phase extension module initialization</dt><dd><p>PEP written by Petr Viktorin, Stefan Behnel, and Nick Coghlan;
  864. implemented by Petr Viktorin.</p>
  865. </dd>
  866. </dl>
  867. </div>
  868. </section>
  869. </section>
  870. <section id="other-language-changes">
  871. <h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading">¶</a></h2>
  872. <p>Some smaller changes made to the core Python language are:</p>
  873. <ul class="simple">
  874. <li><p>Added the <code class="docutils literal notranslate"><span class="pre">&quot;namereplace&quot;</span></code> error handlers. The <code class="docutils literal notranslate"><span class="pre">&quot;backslashreplace&quot;</span></code>
  875. error handlers now work with decoding and translating.
  876. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19676">bpo-19676</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22286">bpo-22286</a>.)</p></li>
  877. <li><p>The <a class="reference internal" href="../using/cmdline.html#cmdoption-b"><code class="xref std std-option docutils literal notranslate"><span class="pre">-b</span></code></a> option now affects comparisons of <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> with
  878. <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>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23681">bpo-23681</a>.)</p></li>
  879. <li><p>New Kazakh <code class="docutils literal notranslate"><span class="pre">kz1048</span></code> and Tajik <code class="docutils literal notranslate"><span class="pre">koi8_t</span></code> <a class="reference internal" href="../library/codecs.html#standard-encodings"><span class="std std-ref">codecs</span></a>.
  880. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22682">bpo-22682</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22681">bpo-22681</a>.)</p></li>
  881. <li><p>Property docstrings are now writable. This is especially useful for
  882. <a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">collections.namedtuple()</span></code></a> docstrings.
  883. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24064">bpo-24064</a>.)</p></li>
  884. <li><p>Circular imports involving relative imports are now supported.
  885. (Contributed by Brett Cannon and Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17636">bpo-17636</a>.)</p></li>
  886. </ul>
  887. </section>
  888. <section id="new-modules">
  889. <h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading">¶</a></h2>
  890. <section id="typing">
  891. <h3>typing<a class="headerlink" href="#typing" title="Link to this heading">¶</a></h3>
  892. <p>The new <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">provisional</span></a> module
  893. provides standard definitions and tools for function type annotations.
  894. See <a class="reference internal" href="#whatsnew-pep-484"><span class="std std-ref">Type Hints</span></a> for more information.</p>
  895. </section>
  896. <section id="zipapp">
  897. <span id="whatsnew-zipapp"></span><h3>zipapp<a class="headerlink" href="#zipapp" title="Link to this heading">¶</a></h3>
  898. <p>The new <a class="reference internal" href="../library/zipapp.html#module-zipapp" title="zipapp: Manage executable Python zip archives"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipapp</span></code></a> module (specified in <span class="target" id="index-29"></span><a class="pep reference external" href="https://peps.python.org/pep-0441/"><strong>PEP 441</strong></a>) provides an API and
  899. command line tool for creating executable Python Zip Applications, which
  900. were introduced in Python 2.6 in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1739468">bpo-1739468</a>, but which were not well
  901. publicized, either at the time or since.</p>
  902. <p>With the new module, bundling your application is as simple as putting all
  903. the files, including a <code class="docutils literal notranslate"><span class="pre">__main__.py</span></code> file, into a directory <code class="docutils literal notranslate"><span class="pre">myapp</span></code>
  904. and running:</p>
  905. <div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>python<span class="w"> </span>-m<span class="w"> </span>zipapp<span class="w"> </span>myapp
  906. <span class="gp">$ </span>python<span class="w"> </span>myapp.pyz
  907. </pre></div>
  908. </div>
  909. <p>The module implementation has been contributed by Paul Moore in
  910. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23491">bpo-23491</a>.</p>
  911. <div class="admonition seealso">
  912. <p class="admonition-title">See also</p>
  913. <p><span class="target" id="index-30"></span><a class="pep reference external" href="https://peps.python.org/pep-0441/"><strong>PEP 441</strong></a> – Improving Python ZIP Application Support</p>
  914. </div>
  915. </section>
  916. </section>
  917. <section id="improved-modules">
  918. <h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading">¶</a></h2>
  919. <section id="argparse">
  920. <h3>argparse<a class="headerlink" href="#argparse" title="Link to this heading">¶</a></h3>
  921. <p>The <a class="reference internal" href="../library/argparse.html#argparse.ArgumentParser" title="argparse.ArgumentParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">ArgumentParser</span></code></a> class now allows disabling
  922. <a class="reference internal" href="../library/argparse.html#prefix-matching"><span class="std std-ref">abbreviated usage</span></a> of long options by setting
  923. <a class="reference internal" href="../library/argparse.html#allow-abbrev"><span class="std std-ref">allow_abbrev</span></a> to <code class="docutils literal notranslate"><span class="pre">False</span></code>. (Contributed by Jonathan Paugh,
  924. Steven Bethard, paul j3 and Daniel Eriksson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14910">bpo-14910</a>.)</p>
  925. </section>
  926. <section id="asyncio">
  927. <h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading">¶</a></h3>
  928. <p>Since the <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> module is <a class="reference internal" href="../glossary.html#term-provisional-API"><span class="xref std std-term">provisional</span></a>,
  929. all changes introduced in Python 3.5 have also been backported to Python 3.4.x.</p>
  930. <p>Notable changes in the <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> module since Python 3.4.0:</p>
  931. <ul class="simple">
  932. <li><p>New debugging APIs: <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.set_debug" title="asyncio.loop.set_debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.set_debug()</span></code></a>
  933. and <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.get_debug" title="asyncio.loop.get_debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.get_debug()</span></code></a> methods.
  934. (Contributed by Victor Stinner.)</p></li>
  935. <li><p>The proactor event loop now supports SSL.
  936. (Contributed by Antoine Pitrou and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22560">bpo-22560</a>.)</p></li>
  937. <li><p>A new <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.is_closed" title="asyncio.loop.is_closed"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.is_closed()</span></code></a> method to
  938. check if the event loop is closed.
  939. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21326">bpo-21326</a>.)</p></li>
  940. <li><p>A new <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_task" title="asyncio.loop.create_task"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_task()</span></code></a>
  941. to conveniently create and schedule a new <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>
  942. for a coroutine. The <code class="docutils literal notranslate"><span class="pre">create_task</span></code> method is also used by all
  943. asyncio functions that wrap coroutines into tasks, such as
  944. <a class="reference internal" href="../library/asyncio-task.html#asyncio.wait" title="asyncio.wait"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.wait()</span></code></a>, <a class="reference internal" href="../library/asyncio-task.html#asyncio.gather" title="asyncio.gather"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.gather()</span></code></a>, etc.
  945. (Contributed by Victor Stinner.)</p></li>
  946. <li><p>A new <a class="reference internal" href="../library/asyncio-protocol.html#asyncio.WriteTransport.get_write_buffer_limits" title="asyncio.WriteTransport.get_write_buffer_limits"><code class="xref py py-meth docutils literal notranslate"><span class="pre">transport.get_write_buffer_limits()</span></code></a>
  947. method to inquire for <em>high-</em> and <em>low-</em> water limits of the flow
  948. control.
  949. (Contributed by Victor Stinner.)</p></li>
  950. <li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">async()</span></code> function is deprecated in favor of
  951. <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>.
  952. (Contributed by Yury Selivanov.)</p></li>
  953. <li><p>New <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.set_task_factory" title="asyncio.loop.set_task_factory"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.set_task_factory()</span></code></a> and
  954. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.get_task_factory" title="asyncio.loop.get_task_factory"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.get_task_factory()</span></code></a>
  955. methods to customize the task factory that <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_task" title="asyncio.loop.create_task"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_task()</span></code></a> method uses. (Contributed by Yury
  956. Selivanov.)</p></li>
  957. <li><p>New <a class="reference internal" href="../library/asyncio-queue.html#asyncio.Queue.join" title="asyncio.Queue.join"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Queue.join()</span></code></a> and
  958. <a class="reference internal" href="../library/asyncio-queue.html#asyncio.Queue.task_done" title="asyncio.Queue.task_done"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Queue.task_done()</span></code></a> queue methods.
  959. (Contributed by Victor Stinner.)</p></li>
  960. <li><p>The <code class="docutils literal notranslate"><span class="pre">JoinableQueue</span></code> class was removed, in favor of the
  961. <a class="reference internal" href="../library/asyncio-queue.html#asyncio.Queue" title="asyncio.Queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Queue</span></code></a> class.
  962. (Contributed by Victor Stinner.)</p></li>
  963. </ul>
  964. <p>Updates in 3.5.1:</p>
  965. <ul class="simple">
  966. <li><p>The <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> function and all functions that
  967. use it, such as <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>,
  968. now accept all kinds of <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitable objects</span></a>.
  969. (Contributed by Yury Selivanov.)</p></li>
  970. <li><p>New <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> function to submit
  971. coroutines to event loops from other threads.
  972. (Contributed by Vincent Michel.)</p></li>
  973. <li><p>New <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>
  974. method to check if the transport is closing or closed.
  975. (Contributed by Yury Selivanov.)</p></li>
  976. <li><p>The <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>
  977. method can now accept a list of hosts.
  978. (Contributed by Yann Sionneau.)</p></li>
  979. </ul>
  980. <p>Updates in 3.5.2:</p>
  981. <ul class="simple">
  982. <li><p>New <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>
  983. method to create Future objects. This allows alternative event
  984. loop implementations, such as
  985. <a class="reference external" href="https://github.com/MagicStack/uvloop">uvloop</a>, to provide a faster
  986. <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> implementation.
  987. (Contributed by Yury Selivanov.)</p></li>
  988. <li><p>New <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>
  989. method to get the current exception handler.
  990. (Contributed by Yury Selivanov.)</p></li>
  991. <li><p>New <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>
  992. method to read data from the stream until a separator bytes
  993. sequence appears.
  994. (Contributed by Mark Korenberg.)</p></li>
  995. <li><p>The <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_connection" title="asyncio.loop.create_connection"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_connection()</span></code></a>
  996. and <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>
  997. methods are optimized to avoid calling the system <code class="docutils literal notranslate"><span class="pre">getaddrinfo</span></code>
  998. function if the address is already resolved.
  999. (Contributed by A. Jesse Jiryu Davis.)</p></li>
  1000. <li><p>The <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_connect" title="asyncio.loop.sock_connect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.sock_connect(sock,</span> <span class="pre">address)</span></code></a>
  1001. no longer requires the <em>address</em> to be resolved prior to the call.
  1002. (Contributed by A. Jesse Jiryu Davis.)</p></li>
  1003. </ul>
  1004. </section>
  1005. <section id="bz2">
  1006. <h3>bz2<a class="headerlink" href="#bz2" title="Link to this heading">¶</a></h3>
  1007. <p>The <a class="reference internal" href="../library/bz2.html#bz2.BZ2Decompressor.decompress" title="bz2.BZ2Decompressor.decompress"><code class="xref py py-meth docutils literal notranslate"><span class="pre">BZ2Decompressor.decompress</span></code></a>
  1008. method now accepts an optional <em>max_length</em> argument to limit the maximum
  1009. size of decompressed data. (Contributed by Nikolaus Rath in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15955">bpo-15955</a>.)</p>
  1010. </section>
  1011. <section id="cgi">
  1012. <h3>cgi<a class="headerlink" href="#cgi" title="Link to this heading">¶</a></h3>
  1013. <p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">FieldStorage</span></code> class now supports the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a>
  1014. protocol. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20289">bpo-20289</a>.)</p>
  1015. </section>
  1016. <section id="cmath">
  1017. <h3>cmath<a class="headerlink" href="#cmath" title="Link to this heading">¶</a></h3>
  1018. <p>A new function <a class="reference internal" href="../library/cmath.html#cmath.isclose" title="cmath.isclose"><code class="xref py py-func docutils literal notranslate"><span class="pre">isclose()</span></code></a> provides a way to test for approximate
  1019. equality. (Contributed by Chris Barker and Tal Einat in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24270">bpo-24270</a>.)</p>
  1020. </section>
  1021. <section id="code">
  1022. <h3>code<a class="headerlink" href="#code" title="Link to this heading">¶</a></h3>
  1023. <p>The <a class="reference internal" href="../library/code.html#code.InteractiveInterpreter.showtraceback" title="code.InteractiveInterpreter.showtraceback"><code class="xref py py-func docutils literal notranslate"><span class="pre">InteractiveInterpreter.showtraceback()</span></code></a>
  1024. method now prints the full chained traceback, just like the interactive
  1025. interpreter. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17442">bpo-17442</a>.)</p>
  1026. </section>
  1027. <section id="collections">
  1028. <h3>collections<a class="headerlink" href="#collections" title="Link to this heading">¶</a></h3>
  1029. <p id="whatsnew-ordereddict">The <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> class is now implemented in C, which
  1030. makes it 4 to 100 times faster. (Contributed by Eric Snow in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16991">bpo-16991</a>.)</p>
  1031. <p><code class="xref py py-meth docutils literal notranslate"><span class="pre">OrderedDict.items()</span></code>,
  1032. <code class="xref py py-meth docutils literal notranslate"><span class="pre">OrderedDict.keys()</span></code>,
  1033. <code class="xref py py-meth docutils literal notranslate"><span class="pre">OrderedDict.values()</span></code> views now support
  1034. <a class="reference internal" href="../library/functions.html#reversed" title="reversed"><code class="xref py py-func docutils literal notranslate"><span class="pre">reversed()</span></code></a> iteration.
  1035. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19505">bpo-19505</a>.)</p>
  1036. <p>The <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">deque</span></code></a> class now defines
  1037. <a class="reference internal" href="../library/collections.html#collections.deque.index" title="collections.deque.index"><code class="xref py py-meth docutils literal notranslate"><span class="pre">index()</span></code></a>, <a class="reference internal" href="../library/collections.html#collections.deque.insert" title="collections.deque.insert"><code class="xref py py-meth docutils literal notranslate"><span class="pre">insert()</span></code></a>, and
  1038. <a class="reference internal" href="../library/collections.html#collections.deque.copy" title="collections.deque.copy"><code class="xref py py-meth docutils literal notranslate"><span class="pre">copy()</span></code></a>, and supports the <code class="docutils literal notranslate"><span class="pre">+</span></code> and <code class="docutils literal notranslate"><span class="pre">*</span></code> operators.
  1039. This allows deques to be recognized as a <a class="reference internal" href="../library/collections.abc.html#collections.abc.MutableSequence" title="collections.abc.MutableSequence"><code class="xref py py-class docutils literal notranslate"><span class="pre">MutableSequence</span></code></a>
  1040. and improves their substitutability for lists.
  1041. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23704">bpo-23704</a>.)</p>
  1042. <p>Docstrings produced by <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> can now be updated:</p>
  1043. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Point</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s1">&#39;Point&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">])</span>
  1044. <span class="n">Point</span><span class="o">.</span><span class="vm">__doc__</span> <span class="o">+=</span> <span class="s1">&#39;: Cartesian coordinate&#39;</span>
  1045. <span class="n">Point</span><span class="o">.</span><span class="n">x</span><span class="o">.</span><span class="vm">__doc__</span> <span class="o">=</span> <span class="s1">&#39;abscissa&#39;</span>
  1046. <span class="n">Point</span><span class="o">.</span><span class="n">y</span><span class="o">.</span><span class="vm">__doc__</span> <span class="o">=</span> <span class="s1">&#39;ordinate&#39;</span>
  1047. </pre></div>
  1048. </div>
  1049. <p>(Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24064">bpo-24064</a>.)</p>
  1050. <p>The <a class="reference internal" href="../library/collections.html#collections.UserString" title="collections.UserString"><code class="xref py py-class docutils literal notranslate"><span class="pre">UserString</span></code></a> class now implements the
  1051. <code class="xref py py-meth docutils literal notranslate"><span class="pre">__getnewargs__()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">__rmod__()</span></code>, <a class="reference internal" href="../library/stdtypes.html#str.casefold" title="str.casefold"><code class="xref py py-meth docutils literal notranslate"><span class="pre">casefold()</span></code></a>,
  1052. <a class="reference internal" href="../library/stdtypes.html#str.format_map" title="str.format_map"><code class="xref py py-meth docutils literal notranslate"><span class="pre">format_map()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#str.isprintable" title="str.isprintable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">isprintable()</span></code></a>, and <a class="reference internal" href="../library/stdtypes.html#str.maketrans" title="str.maketrans"><code class="xref py py-meth docutils literal notranslate"><span class="pre">maketrans()</span></code></a>
  1053. methods to match the corresponding methods of <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>.
  1054. (Contributed by Joe Jevnik in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22189">bpo-22189</a>.)</p>
  1055. </section>
  1056. <section id="collections-abc">
  1057. <h3>collections.abc<a class="headerlink" href="#collections-abc" title="Link to this heading">¶</a></h3>
  1058. <p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">Sequence.index()</span></code> method now
  1059. accepts <em>start</em> and <em>stop</em> arguments to match the corresponding methods
  1060. of <a class="reference internal" href="../library/stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>, etc.
  1061. (Contributed by Devin Jeanpierre in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23086">bpo-23086</a>.)</p>
  1062. <p>A new <a class="reference internal" href="../library/collections.abc.html#collections.abc.Generator" title="collections.abc.Generator"><code class="xref py py-class docutils literal notranslate"><span class="pre">Generator</span></code></a> abstract base class. (Contributed
  1063. by Stefan Behnel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24018">bpo-24018</a>.)</p>
  1064. <p>New <a class="reference internal" href="../library/collections.abc.html#collections.abc.Awaitable" title="collections.abc.Awaitable"><code class="xref py py-class docutils literal notranslate"><span class="pre">Awaitable</span></code></a>, <a class="reference internal" href="../library/collections.abc.html#collections.abc.Coroutine" title="collections.abc.Coroutine"><code class="xref py py-class docutils literal notranslate"><span class="pre">Coroutine</span></code></a>,
  1065. <a class="reference internal" href="../library/collections.abc.html#collections.abc.AsyncIterator" title="collections.abc.AsyncIterator"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncIterator</span></code></a>, and
  1066. <a class="reference internal" href="../library/collections.abc.html#collections.abc.AsyncIterable" title="collections.abc.AsyncIterable"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncIterable</span></code></a> abstract base classes.
  1067. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24184">bpo-24184</a>.)</p>
  1068. <p>For earlier Python versions, a backport of the new ABCs is available in an
  1069. external <a class="reference external" href="https://pypi.org/project/backports_abc">PyPI package</a>.</p>
  1070. </section>
  1071. <section id="compileall">
  1072. <h3>compileall<a class="headerlink" href="#compileall" title="Link to this heading">¶</a></h3>
  1073. <p>A new <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> option, <code class="samp docutils literal notranslate"><span class="pre">-j</span> <em><span class="pre">N</span></em></code>, allows running <em>N</em> workers
  1074. simultaneously to perform parallel bytecode compilation.
  1075. The <a class="reference internal" href="../library/compileall.html#compileall.compile_dir" title="compileall.compile_dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile_dir()</span></code></a> function has a corresponding <code class="docutils literal notranslate"><span class="pre">workers</span></code>
  1076. parameter. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16104">bpo-16104</a>.)</p>
  1077. <p>Another new option, <code class="docutils literal notranslate"><span class="pre">-r</span></code>, allows controlling the maximum recursion
  1078. level for subdirectories. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19628">bpo-19628</a>.)</p>
  1079. <p>The <code class="docutils literal notranslate"><span class="pre">-q</span></code> command line option can now be specified more than once, in
  1080. which case all output, including errors, will be suppressed. The corresponding
  1081. <code class="docutils literal notranslate"><span class="pre">quiet</span></code> parameter in <a class="reference internal" href="../library/compileall.html#compileall.compile_dir" title="compileall.compile_dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile_dir()</span></code></a>,
  1082. <a class="reference internal" href="../library/compileall.html#compileall.compile_file" title="compileall.compile_file"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile_file()</span></code></a>, and <a class="reference internal" href="../library/compileall.html#compileall.compile_path" title="compileall.compile_path"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile_path()</span></code></a> can now
  1083. accept an integer value indicating the level of output suppression.
  1084. (Contributed by Thomas Kluyver in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21338">bpo-21338</a>.)</p>
  1085. </section>
  1086. <section id="concurrent-futures">
  1087. <h3>concurrent.futures<a class="headerlink" href="#concurrent-futures" title="Link to this heading">¶</a></h3>
  1088. <p>The <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.Executor.map" title="concurrent.futures.Executor.map"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Executor.map()</span></code></a> method now accepts a
  1089. <em>chunksize</em> argument to allow batching of tasks to improve performance when
  1090. <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor" title="concurrent.futures.ProcessPoolExecutor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ProcessPoolExecutor()</span></code></a> is used.
  1091. (Contributed by Dan O’Reilly in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11271">bpo-11271</a>.)</p>
  1092. <p>The number of workers in the <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>
  1093. constructor is optional now. The default value is 5 times the number of CPUs.
  1094. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21527">bpo-21527</a>.)</p>
  1095. </section>
  1096. <section id="configparser">
  1097. <h3>configparser<a class="headerlink" href="#configparser" title="Link to this heading">¶</a></h3>
  1098. <p><a class="reference internal" href="../library/configparser.html#module-configparser" title="configparser: Configuration file parser."><code class="xref py py-mod docutils literal notranslate"><span class="pre">configparser</span></code></a> now provides a way to customize the conversion
  1099. of values by specifying a dictionary of converters in the
  1100. <a class="reference internal" href="../library/configparser.html#configparser.ConfigParser" title="configparser.ConfigParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">ConfigParser</span></code></a> constructor, or by defining them
  1101. as methods in <code class="docutils literal notranslate"><span class="pre">ConfigParser</span></code> subclasses. Converters defined in
  1102. a parser instance are inherited by its section proxies.</p>
  1103. <p>Example:</p>
  1104. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">configparser</span>
  1105. <span class="gp">&gt;&gt;&gt; </span><span class="n">conv</span> <span class="o">=</span> <span class="p">{}</span>
  1106. <span class="gp">&gt;&gt;&gt; </span><span class="n">conv</span><span class="p">[</span><span class="s1">&#39;list&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">v</span><span class="p">:</span> <span class="p">[</span><span class="n">e</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">v</span><span class="o">.</span><span class="n">split</span><span class="p">()</span> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">strip</span><span class="p">()]</span>
  1107. <span class="gp">&gt;&gt;&gt; </span><span class="n">cfg</span> <span class="o">=</span> <span class="n">configparser</span><span class="o">.</span><span class="n">ConfigParser</span><span class="p">(</span><span class="n">converters</span><span class="o">=</span><span class="n">conv</span><span class="p">)</span>
  1108. <span class="gp">&gt;&gt;&gt; </span><span class="n">cfg</span><span class="o">.</span><span class="n">read_string</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
  1109. <span class="gp">... </span><span class="s2">[s]</span>
  1110. <span class="gp">... </span><span class="s2">list = a b c d e f g</span>
  1111. <span class="gp">... </span><span class="s2">&quot;&quot;&quot;</span><span class="p">)</span>
  1112. <span class="gp">&gt;&gt;&gt; </span><span class="n">cfg</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;s&#39;</span><span class="p">,</span> <span class="s1">&#39;list&#39;</span><span class="p">)</span>
  1113. <span class="go">&#39;a b c d e f g&#39;</span>
  1114. <span class="gp">&gt;&gt;&gt; </span><span class="n">cfg</span><span class="o">.</span><span class="n">getlist</span><span class="p">(</span><span class="s1">&#39;s&#39;</span><span class="p">,</span> <span class="s1">&#39;list&#39;</span><span class="p">)</span>
  1115. <span class="go">[&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;, &#39;f&#39;, &#39;g&#39;]</span>
  1116. <span class="gp">&gt;&gt;&gt; </span><span class="n">section</span> <span class="o">=</span> <span class="n">cfg</span><span class="p">[</span><span class="s1">&#39;s&#39;</span><span class="p">]</span>
  1117. <span class="gp">&gt;&gt;&gt; </span><span class="n">section</span><span class="o">.</span><span class="n">getlist</span><span class="p">(</span><span class="s1">&#39;list&#39;</span><span class="p">)</span>
  1118. <span class="go">[&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;, &#39;f&#39;, &#39;g&#39;]</span>
  1119. </pre></div>
  1120. </div>
  1121. <p>(Contributed by Łukasz Langa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18159">bpo-18159</a>.)</p>
  1122. </section>
  1123. <section id="contextlib">
  1124. <h3>contextlib<a class="headerlink" href="#contextlib" title="Link to this heading">¶</a></h3>
  1125. <p>The new <a class="reference internal" href="../library/contextlib.html#contextlib.redirect_stderr" title="contextlib.redirect_stderr"><code class="xref py py-func docutils literal notranslate"><span class="pre">redirect_stderr()</span></code></a> <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> (similar to
  1126. <a class="reference internal" href="../library/contextlib.html#contextlib.redirect_stdout" title="contextlib.redirect_stdout"><code class="xref py py-func docutils literal notranslate"><span class="pre">redirect_stdout()</span></code></a>) makes it easier for utility scripts to
  1127. handle inflexible APIs that write their output to <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> and
  1128. don’t provide any options to redirect it:</p>
  1129. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">contextlib</span><span class="o">,</span> <span class="nn">io</span><span class="o">,</span> <span class="nn">logging</span>
  1130. <span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">io</span><span class="o">.</span><span class="n">StringIO</span><span class="p">()</span>
  1131. <span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="n">contextlib</span><span class="o">.</span><span class="n">redirect_stderr</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
  1132. <span class="gp">... </span> <span class="n">logging</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;warning&#39;</span><span class="p">)</span>
  1133. <span class="gp">...</span>
  1134. <span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">getvalue</span><span class="p">()</span>
  1135. <span class="go">&#39;WARNING:root:warning\n&#39;</span>
  1136. </pre></div>
  1137. </div>
  1138. <p>(Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22389">bpo-22389</a>.)</p>
  1139. </section>
  1140. <section id="csv">
  1141. <h3>csv<a class="headerlink" href="#csv" title="Link to this heading">¶</a></h3>
  1142. <p>The <a class="reference internal" href="../library/csv.html#csv.csvwriter.writerow" title="csv.csvwriter.writerow"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writerow()</span></code></a> method now supports arbitrary iterables,
  1143. not just sequences. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23171">bpo-23171</a>.)</p>
  1144. </section>
  1145. <section id="curses">
  1146. <h3>curses<a class="headerlink" href="#curses" title="Link to this heading">¶</a></h3>
  1147. <p>The new <a class="reference internal" href="../library/curses.html#curses.update_lines_cols" title="curses.update_lines_cols"><code class="xref py py-func docutils literal notranslate"><span class="pre">update_lines_cols()</span></code></a> function updates the <code class="xref py py-data docutils literal notranslate"><span class="pre">LINES</span></code>
  1148. and <code class="xref py py-data docutils literal notranslate"><span class="pre">COLS</span></code> module variables. This is useful for detecting
  1149. manual screen resizing. (Contributed by Arnon Yaari in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4254">bpo-4254</a>.)</p>
  1150. </section>
  1151. <section id="dbm">
  1152. <h3>dbm<a class="headerlink" href="#dbm" title="Link to this heading">¶</a></h3>
  1153. <p><a class="reference internal" href="../library/dbm.html#dbm.dumb.open" title="dbm.dumb.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">dumb.open</span></code></a> always creates a new database when the flag
  1154. has the value <code class="docutils literal notranslate"><span class="pre">&quot;n&quot;</span></code>. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18039">bpo-18039</a>.)</p>
  1155. </section>
  1156. <section id="difflib">
  1157. <h3>difflib<a class="headerlink" href="#difflib" title="Link to this heading">¶</a></h3>
  1158. <p>The charset of HTML documents generated by
  1159. <a class="reference internal" href="../library/difflib.html#difflib.HtmlDiff.make_file" title="difflib.HtmlDiff.make_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HtmlDiff.make_file()</span></code></a>
  1160. can now be customized by using a new <em>charset</em> keyword-only argument.
  1161. The default charset of HTML document changed from <code class="docutils literal notranslate"><span class="pre">&quot;ISO-8859-1&quot;</span></code>
  1162. to <code class="docutils literal notranslate"><span class="pre">&quot;utf-8&quot;</span></code>.
  1163. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=2052">bpo-2052</a>.)</p>
  1164. <p>The <a class="reference internal" href="../library/difflib.html#difflib.diff_bytes" title="difflib.diff_bytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">diff_bytes()</span></code></a> function can now compare lists of byte
  1165. strings. This fixes a regression from Python 2.
  1166. (Contributed by Terry J. Reedy and Greg Ward in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17445">bpo-17445</a>.)</p>
  1167. </section>
  1168. <section id="distutils">
  1169. <h3>distutils<a class="headerlink" href="#distutils" title="Link to this heading">¶</a></h3>
  1170. <p>Both the <code class="docutils literal notranslate"><span class="pre">build</span></code> and <code class="docutils literal notranslate"><span class="pre">build_ext</span></code> commands now accept a <code class="docutils literal notranslate"><span class="pre">-j</span></code> option to
  1171. enable parallel building of extension modules.
  1172. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5309">bpo-5309</a>.)</p>
  1173. <p>The <code class="docutils literal notranslate"><span class="pre">distutils</span></code> module now supports <code class="docutils literal notranslate"><span class="pre">xz</span></code> compression, and can be
  1174. enabled by passing <code class="docutils literal notranslate"><span class="pre">xztar</span></code> as an argument to <code class="docutils literal notranslate"><span class="pre">bdist</span> <span class="pre">--format</span></code>.
  1175. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16314">bpo-16314</a>.)</p>
  1176. </section>
  1177. <section id="doctest">
  1178. <h3>doctest<a class="headerlink" href="#doctest" title="Link to this heading">¶</a></h3>
  1179. <p>The <a class="reference internal" href="../library/doctest.html#doctest.DocTestSuite" title="doctest.DocTestSuite"><code class="xref py py-func docutils literal notranslate"><span class="pre">DocTestSuite()</span></code></a> function returns an empty
  1180. <a class="reference internal" href="../library/unittest.html#unittest.TestSuite" title="unittest.TestSuite"><code class="xref py py-class docutils literal notranslate"><span class="pre">unittest.TestSuite</span></code></a> if <em>module</em> contains no docstrings, instead of
  1181. raising <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>. (Contributed by Glenn Jones in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15916">bpo-15916</a>.)</p>
  1182. </section>
  1183. <section id="email">
  1184. <h3>email<a class="headerlink" href="#email" title="Link to this heading">¶</a></h3>
  1185. <p>A new policy option <a class="reference internal" href="../library/email.policy.html#email.policy.Policy.mangle_from_" title="email.policy.Policy.mangle_from_"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Policy.mangle_from_</span></code></a>
  1186. controls whether or not lines that start with <code class="docutils literal notranslate"><span class="pre">&quot;From</span> <span class="pre">&quot;</span></code> in email bodies are
  1187. prefixed with a <code class="docutils literal notranslate"><span class="pre">&quot;&gt;&quot;</span></code> character by generators. The default is <code class="docutils literal notranslate"><span class="pre">True</span></code> for
  1188. <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">compat32</span></code></a> and <code class="docutils literal notranslate"><span class="pre">False</span></code> for all other policies.
  1189. (Contributed by Milan Oberkirch in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20098">bpo-20098</a>.)</p>
  1190. <p>A new
  1191. <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message.get_content_disposition" title="email.message.Message.get_content_disposition"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Message.get_content_disposition()</span></code></a>
  1192. method provides easy access to a canonical value for the
  1193. <em class="mailheader">Content-Disposition</em> header.
  1194. (Contributed by Abhilash Raj in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21083">bpo-21083</a>.)</p>
  1195. <p>A new policy option <a class="reference internal" href="../library/email.policy.html#email.policy.EmailPolicy.utf8" title="email.policy.EmailPolicy.utf8"><code class="xref py py-attr docutils literal notranslate"><span class="pre">EmailPolicy.utf8</span></code></a>
  1196. can be set to <code class="docutils literal notranslate"><span class="pre">True</span></code> to encode email headers using the UTF-8 charset instead
  1197. of using encoded words. This allows <code class="docutils literal notranslate"><span class="pre">Messages</span></code> to be formatted according to
  1198. <span class="target" id="index-31"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6532.html"><strong>RFC 6532</strong></a> and used with an SMTP server that supports the <span class="target" id="index-32"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6531.html"><strong>RFC 6531</strong></a>
  1199. <code class="docutils literal notranslate"><span class="pre">SMTPUTF8</span></code> extension. (Contributed by R. David Murray in
  1200. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24211">bpo-24211</a>.)</p>
  1201. <p>The <a class="reference internal" href="../library/email.mime.html#email.mime.text.MIMEText" title="email.mime.text.MIMEText"><code class="xref py py-class docutils literal notranslate"><span class="pre">mime.text.MIMEText</span></code></a> constructor now
  1202. accepts a <a class="reference internal" href="../library/email.charset.html#email.charset.Charset" title="email.charset.Charset"><code class="xref py py-class docutils literal notranslate"><span class="pre">charset.Charset</span></code></a> instance.
  1203. (Contributed by Claude Paroz and Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16324">bpo-16324</a>.)</p>
  1204. </section>
  1205. <section id="enum">
  1206. <h3>enum<a class="headerlink" href="#enum" title="Link to this heading">¶</a></h3>
  1207. <p>The <a class="reference internal" href="../library/enum.html#enum.Enum" title="enum.Enum"><code class="xref py py-class docutils literal notranslate"><span class="pre">Enum</span></code></a> callable has a new parameter <em>start</em> to
  1208. specify the initial number of enum values if only <em>names</em> are provided:</p>
  1209. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Animal</span> <span class="o">=</span> <span class="n">enum</span><span class="o">.</span><span class="n">Enum</span><span class="p">(</span><span class="s1">&#39;Animal&#39;</span><span class="p">,</span> <span class="s1">&#39;cat dog&#39;</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
  1210. <span class="gp">&gt;&gt;&gt; </span><span class="n">Animal</span><span class="o">.</span><span class="n">cat</span>
  1211. <span class="go">&lt;Animal.cat: 10&gt;</span>
  1212. <span class="gp">&gt;&gt;&gt; </span><span class="n">Animal</span><span class="o">.</span><span class="n">dog</span>
  1213. <span class="go">&lt;Animal.dog: 11&gt;</span>
  1214. </pre></div>
  1215. </div>
  1216. <p>(Contributed by Ethan Furman in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21706">bpo-21706</a>.)</p>
  1217. </section>
  1218. <section id="faulthandler">
  1219. <h3>faulthandler<a class="headerlink" href="#faulthandler" title="Link to this heading">¶</a></h3>
  1220. <p>The <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">enable()</span></code></a>, <a class="reference internal" href="../library/faulthandler.html#faulthandler.register" title="faulthandler.register"><code class="xref py py-func docutils literal notranslate"><span class="pre">register()</span></code></a>,
  1221. <a class="reference internal" href="../library/faulthandler.html#faulthandler.dump_traceback" title="faulthandler.dump_traceback"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump_traceback()</span></code></a> and
  1222. <a class="reference internal" href="../library/faulthandler.html#faulthandler.dump_traceback_later" title="faulthandler.dump_traceback_later"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump_traceback_later()</span></code></a> functions now accept file
  1223. descriptors in addition to file-like objects.
  1224. (Contributed by Wei Wu in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23566">bpo-23566</a>.)</p>
  1225. </section>
  1226. <section id="functools">
  1227. <h3>functools<a class="headerlink" href="#functools" title="Link to this heading">¶</a></h3>
  1228. <p id="whatsnew-lrucache">Most of the <a class="reference internal" href="../library/functools.html#functools.lru_cache" title="functools.lru_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">lru_cache()</span></code></a> machinery is now implemented in C, making
  1229. it significantly faster. (Contributed by Matt Joiner, Alexey Kachayev, and
  1230. Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14373">bpo-14373</a>.)</p>
  1231. </section>
  1232. <section id="glob">
  1233. <h3>glob<a class="headerlink" href="#glob" title="Link to this heading">¶</a></h3>
  1234. <p>The <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> and <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> functions now support recursive
  1235. search in subdirectories, using the <code class="docutils literal notranslate"><span class="pre">&quot;**&quot;</span></code> pattern.
  1236. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13968">bpo-13968</a>.)</p>
  1237. </section>
  1238. <section id="gzip">
  1239. <h3>gzip<a class="headerlink" href="#gzip" title="Link to this heading">¶</a></h3>
  1240. <p>The <em>mode</em> argument of the <a class="reference internal" href="../library/gzip.html#gzip.GzipFile" title="gzip.GzipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">GzipFile</span></code></a> constructor now
  1241. accepts <code class="docutils literal notranslate"><span class="pre">&quot;x&quot;</span></code> to request exclusive creation.
  1242. (Contributed by Tim Heaney in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19222">bpo-19222</a>.)</p>
  1243. </section>
  1244. <section id="heapq">
  1245. <h3>heapq<a class="headerlink" href="#heapq" title="Link to this heading">¶</a></h3>
  1246. <p>Element comparison in <a class="reference internal" href="../library/heapq.html#heapq.merge" title="heapq.merge"><code class="xref py py-func docutils literal notranslate"><span class="pre">merge()</span></code></a> can now be customized by
  1247. passing a <a class="reference internal" href="../glossary.html#term-key-function"><span class="xref std std-term">key function</span></a> in a new optional <em>key</em> keyword argument,
  1248. and a new optional <em>reverse</em> keyword argument can be used to reverse element
  1249. comparison:</p>
  1250. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">heapq</span>
  1251. <span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;9&#39;</span><span class="p">,</span> <span class="s1">&#39;777&#39;</span><span class="p">,</span> <span class="s1">&#39;55555&#39;</span><span class="p">]</span>
  1252. <span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;88&#39;</span><span class="p">,</span> <span class="s1">&#39;6666&#39;</span><span class="p">]</span>
  1253. <span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">heapq</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="nb">len</span><span class="p">))</span>
  1254. <span class="go">[&#39;9&#39;, &#39;88&#39;, &#39;777&#39;, &#39;6666&#39;, &#39;55555&#39;]</span>
  1255. <span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">heapq</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="nb">reversed</span><span class="p">(</span><span class="n">b</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="nb">len</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
  1256. <span class="go">[&#39;55555&#39;, &#39;6666&#39;, &#39;777&#39;, &#39;88&#39;, &#39;9&#39;]</span>
  1257. </pre></div>
  1258. </div>
  1259. <p>(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13742">bpo-13742</a>.)</p>
  1260. </section>
  1261. <section id="http">
  1262. <h3>http<a class="headerlink" href="#http" title="Link to this heading">¶</a></h3>
  1263. <p>A new <a class="reference internal" href="../library/http.html#http.HTTPStatus" title="http.HTTPStatus"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPStatus</span></code></a> enum that defines a set of
  1264. HTTP status codes, reason phrases and long descriptions written in English.
  1265. (Contributed by Demian Brecht in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21793">bpo-21793</a>.)</p>
  1266. </section>
  1267. <section id="http-client">
  1268. <h3>http.client<a class="headerlink" href="#http-client" title="Link to this heading">¶</a></h3>
  1269. <p><a class="reference internal" href="../library/http.client.html#http.client.HTTPConnection.getresponse" title="http.client.HTTPConnection.getresponse"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HTTPConnection.getresponse()</span></code></a>
  1270. now raises a <a class="reference internal" href="../library/http.client.html#http.client.RemoteDisconnected" title="http.client.RemoteDisconnected"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RemoteDisconnected</span></code></a> exception when a
  1271. remote server connection is closed unexpectedly. Additionally, if a
  1272. <a class="reference internal" href="../library/exceptions.html#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a> (of which <code class="docutils literal notranslate"><span class="pre">RemoteDisconnected</span></code>
  1273. is a subclass) is raised, the client socket is now closed automatically,
  1274. and will reconnect on the next request:</p>
  1275. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">http.client</span>
  1276. <span class="n">conn</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">(</span><span class="s1">&#39;www.python.org&#39;</span><span class="p">)</span>
  1277. <span class="k">for</span> <span class="n">retries</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
  1278. <span class="k">try</span><span class="p">:</span>
  1279. <span class="n">conn</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s1">&#39;GET&#39;</span><span class="p">,</span> <span class="s1">&#39;/&#39;</span><span class="p">)</span>
  1280. <span class="n">resp</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">getresponse</span><span class="p">()</span>
  1281. <span class="k">except</span> <span class="n">http</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">RemoteDisconnected</span><span class="p">:</span>
  1282. <span class="k">pass</span>
  1283. </pre></div>
  1284. </div>
  1285. <p>(Contributed by Martin Panter in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=3566">bpo-3566</a>.)</p>
  1286. </section>
  1287. <section id="idlelib-and-idle">
  1288. <h3>idlelib and IDLE<a class="headerlink" href="#idlelib-and-idle" title="Link to this heading">¶</a></h3>
  1289. <p>Since idlelib implements the IDLE shell and editor and is not intended for
  1290. import by other programs, it gets improvements with every release. See
  1291. <code class="file docutils literal notranslate"><span class="pre">Lib/idlelib/NEWS.txt</span></code> for a cumulative list of changes since 3.4.0,
  1292. as well as changes made in future 3.5.x releases. This file is also available
  1293. from the IDLE <span class="menuselection">Help ‣ About IDLE</span> dialog.</p>
  1294. </section>
  1295. <section id="imaplib">
  1296. <h3>imaplib<a class="headerlink" href="#imaplib" title="Link to this heading">¶</a></h3>
  1297. <p>The <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">IMAP4</span></code></a> class now supports the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> protocol.
  1298. When used in a <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement, the IMAP4 <code class="docutils literal notranslate"><span class="pre">LOGOUT</span></code>
  1299. command will be called automatically at the end of the block.
  1300. (Contributed by Tarek Ziadé and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4972">bpo-4972</a>.)</p>
  1301. <p>The <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> module now supports <span class="target" id="index-33"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc5161.html"><strong>RFC 5161</strong></a> (ENABLE Extension)
  1302. and <span class="target" id="index-34"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6855.html"><strong>RFC 6855</strong></a> (UTF-8 Support) via the <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4.enable" title="imaplib.IMAP4.enable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">IMAP4.enable()</span></code></a>
  1303. method. A new <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4.utf8_enabled" title="imaplib.IMAP4.utf8_enabled"><code class="xref py py-attr docutils literal notranslate"><span class="pre">IMAP4.utf8_enabled</span></code></a>
  1304. attribute tracks whether or not <span class="target" id="index-35"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6855.html"><strong>RFC 6855</strong></a> support is enabled.
  1305. (Contributed by Milan Oberkirch, R. David Murray, and Maciej Szulik in
  1306. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21800">bpo-21800</a>.)</p>
  1307. <p>The <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> module now automatically encodes non-ASCII string usernames
  1308. and passwords using UTF-8, as recommended by the RFCs. (Contributed by Milan
  1309. Oberkirch in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21800">bpo-21800</a>.)</p>
  1310. </section>
  1311. <section id="imghdr">
  1312. <h3>imghdr<a class="headerlink" href="#imghdr" title="Link to this heading">¶</a></h3>
  1313. <p>The <a class="reference internal" href="../library/imghdr.html#imghdr.what" title="imghdr.what"><code class="xref py py-func docutils literal notranslate"><span class="pre">what()</span></code></a> function now recognizes the
  1314. <a class="reference external" href="https://www.openexr.com">OpenEXR</a> format
  1315. (contributed by Martin Vignali and Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20295">bpo-20295</a>),
  1316. and the <a class="reference external" href="https://en.wikipedia.org/wiki/WebP">WebP</a> format
  1317. (contributed by Fabrice Aneche and Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20197">bpo-20197</a>.)</p>
  1318. </section>
  1319. <section id="importlib">
  1320. <h3>importlib<a class="headerlink" href="#importlib" title="Link to this heading">¶</a></h3>
  1321. <p>The <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">util.LazyLoader</span></code></a> class allows for
  1322. lazy loading of modules in applications where startup time is important.
  1323. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17621">bpo-17621</a>.)</p>
  1324. <p>The <a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader.source_to_code" title="importlib.abc.InspectLoader.source_to_code"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.InspectLoader.source_to_code()</span></code></a>
  1325. method is now a static method. This makes it easier to initialize a module
  1326. object with code compiled from a string by running
  1327. <code class="docutils literal notranslate"><span class="pre">exec(code,</span> <span class="pre">module.__dict__)</span></code>.
  1328. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21156">bpo-21156</a>.)</p>
  1329. <p>The new <a class="reference internal" href="../library/importlib.html#importlib.util.module_from_spec" title="importlib.util.module_from_spec"><code class="xref py py-func docutils literal notranslate"><span class="pre">util.module_from_spec()</span></code></a>
  1330. function is now the preferred way to create a new module. As opposed to
  1331. creating a <a class="reference internal" href="../library/types.html#types.ModuleType" title="types.ModuleType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.ModuleType</span></code></a> instance directly, this new function
  1332. will set the various import-controlled attributes based on the passed-in
  1333. spec object. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20383">bpo-20383</a>.)</p>
  1334. </section>
  1335. <section id="inspect">
  1336. <h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading">¶</a></h3>
  1337. <p>Both the <a class="reference internal" href="../library/inspect.html#inspect.Signature" title="inspect.Signature"><code class="xref py py-class docutils literal notranslate"><span class="pre">Signature</span></code></a> and <a class="reference internal" href="../library/inspect.html#inspect.Parameter" title="inspect.Parameter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Parameter</span></code></a> classes are
  1338. now picklable and hashable. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20726">bpo-20726</a>
  1339. and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20334">bpo-20334</a>.)</p>
  1340. <p>A new
  1341. <a class="reference internal" href="../library/inspect.html#inspect.BoundArguments.apply_defaults" title="inspect.BoundArguments.apply_defaults"><code class="xref py py-meth docutils literal notranslate"><span class="pre">BoundArguments.apply_defaults()</span></code></a>
  1342. method provides a way to set default values for missing arguments:</p>
  1343. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="s1">&#39;ham&#39;</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span> <span class="k">pass</span>
  1344. <span class="gp">&gt;&gt;&gt; </span><span class="n">ba</span> <span class="o">=</span> <span class="n">inspect</span><span class="o">.</span><span class="n">signature</span><span class="p">(</span><span class="n">foo</span><span class="p">)</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s1">&#39;spam&#39;</span><span class="p">)</span>
  1345. <span class="gp">&gt;&gt;&gt; </span><span class="n">ba</span><span class="o">.</span><span class="n">apply_defaults</span><span class="p">()</span>
  1346. <span class="gp">&gt;&gt;&gt; </span><span class="n">ba</span><span class="o">.</span><span class="n">arguments</span>
  1347. <span class="go">OrderedDict([(&#39;a&#39;, &#39;spam&#39;), (&#39;b&#39;, &#39;ham&#39;), (&#39;args&#39;, ())])</span>
  1348. </pre></div>
  1349. </div>
  1350. <p>(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24190">bpo-24190</a>.)</p>
  1351. <p>A new class method
  1352. <a class="reference internal" href="../library/inspect.html#inspect.Signature.from_callable" title="inspect.Signature.from_callable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Signature.from_callable()</span></code></a> makes
  1353. subclassing of <a class="reference internal" href="../library/inspect.html#inspect.Signature" title="inspect.Signature"><code class="xref py py-class docutils literal notranslate"><span class="pre">Signature</span></code></a> easier. (Contributed
  1354. by Yury Selivanov and Eric Snow in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17373">bpo-17373</a>.)</p>
  1355. <p>The <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">signature()</span></code></a> function now accepts a <em>follow_wrapped</em>
  1356. optional keyword argument, which, when set to <code class="docutils literal notranslate"><span class="pre">False</span></code>, disables automatic
  1357. following of <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> links.
  1358. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20691">bpo-20691</a>.)</p>
  1359. <p>A set of new functions to inspect
  1360. <a class="reference internal" href="../glossary.html#term-coroutine-function"><span class="xref std std-term">coroutine functions</span></a> and
  1361. <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine objects</span></a> has been added:
  1362. <a class="reference internal" href="../library/inspect.html#inspect.iscoroutine" title="inspect.iscoroutine"><code class="xref py py-func docutils literal notranslate"><span class="pre">iscoroutine()</span></code></a>, <a class="reference internal" href="../library/inspect.html#inspect.iscoroutinefunction" title="inspect.iscoroutinefunction"><code class="xref py py-func docutils literal notranslate"><span class="pre">iscoroutinefunction()</span></code></a>,
  1363. <a class="reference internal" href="../library/inspect.html#inspect.isawaitable" title="inspect.isawaitable"><code class="xref py py-func docutils literal notranslate"><span class="pre">isawaitable()</span></code></a>, <a class="reference internal" href="../library/inspect.html#inspect.getcoroutinelocals" title="inspect.getcoroutinelocals"><code class="xref py py-func docutils literal notranslate"><span class="pre">getcoroutinelocals()</span></code></a>,
  1364. and <a class="reference internal" href="../library/inspect.html#inspect.getcoroutinestate" title="inspect.getcoroutinestate"><code class="xref py py-func docutils literal notranslate"><span class="pre">getcoroutinestate()</span></code></a>.
  1365. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24017">bpo-24017</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24400">bpo-24400</a>.)</p>
  1366. <p>The <a class="reference internal" href="../library/inspect.html#inspect.stack" title="inspect.stack"><code class="xref py py-func docutils literal notranslate"><span class="pre">stack()</span></code></a>, <a class="reference internal" href="../library/inspect.html#inspect.trace" title="inspect.trace"><code class="xref py py-func docutils literal notranslate"><span class="pre">trace()</span></code></a>,
  1367. <a class="reference internal" href="../library/inspect.html#inspect.getouterframes" title="inspect.getouterframes"><code class="xref py py-func docutils literal notranslate"><span class="pre">getouterframes()</span></code></a>, and <a class="reference internal" href="../library/inspect.html#inspect.getinnerframes" title="inspect.getinnerframes"><code class="xref py py-func docutils literal notranslate"><span class="pre">getinnerframes()</span></code></a>
  1368. functions now return a list of named tuples.
  1369. (Contributed by Daniel Shahaf in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16808">bpo-16808</a>.)</p>
  1370. </section>
  1371. <section id="io">
  1372. <h3>io<a class="headerlink" href="#io" title="Link to this heading">¶</a></h3>
  1373. <p>A new <a class="reference internal" href="../library/io.html#io.BufferedIOBase.readinto1" title="io.BufferedIOBase.readinto1"><code class="xref py py-meth docutils literal notranslate"><span class="pre">BufferedIOBase.readinto1()</span></code></a>
  1374. method, that uses at most one call to the underlying raw stream’s
  1375. <a class="reference internal" href="../library/io.html#io.RawIOBase.read" title="io.RawIOBase.read"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RawIOBase.read()</span></code></a> or
  1376. <a class="reference internal" href="../library/io.html#io.RawIOBase.readinto" title="io.RawIOBase.readinto"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RawIOBase.readinto()</span></code></a> methods.
  1377. (Contributed by Nikolaus Rath in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20578">bpo-20578</a>.)</p>
  1378. </section>
  1379. <section id="ipaddress">
  1380. <h3>ipaddress<a class="headerlink" href="#ipaddress" title="Link to this heading">¶</a></h3>
  1381. <p>Both the <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv4Network</span></code></a> and <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv6Network</span></code></a> classes
  1382. now accept an <code class="docutils literal notranslate"><span class="pre">(address,</span> <span class="pre">netmask)</span></code> tuple argument, so as to easily construct
  1383. network objects from existing addresses:</p>
  1384. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">ipaddress</span>
  1385. <span class="gp">&gt;&gt;&gt; </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Network</span><span class="p">((</span><span class="s1">&#39;127.0.0.0&#39;</span><span class="p">,</span> <span class="mi">8</span><span class="p">))</span>
  1386. <span class="go">IPv4Network(&#39;127.0.0.0/8&#39;)</span>
  1387. <span class="gp">&gt;&gt;&gt; </span><span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Network</span><span class="p">((</span><span class="s1">&#39;127.0.0.0&#39;</span><span class="p">,</span> <span class="s1">&#39;255.0.0.0&#39;</span><span class="p">))</span>
  1388. <span class="go">IPv4Network(&#39;127.0.0.0/8&#39;)</span>
  1389. </pre></div>
  1390. </div>
  1391. <p>(Contributed by Peter Moody and Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16531">bpo-16531</a>.)</p>
  1392. <p>A new <code class="xref py py-attr docutils literal notranslate"><span class="pre">reverse_pointer</span></code> attribute for the
  1393. <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv4Network</span></code></a> and <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv6Network</span></code></a> classes
  1394. returns the name of the reverse DNS PTR record:</p>
  1395. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">ipaddress</span>
  1396. <span class="gp">&gt;&gt;&gt; </span><span class="n">addr</span> <span class="o">=</span> <span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv4Address</span><span class="p">(</span><span class="s1">&#39;127.0.0.1&#39;</span><span class="p">)</span>
  1397. <span class="gp">&gt;&gt;&gt; </span><span class="n">addr</span><span class="o">.</span><span class="n">reverse_pointer</span>
  1398. <span class="go">&#39;1.0.0.127.in-addr.arpa&#39;</span>
  1399. <span class="gp">&gt;&gt;&gt; </span><span class="n">addr6</span> <span class="o">=</span> <span class="n">ipaddress</span><span class="o">.</span><span class="n">IPv6Address</span><span class="p">(</span><span class="s1">&#39;::1&#39;</span><span class="p">)</span>
  1400. <span class="gp">&gt;&gt;&gt; </span><span class="n">addr6</span><span class="o">.</span><span class="n">reverse_pointer</span>
  1401. <span class="go">&#39;1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa&#39;</span>
  1402. </pre></div>
  1403. </div>
  1404. <p>(Contributed by Leon Weber in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20480">bpo-20480</a>.)</p>
  1405. </section>
  1406. <section id="json">
  1407. <h3>json<a class="headerlink" href="#json" title="Link to this heading">¶</a></h3>
  1408. <p>The <a class="reference internal" href="../library/json.html#module-json.tool" title="json.tool: A command line to validate and pretty-print JSON."><code class="xref py py-mod docutils literal notranslate"><span class="pre">json.tool</span></code></a> command line interface now preserves the order of keys in
  1409. JSON objects passed in input. The new <code class="docutils literal notranslate"><span class="pre">--sort-keys</span></code> option can be used
  1410. to sort the keys alphabetically. (Contributed by Berker Peksag
  1411. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21650">bpo-21650</a>.)</p>
  1412. <p>JSON decoder now raises <a class="reference internal" href="../library/json.html#json.JSONDecodeError" title="json.JSONDecodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">JSONDecodeError</span></code></a> instead of
  1413. <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> to provide better context information about the error.
  1414. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19361">bpo-19361</a>.)</p>
  1415. </section>
  1416. <section id="linecache">
  1417. <h3>linecache<a class="headerlink" href="#linecache" title="Link to this heading">¶</a></h3>
  1418. <p>A new <a class="reference internal" href="../library/linecache.html#linecache.lazycache" title="linecache.lazycache"><code class="xref py py-func docutils literal notranslate"><span class="pre">lazycache()</span></code></a> function can be used to capture information
  1419. about a non-file-based module to permit getting its lines later via
  1420. <a class="reference internal" href="../library/linecache.html#linecache.getline" title="linecache.getline"><code class="xref py py-func docutils literal notranslate"><span class="pre">getline()</span></code></a>. This avoids doing I/O until a line is actually
  1421. needed, without having to carry the module globals around indefinitely.
  1422. (Contributed by Robert Collins in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17911">bpo-17911</a>.)</p>
  1423. </section>
  1424. <section id="locale">
  1425. <h3>locale<a class="headerlink" href="#locale" title="Link to this heading">¶</a></h3>
  1426. <p>A new <a class="reference internal" href="../library/locale.html#locale.delocalize" title="locale.delocalize"><code class="xref py py-func docutils literal notranslate"><span class="pre">delocalize()</span></code></a> function can be used to convert a string into
  1427. a normalized number string, taking the <code class="docutils literal notranslate"><span class="pre">LC_NUMERIC</span></code> settings into account:</p>
  1428. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">locale</span>
  1429. <span class="gp">&gt;&gt;&gt; </span><span class="n">locale</span><span class="o">.</span><span class="n">setlocale</span><span class="p">(</span><span class="n">locale</span><span class="o">.</span><span class="n">LC_NUMERIC</span><span class="p">,</span> <span class="s1">&#39;de_DE.UTF-8&#39;</span><span class="p">)</span>
  1430. <span class="go">&#39;de_DE.UTF-8&#39;</span>
  1431. <span class="gp">&gt;&gt;&gt; </span><span class="n">locale</span><span class="o">.</span><span class="n">delocalize</span><span class="p">(</span><span class="s1">&#39;1.234,56&#39;</span><span class="p">)</span>
  1432. <span class="go">&#39;1234.56&#39;</span>
  1433. <span class="gp">&gt;&gt;&gt; </span><span class="n">locale</span><span class="o">.</span><span class="n">setlocale</span><span class="p">(</span><span class="n">locale</span><span class="o">.</span><span class="n">LC_NUMERIC</span><span class="p">,</span> <span class="s1">&#39;en_US.UTF-8&#39;</span><span class="p">)</span>
  1434. <span class="go">&#39;en_US.UTF-8&#39;</span>
  1435. <span class="gp">&gt;&gt;&gt; </span><span class="n">locale</span><span class="o">.</span><span class="n">delocalize</span><span class="p">(</span><span class="s1">&#39;1,234.56&#39;</span><span class="p">)</span>
  1436. <span class="go">&#39;1234.56&#39;</span>
  1437. </pre></div>
  1438. </div>
  1439. <p>(Contributed by Cédric Krier in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13918">bpo-13918</a>.)</p>
  1440. </section>
  1441. <section id="logging">
  1442. <h3>logging<a class="headerlink" href="#logging" title="Link to this heading">¶</a></h3>
  1443. <p>All logging methods (<a class="reference internal" href="../library/logging.html#logging.Logger" title="logging.Logger"><code class="xref py py-class docutils literal notranslate"><span class="pre">Logger</span></code></a> <a class="reference internal" href="../library/logging.html#logging.Logger.log" title="logging.Logger.log"><code class="xref py py-meth docutils literal notranslate"><span class="pre">log()</span></code></a>,
  1444. <a class="reference internal" href="../library/logging.html#logging.Logger.exception" title="logging.Logger.exception"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exception()</span></code></a>, <a class="reference internal" href="../library/logging.html#logging.Logger.critical" title="logging.Logger.critical"><code class="xref py py-meth docutils literal notranslate"><span class="pre">critical()</span></code></a>,
  1445. <a class="reference internal" href="../library/logging.html#logging.Logger.debug" title="logging.Logger.debug"><code class="xref py py-meth docutils literal notranslate"><span class="pre">debug()</span></code></a>, etc.), now accept exception instances
  1446. as an <em>exc_info</em> argument, in addition to boolean values and exception
  1447. tuples:</p>
  1448. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">logging</span>
  1449. <span class="gp">&gt;&gt;&gt; </span><span class="k">try</span><span class="p">:</span>
  1450. <span class="gp">... </span> <span class="mi">1</span><span class="o">/</span><span class="mi">0</span>
  1451. <span class="gp">... </span><span class="k">except</span> <span class="ne">ZeroDivisionError</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
  1452. <span class="gp">... </span> <span class="n">logging</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;exception&#39;</span><span class="p">,</span> <span class="n">exc_info</span><span class="o">=</span><span class="n">ex</span><span class="p">)</span>
  1453. <span class="go">ERROR:root:exception</span>
  1454. </pre></div>
  1455. </div>
  1456. <p>(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20537">bpo-20537</a>.)</p>
  1457. <p>The <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.HTTPHandler" title="logging.handlers.HTTPHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">handlers.HTTPHandler</span></code></a> class now
  1458. accepts an optional <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> instance to configure SSL
  1459. settings used in an HTTP connection.
  1460. (Contributed by Alex Gaynor in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22788">bpo-22788</a>.)</p>
  1461. <p>The <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.QueueListener" title="logging.handlers.QueueListener"><code class="xref py py-class docutils literal notranslate"><span class="pre">handlers.QueueListener</span></code></a> class now
  1462. takes a <em>respect_handler_level</em> keyword argument which, if set to <code class="docutils literal notranslate"><span class="pre">True</span></code>,
  1463. will pass messages to handlers taking handler levels into account.
  1464. (Contributed by Vinay Sajip.)</p>
  1465. </section>
  1466. <section id="lzma">
  1467. <h3>lzma<a class="headerlink" href="#lzma" title="Link to this heading">¶</a></h3>
  1468. <p>The <a class="reference internal" href="../library/lzma.html#lzma.LZMADecompressor.decompress" title="lzma.LZMADecompressor.decompress"><code class="xref py py-meth docutils literal notranslate"><span class="pre">LZMADecompressor.decompress()</span></code></a>
  1469. method now accepts an optional <em>max_length</em> argument to limit the maximum
  1470. size of decompressed data.
  1471. (Contributed by Martin Panter in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15955">bpo-15955</a>.)</p>
  1472. </section>
  1473. <section id="math">
  1474. <h3>math<a class="headerlink" href="#math" title="Link to this heading">¶</a></h3>
  1475. <p>Two new constants have been added to the <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> module: <a class="reference internal" href="../library/math.html#math.inf" title="math.inf"><code class="xref py py-data docutils literal notranslate"><span class="pre">inf</span></code></a>
  1476. and <a class="reference internal" href="../library/math.html#math.nan" title="math.nan"><code class="xref py py-data docutils literal notranslate"><span class="pre">nan</span></code></a>. (Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23185">bpo-23185</a>.)</p>
  1477. <p>A new function <a class="reference internal" href="../library/math.html#math.isclose" title="math.isclose"><code class="xref py py-func docutils literal notranslate"><span class="pre">isclose()</span></code></a> provides a way to test for approximate
  1478. equality. (Contributed by Chris Barker and Tal Einat in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24270">bpo-24270</a>.)</p>
  1479. <p>A new <a class="reference internal" href="../library/math.html#math.gcd" title="math.gcd"><code class="xref py py-func docutils literal notranslate"><span class="pre">gcd()</span></code></a> function has been added. The <code class="xref py py-func docutils literal notranslate"><span class="pre">fractions.gcd()</span></code>
  1480. function is now deprecated. (Contributed by Mark Dickinson and Serhiy
  1481. Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22486">bpo-22486</a>.)</p>
  1482. </section>
  1483. <section id="multiprocessing">
  1484. <h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Link to this heading">¶</a></h3>
  1485. <p><a class="reference internal" href="../library/multiprocessing.html#multiprocessing.sharedctypes.synchronized" title="multiprocessing.sharedctypes.synchronized"><code class="xref py py-func docutils literal notranslate"><span class="pre">sharedctypes.synchronized()</span></code></a>
  1486. objects now support the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> protocol.
  1487. (Contributed by Charles-François Natali in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21565">bpo-21565</a>.)</p>
  1488. </section>
  1489. <section id="operator">
  1490. <h3>operator<a class="headerlink" href="#operator" title="Link to this heading">¶</a></h3>
  1491. <p><a class="reference internal" href="../library/operator.html#operator.attrgetter" title="operator.attrgetter"><code class="xref py py-func docutils literal notranslate"><span class="pre">attrgetter()</span></code></a>, <a class="reference internal" href="../library/operator.html#operator.itemgetter" title="operator.itemgetter"><code class="xref py py-func docutils literal notranslate"><span class="pre">itemgetter()</span></code></a>,
  1492. and <a class="reference internal" href="../library/operator.html#operator.methodcaller" title="operator.methodcaller"><code class="xref py py-func docutils literal notranslate"><span class="pre">methodcaller()</span></code></a> objects now support pickling.
  1493. (Contributed by Josh Rosenberg and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22955">bpo-22955</a>.)</p>
  1494. <p>New <a class="reference internal" href="../library/operator.html#operator.matmul" title="operator.matmul"><code class="xref py py-func docutils literal notranslate"><span class="pre">matmul()</span></code></a> and <a class="reference internal" href="../library/operator.html#operator.imatmul" title="operator.imatmul"><code class="xref py py-func docutils literal notranslate"><span class="pre">imatmul()</span></code></a> functions
  1495. to perform matrix multiplication.
  1496. (Contributed by Benjamin Peterson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21176">bpo-21176</a>.)</p>
  1497. </section>
  1498. <section id="os">
  1499. <h3>os<a class="headerlink" href="#os" title="Link to this heading">¶</a></h3>
  1500. <p>The new <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> function returning an iterator of
  1501. <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">DirEntry</span></code></a> objects has been added. If possible, <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>
  1502. extracts file attributes while scanning a directory, removing the need to
  1503. perform subsequent system calls to determine file type or attributes, which may
  1504. significantly improve performance. (Contributed by Ben Hoyt with the help
  1505. of Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22524">bpo-22524</a>.)</p>
  1506. <p>On Windows, a new
  1507. <a class="reference internal" href="../library/os.html#os.stat_result.st_file_attributes" title="os.stat_result.st_file_attributes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">stat_result.st_file_attributes</span></code></a>
  1508. attribute is now available. It corresponds to the <code class="docutils literal notranslate"><span class="pre">dwFileAttributes</span></code> member
  1509. of the <code class="docutils literal notranslate"><span class="pre">BY_HANDLE_FILE_INFORMATION</span></code> structure returned by
  1510. <code class="docutils literal notranslate"><span class="pre">GetFileInformationByHandle()</span></code>. (Contributed by Ben Hoyt in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21719">bpo-21719</a>.)</p>
  1511. <p>The <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">urandom()</span></code></a> function now uses the <code class="docutils literal notranslate"><span class="pre">getrandom()</span></code> syscall on Linux 3.17
  1512. or newer, and <code class="docutils literal notranslate"><span class="pre">getentropy()</span></code> on OpenBSD 5.6 and newer, removing the need to
  1513. use <code class="docutils literal notranslate"><span class="pre">/dev/urandom</span></code> and avoiding failures due to potential file descriptor
  1514. exhaustion. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22181">bpo-22181</a>.)</p>
  1515. <p>New <a class="reference internal" href="../library/os.html#os.get_blocking" title="os.get_blocking"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_blocking()</span></code></a> and <a class="reference internal" href="../library/os.html#os.set_blocking" title="os.set_blocking"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_blocking()</span></code></a> functions allow
  1516. getting and setting a file descriptor’s blocking mode (<a class="reference internal" href="../library/os.html#os.O_NONBLOCK" title="os.O_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_NONBLOCK</span></code></a>.)
  1517. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22054">bpo-22054</a>.)</p>
  1518. <p>The <a class="reference internal" href="../library/os.html#os.truncate" title="os.truncate"><code class="xref py py-func docutils literal notranslate"><span class="pre">truncate()</span></code></a> and <a class="reference internal" href="../library/os.html#os.ftruncate" title="os.ftruncate"><code class="xref py py-func docutils literal notranslate"><span class="pre">ftruncate()</span></code></a> functions are now supported
  1519. on Windows. (Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23668">bpo-23668</a>.)</p>
  1520. <p>There is a new <a class="reference internal" href="../library/os.path.html#os.path.commonpath" title="os.path.commonpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.commonpath()</span></code></a> function returning the longest
  1521. common sub-path of each passed pathname. Unlike the
  1522. <a class="reference internal" href="../library/os.path.html#os.path.commonprefix" title="os.path.commonprefix"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.commonprefix()</span></code></a> function, it always returns a valid
  1523. path:</p>
  1524. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">commonprefix</span><span class="p">([</span><span class="s1">&#39;/usr/lib&#39;</span><span class="p">,</span> <span class="s1">&#39;/usr/local/lib&#39;</span><span class="p">])</span>
  1525. <span class="go">&#39;/usr/l&#39;</span>
  1526. <span class="gp">&gt;&gt;&gt; </span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">commonpath</span><span class="p">([</span><span class="s1">&#39;/usr/lib&#39;</span><span class="p">,</span> <span class="s1">&#39;/usr/local/lib&#39;</span><span class="p">])</span>
  1527. <span class="go">&#39;/usr&#39;</span>
  1528. </pre></div>
  1529. </div>
  1530. <p>(Contributed by Rafik Draoui and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10395">bpo-10395</a>.)</p>
  1531. </section>
  1532. <section id="pathlib">
  1533. <h3>pathlib<a class="headerlink" href="#pathlib" title="Link to this heading">¶</a></h3>
  1534. <p>The new <a class="reference internal" href="../library/pathlib.html#pathlib.Path.samefile" title="pathlib.Path.samefile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.samefile()</span></code></a> method can be used
  1535. to check whether the path points to the same file as another path, which can
  1536. be either another <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">Path</span></code></a> object, or a string:</p>
  1537. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pathlib</span>
  1538. <span class="gp">&gt;&gt;&gt; </span><span class="n">p1</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s1">&#39;/etc/hosts&#39;</span><span class="p">)</span>
  1539. <span class="gp">&gt;&gt;&gt; </span><span class="n">p2</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s1">&#39;/etc/../etc/hosts&#39;</span><span class="p">)</span>
  1540. <span class="gp">&gt;&gt;&gt; </span><span class="n">p1</span><span class="o">.</span><span class="n">samefile</span><span class="p">(</span><span class="n">p2</span><span class="p">)</span>
  1541. <span class="go">True</span>
  1542. </pre></div>
  1543. </div>
  1544. <p>(Contributed by Vajrasky Kok and Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19775">bpo-19775</a>.)</p>
  1545. <p>The <a class="reference internal" href="../library/pathlib.html#pathlib.Path.mkdir" title="pathlib.Path.mkdir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.mkdir()</span></code></a> method now accepts a new optional
  1546. <em>exist_ok</em> argument to match <code class="docutils literal notranslate"><span class="pre">mkdir</span> <span class="pre">-p</span></code> and <a class="reference internal" href="../library/os.html#os.makedirs" title="os.makedirs"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.makedirs()</span></code></a>
  1547. functionality. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21539">bpo-21539</a>.)</p>
  1548. <p>There is a new <a class="reference internal" href="../library/pathlib.html#pathlib.Path.expanduser" title="pathlib.Path.expanduser"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.expanduser()</span></code></a> method to
  1549. expand <code class="docutils literal notranslate"><span class="pre">~</span></code> and <code class="docutils literal notranslate"><span class="pre">~user</span></code> prefixes. (Contributed by Serhiy Storchaka and
  1550. Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19776">bpo-19776</a>.)</p>
  1551. <p>A new <a class="reference internal" href="../library/pathlib.html#pathlib.Path.home" title="pathlib.Path.home"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.home()</span></code></a> class method can be used to get
  1552. a <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">Path</span></code></a> instance representing the user’s home
  1553. directory.
  1554. (Contributed by Victor Salgado and Mayank Tripathi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19777">bpo-19777</a>.)</p>
  1555. <p>New <a class="reference internal" href="../library/pathlib.html#pathlib.Path.write_text" title="pathlib.Path.write_text"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.write_text()</span></code></a>,
  1556. <a class="reference internal" href="../library/pathlib.html#pathlib.Path.read_text" title="pathlib.Path.read_text"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.read_text()</span></code></a>,
  1557. <a class="reference internal" href="../library/pathlib.html#pathlib.Path.write_bytes" title="pathlib.Path.write_bytes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.write_bytes()</span></code></a>,
  1558. <a class="reference internal" href="../library/pathlib.html#pathlib.Path.read_bytes" title="pathlib.Path.read_bytes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.read_bytes()</span></code></a> methods to simplify
  1559. read/write operations on files.</p>
  1560. <p>The following code snippet will create or rewrite existing file
  1561. <code class="docutils literal notranslate"><span class="pre">~/spam42</span></code>:</p>
  1562. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">pathlib</span>
  1563. <span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s1">&#39;~/spam42&#39;</span><span class="p">)</span>
  1564. <span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">expanduser</span><span class="p">()</span><span class="o">.</span><span class="n">write_text</span><span class="p">(</span><span class="s1">&#39;ham&#39;</span><span class="p">)</span>
  1565. <span class="go">3</span>
  1566. </pre></div>
  1567. </div>
  1568. <p>(Contributed by Christopher Welborn in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20218">bpo-20218</a>.)</p>
  1569. </section>
  1570. <section id="pickle">
  1571. <h3>pickle<a class="headerlink" href="#pickle" title="Link to this heading">¶</a></h3>
  1572. <p>Nested objects, such as unbound methods or nested classes, can now be pickled
  1573. using <a class="reference internal" href="../library/pickle.html#pickle-protocols"><span class="std std-ref">pickle protocols</span></a> older than protocol version 4.
  1574. Protocol version 4 already supports these cases. (Contributed by Serhiy
  1575. Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23611">bpo-23611</a>.)</p>
  1576. </section>
  1577. <section id="poplib">
  1578. <h3>poplib<a class="headerlink" href="#poplib" title="Link to this heading">¶</a></h3>
  1579. <p>A new <a class="reference internal" href="../library/poplib.html#poplib.POP3.utf8" title="poplib.POP3.utf8"><code class="xref py py-meth docutils literal notranslate"><span class="pre">POP3.utf8()</span></code></a> command enables <span class="target" id="index-36"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6856.html"><strong>RFC 6856</strong></a>
  1580. (Internationalized Email) support, if a POP server supports it.
  1581. (Contributed by Milan OberKirch in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21804">bpo-21804</a>.)</p>
  1582. </section>
  1583. <section id="re">
  1584. <h3>re<a class="headerlink" href="#re" title="Link to this heading">¶</a></h3>
  1585. <p>References and conditional references to groups with fixed length are now
  1586. allowed in lookbehind assertions:</p>
  1587. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">re</span>
  1588. <span class="gp">&gt;&gt;&gt; </span><span class="n">pat</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;(a|b).(?&lt;=\1)c&#39;</span><span class="p">)</span>
  1589. <span class="gp">&gt;&gt;&gt; </span><span class="n">pat</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">&#39;aac&#39;</span><span class="p">)</span>
  1590. <span class="go">&lt;_sre.SRE_Match object; span=(0, 3), match=&#39;aac&#39;&gt;</span>
  1591. <span class="gp">&gt;&gt;&gt; </span><span class="n">pat</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">&#39;bbc&#39;</span><span class="p">)</span>
  1592. <span class="go">&lt;_sre.SRE_Match object; span=(0, 3), match=&#39;bbc&#39;&gt;</span>
  1593. </pre></div>
  1594. </div>
  1595. <p>(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9179">bpo-9179</a>.)</p>
  1596. <p>The number of capturing groups in regular expressions is no longer limited to
  1597. 100. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22437">bpo-22437</a>.)</p>
  1598. <p>The <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">sub()</span></code></a> and <a class="reference internal" href="../library/re.html#re.subn" title="re.subn"><code class="xref py py-func docutils literal notranslate"><span class="pre">subn()</span></code></a> functions now replace unmatched
  1599. groups with empty strings instead of raising an exception.
  1600. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1519638">bpo-1519638</a>.)</p>
  1601. <p>The <a class="reference internal" href="../library/re.html#re.error" title="re.error"><code class="xref py py-class docutils literal notranslate"><span class="pre">re.error</span></code></a> exceptions have new attributes,
  1602. <a class="reference internal" href="../library/re.html#re.error.msg" title="re.error.msg"><code class="xref py py-attr docutils literal notranslate"><span class="pre">msg</span></code></a>, <a class="reference internal" href="../library/re.html#re.error.pattern" title="re.error.pattern"><code class="xref py py-attr docutils literal notranslate"><span class="pre">pattern</span></code></a>,
  1603. <a class="reference internal" href="../library/re.html#re.error.pos" title="re.error.pos"><code class="xref py py-attr docutils literal notranslate"><span class="pre">pos</span></code></a>, <a class="reference internal" href="../library/re.html#re.error.lineno" title="re.error.lineno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">lineno</span></code></a>,
  1604. and <a class="reference internal" href="../library/re.html#re.error.colno" title="re.error.colno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">colno</span></code></a>, that provide better context
  1605. information about the error:</p>
  1606. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
  1607. <span class="gp">... </span><span class="s2"> (?x)</span>
  1608. <span class="gp">... </span><span class="s2"> .++</span>
  1609. <span class="gp">... </span><span class="s2">&quot;&quot;&quot;</span><span class="p">)</span>
  1610. <span class="gt">Traceback (most recent call last):</span>
  1611. <span class="w"> </span><span class="c">...</span>
  1612. <span class="gr">sre_constants.error</span>: <span class="n">multiple repeat at position 16 (line 3, column 7)</span>
  1613. </pre></div>
  1614. </div>
  1615. <p>(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22578">bpo-22578</a>.)</p>
  1616. </section>
  1617. <section id="readline">
  1618. <h3>readline<a class="headerlink" href="#readline" title="Link to this heading">¶</a></h3>
  1619. <p>A new <a class="reference internal" href="../library/readline.html#readline.append_history_file" title="readline.append_history_file"><code class="xref py py-func docutils literal notranslate"><span class="pre">append_history_file()</span></code></a> function can be used to append
  1620. the specified number of trailing elements in history to the given file.
  1621. (Contributed by Bruno Cauet in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22940">bpo-22940</a>.)</p>
  1622. </section>
  1623. <section id="selectors">
  1624. <h3>selectors<a class="headerlink" href="#selectors" title="Link to this heading">¶</a></h3>
  1625. <p>The new <a class="reference internal" href="../library/selectors.html#selectors.DevpollSelector" title="selectors.DevpollSelector"><code class="xref py py-class docutils literal notranslate"><span class="pre">DevpollSelector</span></code></a> supports efficient
  1626. <code class="docutils literal notranslate"><span class="pre">/dev/poll</span></code> polling on Solaris.
  1627. (Contributed by Giampaolo Rodola’ in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18931">bpo-18931</a>.)</p>
  1628. </section>
  1629. <section id="shutil">
  1630. <h3>shutil<a class="headerlink" href="#shutil" title="Link to this heading">¶</a></h3>
  1631. <p>The <a class="reference internal" href="../library/shutil.html#shutil.move" title="shutil.move"><code class="xref py py-func docutils literal notranslate"><span class="pre">move()</span></code></a> function now accepts a <em>copy_function</em> argument,
  1632. allowing, for example, the <a class="reference internal" href="../library/shutil.html#shutil.copy" title="shutil.copy"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy()</span></code></a> function to be used instead of
  1633. the default <a class="reference internal" href="../library/shutil.html#shutil.copy2" title="shutil.copy2"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy2()</span></code></a> if there is a need to ignore file metadata
  1634. when moving.
  1635. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19840">bpo-19840</a>.)</p>
  1636. <p>The <a class="reference internal" href="../library/shutil.html#shutil.make_archive" title="shutil.make_archive"><code class="xref py py-func docutils literal notranslate"><span class="pre">make_archive()</span></code></a> function now supports the <em>xztar</em> format.
  1637. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5411">bpo-5411</a>.)</p>
  1638. </section>
  1639. <section id="signal">
  1640. <h3>signal<a class="headerlink" href="#signal" title="Link to this heading">¶</a></h3>
  1641. <p>On Windows, the <a class="reference internal" href="../library/signal.html#signal.set_wakeup_fd" title="signal.set_wakeup_fd"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_wakeup_fd()</span></code></a> function now also supports
  1642. socket handles. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22018">bpo-22018</a>.)</p>
  1643. <p>Various <code class="docutils literal notranslate"><span class="pre">SIG*</span></code> constants in the <a class="reference internal" href="../library/signal.html#module-signal" title="signal: Set handlers for asynchronous events."><code class="xref py py-mod docutils literal notranslate"><span class="pre">signal</span></code></a> module have been converted into
  1644. <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">Enums</span></code></a>. This allows meaningful names to be printed
  1645. during debugging, instead of integer “magic numbers”.
  1646. (Contributed by Giampaolo Rodola’ in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21076">bpo-21076</a>.)</p>
  1647. </section>
  1648. <section id="smtpd">
  1649. <h3>smtpd<a class="headerlink" href="#smtpd" title="Link to this heading">¶</a></h3>
  1650. <p>Both the <code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code> and <code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPChannel</span></code> classes now
  1651. accept a <em>decode_data</em> keyword argument to determine if the <code class="docutils literal notranslate"><span class="pre">DATA</span></code> portion of
  1652. the SMTP transaction is decoded using the <code class="docutils literal notranslate"><span class="pre">&quot;utf-8&quot;</span></code> codec or is instead
  1653. provided to the
  1654. <code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTPServer.process_message()</span></code>
  1655. method as a byte string. The default is <code class="docutils literal notranslate"><span class="pre">True</span></code> for backward compatibility
  1656. reasons, but will change to <code class="docutils literal notranslate"><span class="pre">False</span></code> in Python 3.6. If <em>decode_data</em> is set
  1657. to <code class="docutils literal notranslate"><span class="pre">False</span></code>, the <code class="docutils literal notranslate"><span class="pre">process_message</span></code> method must be prepared to accept keyword
  1658. arguments.
  1659. (Contributed by Maciej Szulik in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19662">bpo-19662</a>.)</p>
  1660. <p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code> class now advertises the <code class="docutils literal notranslate"><span class="pre">8BITMIME</span></code> extension
  1661. (<span class="target" id="index-37"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6152.html"><strong>RFC 6152</strong></a>) if <em>decode_data</em> has been set <code class="docutils literal notranslate"><span class="pre">True</span></code>. If the client
  1662. specifies <code class="docutils literal notranslate"><span class="pre">BODY=8BITMIME</span></code> on the <code class="docutils literal notranslate"><span class="pre">MAIL</span></code> command, it is passed to
  1663. <code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTPServer.process_message()</span></code>
  1664. via the <em>mail_options</em> keyword.
  1665. (Contributed by Milan Oberkirch and R. David Murray in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21795">bpo-21795</a>.)</p>
  1666. <p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code> class now also supports the <code class="docutils literal notranslate"><span class="pre">SMTPUTF8</span></code>
  1667. extension (<span class="target" id="index-38"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6531.html"><strong>RFC 6531</strong></a>: Internationalized Email). If the client specified
  1668. <code class="docutils literal notranslate"><span class="pre">SMTPUTF8</span> <span class="pre">BODY=8BITMIME</span></code> on the <code class="docutils literal notranslate"><span class="pre">MAIL</span></code> command, they are passed to
  1669. <code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTPServer.process_message()</span></code>
  1670. via the <em>mail_options</em> keyword. It is the responsibility of the
  1671. <code class="docutils literal notranslate"><span class="pre">process_message</span></code> method to correctly handle the <code class="docutils literal notranslate"><span class="pre">SMTPUTF8</span></code> data.
  1672. (Contributed by Milan Oberkirch in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21725">bpo-21725</a>.)</p>
  1673. <p>It is now possible to provide, directly or via name resolution, IPv6
  1674. addresses in the <code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code> constructor, and have it
  1675. successfully connect. (Contributed by Milan Oberkirch in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14758">bpo-14758</a>.)</p>
  1676. </section>
  1677. <section id="smtplib">
  1678. <h3>smtplib<a class="headerlink" href="#smtplib" title="Link to this heading">¶</a></h3>
  1679. <p>A new <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP.auth" title="smtplib.SMTP.auth"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTP.auth()</span></code></a> method provides a convenient way to
  1680. implement custom authentication mechanisms. (Contributed by Milan
  1681. Oberkirch in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15014">bpo-15014</a>.)</p>
  1682. <p>The <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP.set_debuglevel" title="smtplib.SMTP.set_debuglevel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTP.set_debuglevel()</span></code></a> method now
  1683. accepts an additional debuglevel (2), which enables timestamps in debug
  1684. messages. (Contributed by Gavin Chappell and Maciej Szulik in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16914">bpo-16914</a>.)</p>
  1685. <p>Both the <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP.sendmail" title="smtplib.SMTP.sendmail"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTP.sendmail()</span></code></a> and
  1686. <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP.send_message" title="smtplib.SMTP.send_message"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SMTP.send_message()</span></code></a> methods now
  1687. support <span class="target" id="index-39"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc6531.html"><strong>RFC 6531</strong></a> (SMTPUTF8).
  1688. (Contributed by Milan Oberkirch and R. David Murray in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22027">bpo-22027</a>.)</p>
  1689. </section>
  1690. <section id="sndhdr">
  1691. <h3>sndhdr<a class="headerlink" href="#sndhdr" title="Link to this heading">¶</a></h3>
  1692. <p>The <a class="reference internal" href="../library/sndhdr.html#sndhdr.what" title="sndhdr.what"><code class="xref py py-func docutils literal notranslate"><span class="pre">what()</span></code></a> and <a class="reference internal" href="../library/sndhdr.html#sndhdr.whathdr" title="sndhdr.whathdr"><code class="xref py py-func docutils literal notranslate"><span class="pre">whathdr()</span></code></a> functions now return
  1693. a <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>. (Contributed by Claudiu Popa in
  1694. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18615">bpo-18615</a>.)</p>
  1695. </section>
  1696. <section id="socket">
  1697. <h3>socket<a class="headerlink" href="#socket" title="Link to this heading">¶</a></h3>
  1698. <p>Functions with timeouts now use a monotonic clock, instead of a system clock.
  1699. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22043">bpo-22043</a>.)</p>
  1700. <p>A new <a class="reference internal" href="../library/socket.html#socket.socket.sendfile" title="socket.socket.sendfile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.sendfile()</span></code></a> method allows
  1701. sending a file over a socket by using the high-performance <a class="reference internal" href="../library/os.html#os.sendfile" title="os.sendfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.sendfile()</span></code></a>
  1702. function on UNIX, resulting in uploads being from 2 to 3 times faster than when
  1703. using plain <a class="reference internal" href="../library/socket.html#socket.socket.send" title="socket.socket.send"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.send()</span></code></a>.
  1704. (Contributed by Giampaolo Rodola’ in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17552">bpo-17552</a>.)</p>
  1705. <p>The <a class="reference internal" href="../library/socket.html#socket.socket.sendall" title="socket.socket.sendall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.sendall()</span></code></a> method no longer resets the
  1706. socket timeout every time bytes are received or sent. The socket timeout is
  1707. now the maximum total duration to send all data.
  1708. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23853">bpo-23853</a>.)</p>
  1709. <p>The <em>backlog</em> argument of the <a class="reference internal" href="../library/socket.html#socket.socket.listen" title="socket.socket.listen"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.listen()</span></code></a>
  1710. method is now optional. By default it is set to
  1711. <a class="reference internal" href="../library/socket.html#socket.SOMAXCONN" title="socket.SOMAXCONN"><code class="xref py py-data docutils literal notranslate"><span class="pre">SOMAXCONN</span></code></a> or to <code class="docutils literal notranslate"><span class="pre">128</span></code>, whichever is less.
  1712. (Contributed by Charles-François Natali in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21455">bpo-21455</a>.)</p>
  1713. </section>
  1714. <section id="ssl">
  1715. <h3>ssl<a class="headerlink" href="#ssl" title="Link to this heading">¶</a></h3>
  1716. <section id="memory-bio-support">
  1717. <span id="whatsnew-sslmemorybio"></span><h4>Memory BIO Support<a class="headerlink" href="#memory-bio-support" title="Link to this heading">¶</a></h4>
  1718. <p>(Contributed by Geert Jansen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21965">bpo-21965</a>.)</p>
  1719. <p>The new <a class="reference internal" href="../library/ssl.html#ssl.SSLObject" title="ssl.SSLObject"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLObject</span></code></a> class has been added to provide SSL protocol
  1720. support for cases when the network I/O capabilities of <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket" title="ssl.SSLSocket"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLSocket</span></code></a>
  1721. are not necessary or are suboptimal. <code class="docutils literal notranslate"><span class="pre">SSLObject</span></code> represents
  1722. an SSL protocol instance, but does not implement any network I/O methods, and
  1723. instead provides a memory buffer interface. The new <a class="reference internal" href="../library/ssl.html#ssl.MemoryBIO" title="ssl.MemoryBIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">MemoryBIO</span></code></a>
  1724. class can be used to pass data between Python and an SSL protocol instance.</p>
  1725. <p>The memory BIO SSL support is primarily intended to be used in frameworks
  1726. implementing asynchronous I/O for which <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket" title="ssl.SSLSocket"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLSocket</span></code></a>’s readiness
  1727. model (“select/poll”) is inefficient.</p>
  1728. <p>A new <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.wrap_bio" title="ssl.SSLContext.wrap_bio"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLContext.wrap_bio()</span></code></a> method can be used
  1729. to create a new <code class="docutils literal notranslate"><span class="pre">SSLObject</span></code> instance.</p>
  1730. </section>
  1731. <section id="application-layer-protocol-negotiation-support">
  1732. <h4>Application-Layer Protocol Negotiation Support<a class="headerlink" href="#application-layer-protocol-negotiation-support" title="Link to this heading">¶</a></h4>
  1733. <p>(Contributed by Benjamin Peterson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20188">bpo-20188</a>.)</p>
  1734. <p>Where OpenSSL support is present, the <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> module now implements
  1735. the <em>Application-Layer Protocol Negotiation</em> TLS extension as described
  1736. in <span class="target" id="index-40"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc7301.html"><strong>RFC 7301</strong></a>.</p>
  1737. <p>The new <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_alpn_protocols" title="ssl.SSLContext.set_alpn_protocols"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLContext.set_alpn_protocols()</span></code></a>
  1738. can be used to specify which protocols a socket should advertise during
  1739. the TLS handshake.</p>
  1740. <p>The new
  1741. <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.selected_alpn_protocol" title="ssl.SSLSocket.selected_alpn_protocol"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.selected_alpn_protocol()</span></code></a>
  1742. returns the protocol that was selected during the TLS handshake.
  1743. The <a class="reference internal" href="../library/ssl.html#ssl.HAS_ALPN" title="ssl.HAS_ALPN"><code class="xref py py-const docutils literal notranslate"><span class="pre">HAS_ALPN</span></code></a> flag indicates whether ALPN support is present.</p>
  1744. </section>
  1745. <section id="other-changes">
  1746. <h4>Other Changes<a class="headerlink" href="#other-changes" title="Link to this heading">¶</a></h4>
  1747. <p>There is a new <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.version" title="ssl.SSLSocket.version"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.version()</span></code></a> method to
  1748. query the actual protocol version in use.
  1749. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20421">bpo-20421</a>.)</p>
  1750. <p>The <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket" title="ssl.SSLSocket"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLSocket</span></code></a> class now implements
  1751. a <code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.sendfile()</span></code> method.
  1752. (Contributed by Giampaolo Rodola’ in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17552">bpo-17552</a>.)</p>
  1753. <p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.send()</span></code> method now raises either
  1754. the <a class="reference internal" href="../library/ssl.html#ssl.SSLWantReadError" title="ssl.SSLWantReadError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ssl.SSLWantReadError</span></code></a> or <a class="reference internal" href="../library/ssl.html#ssl.SSLWantWriteError" title="ssl.SSLWantWriteError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ssl.SSLWantWriteError</span></code></a> exception on a
  1755. non-blocking socket if the operation would block. Previously, it would return
  1756. <code class="docutils literal notranslate"><span class="pre">0</span></code>. (Contributed by Nikolaus Rath in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20951">bpo-20951</a>.)</p>
  1757. <p>The <a class="reference internal" href="../library/ssl.html#ssl.cert_time_to_seconds" title="ssl.cert_time_to_seconds"><code class="xref py py-func docutils literal notranslate"><span class="pre">cert_time_to_seconds()</span></code></a> function now interprets the input time
  1758. as UTC and not as local time, per <span class="target" id="index-41"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc5280.html"><strong>RFC 5280</strong></a>. Additionally, the return
  1759. value is always an <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>. (Contributed by Akira Li in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19940">bpo-19940</a>.)</p>
  1760. <p>New <code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLObject.shared_ciphers()</span></code> and
  1761. <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.shared_ciphers" title="ssl.SSLSocket.shared_ciphers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.shared_ciphers()</span></code></a> methods return
  1762. the list of ciphers sent by the client during the handshake.
  1763. (Contributed by Benjamin Peterson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23186">bpo-23186</a>.)</p>
  1764. <p>The <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.do_handshake" title="ssl.SSLSocket.do_handshake"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.do_handshake()</span></code></a>,
  1765. <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.read" title="ssl.SSLSocket.read"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.read()</span></code></a>,
  1766. <code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.shutdown()</span></code>, and
  1767. <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.write" title="ssl.SSLSocket.write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.write()</span></code></a> methods of the <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket" title="ssl.SSLSocket"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLSocket</span></code></a>
  1768. class no longer reset the socket timeout every time bytes are received or sent.
  1769. The socket timeout is now the maximum total duration of the method.
  1770. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23853">bpo-23853</a>.)</p>
  1771. <p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">match_hostname()</span></code> function now supports matching of IP addresses.
  1772. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23239">bpo-23239</a>.)</p>
  1773. </section>
  1774. </section>
  1775. <section id="sqlite3">
  1776. <h3>sqlite3<a class="headerlink" href="#sqlite3" title="Link to this heading">¶</a></h3>
  1777. <p>The <a class="reference internal" href="../library/sqlite3.html#sqlite3.Row" title="sqlite3.Row"><code class="xref py py-class docutils literal notranslate"><span class="pre">Row</span></code></a> class now fully supports the sequence protocol,
  1778. in particular <a class="reference internal" href="../library/functions.html#reversed" title="reversed"><code class="xref py py-func docutils literal notranslate"><span class="pre">reversed()</span></code></a> iteration and slice indexing.
  1779. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10203">bpo-10203</a>; by Lucas Sinclair,
  1780. Jessica McKellar, and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13583">bpo-13583</a>.)</p>
  1781. </section>
  1782. <section id="subprocess">
  1783. <span id="whatsnew-subprocess"></span><h3>subprocess<a class="headerlink" href="#subprocess" title="Link to this heading">¶</a></h3>
  1784. <p>The new <a class="reference internal" href="../library/subprocess.html#subprocess.run" title="subprocess.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">run()</span></code></a> function has been added.
  1785. It runs the specified command and returns a
  1786. <a class="reference internal" href="../library/subprocess.html#subprocess.CompletedProcess" title="subprocess.CompletedProcess"><code class="xref py py-class docutils literal notranslate"><span class="pre">CompletedProcess</span></code></a> object, which describes a finished
  1787. process. The new API is more consistent and is the recommended approach
  1788. to invoking subprocesses in Python code that does not need to maintain
  1789. compatibility with earlier Python versions.
  1790. (Contributed by Thomas Kluyver in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23342">bpo-23342</a>.)</p>
  1791. <p>Examples:</p>
  1792. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">subprocess</span><span class="o">.</span><span class="n">run</span><span class="p">([</span><span class="s2">&quot;ls&quot;</span><span class="p">,</span> <span class="s2">&quot;-l&quot;</span><span class="p">])</span> <span class="c1"># doesn&#39;t capture output</span>
  1793. <span class="go">CompletedProcess(args=[&#39;ls&#39;, &#39;-l&#39;], returncode=0)</span>
  1794. <span class="gp">&gt;&gt;&gt; </span><span class="n">subprocess</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="s2">&quot;exit 1&quot;</span><span class="p">,</span> <span class="n">shell</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">check</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
  1795. <span class="gt">Traceback (most recent call last):</span>
  1796. <span class="w"> </span><span class="c">...</span>
  1797. <span class="gr">subprocess.CalledProcessError</span>: <span class="n">Command &#39;exit 1&#39; returned non-zero exit status 1</span>
  1798. <span class="gp">&gt;&gt;&gt; </span><span class="n">subprocess</span><span class="o">.</span><span class="n">run</span><span class="p">([</span><span class="s2">&quot;ls&quot;</span><span class="p">,</span> <span class="s2">&quot;-l&quot;</span><span class="p">,</span> <span class="s2">&quot;/dev/null&quot;</span><span class="p">],</span> <span class="n">stdout</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">)</span>
  1799. <span class="go">CompletedProcess(args=[&#39;ls&#39;, &#39;-l&#39;, &#39;/dev/null&#39;], returncode=0,</span>
  1800. <span class="go">stdout=b&#39;crw-rw-rw- 1 root root 1, 3 Jan 23 16:23 /dev/null\n&#39;)</span>
  1801. </pre></div>
  1802. </div>
  1803. </section>
  1804. <section id="sys">
  1805. <h3>sys<a class="headerlink" href="#sys" title="Link to this heading">¶</a></h3>
  1806. <p>A new <code class="xref py py-func docutils literal notranslate"><span class="pre">set_coroutine_wrapper()</span></code> function allows setting a global
  1807. hook that will be called whenever a <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine object</span></a>
  1808. is created by an <a class="reference internal" href="../reference/compound_stmts.html#async-def"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">def</span></code></a> function. A corresponding
  1809. <code class="xref py py-func docutils literal notranslate"><span class="pre">get_coroutine_wrapper()</span></code> can be used to obtain a currently set
  1810. wrapper. Both functions are <a class="reference internal" href="../glossary.html#term-provisional-API"><span class="xref std std-term">provisional</span></a>,
  1811. and are intended for debugging purposes only. (Contributed by Yury Selivanov
  1812. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24017">bpo-24017</a>.)</p>
  1813. <p>A new <a class="reference internal" href="../library/sys.html#sys.is_finalizing" title="sys.is_finalizing"><code class="xref py py-func docutils literal notranslate"><span class="pre">is_finalizing()</span></code></a> function can be used to check if the Python
  1814. interpreter is <a class="reference internal" href="../glossary.html#term-interpreter-shutdown"><span class="xref std std-term">shutting down</span></a>.
  1815. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22696">bpo-22696</a>.)</p>
  1816. </section>
  1817. <section id="sysconfig">
  1818. <h3>sysconfig<a class="headerlink" href="#sysconfig" title="Link to this heading">¶</a></h3>
  1819. <p>The name of the user scripts directory on Windows now includes the first
  1820. two components of the Python version. (Contributed by Paul Moore
  1821. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23437">bpo-23437</a>.)</p>
  1822. </section>
  1823. <section id="tarfile">
  1824. <h3>tarfile<a class="headerlink" href="#tarfile" title="Link to this heading">¶</a></h3>
  1825. <p>The <em>mode</em> argument of the <a class="reference internal" href="../library/tarfile.html#tarfile.open" title="tarfile.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function now accepts <code class="docutils literal notranslate"><span class="pre">&quot;x&quot;</span></code>
  1826. to request exclusive creation. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21717">bpo-21717</a>.)</p>
  1827. <p>The <a class="reference internal" href="../library/tarfile.html#tarfile.TarFile.extractall" title="tarfile.TarFile.extractall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TarFile.extractall()</span></code></a> and
  1828. <a class="reference internal" href="../library/tarfile.html#tarfile.TarFile.extract" title="tarfile.TarFile.extract"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TarFile.extract()</span></code></a> methods now take a keyword
  1829. argument <em>numeric_owner</em>. If set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, the extracted files and
  1830. directories will be owned by the numeric <code class="docutils literal notranslate"><span class="pre">uid</span></code> and <code class="docutils literal notranslate"><span class="pre">gid</span></code> from the tarfile.
  1831. If set to <code class="docutils literal notranslate"><span class="pre">False</span></code> (the default, and the behavior in versions prior to 3.5),
  1832. they will be owned by the named user and group in the tarfile.
  1833. (Contributed by Michael Vogt and Eric Smith in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23193">bpo-23193</a>.)</p>
  1834. <p>The <a class="reference internal" href="../library/tarfile.html#tarfile.TarFile.list" title="tarfile.TarFile.list"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TarFile.list()</span></code></a> now accepts an optional
  1835. <em>members</em> keyword argument that can be set to a subset of the list returned
  1836. by <a class="reference internal" href="../library/tarfile.html#tarfile.TarFile.getmembers" title="tarfile.TarFile.getmembers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TarFile.getmembers()</span></code></a>.
  1837. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21549">bpo-21549</a>.)</p>
  1838. </section>
  1839. <section id="threading">
  1840. <h3>threading<a class="headerlink" href="#threading" title="Link to this heading">¶</a></h3>
  1841. <p>Both the <a class="reference internal" href="../library/threading.html#threading.Lock.acquire" title="threading.Lock.acquire"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Lock.acquire()</span></code></a> and
  1842. <a class="reference internal" href="../library/threading.html#threading.RLock.acquire" title="threading.RLock.acquire"><code class="xref py py-meth docutils literal notranslate"><span class="pre">RLock.acquire()</span></code></a> methods
  1843. now use a monotonic clock for timeout management.
  1844. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22043">bpo-22043</a>.)</p>
  1845. </section>
  1846. <section id="time">
  1847. <h3>time<a class="headerlink" href="#time" title="Link to this heading">¶</a></h3>
  1848. <p>The <a class="reference internal" href="../library/time.html#time.monotonic" title="time.monotonic"><code class="xref py py-func docutils literal notranslate"><span class="pre">monotonic()</span></code></a> function is now always available.
  1849. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22043">bpo-22043</a>.)</p>
  1850. </section>
  1851. <section id="timeit">
  1852. <h3>timeit<a class="headerlink" href="#timeit" title="Link to this heading">¶</a></h3>
  1853. <p>A new command line option <code class="docutils literal notranslate"><span class="pre">-u</span></code> or <code class="samp docutils literal notranslate"><span class="pre">--unit=</span><em><span class="pre">U</span></em></code> can be used to specify the time
  1854. unit for the timer output. Supported options are <code class="docutils literal notranslate"><span class="pre">usec</span></code>, <code class="docutils literal notranslate"><span class="pre">msec</span></code>,
  1855. or <code class="docutils literal notranslate"><span class="pre">sec</span></code>. (Contributed by Julian Gindi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18983">bpo-18983</a>.)</p>
  1856. <p>The <a class="reference internal" href="../library/timeit.html#timeit.timeit" title="timeit.timeit"><code class="xref py py-func docutils literal notranslate"><span class="pre">timeit()</span></code></a> function has a new <em>globals</em> parameter for
  1857. specifying the namespace in which the code will be running.
  1858. (Contributed by Ben Roberts in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=2527">bpo-2527</a>.)</p>
  1859. </section>
  1860. <section id="tkinter">
  1861. <h3>tkinter<a class="headerlink" href="#tkinter" title="Link to this heading">¶</a></h3>
  1862. <p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter._fix</span></code> module used for setting up the Tcl/Tk environment
  1863. on Windows has been replaced by a private function in the <a class="reference internal" href="../library/tkinter.html#module-_tkinter" title="_tkinter: A binary module that contains the low-level interface to Tcl/Tk."><code class="xref py py-mod docutils literal notranslate"><span class="pre">_tkinter</span></code></a>
  1864. module which makes no permanent changes to environment variables.
  1865. (Contributed by Zachary Ware in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20035">bpo-20035</a>.)</p>
  1866. </section>
  1867. <section id="traceback">
  1868. <span id="whatsnew-traceback"></span><h3>traceback<a class="headerlink" href="#traceback" title="Link to this heading">¶</a></h3>
  1869. <p>New <a class="reference internal" href="../library/traceback.html#traceback.walk_stack" title="traceback.walk_stack"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk_stack()</span></code></a> and <a class="reference internal" href="../library/traceback.html#traceback.walk_tb" title="traceback.walk_tb"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk_tb()</span></code></a>
  1870. functions to conveniently traverse frame and
  1871. <a class="reference internal" href="../reference/datamodel.html#traceback-objects"><span class="std std-ref">traceback objects</span></a>.
  1872. (Contributed by Robert Collins in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17911">bpo-17911</a>.)</p>
  1873. <p>New lightweight classes: <a class="reference internal" href="../library/traceback.html#traceback.TracebackException" title="traceback.TracebackException"><code class="xref py py-class docutils literal notranslate"><span class="pre">TracebackException</span></code></a>,
  1874. <a class="reference internal" href="../library/traceback.html#traceback.StackSummary" title="traceback.StackSummary"><code class="xref py py-class docutils literal notranslate"><span class="pre">StackSummary</span></code></a>, and <a class="reference internal" href="../library/traceback.html#traceback.FrameSummary" title="traceback.FrameSummary"><code class="xref py py-class docutils literal notranslate"><span class="pre">FrameSummary</span></code></a>.
  1875. (Contributed by Robert Collins in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17911">bpo-17911</a>.)</p>
  1876. <p>Both the <a class="reference internal" href="../library/traceback.html#traceback.print_tb" title="traceback.print_tb"><code class="xref py py-func docutils literal notranslate"><span class="pre">print_tb()</span></code></a> and <a class="reference internal" href="../library/traceback.html#traceback.print_stack" title="traceback.print_stack"><code class="xref py py-func docutils literal notranslate"><span class="pre">print_stack()</span></code></a> functions
  1877. now support negative values for the <em>limit</em> argument.
  1878. (Contributed by Dmitry Kazakov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22619">bpo-22619</a>.)</p>
  1879. </section>
  1880. <section id="types">
  1881. <h3>types<a class="headerlink" href="#types" title="Link to this heading">¶</a></h3>
  1882. <p>A new <a class="reference internal" href="../library/types.html#types.coroutine" title="types.coroutine"><code class="xref py py-func docutils literal notranslate"><span class="pre">coroutine()</span></code></a> function to transform
  1883. <a class="reference internal" href="../glossary.html#term-generator-iterator"><span class="xref std std-term">generator</span></a> and
  1884. <a class="reference internal" href="../library/collections.abc.html#collections.abc.Generator" title="collections.abc.Generator"><code class="xref py py-class docutils literal notranslate"><span class="pre">generator-like</span></code></a> objects into
  1885. <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitables</span></a>.
  1886. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24017">bpo-24017</a>.)</p>
  1887. <p>A new type called <a class="reference internal" href="../library/types.html#types.CoroutineType" title="types.CoroutineType"><code class="xref py py-class docutils literal notranslate"><span class="pre">CoroutineType</span></code></a>, which is used for
  1888. <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> objects created by <a class="reference internal" href="../reference/compound_stmts.html#async-def"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">def</span></code></a> functions.
  1889. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24400">bpo-24400</a>.)</p>
  1890. </section>
  1891. <section id="unicodedata">
  1892. <h3>unicodedata<a class="headerlink" href="#unicodedata" title="Link to this heading">¶</a></h3>
  1893. <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="https://unicode.org/versions/Unicode8.0.0/">Unicode 8.0.0</a>.</p>
  1894. </section>
  1895. <section id="unittest">
  1896. <h3>unittest<a class="headerlink" href="#unittest" title="Link to this heading">¶</a></h3>
  1897. <p>The <a class="reference internal" href="../library/unittest.html#unittest.TestLoader.loadTestsFromModule" title="unittest.TestLoader.loadTestsFromModule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TestLoader.loadTestsFromModule()</span></code></a>
  1898. method now accepts a keyword-only argument <em>pattern</em> which is passed to
  1899. <code class="docutils literal notranslate"><span class="pre">load_tests</span></code> as the third argument. Found packages are now checked for
  1900. <code class="docutils literal notranslate"><span class="pre">load_tests</span></code> regardless of whether their path matches <em>pattern</em>, because it
  1901. is impossible for a package name to match the default pattern.
  1902. (Contributed by Robert Collins and Barry A. Warsaw in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16662">bpo-16662</a>.)</p>
  1903. <p>Unittest discovery errors now are exposed in the
  1904. <a class="reference internal" href="../library/unittest.html#unittest.TestLoader.errors" title="unittest.TestLoader.errors"><code class="xref py py-data docutils literal notranslate"><span class="pre">TestLoader.errors</span></code></a> attribute of the
  1905. <a class="reference internal" href="../library/unittest.html#unittest.TestLoader" title="unittest.TestLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestLoader</span></code></a> instance.
  1906. (Contributed by Robert Collins in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19746">bpo-19746</a>.)</p>
  1907. <p>A new command line option <code class="docutils literal notranslate"><span class="pre">--locals</span></code> to show local variables in
  1908. tracebacks. (Contributed by Robert Collins in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22936">bpo-22936</a>.)</p>
  1909. </section>
  1910. <section id="unittest-mock">
  1911. <h3>unittest.mock<a class="headerlink" href="#unittest-mock" title="Link to this heading">¶</a></h3>
  1912. <p>The <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> class has the following improvements:</p>
  1913. <ul class="simple">
  1914. <li><p>The class constructor has a new <em>unsafe</em> parameter, which causes mock
  1915. objects to raise <a class="reference internal" href="../library/exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a> on attribute names starting
  1916. with <code class="docutils literal notranslate"><span class="pre">&quot;assert&quot;</span></code>.
  1917. (Contributed by Kushal Das in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21238">bpo-21238</a>.)</p></li>
  1918. <li><p>A new <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.Mock.assert_not_called" title="unittest.mock.Mock.assert_not_called"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Mock.assert_not_called()</span></code></a>
  1919. method to check if the mock object was called.
  1920. (Contributed by Kushal Das in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21262">bpo-21262</a>.)</p></li>
  1921. </ul>
  1922. <p>The <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.MagicMock" title="unittest.mock.MagicMock"><code class="xref py py-class docutils literal notranslate"><span class="pre">MagicMock</span></code></a> class now supports <code class="xref py py-meth docutils literal notranslate"><span class="pre">__truediv__()</span></code>,
  1923. <code class="xref py py-meth docutils literal notranslate"><span class="pre">__divmod__()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">__matmul__()</span></code> operators.
  1924. (Contributed by Johannes Baiter in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20968">bpo-20968</a>, and Håkan Lövdahl
  1925. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23581">bpo-23581</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23568">bpo-23568</a>.)</p>
  1926. <p>It is no longer necessary to explicitly pass <code class="docutils literal notranslate"><span class="pre">create=True</span></code> to the
  1927. <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.patch" title="unittest.mock.patch"><code class="xref py py-func docutils literal notranslate"><span class="pre">patch()</span></code></a> function when patching builtin names.
  1928. (Contributed by Kushal Das in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17660">bpo-17660</a>.)</p>
  1929. </section>
  1930. <section id="urllib">
  1931. <h3>urllib<a class="headerlink" href="#urllib" title="Link to this heading">¶</a></h3>
  1932. <p>A new
  1933. <a class="reference internal" href="../library/urllib.request.html#urllib.request.HTTPPasswordMgrWithPriorAuth" title="urllib.request.HTTPPasswordMgrWithPriorAuth"><code class="xref py py-class docutils literal notranslate"><span class="pre">request.HTTPPasswordMgrWithPriorAuth</span></code></a>
  1934. class allows HTTP Basic Authentication credentials to be managed so as to
  1935. eliminate unnecessary <code class="docutils literal notranslate"><span class="pre">401</span></code> response handling, or to unconditionally send
  1936. credentials on the first request in order to communicate with servers that
  1937. return a <code class="docutils literal notranslate"><span class="pre">404</span></code> response instead of a <code class="docutils literal notranslate"><span class="pre">401</span></code> if the <code class="docutils literal notranslate"><span class="pre">Authorization</span></code> header
  1938. is not sent. (Contributed by Matej Cepl in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19494">bpo-19494</a> and Akshit Khurana in
  1939. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=7159">bpo-7159</a>.)</p>
  1940. <p>A new <em>quote_via</em> argument for the
  1941. <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.urlencode" title="urllib.parse.urlencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse.urlencode()</span></code></a>
  1942. function provides a way to control the encoding of query parts if needed.
  1943. (Contributed by Samwyse and Arnon Yaari in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13866">bpo-13866</a>.)</p>
  1944. <p>The <a class="reference internal" href="../library/urllib.request.html#urllib.request.urlopen" title="urllib.request.urlopen"><code class="xref py py-func docutils literal notranslate"><span class="pre">request.urlopen()</span></code></a> function accepts an
  1945. <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> object as a <em>context</em> argument, which will be used for
  1946. the HTTPS connection. (Contributed by Alex Gaynor in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22366">bpo-22366</a>.)</p>
  1947. <p>The <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.urljoin" title="urllib.parse.urljoin"><code class="xref py py-func docutils literal notranslate"><span class="pre">parse.urljoin()</span></code></a> was updated to use the
  1948. <span class="target" id="index-42"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc3986.html"><strong>RFC 3986</strong></a> semantics for the resolution of relative URLs, rather than
  1949. <span class="target" id="index-43"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc1808.html"><strong>RFC 1808</strong></a> and <span class="target" id="index-44"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2396.html"><strong>RFC 2396</strong></a>.
  1950. (Contributed by Demian Brecht and Senthil Kumaran in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22118">bpo-22118</a>.)</p>
  1951. </section>
  1952. <section id="wsgiref">
  1953. <h3>wsgiref<a class="headerlink" href="#wsgiref" title="Link to this heading">¶</a></h3>
  1954. <p>The <em>headers</em> argument of the <a class="reference internal" href="../library/wsgiref.html#wsgiref.headers.Headers" title="wsgiref.headers.Headers"><code class="xref py py-class docutils literal notranslate"><span class="pre">headers.Headers</span></code></a>
  1955. class constructor is now optional.
  1956. (Contributed by Pablo Torres Navarrete and SilentGhost in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5800">bpo-5800</a>.)</p>
  1957. </section>
  1958. <section id="xmlrpc">
  1959. <h3>xmlrpc<a class="headerlink" href="#xmlrpc" title="Link to this heading">¶</a></h3>
  1960. <p>The <a class="reference internal" href="../library/xmlrpc.client.html#xmlrpc.client.ServerProxy" title="xmlrpc.client.ServerProxy"><code class="xref py py-class docutils literal notranslate"><span class="pre">client.ServerProxy</span></code></a> class now supports
  1961. the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> protocol.
  1962. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20627">bpo-20627</a>.)</p>
  1963. <p>The <a class="reference internal" href="../library/xmlrpc.client.html#xmlrpc.client.ServerProxy" title="xmlrpc.client.ServerProxy"><code class="xref py py-class docutils literal notranslate"><span class="pre">client.ServerProxy</span></code></a> constructor now accepts
  1964. an optional <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> instance.
  1965. (Contributed by Alex Gaynor in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22960">bpo-22960</a>.)</p>
  1966. </section>
  1967. <section id="xml-sax">
  1968. <h3>xml.sax<a class="headerlink" href="#xml-sax" title="Link to this heading">¶</a></h3>
  1969. <p>SAX parsers now support a character stream of the
  1970. <a class="reference internal" href="../library/xml.sax.reader.html#xml.sax.xmlreader.InputSource" title="xml.sax.xmlreader.InputSource"><code class="xref py py-class docutils literal notranslate"><span class="pre">xmlreader.InputSource</span></code></a> object.
  1971. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=2175">bpo-2175</a>.)</p>
  1972. <p><a class="reference internal" href="../library/xml.sax.html#xml.sax.parseString" title="xml.sax.parseString"><code class="xref py py-func docutils literal notranslate"><span class="pre">parseString()</span></code></a> now accepts 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> instance.
  1973. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10590">bpo-10590</a>.)</p>
  1974. </section>
  1975. <section id="zipfile">
  1976. <h3>zipfile<a class="headerlink" href="#zipfile" title="Link to this heading">¶</a></h3>
  1977. <p>ZIP output can now be written to unseekable streams.
  1978. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23252">bpo-23252</a>.)</p>
  1979. <p>The <em>mode</em> argument of <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> method now
  1980. accepts <code class="docutils literal notranslate"><span class="pre">&quot;x&quot;</span></code> to request exclusive creation.
  1981. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21717">bpo-21717</a>.)</p>
  1982. </section>
  1983. </section>
  1984. <section id="other-module-level-changes">
  1985. <h2>Other module-level changes<a class="headerlink" href="#other-module-level-changes" title="Link to this heading">¶</a></h2>
  1986. <p>Many functions in the <a class="reference internal" href="../library/mmap.html#module-mmap" title="mmap: Interface to memory-mapped files for Unix and Windows."><code class="xref py py-mod docutils literal notranslate"><span class="pre">mmap</span></code></a>, <a class="reference internal" href="../library/ossaudiodev.html#module-ossaudiodev" title="ossaudiodev: Access to OSS-compatible audio devices. (deprecated) (Linux, FreeBSD)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code></a>, <a class="reference internal" href="../library/socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socket</span></code></a>,
  1987. <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>, and <a class="reference internal" href="../library/codecs.html#module-codecs" title="codecs: Encode and decode data and streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">codecs</span></code></a> modules now accept writable
  1988. <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like objects</span></a>.
  1989. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23001">bpo-23001</a>.)</p>
  1990. </section>
  1991. <section id="optimizations">
  1992. <h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading">¶</a></h2>
  1993. <p>The <a class="reference internal" href="../library/os.html#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.walk()</span></code></a> function has been sped up by 3 to 5 times on POSIX systems,
  1994. and by 7 to 20 times on Windows. This was done using the new <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>
  1995. function, which exposes file information from the underlying <code class="docutils literal notranslate"><span class="pre">readdir</span></code> or
  1996. <code class="docutils literal notranslate"><span class="pre">FindFirstFile</span></code>/<code class="docutils literal notranslate"><span class="pre">FindNextFile</span></code> system calls. (Contributed by
  1997. Ben Hoyt with help from Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23605">bpo-23605</a>.)</p>
  1998. <p>Construction of <code class="docutils literal notranslate"><span class="pre">bytes(int)</span></code> (filled by zero bytes) is faster and uses less
  1999. memory for large objects. <code class="docutils literal notranslate"><span class="pre">calloc()</span></code> is used instead of <code class="docutils literal notranslate"><span class="pre">malloc()</span></code> to
  2000. allocate memory for these objects.
  2001. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21233">bpo-21233</a>.)</p>
  2002. <p>Some operations on <a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ipaddress</span></code></a> <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Network" title="ipaddress.IPv4Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv4Network</span></code></a> and
  2003. <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Network" title="ipaddress.IPv6Network"><code class="xref py py-class docutils literal notranslate"><span class="pre">IPv6Network</span></code></a> have been massively sped up, such as
  2004. <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Network.subnets" title="ipaddress.IPv4Network.subnets"><code class="xref py py-meth docutils literal notranslate"><span class="pre">subnets()</span></code></a>, <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Network.supernet" title="ipaddress.IPv4Network.supernet"><code class="xref py py-meth docutils literal notranslate"><span class="pre">supernet()</span></code></a>,
  2005. <a class="reference internal" href="../library/ipaddress.html#ipaddress.summarize_address_range" title="ipaddress.summarize_address_range"><code class="xref py py-func docutils literal notranslate"><span class="pre">summarize_address_range()</span></code></a>, <a class="reference internal" href="../library/ipaddress.html#ipaddress.collapse_addresses" title="ipaddress.collapse_addresses"><code class="xref py py-func docutils literal notranslate"><span class="pre">collapse_addresses()</span></code></a>.
  2006. The speed up can range from 3 to 15 times.
  2007. (Contributed by Antoine Pitrou, Michel Albert, and Markus in
  2008. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21486">bpo-21486</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21487">bpo-21487</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20826">bpo-20826</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23266">bpo-23266</a>.)</p>
  2009. <p>Pickling of <a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ipaddress</span></code></a> objects was optimized to produce significantly
  2010. smaller output. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23133">bpo-23133</a>.)</p>
  2011. <p>Many operations on <a class="reference internal" href="../library/io.html#io.BytesIO" title="io.BytesIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.BytesIO</span></code></a> are now 50% to 100% faster.
  2012. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15381">bpo-15381</a> and David Wilson in
  2013. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22003">bpo-22003</a>.)</p>
  2014. <p>The <a class="reference internal" href="../library/marshal.html#marshal.dumps" title="marshal.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">marshal.dumps()</span></code></a> function is now faster: 65–85% with versions 3
  2015. and 4, 20–25% with versions 0 to 2 on typical data, and up to 5 times in
  2016. best cases.
  2017. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20416">bpo-20416</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23344">bpo-23344</a>.)</p>
  2018. <p>The UTF-32 encoder is now 3 to 7 times faster.
  2019. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15027">bpo-15027</a>.)</p>
  2020. <p>Regular expressions are now parsed up to 10% faster.
  2021. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19380">bpo-19380</a>.)</p>
  2022. <p>The <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">json.dumps()</span></code></a> function was optimized to run with
  2023. <code class="docutils literal notranslate"><span class="pre">ensure_ascii=False</span></code> as fast as with <code class="docutils literal notranslate"><span class="pre">ensure_ascii=True</span></code>.
  2024. (Contributed by Naoki Inada in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23206">bpo-23206</a>.)</p>
  2025. <p>The <a class="reference internal" href="../c-api/object.html#c.PyObject_IsInstance" title="PyObject_IsInstance"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_IsInstance()</span></code></a> and <a class="reference internal" href="../c-api/object.html#c.PyObject_IsSubclass" title="PyObject_IsSubclass"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_IsSubclass()</span></code></a>
  2026. functions have been sped up in the common case that the second argument
  2027. has <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> as its metaclass.
  2028. (Contributed Georg Brandl by in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22540">bpo-22540</a>.)</p>
  2029. <p>Method caching was slightly improved, yielding up to 5% performance
  2030. improvement in some benchmarks.
  2031. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22847">bpo-22847</a>.)</p>
  2032. <p>Objects from the <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> module now use 50% less memory on 64-bit
  2033. builds. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23488">bpo-23488</a>.)</p>
  2034. <p>The <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-func docutils literal notranslate"><span class="pre">property()</span></code></a> getter calls are up to 25% faster.
  2035. (Contributed by Joe Jevnik in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23910">bpo-23910</a>.)</p>
  2036. <p>Instantiation of <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> is now up to 30% faster.
  2037. (Contributed by Stefan Behnel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22464">bpo-22464</a>.)</p>
  2038. <p>String methods <a class="reference internal" href="../library/stdtypes.html#str.find" title="str.find"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#str.rfind" title="str.rfind"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rfind()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#str.split" title="str.split"><code class="xref py py-meth docutils literal notranslate"><span class="pre">split()</span></code></a>,
  2039. <a class="reference internal" href="../library/stdtypes.html#str.partition" title="str.partition"><code class="xref py py-meth docutils literal notranslate"><span class="pre">partition()</span></code></a> and the <a class="reference internal" href="../reference/expressions.html#in"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">in</span></code></a> string operator are now significantly
  2040. faster for searching 1-character substrings.
  2041. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23573">bpo-23573</a>.)</p>
  2042. </section>
  2043. <section id="build-and-c-api-changes">
  2044. <h2>Build and C API Changes<a class="headerlink" href="#build-and-c-api-changes" title="Link to this heading">¶</a></h2>
  2045. <p>New <code class="docutils literal notranslate"><span class="pre">calloc</span></code> functions were added:</p>
  2046. <ul class="simple">
  2047. <li><p><a class="reference internal" href="../c-api/memory.html#c.PyMem_RawCalloc" title="PyMem_RawCalloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawCalloc()</span></code></a>,</p></li>
  2048. <li><p><a class="reference internal" href="../c-api/memory.html#c.PyMem_Calloc" title="PyMem_Calloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Calloc()</span></code></a>,</p></li>
  2049. <li><p><a class="reference internal" href="../c-api/memory.html#c.PyObject_Calloc" title="PyObject_Calloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Calloc()</span></code></a>.</p></li>
  2050. </ul>
  2051. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21233">bpo-21233</a>.)</p>
  2052. <p>New encoding/decoding helper functions:</p>
  2053. <ul class="simple">
  2054. <li><p><a class="reference internal" href="../c-api/sys.html#c.Py_DecodeLocale" title="Py_DecodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DecodeLocale()</span></code></a> (replaced <code class="docutils literal notranslate"><span class="pre">_Py_char2wchar()</span></code>),</p></li>
  2055. <li><p><a class="reference internal" href="../c-api/sys.html#c.Py_EncodeLocale" title="Py_EncodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_EncodeLocale()</span></code></a> (replaced <code class="docutils literal notranslate"><span class="pre">_Py_wchar2char()</span></code>).</p></li>
  2056. </ul>
  2057. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18395">bpo-18395</a>.)</p>
  2058. <p>A new <a class="reference internal" href="../c-api/codec.html#c.PyCodec_NameReplaceErrors" title="PyCodec_NameReplaceErrors"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCodec_NameReplaceErrors()</span></code></a> function to replace the unicode
  2059. encode error with <code class="docutils literal notranslate"><span class="pre">\N{...}</span></code> escapes.
  2060. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19676">bpo-19676</a>.)</p>
  2061. <p>A new <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_FormatV" title="PyErr_FormatV"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_FormatV()</span></code></a> function similar to <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Format" title="PyErr_Format"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Format()</span></code></a>,
  2062. but accepts a <code class="xref c c-type docutils literal notranslate"><span class="pre">va_list</span></code> argument.
  2063. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18711">bpo-18711</a>.)</p>
  2064. <p>A new <code class="xref c c-data docutils literal notranslate"><span class="pre">PyExc_RecursionError</span></code> exception.
  2065. (Contributed by Georg Brandl in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19235">bpo-19235</a>.)</p>
  2066. <p>New <a class="reference internal" href="../c-api/module.html#c.PyModule_FromDefAndSpec" title="PyModule_FromDefAndSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_FromDefAndSpec()</span></code></a>, <a class="reference internal" href="../c-api/module.html#c.PyModule_FromDefAndSpec2" title="PyModule_FromDefAndSpec2"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_FromDefAndSpec2()</span></code></a>,
  2067. and <a class="reference internal" href="../c-api/module.html#c.PyModule_ExecDef" title="PyModule_ExecDef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_ExecDef()</span></code></a> functions introduced by <span class="target" id="index-45"></span><a class="pep reference external" href="https://peps.python.org/pep-0489/"><strong>PEP 489</strong></a> –
  2068. multi-phase extension module initialization.
  2069. (Contributed by Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24268">bpo-24268</a>.)</p>
  2070. <p>New <a class="reference internal" href="../c-api/number.html#c.PyNumber_MatrixMultiply" title="PyNumber_MatrixMultiply"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_MatrixMultiply()</span></code></a> and
  2071. <a class="reference internal" href="../c-api/number.html#c.PyNumber_InPlaceMatrixMultiply" title="PyNumber_InPlaceMatrixMultiply"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_InPlaceMatrixMultiply()</span></code></a> functions to perform matrix
  2072. multiplication.
  2073. (Contributed by Benjamin Peterson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21176">bpo-21176</a>. See also <span class="target" id="index-46"></span><a class="pep reference external" href="https://peps.python.org/pep-0465/"><strong>PEP 465</strong></a>
  2074. for details.)</p>
  2075. <p>The <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_finalize" title="PyTypeObject.tp_finalize"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_finalize</span></code></a> slot is now part of the stable ABI.</p>
  2076. <p>Windows builds now require Microsoft Visual C++ 14.0, which
  2077. is available as part of <a class="reference external" href="https://visualstudio.microsoft.com/en/vs/older-downloads/#visual-studio-2015-and-other-products">Visual Studio 2015</a>.</p>
  2078. <p>Extension modules now include a platform information tag in their filename on
  2079. some platforms (the tag is optional, and CPython will import extensions without
  2080. it, although if the tag is present and mismatched, the extension won’t be
  2081. loaded):</p>
  2082. <ul class="simple">
  2083. <li><p>On Linux, extension module filenames end with
  2084. <code class="docutils literal notranslate"><span class="pre">.cpython-&lt;major&gt;&lt;minor&gt;m-&lt;architecture&gt;-&lt;os&gt;.pyd</span></code>:</p>
  2085. <ul>
  2086. <li><p><code class="docutils literal notranslate"><span class="pre">&lt;major&gt;</span></code> is the major number of the Python version;
  2087. for Python 3.5 this is <code class="docutils literal notranslate"><span class="pre">3</span></code>.</p></li>
  2088. <li><p><code class="docutils literal notranslate"><span class="pre">&lt;minor&gt;</span></code> is the minor number of the Python version;
  2089. for Python 3.5 this is <code class="docutils literal notranslate"><span class="pre">5</span></code>.</p></li>
  2090. <li><p><code class="docutils literal notranslate"><span class="pre">&lt;architecture&gt;</span></code> is the hardware architecture the extension module
  2091. was built to run on. It’s most commonly either <code class="docutils literal notranslate"><span class="pre">i386</span></code> for 32-bit Intel
  2092. platforms or <code class="docutils literal notranslate"><span class="pre">x86_64</span></code> for 64-bit Intel (and AMD) platforms.</p></li>
  2093. <li><p><code class="docutils literal notranslate"><span class="pre">&lt;os&gt;</span></code> is always <code class="docutils literal notranslate"><span class="pre">linux-gnu</span></code>, except for extensions built to
  2094. talk to the 32-bit ABI on 64-bit platforms, in which case it is
  2095. <code class="docutils literal notranslate"><span class="pre">linux-gnu32</span></code> (and <code class="docutils literal notranslate"><span class="pre">&lt;architecture&gt;</span></code> will be <code class="docutils literal notranslate"><span class="pre">x86_64</span></code>).</p></li>
  2096. </ul>
  2097. </li>
  2098. <li><p>On Windows, extension module filenames end with
  2099. <code class="docutils literal notranslate"><span class="pre">&lt;debug&gt;.cp&lt;major&gt;&lt;minor&gt;-&lt;platform&gt;.pyd</span></code>:</p>
  2100. <ul>
  2101. <li><p><code class="docutils literal notranslate"><span class="pre">&lt;major&gt;</span></code> is the major number of the Python version;
  2102. for Python 3.5 this is <code class="docutils literal notranslate"><span class="pre">3</span></code>.</p></li>
  2103. <li><p><code class="docutils literal notranslate"><span class="pre">&lt;minor&gt;</span></code> is the minor number of the Python version;
  2104. for Python 3.5 this is <code class="docutils literal notranslate"><span class="pre">5</span></code>.</p></li>
  2105. <li><p><code class="docutils literal notranslate"><span class="pre">&lt;platform&gt;</span></code> is the platform the extension module was built for,
  2106. either <code class="docutils literal notranslate"><span class="pre">win32</span></code> for Win32, <code class="docutils literal notranslate"><span class="pre">win_amd64</span></code> for Win64, <code class="docutils literal notranslate"><span class="pre">win_ia64</span></code> for
  2107. Windows Itanium 64, and <code class="docutils literal notranslate"><span class="pre">win_arm</span></code> for Windows on ARM.</p></li>
  2108. <li><p>If built in debug mode, <code class="docutils literal notranslate"><span class="pre">&lt;debug&gt;</span></code> will be <code class="docutils literal notranslate"><span class="pre">_d</span></code>,
  2109. otherwise it will be blank.</p></li>
  2110. </ul>
  2111. </li>
  2112. <li><p>On OS X platforms, extension module filenames now end with <code class="docutils literal notranslate"><span class="pre">-darwin.so</span></code>.</p></li>
  2113. <li><p>On all other platforms, extension module filenames are the same as they were
  2114. with Python 3.4.</p></li>
  2115. </ul>
  2116. </section>
  2117. <section id="deprecated">
  2118. <h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading">¶</a></h2>
  2119. <section id="new-keywords">
  2120. <h3>New Keywords<a class="headerlink" href="#new-keywords" title="Link to this heading">¶</a></h3>
  2121. <p><code class="docutils literal notranslate"><span class="pre">async</span></code> and <code class="docutils literal notranslate"><span class="pre">await</span></code> are not recommended to be used as variable, class,
  2122. function or module names. Introduced by <span class="target" id="index-47"></span><a class="pep reference external" href="https://peps.python.org/pep-0492/"><strong>PEP 492</strong></a> in Python 3.5, they will
  2123. become proper keywords in Python 3.7.</p>
  2124. </section>
  2125. <section id="deprecated-python-behavior">
  2126. <h3>Deprecated Python Behavior<a class="headerlink" href="#deprecated-python-behavior" title="Link to this heading">¶</a></h3>
  2127. <p>Raising the <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> exception inside a generator will now generate a silent
  2128. <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>, which will become a non-silent deprecation
  2129. warning in Python 3.6 and will trigger 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> in Python 3.7.
  2130. See <a class="reference internal" href="#whatsnew-pep-479"><span class="std std-ref">PEP 479: Change StopIteration handling inside generators</span></a>
  2131. for details.</p>
  2132. </section>
  2133. <section id="unsupported-operating-systems">
  2134. <h3>Unsupported Operating Systems<a class="headerlink" href="#unsupported-operating-systems" title="Link to this heading">¶</a></h3>
  2135. <p>Windows XP is no longer supported by Microsoft, thus, per <span class="target" id="index-48"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/"><strong>PEP 11</strong></a>, CPython
  2136. 3.5 is no longer officially supported on this OS.</p>
  2137. </section>
  2138. <section id="deprecated-python-modules-functions-and-methods">
  2139. <h3>Deprecated Python modules, functions and methods<a class="headerlink" href="#deprecated-python-modules-functions-and-methods" title="Link to this heading">¶</a></h3>
  2140. <p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">formatter</span></code> module has now graduated to full deprecation and is still
  2141. slated for removal in Python 3.6.</p>
  2142. <p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.async()</span></code> function is deprecated in favor of
  2143. <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>.</p>
  2144. <p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code> module has in the past always decoded the DATA portion of
  2145. email messages using the <code class="docutils literal notranslate"><span class="pre">utf-8</span></code> codec. This can now be controlled by the
  2146. new <em>decode_data</em> keyword to <code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code>. The default value is
  2147. <code class="docutils literal notranslate"><span class="pre">True</span></code>, but this default is deprecated. Specify the <em>decode_data</em> keyword
  2148. with an appropriate value to avoid the deprecation warning.</p>
  2149. <p>Directly assigning values to the <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.key" title="http.cookies.Morsel.key"><code class="xref py py-attr docutils literal notranslate"><span class="pre">key</span></code></a>,
  2150. <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.value" title="http.cookies.Morsel.value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">value</span></code></a> and
  2151. <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.coded_value" title="http.cookies.Morsel.coded_value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">coded_value</span></code></a> of <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel" title="http.cookies.Morsel"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.cookies.Morsel</span></code></a>
  2152. objects is deprecated. Use the <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.set" title="http.cookies.Morsel.set"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set()</span></code></a> method
  2153. instead. In addition, the undocumented <em>LegalChars</em> parameter of
  2154. <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.set" title="http.cookies.Morsel.set"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set()</span></code></a> is deprecated, and is now ignored.</p>
  2155. <p>Passing a format string as keyword argument <em>format_string</em> to the
  2156. <a class="reference internal" href="../library/string.html#string.Formatter.format" title="string.Formatter.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">format()</span></code></a> method of the <a class="reference internal" href="../library/string.html#string.Formatter" title="string.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">string.Formatter</span></code></a>
  2157. class has been deprecated.
  2158. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23671">bpo-23671</a>.)</p>
  2159. <p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">platform.dist()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">platform.linux_distribution()</span></code> functions
  2160. are now deprecated. Linux distributions use too many different ways of
  2161. describing themselves, so the functionality is left to a package.
  2162. (Contributed by Vajrasky Kok and Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1322">bpo-1322</a>.)</p>
  2163. <p>The previously undocumented <code class="docutils literal notranslate"><span class="pre">from_function</span></code> and <code class="docutils literal notranslate"><span class="pre">from_builtin</span></code> methods of
  2164. <a class="reference internal" href="../library/inspect.html#inspect.Signature" title="inspect.Signature"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.Signature</span></code></a> are deprecated. Use the new
  2165. <a class="reference internal" href="../library/inspect.html#inspect.Signature.from_callable" title="inspect.Signature.from_callable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Signature.from_callable()</span></code></a>
  2166. method instead. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24248">bpo-24248</a>.)</p>
  2167. <p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getargspec()</span></code> function is deprecated and scheduled to be
  2168. removed in Python 3.6. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20438">bpo-20438</a> for details.)</p>
  2169. <p>The <a class="reference internal" href="../library/inspect.html#module-inspect" title="inspect: Extract information and source code from live objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">inspect</span></code></a> <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">getfullargspec()</span></code></a>,
  2170. <a class="reference internal" href="../library/inspect.html#inspect.getcallargs" title="inspect.getcallargs"><code class="xref py py-func docutils literal notranslate"><span class="pre">getcallargs()</span></code></a>, and <code class="xref py py-func docutils literal notranslate"><span class="pre">formatargspec()</span></code> functions are
  2171. deprecated in favor of the <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> API. (Contributed by Yury
  2172. Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20438">bpo-20438</a>.)</p>
  2173. <p><a class="reference internal" href="../library/inspect.html#inspect.getargvalues" title="inspect.getargvalues"><code class="xref py py-func docutils literal notranslate"><span class="pre">getargvalues()</span></code></a> and <a class="reference internal" href="../library/inspect.html#inspect.formatargvalues" title="inspect.formatargvalues"><code class="xref py py-func docutils literal notranslate"><span class="pre">formatargvalues()</span></code></a> functions
  2174. were inadvertently marked as deprecated with the release of Python 3.5.0.</p>
  2175. <p>Use of <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> flag with str patterns or <a class="reference internal" href="../library/re.html#re.ASCII" title="re.ASCII"><code class="xref py py-const docutils literal notranslate"><span class="pre">re.ASCII</span></code></a> is now
  2176. deprecated. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22407">bpo-22407</a>.)</p>
  2177. <p>Use of unrecognized special sequences consisting of <code class="docutils literal notranslate"><span class="pre">'\'</span></code> and an ASCII letter
  2178. in regular expression patterns and replacement patterns now raises a
  2179. deprecation warning and will be forbidden in Python 3.6.
  2180. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23622">bpo-23622</a>.)</p>
  2181. <p>The undocumented and unofficial <em>use_load_tests</em> default argument of the
  2182. <a class="reference internal" href="../library/unittest.html#unittest.TestLoader.loadTestsFromModule" title="unittest.TestLoader.loadTestsFromModule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestLoader.loadTestsFromModule()</span></code></a> method now is
  2183. deprecated and ignored.
  2184. (Contributed by Robert Collins and Barry A. Warsaw in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16662">bpo-16662</a>.)</p>
  2185. </section>
  2186. </section>
  2187. <section id="removed">
  2188. <h2>Removed<a class="headerlink" href="#removed" title="Link to this heading">¶</a></h2>
  2189. <section id="api-and-feature-removals">
  2190. <h3>API and Feature Removals<a class="headerlink" href="#api-and-feature-removals" title="Link to this heading">¶</a></h3>
  2191. <p>The following obsolete and previously deprecated APIs and features have been
  2192. removed:</p>
  2193. <ul class="simple">
  2194. <li><p>The <code class="docutils literal notranslate"><span class="pre">__version__</span></code> attribute has been dropped from the email package. The
  2195. email code hasn’t been shipped separately from the stdlib for a long time,
  2196. and the <code class="docutils literal notranslate"><span class="pre">__version__</span></code> string was not updated in the last few releases.</p></li>
  2197. <li><p>The internal <code class="docutils literal notranslate"><span class="pre">Netrc</span></code> class in the <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> module was deprecated in
  2198. 3.4, and has now been removed.
  2199. (Contributed by Matt Chaput in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6623">bpo-6623</a>.)</p></li>
  2200. <li><p>The concept of <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files has been removed.</p></li>
  2201. <li><p>The JoinableQueue class in the provisional <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> module was
  2202. deprecated in 3.4.4 and is now removed.
  2203. (Contributed by A. Jesse Jiryu Davis in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23464">bpo-23464</a>.)</p></li>
  2204. </ul>
  2205. </section>
  2206. </section>
  2207. <section id="porting-to-python-3-5">
  2208. <h2>Porting to Python 3.5<a class="headerlink" href="#porting-to-python-3-5" title="Link to this heading">¶</a></h2>
  2209. <p>This section lists previously described changes and other bugfixes
  2210. that may require changes to your code.</p>
  2211. <section id="changes-in-python-behavior">
  2212. <h3>Changes in Python behavior<a class="headerlink" href="#changes-in-python-behavior" title="Link to this heading">¶</a></h3>
  2213. <ul>
  2214. <li><p>Due to an oversight, earlier Python versions erroneously accepted the
  2215. following syntax:</p>
  2216. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">f</span><span class="p">(</span><span class="mi">1</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span>
  2217. <span class="n">f</span><span class="p">(</span><span class="mi">1</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
  2218. </pre></div>
  2219. </div>
  2220. <p>Python 3.5 now correctly raises 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>, as generator
  2221. expressions must be put in parentheses if not a sole argument to a function.</p>
  2222. </li>
  2223. </ul>
  2224. </section>
  2225. <section id="changes-in-the-python-api">
  2226. <h3>Changes in the Python API<a class="headerlink" href="#changes-in-the-python-api" title="Link to this heading">¶</a></h3>
  2227. <ul class="simple">
  2228. <li><p><span class="target" id="index-49"></span><a class="pep reference external" href="https://peps.python.org/pep-0475/"><strong>PEP 475</strong></a>: System calls are now retried when interrupted by a signal instead
  2229. of raising <a class="reference internal" href="../library/exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a> if the Python signal handler does not
  2230. raise an exception.</p></li>
  2231. <li><p>Before Python 3.5, 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> object was considered to be false
  2232. if it represented midnight in UTC. This behavior was considered obscure and
  2233. error-prone and has been removed in Python 3.5. See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13936">bpo-13936</a> for full
  2234. details.</p></li>
  2235. <li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLSocket.send()</span></code> method now raises either
  2236. <a class="reference internal" href="../library/ssl.html#ssl.SSLWantReadError" title="ssl.SSLWantReadError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ssl.SSLWantReadError</span></code></a> or <a class="reference internal" href="../library/ssl.html#ssl.SSLWantWriteError" title="ssl.SSLWantWriteError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ssl.SSLWantWriteError</span></code></a>
  2237. on a non-blocking socket if the operation would block. Previously,
  2238. it would return <code class="docutils literal notranslate"><span class="pre">0</span></code>. (Contributed by Nikolaus Rath in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20951">bpo-20951</a>.)</p></li>
  2239. <li><p>The <code class="docutils literal notranslate"><span class="pre">__name__</span></code> attribute of generators is now set from the function name,
  2240. instead of being set from the code name. Use <code class="docutils literal notranslate"><span class="pre">gen.gi_code.co_name</span></code> to
  2241. retrieve the code name. Generators also have a new <code class="docutils literal notranslate"><span class="pre">__qualname__</span></code>
  2242. attribute, the qualified name, which is now used for the representation
  2243. of a generator (<code class="docutils literal notranslate"><span class="pre">repr(gen)</span></code>).
  2244. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21205">bpo-21205</a>.)</p></li>
  2245. <li><p>The deprecated “strict” mode and argument of <a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a>,
  2246. <code class="xref py py-meth docutils literal notranslate"><span class="pre">HTMLParser.error()</span></code>, and the <code class="xref py py-exc docutils literal notranslate"><span class="pre">HTMLParserError</span></code> exception have been
  2247. removed. (Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15114">bpo-15114</a>.)
  2248. The <em>convert_charrefs</em> argument of <a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> is
  2249. now <code class="docutils literal notranslate"><span class="pre">True</span></code> by default. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21047">bpo-21047</a>.)</p></li>
  2250. <li><p>Although it is not formally part of the API, it is worth noting for porting
  2251. purposes (ie: fixing tests) that error messages that were previously of the
  2252. form “‘sometype’ does not support the buffer protocol” are now of the form “a
  2253. <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a> is required, not ‘sometype’”.
  2254. (Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16518">bpo-16518</a>.)</p></li>
  2255. <li><p>If the current directory is set to a directory that no longer exists then
  2256. <a class="reference internal" href="../library/exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a> will no longer be raised and instead
  2257. <a class="reference internal" href="../library/importlib.html#importlib.machinery.FileFinder.find_spec" title="importlib.machinery.FileFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find_spec()</span></code></a> will return <code class="docutils literal notranslate"><span class="pre">None</span></code>
  2258. <strong>without</strong> caching <code class="docutils literal notranslate"><span class="pre">None</span></code> in <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a>, which is
  2259. different than the typical case (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22834">bpo-22834</a>).</p></li>
  2260. <li><p>HTTP status code and messages from <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> and <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>
  2261. were refactored into a common <a class="reference internal" href="../library/http.html#http.HTTPStatus" title="http.HTTPStatus"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPStatus</span></code></a> enum. The values in
  2262. <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> and <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> remain available for backwards
  2263. compatibility. (Contributed by Demian Brecht in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21793">bpo-21793</a>.)</p></li>
  2264. <li><p>When an import loader defines <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.Loader.exec_module()</span></code>
  2265. it is now expected to also define
  2266. <code class="xref py py-meth docutils literal notranslate"><span class="pre">create_module()</span></code> (raises a
  2267. <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> now, will be an error in Python 3.6). If the loader
  2268. inherits from <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader" title="importlib.abc.Loader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.Loader</span></code></a> then there is nothing to do, else
  2269. simply define <code class="xref py py-meth docutils literal notranslate"><span class="pre">create_module()</span></code> to return
  2270. <code class="docutils literal notranslate"><span class="pre">None</span></code>. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23014">bpo-23014</a>.)</p></li>
  2271. <li><p>The <a class="reference internal" href="../library/re.html#re.split" title="re.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.split()</span></code></a> function always ignored empty pattern matches, so the
  2272. <code class="docutils literal notranslate"><span class="pre">&quot;x*&quot;</span></code> pattern worked the same as <code class="docutils literal notranslate"><span class="pre">&quot;x+&quot;</span></code>, and the <code class="docutils literal notranslate"><span class="pre">&quot;\b&quot;</span></code> pattern never
  2273. worked. Now <a class="reference internal" href="../library/re.html#re.split" title="re.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.split()</span></code></a> raises a warning if the pattern could match
  2274. an empty string. For compatibility, use patterns that never match an empty
  2275. string (e.g. <code class="docutils literal notranslate"><span class="pre">&quot;x+&quot;</span></code> instead of <code class="docutils literal notranslate"><span class="pre">&quot;x*&quot;</span></code>). Patterns that could only match
  2276. an empty string (such as <code class="docutils literal notranslate"><span class="pre">&quot;\b&quot;</span></code>) now raise an error.
  2277. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22818">bpo-22818</a>.)</p></li>
  2278. <li><p>The <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel" title="http.cookies.Morsel"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.cookies.Morsel</span></code></a> dict-like interface has been made self
  2279. consistent: morsel comparison now takes the <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.key" title="http.cookies.Morsel.key"><code class="xref py py-attr docutils literal notranslate"><span class="pre">key</span></code></a>
  2280. and <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.value" title="http.cookies.Morsel.value"><code class="xref py py-attr docutils literal notranslate"><span class="pre">value</span></code></a> into account,
  2281. <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.copy" title="http.cookies.Morsel.copy"><code class="xref py py-meth docutils literal notranslate"><span class="pre">copy()</span></code></a> now results in a
  2282. <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel" title="http.cookies.Morsel"><code class="xref py py-class docutils literal notranslate"><span class="pre">Morsel</span></code></a> instance rather than a <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>, and
  2283. <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.update" title="http.cookies.Morsel.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> will now raise an exception if any of the
  2284. keys in the update dictionary are invalid. In addition, the undocumented
  2285. <em>LegalChars</em> parameter of <a class="reference internal" href="../library/http.cookies.html#http.cookies.Morsel.set" title="http.cookies.Morsel.set"><code class="xref py py-func docutils literal notranslate"><span class="pre">set()</span></code></a> is deprecated and
  2286. is now ignored. (Contributed by Demian Brecht in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=2211">bpo-2211</a>.)</p></li>
  2287. <li><p><span class="target" id="index-50"></span><a class="pep reference external" href="https://peps.python.org/pep-0488/"><strong>PEP 488</strong></a> has removed <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files from Python and introduced the optional
  2288. <code class="docutils literal notranslate"><span class="pre">opt-</span></code> tag in <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file names. The
  2289. <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> has gained an <em>optimization</em>
  2290. parameter to help control the <code class="docutils literal notranslate"><span class="pre">opt-</span></code> tag. Because of this, the
  2291. <em>debug_override</em> parameter of the function is now deprecated. <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files
  2292. are also no longer supported as a file argument to the Python interpreter and
  2293. thus serve no purpose when distributed on their own (i.e. sourceless code
  2294. distribution). Due to the fact that the magic number for bytecode has changed
  2295. in Python 3.5, all old <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files from previous versions of Python are
  2296. invalid regardless of this PEP.</p></li>
  2297. <li><p>The <a class="reference internal" href="../library/socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socket</span></code></a> module now exports the <a class="reference internal" href="../library/socket.html#socket.CAN_RAW_FD_FRAMES" title="socket.CAN_RAW_FD_FRAMES"><code class="xref py py-const docutils literal notranslate"><span class="pre">CAN_RAW_FD_FRAMES</span></code></a>
  2298. constant on linux 3.6 and greater.</p></li>
  2299. <li><p>The <a class="reference internal" href="../library/ssl.html#ssl.cert_time_to_seconds" title="ssl.cert_time_to_seconds"><code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.cert_time_to_seconds()</span></code></a> function now interprets the input time
  2300. as UTC and not as local time, per <span class="target" id="index-51"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc5280.html"><strong>RFC 5280</strong></a>. Additionally, the return
  2301. value is always an <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>. (Contributed by Akira Li in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19940">bpo-19940</a>.)</p></li>
  2302. <li><p>The <code class="docutils literal notranslate"><span class="pre">pygettext.py</span></code> Tool now uses the standard +NNNN format for timezones in
  2303. the POT-Creation-Date header.</p></li>
  2304. <li><p>The <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> module now uses <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> instead of the previous
  2305. module-level <code class="xref py py-data docutils literal notranslate"><span class="pre">stderr</span></code> variable for debug output. If your (test)
  2306. program depends on patching the module-level variable to capture the debug
  2307. output, you will need to update it to capture sys.stderr instead.</p></li>
  2308. <li><p>The <a class="reference internal" href="../library/stdtypes.html#str.startswith" title="str.startswith"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.startswith()</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#str.endswith" title="str.endswith"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.endswith()</span></code></a> methods no longer return
  2309. <code class="docutils literal notranslate"><span class="pre">True</span></code> when finding the empty string and the indexes are completely out of
  2310. range. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24284">bpo-24284</a>.)</p></li>
  2311. <li><p>The <a class="reference internal" href="../library/inspect.html#inspect.getdoc" title="inspect.getdoc"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getdoc()</span></code></a> function now returns documentation strings
  2312. inherited from base classes. Documentation strings no longer need to be
  2313. duplicated if the inherited documentation is appropriate. To suppress an
  2314. inherited string, an empty string must be specified (or the documentation
  2315. may be filled in). This change affects the output of the <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>
  2316. module and the <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> function.
  2317. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15582">bpo-15582</a>.)</p></li>
  2318. <li><p>Nested <a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.partial()</span></code></a> calls are now flattened. If you were
  2319. relying on the previous behavior, you can now either add an attribute to a
  2320. <a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.partial()</span></code></a> object or you can create a subclass of
  2321. <a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.partial()</span></code></a>.
  2322. (Contributed by Alexander Belopolsky in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=7830">bpo-7830</a>.)</p></li>
  2323. </ul>
  2324. </section>
  2325. <section id="changes-in-the-c-api">
  2326. <h3>Changes in the C API<a class="headerlink" href="#changes-in-the-c-api" title="Link to this heading">¶</a></h3>
  2327. <ul class="simple">
  2328. <li><p>The undocumented <code class="xref c c-member docutils literal notranslate"><span class="pre">format</span></code> member of the
  2329. (non-public) <code class="xref c c-type docutils literal notranslate"><span class="pre">PyMemoryViewObject</span></code> structure has been removed.
  2330. All extensions relying on the relevant parts in <code class="docutils literal notranslate"><span class="pre">memoryobject.h</span></code>
  2331. must be rebuilt.</p></li>
  2332. <li><p>The <code class="xref c c-type docutils literal notranslate"><span class="pre">PyMemAllocator</span></code> structure was renamed to
  2333. <a class="reference internal" href="../c-api/memory.html#c.PyMemAllocatorEx" title="PyMemAllocatorEx"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyMemAllocatorEx</span></code></a> and a new <code class="docutils literal notranslate"><span class="pre">calloc</span></code> field was added.</p></li>
  2334. <li><p>Removed non-documented macro <code class="xref c c-macro docutils literal notranslate"><span class="pre">PyObject_REPR()</span></code> which leaked references.
  2335. Use format character <code class="docutils literal notranslate"><span class="pre">%R</span></code> in <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a>-like functions
  2336. to format the <a class="reference internal" href="../library/functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a> of the object.
  2337. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22453">bpo-22453</a>.)</p></li>
  2338. <li><p>Because the lack of the <code class="xref py py-attr docutils literal notranslate"><span class="pre">__module__</span></code> attribute breaks pickling and
  2339. introspection, a deprecation warning is now raised for builtin types without
  2340. the <code class="xref py py-attr docutils literal notranslate"><span class="pre">__module__</span></code> attribute. This would be an AttributeError in
  2341. the future.
  2342. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20204">bpo-20204</a>.)</p></li>
  2343. <li><p>As part of the <span class="target" id="index-52"></span><a class="pep reference external" href="https://peps.python.org/pep-0492/"><strong>PEP 492</strong></a> implementation, the <code class="docutils literal notranslate"><span class="pre">tp_reserved</span></code> slot of
  2344. <a class="reference internal" href="../c-api/type.html#c.PyTypeObject" title="PyTypeObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyTypeObject</span></code></a> was replaced with a
  2345. <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_as_async" title="PyTypeObject.tp_as_async"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_as_async</span></code></a> slot. Refer to <a class="reference internal" href="../c-api/coro.html#coro-objects"><span class="std std-ref">Coroutine Objects</span></a> for
  2346. new types, structures and functions.</p></li>
  2347. </ul>
  2348. </section>
  2349. </section>
  2350. <section id="notable-changes-in-python-3-5-4">
  2351. <h2>Notable changes in Python 3.5.4<a class="headerlink" href="#notable-changes-in-python-3-5-4" title="Link to this heading">¶</a></h2>
  2352. <section id="new-make-regen-all-build-target">
  2353. <h3>New <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> build target<a class="headerlink" href="#new-make-regen-all-build-target" title="Link to this heading">¶</a></h3>
  2354. <p>To simplify cross-compilation, and to ensure that CPython can reliably be
  2355. compiled without requiring an existing version of Python to already be
  2356. available, the autotools-based build system no longer attempts to implicitly
  2357. recompile generated files based on file modification times.</p>
  2358. <p>Instead, a new <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> command has been added to force regeneration
  2359. of these files when desired (e.g. after an initial version of Python has
  2360. already been built based on the pregenerated versions).</p>
  2361. <p>More selective regeneration targets are also defined - see
  2362. <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Makefile.pre.in">Makefile.pre.in</a> for details.</p>
  2363. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23404">bpo-23404</a>.)</p>
  2364. <div class="versionadded">
  2365. <p><span class="versionmodified added">New in version 3.5.4.</span></p>
  2366. </div>
  2367. </section>
  2368. <section id="removal-of-make-touch-build-target">
  2369. <h3>Removal of <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> build target<a class="headerlink" href="#removal-of-make-touch-build-target" title="Link to this heading">¶</a></h3>
  2370. <p>The <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> build target previously used to request implicit regeneration
  2371. of generated files by updating their modification times has been removed.</p>
  2372. <p>It has been replaced by the new <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> target.</p>
  2373. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23404">bpo-23404</a>.)</p>
  2374. <div class="versionchanged">
  2375. <p><span class="versionmodified changed">Changed in version 3.5.4.</span></p>
  2376. </div>
  2377. </section>
  2378. </section>
  2379. </section>
  2380. <div class="clearer"></div>
  2381. </div>
  2382. </div>
  2383. </div>
  2384. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  2385. <div class="sphinxsidebarwrapper">
  2386. <div>
  2387. <h3><a href="../contents.html">Table of Contents</a></h3>
  2388. <ul>
  2389. <li><a class="reference internal" href="#">What’s New In Python 3.5</a><ul>
  2390. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  2391. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  2392. <li><a class="reference internal" href="#pep-492-coroutines-with-async-and-await-syntax">PEP 492 - Coroutines with async and await syntax</a></li>
  2393. <li><a class="reference internal" href="#pep-465-a-dedicated-infix-operator-for-matrix-multiplication">PEP 465 - A dedicated infix operator for matrix multiplication</a></li>
  2394. <li><a class="reference internal" href="#pep-448-additional-unpacking-generalizations">PEP 448 - Additional Unpacking Generalizations</a></li>
  2395. <li><a class="reference internal" href="#pep-461-percent-formatting-support-for-bytes-and-bytearray">PEP 461 - percent formatting support for bytes and bytearray</a></li>
  2396. <li><a class="reference internal" href="#pep-484-type-hints">PEP 484 - Type Hints</a></li>
  2397. <li><a class="reference internal" href="#pep-471-os-scandir-function-a-better-and-faster-directory-iterator">PEP 471 - os.scandir() function – a better and faster directory iterator</a></li>
  2398. <li><a class="reference internal" href="#pep-475-retry-system-calls-failing-with-eintr">PEP 475: Retry system calls failing with EINTR</a></li>
  2399. <li><a class="reference internal" href="#pep-479-change-stopiteration-handling-inside-generators">PEP 479: Change StopIteration handling inside generators</a></li>
  2400. <li><a class="reference internal" href="#pep-485-a-function-for-testing-approximate-equality">PEP 485: A function for testing approximate equality</a></li>
  2401. <li><a class="reference internal" href="#pep-486-make-the-python-launcher-aware-of-virtual-environments">PEP 486: Make the Python Launcher aware of virtual environments</a></li>
  2402. <li><a class="reference internal" href="#pep-488-elimination-of-pyo-files">PEP 488: Elimination of PYO files</a></li>
  2403. <li><a class="reference internal" href="#pep-489-multi-phase-extension-module-initialization">PEP 489: Multi-phase extension module initialization</a></li>
  2404. </ul>
  2405. </li>
  2406. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  2407. <li><a class="reference internal" href="#new-modules">New Modules</a><ul>
  2408. <li><a class="reference internal" href="#typing">typing</a></li>
  2409. <li><a class="reference internal" href="#zipapp">zipapp</a></li>
  2410. </ul>
  2411. </li>
  2412. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  2413. <li><a class="reference internal" href="#argparse">argparse</a></li>
  2414. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  2415. <li><a class="reference internal" href="#bz2">bz2</a></li>
  2416. <li><a class="reference internal" href="#cgi">cgi</a></li>
  2417. <li><a class="reference internal" href="#cmath">cmath</a></li>
  2418. <li><a class="reference internal" href="#code">code</a></li>
  2419. <li><a class="reference internal" href="#collections">collections</a></li>
  2420. <li><a class="reference internal" href="#collections-abc">collections.abc</a></li>
  2421. <li><a class="reference internal" href="#compileall">compileall</a></li>
  2422. <li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li>
  2423. <li><a class="reference internal" href="#configparser">configparser</a></li>
  2424. <li><a class="reference internal" href="#contextlib">contextlib</a></li>
  2425. <li><a class="reference internal" href="#csv">csv</a></li>
  2426. <li><a class="reference internal" href="#curses">curses</a></li>
  2427. <li><a class="reference internal" href="#dbm">dbm</a></li>
  2428. <li><a class="reference internal" href="#difflib">difflib</a></li>
  2429. <li><a class="reference internal" href="#distutils">distutils</a></li>
  2430. <li><a class="reference internal" href="#doctest">doctest</a></li>
  2431. <li><a class="reference internal" href="#email">email</a></li>
  2432. <li><a class="reference internal" href="#enum">enum</a></li>
  2433. <li><a class="reference internal" href="#faulthandler">faulthandler</a></li>
  2434. <li><a class="reference internal" href="#functools">functools</a></li>
  2435. <li><a class="reference internal" href="#glob">glob</a></li>
  2436. <li><a class="reference internal" href="#gzip">gzip</a></li>
  2437. <li><a class="reference internal" href="#heapq">heapq</a></li>
  2438. <li><a class="reference internal" href="#http">http</a></li>
  2439. <li><a class="reference internal" href="#http-client">http.client</a></li>
  2440. <li><a class="reference internal" href="#idlelib-and-idle">idlelib and IDLE</a></li>
  2441. <li><a class="reference internal" href="#imaplib">imaplib</a></li>
  2442. <li><a class="reference internal" href="#imghdr">imghdr</a></li>
  2443. <li><a class="reference internal" href="#importlib">importlib</a></li>
  2444. <li><a class="reference internal" href="#inspect">inspect</a></li>
  2445. <li><a class="reference internal" href="#io">io</a></li>
  2446. <li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
  2447. <li><a class="reference internal" href="#json">json</a></li>
  2448. <li><a class="reference internal" href="#linecache">linecache</a></li>
  2449. <li><a class="reference internal" href="#locale">locale</a></li>
  2450. <li><a class="reference internal" href="#logging">logging</a></li>
  2451. <li><a class="reference internal" href="#lzma">lzma</a></li>
  2452. <li><a class="reference internal" href="#math">math</a></li>
  2453. <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
  2454. <li><a class="reference internal" href="#operator">operator</a></li>
  2455. <li><a class="reference internal" href="#os">os</a></li>
  2456. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  2457. <li><a class="reference internal" href="#pickle">pickle</a></li>
  2458. <li><a class="reference internal" href="#poplib">poplib</a></li>
  2459. <li><a class="reference internal" href="#re">re</a></li>
  2460. <li><a class="reference internal" href="#readline">readline</a></li>
  2461. <li><a class="reference internal" href="#selectors">selectors</a></li>
  2462. <li><a class="reference internal" href="#shutil">shutil</a></li>
  2463. <li><a class="reference internal" href="#signal">signal</a></li>
  2464. <li><a class="reference internal" href="#smtpd">smtpd</a></li>
  2465. <li><a class="reference internal" href="#smtplib">smtplib</a></li>
  2466. <li><a class="reference internal" href="#sndhdr">sndhdr</a></li>
  2467. <li><a class="reference internal" href="#socket">socket</a></li>
  2468. <li><a class="reference internal" href="#ssl">ssl</a><ul>
  2469. <li><a class="reference internal" href="#memory-bio-support">Memory BIO Support</a></li>
  2470. <li><a class="reference internal" href="#application-layer-protocol-negotiation-support">Application-Layer Protocol Negotiation Support</a></li>
  2471. <li><a class="reference internal" href="#other-changes">Other Changes</a></li>
  2472. </ul>
  2473. </li>
  2474. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  2475. <li><a class="reference internal" href="#subprocess">subprocess</a></li>
  2476. <li><a class="reference internal" href="#sys">sys</a></li>
  2477. <li><a class="reference internal" href="#sysconfig">sysconfig</a></li>
  2478. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  2479. <li><a class="reference internal" href="#threading">threading</a></li>
  2480. <li><a class="reference internal" href="#time">time</a></li>
  2481. <li><a class="reference internal" href="#timeit">timeit</a></li>
  2482. <li><a class="reference internal" href="#tkinter">tkinter</a></li>
  2483. <li><a class="reference internal" href="#traceback">traceback</a></li>
  2484. <li><a class="reference internal" href="#types">types</a></li>
  2485. <li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
  2486. <li><a class="reference internal" href="#unittest">unittest</a></li>
  2487. <li><a class="reference internal" href="#unittest-mock">unittest.mock</a></li>
  2488. <li><a class="reference internal" href="#urllib">urllib</a></li>
  2489. <li><a class="reference internal" href="#wsgiref">wsgiref</a></li>
  2490. <li><a class="reference internal" href="#xmlrpc">xmlrpc</a></li>
  2491. <li><a class="reference internal" href="#xml-sax">xml.sax</a></li>
  2492. <li><a class="reference internal" href="#zipfile">zipfile</a></li>
  2493. </ul>
  2494. </li>
  2495. <li><a class="reference internal" href="#other-module-level-changes">Other module-level changes</a></li>
  2496. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  2497. <li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
  2498. <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
  2499. <li><a class="reference internal" href="#new-keywords">New Keywords</a></li>
  2500. <li><a class="reference internal" href="#deprecated-python-behavior">Deprecated Python Behavior</a></li>
  2501. <li><a class="reference internal" href="#unsupported-operating-systems">Unsupported Operating Systems</a></li>
  2502. <li><a class="reference internal" href="#deprecated-python-modules-functions-and-methods">Deprecated Python modules, functions and methods</a></li>
  2503. </ul>
  2504. </li>
  2505. <li><a class="reference internal" href="#removed">Removed</a><ul>
  2506. <li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
  2507. </ul>
  2508. </li>
  2509. <li><a class="reference internal" href="#porting-to-python-3-5">Porting to Python 3.5</a><ul>
  2510. <li><a class="reference internal" href="#changes-in-python-behavior">Changes in Python behavior</a></li>
  2511. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  2512. <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
  2513. </ul>
  2514. </li>
  2515. <li><a class="reference internal" href="#notable-changes-in-python-3-5-4">Notable changes in Python 3.5.4</a><ul>
  2516. <li><a class="reference internal" href="#new-make-regen-all-build-target">New <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> build target</a></li>
  2517. <li><a class="reference internal" href="#removal-of-make-touch-build-target">Removal of <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> build target</a></li>
  2518. </ul>
  2519. </li>
  2520. </ul>
  2521. </li>
  2522. </ul>
  2523. </div>
  2524. <div>
  2525. <h4>Previous topic</h4>
  2526. <p class="topless"><a href="3.6.html"
  2527. title="previous chapter">What’s New In Python 3.6</a></p>
  2528. </div>
  2529. <div>
  2530. <h4>Next topic</h4>
  2531. <p class="topless"><a href="3.4.html"
  2532. title="next chapter">What’s New In Python 3.4</a></p>
  2533. </div>
  2534. <div role="note" aria-label="source link">
  2535. <h3>This Page</h3>
  2536. <ul class="this-page-menu">
  2537. <li><a href="../bugs.html">Report a Bug</a></li>
  2538. <li>
  2539. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.5.rst"
  2540. rel="nofollow">Show Source
  2541. </a>
  2542. </li>
  2543. </ul>
  2544. </div>
  2545. </div>
  2546. <div id="sidebarbutton" title="Collapse sidebar">
  2547. <span>«</span>
  2548. </div>
  2549. </div>
  2550. <div class="clearer"></div>
  2551. </div>
  2552. <div class="related" role="navigation" aria-label="related navigation">
  2553. <h3>Navigation</h3>
  2554. <ul>
  2555. <li class="right" style="margin-right: 10px">
  2556. <a href="../genindex.html" title="General Index"
  2557. >index</a></li>
  2558. <li class="right" >
  2559. <a href="../py-modindex.html" title="Python Module Index"
  2560. >modules</a> |</li>
  2561. <li class="right" >
  2562. <a href="3.4.html" title="What’s New In Python 3.4"
  2563. >next</a> |</li>
  2564. <li class="right" >
  2565. <a href="3.6.html" title="What’s New In Python 3.6"
  2566. >previous</a> |</li>
  2567. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  2568. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  2569. <li class="switchers">
  2570. <div class="language_switcher_placeholder"></div>
  2571. <div class="version_switcher_placeholder"></div>
  2572. </li>
  2573. <li>
  2574. </li>
  2575. <li id="cpython-language-and-version">
  2576. <a href="../index.html">3.12.3 Documentation</a> &#187;
  2577. </li>
  2578. <li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> &#187;</li>
  2579. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.5</a></li>
  2580. <li class="right">
  2581. <div class="inline-search" role="search">
  2582. <form class="inline-search" action="../search.html" method="get">
  2583. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  2584. <input type="submit" value="Go" />
  2585. </form>
  2586. </div>
  2587. |
  2588. </li>
  2589. <li class="right">
  2590. <label class="theme-selector-label">
  2591. Theme
  2592. <select class="theme-selector" oninput="activateTheme(this.value)">
  2593. <option value="auto" selected>Auto</option>
  2594. <option value="light">Light</option>
  2595. <option value="dark">Dark</option>
  2596. </select>
  2597. </label> |</li>
  2598. </ul>
  2599. </div>
  2600. <div class="footer">
  2601. &copy;
  2602. <a href="../copyright.html">
  2603. Copyright
  2604. </a>
  2605. 2001-2024, Python Software Foundation.
  2606. <br />
  2607. This page is licensed under the Python Software Foundation License Version 2.
  2608. <br />
  2609. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  2610. <br />
  2611. See <a href="/license.html">History and License</a> for more information.<br />
  2612. <br />
  2613. The Python Software Foundation is a non-profit corporation.
  2614. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  2615. <br />
  2616. <br />
  2617. Last updated on Apr 09, 2024 (13:47 UTC).
  2618. <a href="/bugs.html">Found a bug</a>?
  2619. <br />
  2620. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  2621. </div>
  2622. </body>
  2623. </html>
上海开阖软件有限公司 沪ICP备12045867号-1