gooderp18绿色标准版
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

2502 行
305KB

  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.8" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/whatsnew/3.8.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Editor, Raymond Hettinger,. This article explains the new features in Python 3.8, compared to 3.7. Python 3.8 was released on October 14, 2019. For full details, see the changelog. Summary – Releas..." />
  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="Editor, Raymond Hettinger,. This article explains the new features in Python 3.8, compared to 3.7. Python 3.8 was released on October 14, 2019. For full details, see the changelog. Summary – Releas..." />
  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.8 &#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.7" href="3.7.html" />
  33. <link rel="prev" title="What’s New In Python 3.9" href="3.9.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/whatsnew/3.8.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.8</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="#assignment-expressions">Assignment expressions</a></li>
  89. <li><a class="reference internal" href="#positional-only-parameters">Positional-only parameters</a></li>
  90. <li><a class="reference internal" href="#parallel-filesystem-cache-for-compiled-bytecode-files">Parallel filesystem cache for compiled bytecode files</a></li>
  91. <li><a class="reference internal" href="#debug-build-uses-the-same-abi-as-release-build">Debug build uses the same ABI as release build</a></li>
  92. <li><a class="reference internal" href="#f-strings-support-for-self-documenting-expressions-and-debugging">f-strings support <code class="docutils literal notranslate"><span class="pre">=</span></code> for self-documenting expressions and debugging</a></li>
  93. <li><a class="reference internal" href="#pep-578-python-runtime-audit-hooks">PEP 578: Python Runtime Audit Hooks</a></li>
  94. <li><a class="reference internal" href="#pep-587-python-initialization-configuration">PEP 587: Python Initialization Configuration</a></li>
  95. <li><a class="reference internal" href="#pep-590-vectorcall-a-fast-calling-protocol-for-cpython">PEP 590: Vectorcall: a fast calling protocol for CPython</a></li>
  96. <li><a class="reference internal" href="#pickle-protocol-5-with-out-of-band-data-buffers">Pickle protocol 5 with out-of-band data buffers</a></li>
  97. </ul>
  98. </li>
  99. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  100. <li><a class="reference internal" href="#new-modules">New Modules</a></li>
  101. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  102. <li><a class="reference internal" href="#ast">ast</a></li>
  103. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  104. <li><a class="reference internal" href="#builtins">builtins</a></li>
  105. <li><a class="reference internal" href="#collections">collections</a></li>
  106. <li><a class="reference internal" href="#cprofile">cProfile</a></li>
  107. <li><a class="reference internal" href="#csv">csv</a></li>
  108. <li><a class="reference internal" href="#curses">curses</a></li>
  109. <li><a class="reference internal" href="#ctypes">ctypes</a></li>
  110. <li><a class="reference internal" href="#datetime">datetime</a></li>
  111. <li><a class="reference internal" href="#functools">functools</a></li>
  112. <li><a class="reference internal" href="#gc">gc</a></li>
  113. <li><a class="reference internal" href="#gettext">gettext</a></li>
  114. <li><a class="reference internal" href="#gzip">gzip</a></li>
  115. <li><a class="reference internal" href="#idle-and-idlelib">IDLE and idlelib</a></li>
  116. <li><a class="reference internal" href="#inspect">inspect</a></li>
  117. <li><a class="reference internal" href="#io">io</a></li>
  118. <li><a class="reference internal" href="#itertools">itertools</a></li>
  119. <li><a class="reference internal" href="#json-tool">json.tool</a></li>
  120. <li><a class="reference internal" href="#logging">logging</a></li>
  121. <li><a class="reference internal" href="#math">math</a></li>
  122. <li><a class="reference internal" href="#mmap">mmap</a></li>
  123. <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
  124. <li><a class="reference internal" href="#os">os</a></li>
  125. <li><a class="reference internal" href="#os-path">os.path</a></li>
  126. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  127. <li><a class="reference internal" href="#pickle">pickle</a></li>
  128. <li><a class="reference internal" href="#plistlib">plistlib</a></li>
  129. <li><a class="reference internal" href="#pprint">pprint</a></li>
  130. <li><a class="reference internal" href="#py-compile">py_compile</a></li>
  131. <li><a class="reference internal" href="#shlex">shlex</a></li>
  132. <li><a class="reference internal" href="#shutil">shutil</a></li>
  133. <li><a class="reference internal" href="#socket">socket</a></li>
  134. <li><a class="reference internal" href="#ssl">ssl</a></li>
  135. <li><a class="reference internal" href="#statistics">statistics</a></li>
  136. <li><a class="reference internal" href="#sys">sys</a></li>
  137. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  138. <li><a class="reference internal" href="#threading">threading</a></li>
  139. <li><a class="reference internal" href="#tokenize">tokenize</a></li>
  140. <li><a class="reference internal" href="#tkinter">tkinter</a></li>
  141. <li><a class="reference internal" href="#time">time</a></li>
  142. <li><a class="reference internal" href="#typing">typing</a></li>
  143. <li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
  144. <li><a class="reference internal" href="#unittest">unittest</a></li>
  145. <li><a class="reference internal" href="#venv">venv</a></li>
  146. <li><a class="reference internal" href="#weakref">weakref</a></li>
  147. <li><a class="reference internal" href="#xml">xml</a></li>
  148. <li><a class="reference internal" href="#xmlrpc">xmlrpc</a></li>
  149. </ul>
  150. </li>
  151. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  152. <li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
  153. <li><a class="reference internal" href="#deprecated">Deprecated</a></li>
  154. <li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
  155. <li><a class="reference internal" href="#porting-to-python-3-8">Porting to Python 3.8</a><ul>
  156. <li><a class="reference internal" href="#changes-in-python-behavior">Changes in Python behavior</a></li>
  157. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  158. <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
  159. <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
  160. <li><a class="reference internal" href="#demos-and-tools">Demos and Tools</a></li>
  161. </ul>
  162. </li>
  163. <li><a class="reference internal" href="#notable-changes-in-python-3-8-1">Notable changes in Python 3.8.1</a></li>
  164. <li><a class="reference internal" href="#notable-changes-in-python-3-8-2">Notable changes in Python 3.8.2</a></li>
  165. <li><a class="reference internal" href="#notable-changes-in-python-3-8-3">Notable changes in Python 3.8.3</a></li>
  166. <li><a class="reference internal" href="#notable-changes-in-python-3-8-8">Notable changes in Python 3.8.8</a></li>
  167. <li><a class="reference internal" href="#notable-changes-in-python-3-8-9">Notable changes in Python 3.8.9</a></li>
  168. <li><a class="reference internal" href="#notable-changes-in-python-3-8-10">Notable changes in Python 3.8.10</a><ul>
  169. <li><a class="reference internal" href="#macos-11-0-big-sur-and-apple-silicon-mac-support">macOS 11.0 (Big Sur) and Apple Silicon Mac support</a></li>
  170. </ul>
  171. </li>
  172. <li><a class="reference internal" href="#id1">Notable changes in Python 3.8.10</a><ul>
  173. <li><a class="reference internal" href="#urllib-parse">urllib.parse</a></li>
  174. </ul>
  175. </li>
  176. <li><a class="reference internal" href="#notable-changes-in-python-3-8-12">Notable changes in Python 3.8.12</a><ul>
  177. <li><a class="reference internal" href="#id2">Changes in the Python API</a></li>
  178. </ul>
  179. </li>
  180. <li><a class="reference internal" href="#notable-security-feature-in-3-8-14">Notable security feature in 3.8.14</a></li>
  181. <li><a class="reference internal" href="#notable-changes-in-3-8-17">Notable changes in 3.8.17</a><ul>
  182. <li><a class="reference internal" href="#id3">tarfile</a></li>
  183. </ul>
  184. </li>
  185. </ul>
  186. </li>
  187. </ul>
  188. </div>
  189. <div>
  190. <h4>Previous topic</h4>
  191. <p class="topless"><a href="3.9.html"
  192. title="previous chapter">What’s New In Python 3.9</a></p>
  193. </div>
  194. <div>
  195. <h4>Next topic</h4>
  196. <p class="topless"><a href="3.7.html"
  197. title="next chapter">What’s New In Python 3.7</a></p>
  198. </div>
  199. <div role="note" aria-label="source link">
  200. <h3>This Page</h3>
  201. <ul class="this-page-menu">
  202. <li><a href="../bugs.html">Report a Bug</a></li>
  203. <li>
  204. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.8.rst"
  205. rel="nofollow">Show Source
  206. </a>
  207. </li>
  208. </ul>
  209. </div>
  210. </nav>
  211. </div>
  212. </div>
  213. <div class="related" role="navigation" aria-label="related navigation">
  214. <h3>Navigation</h3>
  215. <ul>
  216. <li class="right" style="margin-right: 10px">
  217. <a href="../genindex.html" title="General Index"
  218. accesskey="I">index</a></li>
  219. <li class="right" >
  220. <a href="../py-modindex.html" title="Python Module Index"
  221. >modules</a> |</li>
  222. <li class="right" >
  223. <a href="3.7.html" title="What’s New In Python 3.7"
  224. accesskey="N">next</a> |</li>
  225. <li class="right" >
  226. <a href="3.9.html" title="What’s New In Python 3.9"
  227. accesskey="P">previous</a> |</li>
  228. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  229. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  230. <li class="switchers">
  231. <div class="language_switcher_placeholder"></div>
  232. <div class="version_switcher_placeholder"></div>
  233. </li>
  234. <li>
  235. </li>
  236. <li id="cpython-language-and-version">
  237. <a href="../index.html">3.12.3 Documentation</a> &#187;
  238. </li>
  239. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> &#187;</li>
  240. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.8</a></li>
  241. <li class="right">
  242. <div class="inline-search" role="search">
  243. <form class="inline-search" action="../search.html" method="get">
  244. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  245. <input type="submit" value="Go" />
  246. </form>
  247. </div>
  248. |
  249. </li>
  250. <li class="right">
  251. <label class="theme-selector-label">
  252. Theme
  253. <select class="theme-selector" oninput="activateTheme(this.value)">
  254. <option value="auto" selected>Auto</option>
  255. <option value="light">Light</option>
  256. <option value="dark">Dark</option>
  257. </select>
  258. </label> |</li>
  259. </ul>
  260. </div>
  261. <div class="document">
  262. <div class="documentwrapper">
  263. <div class="bodywrapper">
  264. <div class="body" role="main">
  265. <section id="what-s-new-in-python-3-8">
  266. <h1>What’s New In Python 3.8<a class="headerlink" href="#what-s-new-in-python-3-8" title="Link to this heading">¶</a></h1>
  267. <dl class="field-list simple">
  268. <dt class="field-odd">Editor<span class="colon">:</span></dt>
  269. <dd class="field-odd"><p>Raymond Hettinger</p>
  270. </dd>
  271. </dl>
  272. <p>This article explains the new features in Python 3.8, compared to 3.7.
  273. Python 3.8 was released on October 14, 2019.
  274. For full details, see the <a class="reference internal" href="changelog.html#changelog"><span class="std std-ref">changelog</span></a>.</p>
  275. <section id="summary-release-highlights">
  276. <h2>Summary – Release highlights<a class="headerlink" href="#summary-release-highlights" title="Link to this heading">¶</a></h2>
  277. </section>
  278. <section id="new-features">
  279. <h2>New Features<a class="headerlink" href="#new-features" title="Link to this heading">¶</a></h2>
  280. <section id="assignment-expressions">
  281. <h3>Assignment expressions<a class="headerlink" href="#assignment-expressions" title="Link to this heading">¶</a></h3>
  282. <p>There is new syntax <code class="docutils literal notranslate"><span class="pre">:=</span></code> that assigns values to variables as part of a larger
  283. expression. It is affectionately known as “the walrus operator” due to
  284. its resemblance to <a class="reference external" href="https://en.wikipedia.org/wiki/Walrus#/media/File:Pacific_Walrus_-_Bull_(8247646168).jpg">the eyes and tusks of a walrus</a>.</p>
  285. <p>In this example, the assignment expression helps avoid calling
  286. <a class="reference internal" href="../library/functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a> twice:</p>
  287. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="n">n</span> <span class="o">:=</span> <span class="nb">len</span><span class="p">(</span><span class="n">a</span><span class="p">))</span> <span class="o">&gt;</span> <span class="mi">10</span><span class="p">:</span>
  288. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;List is too long (</span><span class="si">{</span><span class="n">n</span><span class="si">}</span><span class="s2"> elements, expected &lt;= 10)&quot;</span><span class="p">)</span>
  289. </pre></div>
  290. </div>
  291. <p>A similar benefit arises during regular expression matching where
  292. match objects are needed twice, once to test whether a match
  293. occurred and another to extract a subgroup:</p>
  294. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">discount</span> <span class="o">=</span> <span class="mf">0.0</span>
  295. <span class="k">if</span> <span class="p">(</span><span class="n">mo</span> <span class="o">:=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;(\d+)</span><span class="si">% d</span><span class="s1">iscount&#39;</span><span class="p">,</span> <span class="n">advertisement</span><span class="p">)):</span>
  296. <span class="n">discount</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">mo</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span> <span class="o">/</span> <span class="mf">100.0</span>
  297. </pre></div>
  298. </div>
  299. <p>The operator is also useful with while-loops that compute
  300. a value to test loop termination and then need that same
  301. value again in the body of the loop:</p>
  302. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Loop over fixed length blocks</span>
  303. <span class="k">while</span> <span class="p">(</span><span class="n">block</span> <span class="o">:=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">256</span><span class="p">))</span> <span class="o">!=</span> <span class="s1">&#39;&#39;</span><span class="p">:</span>
  304. <span class="n">process</span><span class="p">(</span><span class="n">block</span><span class="p">)</span>
  305. </pre></div>
  306. </div>
  307. <p>Another motivating use case arises in list comprehensions where
  308. a value computed in a filtering condition is also needed in
  309. the expression body:</p>
  310. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="n">clean_name</span><span class="o">.</span><span class="n">title</span><span class="p">()</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span>
  311. <span class="k">if</span> <span class="p">(</span><span class="n">clean_name</span> <span class="o">:=</span> <span class="n">normalize</span><span class="p">(</span><span class="s1">&#39;NFC&#39;</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span> <span class="ow">in</span> <span class="n">allowed_names</span><span class="p">]</span>
  312. </pre></div>
  313. </div>
  314. <p>Try to limit use of the walrus operator to clean cases that reduce
  315. complexity and improve readability.</p>
  316. <p>See <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0572/"><strong>PEP 572</strong></a> for a full description.</p>
  317. <p>(Contributed by Emily Morehouse in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35224">bpo-35224</a>.)</p>
  318. </section>
  319. <section id="positional-only-parameters">
  320. <h3>Positional-only parameters<a class="headerlink" href="#positional-only-parameters" title="Link to this heading">¶</a></h3>
  321. <p>There is a new function parameter syntax <code class="docutils literal notranslate"><span class="pre">/</span></code> to indicate that some
  322. function parameters must be specified positionally and cannot be used as
  323. keyword arguments. This is the same notation shown by <code class="docutils literal notranslate"><span class="pre">help()</span></code> for C
  324. functions annotated with Larry Hastings’
  325. <a class="reference external" href="https://devguide.python.org/development-tools/clinic/">Argument Clinic</a> tool.</p>
  326. <p>In the following example, parameters <em>a</em> and <em>b</em> are positional-only,
  327. while <em>c</em> or <em>d</em> can be positional or keyword, and <em>e</em> or <em>f</em> are
  328. required to be keywords:</p>
  329. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">f</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="o">/</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">f</span><span class="p">):</span>
  330. <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> <span class="n">e</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
  331. </pre></div>
  332. </div>
  333. <p>The following is a valid call:</p>
  334. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">f</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="mi">40</span><span class="p">,</span> <span class="n">e</span><span class="o">=</span><span class="mi">50</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="mi">60</span><span class="p">)</span>
  335. </pre></div>
  336. </div>
  337. <p>However, these are invalid calls:</p>
  338. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">f</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="mi">40</span><span class="p">,</span> <span class="n">e</span><span class="o">=</span><span class="mi">50</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="mi">60</span><span class="p">)</span> <span class="c1"># b cannot be a keyword argument</span>
  339. <span class="n">f</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="n">f</span><span class="o">=</span><span class="mi">60</span><span class="p">)</span> <span class="c1"># e must be a keyword argument</span>
  340. </pre></div>
  341. </div>
  342. <p>One use case for this notation is that it allows pure Python functions
  343. to fully emulate behaviors of existing C coded functions. For example,
  344. the built-in <a class="reference internal" href="../library/functions.html#divmod" title="divmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">divmod()</span></code></a> function does not accept keyword arguments:</p>
  345. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">divmod</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="o">/</span><span class="p">):</span>
  346. <span class="s2">&quot;Emulate the built in divmod() function&quot;</span>
  347. <span class="k">return</span> <span class="p">(</span><span class="n">a</span> <span class="o">//</span> <span class="n">b</span><span class="p">,</span> <span class="n">a</span> <span class="o">%</span> <span class="n">b</span><span class="p">)</span>
  348. </pre></div>
  349. </div>
  350. <p>Another use case is to preclude keyword arguments when the parameter
  351. name is not helpful. For example, the builtin <a class="reference internal" href="../library/functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a> function has
  352. the signature <code class="docutils literal notranslate"><span class="pre">len(obj,</span> <span class="pre">/)</span></code>. This precludes awkward calls such as:</p>
  353. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">len</span><span class="p">(</span><span class="n">obj</span><span class="o">=</span><span class="s1">&#39;hello&#39;</span><span class="p">)</span> <span class="c1"># The &quot;obj&quot; keyword argument impairs readability</span>
  354. </pre></div>
  355. </div>
  356. <p>A further benefit of marking a parameter as positional-only is that it
  357. allows the parameter name to be changed in the future without risk of
  358. breaking client code. For example, in the <a class="reference internal" href="../library/statistics.html#module-statistics" title="statistics: Mathematical statistics functions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">statistics</span></code></a> module, the
  359. parameter name <em>dist</em> may be changed in the future. This was made
  360. possible with the following function specification:</p>
  361. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">quantiles</span><span class="p">(</span><span class="n">dist</span><span class="p">,</span> <span class="o">/</span><span class="p">,</span> <span class="o">*</span><span class="p">,</span> <span class="n">n</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;exclusive&#39;</span><span class="p">)</span>
  362. <span class="o">...</span>
  363. </pre></div>
  364. </div>
  365. <p>Since the parameters to the left of <code class="docutils literal notranslate"><span class="pre">/</span></code> are not exposed as possible
  366. keywords, the parameters names remain available for use in <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code>:</p>
  367. <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">f</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="o">/</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
  368. <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">kwargs</span><span class="p">)</span>
  369. <span class="gp">...</span>
  370. <span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="n">a</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">c</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span> <span class="c1"># a and b are used in two ways</span>
  371. <span class="go">10 20 {&#39;a&#39;: 1, &#39;b&#39;: 2, &#39;c&#39;: 3}</span>
  372. </pre></div>
  373. </div>
  374. <p>This greatly simplifies the implementation of functions and methods
  375. that need to accept arbitrary keyword arguments. For example, here
  376. is an excerpt from code in the <a class="reference internal" href="../library/collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a> module:</p>
  377. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Counter</span><span class="p">(</span><span class="nb">dict</span><span class="p">):</span>
  378. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">iterable</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">/</span><span class="p">,</span> <span class="o">**</span><span class="n">kwds</span><span class="p">):</span>
  379. <span class="c1"># Note &quot;iterable&quot; is a possible keyword argument</span>
  380. </pre></div>
  381. </div>
  382. <p>See <span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0570/"><strong>PEP 570</strong></a> for a full description.</p>
  383. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36540">bpo-36540</a>.)</p>
  384. </section>
  385. <section id="parallel-filesystem-cache-for-compiled-bytecode-files">
  386. <h3>Parallel filesystem cache for compiled bytecode files<a class="headerlink" href="#parallel-filesystem-cache-for-compiled-bytecode-files" title="Link to this heading">¶</a></h3>
  387. <p>The new <span class="target" id="index-2"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPYCACHEPREFIX"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPYCACHEPREFIX</span></code></a> setting (also available as
  388. <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> <code class="docutils literal notranslate"><span class="pre">pycache_prefix</span></code>) configures the implicit bytecode
  389. cache to use a separate parallel filesystem tree, rather than
  390. the default <code class="docutils literal notranslate"><span class="pre">__pycache__</span></code> subdirectories within each source
  391. directory.</p>
  392. <p>The location of the cache is reported in <a class="reference internal" href="../library/sys.html#sys.pycache_prefix" title="sys.pycache_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.pycache_prefix</span></code></a>
  393. (<a class="reference internal" href="../library/constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> indicates the default location in <code class="docutils literal notranslate"><span class="pre">__pycache__</span></code>
  394. subdirectories).</p>
  395. <p>(Contributed by Carl Meyer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33499">bpo-33499</a>.)</p>
  396. </section>
  397. <section id="debug-build-uses-the-same-abi-as-release-build">
  398. <h3>Debug build uses the same ABI as release build<a class="headerlink" href="#debug-build-uses-the-same-abi-as-release-build" title="Link to this heading">¶</a></h3>
  399. <p>Python now uses the same ABI whether it’s built in release or debug mode. On
  400. Unix, when Python is built in debug mode, it is now possible to load C
  401. extensions built in release mode and C extensions built using the stable ABI.</p>
  402. <p>Release builds and <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug builds</span></a> are now ABI compatible: defining the
  403. <code class="docutils literal notranslate"><span class="pre">Py_DEBUG</span></code> macro no longer implies the <code class="docutils literal notranslate"><span class="pre">Py_TRACE_REFS</span></code> macro, which
  404. introduces the only ABI incompatibility. The <code class="docutils literal notranslate"><span class="pre">Py_TRACE_REFS</span></code> macro, which
  405. adds the <code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getobjects()</span></code> function and the <span class="target" id="index-3"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONDUMPREFS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONDUMPREFS</span></code></a>
  406. environment variable, can be set using the new <a class="reference internal" href="../using/configure.html#cmdoption-with-trace-refs"><code class="xref std std-option docutils literal notranslate"><span class="pre">./configure</span>
  407. <span class="pre">--with-trace-refs</span></code></a> build option.
  408. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36465">bpo-36465</a>.)</p>
  409. <p>On Unix, C extensions are no longer linked to libpython except on Android
  410. and Cygwin.
  411. It is now possible
  412. for a statically linked Python to load a C extension built using a shared
  413. library Python.
  414. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21536">bpo-21536</a>.)</p>
  415. <p>On Unix, when Python is built in debug mode, import now also looks for C
  416. extensions compiled in release mode and for C extensions compiled with the
  417. stable ABI.
  418. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36722">bpo-36722</a>.)</p>
  419. <p>To embed Python into an application, a new <code class="docutils literal notranslate"><span class="pre">--embed</span></code> option must be passed to
  420. <code class="docutils literal notranslate"><span class="pre">python3-config</span> <span class="pre">--libs</span> <span class="pre">--embed</span></code> to get <code class="docutils literal notranslate"><span class="pre">-lpython3.8</span></code> (link the application
  421. to libpython). To support both 3.8 and older, try <code class="docutils literal notranslate"><span class="pre">python3-config</span> <span class="pre">--libs</span>
  422. <span class="pre">--embed</span></code> first and fallback to <code class="docutils literal notranslate"><span class="pre">python3-config</span> <span class="pre">--libs</span></code> (without <code class="docutils literal notranslate"><span class="pre">--embed</span></code>)
  423. if the previous command fails.</p>
  424. <p>Add a pkg-config <code class="docutils literal notranslate"><span class="pre">python-3.8-embed</span></code> module to embed Python into an
  425. application: <code class="docutils literal notranslate"><span class="pre">pkg-config</span> <span class="pre">python-3.8-embed</span> <span class="pre">--libs</span></code> includes <code class="docutils literal notranslate"><span class="pre">-lpython3.8</span></code>.
  426. To support both 3.8 and older, try <code class="docutils literal notranslate"><span class="pre">pkg-config</span> <span class="pre">python-X.Y-embed</span> <span class="pre">--libs</span></code> first
  427. and fallback to <code class="docutils literal notranslate"><span class="pre">pkg-config</span> <span class="pre">python-X.Y</span> <span class="pre">--libs</span></code> (without <code class="docutils literal notranslate"><span class="pre">--embed</span></code>) if the
  428. previous command fails (replace <code class="docutils literal notranslate"><span class="pre">X.Y</span></code> with the Python version).</p>
  429. <p>On the other hand, <code class="docutils literal notranslate"><span class="pre">pkg-config</span> <span class="pre">python3.8</span> <span class="pre">--libs</span></code> no longer contains
  430. <code class="docutils literal notranslate"><span class="pre">-lpython3.8</span></code>. C extensions must not be linked to libpython (except on
  431. Android and Cygwin, whose cases are handled by the script);
  432. this change is backward incompatible on purpose.
  433. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36721">bpo-36721</a>.)</p>
  434. </section>
  435. <section id="f-strings-support-for-self-documenting-expressions-and-debugging">
  436. <span id="bpo-36817-whatsnew"></span><h3>f-strings support <code class="docutils literal notranslate"><span class="pre">=</span></code> for self-documenting expressions and debugging<a class="headerlink" href="#f-strings-support-for-self-documenting-expressions-and-debugging" title="Link to this heading">¶</a></h3>
  437. <p>Added an <code class="docutils literal notranslate"><span class="pre">=</span></code> specifier to <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-string</span></a>s. An f-string such as
  438. <code class="docutils literal notranslate"><span class="pre">f'{expr=}'</span></code> will expand to the text of the expression, an equal sign,
  439. then the representation of the evaluated expression. For example:</p>
  440. <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">user</span> <span class="o">=</span> <span class="s1">&#39;eric_idle&#39;</span>
  441. <span class="gp">&gt;&gt;&gt; </span><span class="n">member_since</span> <span class="o">=</span> <span class="n">date</span><span class="p">(</span><span class="mi">1975</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">31</span><span class="p">)</span>
  442. <span class="gp">&gt;&gt;&gt; </span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">user</span><span class="si">=}</span><span class="s1"> </span><span class="si">{</span><span class="n">member_since</span><span class="si">=}</span><span class="s1">&#39;</span>
  443. <span class="go">&quot;user=&#39;eric_idle&#39; member_since=datetime.date(1975, 7, 31)&quot;</span>
  444. </pre></div>
  445. </div>
  446. <p>The usual <a class="reference internal" href="../reference/lexical_analysis.html#f-strings"><span class="std std-ref">f-string format specifiers</span></a> allow more
  447. control over how the result of the expression is displayed:</p>
  448. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">delta</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">today</span><span class="p">()</span> <span class="o">-</span> <span class="n">member_since</span>
  449. <span class="gp">&gt;&gt;&gt; </span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">user</span><span class="si">=!s}</span><span class="s1"> </span><span class="si">{</span><span class="n">delta</span><span class="o">.</span><span class="n">days</span><span class="si">=:</span><span class="s1">,d</span><span class="si">}</span><span class="s1">&#39;</span>
  450. <span class="go">&#39;user=eric_idle delta.days=16,075&#39;</span>
  451. </pre></div>
  452. </div>
  453. <p>The <code class="docutils literal notranslate"><span class="pre">=</span></code> specifier will display the whole expression so that
  454. calculations can be shown:</p>
  455. <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="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">theta</span><span class="si">=}</span><span class="s1"> </span><span class="si">{</span><span class="n">cos</span><span class="p">(</span><span class="n">radians</span><span class="p">(</span><span class="n">theta</span><span class="p">))</span><span class="si">=:</span><span class="s1">.3f</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">)</span>
  456. <span class="go">theta=30 cos(radians(theta))=0.866</span>
  457. </pre></div>
  458. </div>
  459. <p>(Contributed by Eric V. Smith and Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36817">bpo-36817</a>.)</p>
  460. </section>
  461. <section id="pep-578-python-runtime-audit-hooks">
  462. <h3>PEP 578: Python Runtime Audit Hooks<a class="headerlink" href="#pep-578-python-runtime-audit-hooks" title="Link to this heading">¶</a></h3>
  463. <p>The PEP adds an Audit Hook and Verified Open Hook. Both are available from
  464. Python and native code, allowing applications and frameworks written in pure
  465. Python code to take advantage of extra notifications, while also allowing
  466. embedders or system administrators to deploy builds of Python where auditing is
  467. always enabled.</p>
  468. <p>See <span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0578/"><strong>PEP 578</strong></a> for full details.</p>
  469. </section>
  470. <section id="pep-587-python-initialization-configuration">
  471. <h3>PEP 587: Python Initialization Configuration<a class="headerlink" href="#pep-587-python-initialization-configuration" title="Link to this heading">¶</a></h3>
  472. <p>The <span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0587/"><strong>PEP 587</strong></a> adds a new C API to configure the Python Initialization
  473. providing finer control on the whole configuration and better error reporting.</p>
  474. <p>New structures:</p>
  475. <ul class="simple">
  476. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a></p></li>
  477. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig" title="PyPreConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyPreConfig</span></code></a></p></li>
  478. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus" title="PyStatus"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyStatus</span></code></a></p></li>
  479. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyWideStringList" title="PyWideStringList"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyWideStringList</span></code></a></p></li>
  480. </ul>
  481. <p>New functions:</p>
  482. <ul class="simple">
  483. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_Clear" title="PyConfig_Clear"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Clear()</span></code></a></p></li>
  484. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_InitIsolatedConfig" title="PyConfig_InitIsolatedConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_InitIsolatedConfig()</span></code></a></p></li>
  485. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_InitPythonConfig" title="PyConfig_InitPythonConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_InitPythonConfig()</span></code></a></p></li>
  486. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_Read" title="PyConfig_Read"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Read()</span></code></a></p></li>
  487. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_SetArgv" title="PyConfig_SetArgv"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_SetArgv()</span></code></a></p></li>
  488. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_SetBytesArgv" title="PyConfig_SetBytesArgv"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_SetBytesArgv()</span></code></a></p></li>
  489. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_SetBytesString" title="PyConfig_SetBytesString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_SetBytesString()</span></code></a></p></li>
  490. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_SetString" title="PyConfig_SetString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_SetString()</span></code></a></p></li>
  491. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig_InitIsolatedConfig" title="PyPreConfig_InitIsolatedConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyPreConfig_InitIsolatedConfig()</span></code></a></p></li>
  492. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig_InitPythonConfig" title="PyPreConfig_InitPythonConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyPreConfig_InitPythonConfig()</span></code></a></p></li>
  493. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_Error" title="PyStatus_Error"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_Error()</span></code></a></p></li>
  494. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_Exception" title="PyStatus_Exception"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_Exception()</span></code></a></p></li>
  495. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_Exit" title="PyStatus_Exit"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_Exit()</span></code></a></p></li>
  496. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_IsError" title="PyStatus_IsError"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_IsError()</span></code></a></p></li>
  497. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_IsExit" title="PyStatus_IsExit"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_IsExit()</span></code></a></p></li>
  498. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_NoMemory" title="PyStatus_NoMemory"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_NoMemory()</span></code></a></p></li>
  499. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyStatus_Ok" title="PyStatus_Ok"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_Ok()</span></code></a></p></li>
  500. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyWideStringList_Append" title="PyWideStringList_Append"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWideStringList_Append()</span></code></a></p></li>
  501. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyWideStringList_Insert" title="PyWideStringList_Insert"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWideStringList_Insert()</span></code></a></p></li>
  502. <li><p><a class="reference internal" href="../c-api/veryhigh.html#c.Py_BytesMain" title="Py_BytesMain"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_BytesMain()</span></code></a></p></li>
  503. <li><p><a class="reference internal" href="../c-api/init_config.html#c.Py_ExitStatusException" title="Py_ExitStatusException"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_ExitStatusException()</span></code></a></p></li>
  504. <li><p><a class="reference internal" href="../c-api/init_config.html#c.Py_InitializeFromConfig" title="Py_InitializeFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_InitializeFromConfig()</span></code></a></p></li>
  505. <li><p><a class="reference internal" href="../c-api/init_config.html#c.Py_PreInitialize" title="Py_PreInitialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitialize()</span></code></a></p></li>
  506. <li><p><a class="reference internal" href="../c-api/init_config.html#c.Py_PreInitializeFromArgs" title="Py_PreInitializeFromArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitializeFromArgs()</span></code></a></p></li>
  507. <li><p><a class="reference internal" href="../c-api/init_config.html#c.Py_PreInitializeFromBytesArgs" title="Py_PreInitializeFromBytesArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitializeFromBytesArgs()</span></code></a></p></li>
  508. <li><p><a class="reference internal" href="../c-api/init_config.html#c.Py_RunMain" title="Py_RunMain"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_RunMain()</span></code></a></p></li>
  509. </ul>
  510. <p>This PEP also adds <code class="docutils literal notranslate"><span class="pre">_PyRuntimeState.preconfig</span></code> (<a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig" title="PyPreConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyPreConfig</span></code></a> type)
  511. and <code class="docutils literal notranslate"><span class="pre">PyInterpreterState.config</span></code> (<a class="reference internal" href="../c-api/init_config.html#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a> type) fields to these
  512. internal structures. <code class="docutils literal notranslate"><span class="pre">PyInterpreterState.config</span></code> becomes the new
  513. reference configuration, replacing global configuration variables and
  514. other private variables.</p>
  515. <p>See <a class="reference internal" href="../c-api/init_config.html#init-config"><span class="std std-ref">Python Initialization Configuration</span></a> for the
  516. documentation.</p>
  517. <p>See <span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0587/"><strong>PEP 587</strong></a> for a full description.</p>
  518. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36763">bpo-36763</a>.)</p>
  519. </section>
  520. <section id="pep-590-vectorcall-a-fast-calling-protocol-for-cpython">
  521. <h3>PEP 590: Vectorcall: a fast calling protocol for CPython<a class="headerlink" href="#pep-590-vectorcall-a-fast-calling-protocol-for-cpython" title="Link to this heading">¶</a></h3>
  522. <p><a class="reference internal" href="../c-api/call.html#vectorcall"><span class="std std-ref">The Vectorcall Protocol</span></a> is added to the Python/C API.
  523. It is meant to formalize existing optimizations which were already done
  524. for various classes.
  525. Any <a class="reference internal" href="../c-api/typeobj.html#static-types"><span class="std std-ref">static type</span></a> implementing a callable can use this
  526. protocol.</p>
  527. <p>This is currently provisional.
  528. The aim is to make it fully public in Python 3.9.</p>
  529. <p>See <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0590/"><strong>PEP 590</strong></a> for a full description.</p>
  530. <p>(Contributed by Jeroen Demeyer, Mark Shannon and Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36974">bpo-36974</a>.)</p>
  531. </section>
  532. <section id="pickle-protocol-5-with-out-of-band-data-buffers">
  533. <h3>Pickle protocol 5 with out-of-band data buffers<a class="headerlink" href="#pickle-protocol-5-with-out-of-band-data-buffers" title="Link to this heading">¶</a></h3>
  534. <p>When <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> is used to transfer large data between Python processes
  535. in order to take advantage of multi-core or multi-machine processing,
  536. it is important to optimize the transfer by reducing memory copies, and
  537. possibly by applying custom techniques such as data-dependent compression.</p>
  538. <p>The <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> protocol 5 introduces support for out-of-band buffers
  539. where <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-3118/"><strong>PEP 3118</strong></a>-compatible data can be transmitted separately from the
  540. main pickle stream, at the discretion of the communication layer.</p>
  541. <p>See <span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0574/"><strong>PEP 574</strong></a> for a full description.</p>
  542. <p>(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36785">bpo-36785</a>.)</p>
  543. </section>
  544. </section>
  545. <section id="other-language-changes">
  546. <h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading">¶</a></h2>
  547. <ul>
  548. <li><p>A <a class="reference internal" href="../reference/simple_stmts.html#continue"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">continue</span></code></a> statement was illegal in the <a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">finally</span></code></a> clause
  549. due to a problem with the implementation. In Python 3.8 this restriction
  550. was lifted.
  551. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32489">bpo-32489</a>.)</p></li>
  552. <li><p>The <a class="reference internal" href="../library/functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a>, <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>, and <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> types
  553. now have an <a class="reference internal" href="../library/stdtypes.html#int.as_integer_ratio" title="int.as_integer_ratio"><code class="xref py py-meth docutils literal notranslate"><span class="pre">as_integer_ratio()</span></code></a> method like that found in
  554. <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> and <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">decimal.Decimal</span></code></a>. This minor API extension
  555. makes it possible to write <code class="docutils literal notranslate"><span class="pre">numerator,</span> <span class="pre">denominator</span> <span class="pre">=</span>
  556. <span class="pre">x.as_integer_ratio()</span></code> and have it work across multiple numeric types.
  557. (Contributed by Lisa Roach in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33073">bpo-33073</a> and Raymond Hettinger in
  558. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37819">bpo-37819</a>.)</p></li>
  559. <li><p>Constructors of <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>, <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> and <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a> will now
  560. use the <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> special method, if available and the
  561. corresponding method <a class="reference internal" href="../reference/datamodel.html#object.__int__" title="object.__int__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__int__()</span></code></a>, <a class="reference internal" href="../reference/datamodel.html#object.__float__" title="object.__float__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__float__()</span></code></a>
  562. or <a class="reference internal" href="../reference/datamodel.html#object.__complex__" title="object.__complex__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__complex__()</span></code></a> is not available.
  563. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20092">bpo-20092</a>.)</p></li>
  564. <li><p>Added support of <code class="samp docutils literal notranslate"><span class="pre">\N{</span><em><span class="pre">name</span></em><span class="pre">}</span></code> escapes in <a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">regular</span> <span class="pre">expressions</span></code></a>:</p>
  565. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">notice</span> <span class="o">=</span> <span class="s1">&#39;Copyright © 2019&#39;</span>
  566. <span class="gp">&gt;&gt;&gt; </span><span class="n">copyright_year_pattern</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;\N{copyright sign}\s*(\d</span><span class="si">{4}</span><span class="s1">)&#39;</span><span class="p">)</span>
  567. <span class="gp">&gt;&gt;&gt; </span><span class="nb">int</span><span class="p">(</span><span class="n">copyright_year_pattern</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">notice</span><span class="p">)</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
  568. <span class="go">2019</span>
  569. </pre></div>
  570. </div>
  571. <p>(Contributed by Jonathan Eunice and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30688">bpo-30688</a>.)</p>
  572. </li>
  573. <li><p>Dict and dictviews are now iterable in reversed insertion order using
  574. <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>. (Contributed by Rémi Lapeyre in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33462">bpo-33462</a>.)</p></li>
  575. <li><p>The syntax allowed for keyword names in function calls was further
  576. restricted. In particular, <code class="docutils literal notranslate"><span class="pre">f((keyword)=arg)</span></code> is no longer allowed. It was
  577. never intended to permit more than a bare name on the left-hand side of a
  578. keyword argument assignment term.
  579. (Contributed by Benjamin Peterson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34641">bpo-34641</a>.)</p></li>
  580. <li><p>Generalized iterable unpacking in <a class="reference internal" href="../reference/simple_stmts.html#yield"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">yield</span></code></a> and
  581. <a class="reference internal" href="../reference/simple_stmts.html#return"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">return</span></code></a> statements no longer requires enclosing parentheses.
  582. This brings the <em>yield</em> and <em>return</em> syntax into better agreement with
  583. normal assignment syntax:</p>
  584. <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">parse</span><span class="p">(</span><span class="n">family</span><span class="p">):</span>
  585. <span class="go"> lastname, *members = family.split()</span>
  586. <span class="go"> return lastname.upper(), *members</span>
  587. <span class="gp">&gt;&gt;&gt; </span><span class="n">parse</span><span class="p">(</span><span class="s1">&#39;simpsons homer marge bart lisa maggie&#39;</span><span class="p">)</span>
  588. <span class="go">(&#39;SIMPSONS&#39;, &#39;homer&#39;, &#39;marge&#39;, &#39;bart&#39;, &#39;lisa&#39;, &#39;maggie&#39;)</span>
  589. </pre></div>
  590. </div>
  591. <p>(Contributed by David Cuthbert and Jordan Chapman in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32117">bpo-32117</a>.)</p>
  592. </li>
  593. <li><p>When a comma is missed in code such as <code class="docutils literal notranslate"><span class="pre">[(10,</span> <span class="pre">20)</span> <span class="pre">(30,</span> <span class="pre">40)]</span></code>, the
  594. compiler displays a <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a> with a helpful suggestion.
  595. This improves on just having a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> indicating that the
  596. first tuple was not callable. (Contributed by Serhiy Storchaka in
  597. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15248">bpo-15248</a>.)</p></li>
  598. <li><p>Arithmetic operations between subclasses of <a class="reference internal" href="../library/datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.date</span></code></a> or
  599. <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.datetime</span></code></a> and <a class="reference internal" href="../library/datetime.html#datetime.timedelta" title="datetime.timedelta"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.timedelta</span></code></a> objects now return
  600. an instance of the subclass, rather than the base class. This also affects
  601. the return type of operations whose implementation (directly or indirectly)
  602. uses <a class="reference internal" href="../library/datetime.html#datetime.timedelta" title="datetime.timedelta"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.timedelta</span></code></a> arithmetic, such as
  603. <a class="reference internal" href="../library/datetime.html#datetime.datetime.astimezone" title="datetime.datetime.astimezone"><code class="xref py py-meth docutils literal notranslate"><span class="pre">astimezone()</span></code></a>.
  604. (Contributed by Paul Ganssle in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32417">bpo-32417</a>.)</p></li>
  605. <li><p>When the Python interpreter is interrupted by Ctrl-C (SIGINT) and the
  606. resulting <a class="reference internal" href="../library/exceptions.html#KeyboardInterrupt" title="KeyboardInterrupt"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyboardInterrupt</span></code></a> exception is not caught, the Python process
  607. now exits via a SIGINT signal or with the correct exit code such that the
  608. calling process can detect that it died due to a Ctrl-C. Shells on POSIX
  609. and Windows use this to properly terminate scripts in interactive sessions.
  610. (Contributed by Google via Gregory P. Smith in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1054041">bpo-1054041</a>.)</p></li>
  611. <li><p>Some advanced styles of programming require updating the
  612. <a class="reference internal" href="../library/types.html#types.CodeType" title="types.CodeType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.CodeType</span></code></a> object for an existing function. Since code
  613. objects are immutable, a new code object needs to be created, one
  614. that is modeled on the existing code object. With 19 parameters,
  615. this was somewhat tedious. Now, the new <code class="docutils literal notranslate"><span class="pre">replace()</span></code> method makes
  616. it possible to create a clone with a few altered parameters.</p>
  617. <p>Here’s an example that alters the <a class="reference internal" href="../library/statistics.html#statistics.mean" title="statistics.mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.mean()</span></code></a> function to
  618. prevent the <em>data</em> parameter from being used as a keyword argument:</p>
  619. <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">statistics</span> <span class="kn">import</span> <span class="n">mean</span>
  620. <span class="gp">&gt;&gt;&gt; </span><span class="n">mean</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">90</span><span class="p">])</span>
  621. <span class="go">40</span>
  622. <span class="gp">&gt;&gt;&gt; </span><span class="n">mean</span><span class="o">.</span><span class="vm">__code__</span> <span class="o">=</span> <span class="n">mean</span><span class="o">.</span><span class="vm">__code__</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">co_posonlyargcount</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
  623. <span class="gp">&gt;&gt;&gt; </span><span class="n">mean</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">90</span><span class="p">])</span>
  624. <span class="gt">Traceback (most recent call last):</span>
  625. <span class="w"> </span><span class="c">...</span>
  626. <span class="gr">TypeError</span>: <span class="n">mean() got some positional-only arguments passed as keyword arguments: &#39;data&#39;</span>
  627. </pre></div>
  628. </div>
  629. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37032">bpo-37032</a>.)</p>
  630. </li>
  631. <li><p>For integers, the three-argument form of the <a class="reference internal" href="../library/functions.html#pow" title="pow"><code class="xref py py-func docutils literal notranslate"><span class="pre">pow()</span></code></a> function now
  632. permits the exponent to be negative in the case where the base is
  633. relatively prime to the modulus. It then computes a modular inverse to
  634. the base when the exponent is <code class="docutils literal notranslate"><span class="pre">-1</span></code>, and a suitable power of that
  635. inverse for other negative exponents. For example, to compute the
  636. <a class="reference external" href="https://en.wikipedia.org/wiki/Modular_multiplicative_inverse">modular multiplicative inverse</a> of 38
  637. modulo 137, write:</p>
  638. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">pow</span><span class="p">(</span><span class="mi">38</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">137</span><span class="p">)</span>
  639. <span class="go">119</span>
  640. <span class="gp">&gt;&gt;&gt; </span><span class="mi">119</span> <span class="o">*</span> <span class="mi">38</span> <span class="o">%</span> <span class="mi">137</span>
  641. <span class="go">1</span>
  642. </pre></div>
  643. </div>
  644. <p>Modular inverses arise in the solution of <a class="reference external" href="https://en.wikipedia.org/wiki/Diophantine_equation">linear Diophantine
  645. equations</a>.
  646. For example, to find integer solutions for <code class="docutils literal notranslate"><span class="pre">4258𝑥</span> <span class="pre">+</span> <span class="pre">147𝑦</span> <span class="pre">=</span> <span class="pre">369</span></code>,
  647. first rewrite as <code class="docutils literal notranslate"><span class="pre">4258𝑥</span> <span class="pre">≡</span> <span class="pre">369</span> <span class="pre">(mod</span> <span class="pre">147)</span></code> then solve:</p>
  648. <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="mi">369</span> <span class="o">*</span> <span class="nb">pow</span><span class="p">(</span><span class="mi">4258</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">147</span><span class="p">)</span> <span class="o">%</span> <span class="mi">147</span>
  649. <span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="p">(</span><span class="mi">4258</span> <span class="o">*</span> <span class="n">x</span> <span class="o">-</span> <span class="mi">369</span><span class="p">)</span> <span class="o">//</span> <span class="o">-</span><span class="mi">147</span>
  650. <span class="gp">&gt;&gt;&gt; </span><span class="mi">4258</span> <span class="o">*</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">147</span> <span class="o">*</span> <span class="n">y</span>
  651. <span class="go">369</span>
  652. </pre></div>
  653. </div>
  654. <p>(Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36027">bpo-36027</a>.)</p>
  655. </li>
  656. <li><p>Dict comprehensions have been synced-up with dict literals so that the
  657. key is computed first and the value second:</p>
  658. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># Dict comprehension</span>
  659. <span class="gp">&gt;&gt;&gt; </span><span class="n">cast</span> <span class="o">=</span> <span class="p">{</span><span class="nb">input</span><span class="p">(</span><span class="s1">&#39;role? &#39;</span><span class="p">):</span> <span class="nb">input</span><span class="p">(</span><span class="s1">&#39;actor? &#39;</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">)}</span>
  660. <span class="go">role? King Arthur</span>
  661. <span class="go">actor? Chapman</span>
  662. <span class="go">role? Black Knight</span>
  663. <span class="go">actor? Cleese</span>
  664. <span class="gp">&gt;&gt;&gt; </span><span class="c1"># Dict literal</span>
  665. <span class="gp">&gt;&gt;&gt; </span><span class="n">cast</span> <span class="o">=</span> <span class="p">{</span><span class="nb">input</span><span class="p">(</span><span class="s1">&#39;role? &#39;</span><span class="p">):</span> <span class="nb">input</span><span class="p">(</span><span class="s1">&#39;actor? &#39;</span><span class="p">)}</span>
  666. <span class="go">role? Sir Robin</span>
  667. <span class="go">actor? Eric Idle</span>
  668. </pre></div>
  669. </div>
  670. <p>The guaranteed execution order is helpful with assignment expressions
  671. because variables assigned in the key expression will be available in
  672. the value expression:</p>
  673. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">names</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Martin von Löwis&#39;</span><span class="p">,</span> <span class="s1">&#39;Łukasz Langa&#39;</span><span class="p">,</span> <span class="s1">&#39;Walter Dörwald&#39;</span><span class="p">]</span>
  674. <span class="gp">&gt;&gt;&gt; </span><span class="p">{(</span><span class="n">n</span> <span class="o">:=</span> <span class="n">normalize</span><span class="p">(</span><span class="s1">&#39;NFC&#39;</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span><span class="o">.</span><span class="n">casefold</span><span class="p">()</span> <span class="p">:</span> <span class="n">n</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">}</span>
  675. <span class="go">{&#39;martin von löwis&#39;: &#39;Martin von Löwis&#39;,</span>
  676. <span class="go"> &#39;łukasz langa&#39;: &#39;Łukasz Langa&#39;,</span>
  677. <span class="go"> &#39;walter dörwald&#39;: &#39;Walter Dörwald&#39;}</span>
  678. </pre></div>
  679. </div>
  680. <p>(Contributed by Jörn Heissler in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35224">bpo-35224</a>.)</p>
  681. </li>
  682. <li><p>The <a class="reference internal" href="../library/pickle.html#object.__reduce__" title="object.__reduce__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__reduce__()</span></code></a> method can now return a tuple from two to
  683. six elements long. Formerly, five was the limit. The new, optional sixth
  684. element is a callable with a <code class="docutils literal notranslate"><span class="pre">(obj,</span> <span class="pre">state)</span></code> signature. This allows the
  685. direct control over the state-updating behavior of a specific object. If
  686. not <em>None</em>, this callable will have priority over the object’s
  687. <code class="xref py py-meth docutils literal notranslate"><span class="pre">__setstate__()</span></code> method.
  688. (Contributed by Pierre Glaser and Olivier Grisel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35900">bpo-35900</a>.)</p></li>
  689. </ul>
  690. </section>
  691. <section id="new-modules">
  692. <h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading">¶</a></h2>
  693. <ul>
  694. <li><p>The new <a class="reference internal" href="../library/importlib.metadata.html#module-importlib.metadata" title="importlib.metadata: Accessing package metadata"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.metadata</span></code></a> module provides (provisional) support for
  695. reading metadata from third-party packages. For example, it can extract an
  696. installed package’s version number, list of entry points, and more:</p>
  697. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># Note following example requires that the popular &quot;requests&quot;</span>
  698. <span class="gp">&gt;&gt;&gt; </span><span class="c1"># package has been installed.</span>
  699. <span class="gp">&gt;&gt;&gt;</span>
  700. <span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">importlib.metadata</span> <span class="kn">import</span> <span class="n">version</span><span class="p">,</span> <span class="n">requires</span><span class="p">,</span> <span class="n">files</span>
  701. <span class="gp">&gt;&gt;&gt; </span><span class="n">version</span><span class="p">(</span><span class="s1">&#39;requests&#39;</span><span class="p">)</span>
  702. <span class="go">&#39;2.22.0&#39;</span>
  703. <span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">requires</span><span class="p">(</span><span class="s1">&#39;requests&#39;</span><span class="p">))</span>
  704. <span class="go">[&#39;chardet (&lt;3.1.0,&gt;=3.0.2)&#39;]</span>
  705. <span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">files</span><span class="p">(</span><span class="s1">&#39;requests&#39;</span><span class="p">))[:</span><span class="mi">5</span><span class="p">]</span>
  706. <span class="go">[PackagePath(&#39;requests-2.22.0.dist-info/INSTALLER&#39;),</span>
  707. <span class="go"> PackagePath(&#39;requests-2.22.0.dist-info/LICENSE&#39;),</span>
  708. <span class="go"> PackagePath(&#39;requests-2.22.0.dist-info/METADATA&#39;),</span>
  709. <span class="go"> PackagePath(&#39;requests-2.22.0.dist-info/RECORD&#39;),</span>
  710. <span class="go"> PackagePath(&#39;requests-2.22.0.dist-info/WHEEL&#39;)]</span>
  711. </pre></div>
  712. </div>
  713. <p>(Contributed by Barry Warsaw and Jason R. Coombs in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34632">bpo-34632</a>.)</p>
  714. </li>
  715. </ul>
  716. </section>
  717. <section id="improved-modules">
  718. <h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading">¶</a></h2>
  719. <section id="ast">
  720. <h3>ast<a class="headerlink" href="#ast" title="Link to this heading">¶</a></h3>
  721. <p>AST nodes now have <code class="docutils literal notranslate"><span class="pre">end_lineno</span></code> and <code class="docutils literal notranslate"><span class="pre">end_col_offset</span></code> attributes,
  722. which give the precise location of the end of the node. (This only
  723. applies to nodes that have <code class="docutils literal notranslate"><span class="pre">lineno</span></code> and <code class="docutils literal notranslate"><span class="pre">col_offset</span></code> attributes.)</p>
  724. <p>New function <a class="reference internal" href="../library/ast.html#ast.get_source_segment" title="ast.get_source_segment"><code class="xref py py-func docutils literal notranslate"><span class="pre">ast.get_source_segment()</span></code></a> returns the source code
  725. for a specific AST node.</p>
  726. <p>(Contributed by Ivan Levkivskyi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33416">bpo-33416</a>.)</p>
  727. <p>The <a class="reference internal" href="../library/ast.html#ast.parse" title="ast.parse"><code class="xref py py-func docutils literal notranslate"><span class="pre">ast.parse()</span></code></a> function has some new flags:</p>
  728. <ul class="simple">
  729. <li><p><code class="docutils literal notranslate"><span class="pre">type_comments=True</span></code> causes it to return the text of <span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> and
  730. <span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0526/"><strong>PEP 526</strong></a> type comments associated with certain AST nodes;</p></li>
  731. <li><p><code class="docutils literal notranslate"><span class="pre">mode='func_type'</span></code> can be used to parse <span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> “signature type
  732. comments” (returned for function definition AST nodes);</p></li>
  733. <li><p><code class="docutils literal notranslate"><span class="pre">feature_version=(3,</span> <span class="pre">N)</span></code> allows specifying an earlier Python 3
  734. version. For example, <code class="docutils literal notranslate"><span class="pre">feature_version=(3,</span> <span class="pre">4)</span></code> will treat
  735. <a class="reference internal" href="../reference/compound_stmts.html#async"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span></code></a> and <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> as non-reserved words.</p></li>
  736. </ul>
  737. <p>(Contributed by Guido van Rossum in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35766">bpo-35766</a>.)</p>
  738. </section>
  739. <section id="asyncio">
  740. <h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading">¶</a></h3>
  741. <p><a class="reference internal" href="../library/asyncio-runner.html#asyncio.run" title="asyncio.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.run()</span></code></a> has graduated from the provisional to stable API. This
  742. function can be used to execute a <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> and return the result while
  743. automatically managing the event loop. For example:</p>
  744. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">asyncio</span>
  745. <span class="k">async</span> <span class="k">def</span> <span class="nf">main</span><span class="p">():</span>
  746. <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">0</span><span class="p">)</span>
  747. <span class="k">return</span> <span class="mi">42</span>
  748. <span class="n">asyncio</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">main</span><span class="p">())</span>
  749. </pre></div>
  750. </div>
  751. <p>This is <em>roughly</em> equivalent to:</p>
  752. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">asyncio</span>
  753. <span class="k">async</span> <span class="k">def</span> <span class="nf">main</span><span class="p">():</span>
  754. <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">0</span><span class="p">)</span>
  755. <span class="k">return</span> <span class="mi">42</span>
  756. <span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">new_event_loop</span><span class="p">()</span>
  757. <span class="n">asyncio</span><span class="o">.</span><span class="n">set_event_loop</span><span class="p">(</span><span class="n">loop</span><span class="p">)</span>
  758. <span class="k">try</span><span class="p">:</span>
  759. <span class="n">loop</span><span class="o">.</span><span class="n">run_until_complete</span><span class="p">(</span><span class="n">main</span><span class="p">())</span>
  760. <span class="k">finally</span><span class="p">:</span>
  761. <span class="n">asyncio</span><span class="o">.</span><span class="n">set_event_loop</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
  762. <span class="n">loop</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
  763. </pre></div>
  764. </div>
  765. <p>The actual implementation is significantly more complex. Thus,
  766. <a class="reference internal" href="../library/asyncio-runner.html#asyncio.run" title="asyncio.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.run()</span></code></a> should be the preferred way of running asyncio programs.</p>
  767. <p>(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32314">bpo-32314</a>.)</p>
  768. <p>Running <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">asyncio</span></code> launches a natively async REPL. This allows rapid
  769. experimentation with code that has a top-level <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>. There is no
  770. longer a need to directly call <code class="docutils literal notranslate"><span class="pre">asyncio.run()</span></code> which would spawn a new event
  771. loop on every invocation:</p>
  772. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>$ python -m asyncio
  773. asyncio REPL 3.8.0
  774. Use &quot;await&quot; directly instead of &quot;asyncio.run()&quot;.
  775. Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
  776. &gt;&gt;&gt; import asyncio
  777. &gt;&gt;&gt; await asyncio.sleep(10, result=&#39;hello&#39;)
  778. hello
  779. </pre></div>
  780. </div>
  781. <p>(Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37028">bpo-37028</a>.)</p>
  782. <p>The exception <a class="reference internal" href="../library/asyncio-exceptions.html#asyncio.CancelledError" title="asyncio.CancelledError"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.CancelledError</span></code></a> now inherits from
  783. <a class="reference internal" href="../library/exceptions.html#BaseException" title="BaseException"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseException</span></code></a> rather than <a class="reference internal" href="../library/exceptions.html#Exception" title="Exception"><code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></a> and no longer inherits
  784. from <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.CancelledError" title="concurrent.futures.CancelledError"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.CancelledError</span></code></a>.
  785. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32528">bpo-32528</a>.)</p>
  786. <p>On Windows, the default event loop is now <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.ProactorEventLoop" title="asyncio.ProactorEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProactorEventLoop</span></code></a>.
  787. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34687">bpo-34687</a>.)</p>
  788. <p><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.ProactorEventLoop" title="asyncio.ProactorEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProactorEventLoop</span></code></a> now also supports UDP.
  789. (Contributed by Adam Meily and Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29883">bpo-29883</a>.)</p>
  790. <p><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.ProactorEventLoop" title="asyncio.ProactorEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProactorEventLoop</span></code></a> can now be interrupted by
  791. <a class="reference internal" href="../library/exceptions.html#KeyboardInterrupt" title="KeyboardInterrupt"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyboardInterrupt</span></code></a> (“CTRL+C”).
  792. (Contributed by Vladimir Matveev in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23057">bpo-23057</a>.)</p>
  793. <p>Added <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.get_coro" title="asyncio.Task.get_coro"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.Task.get_coro()</span></code></a> for getting the wrapped coroutine
  794. within an <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a>.
  795. (Contributed by Alex Grönholm in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36999">bpo-36999</a>.)</p>
  796. <p>Asyncio tasks can now be named, either by passing the <code class="docutils literal notranslate"><span class="pre">name</span></code> keyword
  797. argument to <a class="reference internal" href="../library/asyncio-task.html#asyncio.create_task" title="asyncio.create_task"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.create_task()</span></code></a> or
  798. the <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">create_task()</span></code></a> event loop method, or by
  799. calling the <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.set_name" title="asyncio.Task.set_name"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_name()</span></code></a> method on the task object. The
  800. task name is visible in the <code class="docutils literal notranslate"><span class="pre">repr()</span></code> output of <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a> and
  801. can also be retrieved using the <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.get_name" title="asyncio.Task.get_name"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_name()</span></code></a> method.
  802. (Contributed by Alex Grönholm in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34270">bpo-34270</a>.)</p>
  803. <p>Added support for
  804. <a class="reference external" href="https://en.wikipedia.org/wiki/Happy_Eyeballs">Happy Eyeballs</a> to
  805. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_connection" title="asyncio.loop.create_connection"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.loop.create_connection()</span></code></a>. To specify the behavior, two new
  806. parameters have been added: <em>happy_eyeballs_delay</em> and <em>interleave</em>. The Happy
  807. Eyeballs algorithm improves responsiveness in applications that support IPv4
  808. and IPv6 by attempting to simultaneously connect using both.
  809. (Contributed by twisteroid ambassador in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33530">bpo-33530</a>.)</p>
  810. </section>
  811. <section id="builtins">
  812. <h3>builtins<a class="headerlink" href="#builtins" title="Link to this heading">¶</a></h3>
  813. <p>The <a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> built-in has been improved to accept the
  814. <code class="docutils literal notranslate"><span class="pre">ast.PyCF_ALLOW_TOP_LEVEL_AWAIT</span></code> flag. With this new flag passed,
  815. <a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> will allow top-level <code class="docutils literal notranslate"><span class="pre">await</span></code>, <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">for</span></code> and <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">with</span></code>
  816. constructs that are usually considered invalid syntax. Asynchronous code object
  817. marked with the <code class="docutils literal notranslate"><span class="pre">CO_COROUTINE</span></code> flag may then be returned.
  818. (Contributed by Matthias Bussonnier in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34616">bpo-34616</a>)</p>
  819. </section>
  820. <section id="collections">
  821. <h3>collections<a class="headerlink" href="#collections" title="Link to this heading">¶</a></h3>
  822. <p>The <a class="reference internal" href="../library/collections.html#collections.somenamedtuple._asdict" title="collections.somenamedtuple._asdict"><code class="xref py py-meth docutils literal notranslate"><span class="pre">_asdict()</span></code></a> method for
  823. <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> now returns 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> instead of a
  824. <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>. This works because regular dicts have
  825. guaranteed ordering since Python 3.7. If the extra features of
  826. <code class="xref py py-class docutils literal notranslate"><span class="pre">OrderedDict</span></code> are required, the suggested remediation is to cast the
  827. result to the desired type: <code class="docutils literal notranslate"><span class="pre">OrderedDict(nt._asdict())</span></code>.
  828. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35864">bpo-35864</a>.)</p>
  829. </section>
  830. <section id="cprofile">
  831. <h3>cProfile<a class="headerlink" href="#cprofile" title="Link to this heading">¶</a></h3>
  832. <p>The <a class="reference internal" href="../library/profile.html#profile.Profile" title="profile.Profile"><code class="xref py py-class docutils literal notranslate"><span class="pre">cProfile.Profile</span></code></a> class can now be used as a context manager.
  833. Profile a block of code by running:</p>
  834. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">cProfile</span>
  835. <span class="k">with</span> <span class="n">cProfile</span><span class="o">.</span><span class="n">Profile</span><span class="p">()</span> <span class="k">as</span> <span class="n">profiler</span><span class="p">:</span>
  836. <span class="c1"># code to be profiled</span>
  837. <span class="o">...</span>
  838. </pre></div>
  839. </div>
  840. <p>(Contributed by Scott Sanderson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29235">bpo-29235</a>.)</p>
  841. </section>
  842. <section id="csv">
  843. <h3>csv<a class="headerlink" href="#csv" title="Link to this heading">¶</a></h3>
  844. <p>The <a class="reference internal" href="../library/csv.html#csv.DictReader" title="csv.DictReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">csv.DictReader</span></code></a> now returns instances of <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> instead of
  845. a <a class="reference internal" href="../library/collections.html#collections.OrderedDict" title="collections.OrderedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.OrderedDict</span></code></a>. The tool is now faster and uses less
  846. memory while still preserving the field order.
  847. (Contributed by Michael Selik in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34003">bpo-34003</a>.)</p>
  848. </section>
  849. <section id="curses">
  850. <h3>curses<a class="headerlink" href="#curses" title="Link to this heading">¶</a></h3>
  851. <p>Added a new variable holding structured version information for the
  852. underlying ncurses library: <a class="reference internal" href="../library/curses.html#curses.ncurses_version" title="curses.ncurses_version"><code class="xref py py-data docutils literal notranslate"><span class="pre">ncurses_version</span></code></a>.
  853. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31680">bpo-31680</a>.)</p>
  854. </section>
  855. <section id="ctypes">
  856. <h3>ctypes<a class="headerlink" href="#ctypes" title="Link to this heading">¶</a></h3>
  857. <p>On Windows, <a class="reference internal" href="../library/ctypes.html#ctypes.CDLL" title="ctypes.CDLL"><code class="xref py py-class docutils literal notranslate"><span class="pre">CDLL</span></code></a> and subclasses now accept a <em>winmode</em> parameter
  858. to specify flags for the underlying <code class="docutils literal notranslate"><span class="pre">LoadLibraryEx</span></code> call. The default flags are
  859. set to only load DLL dependencies from trusted locations, including the path
  860. where the DLL is stored (if a full or partial path is used to load the initial
  861. DLL) and paths added by <a class="reference internal" href="../library/os.html#os.add_dll_directory" title="os.add_dll_directory"><code class="xref py py-func docutils literal notranslate"><span class="pre">add_dll_directory()</span></code></a>.
  862. (Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36085">bpo-36085</a>.)</p>
  863. </section>
  864. <section id="datetime">
  865. <h3>datetime<a class="headerlink" href="#datetime" title="Link to this heading">¶</a></h3>
  866. <p>Added new alternate constructors <a class="reference internal" href="../library/datetime.html#datetime.date.fromisocalendar" title="datetime.date.fromisocalendar"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.date.fromisocalendar()</span></code></a> and
  867. <a class="reference internal" href="../library/datetime.html#datetime.datetime.fromisocalendar" title="datetime.datetime.fromisocalendar"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.fromisocalendar()</span></code></a>, which construct <a class="reference internal" href="../library/datetime.html#datetime.date" title="datetime.date"><code class="xref py py-class docutils literal notranslate"><span class="pre">date</span></code></a> and
  868. <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> objects respectively from ISO year, week number, and weekday;
  869. these are the inverse of each class’s <code class="docutils literal notranslate"><span class="pre">isocalendar</span></code> method.
  870. (Contributed by Paul Ganssle in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36004">bpo-36004</a>.)</p>
  871. </section>
  872. <section id="functools">
  873. <h3>functools<a class="headerlink" href="#functools" title="Link to this heading">¶</a></h3>
  874. <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> can now be used as a straight decorator rather
  875. than as a function returning a decorator. So both of these are now supported:</p>
  876. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nd">@lru_cache</span>
  877. <span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
  878. <span class="o">...</span>
  879. <span class="nd">@lru_cache</span><span class="p">(</span><span class="n">maxsize</span><span class="o">=</span><span class="mi">256</span><span class="p">)</span>
  880. <span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
  881. <span class="o">...</span>
  882. </pre></div>
  883. </div>
  884. <p>(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36772">bpo-36772</a>.)</p>
  885. <p>Added a new <a class="reference internal" href="../library/functools.html#functools.cached_property" title="functools.cached_property"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.cached_property()</span></code></a> decorator, for computed properties
  886. cached for the life of the instance.</p>
  887. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">functools</span>
  888. <span class="kn">import</span> <span class="nn">statistics</span>
  889. <span class="k">class</span> <span class="nc">Dataset</span><span class="p">:</span>
  890. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sequence_of_numbers</span><span class="p">):</span>
  891. <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">sequence_of_numbers</span>
  892. <span class="nd">@functools</span><span class="o">.</span><span class="n">cached_property</span>
  893. <span class="k">def</span> <span class="nf">variance</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  894. <span class="k">return</span> <span class="n">statistics</span><span class="o">.</span><span class="n">variance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">)</span>
  895. </pre></div>
  896. </div>
  897. <p>(Contributed by Carl Meyer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21145">bpo-21145</a>)</p>
  898. <p>Added a new <a class="reference internal" href="../library/functools.html#functools.singledispatchmethod" title="functools.singledispatchmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.singledispatchmethod()</span></code></a> decorator that converts
  899. methods into <a class="reference internal" href="../glossary.html#term-generic-function"><span class="xref std std-term">generic functions</span></a> using
  900. <a class="reference internal" href="../glossary.html#term-single-dispatch"><span class="xref std std-term">single dispatch</span></a>:</p>
  901. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">singledispatchmethod</span>
  902. <span class="kn">from</span> <span class="nn">contextlib</span> <span class="kn">import</span> <span class="n">suppress</span>
  903. <span class="k">class</span> <span class="nc">TaskManager</span><span class="p">:</span>
  904. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tasks</span><span class="p">):</span>
  905. <span class="bp">self</span><span class="o">.</span><span class="n">tasks</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">tasks</span><span class="p">)</span>
  906. <span class="nd">@singledispatchmethod</span>
  907. <span class="k">def</span> <span class="nf">discard</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
  908. <span class="k">with</span> <span class="n">suppress</span><span class="p">(</span><span class="ne">ValueError</span><span class="p">):</span>
  909. <span class="bp">self</span><span class="o">.</span><span class="n">tasks</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
  910. <span class="nd">@discard</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>
  911. <span class="k">def</span> <span class="nf">_</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tasks</span><span class="p">):</span>
  912. <span class="n">targets</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">tasks</span><span class="p">)</span>
  913. <span class="bp">self</span><span class="o">.</span><span class="n">tasks</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">tasks</span> <span class="k">if</span> <span class="n">x</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">targets</span><span class="p">]</span>
  914. </pre></div>
  915. </div>
  916. <p>(Contributed by Ethan Smith in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32380">bpo-32380</a>)</p>
  917. </section>
  918. <section id="gc">
  919. <h3>gc<a class="headerlink" href="#gc" title="Link to this heading">¶</a></h3>
  920. <p><a class="reference internal" href="../library/gc.html#gc.get_objects" title="gc.get_objects"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_objects()</span></code></a> can now receive an optional <em>generation</em> parameter
  921. indicating a generation to get objects from.
  922. (Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36016">bpo-36016</a>.)</p>
  923. </section>
  924. <section id="gettext">
  925. <h3>gettext<a class="headerlink" href="#gettext" title="Link to this heading">¶</a></h3>
  926. <p>Added <a class="reference internal" href="../library/gettext.html#gettext.pgettext" title="gettext.pgettext"><code class="xref py py-func docutils literal notranslate"><span class="pre">pgettext()</span></code></a> and its variants.
  927. (Contributed by Franz Glasner, Éric Araujo, and Cheryl Sabella in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=2504">bpo-2504</a>.)</p>
  928. </section>
  929. <section id="gzip">
  930. <h3>gzip<a class="headerlink" href="#gzip" title="Link to this heading">¶</a></h3>
  931. <p>Added the <em>mtime</em> parameter to <a class="reference internal" href="../library/gzip.html#gzip.compress" title="gzip.compress"><code class="xref py py-func docutils literal notranslate"><span class="pre">gzip.compress()</span></code></a> for reproducible output.
  932. (Contributed by Guo Ci Teo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34898">bpo-34898</a>.)</p>
  933. <p>A <a class="reference internal" href="../library/gzip.html#gzip.BadGzipFile" title="gzip.BadGzipFile"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BadGzipFile</span></code></a> exception is now raised instead of <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>
  934. for certain types of invalid or corrupt gzip files.
  935. (Contributed by Filip Gruszczyński, Michele Orrù, and Zackery Spytz in
  936. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6584">bpo-6584</a>.)</p>
  937. </section>
  938. <section id="idle-and-idlelib">
  939. <h3>IDLE and idlelib<a class="headerlink" href="#idle-and-idlelib" title="Link to this heading">¶</a></h3>
  940. <p>Output over N lines (50 by default) is squeezed down to a button.
  941. N can be changed in the PyShell section of the General page of the
  942. Settings dialog. Fewer, but possibly extra long, lines can be squeezed by
  943. right clicking on the output. Squeezed output can be expanded in place
  944. by double-clicking the button or into the clipboard or a separate window
  945. by right-clicking the button. (Contributed by Tal Einat in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1529353">bpo-1529353</a>.)</p>
  946. <p>Add “Run Customized” to the Run menu to run a module with customized
  947. settings. Any command line arguments entered are added to sys.argv.
  948. They also re-appear in the box for the next customized run. One can also
  949. suppress the normal Shell main module restart. (Contributed by Cheryl
  950. Sabella, Terry Jan Reedy, and others in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5680">bpo-5680</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37627">bpo-37627</a>.)</p>
  951. <p>Added optional line numbers for IDLE editor windows. Windows
  952. open without line numbers unless set otherwise in the General
  953. tab of the configuration dialog. Line numbers for an existing
  954. window are shown and hidden in the Options menu.
  955. (Contributed by Tal Einat and Saimadhav Heblikar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17535">bpo-17535</a>.)</p>
  956. <p>OS native encoding is now used for converting between Python strings and Tcl
  957. objects. This allows IDLE to work with emoji and other non-BMP characters.
  958. These characters can be displayed or copied and pasted to or from the
  959. clipboard. Converting strings from Tcl to Python and back now never fails.
  960. (Many people worked on this for eight years but the problem was finally
  961. solved by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13153">bpo-13153</a>.)</p>
  962. <p>New in 3.8.1:</p>
  963. <p>Add option to toggle cursor blink off. (Contributed by Zackery Spytz
  964. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4603">bpo-4603</a>.)</p>
  965. <p>Escape key now closes IDLE completion windows. (Contributed by Johnny
  966. Najera in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38944">bpo-38944</a>.)</p>
  967. <p>The changes above have been backported to 3.7 maintenance releases.</p>
  968. <p>Add keywords to module name completion list. (Contributed by Terry J.
  969. Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37765">bpo-37765</a>.)</p>
  970. </section>
  971. <section id="inspect">
  972. <h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading">¶</a></h3>
  973. <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 can now find docstrings for <code class="docutils literal notranslate"><span class="pre">__slots__</span></code>
  974. if that attribute is 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> where the values are docstrings.
  975. This provides documentation options similar to what we already have
  976. for <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>, <a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">classmethod()</span></code></a>, and <a class="reference internal" href="../library/functions.html#staticmethod" title="staticmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">staticmethod()</span></code></a>:</p>
  977. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">AudioClip</span><span class="p">:</span>
  978. <span class="vm">__slots__</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;bit_rate&#39;</span><span class="p">:</span> <span class="s1">&#39;expressed in kilohertz to one decimal place&#39;</span><span class="p">,</span>
  979. <span class="s1">&#39;duration&#39;</span><span class="p">:</span> <span class="s1">&#39;in seconds, rounded up to an integer&#39;</span><span class="p">}</span>
  980. <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">bit_rate</span><span class="p">,</span> <span class="n">duration</span><span class="p">):</span>
  981. <span class="bp">self</span><span class="o">.</span><span class="n">bit_rate</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">bit_rate</span> <span class="o">/</span> <span class="mf">1000.0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
  982. <span class="bp">self</span><span class="o">.</span><span class="n">duration</span> <span class="o">=</span> <span class="n">ceil</span><span class="p">(</span><span class="n">duration</span><span class="p">)</span>
  983. </pre></div>
  984. </div>
  985. <p>(Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36326">bpo-36326</a>.)</p>
  986. </section>
  987. <section id="io">
  988. <h3>io<a class="headerlink" href="#io" title="Link to this heading">¶</a></h3>
  989. <p>In development mode (<a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> <code class="docutils literal notranslate"><span class="pre">env</span></code>) and in <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug build</span></a>, the
  990. <a class="reference internal" href="../library/io.html#io.IOBase" title="io.IOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.IOBase</span></code></a> finalizer now logs the exception if the <code class="docutils literal notranslate"><span class="pre">close()</span></code> method
  991. fails. The exception is ignored silently by default in release build.
  992. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18748">bpo-18748</a>.)</p>
  993. </section>
  994. <section id="itertools">
  995. <h3>itertools<a class="headerlink" href="#itertools" title="Link to this heading">¶</a></h3>
  996. <p>The <a class="reference internal" href="../library/itertools.html#itertools.accumulate" title="itertools.accumulate"><code class="xref py py-func docutils literal notranslate"><span class="pre">itertools.accumulate()</span></code></a> function added an option <em>initial</em> keyword
  997. argument to specify an initial value:</p>
  998. <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">itertools</span> <span class="kn">import</span> <span class="n">accumulate</span>
  999. <span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">accumulate</span><span class="p">([</span><span class="mi">10</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">15</span><span class="p">],</span> <span class="n">initial</span><span class="o">=</span><span class="mi">1000</span><span class="p">))</span>
  1000. <span class="go">[1000, 1010, 1015, 1045, 1060]</span>
  1001. </pre></div>
  1002. </div>
  1003. <p>(Contributed by Lisa Roach in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34659">bpo-34659</a>.)</p>
  1004. </section>
  1005. <section id="json-tool">
  1006. <h3>json.tool<a class="headerlink" href="#json-tool" title="Link to this heading">¶</a></h3>
  1007. <p>Add option <code class="docutils literal notranslate"><span class="pre">--json-lines</span></code> to parse every input line as a separate JSON object.
  1008. (Contributed by Weipeng Hong in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31553">bpo-31553</a>.)</p>
  1009. </section>
  1010. <section id="logging">
  1011. <h3>logging<a class="headerlink" href="#logging" title="Link to this heading">¶</a></h3>
  1012. <p>Added a <em>force</em> keyword argument to <a class="reference internal" href="../library/logging.html#logging.basicConfig" title="logging.basicConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">logging.basicConfig()</span></code></a>
  1013. When set to true, any existing handlers attached
  1014. to the root logger are removed and closed before carrying out the
  1015. configuration specified by the other arguments.</p>
  1016. <p>This solves a long-standing problem. Once a logger or <em>basicConfig()</em> had
  1017. been called, subsequent calls to <em>basicConfig()</em> were silently ignored.
  1018. This made it difficult to update, experiment with, or teach the various
  1019. logging configuration options using the interactive prompt or a Jupyter
  1020. notebook.</p>
  1021. <p>(Suggested by Raymond Hettinger, implemented by Donghee Na, and
  1022. reviewed by Vinay Sajip in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33897">bpo-33897</a>.)</p>
  1023. </section>
  1024. <section id="math">
  1025. <h3>math<a class="headerlink" href="#math" title="Link to this heading">¶</a></h3>
  1026. <p>Added new function <a class="reference internal" href="../library/math.html#math.dist" title="math.dist"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.dist()</span></code></a> for computing Euclidean distance
  1027. between two points. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33089">bpo-33089</a>.)</p>
  1028. <p>Expanded the <a class="reference internal" href="../library/math.html#math.hypot" title="math.hypot"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.hypot()</span></code></a> function to handle multiple dimensions.
  1029. Formerly, it only supported the 2-D case.
  1030. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33089">bpo-33089</a>.)</p>
  1031. <p>Added new function, <a class="reference internal" href="../library/math.html#math.prod" title="math.prod"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.prod()</span></code></a>, as analogous function to <a class="reference internal" href="../library/functions.html#sum" title="sum"><code class="xref py py-func docutils literal notranslate"><span class="pre">sum()</span></code></a>
  1032. that returns the product of a ‘start’ value (default: 1) times an iterable of
  1033. numbers:</p>
  1034. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">prior</span> <span class="o">=</span> <span class="mf">0.8</span>
  1035. <span class="gp">&gt;&gt;&gt; </span><span class="n">likelihoods</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.625</span><span class="p">,</span> <span class="mf">0.84</span><span class="p">,</span> <span class="mf">0.30</span><span class="p">]</span>
  1036. <span class="gp">&gt;&gt;&gt; </span><span class="n">math</span><span class="o">.</span><span class="n">prod</span><span class="p">(</span><span class="n">likelihoods</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="n">prior</span><span class="p">)</span>
  1037. <span class="go">0.126</span>
  1038. </pre></div>
  1039. </div>
  1040. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35606">bpo-35606</a>.)</p>
  1041. <p>Added two new combinatoric functions <a class="reference internal" href="../library/math.html#math.perm" title="math.perm"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.perm()</span></code></a> and <a class="reference internal" href="../library/math.html#math.comb" title="math.comb"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.comb()</span></code></a>:</p>
  1042. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">math</span><span class="o">.</span><span class="n">perm</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span> <span class="c1"># Permutations of 10 things taken 3 at a time</span>
  1043. <span class="go">720</span>
  1044. <span class="gp">&gt;&gt;&gt; </span><span class="n">math</span><span class="o">.</span><span class="n">comb</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span> <span class="c1"># Combinations of 10 things taken 3 at a time</span>
  1045. <span class="go">120</span>
  1046. </pre></div>
  1047. </div>
  1048. <p>(Contributed by Yash Aggarwal, Keller Fuchs, Serhiy Storchaka, and Raymond
  1049. Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37128">bpo-37128</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37178">bpo-37178</a>, and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35431">bpo-35431</a>.)</p>
  1050. <p>Added a new function <a class="reference internal" href="../library/math.html#math.isqrt" title="math.isqrt"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.isqrt()</span></code></a> for computing accurate integer square
  1051. roots without conversion to floating point. The new function supports
  1052. arbitrarily large integers. It is faster than <code class="docutils literal notranslate"><span class="pre">floor(sqrt(n))</span></code> but slower
  1053. than <a class="reference internal" href="../library/math.html#math.sqrt" title="math.sqrt"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.sqrt()</span></code></a>:</p>
  1054. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">r</span> <span class="o">=</span> <span class="mi">650320427</span>
  1055. <span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">r</span> <span class="o">**</span> <span class="mi">2</span>
  1056. <span class="gp">&gt;&gt;&gt; </span><span class="n">isqrt</span><span class="p">(</span><span class="n">s</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="c1"># correct</span>
  1057. <span class="go">650320426</span>
  1058. <span class="gp">&gt;&gt;&gt; </span><span class="n">floor</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">s</span> <span class="o">-</span> <span class="mi">1</span><span class="p">))</span> <span class="c1"># incorrect</span>
  1059. <span class="go">650320427</span>
  1060. </pre></div>
  1061. </div>
  1062. <p>(Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36887">bpo-36887</a>.)</p>
  1063. <p>The function <a class="reference internal" href="../library/math.html#math.factorial" title="math.factorial"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.factorial()</span></code></a> no longer accepts arguments that are not
  1064. int-like. (Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33083">bpo-33083</a>.)</p>
  1065. </section>
  1066. <section id="mmap">
  1067. <h3>mmap<a class="headerlink" href="#mmap" title="Link to this heading">¶</a></h3>
  1068. <p>The <a class="reference internal" href="../library/mmap.html#mmap.mmap" title="mmap.mmap"><code class="xref py py-class docutils literal notranslate"><span class="pre">mmap.mmap</span></code></a> class now has an <a class="reference internal" href="../library/mmap.html#mmap.mmap.madvise" title="mmap.mmap.madvise"><code class="xref py py-meth docutils literal notranslate"><span class="pre">madvise()</span></code></a> method to
  1069. access the <code class="docutils literal notranslate"><span class="pre">madvise()</span></code> system call.
  1070. (Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32941">bpo-32941</a>.)</p>
  1071. </section>
  1072. <section id="multiprocessing">
  1073. <h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Link to this heading">¶</a></h3>
  1074. <p>Added new <a class="reference internal" href="../library/multiprocessing.shared_memory.html#module-multiprocessing.shared_memory" title="multiprocessing.shared_memory: Provides shared memory for direct access across processes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing.shared_memory</span></code></a> module.
  1075. (Contributed by Davin Potts in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35813">bpo-35813</a>.)</p>
  1076. <p>On macOS, the <em>spawn</em> start method is now used by default.
  1077. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33725">bpo-33725</a>.)</p>
  1078. </section>
  1079. <section id="os">
  1080. <h3>os<a class="headerlink" href="#os" title="Link to this heading">¶</a></h3>
  1081. <p>Added new function <a class="reference internal" href="../library/os.html#os.add_dll_directory" title="os.add_dll_directory"><code class="xref py py-func docutils literal notranslate"><span class="pre">add_dll_directory()</span></code></a> on Windows for providing
  1082. additional search paths for native dependencies when importing extension
  1083. modules or loading DLLs using <a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a>.
  1084. (Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36085">bpo-36085</a>.)</p>
  1085. <p>A new <a class="reference internal" href="../library/os.html#os.memfd_create" title="os.memfd_create"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.memfd_create()</span></code></a> function was added to wrap the
  1086. <code class="docutils literal notranslate"><span class="pre">memfd_create()</span></code> syscall.
  1087. (Contributed by Zackery Spytz and Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26836">bpo-26836</a>.)</p>
  1088. <p>On Windows, much of the manual logic for handling reparse points (including
  1089. symlinks and directory junctions) has been delegated to the operating system.
  1090. Specifically, <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> will now traverse anything supported by the
  1091. operating system, while <a class="reference internal" href="../library/os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.lstat()</span></code></a> will only open reparse points that
  1092. identify as “name surrogates” while others are opened as for <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>.
  1093. In all cases, <code class="xref py py-attr docutils literal notranslate"><span class="pre">stat_result.st_mode</span></code> will only have <code class="docutils literal notranslate"><span class="pre">S_IFLNK</span></code> set for
  1094. symbolic links and not other kinds of reparse points. To identify other kinds
  1095. of reparse point, check the new <code class="xref py py-attr docutils literal notranslate"><span class="pre">stat_result.st_reparse_tag</span></code> attribute.</p>
  1096. <p>On Windows, <a class="reference internal" href="../library/os.html#os.readlink" title="os.readlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.readlink()</span></code></a> is now able to read directory junctions. Note
  1097. that <a class="reference internal" href="../library/os.path.html#os.path.islink" title="os.path.islink"><code class="xref py py-func docutils literal notranslate"><span class="pre">islink()</span></code></a> will return <code class="docutils literal notranslate"><span class="pre">False</span></code> for directory junctions,
  1098. and so code that checks <code class="docutils literal notranslate"><span class="pre">islink</span></code> first will continue to treat junctions as
  1099. directories, while code that handles errors from <a class="reference internal" href="../library/os.html#os.readlink" title="os.readlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.readlink()</span></code></a> may now
  1100. treat junctions as links.</p>
  1101. <p>(Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37834">bpo-37834</a>.)</p>
  1102. </section>
  1103. <section id="os-path">
  1104. <h3>os.path<a class="headerlink" href="#os-path" title="Link to this heading">¶</a></h3>
  1105. <p><a class="reference internal" href="../library/os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> functions that return a boolean result like
  1106. <a class="reference internal" href="../library/os.path.html#os.path.exists" title="os.path.exists"><code class="xref py py-func docutils literal notranslate"><span class="pre">exists()</span></code></a>, <a class="reference internal" href="../library/os.path.html#os.path.lexists" title="os.path.lexists"><code class="xref py py-func docutils literal notranslate"><span class="pre">lexists()</span></code></a>, <a class="reference internal" href="../library/os.path.html#os.path.isdir" title="os.path.isdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">isdir()</span></code></a>,
  1107. <a class="reference internal" href="../library/os.path.html#os.path.isfile" title="os.path.isfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">isfile()</span></code></a>, <a class="reference internal" href="../library/os.path.html#os.path.islink" title="os.path.islink"><code class="xref py py-func docutils literal notranslate"><span class="pre">islink()</span></code></a>, and <a class="reference internal" href="../library/os.path.html#os.path.ismount" title="os.path.ismount"><code class="xref py py-func docutils literal notranslate"><span class="pre">ismount()</span></code></a>
  1108. now return <code class="docutils literal notranslate"><span class="pre">False</span></code> instead of 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> or its subclasses
  1109. <a class="reference internal" href="../library/exceptions.html#UnicodeEncodeError" title="UnicodeEncodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeEncodeError</span></code></a> and <a class="reference internal" href="../library/exceptions.html#UnicodeDecodeError" title="UnicodeDecodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeDecodeError</span></code></a> for paths that contain
  1110. characters or bytes unrepresentable at the OS level.
  1111. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33721">bpo-33721</a>.)</p>
  1112. <p><a class="reference internal" href="../library/os.path.html#os.path.expanduser" title="os.path.expanduser"><code class="xref py py-func docutils literal notranslate"><span class="pre">expanduser()</span></code></a> on Windows now prefers the <span class="target" id="index-13"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">USERPROFILE</span></code>
  1113. environment variable and does not use <span class="target" id="index-14"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">HOME</span></code>, which is not normally set
  1114. for regular user accounts.
  1115. (Contributed by Anthony Sottile in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36264">bpo-36264</a>.)</p>
  1116. <p><a class="reference internal" href="../library/os.path.html#os.path.isdir" title="os.path.isdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">isdir()</span></code></a> on Windows no longer returns <code class="docutils literal notranslate"><span class="pre">True</span></code> for a link to a
  1117. non-existent directory.</p>
  1118. <p><a class="reference internal" href="../library/os.path.html#os.path.realpath" title="os.path.realpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">realpath()</span></code></a> on Windows now resolves reparse points, including
  1119. symlinks and directory junctions.</p>
  1120. <p>(Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37834">bpo-37834</a>.)</p>
  1121. </section>
  1122. <section id="pathlib">
  1123. <h3>pathlib<a class="headerlink" href="#pathlib" title="Link to this heading">¶</a></h3>
  1124. <p><a class="reference internal" href="../library/pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> methods that return a boolean result like
  1125. <a class="reference internal" href="../library/pathlib.html#pathlib.Path.exists" title="pathlib.Path.exists"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exists()</span></code></a>, <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_dir" title="pathlib.Path.is_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_dir()</span></code></a>,
  1126. <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_file" title="pathlib.Path.is_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_file()</span></code></a>, <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_mount" title="pathlib.Path.is_mount"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_mount()</span></code></a>,
  1127. <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_symlink" title="pathlib.Path.is_symlink"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_symlink()</span></code></a>, <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_block_device" title="pathlib.Path.is_block_device"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_block_device()</span></code></a>,
  1128. <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_char_device" title="pathlib.Path.is_char_device"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_char_device()</span></code></a>, <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_fifo" title="pathlib.Path.is_fifo"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_fifo()</span></code></a>,
  1129. <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_socket" title="pathlib.Path.is_socket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_socket()</span></code></a> now return <code class="docutils literal notranslate"><span class="pre">False</span></code> instead of raising
  1130. <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> or its subclass <a class="reference internal" href="../library/exceptions.html#UnicodeEncodeError" title="UnicodeEncodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeEncodeError</span></code></a> for paths that
  1131. contain characters unrepresentable at the OS level.
  1132. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33721">bpo-33721</a>.)</p>
  1133. <p>Added <code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.link_to()</span></code> which creates a hard link pointing
  1134. to a path.
  1135. (Contributed by Joannah Nanjekye in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26978">bpo-26978</a>)
  1136. Note that <code class="docutils literal notranslate"><span class="pre">link_to</span></code> was deprecated in 3.10 and removed in 3.12 in
  1137. favor of a <code class="docutils literal notranslate"><span class="pre">hardlink_to</span></code> method added in 3.10 which matches the
  1138. semantics of the existing <code class="docutils literal notranslate"><span class="pre">symlink_to</span></code> method.</p>
  1139. </section>
  1140. <section id="pickle">
  1141. <h3>pickle<a class="headerlink" href="#pickle" title="Link to this heading">¶</a></h3>
  1142. <p><a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> extensions subclassing the C-optimized <a class="reference internal" href="../library/pickle.html#pickle.Pickler" title="pickle.Pickler"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pickler</span></code></a>
  1143. can now override the pickling logic of functions and classes by defining the
  1144. special <a class="reference internal" href="../library/pickle.html#pickle.Pickler.reducer_override" title="pickle.Pickler.reducer_override"><code class="xref py py-meth docutils literal notranslate"><span class="pre">reducer_override()</span></code></a> method.
  1145. (Contributed by Pierre Glaser and Olivier Grisel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35900">bpo-35900</a>.)</p>
  1146. </section>
  1147. <section id="plistlib">
  1148. <h3>plistlib<a class="headerlink" href="#plistlib" title="Link to this heading">¶</a></h3>
  1149. <p>Added new <a class="reference internal" href="../library/plistlib.html#plistlib.UID" title="plistlib.UID"><code class="xref py py-class docutils literal notranslate"><span class="pre">plistlib.UID</span></code></a> and enabled support for reading and writing
  1150. NSKeyedArchiver-encoded binary plists.
  1151. (Contributed by Jon Janzen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26707">bpo-26707</a>.)</p>
  1152. </section>
  1153. <section id="pprint">
  1154. <h3>pprint<a class="headerlink" href="#pprint" title="Link to this heading">¶</a></h3>
  1155. <p>The <a class="reference internal" href="../library/pprint.html#module-pprint" title="pprint: Data pretty printer."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pprint</span></code></a> module added a <em>sort_dicts</em> parameter to several functions.
  1156. By default, those functions continue to sort dictionaries before rendering or
  1157. printing. However, if <em>sort_dicts</em> is set to false, the dictionaries retain
  1158. the order that keys were inserted. This can be useful for comparison to JSON
  1159. inputs during debugging.</p>
  1160. <p>In addition, there is a convenience new function, <a class="reference internal" href="../library/pprint.html#pprint.pp" title="pprint.pp"><code class="xref py py-func docutils literal notranslate"><span class="pre">pprint.pp()</span></code></a> that is
  1161. like <a class="reference internal" href="../library/pprint.html#pprint.pprint" title="pprint.pprint"><code class="xref py py-func docutils literal notranslate"><span class="pre">pprint.pprint()</span></code></a> but with <em>sort_dicts</em> defaulting to <code class="docutils literal notranslate"><span class="pre">False</span></code>:</p>
  1162. <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">pprint</span> <span class="kn">import</span> <span class="n">pprint</span><span class="p">,</span> <span class="n">pp</span>
  1163. <span class="gp">&gt;&gt;&gt; </span><span class="n">d</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">source</span><span class="o">=</span><span class="s1">&#39;input.txt&#39;</span><span class="p">,</span> <span class="n">operation</span><span class="o">=</span><span class="s1">&#39;filter&#39;</span><span class="p">,</span> <span class="n">destination</span><span class="o">=</span><span class="s1">&#39;output.txt&#39;</span><span class="p">)</span>
  1164. <span class="gp">&gt;&gt;&gt; </span><span class="n">pp</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">40</span><span class="p">)</span> <span class="c1"># Original order</span>
  1165. <span class="go">{&#39;source&#39;: &#39;input.txt&#39;,</span>
  1166. <span class="go"> &#39;operation&#39;: &#39;filter&#39;,</span>
  1167. <span class="go"> &#39;destination&#39;: &#39;output.txt&#39;}</span>
  1168. <span class="gp">&gt;&gt;&gt; </span><span class="n">pprint</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">40</span><span class="p">)</span> <span class="c1"># Keys sorted alphabetically</span>
  1169. <span class="go">{&#39;destination&#39;: &#39;output.txt&#39;,</span>
  1170. <span class="go"> &#39;operation&#39;: &#39;filter&#39;,</span>
  1171. <span class="go"> &#39;source&#39;: &#39;input.txt&#39;}</span>
  1172. </pre></div>
  1173. </div>
  1174. <p>(Contributed by Rémi Lapeyre in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30670">bpo-30670</a>.)</p>
  1175. </section>
  1176. <section id="py-compile">
  1177. <h3>py_compile<a class="headerlink" href="#py-compile" title="Link to this heading">¶</a></h3>
  1178. <p><a class="reference internal" href="../library/py_compile.html#py_compile.compile" title="py_compile.compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">py_compile.compile()</span></code></a> now supports silent mode.
  1179. (Contributed by Joannah Nanjekye in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22640">bpo-22640</a>.)</p>
  1180. </section>
  1181. <section id="shlex">
  1182. <h3>shlex<a class="headerlink" href="#shlex" title="Link to this heading">¶</a></h3>
  1183. <p>The new <a class="reference internal" href="../library/shlex.html#shlex.join" title="shlex.join"><code class="xref py py-func docutils literal notranslate"><span class="pre">shlex.join()</span></code></a> function acts as the inverse of <a class="reference internal" href="../library/shlex.html#shlex.split" title="shlex.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">shlex.split()</span></code></a>.
  1184. (Contributed by Bo Bayles in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32102">bpo-32102</a>.)</p>
  1185. </section>
  1186. <section id="shutil">
  1187. <h3>shutil<a class="headerlink" href="#shutil" title="Link to this heading">¶</a></h3>
  1188. <p><a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copytree()</span></code></a> now accepts a new <code class="docutils literal notranslate"><span class="pre">dirs_exist_ok</span></code> keyword argument.
  1189. (Contributed by Josh Bronson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20849">bpo-20849</a>.)</p>
  1190. <p><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">shutil.make_archive()</span></code></a> now defaults to the modern pax (POSIX.1-2001)
  1191. format for new archives to improve portability and standards conformance,
  1192. inherited from the corresponding change to the <a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a> module.
  1193. (Contributed by C.A.M. Gerlach in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30661">bpo-30661</a>.)</p>
  1194. <p><a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.rmtree()</span></code></a> on Windows now removes directory junctions without
  1195. recursively removing their contents first.
  1196. (Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37834">bpo-37834</a>.)</p>
  1197. </section>
  1198. <section id="socket">
  1199. <h3>socket<a class="headerlink" href="#socket" title="Link to this heading">¶</a></h3>
  1200. <p>Added <a class="reference internal" href="../library/socket.html#socket.create_server" title="socket.create_server"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_server()</span></code></a> and <a class="reference internal" href="../library/socket.html#socket.has_dualstack_ipv6" title="socket.has_dualstack_ipv6"><code class="xref py py-meth docutils literal notranslate"><span class="pre">has_dualstack_ipv6()</span></code></a>
  1201. convenience functions to automate the necessary tasks usually involved when
  1202. creating a server socket, including accepting both IPv4 and IPv6 connections
  1203. on the same socket. (Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17561">bpo-17561</a>.)</p>
  1204. <p>The <a class="reference internal" href="../library/socket.html#socket.if_nameindex" title="socket.if_nameindex"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.if_nameindex()</span></code></a>, <a class="reference internal" href="../library/socket.html#socket.if_nametoindex" title="socket.if_nametoindex"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.if_nametoindex()</span></code></a>, and
  1205. <a class="reference internal" href="../library/socket.html#socket.if_indextoname" title="socket.if_indextoname"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.if_indextoname()</span></code></a> functions have been implemented on Windows.
  1206. (Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37007">bpo-37007</a>.)</p>
  1207. </section>
  1208. <section id="ssl">
  1209. <h3>ssl<a class="headerlink" href="#ssl" title="Link to this heading">¶</a></h3>
  1210. <p>Added <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.post_handshake_auth" title="ssl.SSLContext.post_handshake_auth"><code class="xref py py-attr docutils literal notranslate"><span class="pre">post_handshake_auth</span></code></a> to enable and
  1211. <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.verify_client_post_handshake" title="ssl.SSLSocket.verify_client_post_handshake"><code class="xref py py-meth docutils literal notranslate"><span class="pre">verify_client_post_handshake()</span></code></a> to initiate TLS 1.3
  1212. post-handshake authentication.
  1213. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34670">bpo-34670</a>.)</p>
  1214. </section>
  1215. <section id="statistics">
  1216. <h3>statistics<a class="headerlink" href="#statistics" title="Link to this heading">¶</a></h3>
  1217. <p>Added <a class="reference internal" href="../library/statistics.html#statistics.fmean" title="statistics.fmean"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.fmean()</span></code></a> as a faster, floating point variant of
  1218. <a class="reference internal" href="../library/statistics.html#statistics.mean" title="statistics.mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.mean()</span></code></a>. (Contributed by Raymond Hettinger and
  1219. Steven D’Aprano in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35904">bpo-35904</a>.)</p>
  1220. <p>Added <a class="reference internal" href="../library/statistics.html#statistics.geometric_mean" title="statistics.geometric_mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.geometric_mean()</span></code></a>
  1221. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27181">bpo-27181</a>.)</p>
  1222. <p>Added <a class="reference internal" href="../library/statistics.html#statistics.multimode" title="statistics.multimode"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.multimode()</span></code></a> that returns a list of the most
  1223. common values. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35892">bpo-35892</a>.)</p>
  1224. <p>Added <a class="reference internal" href="../library/statistics.html#statistics.quantiles" title="statistics.quantiles"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.quantiles()</span></code></a> that divides data or a distribution
  1225. in to equiprobable intervals (e.g. quartiles, deciles, or percentiles).
  1226. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36546">bpo-36546</a>.)</p>
  1227. <p>Added <a class="reference internal" href="../library/statistics.html#statistics.NormalDist" title="statistics.NormalDist"><code class="xref py py-class docutils literal notranslate"><span class="pre">statistics.NormalDist</span></code></a>, a tool for creating
  1228. and manipulating normal distributions of a random variable.
  1229. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36018">bpo-36018</a>.)</p>
  1230. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">temperature_feb</span> <span class="o">=</span> <span class="n">NormalDist</span><span class="o">.</span><span class="n">from_samples</span><span class="p">([</span><span class="mi">4</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="o">-</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">14</span><span class="p">])</span>
  1231. <span class="gp">&gt;&gt;&gt; </span><span class="n">temperature_feb</span><span class="o">.</span><span class="n">mean</span>
  1232. <span class="go">6.0</span>
  1233. <span class="gp">&gt;&gt;&gt; </span><span class="n">temperature_feb</span><span class="o">.</span><span class="n">stdev</span>
  1234. <span class="go">6.356099432828281</span>
  1235. <span class="gp">&gt;&gt;&gt; </span><span class="n">temperature_feb</span><span class="o">.</span><span class="n">cdf</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="c1"># Chance of being under 3 degrees</span>
  1236. <span class="go">0.3184678262814532</span>
  1237. <span class="gp">&gt;&gt;&gt; </span><span class="c1"># Relative chance of being 7 degrees versus 10 degrees</span>
  1238. <span class="gp">&gt;&gt;&gt; </span><span class="n">temperature_feb</span><span class="o">.</span><span class="n">pdf</span><span class="p">(</span><span class="mi">7</span><span class="p">)</span> <span class="o">/</span> <span class="n">temperature_feb</span><span class="o">.</span><span class="n">pdf</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
  1239. <span class="go">1.2039930378537762</span>
  1240. <span class="gp">&gt;&gt;&gt; </span><span class="n">el_niño</span> <span class="o">=</span> <span class="n">NormalDist</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mf">2.5</span><span class="p">)</span>
  1241. <span class="gp">&gt;&gt;&gt; </span><span class="n">temperature_feb</span> <span class="o">+=</span> <span class="n">el_niño</span> <span class="c1"># Add in a climate effect</span>
  1242. <span class="gp">&gt;&gt;&gt; </span><span class="n">temperature_feb</span>
  1243. <span class="go">NormalDist(mu=10.0, sigma=6.830080526611674)</span>
  1244. <span class="gp">&gt;&gt;&gt; </span><span class="n">temperature_feb</span> <span class="o">*</span> <span class="p">(</span><span class="mi">9</span><span class="o">/</span><span class="mi">5</span><span class="p">)</span> <span class="o">+</span> <span class="mi">32</span> <span class="c1"># Convert to Fahrenheit</span>
  1245. <span class="go">NormalDist(mu=50.0, sigma=12.294144947901014)</span>
  1246. <span class="gp">&gt;&gt;&gt; </span><span class="n">temperature_feb</span><span class="o">.</span><span class="n">samples</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="c1"># Generate random samples</span>
  1247. <span class="go">[7.672102882379219, 12.000027119750287, 4.647488369766392]</span>
  1248. </pre></div>
  1249. </div>
  1250. </section>
  1251. <section id="sys">
  1252. <h3>sys<a class="headerlink" href="#sys" title="Link to this heading">¶</a></h3>
  1253. <p>Add new <a class="reference internal" href="../library/sys.html#sys.unraisablehook" title="sys.unraisablehook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.unraisablehook()</span></code></a> function which can be overridden to control
  1254. how “unraisable exceptions” are handled. It is called when an exception has
  1255. occurred but there is no way for Python to handle it. For example, when a
  1256. destructor raises an exception or during garbage collection
  1257. (<a class="reference internal" href="../library/gc.html#gc.collect" title="gc.collect"><code class="xref py py-func docutils literal notranslate"><span class="pre">gc.collect()</span></code></a>).
  1258. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36829">bpo-36829</a>.)</p>
  1259. </section>
  1260. <section id="tarfile">
  1261. <h3>tarfile<a class="headerlink" href="#tarfile" title="Link to this heading">¶</a></h3>
  1262. <p>The <a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a> module now defaults to the modern pax (POSIX.1-2001)
  1263. format for new archives, instead of the previous GNU-specific one.
  1264. This improves cross-platform portability with a consistent encoding (UTF-8)
  1265. in a standardized and extensible format, and offers several other benefits.
  1266. (Contributed by C.A.M. Gerlach in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36268">bpo-36268</a>.)</p>
  1267. </section>
  1268. <section id="threading">
  1269. <h3>threading<a class="headerlink" href="#threading" title="Link to this heading">¶</a></h3>
  1270. <p>Add a new <a class="reference internal" href="../library/threading.html#threading.excepthook" title="threading.excepthook"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.excepthook()</span></code></a> function which handles uncaught
  1271. <a class="reference internal" href="../library/threading.html#threading.Thread.run" title="threading.Thread.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Thread.run()</span></code></a> exception. It can be overridden to control how
  1272. uncaught <a class="reference internal" href="../library/threading.html#threading.Thread.run" title="threading.Thread.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Thread.run()</span></code></a> exceptions are handled.
  1273. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1230540">bpo-1230540</a>.)</p>
  1274. <p>Add a new <a class="reference internal" href="../library/threading.html#threading.get_native_id" title="threading.get_native_id"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.get_native_id()</span></code></a> function and
  1275. a <a class="reference internal" href="../library/threading.html#threading.Thread.native_id" title="threading.Thread.native_id"><code class="xref py py-data docutils literal notranslate"><span class="pre">native_id</span></code></a>
  1276. attribute to the <a class="reference internal" href="../library/threading.html#threading.Thread" title="threading.Thread"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Thread</span></code></a> class. These return the native
  1277. integral Thread ID of the current thread assigned by the kernel.
  1278. This feature is only available on certain platforms, see
  1279. <a class="reference internal" href="../library/threading.html#threading.get_native_id" title="threading.get_native_id"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_native_id</span></code></a> for more information.
  1280. (Contributed by Jake Tesler in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36084">bpo-36084</a>.)</p>
  1281. </section>
  1282. <section id="tokenize">
  1283. <h3>tokenize<a class="headerlink" href="#tokenize" title="Link to this heading">¶</a></h3>
  1284. <p>The <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> module now implicitly emits a <code class="docutils literal notranslate"><span class="pre">NEWLINE</span></code> token when
  1285. provided with input that does not have a trailing new line. This behavior
  1286. now matches what the C tokenizer does internally.
  1287. (Contributed by Ammar Askar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33899">bpo-33899</a>.)</p>
  1288. </section>
  1289. <section id="tkinter">
  1290. <h3>tkinter<a class="headerlink" href="#tkinter" title="Link to this heading">¶</a></h3>
  1291. <p>Added methods <code class="xref py py-meth docutils literal notranslate"><span class="pre">selection_from()</span></code>,
  1292. <code class="xref py py-meth docutils literal notranslate"><span class="pre">selection_present()</span></code>,
  1293. <code class="xref py py-meth docutils literal notranslate"><span class="pre">selection_range()</span></code> and
  1294. <code class="xref py py-meth docutils literal notranslate"><span class="pre">selection_to()</span></code>
  1295. in the <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.Spinbox</span></code> class.
  1296. (Contributed by Juliette Monsel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34829">bpo-34829</a>.)</p>
  1297. <p>Added method <code class="xref py py-meth docutils literal notranslate"><span class="pre">moveto()</span></code>
  1298. in the <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.Canvas</span></code> class.
  1299. (Contributed by Juliette Monsel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23831">bpo-23831</a>.)</p>
  1300. <p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.PhotoImage</span></code> class now has
  1301. <code class="xref py py-meth docutils literal notranslate"><span class="pre">transparency_get()</span></code> and
  1302. <code class="xref py py-meth docutils literal notranslate"><span class="pre">transparency_set()</span></code> methods. (Contributed by
  1303. Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25451">bpo-25451</a>.)</p>
  1304. </section>
  1305. <section id="time">
  1306. <h3>time<a class="headerlink" href="#time" title="Link to this heading">¶</a></h3>
  1307. <p>Added new clock <a class="reference internal" href="../library/time.html#time.CLOCK_UPTIME_RAW" title="time.CLOCK_UPTIME_RAW"><code class="xref py py-const docutils literal notranslate"><span class="pre">CLOCK_UPTIME_RAW</span></code></a> for macOS 10.12.
  1308. (Contributed by Joannah Nanjekye in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35702">bpo-35702</a>.)</p>
  1309. </section>
  1310. <section id="typing">
  1311. <h3>typing<a class="headerlink" href="#typing" title="Link to this heading">¶</a></h3>
  1312. <p>The <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module incorporates several new features:</p>
  1313. <ul>
  1314. <li><p>A dictionary type with per-key types. See <span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0589/"><strong>PEP 589</strong></a> and
  1315. <a class="reference internal" href="../library/typing.html#typing.TypedDict" title="typing.TypedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.TypedDict</span></code></a>.
  1316. TypedDict uses only string keys. By default, every key is required
  1317. to be present. Specify “total=False” to allow keys to be optional:</p>
  1318. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Location</span><span class="p">(</span><span class="n">TypedDict</span><span class="p">,</span> <span class="n">total</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
  1319. <span class="n">lat_long</span><span class="p">:</span> <span class="nb">tuple</span>
  1320. <span class="n">grid_square</span><span class="p">:</span> <span class="nb">str</span>
  1321. <span class="n">xy_coordinate</span><span class="p">:</span> <span class="nb">tuple</span>
  1322. </pre></div>
  1323. </div>
  1324. </li>
  1325. <li><p>Literal types. See <span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0586/"><strong>PEP 586</strong></a> and <a class="reference internal" href="../library/typing.html#typing.Literal" title="typing.Literal"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Literal</span></code></a>.
  1326. Literal types indicate that a parameter or return value
  1327. is constrained to one or more specific literal values:</p>
  1328. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">get_status</span><span class="p">(</span><span class="n">port</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Literal</span><span class="p">[</span><span class="s1">&#39;connected&#39;</span><span class="p">,</span> <span class="s1">&#39;disconnected&#39;</span><span class="p">]:</span>
  1329. <span class="o">...</span>
  1330. </pre></div>
  1331. </div>
  1332. </li>
  1333. <li><p>“Final” variables, functions, methods and classes. See <span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0591/"><strong>PEP 591</strong></a>,
  1334. <a class="reference internal" href="../library/typing.html#typing.Final" title="typing.Final"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Final</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.final" title="typing.final"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.final()</span></code></a>.
  1335. The final qualifier instructs a static type checker to restrict
  1336. subclassing, overriding, or reassignment:</p>
  1337. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">pi</span><span class="p">:</span> <span class="n">Final</span><span class="p">[</span><span class="nb">float</span><span class="p">]</span> <span class="o">=</span> <span class="mf">3.1415926536</span>
  1338. </pre></div>
  1339. </div>
  1340. </li>
  1341. <li><p>Protocol definitions. See <span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0544/"><strong>PEP 544</strong></a>, <a class="reference internal" href="../library/typing.html#typing.Protocol" title="typing.Protocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Protocol</span></code></a> and
  1342. <a class="reference internal" href="../library/typing.html#typing.runtime_checkable" title="typing.runtime_checkable"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.runtime_checkable()</span></code></a>. Simple ABCs like
  1343. <a class="reference internal" href="../library/typing.html#typing.SupportsInt" title="typing.SupportsInt"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.SupportsInt</span></code></a> are now <code class="docutils literal notranslate"><span class="pre">Protocol</span></code> subclasses.</p></li>
  1344. <li><p>New protocol class <a class="reference internal" href="../library/typing.html#typing.SupportsIndex" title="typing.SupportsIndex"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.SupportsIndex</span></code></a>.</p></li>
  1345. <li><p>New functions <a class="reference internal" href="../library/typing.html#typing.get_origin" title="typing.get_origin"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_origin()</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.get_args" title="typing.get_args"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_args()</span></code></a>.</p></li>
  1346. </ul>
  1347. </section>
  1348. <section id="unicodedata">
  1349. <h3>unicodedata<a class="headerlink" href="#unicodedata" title="Link to this heading">¶</a></h3>
  1350. <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 has been upgraded to use the <a class="reference external" href="https://blog.unicode.org/2019/05/unicode-12-1-en.html">Unicode 12.1.0</a> release.</p>
  1351. <p>New function <a class="reference internal" href="../library/unicodedata.html#unicodedata.is_normalized" title="unicodedata.is_normalized"><code class="xref py py-func docutils literal notranslate"><span class="pre">is_normalized()</span></code></a> can be used to verify a string
  1352. is in a specific normal form, often much faster than by actually normalizing
  1353. the string. (Contributed by Max Belanger, David Euresti, and Greg Price in
  1354. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32285">bpo-32285</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37966">bpo-37966</a>).</p>
  1355. </section>
  1356. <section id="unittest">
  1357. <h3>unittest<a class="headerlink" href="#unittest" title="Link to this heading">¶</a></h3>
  1358. <p>Added <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.AsyncMock" title="unittest.mock.AsyncMock"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncMock</span></code></a> to support an asynchronous version of
  1359. <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>. Appropriate new assert functions for testing
  1360. have been added as well.
  1361. (Contributed by Lisa Roach in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26467">bpo-26467</a>).</p>
  1362. <p>Added <a class="reference internal" href="../library/unittest.html#unittest.addModuleCleanup" title="unittest.addModuleCleanup"><code class="xref py py-func docutils literal notranslate"><span class="pre">addModuleCleanup()</span></code></a> and
  1363. <a class="reference internal" href="../library/unittest.html#unittest.TestCase.addClassCleanup" title="unittest.TestCase.addClassCleanup"><code class="xref py py-meth docutils literal notranslate"><span class="pre">addClassCleanup()</span></code></a> to unittest to support
  1364. cleanups for <code class="xref py py-func docutils literal notranslate"><span class="pre">setUpModule()</span></code> and
  1365. <a class="reference internal" href="../library/unittest.html#unittest.TestCase.setUpClass" title="unittest.TestCase.setUpClass"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setUpClass()</span></code></a>.
  1366. (Contributed by Lisa Roach in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24412">bpo-24412</a>.)</p>
  1367. <p>Several mock assert functions now also print a list of actual calls upon
  1368. failure. (Contributed by Petter Strandmark in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35047">bpo-35047</a>.)</p>
  1369. <p><a class="reference internal" href="../library/unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code></a> module gained support for coroutines to be used as test cases
  1370. with <a class="reference internal" href="../library/unittest.html#unittest.IsolatedAsyncioTestCase" title="unittest.IsolatedAsyncioTestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">unittest.IsolatedAsyncioTestCase</span></code></a>.
  1371. (Contributed by Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32972">bpo-32972</a>.)</p>
  1372. <p>Example:</p>
  1373. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">unittest</span>
  1374. <span class="k">class</span> <span class="nc">TestRequest</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">IsolatedAsyncioTestCase</span><span class="p">):</span>
  1375. <span class="k">async</span> <span class="k">def</span> <span class="nf">asyncSetUp</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  1376. <span class="bp">self</span><span class="o">.</span><span class="n">connection</span> <span class="o">=</span> <span class="k">await</span> <span class="n">AsyncConnection</span><span class="p">()</span>
  1377. <span class="k">async</span> <span class="k">def</span> <span class="nf">test_get</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  1378. <span class="n">response</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;https://example.com&quot;</span><span class="p">)</span>
  1379. <span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span><span class="p">,</span> <span class="mi">200</span><span class="p">)</span>
  1380. <span class="k">async</span> <span class="k">def</span> <span class="nf">asyncTearDown</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  1381. <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
  1382. <span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
  1383. <span class="n">unittest</span><span class="o">.</span><span class="n">main</span><span class="p">()</span>
  1384. </pre></div>
  1385. </div>
  1386. </section>
  1387. <section id="venv">
  1388. <h3>venv<a class="headerlink" href="#venv" title="Link to this heading">¶</a></h3>
  1389. <p><a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a> now includes an <code class="docutils literal notranslate"><span class="pre">Activate.ps1</span></code> script on all platforms for
  1390. activating virtual environments under PowerShell Core 6.1.
  1391. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32718">bpo-32718</a>.)</p>
  1392. </section>
  1393. <section id="weakref">
  1394. <h3>weakref<a class="headerlink" href="#weakref" title="Link to this heading">¶</a></h3>
  1395. <p>The proxy objects returned by <a class="reference internal" href="../library/weakref.html#weakref.proxy" title="weakref.proxy"><code class="xref py py-func docutils literal notranslate"><span class="pre">weakref.proxy()</span></code></a> now support the matrix
  1396. multiplication operators <code class="docutils literal notranslate"><span class="pre">&#64;</span></code> and <code class="docutils literal notranslate"><span class="pre">&#64;=</span></code> in addition to the other
  1397. numeric operators. (Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36669">bpo-36669</a>.)</p>
  1398. </section>
  1399. <section id="xml">
  1400. <h3>xml<a class="headerlink" href="#xml" title="Link to this heading">¶</a></h3>
  1401. <p>As mitigation against DTD and external entity retrieval, the
  1402. <a class="reference internal" href="../library/xml.dom.minidom.html#module-xml.dom.minidom" title="xml.dom.minidom: Minimal Document Object Model (DOM) implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code></a> and <a class="reference internal" href="../library/xml.sax.html#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code></a> modules no longer process
  1403. external entities by default.
  1404. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17239">bpo-17239</a>.)</p>
  1405. <p>The <code class="docutils literal notranslate"><span class="pre">.find*()</span></code> methods in the <a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code></a> module
  1406. support wildcard searches like <code class="docutils literal notranslate"><span class="pre">{*}tag</span></code> which ignores the namespace
  1407. and <code class="docutils literal notranslate"><span class="pre">{namespace}*</span></code> which returns all tags in the given namespace.
  1408. (Contributed by Stefan Behnel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28238">bpo-28238</a>.)</p>
  1409. <p>The <a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code></a> module provides a new function
  1410. <code class="xref py py-func docutils literal notranslate"><span class="pre">–xml.etree.ElementTree.canonicalize()</span></code> that implements C14N 2.0.
  1411. (Contributed by Stefan Behnel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13611">bpo-13611</a>.)</p>
  1412. <p>The target object of <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLParser" title="xml.etree.ElementTree.XMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.etree.ElementTree.XMLParser</span></code></a> can
  1413. receive namespace declaration events through the new callback methods
  1414. <code class="docutils literal notranslate"><span class="pre">start_ns()</span></code> and <code class="docutils literal notranslate"><span class="pre">end_ns()</span></code>. Additionally, the
  1415. <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.TreeBuilder" title="xml.etree.ElementTree.TreeBuilder"><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.etree.ElementTree.TreeBuilder</span></code></a> target can be configured
  1416. to process events about comments and processing instructions to include
  1417. them in the generated tree.
  1418. (Contributed by Stefan Behnel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36676">bpo-36676</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36673">bpo-36673</a>.)</p>
  1419. </section>
  1420. <section id="xmlrpc">
  1421. <h3>xmlrpc<a class="headerlink" href="#xmlrpc" title="Link to this heading">¶</a></h3>
  1422. <p><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">xmlrpc.client.ServerProxy</span></code></a> now supports an optional <em>headers</em> keyword
  1423. argument for a sequence of HTTP headers to be sent with each request. Among
  1424. other things, this makes it possible to upgrade from default basic
  1425. authentication to faster session authentication.
  1426. (Contributed by Cédric Krier in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35153">bpo-35153</a>.)</p>
  1427. </section>
  1428. </section>
  1429. <section id="optimizations">
  1430. <h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading">¶</a></h2>
  1431. <ul>
  1432. <li><p>The <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module can now use the <a class="reference internal" href="../library/os.html#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.posix_spawn()</span></code></a> function
  1433. in some cases for better performance. Currently, it is only used on macOS
  1434. and Linux (using glibc 2.24 or newer) if all these conditions are met:</p>
  1435. <ul class="simple">
  1436. <li><p><em>close_fds</em> is false;</p></li>
  1437. <li><p><em>preexec_fn</em>, <em>pass_fds</em>, <em>cwd</em> and <em>start_new_session</em> parameters
  1438. are not set;</p></li>
  1439. <li><p>the <em>executable</em> path contains a directory.</p></li>
  1440. </ul>
  1441. <p>(Contributed by Joannah Nanjekye and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35537">bpo-35537</a>.)</p>
  1442. </li>
  1443. <li><p><a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copyfile()</span></code></a>, <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">shutil.copy()</span></code></a>, <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">shutil.copy2()</span></code></a>,
  1444. <a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copytree()</span></code></a> and <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">shutil.move()</span></code></a> use platform-specific
  1445. “fast-copy” syscalls on Linux and macOS in order to copy the file
  1446. more efficiently.
  1447. “fast-copy” means that the copying operation occurs within the kernel,
  1448. avoiding the use of userspace buffers in Python as in
  1449. “<code class="docutils literal notranslate"><span class="pre">outfd.write(infd.read())</span></code>”.
  1450. On Windows <a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copyfile()</span></code></a> uses a bigger default buffer size (1 MiB
  1451. instead of 16 KiB) and a <a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-func docutils literal notranslate"><span class="pre">memoryview()</span></code></a>-based variant of
  1452. <a class="reference internal" href="../library/shutil.html#shutil.copyfileobj" title="shutil.copyfileobj"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copyfileobj()</span></code></a> is used.
  1453. The speedup for copying a 512 MiB file within the same partition is about
  1454. +26% on Linux, +50% on macOS and +40% on Windows. Also, much less CPU cycles
  1455. are consumed.
  1456. See <a class="reference internal" href="../library/shutil.html#shutil-platform-dependent-efficient-copy-operations"><span class="std std-ref">Platform-dependent efficient copy operations</span></a> section.
  1457. (Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33671">bpo-33671</a>.)</p></li>
  1458. <li><p><a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copytree()</span></code></a> uses <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 and all copy
  1459. functions depending from it use cached <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> values. The speedup
  1460. for copying a directory with 8000 files is around +9% on Linux, +20% on
  1461. Windows and +30% on a Windows SMB share. Also the number of <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>
  1462. syscalls is reduced by 38% making <a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copytree()</span></code></a> especially faster
  1463. on network filesystems. (Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33695">bpo-33695</a>.)</p></li>
  1464. <li><p>The default protocol in the <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> module is now Protocol 4,
  1465. first introduced in Python 3.4. It offers better performance and smaller
  1466. size compared to Protocol 3 available since Python 3.0.</p></li>
  1467. <li><p>Removed one <a class="reference internal" href="../c-api/intro.html#c.Py_ssize_t" title="Py_ssize_t"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_ssize_t</span></code></a> member from <code class="docutils literal notranslate"><span class="pre">PyGC_Head</span></code>. All GC tracked
  1468. objects (e.g. tuple, list, dict) size is reduced 4 or 8 bytes.
  1469. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33597">bpo-33597</a>.)</p></li>
  1470. <li><p><a class="reference internal" href="../library/uuid.html#uuid.UUID" title="uuid.UUID"><code class="xref py py-class docutils literal notranslate"><span class="pre">uuid.UUID</span></code></a> now uses <code class="docutils literal notranslate"><span class="pre">__slots__</span></code> to reduce its memory footprint.
  1471. (Contributed by Wouter Bolsterlee and Tal Einat in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30977">bpo-30977</a>)</p></li>
  1472. <li><p>Improved performance of <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">operator.itemgetter()</span></code></a> by 33%. Optimized
  1473. argument handling and added a fast path for the common case of a single
  1474. non-negative integer index into a tuple (which is the typical use case in
  1475. the standard library). (Contributed by Raymond Hettinger in
  1476. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35664">bpo-35664</a>.)</p></li>
  1477. <li><p>Sped-up field lookups in <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>. They are now more
  1478. than two times faster, making them the fastest form of instance variable
  1479. lookup in Python. (Contributed by Raymond Hettinger, Pablo Galindo, and
  1480. Joe Jevnik, Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32492">bpo-32492</a>.)</p></li>
  1481. <li><p>The <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> constructor does not overallocate the internal item buffer
  1482. if the input iterable has a known length (the input implements <code class="docutils literal notranslate"><span class="pre">__len__</span></code>).
  1483. This makes the created list 12% smaller on average. (Contributed by
  1484. Raymond Hettinger and Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33234">bpo-33234</a>.)</p></li>
  1485. <li><p>Doubled the speed of class variable writes. When a non-dunder attribute
  1486. was updated, there was an unnecessary call to update slots.
  1487. (Contributed by Stefan Behnel, Pablo Galindo Salgado, Raymond Hettinger,
  1488. Neil Schemenauer, and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36012">bpo-36012</a>.)</p></li>
  1489. <li><p>Reduced an overhead of converting arguments passed to many builtin functions
  1490. and methods. This sped up calling some simple builtin functions and
  1491. methods up to 20–50%. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23867">bpo-23867</a>,
  1492. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35582">bpo-35582</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36127">bpo-36127</a>.)</p></li>
  1493. <li><p><code class="docutils literal notranslate"><span class="pre">LOAD_GLOBAL</span></code> instruction now uses new “per opcode cache” mechanism.
  1494. It is about 40% faster now. (Contributed by Yury Selivanov and Inada Naoki in
  1495. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26219">bpo-26219</a>.)</p></li>
  1496. </ul>
  1497. </section>
  1498. <section id="build-and-c-api-changes">
  1499. <h2>Build and C API Changes<a class="headerlink" href="#build-and-c-api-changes" title="Link to this heading">¶</a></h2>
  1500. <ul>
  1501. <li><p>Default <a class="reference internal" href="../library/sys.html#sys.abiflags" title="sys.abiflags"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.abiflags</span></code></a> became an empty string: the <code class="docutils literal notranslate"><span class="pre">m</span></code> flag for
  1502. pymalloc became useless (builds with and without pymalloc are ABI compatible)
  1503. and so has been removed. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36707">bpo-36707</a>.)</p>
  1504. <p>Example of changes:</p>
  1505. <ul class="simple">
  1506. <li><p>Only <code class="docutils literal notranslate"><span class="pre">python3.8</span></code> program is installed, <code class="docutils literal notranslate"><span class="pre">python3.8m</span></code> program is gone.</p></li>
  1507. <li><p>Only <code class="docutils literal notranslate"><span class="pre">python3.8-config</span></code> script is installed, <code class="docutils literal notranslate"><span class="pre">python3.8m-config</span></code> script
  1508. is gone.</p></li>
  1509. <li><p>The <code class="docutils literal notranslate"><span class="pre">m</span></code> flag has been removed from the suffix of dynamic library
  1510. filenames: extension modules in the standard library as well as those
  1511. produced and installed by third-party packages, like those downloaded from
  1512. PyPI. On Linux, for example, the Python 3.7 suffix
  1513. <code class="docutils literal notranslate"><span class="pre">.cpython-37m-x86_64-linux-gnu.so</span></code> became
  1514. <code class="docutils literal notranslate"><span class="pre">.cpython-38-x86_64-linux-gnu.so</span></code> in Python 3.8.</p></li>
  1515. </ul>
  1516. </li>
  1517. <li><p>The header files have been reorganized to better separate the different kinds
  1518. of APIs:</p>
  1519. <ul class="simple">
  1520. <li><p><code class="docutils literal notranslate"><span class="pre">Include/*.h</span></code> should be the portable public stable C API.</p></li>
  1521. <li><p><code class="docutils literal notranslate"><span class="pre">Include/cpython/*.h</span></code> should be the unstable C API specific to CPython;
  1522. public API, with some private API prefixed by <code class="docutils literal notranslate"><span class="pre">_Py</span></code> or <code class="docutils literal notranslate"><span class="pre">_PY</span></code>.</p></li>
  1523. <li><p><code class="docutils literal notranslate"><span class="pre">Include/internal/*.h</span></code> is the private internal C API very specific to
  1524. CPython. This API comes with no backward compatibility warranty and should
  1525. not be used outside CPython. It is only exposed for very specific needs
  1526. like debuggers and profiles which has to access to CPython internals
  1527. without calling functions. This API is now installed by <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">install</span></code>.</p></li>
  1528. </ul>
  1529. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35134">bpo-35134</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35081">bpo-35081</a>,
  1530. work initiated by Eric Snow in Python 3.7.)</p>
  1531. </li>
  1532. <li><p>Some macros have been converted to static inline functions: parameter types
  1533. and return type are well defined, they don’t have issues specific to macros,
  1534. variables have a local scopes. Examples:</p>
  1535. <ul class="simple">
  1536. <li><p><a class="reference internal" href="../c-api/refcounting.html#c.Py_INCREF" title="Py_INCREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_INCREF()</span></code></a>, <a class="reference internal" href="../c-api/refcounting.html#c.Py_DECREF" title="Py_DECREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DECREF()</span></code></a></p></li>
  1537. <li><p><a class="reference internal" href="../c-api/refcounting.html#c.Py_XINCREF" title="Py_XINCREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_XINCREF()</span></code></a>, <a class="reference internal" href="../c-api/refcounting.html#c.Py_XDECREF" title="Py_XDECREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_XDECREF()</span></code></a></p></li>
  1538. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_INIT()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_INIT_VAR()</span></code></p></li>
  1539. <li><p>Private functions: <code class="xref c c-func docutils literal notranslate"><span class="pre">_PyObject_GC_TRACK()</span></code>,
  1540. <code class="xref c c-func docutils literal notranslate"><span class="pre">_PyObject_GC_UNTRACK()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">_Py_Dealloc()</span></code></p></li>
  1541. </ul>
  1542. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35059">bpo-35059</a>.)</p>
  1543. </li>
  1544. <li><p>The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyByteArray_Init()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyByteArray_Fini()</span></code> functions have
  1545. been removed. They did nothing since Python 2.7.4 and Python 3.2.0, were
  1546. excluded from the limited API (stable ABI), and were not documented.
  1547. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35713">bpo-35713</a>.)</p></li>
  1548. <li><p>The result of <code class="xref c c-func docutils literal notranslate"><span class="pre">PyExceptionClass_Name()</span></code> is now of type
  1549. <code class="docutils literal notranslate"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></code> rather of <code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*</span></code>.
  1550. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33818">bpo-33818</a>.)</p></li>
  1551. <li><p>The duality of <code class="docutils literal notranslate"><span class="pre">Modules/Setup.dist</span></code> and <code class="docutils literal notranslate"><span class="pre">Modules/Setup</span></code> has been
  1552. removed. Previously, when updating the CPython source tree, one had
  1553. to manually copy <code class="docutils literal notranslate"><span class="pre">Modules/Setup.dist</span></code> (inside the source tree) to
  1554. <code class="docutils literal notranslate"><span class="pre">Modules/Setup</span></code> (inside the build tree) in order to reflect any changes
  1555. upstream. This was of a small benefit to packagers at the expense of
  1556. a frequent annoyance to developers following CPython development, as
  1557. forgetting to copy the file could produce build failures.</p>
  1558. <p>Now the build system always reads from <code class="docutils literal notranslate"><span class="pre">Modules/Setup</span></code> inside the source
  1559. tree. People who want to customize that file are encouraged to maintain
  1560. their changes in a git fork of CPython or as patch files, as they would do
  1561. for any other change to the source tree.</p>
  1562. <p>(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32430">bpo-32430</a>.)</p>
  1563. </li>
  1564. <li><p>Functions that convert Python number to C integer like
  1565. <a class="reference internal" href="../c-api/long.html#c.PyLong_AsLong" title="PyLong_AsLong"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyLong_AsLong()</span></code></a> and argument parsing functions like
  1566. <a class="reference internal" href="../c-api/arg.html#c.PyArg_ParseTuple" title="PyArg_ParseTuple"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTuple()</span></code></a> with integer converting format units like <code class="docutils literal notranslate"><span class="pre">'i'</span></code>
  1567. will now use the <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> special method instead of
  1568. <a class="reference internal" href="../reference/datamodel.html#object.__int__" title="object.__int__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__int__()</span></code></a>, if available. The deprecation warning will be
  1569. emitted for objects with the <code class="docutils literal notranslate"><span class="pre">__int__()</span></code> method but without the
  1570. <code class="docutils literal notranslate"><span class="pre">__index__()</span></code> method (like <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">Decimal</span></code></a> and
  1571. <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">Fraction</span></code></a>). <a class="reference internal" href="../c-api/number.html#c.PyNumber_Check" title="PyNumber_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_Check()</span></code></a> will now return
  1572. <code class="docutils literal notranslate"><span class="pre">1</span></code> for objects implementing <code class="docutils literal notranslate"><span class="pre">__index__()</span></code>.
  1573. <a class="reference internal" href="../c-api/number.html#c.PyNumber_Long" title="PyNumber_Long"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_Long()</span></code></a>, <a class="reference internal" href="../c-api/number.html#c.PyNumber_Float" title="PyNumber_Float"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_Float()</span></code></a> and
  1574. <a class="reference internal" href="../c-api/float.html#c.PyFloat_AsDouble" title="PyFloat_AsDouble"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_AsDouble()</span></code></a> also now use the <code class="docutils literal notranslate"><span class="pre">__index__()</span></code> method if
  1575. available.
  1576. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36048">bpo-36048</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20092">bpo-20092</a>.)</p></li>
  1577. <li><p>Heap-allocated type objects will now increase their reference count
  1578. in <a class="reference internal" href="../c-api/allocation.html#c.PyObject_Init" title="PyObject_Init"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Init()</span></code></a> (and its parallel macro <code class="docutils literal notranslate"><span class="pre">PyObject_INIT</span></code>)
  1579. instead of in <a class="reference internal" href="../c-api/type.html#c.PyType_GenericAlloc" title="PyType_GenericAlloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GenericAlloc()</span></code></a>. Types that modify instance
  1580. allocation or deallocation may need to be adjusted.
  1581. (Contributed by Eddie Elizondo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35810">bpo-35810</a>.)</p></li>
  1582. <li><p>The new function <code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_NewWithPosOnlyArgs()</span></code> allows to create
  1583. code objects like <code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_New()</span></code>, but with an extra <em>posonlyargcount</em>
  1584. parameter for indicating the number of positional-only arguments.
  1585. (Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37221">bpo-37221</a>.)</p></li>
  1586. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetPath()</span></code> now sets <a class="reference internal" href="../library/sys.html#sys.executable" title="sys.executable"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.executable</span></code></a> to the program full
  1587. path (<a class="reference internal" href="../c-api/init.html#c.Py_GetProgramFullPath" title="Py_GetProgramFullPath"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetProgramFullPath()</span></code></a>) rather than to the program name
  1588. (<a class="reference internal" href="../c-api/init.html#c.Py_GetProgramName" title="Py_GetProgramName"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetProgramName()</span></code></a>).
  1589. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38234">bpo-38234</a>.)</p></li>
  1590. </ul>
  1591. </section>
  1592. <section id="deprecated">
  1593. <h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading">¶</a></h2>
  1594. <ul>
  1595. <li><p>The distutils <code class="docutils literal notranslate"><span class="pre">bdist_wininst</span></code> command is now deprecated, use
  1596. <code class="docutils literal notranslate"><span class="pre">bdist_wheel</span></code> (wheel packages) instead.
  1597. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37481">bpo-37481</a>.)</p></li>
  1598. <li><p>Deprecated methods <code class="docutils literal notranslate"><span class="pre">getchildren()</span></code> and <code class="docutils literal notranslate"><span class="pre">getiterator()</span></code> in
  1599. the <a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ElementTree</span></code></a> module now emit a
  1600. <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> instead of <a class="reference internal" href="../library/exceptions.html#PendingDeprecationWarning" title="PendingDeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PendingDeprecationWarning</span></code></a>.
  1601. They will be removed in Python 3.9.
  1602. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29209">bpo-29209</a>.)</p></li>
  1603. <li><p>Passing an object that is not an instance of
  1604. <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.ThreadPoolExecutor</span></code></a> to
  1605. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.set_default_executor" title="asyncio.loop.set_default_executor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.set_default_executor()</span></code></a> is
  1606. deprecated and will be prohibited in Python 3.9.
  1607. (Contributed by Elvis Pranskevichus in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34075">bpo-34075</a>.)</p></li>
  1608. <li><p>The <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a> methods of <a class="reference internal" href="../library/xml.dom.pulldom.html#xml.dom.pulldom.DOMEventStream" title="xml.dom.pulldom.DOMEventStream"><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.dom.pulldom.DOMEventStream</span></code></a>,
  1609. <a class="reference internal" href="../library/wsgiref.html#wsgiref.util.FileWrapper" title="wsgiref.util.FileWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">wsgiref.util.FileWrapper</span></code></a> and <a class="reference internal" href="../library/fileinput.html#fileinput.FileInput" title="fileinput.FileInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">fileinput.FileInput</span></code></a> have been
  1610. deprecated.</p>
  1611. <p>Implementations of these methods have been ignoring their <em>index</em> parameter,
  1612. and returning the next item instead.
  1613. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9372">bpo-9372</a>.)</p>
  1614. </li>
  1615. <li><p>The <a class="reference internal" href="../library/typing.html#typing.NamedTuple" title="typing.NamedTuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.NamedTuple</span></code></a> class has deprecated the <code class="docutils literal notranslate"><span class="pre">_field_types</span></code>
  1616. attribute in favor of the <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code> attribute which has the same
  1617. information. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36320">bpo-36320</a>.)</p></li>
  1618. <li><p><a class="reference internal" href="../library/ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a> classes <code class="docutils literal notranslate"><span class="pre">Num</span></code>, <code class="docutils literal notranslate"><span class="pre">Str</span></code>, <code class="docutils literal notranslate"><span class="pre">Bytes</span></code>, <code class="docutils literal notranslate"><span class="pre">NameConstant</span></code> and
  1619. <code class="docutils literal notranslate"><span class="pre">Ellipsis</span></code> are considered deprecated and will be removed in future Python
  1620. versions. <a class="reference internal" href="../library/ast.html#ast.Constant" title="ast.Constant"><code class="xref py py-class docutils literal notranslate"><span class="pre">Constant</span></code></a> should be used instead.
  1621. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32892">bpo-32892</a>.)</p></li>
  1622. <li><p><a class="reference internal" href="../library/ast.html#ast.NodeVisitor" title="ast.NodeVisitor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.NodeVisitor</span></code></a> methods <code class="docutils literal notranslate"><span class="pre">visit_Num()</span></code>, <code class="docutils literal notranslate"><span class="pre">visit_Str()</span></code>,
  1623. <code class="docutils literal notranslate"><span class="pre">visit_Bytes()</span></code>, <code class="docutils literal notranslate"><span class="pre">visit_NameConstant()</span></code> and <code class="docutils literal notranslate"><span class="pre">visit_Ellipsis()</span></code> are
  1624. deprecated now and will not be called in future Python versions.
  1625. Add the <a class="reference internal" href="../library/ast.html#ast.NodeVisitor.visit_Constant" title="ast.NodeVisitor.visit_Constant"><code class="xref py py-meth docutils literal notranslate"><span class="pre">visit_Constant()</span></code></a> method to handle all
  1626. constant nodes.
  1627. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36917">bpo-36917</a>.)</p></li>
  1628. <li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.coroutine()</span></code> <a class="reference internal" href="../glossary.html#term-decorator"><span class="xref std std-term">decorator</span></a> is deprecated and will be
  1629. removed in version 3.10. Instead of <code class="docutils literal notranslate"><span class="pre">&#64;asyncio.coroutine</span></code>, use
  1630. <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> instead.
  1631. (Contributed by Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36921">bpo-36921</a>.)</p></li>
  1632. <li><p>In <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>, the explicit passing of a <em>loop</em> argument has been
  1633. deprecated and will be removed in version 3.10 for the following:
  1634. <a class="reference internal" href="../library/asyncio-task.html#asyncio.sleep" title="asyncio.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.sleep()</span></code></a>, <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>, <a class="reference internal" href="../library/asyncio-task.html#asyncio.shield" title="asyncio.shield"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.shield()</span></code></a>,
  1635. <a class="reference internal" href="../library/asyncio-task.html#asyncio.wait_for" title="asyncio.wait_for"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.wait_for()</span></code></a>, <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.as_completed" title="asyncio.as_completed"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.as_completed()</span></code></a>,
  1636. <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a>, <a class="reference internal" href="../library/asyncio-sync.html#asyncio.Lock" title="asyncio.Lock"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Lock</span></code></a>, <a class="reference internal" href="../library/asyncio-sync.html#asyncio.Event" title="asyncio.Event"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Event</span></code></a>,
  1637. <a class="reference internal" href="../library/asyncio-sync.html#asyncio.Condition" title="asyncio.Condition"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Condition</span></code></a>, <a class="reference internal" href="../library/asyncio-sync.html#asyncio.Semaphore" title="asyncio.Semaphore"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Semaphore</span></code></a>,
  1638. <a class="reference internal" href="../library/asyncio-sync.html#asyncio.BoundedSemaphore" title="asyncio.BoundedSemaphore"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.BoundedSemaphore</span></code></a>, <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>,
  1639. <a class="reference internal" href="../library/asyncio-subprocess.html#asyncio.create_subprocess_exec" title="asyncio.create_subprocess_exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.create_subprocess_exec()</span></code></a>, and
  1640. <a class="reference internal" href="../library/asyncio-subprocess.html#asyncio.create_subprocess_shell" title="asyncio.create_subprocess_shell"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.create_subprocess_shell()</span></code></a>.</p></li>
  1641. <li><p>The explicit passing of coroutine objects to <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> has been
  1642. deprecated and will be removed in version 3.11.
  1643. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34790">bpo-34790</a>.)</p></li>
  1644. <li><p>The following functions and methods are deprecated in the <a class="reference internal" href="../library/gettext.html#module-gettext" title="gettext: Multilingual internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gettext</span></code></a>
  1645. module: <code class="xref py py-func docutils literal notranslate"><span class="pre">lgettext()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">ldgettext()</span></code>,
  1646. <code class="xref py py-func docutils literal notranslate"><span class="pre">lngettext()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">ldngettext()</span></code>.
  1647. They return encoded bytes, and it’s possible that you will get unexpected
  1648. Unicode-related exceptions if there are encoding problems with the
  1649. translated strings. It’s much better to use alternatives which return
  1650. Unicode strings in Python 3. These functions have been broken for a long time.</p>
  1651. <p>Function <code class="xref py py-func docutils literal notranslate"><span class="pre">bind_textdomain_codeset()</span></code>, methods
  1652. <code class="xref py py-meth docutils literal notranslate"><span class="pre">output_charset()</span></code> and
  1653. <code class="xref py py-meth docutils literal notranslate"><span class="pre">set_output_charset()</span></code>, and the <em>codeset</em>
  1654. parameter of functions <a class="reference internal" href="../library/gettext.html#gettext.translation" title="gettext.translation"><code class="xref py py-func docutils literal notranslate"><span class="pre">translation()</span></code></a> and
  1655. <a class="reference internal" href="../library/gettext.html#gettext.install" title="gettext.install"><code class="xref py py-func docutils literal notranslate"><span class="pre">install()</span></code></a> are also deprecated, since they are only used for
  1656. the <code class="docutils literal notranslate"><span class="pre">l*gettext()</span></code> functions.
  1657. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33710">bpo-33710</a>.)</p>
  1658. </li>
  1659. <li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">isAlive()</span></code> method of <a class="reference internal" href="../library/threading.html#threading.Thread" title="threading.Thread"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Thread</span></code></a>
  1660. has been deprecated.
  1661. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35283">bpo-35283</a>.)</p></li>
  1662. <li><p>Many builtin and extension functions that take integer arguments will
  1663. now emit a deprecation warning for <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">Decimal</span></code></a>s,
  1664. <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">Fraction</span></code></a>s and any other objects that can be converted
  1665. to integers only with a loss (e.g. that have the <a class="reference internal" href="../reference/datamodel.html#object.__int__" title="object.__int__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__int__()</span></code></a>
  1666. method but do not have the <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> method). In future
  1667. version they will be errors.
  1668. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36048">bpo-36048</a>.)</p></li>
  1669. <li><p>Deprecated passing the following arguments as keyword arguments:</p>
  1670. <ul class="simple">
  1671. <li><p><em>func</em> in <a class="reference internal" href="../library/functools.html#functools.partialmethod" title="functools.partialmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.partialmethod()</span></code></a>, <a class="reference internal" href="../library/weakref.html#weakref.finalize" title="weakref.finalize"><code class="xref py py-func docutils literal notranslate"><span class="pre">weakref.finalize()</span></code></a>,
  1672. <a class="reference internal" href="../library/profile.html#profile.Profile.runcall" title="profile.Profile.runcall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">profile.Profile.runcall()</span></code></a>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">cProfile.Profile.runcall()</span></code>,
  1673. <a class="reference internal" href="../library/bdb.html#bdb.Bdb.runcall" title="bdb.Bdb.runcall"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bdb.Bdb.runcall()</span></code></a>, <a class="reference internal" href="../library/trace.html#trace.Trace.runfunc" title="trace.Trace.runfunc"><code class="xref py py-meth docutils literal notranslate"><span class="pre">trace.Trace.runfunc()</span></code></a> and
  1674. <a class="reference internal" href="../library/curses.html#curses.wrapper" title="curses.wrapper"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.wrapper()</span></code></a>.</p></li>
  1675. <li><p><em>function</em> in <a class="reference internal" href="../library/unittest.html#unittest.TestCase.addCleanup" title="unittest.TestCase.addCleanup"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestCase.addCleanup()</span></code></a>.</p></li>
  1676. <li><p><em>fn</em> in the <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.Executor.submit" title="concurrent.futures.Executor.submit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">submit()</span></code></a> method of
  1677. <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.ThreadPoolExecutor</span></code></a> and
  1678. <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor" title="concurrent.futures.ProcessPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.ProcessPoolExecutor</span></code></a>.</p></li>
  1679. <li><p><em>callback</em> in <a class="reference internal" href="../library/contextlib.html#contextlib.ExitStack.callback" title="contextlib.ExitStack.callback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">contextlib.ExitStack.callback()</span></code></a>,
  1680. <code class="xref py py-meth docutils literal notranslate"><span class="pre">contextlib.AsyncExitStack.callback()</span></code> and
  1681. <a class="reference internal" href="../library/contextlib.html#contextlib.AsyncExitStack.push_async_callback" title="contextlib.AsyncExitStack.push_async_callback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">contextlib.AsyncExitStack.push_async_callback()</span></code></a>.</p></li>
  1682. <li><p><em>c</em> and <em>typeid</em> in the <code class="xref py py-meth docutils literal notranslate"><span class="pre">create()</span></code>
  1683. method of <code class="xref py py-class docutils literal notranslate"><span class="pre">multiprocessing.managers.Server</span></code> and
  1684. <code class="xref py py-class docutils literal notranslate"><span class="pre">multiprocessing.managers.SharedMemoryServer</span></code>.</p></li>
  1685. <li><p><em>obj</em> in <a class="reference internal" href="../library/weakref.html#weakref.finalize" title="weakref.finalize"><code class="xref py py-func docutils literal notranslate"><span class="pre">weakref.finalize()</span></code></a>.</p></li>
  1686. </ul>
  1687. <p>In future releases of Python, they will be <a class="reference internal" href="../glossary.html#positional-only-parameter"><span class="std std-ref">positional-only</span></a>.
  1688. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36492">bpo-36492</a>.)</p>
  1689. </li>
  1690. </ul>
  1691. </section>
  1692. <section id="api-and-feature-removals">
  1693. <h2>API and Feature Removals<a class="headerlink" href="#api-and-feature-removals" title="Link to this heading">¶</a></h2>
  1694. <p>The following features and APIs have been removed from Python 3.8:</p>
  1695. <ul class="simple">
  1696. <li><p>Starting with Python 3.3, importing ABCs from <a class="reference internal" href="../library/collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a> was
  1697. deprecated, and importing should be done from <a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a>. Being
  1698. able to import from collections was marked for removal in 3.8, but has been
  1699. delayed to 3.9. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36952">bpo-36952</a>.)</p></li>
  1700. <li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">macpath</span></code> module, deprecated in Python 3.7, has been removed.
  1701. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35471">bpo-35471</a>.)</p></li>
  1702. <li><p>The function <code class="xref py py-func docutils literal notranslate"><span class="pre">platform.popen()</span></code> has been removed, after having been
  1703. deprecated since Python 3.3: use <a class="reference internal" href="../library/os.html#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.popen()</span></code></a> instead.
  1704. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35345">bpo-35345</a>.)</p></li>
  1705. <li><p>The function <code class="xref py py-func docutils literal notranslate"><span class="pre">time.clock()</span></code> has been removed, after having been
  1706. deprecated since Python 3.3: use <a class="reference internal" href="../library/time.html#time.perf_counter" title="time.perf_counter"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.perf_counter()</span></code></a> or
  1707. <a class="reference internal" href="../library/time.html#time.process_time" title="time.process_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.process_time()</span></code></a> instead, depending
  1708. on your requirements, to have well-defined behavior.
  1709. (Contributed by Matthias Bussonnier in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36895">bpo-36895</a>.)</p></li>
  1710. <li><p>The <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> script has been removed in favor of <code class="docutils literal notranslate"><span class="pre">python3.8</span> <span class="pre">-m</span> <span class="pre">venv</span></code>
  1711. to help eliminate confusion as to what Python interpreter the <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code>
  1712. script is tied to. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25427">bpo-25427</a>.)</p></li>
  1713. <li><p><code class="docutils literal notranslate"><span class="pre">parse_qs</span></code>, <code class="docutils literal notranslate"><span class="pre">parse_qsl</span></code>, and <code class="docutils literal notranslate"><span class="pre">escape</span></code> are removed from the <a class="reference internal" href="../library/cgi.html#module-cgi" title="cgi: Helpers for running Python scripts via the Common Gateway Interface. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cgi</span></code></a>
  1714. module. They are deprecated in Python 3.2 or older. They should be imported
  1715. from the <code class="docutils literal notranslate"><span class="pre">urllib.parse</span></code> and <code class="docutils literal notranslate"><span class="pre">html</span></code> modules instead.</p></li>
  1716. <li><p><code class="docutils literal notranslate"><span class="pre">filemode</span></code> function is removed from the <a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a> module.
  1717. It is not documented and deprecated since Python 3.3.</p></li>
  1718. <li><p>The <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLParser" title="xml.etree.ElementTree.XMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLParser</span></code></a> constructor no longer accepts
  1719. the <em>html</em> argument. It never had an effect and was deprecated in Python 3.4.
  1720. All other parameters are now <a class="reference internal" href="../glossary.html#keyword-only-parameter"><span class="std std-ref">keyword-only</span></a>.
  1721. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29209">bpo-29209</a>.)</p></li>
  1722. <li><p>Removed the <code class="docutils literal notranslate"><span class="pre">doctype()</span></code> method of <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLParser" title="xml.etree.ElementTree.XMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLParser</span></code></a>.
  1723. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29209">bpo-29209</a>.)</p></li>
  1724. <li><p>“unicode_internal” codec is removed.
  1725. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36297">bpo-36297</a>.)</p></li>
  1726. <li><p>The <code class="docutils literal notranslate"><span class="pre">Cache</span></code> and <code class="docutils literal notranslate"><span class="pre">Statement</span></code> objects of the <a class="reference internal" href="../library/sqlite3.html#module-sqlite3" title="sqlite3: A DB-API 2.0 implementation using SQLite 3.x."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlite3</span></code></a> module are not
  1727. exposed to the user.
  1728. (Contributed by Aviv Palivoda in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30262">bpo-30262</a>.)</p></li>
  1729. <li><p>The <code class="docutils literal notranslate"><span class="pre">bufsize</span></code> keyword argument of <a class="reference internal" href="../library/fileinput.html#fileinput.input" title="fileinput.input"><code class="xref py py-func docutils literal notranslate"><span class="pre">fileinput.input()</span></code></a> and
  1730. <a class="reference internal" href="../library/fileinput.html#fileinput.FileInput" title="fileinput.FileInput"><code class="xref py py-func docutils literal notranslate"><span class="pre">fileinput.FileInput()</span></code></a> which was ignored and deprecated since Python 3.6
  1731. has been removed. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36952">bpo-36952</a> (Contributed by Matthias Bussonnier.)</p></li>
  1732. <li><p>The functions <code class="xref py py-func docutils literal notranslate"><span class="pre">sys.set_coroutine_wrapper()</span></code> and
  1733. <code class="xref py py-func docutils literal notranslate"><span class="pre">sys.get_coroutine_wrapper()</span></code> deprecated in Python 3.7 have been removed;
  1734. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36933">bpo-36933</a> (Contributed by Matthias Bussonnier.)</p></li>
  1735. </ul>
  1736. </section>
  1737. <section id="porting-to-python-3-8">
  1738. <h2>Porting to Python 3.8<a class="headerlink" href="#porting-to-python-3-8" title="Link to this heading">¶</a></h2>
  1739. <p>This section lists previously described changes and other bugfixes
  1740. that may require changes to your code.</p>
  1741. <section id="changes-in-python-behavior">
  1742. <h3>Changes in Python behavior<a class="headerlink" href="#changes-in-python-behavior" title="Link to this heading">¶</a></h3>
  1743. <ul class="simple">
  1744. <li><p>Yield expressions (both <code class="docutils literal notranslate"><span class="pre">yield</span></code> and <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> clauses) are now disallowed
  1745. in comprehensions and generator expressions (aside from the iterable expression
  1746. in the leftmost <code class="xref std std-keyword docutils literal notranslate"><span class="pre">for</span></code> clause).
  1747. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10544">bpo-10544</a>.)</p></li>
  1748. <li><p>The compiler now produces a <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a> when identity checks
  1749. (<code class="docutils literal notranslate"><span class="pre">is</span></code> and <code class="docutils literal notranslate"><span class="pre">is</span> <span class="pre">not</span></code>) are used with certain types of literals
  1750. (e.g. strings, numbers). These can often work by accident in CPython,
  1751. but are not guaranteed by the language spec. The warning advises users
  1752. to use equality tests (<code class="docutils literal notranslate"><span class="pre">==</span></code> and <code class="docutils literal notranslate"><span class="pre">!=</span></code>) instead.
  1753. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34850">bpo-34850</a>.)</p></li>
  1754. <li><p>The CPython interpreter can swallow exceptions in some circumstances.
  1755. In Python 3.8 this happens in fewer cases. In particular, exceptions
  1756. raised when getting the attribute from the type dictionary are no longer
  1757. ignored. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35459">bpo-35459</a>.)</p></li>
  1758. <li><p>Removed <code class="docutils literal notranslate"><span class="pre">__str__</span></code> implementations from builtin types <a class="reference internal" href="../library/functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a>,
  1759. <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>, <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>, <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a> and few classes from
  1760. the standard library. They now inherit <code class="docutils literal notranslate"><span class="pre">__str__()</span></code> from <a class="reference internal" href="../library/functions.html#object" title="object"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a>.
  1761. As result, defining the <code class="docutils literal notranslate"><span class="pre">__repr__()</span></code> method in the subclass of these
  1762. classes will affect their string representation.
  1763. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36793">bpo-36793</a>.)</p></li>
  1764. <li><p>On AIX, <a class="reference internal" href="../library/sys.html#sys.platform" title="sys.platform"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platform</span></code></a> doesn’t contain the major version anymore.
  1765. It is always <code class="docutils literal notranslate"><span class="pre">'aix'</span></code>, instead of <code class="docutils literal notranslate"><span class="pre">'aix3'</span></code> .. <code class="docutils literal notranslate"><span class="pre">'aix7'</span></code>. Since
  1766. older Python versions include the version number, so it is recommended to
  1767. always use <code class="docutils literal notranslate"><span class="pre">sys.platform.startswith('aix')</span></code>.
  1768. (Contributed by M. Felt in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36588">bpo-36588</a>.)</p></li>
  1769. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_AcquireLock()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_AcquireThread()</span></code> now
  1770. terminate the current thread if called while the interpreter is
  1771. finalizing, making them consistent with <a class="reference internal" href="../c-api/init.html#c.PyEval_RestoreThread" title="PyEval_RestoreThread"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_RestoreThread()</span></code></a>,
  1772. <a class="reference internal" href="../c-api/init.html#c.Py_END_ALLOW_THREADS" title="Py_END_ALLOW_THREADS"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_END_ALLOW_THREADS()</span></code></a>, and <a class="reference internal" href="../c-api/init.html#c.PyGILState_Ensure" title="PyGILState_Ensure"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyGILState_Ensure()</span></code></a>. If this
  1773. behavior is not desired, guard the call by checking <code class="xref c c-func docutils literal notranslate"><span class="pre">_Py_IsFinalizing()</span></code>
  1774. or <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">sys.is_finalizing()</span></code></a>.
  1775. (Contributed by Joannah Nanjekye in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36475">bpo-36475</a>.)</p></li>
  1776. </ul>
  1777. </section>
  1778. <section id="changes-in-the-python-api">
  1779. <h3>Changes in the Python API<a class="headerlink" href="#changes-in-the-python-api" title="Link to this heading">¶</a></h3>
  1780. <ul class="simple">
  1781. <li><p>The <a class="reference internal" href="../library/os.html#os.getcwdb" title="os.getcwdb"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.getcwdb()</span></code></a> function now uses the UTF-8 encoding on Windows,
  1782. rather than the ANSI code page: see <span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0529/"><strong>PEP 529</strong></a> for the rationale. The
  1783. function is no longer deprecated on Windows.
  1784. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37412">bpo-37412</a>.)</p></li>
  1785. <li><p><a class="reference internal" href="../library/subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a> can now use <a class="reference internal" href="../library/os.html#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.posix_spawn()</span></code></a> in some cases
  1786. for better performance. On Windows Subsystem for Linux and QEMU User
  1787. Emulation, the <code class="xref py py-class docutils literal notranslate"><span class="pre">Popen</span></code> constructor using <a class="reference internal" href="../library/os.html#os.posix_spawn" title="os.posix_spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.posix_spawn()</span></code></a> no longer raises an
  1788. exception on errors like “missing program”. Instead the child process fails with a
  1789. non-zero <code class="xref py py-attr docutils literal notranslate"><span class="pre">returncode</span></code>.
  1790. (Contributed by Joannah Nanjekye and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35537">bpo-35537</a>.)</p></li>
  1791. <li><p>The <em>preexec_fn</em> argument of * <a class="reference internal" href="../library/subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a> is no longer
  1792. compatible with subinterpreters. The use of the parameter in a
  1793. subinterpreter now raises <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>.
  1794. (Contributed by Eric Snow in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34651">bpo-34651</a>, modified by Christian Heimes
  1795. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37951">bpo-37951</a>.)</p></li>
  1796. <li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">imap.IMAP4.logout()</span></code> method no longer silently ignores arbitrary
  1797. exceptions.
  1798. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36348">bpo-36348</a>.)</p></li>
  1799. <li><p>The function <code class="xref py py-func docutils literal notranslate"><span class="pre">platform.popen()</span></code> has been removed, after having been deprecated since
  1800. Python 3.3: use <a class="reference internal" href="../library/os.html#os.popen" title="os.popen"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.popen()</span></code></a> instead.
  1801. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35345">bpo-35345</a>.)</p></li>
  1802. <li><p>The <a class="reference internal" href="../library/statistics.html#statistics.mode" title="statistics.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">statistics.mode()</span></code></a> function no longer raises an exception
  1803. when given multimodal data. Instead, it returns the first mode
  1804. encountered in the input data. (Contributed by Raymond Hettinger
  1805. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35892">bpo-35892</a>.)</p></li>
  1806. <li><p>The <a class="reference internal" href="../library/tkinter.ttk.html#tkinter.ttk.Treeview.selection" title="tkinter.ttk.Treeview.selection"><code class="xref py py-meth docutils literal notranslate"><span class="pre">selection()</span></code></a> method of the
  1807. <a class="reference internal" href="../library/tkinter.ttk.html#tkinter.ttk.Treeview" title="tkinter.ttk.Treeview"><code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.ttk.Treeview</span></code></a> class no longer takes arguments. Using it with
  1808. arguments for changing the selection was deprecated in Python 3.6. Use
  1809. specialized methods like <a class="reference internal" href="../library/tkinter.ttk.html#tkinter.ttk.Treeview.selection_set" title="tkinter.ttk.Treeview.selection_set"><code class="xref py py-meth docutils literal notranslate"><span class="pre">selection_set()</span></code></a> for
  1810. changing the selection. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31508">bpo-31508</a>.)</p></li>
  1811. <li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">writexml()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">toxml()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">toprettyxml()</span></code> methods of
  1812. <a class="reference internal" href="../library/xml.dom.minidom.html#module-xml.dom.minidom" title="xml.dom.minidom: Minimal Document Object Model (DOM) implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code></a>, and the <code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code> method of <code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree</span></code>,
  1813. now preserve the attribute order specified by the user.
  1814. (Contributed by Diego Rojas and Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34160">bpo-34160</a>.)</p></li>
  1815. <li><p>A <a class="reference internal" href="../library/dbm.html#module-dbm.dumb" title="dbm.dumb: Portable implementation of the simple DBM interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.dumb</span></code></a> database opened with flags <code class="docutils literal notranslate"><span class="pre">'r'</span></code> is now read-only.
  1816. <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">dbm.dumb.open()</span></code></a> with flags <code class="docutils literal notranslate"><span class="pre">'r'</span></code> and <code class="docutils literal notranslate"><span class="pre">'w'</span></code> no longer creates
  1817. a database if it does not exist.
  1818. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32749">bpo-32749</a>.)</p></li>
  1819. <li><p>The <code class="docutils literal notranslate"><span class="pre">doctype()</span></code> method defined in a subclass of
  1820. <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLParser" title="xml.etree.ElementTree.XMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLParser</span></code></a> will no longer be called and will
  1821. emit a <a class="reference internal" href="../library/exceptions.html#RuntimeWarning" title="RuntimeWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeWarning</span></code></a> instead of a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>.
  1822. Define the <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.TreeBuilder.doctype" title="xml.etree.ElementTree.TreeBuilder.doctype"><code class="xref py py-meth docutils literal notranslate"><span class="pre">doctype()</span></code></a>
  1823. method on a target for handling an XML doctype declaration.
  1824. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29209">bpo-29209</a>.)</p></li>
  1825. <li><p>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> is now raised when the custom metaclass doesn’t
  1826. provide the <code class="docutils literal notranslate"><span class="pre">__classcell__</span></code> entry in the namespace passed to
  1827. <code class="docutils literal notranslate"><span class="pre">type.__new__</span></code>. A <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> was emitted in Python
  1828. 3.6–3.7. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23722">bpo-23722</a>.)</p></li>
  1829. <li><p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">cProfile.Profile</span></code> class can now be used as a context
  1830. manager. (Contributed by Scott Sanderson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29235">bpo-29235</a>.)</p></li>
  1831. <li><p><a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copyfile()</span></code></a>, <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">shutil.copy()</span></code></a>, <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">shutil.copy2()</span></code></a>,
  1832. <a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copytree()</span></code></a> and <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">shutil.move()</span></code></a> use platform-specific
  1833. “fast-copy” syscalls (see
  1834. <a class="reference internal" href="../library/shutil.html#shutil-platform-dependent-efficient-copy-operations"><span class="std std-ref">Platform-dependent efficient copy operations</span></a> section).</p></li>
  1835. <li><p><a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copyfile()</span></code></a> default buffer size on Windows was changed from
  1836. 16 KiB to 1 MiB.</p></li>
  1837. <li><p>The <code class="docutils literal notranslate"><span class="pre">PyGC_Head</span></code> struct has changed completely. All code that touched the
  1838. struct member should be rewritten. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33597">bpo-33597</a>.)</p></li>
  1839. <li><p>The <a class="reference internal" href="../c-api/init.html#c.PyInterpreterState" title="PyInterpreterState"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyInterpreterState</span></code></a> struct has been moved into the “internal”
  1840. header files (specifically Include/internal/pycore_pystate.h). An
  1841. opaque <code class="docutils literal notranslate"><span class="pre">PyInterpreterState</span></code> is still available as part of the public
  1842. API (and stable ABI). The docs indicate that none of the struct’s
  1843. fields are public, so we hope no one has been using them. However,
  1844. if you do rely on one or more of those private fields and have no
  1845. alternative then please open a BPO issue. We’ll work on helping
  1846. you adjust (possibly including adding accessor functions to the
  1847. public API). (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35886">bpo-35886</a>.)</p></li>
  1848. <li><p>The <a class="reference internal" href="../library/mmap.html#mmap.mmap.flush" title="mmap.mmap.flush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">mmap.flush()</span></code></a> method now returns <code class="docutils literal notranslate"><span class="pre">None</span></code> on
  1849. success and raises an exception on error under all platforms. Previously,
  1850. its behavior was platform-dependent: a nonzero value was returned on success;
  1851. zero was returned on error under Windows. A zero value was returned on
  1852. success; an exception was raised on error under Unix.
  1853. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=2122">bpo-2122</a>.)</p></li>
  1854. <li><p><a class="reference internal" href="../library/xml.dom.minidom.html#module-xml.dom.minidom" title="xml.dom.minidom: Minimal Document Object Model (DOM) implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code></a> and <a class="reference internal" href="../library/xml.sax.html#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code></a> modules no longer process
  1855. external entities by default.
  1856. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17239">bpo-17239</a>.)</p></li>
  1857. <li><p>Deleting a key from a read-only <a class="reference internal" href="../library/dbm.html#module-dbm" title="dbm: Interfaces to various Unix &quot;database&quot; formats."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm</span></code></a> database (<a class="reference internal" href="../library/dbm.html#module-dbm.dumb" title="dbm.dumb: Portable implementation of the simple DBM interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.dumb</span></code></a>,
  1858. <a class="reference internal" href="../library/dbm.html#module-dbm.gnu" title="dbm.gnu: GNU database manager (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.gnu</span></code></a> or <a class="reference internal" href="../library/dbm.html#module-dbm.ndbm" title="dbm.ndbm: The New Database Manager (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.ndbm</span></code></a>) raises <code class="xref py py-attr docutils literal notranslate"><span class="pre">error</span></code> (<a class="reference internal" href="../library/dbm.html#dbm.dumb.error" title="dbm.dumb.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">dbm.dumb.error</span></code></a>,
  1859. <a class="reference internal" href="../library/dbm.html#dbm.gnu.error" title="dbm.gnu.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">dbm.gnu.error</span></code></a> or <a class="reference internal" href="../library/dbm.html#dbm.ndbm.error" title="dbm.ndbm.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">dbm.ndbm.error</span></code></a>) instead of <a class="reference internal" href="../library/exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a>.
  1860. (Contributed by Xiang Zhang in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33106">bpo-33106</a>.)</p></li>
  1861. <li><p>Simplified AST for literals. All constants will be represented as
  1862. <a class="reference internal" href="../library/ast.html#ast.Constant" title="ast.Constant"><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Constant</span></code></a> instances. Instantiating old classes <code class="docutils literal notranslate"><span class="pre">Num</span></code>,
  1863. <code class="docutils literal notranslate"><span class="pre">Str</span></code>, <code class="docutils literal notranslate"><span class="pre">Bytes</span></code>, <code class="docutils literal notranslate"><span class="pre">NameConstant</span></code> and <code class="docutils literal notranslate"><span class="pre">Ellipsis</span></code> will return
  1864. an instance of <code class="docutils literal notranslate"><span class="pre">Constant</span></code>.
  1865. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32892">bpo-32892</a>.)</p></li>
  1866. <li><p><a class="reference internal" href="../library/os.path.html#os.path.expanduser" title="os.path.expanduser"><code class="xref py py-func docutils literal notranslate"><span class="pre">expanduser()</span></code></a> on Windows now prefers the <span class="target" id="index-20"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">USERPROFILE</span></code>
  1867. environment variable and does not use <span class="target" id="index-21"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">HOME</span></code>, which is not normally
  1868. set for regular user accounts.
  1869. (Contributed by Anthony Sottile in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36264">bpo-36264</a>.)</p></li>
  1870. <li><p>The exception <a class="reference internal" href="../library/asyncio-exceptions.html#asyncio.CancelledError" title="asyncio.CancelledError"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.CancelledError</span></code></a> now inherits from
  1871. <a class="reference internal" href="../library/exceptions.html#BaseException" title="BaseException"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseException</span></code></a> rather than <a class="reference internal" href="../library/exceptions.html#Exception" title="Exception"><code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></a> and no longer inherits
  1872. from <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.CancelledError" title="concurrent.futures.CancelledError"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.CancelledError</span></code></a>.
  1873. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32528">bpo-32528</a>.)</p></li>
  1874. <li><p>The function <a class="reference internal" href="../library/asyncio-task.html#asyncio.wait_for" title="asyncio.wait_for"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.wait_for()</span></code></a> now correctly waits for cancellation
  1875. when using an instance of <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a>. Previously, upon reaching
  1876. <em>timeout</em>, it was cancelled and immediately returned.
  1877. (Contributed by Elvis Pranskevichus in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32751">bpo-32751</a>.)</p></li>
  1878. <li><p>The function <a class="reference internal" href="../library/asyncio-protocol.html#asyncio.BaseTransport.get_extra_info" title="asyncio.BaseTransport.get_extra_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.BaseTransport.get_extra_info()</span></code></a> now returns a safe
  1879. to use socket object when ‘socket’ is passed to the <em>name</em> parameter.
  1880. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37027">bpo-37027</a>.)</p></li>
  1881. <li><p><a class="reference internal" href="../library/asyncio-protocol.html#asyncio.BufferedProtocol" title="asyncio.BufferedProtocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.BufferedProtocol</span></code></a> has graduated to the stable API.</p></li>
  1882. </ul>
  1883. <ul class="simple" id="bpo-36085-whatsnew">
  1884. <li><p>DLL dependencies for extension modules and DLLs loaded with <a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a> on
  1885. Windows are now resolved more securely. Only the system paths, the directory
  1886. containing the DLL or PYD file, and directories added with
  1887. <a class="reference internal" href="../library/os.html#os.add_dll_directory" title="os.add_dll_directory"><code class="xref py py-func docutils literal notranslate"><span class="pre">add_dll_directory()</span></code></a> are searched for load-time dependencies.
  1888. Specifically, <span class="target" id="index-22"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> and the current working directory are no longer
  1889. used, and modifications to these will no longer have any effect on normal DLL
  1890. resolution. If your application relies on these mechanisms, you should check
  1891. for <a class="reference internal" href="../library/os.html#os.add_dll_directory" title="os.add_dll_directory"><code class="xref py py-func docutils literal notranslate"><span class="pre">add_dll_directory()</span></code></a> and if it exists, use it to add your DLLs
  1892. directory while loading your library. Note that Windows 7 users will need to
  1893. ensure that Windows Update KB2533623 has been installed (this is also verified
  1894. by the installer).
  1895. (Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36085">bpo-36085</a>.)</p></li>
  1896. <li><p>The header files and functions related to pgen have been removed after its
  1897. replacement by a pure Python implementation. (Contributed by Pablo Galindo
  1898. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36623">bpo-36623</a>.)</p></li>
  1899. <li><p><a class="reference internal" href="../library/types.html#types.CodeType" title="types.CodeType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.CodeType</span></code></a> has a new parameter in the second position of the
  1900. constructor (<em>posonlyargcount</em>) to support positional-only arguments defined
  1901. in <span class="target" id="index-23"></span><a class="pep reference external" href="https://peps.python.org/pep-0570/"><strong>PEP 570</strong></a>. The first argument (<em>argcount</em>) now represents the total
  1902. number of positional arguments (including positional-only arguments). The new
  1903. <code class="docutils literal notranslate"><span class="pre">replace()</span></code> method of <a class="reference internal" href="../library/types.html#types.CodeType" title="types.CodeType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.CodeType</span></code></a> can be used to make the code
  1904. future-proof.</p></li>
  1905. <li><p>The parameter <code class="docutils literal notranslate"><span class="pre">digestmod</span></code> for <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">hmac.new()</span></code></a> no longer uses the MD5 digest
  1906. by default.</p></li>
  1907. </ul>
  1908. </section>
  1909. <section id="changes-in-the-c-api">
  1910. <h3>Changes in the C API<a class="headerlink" href="#changes-in-the-c-api" title="Link to this heading">¶</a></h3>
  1911. <ul>
  1912. <li><p>The <a class="reference internal" href="../c-api/veryhigh.html#c.PyCompilerFlags" title="PyCompilerFlags"><code class="xref c c-struct docutils literal notranslate"><span class="pre">PyCompilerFlags</span></code></a> structure got a new <em>cf_feature_version</em>
  1913. field. It should be initialized to <code class="docutils literal notranslate"><span class="pre">PY_MINOR_VERSION</span></code>. The field is ignored
  1914. by default, and is used if and only if <code class="docutils literal notranslate"><span class="pre">PyCF_ONLY_AST</span></code> flag is set in
  1915. <em>cf_flags</em>.
  1916. (Contributed by Guido van Rossum in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35766">bpo-35766</a>.)</p></li>
  1917. <li><p>The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_ReInitThreads()</span></code> function has been removed from the C API.
  1918. It should not be called explicitly: use <a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork_Child" title="PyOS_AfterFork_Child"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Child()</span></code></a>
  1919. instead.
  1920. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36728">bpo-36728</a>.)</p></li>
  1921. <li><p>On Unix, C extensions are no longer linked to libpython except on Android
  1922. and Cygwin. When Python is embedded, <code class="docutils literal notranslate"><span class="pre">libpython</span></code> must not be loaded with
  1923. <code class="docutils literal notranslate"><span class="pre">RTLD_LOCAL</span></code>, but <code class="docutils literal notranslate"><span class="pre">RTLD_GLOBAL</span></code> instead. Previously, using
  1924. <code class="docutils literal notranslate"><span class="pre">RTLD_LOCAL</span></code>, it was already not possible to load C extensions which
  1925. were not linked to <code class="docutils literal notranslate"><span class="pre">libpython</span></code>, like C extensions of the standard
  1926. library built by the <code class="docutils literal notranslate"><span class="pre">*shared*</span></code> section of <code class="docutils literal notranslate"><span class="pre">Modules/Setup</span></code>.
  1927. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21536">bpo-21536</a>.)</p></li>
  1928. <li><p>Use of <code class="docutils literal notranslate"><span class="pre">#</span></code> variants of formats in parsing or building value (e.g.
  1929. <a class="reference internal" href="../c-api/arg.html#c.PyArg_ParseTuple" title="PyArg_ParseTuple"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTuple()</span></code></a>, <a class="reference internal" href="../c-api/arg.html#c.Py_BuildValue" title="Py_BuildValue"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_BuildValue()</span></code></a>, <a class="reference internal" href="../c-api/call.html#c.PyObject_CallFunction" title="PyObject_CallFunction"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CallFunction()</span></code></a>,
  1930. etc.) without <code class="docutils literal notranslate"><span class="pre">PY_SSIZE_T_CLEAN</span></code> defined raises <code class="docutils literal notranslate"><span class="pre">DeprecationWarning</span></code> now.
  1931. It will be removed in 3.10 or 4.0. Read <a class="reference internal" href="../c-api/arg.html#arg-parsing"><span class="std std-ref">Parsing arguments and building values</span></a> for detail.
  1932. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36381">bpo-36381</a>.)</p></li>
  1933. <li><p>Instances of heap-allocated types (such as those created with
  1934. <a class="reference internal" href="../c-api/type.html#c.PyType_FromSpec" title="PyType_FromSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromSpec()</span></code></a>) hold a reference to their type object.
  1935. Increasing the reference count of these type objects has been moved from
  1936. <a class="reference internal" href="../c-api/type.html#c.PyType_GenericAlloc" title="PyType_GenericAlloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GenericAlloc()</span></code></a> to the more low-level functions,
  1937. <a class="reference internal" href="../c-api/allocation.html#c.PyObject_Init" title="PyObject_Init"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Init()</span></code></a> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_INIT()</span></code>.
  1938. This makes types created through <a class="reference internal" href="../c-api/type.html#c.PyType_FromSpec" title="PyType_FromSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromSpec()</span></code></a> behave like
  1939. other classes in managed code.</p>
  1940. <p><a class="reference internal" href="../c-api/typeobj.html#static-types"><span class="std std-ref">Statically allocated types</span></a> are not affected.</p>
  1941. <p>For the vast majority of cases, there should be no side effect.
  1942. However, types that manually increase the reference count after allocating
  1943. an instance (perhaps to work around the bug) may now become immortal.
  1944. To avoid this, these classes need to call Py_DECREF on the type object
  1945. during instance deallocation.</p>
  1946. <p>To correctly port these types into 3.8, please apply the following
  1947. changes:</p>
  1948. <ul>
  1949. <li><p>Remove <a class="reference internal" href="../c-api/refcounting.html#c.Py_INCREF" title="Py_INCREF"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_INCREF</span></code></a> on the type object after allocating an
  1950. instance - if any.
  1951. This may happen after calling <a class="reference internal" href="../c-api/allocation.html#c.PyObject_New" title="PyObject_New"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyObject_New</span></code></a>,
  1952. <a class="reference internal" href="../c-api/allocation.html#c.PyObject_NewVar" title="PyObject_NewVar"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyObject_NewVar</span></code></a>, <a class="reference internal" href="../c-api/gcsupport.html#c.PyObject_GC_New" title="PyObject_GC_New"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GC_New()</span></code></a>,
  1953. <a class="reference internal" href="../c-api/gcsupport.html#c.PyObject_GC_NewVar" title="PyObject_GC_NewVar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GC_NewVar()</span></code></a>, or any other custom allocator that uses
  1954. <a class="reference internal" href="../c-api/allocation.html#c.PyObject_Init" title="PyObject_Init"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Init()</span></code></a> or <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_INIT()</span></code>.</p>
  1955. <p>Example:</p>
  1956. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">static</span><span class="w"> </span><span class="n">foo_struct</span><span class="w"> </span><span class="o">*</span>
  1957. <span class="nf">foo_new</span><span class="p">(</span><span class="n">PyObject</span><span class="w"> </span><span class="o">*</span><span class="n">type</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
  1958. <span class="w"> </span><span class="n">foo_struct</span><span class="w"> </span><span class="o">*</span><span class="n">foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyObject_GC_New</span><span class="p">(</span><span class="n">foo_struct</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">PyTypeObject</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="w"> </span><span class="n">type</span><span class="p">);</span>
  1959. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">foo</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span>
  1960. <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span>
  1961. <span class="cp">#if PY_VERSION_HEX &lt; 0x03080000</span>
  1962. <span class="w"> </span><span class="c1">// Workaround for Python issue 35810; no longer necessary in Python 3.8</span>
  1963. <span class="w"> </span><span class="n">PY_INCREF</span><span class="p">(</span><span class="n">type</span><span class="p">)</span>
  1964. <span class="cp">#endif</span>
  1965. <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">foo</span><span class="p">;</span>
  1966. <span class="p">}</span>
  1967. </pre></div>
  1968. </div>
  1969. </li>
  1970. <li><p>Ensure that all custom <code class="docutils literal notranslate"><span class="pre">tp_dealloc</span></code> functions of heap-allocated types
  1971. decrease the type’s reference count.</p>
  1972. <p>Example:</p>
  1973. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="k">static</span><span class="w"> </span><span class="kt">void</span>
  1974. <span class="nf">foo_dealloc</span><span class="p">(</span><span class="n">foo_struct</span><span class="w"> </span><span class="o">*</span><span class="n">instance</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
  1975. <span class="w"> </span><span class="n">PyObject</span><span class="w"> </span><span class="o">*</span><span class="n">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Py_TYPE</span><span class="p">(</span><span class="n">instance</span><span class="p">);</span>
  1976. <span class="w"> </span><span class="n">PyObject_GC_Del</span><span class="p">(</span><span class="n">instance</span><span class="p">);</span>
  1977. <span class="cp">#if PY_VERSION_HEX &gt;= 0x03080000</span>
  1978. <span class="w"> </span><span class="c1">// This was not needed before Python 3.8 (Python issue 35810)</span>
  1979. <span class="w"> </span><span class="n">Py_DECREF</span><span class="p">(</span><span class="n">type</span><span class="p">);</span>
  1980. <span class="cp">#endif</span>
  1981. <span class="p">}</span>
  1982. </pre></div>
  1983. </div>
  1984. </li>
  1985. </ul>
  1986. <p>(Contributed by Eddie Elizondo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35810">bpo-35810</a>.)</p>
  1987. </li>
  1988. <li><p>The <a class="reference internal" href="../c-api/intro.html#c.Py_DEPRECATED" title="Py_DEPRECATED"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_DEPRECATED()</span></code></a> macro has been implemented for MSVC.
  1989. The macro now must be placed before the symbol name.</p>
  1990. <p>Example:</p>
  1991. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">Py_DEPRECATED</span><span class="p">(</span><span class="mf">3.8</span><span class="p">)</span><span class="w"> </span><span class="n">PyAPI_FUNC</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="w"> </span><span class="n">Py_OldFunction</span><span class="p">(</span><span class="kt">void</span><span class="p">);</span>
  1992. </pre></div>
  1993. </div>
  1994. <p>(Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33407">bpo-33407</a>.)</p>
  1995. </li>
  1996. <li><p>The interpreter does not pretend to support binary compatibility of
  1997. extension types across feature releases, anymore. A <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>
  1998. exported by a third-party extension module is supposed to have all the
  1999. slots expected in the current Python version, including
  2000. <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">tp_finalize</span></code></a> (<a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_HAVE_FINALIZE" title="Py_TPFLAGS_HAVE_FINALIZE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_HAVE_FINALIZE</span></code></a>
  2001. is not checked anymore before reading <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">tp_finalize</span></code></a>).</p>
  2002. <p>(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32388">bpo-32388</a>.)</p>
  2003. </li>
  2004. <li><p>The functions <code class="xref c c-func docutils literal notranslate"><span class="pre">PyNode_AddChild()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyParser_AddToken()</span></code> now accept
  2005. two additional <code class="docutils literal notranslate"><span class="pre">int</span></code> arguments <em>end_lineno</em> and <em>end_col_offset</em>.</p></li>
  2006. <li><p>The <code class="file docutils literal notranslate"><span class="pre">libpython38.a</span></code> file to allow MinGW tools to link directly against
  2007. <code class="file docutils literal notranslate"><span class="pre">python38.dll</span></code> is no longer included in the regular Windows distribution.
  2008. If you require this file, it may be generated with the <code class="docutils literal notranslate"><span class="pre">gendef</span></code> and
  2009. <code class="docutils literal notranslate"><span class="pre">dlltool</span></code> tools, which are part of the MinGW binutils package:</p>
  2010. <div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>gendef<span class="w"> </span>-<span class="w"> </span>python38.dll<span class="w"> </span>&gt;<span class="w"> </span>tmp.def
  2011. dlltool<span class="w"> </span>--dllname<span class="w"> </span>python38.dll<span class="w"> </span>--def<span class="w"> </span>tmp.def<span class="w"> </span>--output-lib<span class="w"> </span>libpython38.a
  2012. </pre></div>
  2013. </div>
  2014. <p>The location of an installed <code class="file docutils literal notranslate"><span class="pre">pythonXY.dll</span></code> will depend on the
  2015. installation options and the version and language of Windows. See
  2016. <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. The resulting library should be
  2017. placed in the same directory as <code class="file docutils literal notranslate"><span class="pre">pythonXY.lib</span></code>, which is generally the
  2018. <code class="file docutils literal notranslate"><span class="pre">libs</span></code> directory under your Python installation.</p>
  2019. <p>(Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37351">bpo-37351</a>.)</p>
  2020. </li>
  2021. </ul>
  2022. </section>
  2023. <section id="cpython-bytecode-changes">
  2024. <h3>CPython bytecode changes<a class="headerlink" href="#cpython-bytecode-changes" title="Link to this heading">¶</a></h3>
  2025. <ul>
  2026. <li><p>The interpreter loop has been simplified by moving the logic of unrolling
  2027. the stack of blocks into the compiler. The compiler emits now explicit
  2028. instructions for adjusting the stack of values and calling the
  2029. cleaning-up code for <a class="reference internal" href="../reference/simple_stmts.html#break"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">break</span></code></a>, <a class="reference internal" href="../reference/simple_stmts.html#continue"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">continue</span></code></a> and
  2030. <a class="reference internal" href="../reference/simple_stmts.html#return"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">return</span></code></a>.</p>
  2031. <p>Removed opcodes <code class="xref std std-opcode docutils literal notranslate"><span class="pre">BREAK_LOOP</span></code>, <code class="xref std std-opcode docutils literal notranslate"><span class="pre">CONTINUE_LOOP</span></code>,
  2032. <code class="xref std std-opcode docutils literal notranslate"><span class="pre">SETUP_LOOP</span></code> and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">SETUP_EXCEPT</span></code>. Added new opcodes
  2033. <code class="xref std std-opcode docutils literal notranslate"><span class="pre">ROT_FOUR</span></code>, <code class="xref std std-opcode docutils literal notranslate"><span class="pre">BEGIN_FINALLY</span></code>, <code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FINALLY</span></code> and
  2034. <code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_FINALLY</span></code>. Changed the behavior of <code class="xref std std-opcode docutils literal notranslate"><span class="pre">END_FINALLY</span></code>
  2035. and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">WITH_CLEANUP_START</span></code>.</p>
  2036. <p>(Contributed by Mark Shannon, Antoine Pitrou and Serhiy Storchaka in
  2037. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17611">bpo-17611</a>.)</p>
  2038. </li>
  2039. <li><p>Added new opcode <a class="reference internal" href="../library/dis.html#opcode-END_ASYNC_FOR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">END_ASYNC_FOR</span></code></a> for handling exceptions raised
  2040. when awaiting a next item in an <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> loop.
  2041. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33041">bpo-33041</a>.)</p></li>
  2042. <li><p>The <a class="reference internal" href="../library/dis.html#opcode-MAP_ADD"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">MAP_ADD</span></code></a> now expects the value as the first element in the
  2043. stack and the key as the second element. This change was made so the key
  2044. is always evaluated before the value in dictionary comprehensions, as
  2045. proposed by <span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0572/"><strong>PEP 572</strong></a>. (Contributed by Jörn Heissler in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35224">bpo-35224</a>.)</p></li>
  2046. </ul>
  2047. </section>
  2048. <section id="demos-and-tools">
  2049. <h3>Demos and Tools<a class="headerlink" href="#demos-and-tools" title="Link to this heading">¶</a></h3>
  2050. <p>Added a benchmark script for timing various ways to access variables:
  2051. <code class="docutils literal notranslate"><span class="pre">Tools/scripts/var_access_benchmark.py</span></code>.
  2052. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35884">bpo-35884</a>.)</p>
  2053. <p>Here’s a summary of performance improvements since Python 3.3:</p>
  2054. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Python version 3.3 3.4 3.5 3.6 3.7 3.8
  2055. -------------- --- --- --- --- --- ---
  2056. Variable and attribute read access:
  2057. read_local 4.0 7.1 7.1 5.4 5.1 3.9
  2058. read_nonlocal 5.3 7.1 8.1 5.8 5.4 4.4
  2059. read_global 13.3 15.5 19.0 14.3 13.6 7.6
  2060. read_builtin 20.0 21.1 21.6 18.5 19.0 7.5
  2061. read_classvar_from_class 20.5 25.6 26.5 20.7 19.5 18.4
  2062. read_classvar_from_instance 18.5 22.8 23.5 18.8 17.1 16.4
  2063. read_instancevar 26.8 32.4 33.1 28.0 26.3 25.4
  2064. read_instancevar_slots 23.7 27.8 31.3 20.8 20.8 20.2
  2065. read_namedtuple 68.5 73.8 57.5 45.0 46.8 18.4
  2066. read_boundmethod 29.8 37.6 37.9 29.6 26.9 27.7
  2067. Variable and attribute write access:
  2068. write_local 4.6 8.7 9.3 5.5 5.3 4.3
  2069. write_nonlocal 7.3 10.5 11.1 5.6 5.5 4.7
  2070. write_global 15.9 19.7 21.2 18.0 18.0 15.8
  2071. write_classvar 81.9 92.9 96.0 104.6 102.1 39.2
  2072. write_instancevar 36.4 44.6 45.8 40.0 38.9 35.5
  2073. write_instancevar_slots 28.7 35.6 36.1 27.3 26.6 25.7
  2074. Data structure read access:
  2075. read_list 19.2 24.2 24.5 20.8 20.8 19.0
  2076. read_deque 19.9 24.7 25.5 20.2 20.6 19.8
  2077. read_dict 19.7 24.3 25.7 22.3 23.0 21.0
  2078. read_strdict 17.9 22.6 24.3 19.5 21.2 18.9
  2079. Data structure write access:
  2080. write_list 21.2 27.1 28.5 22.5 21.6 20.0
  2081. write_deque 23.8 28.7 30.1 22.7 21.8 23.5
  2082. write_dict 25.9 31.4 33.3 29.3 29.2 24.7
  2083. write_strdict 22.9 28.4 29.9 27.5 25.2 23.1
  2084. Stack (or queue) operations:
  2085. list_append_pop 144.2 93.4 112.7 75.4 74.2 50.8
  2086. deque_append_pop 30.4 43.5 57.0 49.4 49.2 42.5
  2087. deque_append_popleft 30.8 43.7 57.3 49.7 49.7 42.8
  2088. Timing loop:
  2089. loop_overhead 0.3 0.5 0.6 0.4 0.3 0.3
  2090. </pre></div>
  2091. </div>
  2092. <p>The benchmarks were measured on an
  2093. <a class="reference external" href="https://ark.intel.com/content/www/us/en/ark/products/76088/intel-core-i7-4960hq-processor-6m-cache-up-to-3-80-ghz.html">Intel® Core™ i7-4960HQ processor</a>
  2094. running the macOS 64-bit builds found at
  2095. <a class="reference external" href="https://www.python.org/downloads/macos/">python.org</a>.
  2096. The benchmark script displays timings in nanoseconds.</p>
  2097. </section>
  2098. </section>
  2099. <section id="notable-changes-in-python-3-8-1">
  2100. <h2>Notable changes in Python 3.8.1<a class="headerlink" href="#notable-changes-in-python-3-8-1" title="Link to this heading">¶</a></h2>
  2101. <p>Due to significant security concerns, the <em>reuse_address</em> parameter of
  2102. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_datagram_endpoint" title="asyncio.loop.create_datagram_endpoint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.create_datagram_endpoint()</span></code></a> is no longer supported. This is
  2103. because of the behavior of the socket option <code class="docutils literal notranslate"><span class="pre">SO_REUSEADDR</span></code> in UDP. For more
  2104. details, see the documentation for <code class="docutils literal notranslate"><span class="pre">loop.create_datagram_endpoint()</span></code>.
  2105. (Contributed by Kyle Stanley, Antoine Pitrou, and Yury Selivanov in
  2106. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37228">bpo-37228</a>.)</p>
  2107. </section>
  2108. <section id="notable-changes-in-python-3-8-2">
  2109. <h2>Notable changes in Python 3.8.2<a class="headerlink" href="#notable-changes-in-python-3-8-2" title="Link to this heading">¶</a></h2>
  2110. <p>Fixed a regression with the <code class="docutils literal notranslate"><span class="pre">ignore</span></code> callback of <a class="reference internal" href="../library/shutil.html#shutil.copytree" title="shutil.copytree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.copytree()</span></code></a>.
  2111. The argument types are now str and List[str] again.
  2112. (Contributed by Manuel Barkhau and Giampaolo Rodola in <a class="reference external" href="https://github.com/python/cpython/issues/83571">gh-83571</a>.)</p>
  2113. </section>
  2114. <section id="notable-changes-in-python-3-8-3">
  2115. <h2>Notable changes in Python 3.8.3<a class="headerlink" href="#notable-changes-in-python-3-8-3" title="Link to this heading">¶</a></h2>
  2116. <p>The constant values of future flags in the <a class="reference internal" href="../library/__future__.html#module-__future__" title="__future__: Future statement definitions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">__future__</span></code></a> module
  2117. are updated in order to prevent collision with compiler flags. Previously
  2118. <code class="docutils literal notranslate"><span class="pre">PyCF_ALLOW_TOP_LEVEL_AWAIT</span></code> was clashing with <code class="docutils literal notranslate"><span class="pre">CO_FUTURE_DIVISION</span></code>.
  2119. (Contributed by Batuhan Taskaya in <a class="reference external" href="https://github.com/python/cpython/issues/83743">gh-83743</a>)</p>
  2120. </section>
  2121. <section id="notable-changes-in-python-3-8-8">
  2122. <h2>Notable changes in Python 3.8.8<a class="headerlink" href="#notable-changes-in-python-3-8-8" title="Link to this heading">¶</a></h2>
  2123. <p>Earlier Python versions allowed using both <code class="docutils literal notranslate"><span class="pre">;</span></code> and <code class="docutils literal notranslate"><span class="pre">&amp;</span></code> as
  2124. query parameter separators in <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.parse_qs" title="urllib.parse.parse_qs"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.parse_qs()</span></code></a> and
  2125. <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.parse_qsl" title="urllib.parse.parse_qsl"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.parse_qsl()</span></code></a>. Due to security concerns, and to conform with
  2126. newer W3C recommendations, this has been changed to allow only a single
  2127. separator key, with <code class="docutils literal notranslate"><span class="pre">&amp;</span></code> as the default. This change also affects
  2128. <a class="reference internal" href="../library/cgi.html#cgi.parse" title="cgi.parse"><code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.parse()</span></code></a> and <a class="reference internal" href="../library/cgi.html#cgi.parse_multipart" title="cgi.parse_multipart"><code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.parse_multipart()</span></code></a> as they use the affected
  2129. functions internally. For more details, please see their respective
  2130. documentation.
  2131. (Contributed by Adam Goldschmidt, Senthil Kumaran and Ken Jin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42967">bpo-42967</a>.)</p>
  2132. </section>
  2133. <section id="notable-changes-in-python-3-8-9">
  2134. <h2>Notable changes in Python 3.8.9<a class="headerlink" href="#notable-changes-in-python-3-8-9" title="Link to this heading">¶</a></h2>
  2135. <p>A security fix alters the <a class="reference internal" href="../library/ftplib.html#ftplib.FTP" title="ftplib.FTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">ftplib.FTP</span></code></a> behavior to not trust the
  2136. IPv4 address sent from the remote server when setting up a passive data
  2137. channel. We reuse the ftp server IP address instead. For unusual code
  2138. requiring the old behavior, set a <code class="docutils literal notranslate"><span class="pre">trust_server_pasv_ipv4_address</span></code>
  2139. attribute on your FTP instance to <code class="docutils literal notranslate"><span class="pre">True</span></code>. (See <a class="reference external" href="https://github.com/python/cpython/issues/87451">gh-87451</a>)</p>
  2140. </section>
  2141. <section id="notable-changes-in-python-3-8-10">
  2142. <h2>Notable changes in Python 3.8.10<a class="headerlink" href="#notable-changes-in-python-3-8-10" title="Link to this heading">¶</a></h2>
  2143. <section id="macos-11-0-big-sur-and-apple-silicon-mac-support">
  2144. <h3>macOS 11.0 (Big Sur) and Apple Silicon Mac support<a class="headerlink" href="#macos-11-0-big-sur-and-apple-silicon-mac-support" title="Link to this heading">¶</a></h3>
  2145. <p>As of 3.8.10, Python now supports building and running on macOS 11
  2146. (Big Sur) and on Apple Silicon Macs (based on the <code class="docutils literal notranslate"><span class="pre">ARM64</span></code> architecture).
  2147. A new universal build variant, <code class="docutils literal notranslate"><span class="pre">universal2</span></code>, is now available to natively
  2148. support both <code class="docutils literal notranslate"><span class="pre">ARM64</span></code> and <code class="docutils literal notranslate"><span class="pre">Intel</span> <span class="pre">64</span></code> in one set of executables.
  2149. Note that support for “weaklinking”, building binaries targeted for newer
  2150. versions of macOS that will also run correctly on older versions by
  2151. testing at runtime for missing features, is not included in this backport
  2152. from Python 3.9; to support a range of macOS versions, continue to target
  2153. for and build on the oldest version in the range.</p>
  2154. <p>(Originally contributed by Ronald Oussoren and Lawrence D’Anna in <a class="reference external" href="https://github.com/python/cpython/issues/85272">gh-85272</a>,
  2155. with fixes by FX Coudert and Eli Rykoff, and backported to 3.8 by Maxime Bélanger
  2156. and Ned Deily)</p>
  2157. </section>
  2158. </section>
  2159. <section id="id1">
  2160. <h2>Notable changes in Python 3.8.10<a class="headerlink" href="#id1" title="Link to this heading">¶</a></h2>
  2161. <section id="urllib-parse">
  2162. <h3>urllib.parse<a class="headerlink" href="#urllib-parse" title="Link to this heading">¶</a></h3>
  2163. <p>The presence of newline or tab characters in parts of a URL allows for some
  2164. forms of attacks. Following the WHATWG specification that updates <span class="target" id="index-25"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc3986.html"><strong>RFC 3986</strong></a>,
  2165. ASCII newline <code class="docutils literal notranslate"><span class="pre">\n</span></code>, <code class="docutils literal notranslate"><span class="pre">\r</span></code> and tab <code class="docutils literal notranslate"><span class="pre">\t</span></code> characters are stripped from the
  2166. URL by the parser in <a class="reference internal" href="../library/urllib.parse.html#module-urllib.parse" title="urllib.parse: Parse URLs into or assemble them from components."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.parse</span></code></a> preventing such attacks. The removal
  2167. characters are controlled by a new module level variable
  2168. <code class="docutils literal notranslate"><span class="pre">urllib.parse._UNSAFE_URL_BYTES_TO_REMOVE</span></code>. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43882">bpo-43882</a>)</p>
  2169. </section>
  2170. </section>
  2171. <section id="notable-changes-in-python-3-8-12">
  2172. <h2>Notable changes in Python 3.8.12<a class="headerlink" href="#notable-changes-in-python-3-8-12" title="Link to this heading">¶</a></h2>
  2173. <section id="id2">
  2174. <h3>Changes in the Python API<a class="headerlink" href="#id2" title="Link to this heading">¶</a></h3>
  2175. <p>Starting with Python 3.8.12 the <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> module no longer accepts
  2176. any leading zeros in IPv4 address strings. Leading zeros are ambiguous and
  2177. interpreted as octal notation by some libraries. For example the legacy
  2178. function <a class="reference internal" href="../library/socket.html#socket.inet_aton" title="socket.inet_aton"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.inet_aton()</span></code></a> treats leading zeros as octal notation.
  2179. glibc implementation of modern <a class="reference internal" href="../library/socket.html#socket.inet_pton" title="socket.inet_pton"><code class="xref py py-func docutils literal notranslate"><span class="pre">inet_pton()</span></code></a> does not accept
  2180. any leading zeros.</p>
  2181. <p>(Originally contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36384">bpo-36384</a>, and backported
  2182. to 3.8 by Achraf Merzouki.)</p>
  2183. </section>
  2184. </section>
  2185. <section id="notable-security-feature-in-3-8-14">
  2186. <h2>Notable security feature in 3.8.14<a class="headerlink" href="#notable-security-feature-in-3-8-14" title="Link to this heading">¶</a></h2>
  2187. <p>Converting between <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> and <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> in bases other than 2
  2188. (binary), 4, 8 (octal), 16 (hexadecimal), or 32 such as base 10 (decimal)
  2189. now raises a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> if the number of digits in string form is
  2190. above a limit to avoid potential denial of service attacks due to the
  2191. algorithmic complexity. This is a mitigation for <a class="reference external" href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-10735">CVE-2020-10735</a>.
  2192. This limit can be configured or disabled by environment variable, command
  2193. line flag, or <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> APIs. See the <a class="reference internal" href="../library/stdtypes.html#int-max-str-digits"><span class="std std-ref">integer string conversion
  2194. length limitation</span></a> documentation. The default limit
  2195. is 4300 digits in string form.</p>
  2196. </section>
  2197. <section id="notable-changes-in-3-8-17">
  2198. <h2>Notable changes in 3.8.17<a class="headerlink" href="#notable-changes-in-3-8-17" title="Link to this heading">¶</a></h2>
  2199. <section id="id3">
  2200. <h3>tarfile<a class="headerlink" href="#id3" title="Link to this heading">¶</a></h3>
  2201. <ul class="simple">
  2202. <li><p>The extraction methods in <a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a>, and <a class="reference internal" href="../library/shutil.html#shutil.unpack_archive" title="shutil.unpack_archive"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.unpack_archive()</span></code></a>,
  2203. have a new a <em>filter</em> argument that allows limiting tar features than may be
  2204. surprising or dangerous, such as creating files outside the destination
  2205. directory.
  2206. See <a class="reference internal" href="../library/tarfile.html#tarfile-extraction-filter"><span class="std std-ref">Extraction filters</span></a> for details.
  2207. In Python 3.12, use without the <em>filter</em> argument will show a
  2208. <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>.
  2209. In Python 3.14, the default will switch to <code class="docutils literal notranslate"><span class="pre">'data'</span></code>.
  2210. (Contributed by Petr Viktorin in <span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-0706/"><strong>PEP 706</strong></a>.)</p></li>
  2211. </ul>
  2212. </section>
  2213. </section>
  2214. </section>
  2215. <div class="clearer"></div>
  2216. </div>
  2217. </div>
  2218. </div>
  2219. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  2220. <div class="sphinxsidebarwrapper">
  2221. <div>
  2222. <h3><a href="../contents.html">Table of Contents</a></h3>
  2223. <ul>
  2224. <li><a class="reference internal" href="#">What’s New In Python 3.8</a><ul>
  2225. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  2226. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  2227. <li><a class="reference internal" href="#assignment-expressions">Assignment expressions</a></li>
  2228. <li><a class="reference internal" href="#positional-only-parameters">Positional-only parameters</a></li>
  2229. <li><a class="reference internal" href="#parallel-filesystem-cache-for-compiled-bytecode-files">Parallel filesystem cache for compiled bytecode files</a></li>
  2230. <li><a class="reference internal" href="#debug-build-uses-the-same-abi-as-release-build">Debug build uses the same ABI as release build</a></li>
  2231. <li><a class="reference internal" href="#f-strings-support-for-self-documenting-expressions-and-debugging">f-strings support <code class="docutils literal notranslate"><span class="pre">=</span></code> for self-documenting expressions and debugging</a></li>
  2232. <li><a class="reference internal" href="#pep-578-python-runtime-audit-hooks">PEP 578: Python Runtime Audit Hooks</a></li>
  2233. <li><a class="reference internal" href="#pep-587-python-initialization-configuration">PEP 587: Python Initialization Configuration</a></li>
  2234. <li><a class="reference internal" href="#pep-590-vectorcall-a-fast-calling-protocol-for-cpython">PEP 590: Vectorcall: a fast calling protocol for CPython</a></li>
  2235. <li><a class="reference internal" href="#pickle-protocol-5-with-out-of-band-data-buffers">Pickle protocol 5 with out-of-band data buffers</a></li>
  2236. </ul>
  2237. </li>
  2238. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  2239. <li><a class="reference internal" href="#new-modules">New Modules</a></li>
  2240. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  2241. <li><a class="reference internal" href="#ast">ast</a></li>
  2242. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  2243. <li><a class="reference internal" href="#builtins">builtins</a></li>
  2244. <li><a class="reference internal" href="#collections">collections</a></li>
  2245. <li><a class="reference internal" href="#cprofile">cProfile</a></li>
  2246. <li><a class="reference internal" href="#csv">csv</a></li>
  2247. <li><a class="reference internal" href="#curses">curses</a></li>
  2248. <li><a class="reference internal" href="#ctypes">ctypes</a></li>
  2249. <li><a class="reference internal" href="#datetime">datetime</a></li>
  2250. <li><a class="reference internal" href="#functools">functools</a></li>
  2251. <li><a class="reference internal" href="#gc">gc</a></li>
  2252. <li><a class="reference internal" href="#gettext">gettext</a></li>
  2253. <li><a class="reference internal" href="#gzip">gzip</a></li>
  2254. <li><a class="reference internal" href="#idle-and-idlelib">IDLE and idlelib</a></li>
  2255. <li><a class="reference internal" href="#inspect">inspect</a></li>
  2256. <li><a class="reference internal" href="#io">io</a></li>
  2257. <li><a class="reference internal" href="#itertools">itertools</a></li>
  2258. <li><a class="reference internal" href="#json-tool">json.tool</a></li>
  2259. <li><a class="reference internal" href="#logging">logging</a></li>
  2260. <li><a class="reference internal" href="#math">math</a></li>
  2261. <li><a class="reference internal" href="#mmap">mmap</a></li>
  2262. <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
  2263. <li><a class="reference internal" href="#os">os</a></li>
  2264. <li><a class="reference internal" href="#os-path">os.path</a></li>
  2265. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  2266. <li><a class="reference internal" href="#pickle">pickle</a></li>
  2267. <li><a class="reference internal" href="#plistlib">plistlib</a></li>
  2268. <li><a class="reference internal" href="#pprint">pprint</a></li>
  2269. <li><a class="reference internal" href="#py-compile">py_compile</a></li>
  2270. <li><a class="reference internal" href="#shlex">shlex</a></li>
  2271. <li><a class="reference internal" href="#shutil">shutil</a></li>
  2272. <li><a class="reference internal" href="#socket">socket</a></li>
  2273. <li><a class="reference internal" href="#ssl">ssl</a></li>
  2274. <li><a class="reference internal" href="#statistics">statistics</a></li>
  2275. <li><a class="reference internal" href="#sys">sys</a></li>
  2276. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  2277. <li><a class="reference internal" href="#threading">threading</a></li>
  2278. <li><a class="reference internal" href="#tokenize">tokenize</a></li>
  2279. <li><a class="reference internal" href="#tkinter">tkinter</a></li>
  2280. <li><a class="reference internal" href="#time">time</a></li>
  2281. <li><a class="reference internal" href="#typing">typing</a></li>
  2282. <li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
  2283. <li><a class="reference internal" href="#unittest">unittest</a></li>
  2284. <li><a class="reference internal" href="#venv">venv</a></li>
  2285. <li><a class="reference internal" href="#weakref">weakref</a></li>
  2286. <li><a class="reference internal" href="#xml">xml</a></li>
  2287. <li><a class="reference internal" href="#xmlrpc">xmlrpc</a></li>
  2288. </ul>
  2289. </li>
  2290. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  2291. <li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
  2292. <li><a class="reference internal" href="#deprecated">Deprecated</a></li>
  2293. <li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
  2294. <li><a class="reference internal" href="#porting-to-python-3-8">Porting to Python 3.8</a><ul>
  2295. <li><a class="reference internal" href="#changes-in-python-behavior">Changes in Python behavior</a></li>
  2296. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  2297. <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
  2298. <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
  2299. <li><a class="reference internal" href="#demos-and-tools">Demos and Tools</a></li>
  2300. </ul>
  2301. </li>
  2302. <li><a class="reference internal" href="#notable-changes-in-python-3-8-1">Notable changes in Python 3.8.1</a></li>
  2303. <li><a class="reference internal" href="#notable-changes-in-python-3-8-2">Notable changes in Python 3.8.2</a></li>
  2304. <li><a class="reference internal" href="#notable-changes-in-python-3-8-3">Notable changes in Python 3.8.3</a></li>
  2305. <li><a class="reference internal" href="#notable-changes-in-python-3-8-8">Notable changes in Python 3.8.8</a></li>
  2306. <li><a class="reference internal" href="#notable-changes-in-python-3-8-9">Notable changes in Python 3.8.9</a></li>
  2307. <li><a class="reference internal" href="#notable-changes-in-python-3-8-10">Notable changes in Python 3.8.10</a><ul>
  2308. <li><a class="reference internal" href="#macos-11-0-big-sur-and-apple-silicon-mac-support">macOS 11.0 (Big Sur) and Apple Silicon Mac support</a></li>
  2309. </ul>
  2310. </li>
  2311. <li><a class="reference internal" href="#id1">Notable changes in Python 3.8.10</a><ul>
  2312. <li><a class="reference internal" href="#urllib-parse">urllib.parse</a></li>
  2313. </ul>
  2314. </li>
  2315. <li><a class="reference internal" href="#notable-changes-in-python-3-8-12">Notable changes in Python 3.8.12</a><ul>
  2316. <li><a class="reference internal" href="#id2">Changes in the Python API</a></li>
  2317. </ul>
  2318. </li>
  2319. <li><a class="reference internal" href="#notable-security-feature-in-3-8-14">Notable security feature in 3.8.14</a></li>
  2320. <li><a class="reference internal" href="#notable-changes-in-3-8-17">Notable changes in 3.8.17</a><ul>
  2321. <li><a class="reference internal" href="#id3">tarfile</a></li>
  2322. </ul>
  2323. </li>
  2324. </ul>
  2325. </li>
  2326. </ul>
  2327. </div>
  2328. <div>
  2329. <h4>Previous topic</h4>
  2330. <p class="topless"><a href="3.9.html"
  2331. title="previous chapter">What’s New In Python 3.9</a></p>
  2332. </div>
  2333. <div>
  2334. <h4>Next topic</h4>
  2335. <p class="topless"><a href="3.7.html"
  2336. title="next chapter">What’s New In Python 3.7</a></p>
  2337. </div>
  2338. <div role="note" aria-label="source link">
  2339. <h3>This Page</h3>
  2340. <ul class="this-page-menu">
  2341. <li><a href="../bugs.html">Report a Bug</a></li>
  2342. <li>
  2343. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.8.rst"
  2344. rel="nofollow">Show Source
  2345. </a>
  2346. </li>
  2347. </ul>
  2348. </div>
  2349. </div>
  2350. <div id="sidebarbutton" title="Collapse sidebar">
  2351. <span>«</span>
  2352. </div>
  2353. </div>
  2354. <div class="clearer"></div>
  2355. </div>
  2356. <div class="related" role="navigation" aria-label="related navigation">
  2357. <h3>Navigation</h3>
  2358. <ul>
  2359. <li class="right" style="margin-right: 10px">
  2360. <a href="../genindex.html" title="General Index"
  2361. >index</a></li>
  2362. <li class="right" >
  2363. <a href="../py-modindex.html" title="Python Module Index"
  2364. >modules</a> |</li>
  2365. <li class="right" >
  2366. <a href="3.7.html" title="What’s New In Python 3.7"
  2367. >next</a> |</li>
  2368. <li class="right" >
  2369. <a href="3.9.html" title="What’s New In Python 3.9"
  2370. >previous</a> |</li>
  2371. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  2372. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  2373. <li class="switchers">
  2374. <div class="language_switcher_placeholder"></div>
  2375. <div class="version_switcher_placeholder"></div>
  2376. </li>
  2377. <li>
  2378. </li>
  2379. <li id="cpython-language-and-version">
  2380. <a href="../index.html">3.12.3 Documentation</a> &#187;
  2381. </li>
  2382. <li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> &#187;</li>
  2383. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.8</a></li>
  2384. <li class="right">
  2385. <div class="inline-search" role="search">
  2386. <form class="inline-search" action="../search.html" method="get">
  2387. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  2388. <input type="submit" value="Go" />
  2389. </form>
  2390. </div>
  2391. |
  2392. </li>
  2393. <li class="right">
  2394. <label class="theme-selector-label">
  2395. Theme
  2396. <select class="theme-selector" oninput="activateTheme(this.value)">
  2397. <option value="auto" selected>Auto</option>
  2398. <option value="light">Light</option>
  2399. <option value="dark">Dark</option>
  2400. </select>
  2401. </label> |</li>
  2402. </ul>
  2403. </div>
  2404. <div class="footer">
  2405. &copy;
  2406. <a href="../copyright.html">
  2407. Copyright
  2408. </a>
  2409. 2001-2024, Python Software Foundation.
  2410. <br />
  2411. This page is licensed under the Python Software Foundation License Version 2.
  2412. <br />
  2413. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  2414. <br />
  2415. See <a href="/license.html">History and License</a> for more information.<br />
  2416. <br />
  2417. The Python Software Foundation is a non-profit corporation.
  2418. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  2419. <br />
  2420. <br />
  2421. Last updated on Apr 09, 2024 (13:47 UTC).
  2422. <a href="/bugs.html">Found a bug</a>?
  2423. <br />
  2424. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  2425. </div>
  2426. </body>
  2427. </html>
上海开阖软件有限公司 沪ICP备12045867号-1