gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1866 lines
216KB

  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.9" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/whatsnew/3.9.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Editor, Łukasz Langa,. This article explains the new features in Python 3.9, compared to 3.8. Python 3.9 was released on October 5, 2020. For full details, see the changelog. Summary – Release high..." />
  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, Łukasz Langa,. This article explains the new features in Python 3.9, compared to 3.8. Python 3.9 was released on October 5, 2020. For full details, see the changelog. Summary – Release high..." />
  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.9 &#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.8" href="3.8.html" />
  33. <link rel="prev" title="What’s New In Python 3.10" href="3.10.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/whatsnew/3.9.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.9</a><ul>
  86. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  87. <li><a class="reference internal" href="#you-should-check-for-deprecationwarning-in-your-code">You should check for DeprecationWarning in your code</a></li>
  88. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  89. <li><a class="reference internal" href="#dictionary-merge-update-operators">Dictionary Merge &amp; Update Operators</a></li>
  90. <li><a class="reference internal" href="#new-string-methods-to-remove-prefixes-and-suffixes">New String Methods to Remove Prefixes and Suffixes</a></li>
  91. <li><a class="reference internal" href="#type-hinting-generics-in-standard-collections">Type Hinting Generics in Standard Collections</a></li>
  92. <li><a class="reference internal" href="#new-parser">New Parser</a></li>
  93. </ul>
  94. </li>
  95. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  96. <li><a class="reference internal" href="#new-modules">New Modules</a><ul>
  97. <li><a class="reference internal" href="#zoneinfo">zoneinfo</a></li>
  98. <li><a class="reference internal" href="#graphlib">graphlib</a></li>
  99. </ul>
  100. </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="#compileall">compileall</a></li>
  105. <li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li>
  106. <li><a class="reference internal" href="#curses">curses</a></li>
  107. <li><a class="reference internal" href="#datetime">datetime</a></li>
  108. <li><a class="reference internal" href="#distutils">distutils</a></li>
  109. <li><a class="reference internal" href="#fcntl">fcntl</a></li>
  110. <li><a class="reference internal" href="#ftplib">ftplib</a></li>
  111. <li><a class="reference internal" href="#gc">gc</a></li>
  112. <li><a class="reference internal" href="#hashlib">hashlib</a></li>
  113. <li><a class="reference internal" href="#http">http</a></li>
  114. <li><a class="reference internal" href="#idle-and-idlelib">IDLE and idlelib</a></li>
  115. <li><a class="reference internal" href="#imaplib">imaplib</a></li>
  116. <li><a class="reference internal" href="#importlib">importlib</a></li>
  117. <li><a class="reference internal" href="#inspect">inspect</a></li>
  118. <li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
  119. <li><a class="reference internal" href="#math">math</a></li>
  120. <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
  121. <li><a class="reference internal" href="#nntplib">nntplib</a></li>
  122. <li><a class="reference internal" href="#os">os</a></li>
  123. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  124. <li><a class="reference internal" href="#pdb">pdb</a></li>
  125. <li><a class="reference internal" href="#poplib">poplib</a></li>
  126. <li><a class="reference internal" href="#pprint">pprint</a></li>
  127. <li><a class="reference internal" href="#pydoc">pydoc</a></li>
  128. <li><a class="reference internal" href="#random">random</a></li>
  129. <li><a class="reference internal" href="#signal">signal</a></li>
  130. <li><a class="reference internal" href="#smtplib">smtplib</a></li>
  131. <li><a class="reference internal" href="#socket">socket</a></li>
  132. <li><a class="reference internal" href="#time">time</a></li>
  133. <li><a class="reference internal" href="#sys">sys</a></li>
  134. <li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
  135. <li><a class="reference internal" href="#typing">typing</a></li>
  136. <li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
  137. <li><a class="reference internal" href="#venv">venv</a></li>
  138. <li><a class="reference internal" href="#xml">xml</a></li>
  139. </ul>
  140. </li>
  141. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  142. <li><a class="reference internal" href="#deprecated">Deprecated</a></li>
  143. <li><a class="reference internal" href="#removed">Removed</a></li>
  144. <li><a class="reference internal" href="#porting-to-python-3-9">Porting to Python 3.9</a><ul>
  145. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  146. <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
  147. <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
  148. </ul>
  149. </li>
  150. <li><a class="reference internal" href="#build-changes">Build Changes</a></li>
  151. <li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
  152. <li><a class="reference internal" href="#id1">New Features</a></li>
  153. <li><a class="reference internal" href="#id2">Porting to Python 3.9</a></li>
  154. <li><a class="reference internal" href="#id3">Removed</a></li>
  155. </ul>
  156. </li>
  157. <li><a class="reference internal" href="#notable-changes-in-python-3-9-1">Notable changes in Python 3.9.1</a><ul>
  158. <li><a class="reference internal" href="#id4">typing</a></li>
  159. <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>
  160. </ul>
  161. </li>
  162. <li><a class="reference internal" href="#notable-changes-in-python-3-9-2">Notable changes in Python 3.9.2</a><ul>
  163. <li><a class="reference internal" href="#collections-abc">collections.abc</a></li>
  164. <li><a class="reference internal" href="#urllib-parse">urllib.parse</a></li>
  165. </ul>
  166. </li>
  167. <li><a class="reference internal" href="#notable-changes-in-python-3-9-3">Notable changes in Python 3.9.3</a></li>
  168. <li><a class="reference internal" href="#notable-changes-in-python-3-9-5">Notable changes in Python 3.9.5</a><ul>
  169. <li><a class="reference internal" href="#id5">urllib.parse</a></li>
  170. </ul>
  171. </li>
  172. <li><a class="reference internal" href="#notable-security-feature-in-3-9-14">Notable security feature in 3.9.14</a></li>
  173. <li><a class="reference internal" href="#notable-changes-in-3-9-17">Notable changes in 3.9.17</a><ul>
  174. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  175. </ul>
  176. </li>
  177. </ul>
  178. </li>
  179. </ul>
  180. </div>
  181. <div>
  182. <h4>Previous topic</h4>
  183. <p class="topless"><a href="3.10.html"
  184. title="previous chapter">What’s New In Python 3.10</a></p>
  185. </div>
  186. <div>
  187. <h4>Next topic</h4>
  188. <p class="topless"><a href="3.8.html"
  189. title="next chapter">What’s New In Python 3.8</a></p>
  190. </div>
  191. <div role="note" aria-label="source link">
  192. <h3>This Page</h3>
  193. <ul class="this-page-menu">
  194. <li><a href="../bugs.html">Report a Bug</a></li>
  195. <li>
  196. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.9.rst"
  197. rel="nofollow">Show Source
  198. </a>
  199. </li>
  200. </ul>
  201. </div>
  202. </nav>
  203. </div>
  204. </div>
  205. <div class="related" role="navigation" aria-label="related navigation">
  206. <h3>Navigation</h3>
  207. <ul>
  208. <li class="right" style="margin-right: 10px">
  209. <a href="../genindex.html" title="General Index"
  210. accesskey="I">index</a></li>
  211. <li class="right" >
  212. <a href="../py-modindex.html" title="Python Module Index"
  213. >modules</a> |</li>
  214. <li class="right" >
  215. <a href="3.8.html" title="What’s New In Python 3.8"
  216. accesskey="N">next</a> |</li>
  217. <li class="right" >
  218. <a href="3.10.html" title="What’s New In Python 3.10"
  219. accesskey="P">previous</a> |</li>
  220. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  221. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  222. <li class="switchers">
  223. <div class="language_switcher_placeholder"></div>
  224. <div class="version_switcher_placeholder"></div>
  225. </li>
  226. <li>
  227. </li>
  228. <li id="cpython-language-and-version">
  229. <a href="../index.html">3.12.3 Documentation</a> &#187;
  230. </li>
  231. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> &#187;</li>
  232. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.9</a></li>
  233. <li class="right">
  234. <div class="inline-search" role="search">
  235. <form class="inline-search" action="../search.html" method="get">
  236. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  237. <input type="submit" value="Go" />
  238. </form>
  239. </div>
  240. |
  241. </li>
  242. <li class="right">
  243. <label class="theme-selector-label">
  244. Theme
  245. <select class="theme-selector" oninput="activateTheme(this.value)">
  246. <option value="auto" selected>Auto</option>
  247. <option value="light">Light</option>
  248. <option value="dark">Dark</option>
  249. </select>
  250. </label> |</li>
  251. </ul>
  252. </div>
  253. <div class="document">
  254. <div class="documentwrapper">
  255. <div class="bodywrapper">
  256. <div class="body" role="main">
  257. <section id="what-s-new-in-python-3-9">
  258. <h1>What’s New In Python 3.9<a class="headerlink" href="#what-s-new-in-python-3-9" title="Link to this heading">¶</a></h1>
  259. <dl class="field-list simple">
  260. <dt class="field-odd">Editor<span class="colon">:</span></dt>
  261. <dd class="field-odd"><p>Łukasz Langa</p>
  262. </dd>
  263. </dl>
  264. <p>This article explains the new features in Python 3.9, compared to 3.8.
  265. Python 3.9 was released on October 5, 2020.
  266. For full details, see the <a class="reference internal" href="changelog.html#changelog"><span class="std std-ref">changelog</span></a>.</p>
  267. <div class="admonition seealso">
  268. <p class="admonition-title">See also</p>
  269. <p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0596/"><strong>PEP 596</strong></a> - Python 3.9 Release Schedule</p>
  270. </div>
  271. <section id="summary-release-highlights">
  272. <h2>Summary – Release highlights<a class="headerlink" href="#summary-release-highlights" title="Link to this heading">¶</a></h2>
  273. <p>New syntax features:</p>
  274. <ul class="simple">
  275. <li><p><span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0584/"><strong>PEP 584</strong></a>, union operators added to <code class="docutils literal notranslate"><span class="pre">dict</span></code>;</p></li>
  276. <li><p><span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0585/"><strong>PEP 585</strong></a>, type hinting generics in standard collections;</p></li>
  277. <li><p><span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0614/"><strong>PEP 614</strong></a>, relaxed grammar restrictions on decorators.</p></li>
  278. </ul>
  279. <p>New built-in features:</p>
  280. <ul class="simple">
  281. <li><p><span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0616/"><strong>PEP 616</strong></a>, string methods to remove prefixes and suffixes.</p></li>
  282. </ul>
  283. <p>New features in the standard library:</p>
  284. <ul class="simple">
  285. <li><p><span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0593/"><strong>PEP 593</strong></a>, flexible function and variable annotations;</p></li>
  286. <li><p><a class="reference internal" href="../library/os.html#os.pidfd_open" title="os.pidfd_open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pidfd_open()</span></code></a> added that allows process management without races
  287. and signals.</p></li>
  288. </ul>
  289. <p>Interpreter improvements:</p>
  290. <ul class="simple">
  291. <li><p><span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0573/"><strong>PEP 573</strong></a>, fast access to module state from methods of C extension
  292. types;</p></li>
  293. <li><p><span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0617/"><strong>PEP 617</strong></a>, CPython now uses a new parser based on PEG;</p></li>
  294. <li><p>a number of Python builtins (range, tuple, set, frozenset, list, dict) are
  295. now sped up using <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0590/"><strong>PEP 590</strong></a> vectorcall;</p></li>
  296. <li><p>garbage collection does not block on resurrected objects;</p></li>
  297. <li><p>a number of Python modules (<code class="xref py py-mod docutils literal notranslate"><span class="pre">_abc</span></code>, <a class="reference internal" href="../library/audioop.html#module-audioop" title="audioop: Manipulate raw audio data. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code></a>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_bz2</span></code>,
  298. <code class="xref py py-mod docutils literal notranslate"><span class="pre">_codecs</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_contextvars</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_crypt</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_functools</span></code>,
  299. <code class="xref py py-mod docutils literal notranslate"><span class="pre">_json</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_locale</span></code>, <a class="reference internal" href="../library/math.html#module-math" title="math: Mathematical functions (sin() etc.)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">math</span></code></a>, <a class="reference internal" href="../library/operator.html#module-operator" title="operator: Functions corresponding to the standard operators."><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code></a>, <a class="reference internal" href="../library/resource.html#module-resource" title="resource: An interface to provide resource usage information on the current process. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">resource</span></code></a>,
  300. <a class="reference internal" href="../library/time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_weakref</span></code>) now use multiphase initialization as defined
  301. by PEP 489;</p></li>
  302. <li><p>a number of standard library modules (<a class="reference internal" href="../library/audioop.html#module-audioop" title="audioop: Manipulate raw audio data. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code></a>, <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>, <a class="reference internal" href="../library/grp.html#module-grp" title="grp: The group database (getgrnam() and friends). (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">grp</span></code></a>,
  303. <code class="xref py py-mod docutils literal notranslate"><span class="pre">_hashlib</span></code>, <a class="reference internal" href="../library/pwd.html#module-pwd" title="pwd: The password database (getpwnam() and friends). (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pwd</span></code></a>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">_posixsubprocess</span></code>, <a class="reference internal" href="../library/random.html#module-random" title="random: Generate pseudo-random numbers with various common distributions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">random</span></code></a>,
  304. <a class="reference internal" href="../library/select.html#module-select" title="select: Wait for I/O completion on multiple streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code></a>, <a class="reference internal" href="../library/struct.html#module-struct" title="struct: Interpret bytes as packed binary data."><code class="xref py py-mod docutils literal notranslate"><span class="pre">struct</span></code></a>, <a class="reference internal" href="../library/termios.html#module-termios" title="termios: POSIX style tty control. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">termios</span></code></a>, <a class="reference internal" href="../library/zlib.html#module-zlib" title="zlib: Low-level interface to compression and decompression routines compatible with gzip."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zlib</span></code></a>) are now using
  305. the stable ABI defined by PEP 384.</p></li>
  306. </ul>
  307. <p>New library modules:</p>
  308. <ul class="simple">
  309. <li><p><span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0615/"><strong>PEP 615</strong></a>, the IANA Time Zone Database is now present in the standard
  310. library in the <a class="reference internal" href="../library/zoneinfo.html#module-zoneinfo" title="zoneinfo: IANA time zone support"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zoneinfo</span></code></a> module;</p></li>
  311. <li><p>an implementation of a topological sort of a graph is now provided in
  312. the new <a class="reference internal" href="../library/graphlib.html#module-graphlib" title="graphlib: Functionality to operate with graph-like structures"><code class="xref py py-mod docutils literal notranslate"><span class="pre">graphlib</span></code></a> module.</p></li>
  313. </ul>
  314. <p>Release process changes:</p>
  315. <ul class="simple">
  316. <li><p><span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0602/"><strong>PEP 602</strong></a>, CPython adopts an annual release cycle.</p></li>
  317. </ul>
  318. </section>
  319. <section id="you-should-check-for-deprecationwarning-in-your-code">
  320. <h2>You should check for DeprecationWarning in your code<a class="headerlink" href="#you-should-check-for-deprecationwarning-in-your-code" title="Link to this heading">¶</a></h2>
  321. <p>When Python 2.7 was still supported, a lot of functionality in Python 3
  322. was kept for backward compatibility with Python 2.7. With the end of Python
  323. 2 support, these backward compatibility layers have been removed, or will
  324. be removed soon. Most of them emitted 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> warning for
  325. several years. For example, using <code class="docutils literal notranslate"><span class="pre">collections.Mapping</span></code> instead of
  326. <code class="docutils literal notranslate"><span class="pre">collections.abc.Mapping</span></code> emits 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> since Python
  327. 3.3, released in 2012.</p>
  328. <p>Test your application with the <a class="reference internal" href="../using/cmdline.html#cmdoption-W"><code class="xref std std-option docutils literal notranslate"><span class="pre">-W</span></code></a> <code class="docutils literal notranslate"><span class="pre">default</span></code> command-line option to see
  329. <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> and <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>, or even with
  330. <a class="reference internal" href="../using/cmdline.html#cmdoption-W"><code class="xref std std-option docutils literal notranslate"><span class="pre">-W</span></code></a> <code class="docutils literal notranslate"><span class="pre">error</span></code> to treat them as errors. <a class="reference internal" href="../library/warnings.html#warning-filter"><span class="std std-ref">Warnings Filter</span></a> can be used to ignore warnings from third-party code.</p>
  331. <p>Python 3.9 is the last version providing those Python 2 backward compatibility
  332. layers, to give more time to Python projects maintainers to organize the
  333. removal of the Python 2 support and add support for Python 3.9.</p>
  334. <p>Aliases to <a class="reference internal" href="../library/collections.abc.html#collections-abstract-base-classes"><span class="std std-ref">Abstract Base Classes</span></a> in
  335. 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, like <code class="docutils literal notranslate"><span class="pre">collections.Mapping</span></code> alias to
  336. <a class="reference internal" href="../library/collections.abc.html#collections.abc.Mapping" title="collections.abc.Mapping"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Mapping</span></code></a>, are kept for one last release for backward
  337. compatibility. They will be removed from Python 3.10.</p>
  338. <p>More generally, try to run your tests in the <a class="reference internal" href="../library/devmode.html#devmode"><span class="std std-ref">Python Development Mode</span></a> which helps to prepare your code to make it compatible with the
  339. next Python version.</p>
  340. <p>Note: a number of pre-existing deprecations were removed in this version of
  341. Python as well. Consult the <a class="reference internal" href="#removed-in-python-39"><span class="std std-ref">Removed</span></a> section.</p>
  342. </section>
  343. <section id="new-features">
  344. <h2>New Features<a class="headerlink" href="#new-features" title="Link to this heading">¶</a></h2>
  345. <section id="dictionary-merge-update-operators">
  346. <h3>Dictionary Merge &amp; Update Operators<a class="headerlink" href="#dictionary-merge-update-operators" title="Link to this heading">¶</a></h3>
  347. <p>Merge (<code class="docutils literal notranslate"><span class="pre">|</span></code>) and update (<code class="docutils literal notranslate"><span class="pre">|=</span></code>) operators have been added to the built-in
  348. <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> class. Those complement the existing <code class="docutils literal notranslate"><span class="pre">dict.update</span></code> and
  349. <code class="docutils literal notranslate"><span class="pre">{**d1,</span> <span class="pre">**d2}</span></code> methods of merging dictionaries.</p>
  350. <p>Example:</p>
  351. <div class="highlight-python3 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="p">{</span><span class="s2">&quot;key1&quot;</span><span class="p">:</span> <span class="s2">&quot;value1 from x&quot;</span><span class="p">,</span> <span class="s2">&quot;key2&quot;</span><span class="p">:</span> <span class="s2">&quot;value2 from x&quot;</span><span class="p">}</span>
  352. <span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;key2&quot;</span><span class="p">:</span> <span class="s2">&quot;value2 from y&quot;</span><span class="p">,</span> <span class="s2">&quot;key3&quot;</span><span class="p">:</span> <span class="s2">&quot;value3 from y&quot;</span><span class="p">}</span>
  353. <span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">|</span> <span class="n">y</span>
  354. <span class="go">{&#39;key1&#39;: &#39;value1 from x&#39;, &#39;key2&#39;: &#39;value2 from y&#39;, &#39;key3&#39;: &#39;value3 from y&#39;}</span>
  355. <span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">|</span> <span class="n">x</span>
  356. <span class="go">{&#39;key2&#39;: &#39;value2 from x&#39;, &#39;key3&#39;: &#39;value3 from y&#39;, &#39;key1&#39;: &#39;value1 from x&#39;}</span>
  357. </pre></div>
  358. </div>
  359. <p>See <span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0584/"><strong>PEP 584</strong></a> for a full description.
  360. (Contributed by Brandt Bucher in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36144">bpo-36144</a>.)</p>
  361. </section>
  362. <section id="new-string-methods-to-remove-prefixes-and-suffixes">
  363. <h3>New String Methods to Remove Prefixes and Suffixes<a class="headerlink" href="#new-string-methods-to-remove-prefixes-and-suffixes" title="Link to this heading">¶</a></h3>
  364. <p><a class="reference internal" href="../library/stdtypes.html#str.removeprefix" title="str.removeprefix"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.removeprefix(prefix)</span></code></a> and
  365. <a class="reference internal" href="../library/stdtypes.html#str.removesuffix" title="str.removesuffix"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.removesuffix(suffix)</span></code></a> have been added
  366. to easily remove an unneeded prefix or a suffix from a string. Corresponding
  367. <code class="docutils literal notranslate"><span class="pre">bytes</span></code>, <code class="docutils literal notranslate"><span class="pre">bytearray</span></code>, and <code class="docutils literal notranslate"><span class="pre">collections.UserString</span></code> methods have also been
  368. added. See <span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0616/"><strong>PEP 616</strong></a> for a full description. (Contributed by Dennis Sweeney in
  369. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39939">bpo-39939</a>.)</p>
  370. </section>
  371. <section id="type-hinting-generics-in-standard-collections">
  372. <h3>Type Hinting Generics in Standard Collections<a class="headerlink" href="#type-hinting-generics-in-standard-collections" title="Link to this heading">¶</a></h3>
  373. <p>In type annotations you can now use built-in collection types such as
  374. <code class="docutils literal notranslate"><span class="pre">list</span></code> and <code class="docutils literal notranslate"><span class="pre">dict</span></code> as generic types instead of importing the
  375. corresponding capitalized types (e.g. <code class="docutils literal notranslate"><span class="pre">List</span></code> or <code class="docutils literal notranslate"><span class="pre">Dict</span></code>) from
  376. <code class="docutils literal notranslate"><span class="pre">typing</span></code>. Some other types in the standard library are also now generic,
  377. for example <code class="docutils literal notranslate"><span class="pre">queue.Queue</span></code>.</p>
  378. <p>Example:</p>
  379. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">greet_all</span><span class="p">(</span><span class="n">names</span><span class="p">:</span> <span class="nb">list</span><span class="p">[</span><span class="nb">str</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
  380. <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
  381. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Hello&quot;</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
  382. </pre></div>
  383. </div>
  384. <p>See <span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0585/"><strong>PEP 585</strong></a> for more details. (Contributed by Guido van Rossum,
  385. Ethan Smith, and Batuhan Taşkaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39481">bpo-39481</a>.)</p>
  386. </section>
  387. <section id="new-parser">
  388. <h3>New Parser<a class="headerlink" href="#new-parser" title="Link to this heading">¶</a></h3>
  389. <p>Python 3.9 uses a new parser, based on <a class="reference external" href="https://en.wikipedia.org/wiki/Parsing_expression_grammar">PEG</a> instead
  390. of <a class="reference external" href="https://en.wikipedia.org/wiki/LL_parser">LL(1)</a>. The new
  391. parser’s performance is roughly comparable to that of the old parser,
  392. but the PEG formalism is more flexible than LL(1) when it comes to
  393. designing new language features. We’ll start using this flexibility
  394. in Python 3.10 and later.</p>
  395. <p>The <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> module uses the new parser and produces the same AST as
  396. the old parser.</p>
  397. <p>In Python 3.10, the old parser will be deleted and so will all
  398. functionality that depends on it (primarily the <code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code> module,
  399. which has long been deprecated). In Python 3.9 <em>only</em>, you can switch
  400. back to the LL(1) parser using a command line switch (<code class="docutils literal notranslate"><span class="pre">-X</span>
  401. <span class="pre">oldparser</span></code>) or an environment variable (<code class="docutils literal notranslate"><span class="pre">PYTHONOLDPARSER=1</span></code>).</p>
  402. <p>See <span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0617/"><strong>PEP 617</strong></a> for more details. (Contributed by Guido van Rossum,
  403. Pablo Galindo and Lysandros Nikolaou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40334">bpo-40334</a>.)</p>
  404. </section>
  405. </section>
  406. <section id="other-language-changes">
  407. <h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading">¶</a></h2>
  408. <ul>
  409. <li><p><a class="reference internal" href="../library/functions.html#import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> now raises <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> instead of
  410. <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>, which used to occur when a relative import went past
  411. its top-level package.
  412. (Contributed by Ngalim Siregar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37444">bpo-37444</a>.)</p></li>
  413. <li><p>Python now gets the absolute path of the script filename specified on
  414. the command line (ex: <code class="docutils literal notranslate"><span class="pre">python3</span> <span class="pre">script.py</span></code>): the <code class="docutils literal notranslate"><span class="pre">__file__</span></code> attribute of
  415. the <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> module became an absolute path, rather than a relative
  416. path. These paths now remain valid after the current directory is changed
  417. by <a class="reference internal" href="../library/os.html#os.chdir" title="os.chdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.chdir()</span></code></a>. As a side effect, the traceback also displays the
  418. absolute path for <a class="reference internal" href="../library/__main__.html#module-__main__" title="__main__: The environment where top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``."><code class="xref py py-mod docutils literal notranslate"><span class="pre">__main__</span></code></a> module frames in this case.
  419. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20443">bpo-20443</a>.)</p></li>
  420. <li><p>In the <a class="reference internal" href="../library/devmode.html#devmode"><span class="std std-ref">Python Development Mode</span></a> and in <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug build</span></a>, the
  421. <em>encoding</em> and <em>errors</em> arguments are now checked for string encoding and
  422. decoding operations. Examples: <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#str.encode" title="str.encode"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.encode()</span></code></a> and
  423. <a class="reference internal" href="../library/stdtypes.html#bytes.decode" title="bytes.decode"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytes.decode()</span></code></a>.</p>
  424. <p>By default, for best performance, the <em>errors</em> argument is only checked at
  425. the first encoding/decoding error and the <em>encoding</em> argument is sometimes
  426. ignored for empty strings.
  427. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37388">bpo-37388</a>.)</p>
  428. </li>
  429. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;&quot;.replace(&quot;&quot;,</span> <span class="pre">s,</span> <span class="pre">n)</span></code> now returns <code class="docutils literal notranslate"><span class="pre">s</span></code> instead of an empty string for
  430. all non-zero <code class="docutils literal notranslate"><span class="pre">n</span></code>. It is now consistent with <code class="docutils literal notranslate"><span class="pre">&quot;&quot;.replace(&quot;&quot;,</span> <span class="pre">s)</span></code>.
  431. There are similar changes for <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> objects.
  432. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28029">bpo-28029</a>.)</p></li>
  433. <li><p>Any valid expression can now be used as a <a class="reference internal" href="../glossary.html#term-decorator"><span class="xref std std-term">decorator</span></a>. Previously, the
  434. grammar was much more restrictive. See <span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0614/"><strong>PEP 614</strong></a> for details.
  435. (Contributed by Brandt Bucher in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39702">bpo-39702</a>.)</p></li>
  436. <li><p>Improved help for 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. Docstrings are now shown for
  437. all special forms and special generic aliases (like <code class="docutils literal notranslate"><span class="pre">Union</span></code> and <code class="docutils literal notranslate"><span class="pre">List</span></code>).
  438. Using <a class="reference internal" href="../library/functions.html#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a> with generic alias like <code class="docutils literal notranslate"><span class="pre">List[int]</span></code> will show the help
  439. for the correspondent concrete type (<code class="docutils literal notranslate"><span class="pre">list</span></code> in this case).
  440. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40257">bpo-40257</a>.)</p></li>
  441. <li><p>Parallel running of <a class="reference internal" href="../reference/expressions.html#agen.aclose" title="agen.aclose"><code class="xref py py-meth docutils literal notranslate"><span class="pre">aclose()</span></code></a> / <a class="reference internal" href="../reference/expressions.html#agen.asend" title="agen.asend"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asend()</span></code></a> /
  442. <a class="reference internal" href="../reference/expressions.html#agen.athrow" title="agen.athrow"><code class="xref py py-meth docutils literal notranslate"><span class="pre">athrow()</span></code></a> is now prohibited, and <code class="docutils literal notranslate"><span class="pre">ag_running</span></code> now reflects
  443. the actual running status of the async generator.
  444. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30773">bpo-30773</a>.)</p></li>
  445. <li><p>Unexpected errors in calling the <code class="docutils literal notranslate"><span class="pre">__iter__</span></code> method are no longer masked by
  446. <code class="docutils literal notranslate"><span class="pre">TypeError</span></code> in the <a class="reference internal" href="../reference/expressions.html#in"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">in</span></code></a> operator and functions
  447. <a class="reference internal" href="../library/operator.html#operator.contains" title="operator.contains"><code class="xref py py-func docutils literal notranslate"><span class="pre">contains()</span></code></a>, <a class="reference internal" href="../library/operator.html#operator.indexOf" title="operator.indexOf"><code class="xref py py-func docutils literal notranslate"><span class="pre">indexOf()</span></code></a> and
  448. <a class="reference internal" href="../library/operator.html#operator.countOf" title="operator.countOf"><code class="xref py py-func docutils literal notranslate"><span class="pre">countOf()</span></code></a> of the <a class="reference internal" href="../library/operator.html#module-operator" title="operator: Functions corresponding to the standard operators."><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code></a> module.
  449. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40824">bpo-40824</a>.)</p></li>
  450. <li><p>Unparenthesized lambda expressions can no longer be the expression part in an
  451. <code class="docutils literal notranslate"><span class="pre">if</span></code> clause in comprehensions and generator expressions. See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41848">bpo-41848</a>
  452. and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43755">bpo-43755</a> for details.</p></li>
  453. </ul>
  454. </section>
  455. <section id="new-modules">
  456. <h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading">¶</a></h2>
  457. <section id="zoneinfo">
  458. <h3>zoneinfo<a class="headerlink" href="#zoneinfo" title="Link to this heading">¶</a></h3>
  459. <p>The <a class="reference internal" href="../library/zoneinfo.html#module-zoneinfo" title="zoneinfo: IANA time zone support"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zoneinfo</span></code></a> module brings support for the IANA time zone database to
  460. the standard library. It adds <a class="reference internal" href="../library/zoneinfo.html#zoneinfo.ZoneInfo" title="zoneinfo.ZoneInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">zoneinfo.ZoneInfo</span></code></a>, a concrete
  461. <a class="reference internal" href="../library/datetime.html#datetime.tzinfo" title="datetime.tzinfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.tzinfo</span></code></a> implementation backed by the system’s time zone data.</p>
  462. <p>Example:</p>
  463. <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">zoneinfo</span> <span class="kn">import</span> <span class="n">ZoneInfo</span>
  464. <span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timedelta</span>
  465. <span class="gp">&gt;&gt;&gt; </span><span class="c1"># Daylight saving time</span>
  466. <span class="gp">&gt;&gt;&gt; </span><span class="n">dt</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2020</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">31</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="n">tzinfo</span><span class="o">=</span><span class="n">ZoneInfo</span><span class="p">(</span><span class="s2">&quot;America/Los_Angeles&quot;</span><span class="p">))</span>
  467. <span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span>
  468. <span class="go">2020-10-31 12:00:00-07:00</span>
  469. <span class="gp">&gt;&gt;&gt; </span><span class="n">dt</span><span class="o">.</span><span class="n">tzname</span><span class="p">()</span>
  470. <span class="go">&#39;PDT&#39;</span>
  471. <span class="gp">&gt;&gt;&gt; </span><span class="c1"># Standard time</span>
  472. <span class="gp">&gt;&gt;&gt; </span><span class="n">dt</span> <span class="o">+=</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">7</span><span class="p">)</span>
  473. <span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">dt</span><span class="p">)</span>
  474. <span class="go">2020-11-07 12:00:00-08:00</span>
  475. <span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">dt</span><span class="o">.</span><span class="n">tzname</span><span class="p">())</span>
  476. <span class="go">PST</span>
  477. </pre></div>
  478. </div>
  479. <p>As a fall-back source of data for platforms that don’t ship the IANA database,
  480. the <a class="reference external" href="https://pypi.org/project/tzdata/"><code class="docutils literal notranslate"><span class="pre">tzdata</span></code></a> module was released as a first-party package – distributed via
  481. PyPI and maintained by the CPython core team.</p>
  482. <div class="admonition seealso">
  483. <p class="admonition-title">See also</p>
  484. <dl class="simple">
  485. <dt><span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0615/"><strong>PEP 615</strong></a> – Support for the IANA Time Zone Database in the Standard Library</dt><dd><p>PEP written and implemented by Paul Ganssle</p>
  486. </dd>
  487. </dl>
  488. </div>
  489. </section>
  490. <section id="graphlib">
  491. <h3>graphlib<a class="headerlink" href="#graphlib" title="Link to this heading">¶</a></h3>
  492. <p>A new module, <a class="reference internal" href="../library/graphlib.html#module-graphlib" title="graphlib: Functionality to operate with graph-like structures"><code class="xref py py-mod docutils literal notranslate"><span class="pre">graphlib</span></code></a>, was added that contains the
  493. <a class="reference internal" href="../library/graphlib.html#graphlib.TopologicalSorter" title="graphlib.TopologicalSorter"><code class="xref py py-class docutils literal notranslate"><span class="pre">graphlib.TopologicalSorter</span></code></a> class to offer functionality to perform
  494. topological sorting of graphs. (Contributed by Pablo Galindo, Tim Peters and
  495. Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17005">bpo-17005</a>.)</p>
  496. </section>
  497. </section>
  498. <section id="improved-modules">
  499. <h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading">¶</a></h2>
  500. <section id="ast">
  501. <h3>ast<a class="headerlink" href="#ast" title="Link to this heading">¶</a></h3>
  502. <p>Added the <em>indent</em> option to <a class="reference internal" href="../library/ast.html#ast.dump" title="ast.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump()</span></code></a> which allows it to produce a
  503. multiline indented output.
  504. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37995">bpo-37995</a>.)</p>
  505. <p>Added <a class="reference internal" href="../library/ast.html#ast.unparse" title="ast.unparse"><code class="xref py py-func docutils literal notranslate"><span class="pre">ast.unparse()</span></code></a> as a function in the <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> module that can
  506. be used to unparse an <a class="reference internal" href="../library/ast.html#ast.AST" title="ast.AST"><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.AST</span></code></a> object and produce a string with code
  507. that would produce an equivalent <a class="reference internal" href="../library/ast.html#ast.AST" title="ast.AST"><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.AST</span></code></a> object when parsed.
  508. (Contributed by Pablo Galindo and Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38870">bpo-38870</a>.)</p>
  509. <p>Added docstrings to AST nodes that contains the ASDL signature used to
  510. construct that node. (Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39638">bpo-39638</a>.)</p>
  511. </section>
  512. <section id="asyncio">
  513. <h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading">¶</a></h3>
  514. <p>Due to significant security concerns, the <em>reuse_address</em> parameter of
  515. <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
  516. because of the behavior of the socket option <code class="docutils literal notranslate"><span class="pre">SO_REUSEADDR</span></code> in UDP. For more
  517. details, see the documentation for <code class="docutils literal notranslate"><span class="pre">loop.create_datagram_endpoint()</span></code>.
  518. (Contributed by Kyle Stanley, Antoine Pitrou, and Yury Selivanov in
  519. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37228">bpo-37228</a>.)</p>
  520. <p>Added a new <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.shutdown_default_executor" title="asyncio.loop.shutdown_default_executor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">shutdown_default_executor()</span></code></a>
  521. that schedules a shutdown for the default executor that waits on the
  522. <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ThreadPoolExecutor</span></code></a> to finish closing. Also,
  523. <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 been updated to use the new <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a>.
  524. (Contributed by Kyle Stanley in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34037">bpo-34037</a>.)</p>
  525. <p>Added <a class="reference internal" href="../library/asyncio-policy.html#asyncio.PidfdChildWatcher" title="asyncio.PidfdChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.PidfdChildWatcher</span></code></a>, a Linux-specific child watcher
  526. implementation that polls process file descriptors. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38692">bpo-38692</a>)</p>
  527. <p>Added a new <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> <a class="reference internal" href="../library/asyncio-task.html#asyncio.to_thread" title="asyncio.to_thread"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.to_thread()</span></code></a>. It is mainly used for
  528. running IO-bound functions in a separate thread to avoid blocking the event
  529. loop, and essentially works as a high-level version of
  530. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.run_in_executor" title="asyncio.loop.run_in_executor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">run_in_executor()</span></code></a> that can directly take keyword arguments.
  531. (Contributed by Kyle Stanley and Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32309">bpo-32309</a>.)</p>
  532. <p>When cancelling the task due to a timeout, <a class="reference internal" href="../library/asyncio-task.html#asyncio.wait_for" title="asyncio.wait_for"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.wait_for()</span></code></a> will now
  533. wait until the cancellation is complete also in the case when <em>timeout</em> is
  534. &lt;= 0, like it does with positive timeouts.
  535. (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>
  536. <p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> now raises <code class="xref py py-exc docutils literal notranslate"><span class="pre">TyperError</span></code> when calling incompatible
  537. methods with an <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket" title="ssl.SSLSocket"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLSocket</span></code></a> socket.
  538. (Contributed by Ido Michael in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37404">bpo-37404</a>.)</p>
  539. </section>
  540. <section id="compileall">
  541. <h3>compileall<a class="headerlink" href="#compileall" title="Link to this heading">¶</a></h3>
  542. <p>Added new possibility to use hardlinks for duplicated <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files: <em>hardlink_dupes</em> parameter and –hardlink-dupes command line option.
  543. (Contributed by Lumír ‘Frenzy’ Balhar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40495">bpo-40495</a>.)</p>
  544. <p>Added new options for path manipulation in resulting <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files: <em>stripdir</em>, <em>prependdir</em>, <em>limit_sl_dest</em> parameters and -s, -p, -e command line options.
  545. Added the possibility to specify the option for an optimization level multiple times.
  546. (Contributed by Lumír ‘Frenzy’ Balhar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38112">bpo-38112</a>.)</p>
  547. </section>
  548. <section id="concurrent-futures">
  549. <h3>concurrent.futures<a class="headerlink" href="#concurrent-futures" title="Link to this heading">¶</a></h3>
  550. <p>Added a new <em>cancel_futures</em> parameter to
  551. <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.Executor.shutdown" title="concurrent.futures.Executor.shutdown"><code class="xref py py-meth docutils literal notranslate"><span class="pre">concurrent.futures.Executor.shutdown()</span></code></a> that cancels all pending futures
  552. which have not started running, instead of waiting for them to complete before
  553. shutting down the executor.
  554. (Contributed by Kyle Stanley in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39349">bpo-39349</a>.)</p>
  555. <p>Removed daemon threads from <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ThreadPoolExecutor</span></code></a>
  556. and <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor" title="concurrent.futures.ProcessPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProcessPoolExecutor</span></code></a>. This improves
  557. compatibility with subinterpreters and predictability in their shutdown
  558. processes. (Contributed by Kyle Stanley in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39812">bpo-39812</a>.)</p>
  559. <p>Workers in <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ProcessPoolExecutor" title="concurrent.futures.ProcessPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProcessPoolExecutor</span></code></a> are now spawned on
  560. demand, only when there are no available idle workers to reuse. This optimizes
  561. startup overhead and reduces the amount of lost CPU time to idle workers.
  562. (Contributed by Kyle Stanley in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39207">bpo-39207</a>.)</p>
  563. </section>
  564. <section id="curses">
  565. <h3>curses<a class="headerlink" href="#curses" title="Link to this heading">¶</a></h3>
  566. <p>Added <a class="reference internal" href="../library/curses.html#curses.get_escdelay" title="curses.get_escdelay"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.get_escdelay()</span></code></a>, <a class="reference internal" href="../library/curses.html#curses.set_escdelay" title="curses.set_escdelay"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.set_escdelay()</span></code></a>,
  567. <a class="reference internal" href="../library/curses.html#curses.get_tabsize" title="curses.get_tabsize"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.get_tabsize()</span></code></a>, and <a class="reference internal" href="../library/curses.html#curses.set_tabsize" title="curses.set_tabsize"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.set_tabsize()</span></code></a> functions.
  568. (Contributed by Anthony Sottile in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38312">bpo-38312</a>.)</p>
  569. </section>
  570. <section id="datetime">
  571. <h3>datetime<a class="headerlink" href="#datetime" title="Link to this heading">¶</a></h3>
  572. <p>The <a class="reference internal" href="../library/datetime.html#datetime.date.isocalendar" title="datetime.date.isocalendar"><code class="xref py py-meth docutils literal notranslate"><span class="pre">isocalendar()</span></code></a> 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>
  573. and <a class="reference internal" href="../library/datetime.html#datetime.datetime.isocalendar" title="datetime.datetime.isocalendar"><code class="xref py py-meth docutils literal notranslate"><span class="pre">isocalendar()</span></code></a> of <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>
  574. methods now returns a <a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a> instead of a <a class="reference internal" href="../library/stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a>.
  575. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24416">bpo-24416</a>.)</p>
  576. </section>
  577. <section id="distutils">
  578. <h3>distutils<a class="headerlink" href="#distutils" title="Link to this heading">¶</a></h3>
  579. <p>The <strong class="command">upload</strong> command now creates SHA2-256 and Blake2b-256 hash
  580. digests. It skips MD5 on platforms that block MD5 digest.
  581. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40698">bpo-40698</a>.)</p>
  582. </section>
  583. <section id="fcntl">
  584. <h3>fcntl<a class="headerlink" href="#fcntl" title="Link to this heading">¶</a></h3>
  585. <p>Added constants <code class="xref py py-const docutils literal notranslate"><span class="pre">F_OFD_GETLK</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">F_OFD_SETLK</span></code>
  586. and <code class="xref py py-const docutils literal notranslate"><span class="pre">F_OFD_SETLKW</span></code>.
  587. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38602">bpo-38602</a>.)</p>
  588. </section>
  589. <section id="ftplib">
  590. <h3>ftplib<a class="headerlink" href="#ftplib" title="Link to this heading">¶</a></h3>
  591. <p><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">FTP</span></code></a> and <a class="reference internal" href="../library/ftplib.html#ftplib.FTP_TLS" title="ftplib.FTP_TLS"><code class="xref py py-class docutils literal notranslate"><span class="pre">FTP_TLS</span></code></a> now raise a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a>
  592. if the given timeout for their constructor is zero to prevent the creation of
  593. a non-blocking socket. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39259">bpo-39259</a>.)</p>
  594. </section>
  595. <section id="gc">
  596. <h3>gc<a class="headerlink" href="#gc" title="Link to this heading">¶</a></h3>
  597. <p>When the garbage collector makes a collection in which some objects resurrect
  598. (they are reachable from outside the isolated cycles after the finalizers have
  599. been executed), do not block the collection of all objects that are still
  600. unreachable. (Contributed by Pablo Galindo and Tim Peters in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38379">bpo-38379</a>.)</p>
  601. <p>Added a new function <a class="reference internal" href="../library/gc.html#gc.is_finalized" title="gc.is_finalized"><code class="xref py py-func docutils literal notranslate"><span class="pre">gc.is_finalized()</span></code></a> to check if an object has been
  602. finalized by the garbage collector. (Contributed by Pablo Galindo in
  603. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39322">bpo-39322</a>.)</p>
  604. </section>
  605. <section id="hashlib">
  606. <h3>hashlib<a class="headerlink" href="#hashlib" title="Link to this heading">¶</a></h3>
  607. <p>The <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> module can now use SHA3 hashes and SHAKE XOF from OpenSSL
  608. when available.
  609. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37630">bpo-37630</a>.)</p>
  610. <p>Builtin hash modules can now be disabled with
  611. <code class="docutils literal notranslate"><span class="pre">./configure</span> <span class="pre">--without-builtin-hashlib-hashes</span></code> or selectively enabled with
  612. e.g. <code class="docutils literal notranslate"><span class="pre">./configure</span> <span class="pre">--with-builtin-hashlib-hashes=sha3,blake2</span></code> to force use
  613. of OpenSSL based implementation.
  614. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40479">bpo-40479</a>)</p>
  615. </section>
  616. <section id="http">
  617. <h3>http<a class="headerlink" href="#http" title="Link to this heading">¶</a></h3>
  618. <p>HTTP status codes <code class="docutils literal notranslate"><span class="pre">103</span> <span class="pre">EARLY_HINTS</span></code>, <code class="docutils literal notranslate"><span class="pre">418</span> <span class="pre">IM_A_TEAPOT</span></code> and <code class="docutils literal notranslate"><span class="pre">425</span> <span class="pre">TOO_EARLY</span></code> are added to
  619. <a class="reference internal" href="../library/http.html#http.HTTPStatus" title="http.HTTPStatus"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.HTTPStatus</span></code></a>. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39509">bpo-39509</a> and Ross Rhodes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39507">bpo-39507</a>.)</p>
  620. </section>
  621. <section id="idle-and-idlelib">
  622. <h3>IDLE and idlelib<a class="headerlink" href="#idle-and-idlelib" title="Link to this heading">¶</a></h3>
  623. <p>Added option to toggle cursor blink off. (Contributed by Zackery Spytz
  624. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4603">bpo-4603</a>.)</p>
  625. <p>Escape key now closes IDLE completion windows. (Contributed by Johnny
  626. Najera in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38944">bpo-38944</a>.)</p>
  627. <p>Added keywords to module name completion list. (Contributed by Terry J.
  628. Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37765">bpo-37765</a>.)</p>
  629. <p>New in 3.9 maintenance releases</p>
  630. <p>Make IDLE invoke <a class="reference internal" href="../library/sys.html#sys.excepthook" title="sys.excepthook"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.excepthook()</span></code></a> (when started without ‘-n’).
  631. User hooks were previously ignored. (Contributed by Ken Hilton in
  632. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43008">bpo-43008</a>.)</p>
  633. <p>The changes above have been backported to 3.8 maintenance releases.</p>
  634. <p>Rearrange the settings dialog. Split the General tab into Windows
  635. and Shell/Ed tabs. Move help sources, which extend the Help menu, to the
  636. Extensions tab. Make space for new options and shorten the dialog. The
  637. latter makes the dialog better fit small screens. (Contributed by Terry Jan
  638. Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40468">bpo-40468</a>.) Move the indent space setting from the Font tab to
  639. the new Windows tab. (Contributed by Mark Roseman and Terry Jan Reedy in
  640. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33962">bpo-33962</a>.)</p>
  641. <p>Apply syntax highlighting to <code class="docutils literal notranslate"><span class="pre">.pyi</span></code> files. (Contributed by Alex
  642. Waygood and Terry Jan Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45447">bpo-45447</a>.)</p>
  643. </section>
  644. <section id="imaplib">
  645. <h3>imaplib<a class="headerlink" href="#imaplib" title="Link to this heading">¶</a></h3>
  646. <p><a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4</span></code></a> and <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4_SSL" title="imaplib.IMAP4_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4_SSL</span></code></a> now have
  647. an optional <em>timeout</em> parameter for their constructors.
  648. Also, the <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4.open" title="imaplib.IMAP4.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">open()</span></code></a> method now has an optional <em>timeout</em> parameter
  649. with this change. The overridden methods of <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4_SSL" title="imaplib.IMAP4_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4_SSL</span></code></a> and
  650. <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4_stream" title="imaplib.IMAP4_stream"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4_stream</span></code></a> were applied to this change.
  651. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38615">bpo-38615</a>.)</p>
  652. <p><a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4.unselect" title="imaplib.IMAP4.unselect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">imaplib.IMAP4.unselect()</span></code></a> is added.
  653. <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4.unselect" title="imaplib.IMAP4.unselect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">imaplib.IMAP4.unselect()</span></code></a> frees server’s resources associated with the
  654. selected mailbox and returns the server to the authenticated
  655. state. This command performs the same actions as <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4.close" title="imaplib.IMAP4.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">imaplib.IMAP4.close()</span></code></a>, except
  656. that no messages are permanently removed from the currently
  657. selected mailbox. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40375">bpo-40375</a>.)</p>
  658. </section>
  659. <section id="importlib">
  660. <h3>importlib<a class="headerlink" href="#importlib" title="Link to this heading">¶</a></h3>
  661. <p>To improve consistency with import statements, <a class="reference internal" href="../library/importlib.html#importlib.util.resolve_name" title="importlib.util.resolve_name"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.resolve_name()</span></code></a>
  662. now raises <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> instead of <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> for invalid relative
  663. import attempts.
  664. (Contributed by Ngalim Siregar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37444">bpo-37444</a>.)</p>
  665. <p>Import loaders which publish immutable module objects can now publish
  666. immutable packages in addition to individual modules.
  667. (Contributed by Dino Viehland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39336">bpo-39336</a>.)</p>
  668. <p>Added <a class="reference internal" href="../library/importlib.resources.html#importlib.resources.files" title="importlib.resources.files"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.files()</span></code></a> function with support for
  669. subdirectories in package data, matching backport in <code class="docutils literal notranslate"><span class="pre">importlib_resources</span></code>
  670. version 1.5.
  671. (Contributed by Jason R. Coombs in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39791">bpo-39791</a>.)</p>
  672. <p>Refreshed <code class="docutils literal notranslate"><span class="pre">importlib.metadata</span></code> from <code class="docutils literal notranslate"><span class="pre">importlib_metadata</span></code> version 1.6.1.</p>
  673. </section>
  674. <section id="inspect">
  675. <h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading">¶</a></h3>
  676. <p><a class="reference internal" href="../library/inspect.html#inspect.BoundArguments.arguments" title="inspect.BoundArguments.arguments"><code class="xref py py-attr docutils literal notranslate"><span class="pre">inspect.BoundArguments.arguments</span></code></a> is changed from <code class="docutils literal notranslate"><span class="pre">OrderedDict</span></code> to regular
  677. dict. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36350">bpo-36350</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39775">bpo-39775</a>.)</p>
  678. </section>
  679. <section id="ipaddress">
  680. <h3>ipaddress<a class="headerlink" href="#ipaddress" title="Link to this heading">¶</a></h3>
  681. <p><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> now supports IPv6 Scoped Addresses (IPv6 address with suffix <code class="docutils literal notranslate"><span class="pre">%&lt;scope_id&gt;</span></code>).</p>
  682. <p>Scoped IPv6 addresses can be parsed using <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Address" title="ipaddress.IPv6Address"><code class="xref py py-class docutils literal notranslate"><span class="pre">ipaddress.IPv6Address</span></code></a>.
  683. If present, scope zone ID is available through the <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv6Address.scope_id" title="ipaddress.IPv6Address.scope_id"><code class="xref py py-attr docutils literal notranslate"><span class="pre">scope_id</span></code></a> attribute.
  684. (Contributed by Oleksandr Pavliuk in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34788">bpo-34788</a>.)</p>
  685. <p>Starting with Python 3.9.5 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
  686. accepts any leading zeros in IPv4 address strings.
  687. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36384">bpo-36384</a>).</p>
  688. </section>
  689. <section id="math">
  690. <h3>math<a class="headerlink" href="#math" title="Link to this heading">¶</a></h3>
  691. <p>Expanded the <a class="reference internal" href="../library/math.html#math.gcd" title="math.gcd"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.gcd()</span></code></a> function to handle multiple arguments.
  692. Formerly, it only supported two arguments.
  693. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39648">bpo-39648</a>.)</p>
  694. <p>Added <a class="reference internal" href="../library/math.html#math.lcm" title="math.lcm"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.lcm()</span></code></a>: return the least common multiple of specified arguments.
  695. (Contributed by Mark Dickinson, Ananthakrishnan and Serhiy Storchaka in
  696. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39479">bpo-39479</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39648">bpo-39648</a>.)</p>
  697. <p>Added <a class="reference internal" href="../library/math.html#math.nextafter" title="math.nextafter"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.nextafter()</span></code></a>: return the next floating-point value after <em>x</em>
  698. towards <em>y</em>.
  699. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39288">bpo-39288</a>.)</p>
  700. <p>Added <a class="reference internal" href="../library/math.html#math.ulp" title="math.ulp"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.ulp()</span></code></a>: return the value of the least significant bit
  701. of a float.
  702. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39310">bpo-39310</a>.)</p>
  703. </section>
  704. <section id="multiprocessing">
  705. <h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Link to this heading">¶</a></h3>
  706. <p>The <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.SimpleQueue" title="multiprocessing.SimpleQueue"><code class="xref py py-class docutils literal notranslate"><span class="pre">multiprocessing.SimpleQueue</span></code></a> class has a new
  707. <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.SimpleQueue.close" title="multiprocessing.SimpleQueue.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> method to explicitly close the
  708. queue.
  709. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30966">bpo-30966</a>.)</p>
  710. </section>
  711. <section id="nntplib">
  712. <h3>nntplib<a class="headerlink" href="#nntplib" title="Link to this heading">¶</a></h3>
  713. <p><a class="reference internal" href="../library/nntplib.html#nntplib.NNTP" title="nntplib.NNTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">NNTP</span></code></a> and <a class="reference internal" href="../library/nntplib.html#nntplib.NNTP_SSL" title="nntplib.NNTP_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">NNTP_SSL</span></code></a> now raise a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a>
  714. if the given timeout for their constructor is zero to prevent the creation of
  715. a non-blocking socket. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39259">bpo-39259</a>.)</p>
  716. </section>
  717. <section id="os">
  718. <h3>os<a class="headerlink" href="#os" title="Link to this heading">¶</a></h3>
  719. <p>Added <a class="reference internal" href="../library/os.html#os.CLD_KILLED" title="os.CLD_KILLED"><code class="xref py py-const docutils literal notranslate"><span class="pre">CLD_KILLED</span></code></a> and <a class="reference internal" href="../library/os.html#os.CLD_STOPPED" title="os.CLD_STOPPED"><code class="xref py py-const docutils literal notranslate"><span class="pre">CLD_STOPPED</span></code></a> for <code class="xref py py-attr docutils literal notranslate"><span class="pre">si_code</span></code>.
  720. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38493">bpo-38493</a>.)</p>
  721. <p>Exposed the Linux-specific <a class="reference internal" href="../library/os.html#os.pidfd_open" title="os.pidfd_open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pidfd_open()</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38692">bpo-38692</a>) and
  722. <a class="reference internal" href="../library/os.html#os.P_PIDFD" title="os.P_PIDFD"><code class="xref py py-const docutils literal notranslate"><span class="pre">os.P_PIDFD</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38713">bpo-38713</a>) for process management with file
  723. descriptors.</p>
  724. <p>The <a class="reference internal" href="../library/os.html#os.unsetenv" title="os.unsetenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.unsetenv()</span></code></a> function is now also available on Windows.
  725. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39413">bpo-39413</a>.)</p>
  726. <p>The <a class="reference internal" href="../library/os.html#os.putenv" title="os.putenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.putenv()</span></code></a> and <a class="reference internal" href="../library/os.html#os.unsetenv" title="os.unsetenv"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.unsetenv()</span></code></a> functions are now always
  727. available.
  728. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39395">bpo-39395</a>.)</p>
  729. <p>Added <a class="reference internal" href="../library/os.html#os.waitstatus_to_exitcode" title="os.waitstatus_to_exitcode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.waitstatus_to_exitcode()</span></code></a> function:
  730. convert a wait status to an exit code.
  731. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40094">bpo-40094</a>.)</p>
  732. </section>
  733. <section id="pathlib">
  734. <h3>pathlib<a class="headerlink" href="#pathlib" title="Link to this heading">¶</a></h3>
  735. <p>Added <a class="reference internal" href="../library/pathlib.html#pathlib.Path.readlink" title="pathlib.Path.readlink"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.readlink()</span></code></a> which acts similarly to
  736. <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>.
  737. (Contributed by Girts Folkmanis in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30618">bpo-30618</a>)</p>
  738. </section>
  739. <section id="pdb">
  740. <h3>pdb<a class="headerlink" href="#pdb" title="Link to this heading">¶</a></h3>
  741. <p>On Windows now <a class="reference internal" href="../library/pdb.html#pdb.Pdb" title="pdb.Pdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pdb</span></code></a> supports <code class="docutils literal notranslate"><span class="pre">~/.pdbrc</span></code>.
  742. (Contributed by Tim Hopper and Dan Lidral-Porter in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20523">bpo-20523</a>.)</p>
  743. </section>
  744. <section id="poplib">
  745. <h3>poplib<a class="headerlink" href="#poplib" title="Link to this heading">¶</a></h3>
  746. <p><a class="reference internal" href="../library/poplib.html#poplib.POP3" title="poplib.POP3"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3</span></code></a> and <a class="reference internal" href="../library/poplib.html#poplib.POP3_SSL" title="poplib.POP3_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">POP3_SSL</span></code></a> now raise a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a>
  747. if the given timeout for their constructor is zero to prevent the creation of
  748. a non-blocking socket. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39259">bpo-39259</a>.)</p>
  749. </section>
  750. <section id="pprint">
  751. <h3>pprint<a class="headerlink" href="#pprint" title="Link to this heading">¶</a></h3>
  752. <p><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> can now pretty-print <a class="reference internal" href="../library/types.html#types.SimpleNamespace" title="types.SimpleNamespace"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.SimpleNamespace</span></code></a>.
  753. (Contributed by Carl Bordum Hansen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37376">bpo-37376</a>.)</p>
  754. </section>
  755. <section id="pydoc">
  756. <h3>pydoc<a class="headerlink" href="#pydoc" title="Link to this heading">¶</a></h3>
  757. <p>The documentation string is now shown not only for class, function,
  758. method etc, but for any object that has its own <code class="docutils literal notranslate"><span class="pre">__doc__</span></code> attribute.
  759. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40257">bpo-40257</a>.)</p>
  760. </section>
  761. <section id="random">
  762. <h3>random<a class="headerlink" href="#random" title="Link to this heading">¶</a></h3>
  763. <p>Added a new <code class="xref py py-attr docutils literal notranslate"><span class="pre">random.Random.randbytes</span></code> method: generate random bytes.
  764. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40286">bpo-40286</a>.)</p>
  765. </section>
  766. <section id="signal">
  767. <h3>signal<a class="headerlink" href="#signal" title="Link to this heading">¶</a></h3>
  768. <p>Exposed the Linux-specific <a class="reference internal" href="../library/signal.html#signal.pidfd_send_signal" title="signal.pidfd_send_signal"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.pidfd_send_signal()</span></code></a> for sending to
  769. signals to a process using a file descriptor instead of a pid. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38712">bpo-38712</a>)</p>
  770. </section>
  771. <section id="smtplib">
  772. <h3>smtplib<a class="headerlink" href="#smtplib" title="Link to this heading">¶</a></h3>
  773. <p><a class="reference internal" href="../library/smtplib.html#smtplib.SMTP" title="smtplib.SMTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTP</span></code></a> and <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP_SSL" title="smtplib.SMTP_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTP_SSL</span></code></a> now raise a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a>
  774. if the given timeout for their constructor is zero to prevent the creation of
  775. a non-blocking socket. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39259">bpo-39259</a>.)</p>
  776. <p><a class="reference internal" href="../library/smtplib.html#smtplib.LMTP" title="smtplib.LMTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">LMTP</span></code></a> constructor now has an optional <em>timeout</em> parameter.
  777. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39329">bpo-39329</a>.)</p>
  778. </section>
  779. <section id="socket">
  780. <h3>socket<a class="headerlink" href="#socket" title="Link to this heading">¶</a></h3>
  781. <p>The <a class="reference internal" href="../library/socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socket</span></code></a> module now exports the <a class="reference internal" href="../library/socket.html#socket.CAN_RAW_JOIN_FILTERS" title="socket.CAN_RAW_JOIN_FILTERS"><code class="xref py py-const docutils literal notranslate"><span class="pre">CAN_RAW_JOIN_FILTERS</span></code></a>
  782. constant on Linux 4.1 and greater.
  783. (Contributed by Stefan Tatschner and Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25780">bpo-25780</a>.)</p>
  784. <p>The socket module now supports the <a class="reference internal" href="../library/socket.html#socket.CAN_J1939" title="socket.CAN_J1939"><code class="xref py py-const docutils literal notranslate"><span class="pre">CAN_J1939</span></code></a> protocol on
  785. platforms that support it. (Contributed by Karl Ding in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40291">bpo-40291</a>.)</p>
  786. <p>The socket module now has the <a class="reference internal" href="../library/socket.html#socket.send_fds" title="socket.send_fds"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.send_fds()</span></code></a> and
  787. <a class="reference internal" href="../library/socket.html#socket.recv_fds" title="socket.recv_fds"><code class="xref py py-func docutils literal notranslate"><span class="pre">socket.recv_fds()</span></code></a> functions. (Contributed by Joannah Nanjekye, Shinya
  788. Okano and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28724">bpo-28724</a>.)</p>
  789. </section>
  790. <section id="time">
  791. <h3>time<a class="headerlink" href="#time" title="Link to this heading">¶</a></h3>
  792. <p>On AIX, <a class="reference internal" href="../library/time.html#time.thread_time" title="time.thread_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">thread_time()</span></code></a> is now implemented with <code class="docutils literal notranslate"><span class="pre">thread_cputime()</span></code>
  793. which has nanosecond resolution, rather than
  794. <code class="docutils literal notranslate"><span class="pre">clock_gettime(CLOCK_THREAD_CPUTIME_ID)</span></code> which has a resolution of 10 milliseconds.
  795. (Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40192">bpo-40192</a>)</p>
  796. </section>
  797. <section id="sys">
  798. <h3>sys<a class="headerlink" href="#sys" title="Link to this heading">¶</a></h3>
  799. <p>Added a new <a class="reference internal" href="../library/sys.html#sys.platlibdir" title="sys.platlibdir"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platlibdir</span></code></a> attribute: name of the platform-specific
  800. library directory. It is used to build the path of standard library and the
  801. paths of installed extension modules. It is equal to <code class="docutils literal notranslate"><span class="pre">&quot;lib&quot;</span></code> on most
  802. platforms. On Fedora and SuSE, it is equal to <code class="docutils literal notranslate"><span class="pre">&quot;lib64&quot;</span></code> on 64-bit platforms.
  803. (Contributed by Jan Matějek, Matěj Cepl, Charalampos Stratakis and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1294959">bpo-1294959</a>.)</p>
  804. <p>Previously, <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> was block-buffered when non-interactive. Now
  805. <code class="docutils literal notranslate"><span class="pre">stderr</span></code> defaults to always being line-buffered.
  806. (Contributed by Jendrik Seipp in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13601">bpo-13601</a>.)</p>
  807. </section>
  808. <section id="tracemalloc">
  809. <h3>tracemalloc<a class="headerlink" href="#tracemalloc" title="Link to this heading">¶</a></h3>
  810. <p>Added <a class="reference internal" href="../library/tracemalloc.html#tracemalloc.reset_peak" title="tracemalloc.reset_peak"><code class="xref py py-func docutils literal notranslate"><span class="pre">tracemalloc.reset_peak()</span></code></a> to set the peak size of traced memory
  811. blocks to the current size, to measure the peak of specific pieces of code.
  812. (Contributed by Huon Wilson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40630">bpo-40630</a>.)</p>
  813. </section>
  814. <section id="typing">
  815. <h3>typing<a class="headerlink" href="#typing" title="Link to this heading">¶</a></h3>
  816. <p><span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0593/"><strong>PEP 593</strong></a> introduced an <a class="reference internal" href="../library/typing.html#typing.Annotated" title="typing.Annotated"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.Annotated</span></code></a> type to decorate existing
  817. types with context-specific metadata and new <code class="docutils literal notranslate"><span class="pre">include_extras</span></code> parameter to
  818. <a class="reference internal" href="../library/typing.html#typing.get_type_hints" title="typing.get_type_hints"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_type_hints()</span></code></a> to access the metadata at runtime. (Contributed
  819. by Till Varoquaux and Konstantin Kashin.)</p>
  820. </section>
  821. <section id="unicodedata">
  822. <h3>unicodedata<a class="headerlink" href="#unicodedata" title="Link to this heading">¶</a></h3>
  823. <p>The Unicode database has been updated to version 13.0.0. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39926">bpo-39926</a>).</p>
  824. </section>
  825. <section id="venv">
  826. <h3>venv<a class="headerlink" href="#venv" title="Link to this heading">¶</a></h3>
  827. <p>The activation scripts provided by <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 all specify their prompt
  828. customization consistently by always using the value specified by
  829. <code class="docutils literal notranslate"><span class="pre">__VENV_PROMPT__</span></code>. Previously some scripts unconditionally used
  830. <code class="docutils literal notranslate"><span class="pre">__VENV_PROMPT__</span></code>, others only if it happened to be set (which was the default
  831. case), and one used <code class="docutils literal notranslate"><span class="pre">__VENV_NAME__</span></code> instead.
  832. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37663">bpo-37663</a>.)</p>
  833. </section>
  834. <section id="xml">
  835. <h3>xml<a class="headerlink" href="#xml" title="Link to this heading">¶</a></h3>
  836. <p>White space characters within attributes are now preserved when serializing
  837. <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> to XML file. EOLNs are no longer normalized
  838. to “n”. This is the result of discussion about how to interpret
  839. section 2.11 of XML spec.
  840. (Contributed by Mefistotelis in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39011">bpo-39011</a>.)</p>
  841. </section>
  842. </section>
  843. <section id="optimizations">
  844. <h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading">¶</a></h2>
  845. <ul>
  846. <li><p>Optimized the idiom for assignment a temporary variable in comprehensions.
  847. Now <code class="docutils literal notranslate"><span class="pre">for</span> <span class="pre">y</span> <span class="pre">in</span> <span class="pre">[expr]</span></code> in comprehensions is as fast as a simple assignment
  848. <code class="docutils literal notranslate"><span class="pre">y</span> <span class="pre">=</span> <span class="pre">expr</span></code>. For example:</p>
  849. <blockquote>
  850. <div><p>sums = [s for s in [0] for x in data for s in [s + x]]</p>
  851. </div></blockquote>
  852. <p>Unlike the <code class="docutils literal notranslate"><span class="pre">:=</span></code> operator this idiom does not leak a variable to the
  853. outer scope.</p>
  854. <p>(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=32856">bpo-32856</a>.)</p>
  855. </li>
  856. <li><p>Optimized signal handling in multithreaded applications. If a thread different
  857. than the main thread gets a signal, the bytecode evaluation loop is no longer
  858. interrupted at each bytecode instruction to check for pending signals which
  859. cannot be handled. Only the main thread of the main interpreter can handle
  860. signals.</p>
  861. <p>Previously, the bytecode evaluation loop was interrupted at each instruction
  862. until the main thread handles signals.
  863. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40010">bpo-40010</a>.)</p>
  864. </li>
  865. <li><p>Optimized 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 on FreeBSD using <code class="docutils literal notranslate"><span class="pre">closefrom()</span></code>.
  866. (Contributed by Ed Maste, Conrad Meyer, Kyle Evans, Kubilay Kocak and Victor
  867. Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38061">bpo-38061</a>.)</p></li>
  868. <li><p><a class="reference internal" href="../c-api/long.html#c.PyLong_FromDouble" title="PyLong_FromDouble"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyLong_FromDouble()</span></code></a> is now up to 1.87x faster for values that
  869. fit into <span class="c-expr sig sig-inline c"><span class="kt">long</span></span>.
  870. (Contributed by Sergey Fedoseev in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37986">bpo-37986</a>.)</p></li>
  871. <li><p>A number of Python builtins (<a class="reference internal" href="../library/stdtypes.html#range" title="range"><code class="xref py py-class docutils literal notranslate"><span class="pre">range</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>,
  872. <a class="reference internal" href="../library/stdtypes.html#frozenset" title="frozenset"><code class="xref py py-class docutils literal notranslate"><span class="pre">frozenset</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>, <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>) are now sped up by using
  873. <span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0590/"><strong>PEP 590</strong></a> vectorcall protocol.
  874. (Contributed by Donghee Na, Mark Shannon, Jeroen Demeyer and Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37207">bpo-37207</a>.)</p></li>
  875. <li><p>Optimized <code class="xref py py-func docutils literal notranslate"><span class="pre">difference_update()</span></code> for the case when the other set
  876. is much larger than the base set.
  877. (Suggested by Evgeny Kapun with code contributed by Michele Orrù in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8425">bpo-8425</a>.)</p></li>
  878. <li><p>Python’s small object allocator (<code class="docutils literal notranslate"><span class="pre">obmalloc.c</span></code>) now allows (no more than)
  879. one empty arena to remain available for immediate reuse, without returning
  880. it to the OS. This prevents thrashing in simple loops where an arena could
  881. be created and destroyed anew on each iteration.
  882. (Contributed by Tim Peters in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37257">bpo-37257</a>.)</p></li>
  883. <li><p><a class="reference internal" href="../glossary.html#term-floor-division"><span class="xref std std-term">floor division</span></a> of float operation now has a better performance. Also
  884. the message of <a class="reference internal" href="../library/exceptions.html#ZeroDivisionError" title="ZeroDivisionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ZeroDivisionError</span></code></a> for this operation is updated.
  885. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39434">bpo-39434</a>.)</p></li>
  886. <li><p>Decoding short ASCII strings with UTF-8 and ascii codecs is now about
  887. 15% faster. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37348">bpo-37348</a>.)</p></li>
  888. </ul>
  889. <p>Here’s a summary of performance improvements from Python 3.4 through Python 3.9:</p>
  890. <div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Python version 3.4 3.5 3.6 3.7 3.8 3.9
  891. -------------- --- --- --- --- --- ---
  892. Variable and attribute read access:
  893. read_local 7.1 7.1 5.4 5.1 3.9 3.9
  894. read_nonlocal 7.1 8.1 5.8 5.4 4.4 4.5
  895. read_global 15.5 19.0 14.3 13.6 7.6 7.8
  896. read_builtin 21.1 21.6 18.5 19.0 7.5 7.8
  897. read_classvar_from_class 25.6 26.5 20.7 19.5 18.4 17.9
  898. read_classvar_from_instance 22.8 23.5 18.8 17.1 16.4 16.9
  899. read_instancevar 32.4 33.1 28.0 26.3 25.4 25.3
  900. read_instancevar_slots 27.8 31.3 20.8 20.8 20.2 20.5
  901. read_namedtuple 73.8 57.5 45.0 46.8 18.4 18.7
  902. read_boundmethod 37.6 37.9 29.6 26.9 27.7 41.1
  903. Variable and attribute write access:
  904. write_local 8.7 9.3 5.5 5.3 4.3 4.3
  905. write_nonlocal 10.5 11.1 5.6 5.5 4.7 4.8
  906. write_global 19.7 21.2 18.0 18.0 15.8 16.7
  907. write_classvar 92.9 96.0 104.6 102.1 39.2 39.8
  908. write_instancevar 44.6 45.8 40.0 38.9 35.5 37.4
  909. write_instancevar_slots 35.6 36.1 27.3 26.6 25.7 25.8
  910. Data structure read access:
  911. read_list 24.2 24.5 20.8 20.8 19.0 19.5
  912. read_deque 24.7 25.5 20.2 20.6 19.8 20.2
  913. read_dict 24.3 25.7 22.3 23.0 21.0 22.4
  914. read_strdict 22.6 24.3 19.5 21.2 18.9 21.5
  915. Data structure write access:
  916. write_list 27.1 28.5 22.5 21.6 20.0 20.0
  917. write_deque 28.7 30.1 22.7 21.8 23.5 21.7
  918. write_dict 31.4 33.3 29.3 29.2 24.7 25.4
  919. write_strdict 28.4 29.9 27.5 25.2 23.1 24.5
  920. Stack (or queue) operations:
  921. list_append_pop 93.4 112.7 75.4 74.2 50.8 50.6
  922. deque_append_pop 43.5 57.0 49.4 49.2 42.5 44.2
  923. deque_append_popleft 43.7 57.3 49.7 49.7 42.8 46.4
  924. Timing loop:
  925. loop_overhead 0.5 0.6 0.4 0.3 0.3 0.3
  926. </pre></div>
  927. </div>
  928. <p>These results were generated from the variable access benchmark script at:
  929. <code class="docutils literal notranslate"><span class="pre">Tools/scripts/var_access_benchmark.py</span></code>. The benchmark script displays timings
  930. in nanoseconds. The benchmarks were measured on an
  931. <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>
  932. running the macOS 64-bit builds found at
  933. <a class="reference external" href="https://www.python.org/downloads/macos/">python.org</a>.</p>
  934. </section>
  935. <section id="deprecated">
  936. <h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading">¶</a></h2>
  937. <ul>
  938. <li><p>The distutils <code class="docutils literal notranslate"><span class="pre">bdist_msi</span></code> command is now deprecated, use
  939. <code class="docutils literal notranslate"><span class="pre">bdist_wheel</span></code> (wheel packages) instead.
  940. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39586">bpo-39586</a>.)</p></li>
  941. <li><p>Currently <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> accepts <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> instances with
  942. non-negative integer values (like <code class="docutils literal notranslate"><span class="pre">5.0</span></code>). It 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>
  943. for non-integral and negative floats. It is now deprecated. In future
  944. Python versions it will raise 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> for all floats.
  945. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37315">bpo-37315</a>.)</p></li>
  946. <li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">symbol</span></code> modules are deprecated and will be
  947. removed in future versions of Python. For the majority of use cases,
  948. users can leverage the Abstract Syntax Tree (AST) generation and compilation
  949. stage, using the <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> module.</p></li>
  950. <li><p>The Public C API functions <code class="xref c c-func docutils literal notranslate"><span class="pre">PyParser_SimpleParseStringFlags()</span></code>,
  951. <code class="xref c c-func docutils literal notranslate"><span class="pre">PyParser_SimpleParseStringFlagsFilename()</span></code>,
  952. <code class="xref c c-func docutils literal notranslate"><span class="pre">PyParser_SimpleParseFileFlags()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyNode_Compile()</span></code>
  953. are deprecated and will be removed in Python 3.10 together with the old parser.</p></li>
  954. <li><p>Using <a class="reference internal" href="../library/constants.html#NotImplemented" title="NotImplemented"><code class="xref py py-data docutils literal notranslate"><span class="pre">NotImplemented</span></code></a> in a boolean context has been deprecated,
  955. as it is almost exclusively the result of incorrect rich comparator
  956. implementations. It will be made 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> in a future version
  957. of Python.
  958. (Contributed by Josh Rosenberg in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35712">bpo-35712</a>.)</p></li>
  959. <li><p>The <a class="reference internal" href="../library/random.html#module-random" title="random: Generate pseudo-random numbers with various common distributions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">random</span></code></a> module currently accepts any hashable type as a
  960. possible seed value. Unfortunately, some of those types are not
  961. guaranteed to have a deterministic hash value. After Python 3.9,
  962. the module will restrict its seeds to <a class="reference internal" href="../library/constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>, <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>,
  963. <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/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>, and <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a>.</p></li>
  964. <li><p>Opening the <a class="reference internal" href="../library/gzip.html#gzip.GzipFile" title="gzip.GzipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">GzipFile</span></code></a> file for writing without specifying
  965. the <em>mode</em> argument is deprecated. In future Python versions it will always
  966. be opened for reading by default. Specify the <em>mode</em> argument for opening
  967. it for writing and silencing a warning.
  968. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28286">bpo-28286</a>.)</p></li>
  969. <li><p>Deprecated the <code class="docutils literal notranslate"><span class="pre">split()</span></code> method of <code class="xref py py-class docutils literal notranslate"><span class="pre">_tkinter.TkappType</span></code> in
  970. favour of the <code class="docutils literal notranslate"><span class="pre">splitlist()</span></code> method which has more consistent and
  971. predicable behavior.
  972. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38371">bpo-38371</a>.)</p></li>
  973. <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
  974. deprecated and will be removed in version 3.11.
  975. (Contributed by Yury Selivanov and Kyle Stanley in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34790">bpo-34790</a>.)</p></li>
  976. <li><p>binhex4 and hexbin4 standards are now deprecated. The <code class="xref py py-mod docutils literal notranslate"><span class="pre">binhex</span></code> module
  977. and the following <a class="reference internal" href="../library/binascii.html#module-binascii" title="binascii: Tools for converting between binary and various ASCII-encoded binary representations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">binascii</span></code></a> functions are now deprecated:</p>
  978. <ul class="simple">
  979. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">b2a_hqx()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">a2b_hqx()</span></code></p></li>
  980. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">rlecode_hqx()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">rledecode_hqx()</span></code></p></li>
  981. </ul>
  982. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39353">bpo-39353</a>.)</p>
  983. </li>
  984. <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">slice</span></code>, <code class="docutils literal notranslate"><span class="pre">Index</span></code> and <code class="docutils literal notranslate"><span class="pre">ExtSlice</span></code> are considered deprecated
  985. and will be removed in future Python versions. <code class="docutils literal notranslate"><span class="pre">value</span></code> itself should be
  986. used instead of <code class="docutils literal notranslate"><span class="pre">Index(value)</span></code>. <code class="docutils literal notranslate"><span class="pre">Tuple(slices,</span> <span class="pre">Load())</span></code> should be
  987. used instead of <code class="docutils literal notranslate"><span class="pre">ExtSlice(slices)</span></code>.
  988. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34822">bpo-34822</a>.)</p></li>
  989. <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">Suite</span></code>, <code class="docutils literal notranslate"><span class="pre">Param</span></code>, <code class="docutils literal notranslate"><span class="pre">AugLoad</span></code> and <code class="docutils literal notranslate"><span class="pre">AugStore</span></code>
  990. are considered deprecated and will be removed in future Python versions.
  991. They were not generated by the parser and not accepted by the code
  992. generator in Python 3.
  993. (Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39639">bpo-39639</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39969">bpo-39969</a>
  994. and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39988">bpo-39988</a>.)</p></li>
  995. <li><p>The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_InitThreads()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_ThreadsInitialized()</span></code>
  996. functions are now deprecated and will be removed in Python 3.11. Calling
  997. <code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_InitThreads()</span></code> now does nothing. The <a class="reference internal" href="../glossary.html#term-GIL"><span class="xref std std-term">GIL</span></a> is initialized
  998. by <a class="reference internal" href="../c-api/init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Initialize()</span></code></a> since Python 3.7.
  999. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39877">bpo-39877</a>.)</p></li>
  1000. <li><p>Passing <code class="docutils literal notranslate"><span class="pre">None</span></code> as the first argument to the <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> function
  1001. has been deprecated. (Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33262">bpo-33262</a>.)</p></li>
  1002. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">smtpd.MailmanProxy()</span></code> is now deprecated as it is unusable without
  1003. an external module, <code class="docutils literal notranslate"><span class="pre">mailman</span></code>. (Contributed by Samuel Colvin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35800">bpo-35800</a>.)</p></li>
  1004. <li><p>The <a class="reference internal" href="../library/2to3.html#module-lib2to3" title="lib2to3: The 2to3 library"><code class="xref py py-mod docutils literal notranslate"><span class="pre">lib2to3</span></code></a> module now emits a <a class="reference internal" href="../library/exceptions.html#PendingDeprecationWarning" title="PendingDeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PendingDeprecationWarning</span></code></a>.
  1005. Python 3.9 switched to a PEG parser (see <span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0617/"><strong>PEP 617</strong></a>), and Python 3.10 may
  1006. include new language syntax that is not parsable by lib2to3’s LL(1) parser.
  1007. The <code class="docutils literal notranslate"><span class="pre">lib2to3</span></code> module may be removed from the standard library in a future
  1008. Python version. Consider third-party alternatives such as <a class="reference external" href="https://libcst.readthedocs.io/">LibCST</a> or
  1009. <a class="reference external" href="https://parso.readthedocs.io/">parso</a>.
  1010. (Contributed by Carl Meyer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40360">bpo-40360</a>.)</p></li>
  1011. <li><p>The <em>random</em> parameter of <a class="reference internal" href="../library/random.html#random.shuffle" title="random.shuffle"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.shuffle()</span></code></a> has been deprecated.
  1012. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40465">bpo-40465</a>)</p></li>
  1013. </ul>
  1014. </section>
  1015. <section id="removed">
  1016. <span id="removed-in-python-39"></span><h2>Removed<a class="headerlink" href="#removed" title="Link to this heading">¶</a></h2>
  1017. <ul class="simple">
  1018. <li><p>The erroneous version at <code class="xref py py-data docutils literal notranslate"><span class="pre">unittest.mock.__version__</span></code> has been removed.</p></li>
  1019. <li><p><a class="reference internal" href="../library/nntplib.html#nntplib.NNTP" title="nntplib.NNTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">nntplib.NNTP</span></code></a>: <code class="docutils literal notranslate"><span class="pre">xpath()</span></code> and <code class="docutils literal notranslate"><span class="pre">xgtitle()</span></code> methods have been removed.
  1020. These methods are deprecated since Python 3.3. Generally, these extensions
  1021. are not supported or not enabled by NNTP server administrators.
  1022. For <code class="docutils literal notranslate"><span class="pre">xgtitle()</span></code>, please use <a class="reference internal" href="../library/nntplib.html#nntplib.NNTP.descriptions" title="nntplib.NNTP.descriptions"><code class="xref py py-meth docutils literal notranslate"><span class="pre">nntplib.NNTP.descriptions()</span></code></a> or
  1023. <a class="reference internal" href="../library/nntplib.html#nntplib.NNTP.description" title="nntplib.NNTP.description"><code class="xref py py-meth docutils literal notranslate"><span class="pre">nntplib.NNTP.description()</span></code></a> instead.
  1024. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39366">bpo-39366</a>.)</p></li>
  1025. <li><p><a class="reference internal" href="../library/array.html#array.array" title="array.array"><code class="xref py py-class docutils literal notranslate"><span class="pre">array.array</span></code></a>: <code class="docutils literal notranslate"><span class="pre">tostring()</span></code> and <code class="docutils literal notranslate"><span class="pre">fromstring()</span></code> methods have been
  1026. removed. They were aliases to <code class="docutils literal notranslate"><span class="pre">tobytes()</span></code> and <code class="docutils literal notranslate"><span class="pre">frombytes()</span></code>, deprecated
  1027. since Python 3.2.
  1028. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38916">bpo-38916</a>.)</p></li>
  1029. <li><p>The undocumented <code class="docutils literal notranslate"><span class="pre">sys.callstats()</span></code> function has been removed. Since Python
  1030. 3.7, it was deprecated and always returned <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>. It required a special
  1031. build option <code class="docutils literal notranslate"><span class="pre">CALL_PROFILE</span></code> which was already removed in Python 3.7.
  1032. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37414">bpo-37414</a>.)</p></li>
  1033. <li><p>The <code class="docutils literal notranslate"><span class="pre">sys.getcheckinterval()</span></code> and <code class="docutils literal notranslate"><span class="pre">sys.setcheckinterval()</span></code> functions have
  1034. been removed. They were deprecated since Python 3.2. Use
  1035. <a class="reference internal" href="../library/sys.html#sys.getswitchinterval" title="sys.getswitchinterval"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getswitchinterval()</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.setswitchinterval" title="sys.setswitchinterval"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.setswitchinterval()</span></code></a> instead.
  1036. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37392">bpo-37392</a>.)</p></li>
  1037. <li><p>The C function <code class="docutils literal notranslate"><span class="pre">PyImport_Cleanup()</span></code> has been removed. It was documented as:
  1038. “Empty the module table. For internal use only.”
  1039. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36710">bpo-36710</a>.)</p></li>
  1040. <li><p><code class="docutils literal notranslate"><span class="pre">_dummy_thread</span></code> and <code class="docutils literal notranslate"><span class="pre">dummy_threading</span></code> modules have been removed. These
  1041. modules were deprecated since Python 3.7 which requires threading support.
  1042. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37312">bpo-37312</a>.)</p></li>
  1043. <li><p><code class="docutils literal notranslate"><span class="pre">aifc.openfp()</span></code> alias to <code class="docutils literal notranslate"><span class="pre">aifc.open()</span></code>, <code class="docutils literal notranslate"><span class="pre">sunau.openfp()</span></code> alias to
  1044. <code class="docutils literal notranslate"><span class="pre">sunau.open()</span></code>, and <code class="docutils literal notranslate"><span class="pre">wave.openfp()</span></code> alias to <a class="reference internal" href="../library/wave.html#wave.open" title="wave.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">wave.open()</span></code></a> have been
  1045. removed. They were deprecated since Python 3.7.
  1046. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37320">bpo-37320</a>.)</p></li>
  1047. <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>
  1048. has been removed. It was deprecated since Python 3.8.
  1049. Use <a class="reference internal" href="../library/threading.html#threading.Thread.is_alive" title="threading.Thread.is_alive"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_alive()</span></code></a> instead.
  1050. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37804">bpo-37804</a>.)</p></li>
  1051. <li><p>Methods <code class="docutils literal notranslate"><span class="pre">getchildren()</span></code> and <code class="docutils literal notranslate"><span class="pre">getiterator()</span></code> of classes
  1052. <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree" title="xml.etree.ElementTree.ElementTree"><code class="xref py py-class docutils literal notranslate"><span class="pre">ElementTree</span></code></a> and
  1053. <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.Element" title="xml.etree.ElementTree.Element"><code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code></a> 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">ElementTree</span></code></a>
  1054. module have been removed. They were deprecated in Python 3.2.
  1055. Use <code class="docutils literal notranslate"><span class="pre">iter(x)</span></code> or <code class="docutils literal notranslate"><span class="pre">list(x)</span></code> instead of <code class="docutils literal notranslate"><span class="pre">x.getchildren()</span></code> and
  1056. <code class="docutils literal notranslate"><span class="pre">x.iter()</span></code> or <code class="docutils literal notranslate"><span class="pre">list(x.iter())</span></code> instead of <code class="docutils literal notranslate"><span class="pre">x.getiterator()</span></code>.
  1057. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36543">bpo-36543</a>.)</p></li>
  1058. <li><p>The old <a class="reference internal" href="../library/plistlib.html#module-plistlib" title="plistlib: Generate and parse Apple plist files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code></a> API has been removed, it was deprecated since Python
  1059. 3.4. Use the <a class="reference internal" href="../library/plistlib.html#plistlib.load" title="plistlib.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">load()</span></code></a>, <a class="reference internal" href="../library/plistlib.html#plistlib.loads" title="plistlib.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">loads()</span></code></a>, <a class="reference internal" href="../library/plistlib.html#plistlib.dump" title="plistlib.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump()</span></code></a>, and
  1060. <a class="reference internal" href="../library/plistlib.html#plistlib.dumps" title="plistlib.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">dumps()</span></code></a> functions. Additionally, the <em>use_builtin_types</em> parameter was
  1061. removed, standard <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> objects are always used instead.
  1062. (Contributed by Jon Janzen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36409">bpo-36409</a>.)</p></li>
  1063. <li><p>The C function <code class="docutils literal notranslate"><span class="pre">PyGen_NeedsFinalizing</span></code> has been removed. It was not
  1064. documented, tested, or used anywhere within CPython after the implementation
  1065. of <span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0442/"><strong>PEP 442</strong></a>. Patch by Joannah Nanjekye.
  1066. (Contributed by Joannah Nanjekye in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15088">bpo-15088</a>)</p></li>
  1067. <li><p><code class="docutils literal notranslate"><span class="pre">base64.encodestring()</span></code> and <code class="docutils literal notranslate"><span class="pre">base64.decodestring()</span></code>, aliases deprecated
  1068. since Python 3.1, have been removed: use <a class="reference internal" href="../library/base64.html#base64.encodebytes" title="base64.encodebytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">base64.encodebytes()</span></code></a> and
  1069. <a class="reference internal" href="../library/base64.html#base64.decodebytes" title="base64.decodebytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">base64.decodebytes()</span></code></a> instead.
  1070. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39351">bpo-39351</a>.)</p></li>
  1071. <li><p><code class="docutils literal notranslate"><span class="pre">fractions.gcd()</span></code> function has been removed, it was deprecated since Python
  1072. 3.5 (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22486">bpo-22486</a>): use <a class="reference internal" href="../library/math.html#math.gcd" title="math.gcd"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.gcd()</span></code></a> instead.
  1073. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39350">bpo-39350</a>.)</p></li>
  1074. <li><p>The <em>buffering</em> parameter of <a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><code class="xref py py-class docutils literal notranslate"><span class="pre">bz2.BZ2File</span></code></a> has been removed. Since
  1075. Python 3.0, it was ignored and using it emitted 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>.
  1076. Pass an open file object to control how the file is opened.
  1077. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39357">bpo-39357</a>.)</p></li>
  1078. <li><p>The <em>encoding</em> parameter of <a class="reference internal" href="../library/json.html#json.loads" title="json.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.loads()</span></code></a> has been removed.
  1079. As of Python 3.1, it was deprecated and ignored; using it has emitted a
  1080. <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> since Python 3.8.
  1081. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39377">bpo-39377</a>)</p></li>
  1082. <li><p><code class="docutils literal notranslate"><span class="pre">with</span> <span class="pre">(await</span> <span class="pre">asyncio.lock):</span></code> and <code class="docutils literal notranslate"><span class="pre">with</span> <span class="pre">(yield</span> <span class="pre">from</span> <span class="pre">asyncio.lock):</span></code> statements are
  1083. not longer supported, use <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">with</span> <span class="pre">lock</span></code> instead. The same is correct for
  1084. <code class="docutils literal notranslate"><span class="pre">asyncio.Condition</span></code> and <code class="docutils literal notranslate"><span class="pre">asyncio.Semaphore</span></code>.
  1085. (Contributed by Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34793">bpo-34793</a>.)</p></li>
  1086. <li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getcounts()</span></code> function, the <code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">showalloccount</span></code> command line
  1087. option and the <code class="docutils literal notranslate"><span class="pre">show_alloc_count</span></code> field of the C structure
  1088. <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> have been removed. They required a special Python build by
  1089. defining <code class="docutils literal notranslate"><span class="pre">COUNT_ALLOCS</span></code> macro.
  1090. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39489">bpo-39489</a>.)</p></li>
  1091. <li><p>The <code class="docutils literal notranslate"><span class="pre">_field_types</span></code> attribute of 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
  1092. has been removed. It was deprecated since Python 3.8. Use
  1093. the <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code> attribute instead.
  1094. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40182">bpo-40182</a>.)</p></li>
  1095. <li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">symtable.SymbolTable.has_exec()</span></code> method has been removed. It was
  1096. deprecated since 2006, and only returning <code class="docutils literal notranslate"><span class="pre">False</span></code> when it’s called.
  1097. (Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40208">bpo-40208</a>)</p></li>
  1098. <li><p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.Task.current_task()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.Task.all_tasks()</span></code>
  1099. have been removed. They were deprecated since Python 3.7 and you can use
  1100. <a class="reference internal" href="../library/asyncio-task.html#asyncio.current_task" title="asyncio.current_task"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.current_task()</span></code></a> and <a class="reference internal" href="../library/asyncio-task.html#asyncio.all_tasks" title="asyncio.all_tasks"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.all_tasks()</span></code></a> instead.
  1101. (Contributed by Rémi Lapeyre in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40967">bpo-40967</a>)</p></li>
  1102. <li><p>The <code class="docutils literal notranslate"><span class="pre">unescape()</span></code> method in the <a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">html.parser.HTMLParser</span></code></a> class
  1103. has been removed (it was deprecated since Python 3.4). <a class="reference internal" href="../library/html.html#html.unescape" title="html.unescape"><code class="xref py py-func docutils literal notranslate"><span class="pre">html.unescape()</span></code></a>
  1104. should be used for converting character references to the corresponding
  1105. unicode characters.</p></li>
  1106. </ul>
  1107. </section>
  1108. <section id="porting-to-python-3-9">
  1109. <h2>Porting to Python 3.9<a class="headerlink" href="#porting-to-python-3-9" title="Link to this heading">¶</a></h2>
  1110. <p>This section lists previously described changes and other bugfixes
  1111. that may require changes to your code.</p>
  1112. <section id="changes-in-the-python-api">
  1113. <h3>Changes in the Python API<a class="headerlink" href="#changes-in-the-python-api" title="Link to this heading">¶</a></h3>
  1114. <ul class="simple">
  1115. <li><p><a class="reference internal" href="../library/functions.html#import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> and <a class="reference internal" href="../library/importlib.html#importlib.util.resolve_name" title="importlib.util.resolve_name"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.resolve_name()</span></code></a> now raise
  1116. <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> where it previously raised <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>. Callers
  1117. catching the specific exception type and supporting both Python 3.9 and
  1118. earlier versions will need to catch both using <code class="docutils literal notranslate"><span class="pre">except</span> <span class="pre">(ImportError,</span> <span class="pre">ValueError):</span></code>.</p></li>
  1119. <li><p>The <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> activation scripts no longer special-case when
  1120. <code class="docutils literal notranslate"><span class="pre">__VENV_PROMPT__</span></code> is set to <code class="docutils literal notranslate"><span class="pre">&quot;&quot;</span></code>.</p></li>
  1121. <li><p>The <a class="reference internal" href="../library/select.html#select.epoll.unregister" title="select.epoll.unregister"><code class="xref py py-meth docutils literal notranslate"><span class="pre">select.epoll.unregister()</span></code></a> method no longer ignores the
  1122. <a class="reference internal" href="../library/errno.html#errno.EBADF" title="errno.EBADF"><code class="xref py py-const docutils literal notranslate"><span class="pre">EBADF</span></code></a> error.
  1123. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39239">bpo-39239</a>.)</p></li>
  1124. <li><p>The <em>compresslevel</em> parameter of <a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><code class="xref py py-class docutils literal notranslate"><span class="pre">bz2.BZ2File</span></code></a> became keyword-only,
  1125. since the <em>buffering</em> parameter has been removed.
  1126. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39357">bpo-39357</a>.)</p></li>
  1127. <li><p>Simplified AST for subscription. Simple indices will be represented by
  1128. their value, extended slices will be represented as tuples.
  1129. <code class="docutils literal notranslate"><span class="pre">Index(value)</span></code> will return a <code class="docutils literal notranslate"><span class="pre">value</span></code> itself, <code class="docutils literal notranslate"><span class="pre">ExtSlice(slices)</span></code>
  1130. will return <code class="docutils literal notranslate"><span class="pre">Tuple(slices,</span> <span class="pre">Load())</span></code>.
  1131. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34822">bpo-34822</a>.)</p></li>
  1132. <li><p>The <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> module now ignores the <span class="target" id="index-21"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONCASEOK"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONCASEOK</span></code></a>
  1133. environment variable when the <a class="reference internal" href="../using/cmdline.html#cmdoption-E"><code class="xref std std-option docutils literal notranslate"><span class="pre">-E</span></code></a> or <a class="reference internal" href="../using/cmdline.html#cmdoption-I"><code class="xref std std-option docutils literal notranslate"><span class="pre">-I</span></code></a> command line
  1134. options are being used.</p></li>
  1135. <li><p>The <em>encoding</em> parameter has been added to the classes <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> and
  1136. <a class="reference internal" href="../library/ftplib.html#ftplib.FTP_TLS" title="ftplib.FTP_TLS"><code class="xref py py-class docutils literal notranslate"><span class="pre">ftplib.FTP_TLS</span></code></a> as a keyword-only parameter, and the default encoding
  1137. is changed from Latin-1 to UTF-8 to follow <span class="target" id="index-22"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc2640.html"><strong>RFC 2640</strong></a>.</p></li>
  1138. <li><p><a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.shutdown_default_executor" title="asyncio.loop.shutdown_default_executor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.shutdown_default_executor()</span></code></a> has been added to
  1139. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.AbstractEventLoop" title="asyncio.AbstractEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">AbstractEventLoop</span></code></a>, meaning alternative event loops that
  1140. inherit from it should have this method defined.
  1141. (Contributed by Kyle Stanley in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34037">bpo-34037</a>.)</p></li>
  1142. <li><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
  1143. is updated in order to prevent collision with compiler flags. Previously
  1144. <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>.
  1145. (Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39562">bpo-39562</a>)</p></li>
  1146. <li><p><code class="docutils literal notranslate"><span class="pre">array('u')</span></code> now uses <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code> as C type instead of <code class="docutils literal notranslate"><span class="pre">Py_UNICODE</span></code>.
  1147. This change doesn’t affect to its behavior because <code class="docutils literal notranslate"><span class="pre">Py_UNICODE</span></code> is alias
  1148. of <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code> since Python 3.3.
  1149. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34538">bpo-34538</a>.)</p></li>
  1150. <li><p>The <a class="reference internal" href="../library/logging.html#logging.getLogger" title="logging.getLogger"><code class="xref py py-func docutils literal notranslate"><span class="pre">logging.getLogger()</span></code></a> API now returns the root logger when passed
  1151. the name <code class="docutils literal notranslate"><span class="pre">'root'</span></code>, whereas previously it returned a non-root logger named
  1152. <code class="docutils literal notranslate"><span class="pre">'root'</span></code>. This could affect cases where user code explicitly wants a
  1153. non-root logger named <code class="docutils literal notranslate"><span class="pre">'root'</span></code>, or instantiates a logger using
  1154. <code class="docutils literal notranslate"><span class="pre">logging.getLogger(__name__)</span></code> in some top-level module called <code class="docutils literal notranslate"><span class="pre">'root.py'</span></code>.
  1155. (Contributed by Vinay Sajip in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37742">bpo-37742</a>.)</p></li>
  1156. <li><p>Division handling of <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePath</span></code></a> now returns <a class="reference internal" href="../library/constants.html#NotImplemented" title="NotImplemented"><code class="xref py py-data docutils literal notranslate"><span class="pre">NotImplemented</span></code></a>
  1157. instead of raising 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> when passed something other than an
  1158. instance of <code class="docutils literal notranslate"><span class="pre">str</span></code> or <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">PurePath</span></code></a>. This allows creating
  1159. compatible classes that don’t inherit from those mentioned types.
  1160. (Contributed by Roger Aiudi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34775">bpo-34775</a>).</p></li>
  1161. <li><p>Starting with Python 3.9.5 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
  1162. accepts any leading zeros in IPv4 address strings. Leading zeros are
  1163. ambiguous and interpreted as octal notation by some libraries. For example
  1164. the legacy 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
  1165. notatation. 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
  1166. not accept any leading zeros.
  1167. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36384">bpo-36384</a>).</p></li>
  1168. <li><p><a class="reference internal" href="../library/codecs.html#codecs.lookup" title="codecs.lookup"><code class="xref py py-func docutils literal notranslate"><span class="pre">codecs.lookup()</span></code></a> now normalizes the encoding name the same way as
  1169. <code class="xref py py-func docutils literal notranslate"><span class="pre">encodings.normalize_encoding()</span></code>, except that <a class="reference internal" href="../library/codecs.html#codecs.lookup" title="codecs.lookup"><code class="xref py py-func docutils literal notranslate"><span class="pre">codecs.lookup()</span></code></a> also
  1170. converts the name to lower case. For example, <code class="docutils literal notranslate"><span class="pre">&quot;latex+latin1&quot;</span></code> encoding
  1171. name is now normalized to <code class="docutils literal notranslate"><span class="pre">&quot;latex_latin1&quot;</span></code>.
  1172. (Contributed by Jordon Xu in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37751">bpo-37751</a>.)</p></li>
  1173. </ul>
  1174. </section>
  1175. <section id="changes-in-the-c-api">
  1176. <h3>Changes in the C API<a class="headerlink" href="#changes-in-the-c-api" title="Link to this heading">¶</a></h3>
  1177. <ul>
  1178. <li><p>Instances of <a class="reference internal" href="../c-api/typeobj.html#heap-types"><span class="std std-ref">heap-allocated types</span></a> (such as those created with
  1179. <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> and similar APIs) hold a reference to their type
  1180. object since Python 3.8. As indicated in the “Changes in the C API” of Python
  1181. 3.8, for the vast majority of cases, there should be no side effect but for
  1182. types that have a custom <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_traverse" title="PyTypeObject.tp_traverse"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_traverse</span></code></a> function,
  1183. ensure that all custom <code class="docutils literal notranslate"><span class="pre">tp_traverse</span></code> functions of heap-allocated types
  1184. visit the object’s type.</p>
  1185. <blockquote>
  1186. <div><p>Example:</p>
  1187. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span>
  1188. <span class="nf">foo_traverse</span><span class="p">(</span><span class="n">foo_struct</span><span class="w"> </span><span class="o">*</span><span class="n">self</span><span class="p">,</span><span class="w"> </span><span class="n">visitproc</span><span class="w"> </span><span class="n">visit</span><span class="p">,</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">arg</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
  1189. <span class="c1">// Rest of the traverse function</span>
  1190. <span class="cp">#if PY_VERSION_HEX &gt;= 0x03090000</span>
  1191. <span class="w"> </span><span class="c1">// This was not needed before Python 3.9 (Python issue 35810 and 40217)</span>
  1192. <span class="w"> </span><span class="n">Py_VISIT</span><span class="p">(</span><span class="n">Py_TYPE</span><span class="p">(</span><span class="n">self</span><span class="p">));</span>
  1193. <span class="cp">#endif</span>
  1194. <span class="p">}</span>
  1195. </pre></div>
  1196. </div>
  1197. </div></blockquote>
  1198. <p>If your traverse function delegates to <code class="docutils literal notranslate"><span class="pre">tp_traverse</span></code> of its base class
  1199. (or another type), ensure that <code class="docutils literal notranslate"><span class="pre">Py_TYPE(self)</span></code> is visited only once.
  1200. Note that only <a class="reference internal" href="../c-api/typeobj.html#heap-types"><span class="std std-ref">heap type</span></a> are expected to visit the type
  1201. in <code class="docutils literal notranslate"><span class="pre">tp_traverse</span></code>.</p>
  1202. <blockquote>
  1203. <div><p>For example, if your <code class="docutils literal notranslate"><span class="pre">tp_traverse</span></code> function includes:</p>
  1204. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">base</span><span class="o">-&gt;</span><span class="n">tp_traverse</span><span class="p">(</span><span class="n">self</span><span class="p">,</span><span class="w"> </span><span class="n">visit</span><span class="p">,</span><span class="w"> </span><span class="n">arg</span><span class="p">)</span>
  1205. </pre></div>
  1206. </div>
  1207. <p>then add:</p>
  1208. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="cp">#if PY_VERSION_HEX &gt;= 0x03090000</span>
  1209. <span class="w"> </span><span class="c1">// This was not needed before Python 3.9 (bpo-35810 and bpo-40217)</span>
  1210. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">base</span><span class="o">-&gt;</span><span class="n">tp_flags</span><span class="w"> </span><span class="o">&amp;</span><span class="w"> </span><span class="n">Py_TPFLAGS_HEAPTYPE</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
  1211. <span class="w"> </span><span class="c1">// a heap type&#39;s tp_traverse already visited Py_TYPE(self)</span>
  1212. <span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span>
  1213. <span class="w"> </span><span class="n">Py_VISIT</span><span class="p">(</span><span class="n">Py_TYPE</span><span class="p">(</span><span class="n">self</span><span class="p">));</span>
  1214. <span class="w"> </span><span class="p">}</span>
  1215. <span class="cp">#else</span>
  1216. </pre></div>
  1217. </div>
  1218. </div></blockquote>
  1219. <p>(See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35810">bpo-35810</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40217">bpo-40217</a> for more information.)</p>
  1220. </li>
  1221. <li><p>The functions <code class="docutils literal notranslate"><span class="pre">PyEval_CallObject</span></code>, <code class="docutils literal notranslate"><span class="pre">PyEval_CallFunction</span></code>,
  1222. <code class="docutils literal notranslate"><span class="pre">PyEval_CallMethod</span></code> and <code class="docutils literal notranslate"><span class="pre">PyEval_CallObjectWithKeywords</span></code> are deprecated.
  1223. Use <a class="reference internal" href="../c-api/call.html#c.PyObject_Call" title="PyObject_Call"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Call()</span></code></a> and its variants instead.
  1224. (See more details in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29548">bpo-29548</a>.)</p></li>
  1225. </ul>
  1226. </section>
  1227. <section id="cpython-bytecode-changes">
  1228. <h3>CPython bytecode changes<a class="headerlink" href="#cpython-bytecode-changes" title="Link to this heading">¶</a></h3>
  1229. <ul>
  1230. <li><p>The <a class="reference internal" href="../library/dis.html#opcode-LOAD_ASSERTION_ERROR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_ASSERTION_ERROR</span></code></a> opcode was added for handling the
  1231. <a class="reference internal" href="../reference/simple_stmts.html#assert"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">assert</span></code></a> statement. Previously, the assert statement would not work
  1232. correctly if the <a class="reference internal" href="../library/exceptions.html#AssertionError" title="AssertionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AssertionError</span></code></a> exception was being shadowed.
  1233. (Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34880">bpo-34880</a>.)</p></li>
  1234. <li><p>The <a class="reference internal" href="../library/dis.html#opcode-COMPARE_OP"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">COMPARE_OP</span></code></a> opcode was split into four distinct instructions:</p>
  1235. <ul class="simple">
  1236. <li><p><code class="docutils literal notranslate"><span class="pre">COMPARE_OP</span></code> for rich comparisons</p></li>
  1237. <li><p><code class="docutils literal notranslate"><span class="pre">IS_OP</span></code> for ‘is’ and ‘is not’ tests</p></li>
  1238. <li><p><code class="docutils literal notranslate"><span class="pre">CONTAINS_OP</span></code> for ‘in’ and ‘not in’ tests</p></li>
  1239. <li><p><code class="docutils literal notranslate"><span class="pre">JUMP_IF_NOT_EXC_MATCH</span></code> for checking exceptions in ‘try-except’
  1240. statements.</p></li>
  1241. </ul>
  1242. <p>(Contributed by Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39156">bpo-39156</a>.)</p>
  1243. </li>
  1244. </ul>
  1245. </section>
  1246. </section>
  1247. <section id="build-changes">
  1248. <h2>Build Changes<a class="headerlink" href="#build-changes" title="Link to this heading">¶</a></h2>
  1249. <ul class="simple">
  1250. <li><p>Added <code class="docutils literal notranslate"><span class="pre">--with-platlibdir</span></code> option to the <code class="docutils literal notranslate"><span class="pre">configure</span></code> script: name of the
  1251. platform-specific library directory, stored in the new <a class="reference internal" href="../library/sys.html#sys.platlibdir" title="sys.platlibdir"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platlibdir</span></code></a>
  1252. attribute. See <a class="reference internal" href="../library/sys.html#sys.platlibdir" title="sys.platlibdir"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platlibdir</span></code></a> attribute for more information.
  1253. (Contributed by Jan Matějek, Matěj Cepl, Charalampos Stratakis
  1254. and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1294959">bpo-1294959</a>.)</p></li>
  1255. <li><p>The <code class="docutils literal notranslate"><span class="pre">COUNT_ALLOCS</span></code> special build macro has been removed.
  1256. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39489">bpo-39489</a>.)</p></li>
  1257. <li><p>On non-Windows platforms, the <code class="xref c c-func docutils literal notranslate"><span class="pre">setenv()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">unsetenv()</span></code>
  1258. functions are now required to build Python.
  1259. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39395">bpo-39395</a>.)</p></li>
  1260. <li><p>On non-Windows platforms, creating <code class="docutils literal notranslate"><span class="pre">bdist_wininst</span></code> installers is now
  1261. officially unsupported. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10945">bpo-10945</a> for more details.)</p></li>
  1262. <li><p>When building Python on macOS from source, <code class="docutils literal notranslate"><span class="pre">_tkinter</span></code> now links with
  1263. non-system Tcl and Tk frameworks if they are installed in
  1264. <code class="docutils literal notranslate"><span class="pre">/Library/Frameworks</span></code>, as had been the case on older releases
  1265. of macOS. If a macOS SDK is explicitly configured, by using
  1266. <a class="reference internal" href="../using/configure.html#cmdoption-enable-universalsdk"><code class="xref std std-option docutils literal notranslate"><span class="pre">--enable-universalsdk</span></code></a> or <code class="docutils literal notranslate"><span class="pre">-isysroot</span></code>, only the SDK itself is
  1267. searched. The default behavior can still be overridden with
  1268. <code class="docutils literal notranslate"><span class="pre">--with-tcltk-includes</span></code> and <code class="docutils literal notranslate"><span class="pre">--with-tcltk-libs</span></code>.
  1269. (Contributed by Ned Deily in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34956">bpo-34956</a>.)</p></li>
  1270. <li><p>Python can now be built for Windows 10 ARM64.
  1271. (Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33125">bpo-33125</a>.)</p></li>
  1272. <li><p>Some individual tests are now skipped when <code class="docutils literal notranslate"><span class="pre">--pgo</span></code> is used. The tests
  1273. in question increased the PGO task time significantly and likely
  1274. didn’t help improve optimization of the final executable. This
  1275. speeds up the task by a factor of about 15x. Running the full unit test
  1276. suite is slow. This change may result in a slightly less optimized build
  1277. since not as many code branches will be executed. If you are willing to
  1278. wait for the much slower build, the old behavior can be restored using
  1279. <code class="docutils literal notranslate"><span class="pre">./configure</span> <span class="pre">[..]</span> <span class="pre">PROFILE_TASK=&quot;-m</span> <span class="pre">test</span> <span class="pre">--pgo-extended&quot;</span></code>. We make no
  1280. guarantees as to which PGO task set produces a faster build. Users who care
  1281. should run their own relevant benchmarks as results can depend on the
  1282. environment, workload, and compiler tool chain.
  1283. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36044">bpo-36044</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37707">bpo-37707</a> for more details.)</p></li>
  1284. </ul>
  1285. </section>
  1286. <section id="c-api-changes">
  1287. <h2>C API Changes<a class="headerlink" href="#c-api-changes" title="Link to this heading">¶</a></h2>
  1288. <section id="id1">
  1289. <h3>New Features<a class="headerlink" href="#id1" title="Link to this heading">¶</a></h3>
  1290. <ul>
  1291. <li><p><span class="target" id="index-23"></span><a class="pep reference external" href="https://peps.python.org/pep-0573/"><strong>PEP 573</strong></a>: Added <a class="reference internal" href="../c-api/type.html#c.PyType_FromModuleAndSpec" title="PyType_FromModuleAndSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromModuleAndSpec()</span></code></a> to associate
  1292. a module with a class; <a class="reference internal" href="../c-api/type.html#c.PyType_GetModule" title="PyType_GetModule"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetModule()</span></code></a> and
  1293. <a class="reference internal" href="../c-api/type.html#c.PyType_GetModuleState" title="PyType_GetModuleState"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetModuleState()</span></code></a> to retrieve the module and its state; and
  1294. <a class="reference internal" href="../c-api/structures.html#c.PyCMethod" title="PyCMethod"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyCMethod</span></code></a> and <a class="reference internal" href="../c-api/structures.html#c.METH_METHOD" title="METH_METHOD"><code class="xref c c-macro docutils literal notranslate"><span class="pre">METH_METHOD</span></code></a> to allow a method to
  1295. access the class it was defined in.
  1296. (Contributed by Marcel Plch and Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38787">bpo-38787</a>.)</p></li>
  1297. <li><p>Added <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetCode" title="PyFrame_GetCode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetCode()</span></code></a> function: get a frame code.
  1298. Added <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBack" title="PyFrame_GetBack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBack()</span></code></a> function: get the frame next outer frame.
  1299. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40421">bpo-40421</a>.)</p></li>
  1300. <li><p>Added <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLineNumber" title="PyFrame_GetLineNumber"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLineNumber()</span></code></a> to the limited C API.
  1301. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40421">bpo-40421</a>.)</p></li>
  1302. <li><p>Added <a class="reference internal" href="../c-api/init.html#c.PyThreadState_GetInterpreter" title="PyThreadState_GetInterpreter"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_GetInterpreter()</span></code></a> and
  1303. <a class="reference internal" href="../c-api/init.html#c.PyInterpreterState_Get" title="PyInterpreterState_Get"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyInterpreterState_Get()</span></code></a> functions to get the interpreter.
  1304. Added <a class="reference internal" href="../c-api/init.html#c.PyThreadState_GetFrame" title="PyThreadState_GetFrame"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_GetFrame()</span></code></a> function to get the current frame of a
  1305. Python thread state.
  1306. Added <a class="reference internal" href="../c-api/init.html#c.PyThreadState_GetID" title="PyThreadState_GetID"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_GetID()</span></code></a> function: get the unique identifier of a
  1307. Python thread state.
  1308. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39947">bpo-39947</a>.)</p></li>
  1309. <li><p>Added a new public <a class="reference internal" href="../c-api/call.html#c.PyObject_CallNoArgs" title="PyObject_CallNoArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CallNoArgs()</span></code></a> function to the C API, which
  1310. calls a callable Python object without any arguments. It is the most efficient
  1311. way to call a callable Python object without any argument.
  1312. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37194">bpo-37194</a>.)</p></li>
  1313. <li><p>Changes in the limited C API (if <code class="docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code> macro is defined):</p>
  1314. <ul class="simple">
  1315. <li><p>Provide <a class="reference internal" href="../c-api/exceptions.html#c.Py_EnterRecursiveCall" title="Py_EnterRecursiveCall"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_EnterRecursiveCall()</span></code></a> and <a class="reference internal" href="../c-api/exceptions.html#c.Py_LeaveRecursiveCall" title="Py_LeaveRecursiveCall"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_LeaveRecursiveCall()</span></code></a>
  1316. as regular functions for the limited API. Previously, there were defined as
  1317. macros, but these macros didn’t compile with the limited C API which cannot
  1318. access <code class="docutils literal notranslate"><span class="pre">PyThreadState.recursion_depth</span></code> field (the structure is opaque in
  1319. the limited C API).</p></li>
  1320. <li><p><code class="docutils literal notranslate"><span class="pre">PyObject_INIT()</span></code> and <code class="docutils literal notranslate"><span class="pre">PyObject_INIT_VAR()</span></code> become regular “opaque”
  1321. function to hide implementation details.</p></li>
  1322. </ul>
  1323. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38644">bpo-38644</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39542">bpo-39542</a>.)</p>
  1324. </li>
  1325. <li><p>The <a class="reference internal" href="../c-api/module.html#c.PyModule_AddType" title="PyModule_AddType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_AddType()</span></code></a> function is added to help adding a type
  1326. to a module.
  1327. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40024">bpo-40024</a>.)</p></li>
  1328. <li><p>Added the functions <a class="reference internal" href="../c-api/gcsupport.html#c.PyObject_GC_IsTracked" title="PyObject_GC_IsTracked"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GC_IsTracked()</span></code></a> and
  1329. <a class="reference internal" href="../c-api/gcsupport.html#c.PyObject_GC_IsFinalized" title="PyObject_GC_IsFinalized"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GC_IsFinalized()</span></code></a> to the public API to allow to query if
  1330. Python objects are being currently tracked or have been already finalized by
  1331. the garbage collector respectively.
  1332. (Contributed by Pablo Galindo Salgado in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40241">bpo-40241</a>.)</p></li>
  1333. <li><p>Added <code class="xref c c-func docutils literal notranslate"><span class="pre">_PyObject_FunctionStr()</span></code> to get a user-friendly string
  1334. representation of a function-like object.
  1335. (Patch by Jeroen Demeyer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37645">bpo-37645</a>.)</p></li>
  1336. <li><p>Added <a class="reference internal" href="../c-api/call.html#c.PyObject_CallOneArg" title="PyObject_CallOneArg"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CallOneArg()</span></code></a> for calling an object with one
  1337. positional argument
  1338. (Patch by Jeroen Demeyer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37483">bpo-37483</a>.)</p></li>
  1339. </ul>
  1340. </section>
  1341. <section id="id2">
  1342. <h3>Porting to Python 3.9<a class="headerlink" href="#id2" title="Link to this heading">¶</a></h3>
  1343. <ul>
  1344. <li><p><code class="docutils literal notranslate"><span class="pre">PyInterpreterState.eval_frame</span></code> (<span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0523/"><strong>PEP 523</strong></a>) now requires a new mandatory
  1345. <em>tstate</em> parameter (<code class="docutils literal notranslate"><span class="pre">PyThreadState*</span></code>).
  1346. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38500">bpo-38500</a>.)</p></li>
  1347. <li><p>Extension modules: <a class="reference internal" href="../c-api/module.html#c.PyModuleDef.m_traverse" title="PyModuleDef.m_traverse"><code class="xref c c-member docutils literal notranslate"><span class="pre">m_traverse</span></code></a>,
  1348. <a class="reference internal" href="../c-api/module.html#c.PyModuleDef.m_clear" title="PyModuleDef.m_clear"><code class="xref c c-member docutils literal notranslate"><span class="pre">m_clear</span></code></a> and <a class="reference internal" href="../c-api/module.html#c.PyModuleDef.m_free" title="PyModuleDef.m_free"><code class="xref c c-member docutils literal notranslate"><span class="pre">m_free</span></code></a>
  1349. functions of <a class="reference internal" href="../c-api/module.html#c.PyModuleDef" title="PyModuleDef"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyModuleDef</span></code></a> are no longer called if the module state
  1350. was requested but is not allocated yet. This is the case immediately after
  1351. the module is created and before the module is executed
  1352. (<a class="reference internal" href="../c-api/module.html#c.Py_mod_exec" title="Py_mod_exec"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_mod_exec</span></code></a> function). More precisely, these functions are not called
  1353. if <a class="reference internal" href="../c-api/module.html#c.PyModuleDef.m_size" title="PyModuleDef.m_size"><code class="xref c c-member docutils literal notranslate"><span class="pre">m_size</span></code></a> is greater than 0 and the module state (as
  1354. returned by <a class="reference internal" href="../c-api/module.html#c.PyModule_GetState" title="PyModule_GetState"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_GetState()</span></code></a>) is <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  1355. <p>Extension modules without module state (<code class="docutils literal notranslate"><span class="pre">m_size</span> <span class="pre">&lt;=</span> <span class="pre">0</span></code>) are not affected.</p>
  1356. </li>
  1357. <li><p>If <a class="reference internal" href="../c-api/init.html#c.Py_AddPendingCall" title="Py_AddPendingCall"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_AddPendingCall()</span></code></a> is called in a subinterpreter, the function is
  1358. now scheduled to be called from the subinterpreter, rather than being called
  1359. from the main interpreter. Each subinterpreter now has its own list of
  1360. scheduled calls.
  1361. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39984">bpo-39984</a>.)</p></li>
  1362. <li><p>The Windows registry is no longer used to initialize <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> when
  1363. the <code class="docutils literal notranslate"><span class="pre">-E</span></code> option is used (if <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.use_environment" title="PyConfig.use_environment"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.use_environment</span></code></a> is set to
  1364. <code class="docutils literal notranslate"><span class="pre">0</span></code>). This is significant when embedding Python on Windows.
  1365. (Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8901">bpo-8901</a>.)</p></li>
  1366. <li><p>The global variable <a class="reference internal" href="../c-api/tuple.html#c.PyStructSequence_UnnamedField" title="PyStructSequence_UnnamedField"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyStructSequence_UnnamedField</span></code></a> is now a constant
  1367. and refers to a constant string.
  1368. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38650">bpo-38650</a>.)</p></li>
  1369. <li><p>The <code class="xref c c-type docutils literal notranslate"><span class="pre">PyGC_Head</span></code> structure is now opaque. It is only defined in the
  1370. internal C API (<code class="docutils literal notranslate"><span class="pre">pycore_gc.h</span></code>).
  1371. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40241">bpo-40241</a>.)</p></li>
  1372. <li><p>The <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_COPY</span></code>, <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_FILL</span></code>, <code class="docutils literal notranslate"><span class="pre">PyUnicode_WSTR_LENGTH</span></code>,
  1373. <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromUnicode()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicode()</span></code>,
  1374. <code class="docutils literal notranslate"><span class="pre">_PyUnicode_AsUnicode</span></code>, and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicodeAndSize()</span></code> are
  1375. marked as deprecated in C. They have been deprecated by <span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a> since
  1376. Python 3.3.
  1377. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36346">bpo-36346</a>.)</p></li>
  1378. <li><p>The <a class="reference internal" href="../c-api/sys.html#c.Py_FatalError" title="Py_FatalError"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_FatalError()</span></code></a> function is replaced with a macro which logs
  1379. automatically the name of the current function, unless the
  1380. <code class="docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code> macro is defined.
  1381. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39882">bpo-39882</a>.)</p></li>
  1382. <li><p>The vectorcall protocol now requires that the caller passes only strings as
  1383. keyword names. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37540">bpo-37540</a> for more information.)</p></li>
  1384. <li><p>Implementation details of a number of macros and functions are now hidden:</p>
  1385. <ul class="simple">
  1386. <li><p><a class="reference internal" href="../c-api/gcsupport.html#c.PyObject_IS_GC" title="PyObject_IS_GC"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_IS_GC()</span></code></a> macro was converted to a function.</p></li>
  1387. <li><p>The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_NEW()</span></code> macro becomes an alias to the
  1388. <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> macro, and the <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_NEW_VAR()</span></code> macro
  1389. becomes an alias to the <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> macro. They no longer
  1390. access directly the <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_basicsize" title="PyTypeObject.tp_basicsize"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_basicsize</span></code></a> member.</p></li>
  1391. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GET_WEAKREFS_LISTPTR()</span></code> macro was converted to a function:
  1392. the macro accessed directly the <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_weaklistoffset" title="PyTypeObject.tp_weaklistoffset"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_weaklistoffset</span></code></a>
  1393. member.</p></li>
  1394. <li><p><a class="reference internal" href="../c-api/buffer.html#c.PyObject_CheckBuffer" title="PyObject_CheckBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CheckBuffer()</span></code></a> macro was converted to a function: the macro
  1395. accessed directly the <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_as_buffer" title="PyTypeObject.tp_as_buffer"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_as_buffer</span></code></a> member.</p></li>
  1396. <li><p><a class="reference internal" href="../c-api/number.html#c.PyIndex_Check" title="PyIndex_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyIndex_Check()</span></code></a> is now always declared as an opaque function to hide
  1397. implementation details: removed the <code class="docutils literal notranslate"><span class="pre">PyIndex_Check()</span></code> macro. The macro accessed
  1398. directly the <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_as_number" title="PyTypeObject.tp_as_number"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_as_number</span></code></a> member.</p></li>
  1399. </ul>
  1400. <p>(See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40170">bpo-40170</a> for more details.)</p>
  1401. </li>
  1402. </ul>
  1403. </section>
  1404. <section id="id3">
  1405. <h3>Removed<a class="headerlink" href="#id3" title="Link to this heading">¶</a></h3>
  1406. <ul>
  1407. <li><p>Excluded <code class="docutils literal notranslate"><span class="pre">PyFPE_START_PROTECT()</span></code> and <code class="docutils literal notranslate"><span class="pre">PyFPE_END_PROTECT()</span></code> macros of
  1408. <code class="docutils literal notranslate"><span class="pre">pyfpe.h</span></code> from the limited C API.
  1409. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38835">bpo-38835</a>.)</p></li>
  1410. <li><p>The <code class="docutils literal notranslate"><span class="pre">tp_print</span></code> slot of <a class="reference internal" href="../c-api/typeobj.html#type-structs"><span class="std std-ref">PyTypeObject</span></a> has been removed.
  1411. It was used for printing objects to files in Python 2.7 and before. Since
  1412. Python 3.0, it has been ignored and unused.
  1413. (Contributed by Jeroen Demeyer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36974">bpo-36974</a>.)</p></li>
  1414. <li><p>Changes in the limited C API (if <code class="docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code> macro is defined):</p>
  1415. <ul class="simple">
  1416. <li><p>Excluded the following functions from the limited C API:</p>
  1417. <ul>
  1418. <li><p><code class="docutils literal notranslate"><span class="pre">PyThreadState_DeleteCurrent()</span></code>
  1419. (Contributed by Joannah Nanjekye in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37878">bpo-37878</a>.)</p></li>
  1420. <li><p><code class="docutils literal notranslate"><span class="pre">_Py_CheckRecursionLimit</span></code></p></li>
  1421. <li><p><code class="docutils literal notranslate"><span class="pre">_Py_NewReference()</span></code></p></li>
  1422. <li><p><code class="docutils literal notranslate"><span class="pre">_Py_ForgetReference()</span></code></p></li>
  1423. <li><p><code class="docutils literal notranslate"><span class="pre">_PyTraceMalloc_NewReference()</span></code></p></li>
  1424. <li><p><code class="docutils literal notranslate"><span class="pre">_Py_GetRefTotal()</span></code></p></li>
  1425. <li><p>The trashcan mechanism which never worked in the limited C API.</p></li>
  1426. <li><p><code class="docutils literal notranslate"><span class="pre">PyTrash_UNWIND_LEVEL</span></code></p></li>
  1427. <li><p><code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_BEGIN_CONDITION</span></code></p></li>
  1428. <li><p><code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_BEGIN</span></code></p></li>
  1429. <li><p><code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_END</span></code></p></li>
  1430. <li><p><code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_SAFE_BEGIN</span></code></p></li>
  1431. <li><p><code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_SAFE_END</span></code></p></li>
  1432. </ul>
  1433. </li>
  1434. <li><p>Moved following functions and definitions to the internal C API:</p>
  1435. <ul>
  1436. <li><p><code class="docutils literal notranslate"><span class="pre">_PyDebug_PrintTotalRefs()</span></code></p></li>
  1437. <li><p><code class="docutils literal notranslate"><span class="pre">_Py_PrintReferences()</span></code></p></li>
  1438. <li><p><code class="docutils literal notranslate"><span class="pre">_Py_PrintReferenceAddresses()</span></code></p></li>
  1439. <li><p><code class="docutils literal notranslate"><span class="pre">_Py_tracemalloc_config</span></code></p></li>
  1440. <li><p><code class="docutils literal notranslate"><span class="pre">_Py_AddToAllObjects()</span></code> (specific to <code class="docutils literal notranslate"><span class="pre">Py_TRACE_REFS</span></code> build)</p></li>
  1441. </ul>
  1442. </li>
  1443. </ul>
  1444. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38644">bpo-38644</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39542">bpo-39542</a>.)</p>
  1445. </li>
  1446. <li><p>Removed <code class="docutils literal notranslate"><span class="pre">_PyRuntime.getframe</span></code> hook and removed <code class="docutils literal notranslate"><span class="pre">_PyThreadState_GetFrame</span></code>
  1447. macro which was an alias to <code class="docutils literal notranslate"><span class="pre">_PyRuntime.getframe</span></code>. They were only exposed
  1448. by the internal C API. Removed also <code class="docutils literal notranslate"><span class="pre">PyThreadFrameGetter</span></code> type.
  1449. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39946">bpo-39946</a>.)</p></li>
  1450. <li><p>Removed the following functions from the C API. Call <a class="reference internal" href="../c-api/gcsupport.html#c.PyGC_Collect" title="PyGC_Collect"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyGC_Collect()</span></code></a>
  1451. explicitly to clear all free lists.
  1452. (Contributed by Inada Naoki and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37340">bpo-37340</a>,
  1453. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38896">bpo-38896</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40428">bpo-40428</a>.)</p>
  1454. <ul class="simple">
  1455. <li><p><code class="docutils literal notranslate"><span class="pre">PyAsyncGen_ClearFreeLists()</span></code></p></li>
  1456. <li><p><code class="docutils literal notranslate"><span class="pre">PyContext_ClearFreeList()</span></code></p></li>
  1457. <li><p><code class="docutils literal notranslate"><span class="pre">PyDict_ClearFreeList()</span></code></p></li>
  1458. <li><p><code class="docutils literal notranslate"><span class="pre">PyFloat_ClearFreeList()</span></code></p></li>
  1459. <li><p><code class="docutils literal notranslate"><span class="pre">PyFrame_ClearFreeList()</span></code></p></li>
  1460. <li><p><code class="docutils literal notranslate"><span class="pre">PyList_ClearFreeList()</span></code></p></li>
  1461. <li><p><code class="docutils literal notranslate"><span class="pre">PyMethod_ClearFreeList()</span></code> and <code class="docutils literal notranslate"><span class="pre">PyCFunction_ClearFreeList()</span></code>:
  1462. the free lists of bound method objects have been removed.</p></li>
  1463. <li><p><code class="docutils literal notranslate"><span class="pre">PySet_ClearFreeList()</span></code>: the set free list has been removed
  1464. in Python 3.4.</p></li>
  1465. <li><p><code class="docutils literal notranslate"><span class="pre">PyTuple_ClearFreeList()</span></code></p></li>
  1466. <li><p><code class="docutils literal notranslate"><span class="pre">PyUnicode_ClearFreeList()</span></code>: the Unicode free list has been removed in
  1467. Python 3.3.</p></li>
  1468. </ul>
  1469. </li>
  1470. <li><p>Removed <code class="docutils literal notranslate"><span class="pre">_PyUnicode_ClearStaticStrings()</span></code> function.
  1471. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39465">bpo-39465</a>.)</p></li>
  1472. <li><p>Removed <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_MATCH</span></code>. It has been deprecated by <span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a>, and
  1473. broken since Python 3.3. The <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Tailmatch" title="PyUnicode_Tailmatch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Tailmatch()</span></code></a> function can be
  1474. used instead.
  1475. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36346">bpo-36346</a>.)</p></li>
  1476. <li><p>Cleaned header files of interfaces defined but with no implementation.
  1477. The public API symbols being removed are:
  1478. <code class="docutils literal notranslate"><span class="pre">_PyBytes_InsertThousandsGroupingLocale</span></code>,
  1479. <code class="docutils literal notranslate"><span class="pre">_PyBytes_InsertThousandsGrouping</span></code>, <code class="docutils literal notranslate"><span class="pre">_Py_InitializeFromArgs</span></code>,
  1480. <code class="docutils literal notranslate"><span class="pre">_Py_InitializeFromWideArgs</span></code>, <code class="docutils literal notranslate"><span class="pre">_PyFloat_Repr</span></code>, <code class="docutils literal notranslate"><span class="pre">_PyFloat_Digits</span></code>,
  1481. <code class="docutils literal notranslate"><span class="pre">_PyFloat_DigitsInit</span></code>, <code class="docutils literal notranslate"><span class="pre">PyFrame_ExtendStack</span></code>, <code class="docutils literal notranslate"><span class="pre">_PyAIterWrapper_Type</span></code>,
  1482. <code class="docutils literal notranslate"><span class="pre">PyNullImporter_Type</span></code>, <code class="docutils literal notranslate"><span class="pre">PyCmpWrapper_Type</span></code>, <code class="docutils literal notranslate"><span class="pre">PySortWrapper_Type</span></code>,
  1483. <code class="docutils literal notranslate"><span class="pre">PyNoArgsFunction</span></code>.
  1484. (Contributed by Pablo Galindo Salgado in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39372">bpo-39372</a>.)</p></li>
  1485. </ul>
  1486. </section>
  1487. </section>
  1488. <section id="notable-changes-in-python-3-9-1">
  1489. <h2>Notable changes in Python 3.9.1<a class="headerlink" href="#notable-changes-in-python-3-9-1" title="Link to this heading">¶</a></h2>
  1490. <section id="id4">
  1491. <h3>typing<a class="headerlink" href="#id4" title="Link to this heading">¶</a></h3>
  1492. <p>The behavior of <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> was changed to conform with <span class="target" id="index-27"></span><a class="pep reference external" href="https://peps.python.org/pep-0586/"><strong>PEP 586</strong></a>
  1493. and to match the behavior of static type checkers specified in the PEP.</p>
  1494. <ol class="arabic">
  1495. <li><p><code class="docutils literal notranslate"><span class="pre">Literal</span></code> now de-duplicates parameters.</p></li>
  1496. <li><p>Equality comparisons between <code class="docutils literal notranslate"><span class="pre">Literal</span></code> objects are now order independent.</p></li>
  1497. <li><p><code class="docutils literal notranslate"><span class="pre">Literal</span></code> comparisons now respect types. For example,
  1498. <code class="docutils literal notranslate"><span class="pre">Literal[0]</span> <span class="pre">==</span> <span class="pre">Literal[False]</span></code> previously evaluated to <code class="docutils literal notranslate"><span class="pre">True</span></code>. It is
  1499. now <code class="docutils literal notranslate"><span class="pre">False</span></code>. To support this change, the internally used type cache now
  1500. supports differentiating types.</p></li>
  1501. <li><p><code class="docutils literal notranslate"><span class="pre">Literal</span></code> objects will now raise 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> exception during
  1502. equality comparisons if any of their parameters are not <a class="reference internal" href="../glossary.html#term-hashable"><span class="xref std std-term">hashable</span></a>.
  1503. Note that declaring <code class="docutils literal notranslate"><span class="pre">Literal</span></code> with mutable parameters will not throw
  1504. an error:</p>
  1505. <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">typing</span> <span class="kn">import</span> <span class="n">Literal</span>
  1506. <span class="gp">&gt;&gt;&gt; </span><span class="n">Literal</span><span class="p">[{</span><span class="mi">0</span><span class="p">}]</span>
  1507. <span class="gp">&gt;&gt;&gt; </span><span class="n">Literal</span><span class="p">[{</span><span class="mi">0</span><span class="p">}]</span> <span class="o">==</span> <span class="n">Literal</span><span class="p">[{</span><span class="kc">False</span><span class="p">}]</span>
  1508. <span class="gt">Traceback (most recent call last):</span>
  1509. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  1510. <span class="gr">TypeError</span>: <span class="n">unhashable type: &#39;set&#39;</span>
  1511. </pre></div>
  1512. </div>
  1513. </li>
  1514. </ol>
  1515. <p>(Contributed by Yurii Karabas in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42345">bpo-42345</a>.)</p>
  1516. </section>
  1517. <section id="macos-11-0-big-sur-and-apple-silicon-mac-support">
  1518. <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>
  1519. <p>As of 3.9.1, Python now fully supports building and running on macOS 11.0
  1520. (Big Sur) and on Apple Silicon Macs (based on the <code class="docutils literal notranslate"><span class="pre">ARM64</span></code> architecture).
  1521. A new universal build variant, <code class="docutils literal notranslate"><span class="pre">universal2</span></code>, is now available to natively
  1522. 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. Binaries
  1523. can also now be built on current versions of macOS to be deployed on a range
  1524. of older macOS versions (tested to 10.9) while making some newer OS
  1525. functions and options conditionally available based on the operating system
  1526. version in use at runtime (“weaklinking”).</p>
  1527. <p>(Contributed by Ronald Oussoren and Lawrence D’Anna in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41100">bpo-41100</a>.)</p>
  1528. </section>
  1529. </section>
  1530. <section id="notable-changes-in-python-3-9-2">
  1531. <h2>Notable changes in Python 3.9.2<a class="headerlink" href="#notable-changes-in-python-3-9-2" title="Link to this heading">¶</a></h2>
  1532. <section id="collections-abc">
  1533. <h3>collections.abc<a class="headerlink" href="#collections-abc" title="Link to this heading">¶</a></h3>
  1534. <p><a class="reference internal" href="../library/collections.abc.html#collections.abc.Callable" title="collections.abc.Callable"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Callable</span></code></a> generic now flattens type parameters, similar
  1535. to what <a class="reference internal" href="../library/typing.html#typing.Callable" title="typing.Callable"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.Callable</span></code></a> currently does. This means that
  1536. <code class="docutils literal notranslate"><span class="pre">collections.abc.Callable[[int,</span> <span class="pre">str],</span> <span class="pre">str]</span></code> will have <code class="docutils literal notranslate"><span class="pre">__args__</span></code> of
  1537. <code class="docutils literal notranslate"><span class="pre">(int,</span> <span class="pre">str,</span> <span class="pre">str)</span></code>; previously this was <code class="docutils literal notranslate"><span class="pre">([int,</span> <span class="pre">str],</span> <span class="pre">str)</span></code>. To allow this
  1538. change, <a class="reference internal" href="../library/types.html#types.GenericAlias" title="types.GenericAlias"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.GenericAlias</span></code></a> can now be subclassed, and a subclass will
  1539. be returned when subscripting the <a class="reference internal" href="../library/collections.abc.html#collections.abc.Callable" title="collections.abc.Callable"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Callable</span></code></a> type.
  1540. Code which accesses the arguments via <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> or <code class="docutils literal notranslate"><span class="pre">__args__</span></code>
  1541. need to account for this change. 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> may be emitted for
  1542. invalid forms of parameterizing <a class="reference internal" href="../library/collections.abc.html#collections.abc.Callable" title="collections.abc.Callable"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Callable</span></code></a> which may have
  1543. passed silently in Python 3.9.1. This <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> will
  1544. become 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> in Python 3.10.
  1545. (Contributed by Ken Jin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42195">bpo-42195</a>.)</p>
  1546. </section>
  1547. <section id="urllib-parse">
  1548. <h3>urllib.parse<a class="headerlink" href="#urllib-parse" title="Link to this heading">¶</a></h3>
  1549. <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
  1550. 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
  1551. <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
  1552. newer W3C recommendations, this has been changed to allow only a single
  1553. separator key, with <code class="docutils literal notranslate"><span class="pre">&amp;</span></code> as the default. This change also affects
  1554. <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
  1555. functions internally. For more details, please see their respective
  1556. documentation.
  1557. (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>
  1558. </section>
  1559. </section>
  1560. <section id="notable-changes-in-python-3-9-3">
  1561. <h2>Notable changes in Python 3.9.3<a class="headerlink" href="#notable-changes-in-python-3-9-3" title="Link to this heading">¶</a></h2>
  1562. <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
  1563. IPv4 address sent from the remote server when setting up a passive data
  1564. channel. We reuse the ftp server IP address instead. For unusual code
  1565. requiring the old behavior, set a <code class="docutils literal notranslate"><span class="pre">trust_server_pasv_ipv4_address</span></code>
  1566. 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>
  1567. </section>
  1568. <section id="notable-changes-in-python-3-9-5">
  1569. <h2>Notable changes in Python 3.9.5<a class="headerlink" href="#notable-changes-in-python-3-9-5" title="Link to this heading">¶</a></h2>
  1570. <section id="id5">
  1571. <h3>urllib.parse<a class="headerlink" href="#id5" title="Link to this heading">¶</a></h3>
  1572. <p>The presence of newline or tab characters in parts of a URL allows for some
  1573. forms of attacks. Following the WHATWG specification that updates <span class="target" id="index-28"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc3986.html"><strong>RFC 3986</strong></a>,
  1574. 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
  1575. 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
  1576. characters are controlled by a new module level variable
  1577. <code class="docutils literal notranslate"><span class="pre">urllib.parse._UNSAFE_URL_BYTES_TO_REMOVE</span></code>. (See <a class="reference external" href="https://github.com/python/cpython/issues/88048">gh-88048</a>)</p>
  1578. </section>
  1579. </section>
  1580. <section id="notable-security-feature-in-3-9-14">
  1581. <h2>Notable security feature in 3.9.14<a class="headerlink" href="#notable-security-feature-in-3-9-14" title="Link to this heading">¶</a></h2>
  1582. <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
  1583. (binary), 4, 8 (octal), 16 (hexadecimal), or 32 such as base 10 (decimal)
  1584. 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
  1585. above a limit to avoid potential denial of service attacks due to the
  1586. 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>.
  1587. This limit can be configured or disabled by environment variable, command
  1588. 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
  1589. length limitation</span></a> documentation. The default limit
  1590. is 4300 digits in string form.</p>
  1591. </section>
  1592. <section id="notable-changes-in-3-9-17">
  1593. <h2>Notable changes in 3.9.17<a class="headerlink" href="#notable-changes-in-3-9-17" title="Link to this heading">¶</a></h2>
  1594. <section id="tarfile">
  1595. <h3>tarfile<a class="headerlink" href="#tarfile" title="Link to this heading">¶</a></h3>
  1596. <ul class="simple">
  1597. <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>,
  1598. have a new a <em>filter</em> argument that allows limiting tar features than may be
  1599. surprising or dangerous, such as creating files outside the destination
  1600. directory.
  1601. See <a class="reference internal" href="../library/tarfile.html#tarfile-extraction-filter"><span class="std std-ref">Extraction filters</span></a> for details.
  1602. In Python 3.12, use without the <em>filter</em> argument will show a
  1603. <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>.
  1604. In Python 3.14, the default will switch to <code class="docutils literal notranslate"><span class="pre">'data'</span></code>.
  1605. (Contributed by Petr Viktorin in <span class="target" id="index-29"></span><a class="pep reference external" href="https://peps.python.org/pep-0706/"><strong>PEP 706</strong></a>.)</p></li>
  1606. </ul>
  1607. </section>
  1608. </section>
  1609. </section>
  1610. <div class="clearer"></div>
  1611. </div>
  1612. </div>
  1613. </div>
  1614. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  1615. <div class="sphinxsidebarwrapper">
  1616. <div>
  1617. <h3><a href="../contents.html">Table of Contents</a></h3>
  1618. <ul>
  1619. <li><a class="reference internal" href="#">What’s New In Python 3.9</a><ul>
  1620. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  1621. <li><a class="reference internal" href="#you-should-check-for-deprecationwarning-in-your-code">You should check for DeprecationWarning in your code</a></li>
  1622. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  1623. <li><a class="reference internal" href="#dictionary-merge-update-operators">Dictionary Merge &amp; Update Operators</a></li>
  1624. <li><a class="reference internal" href="#new-string-methods-to-remove-prefixes-and-suffixes">New String Methods to Remove Prefixes and Suffixes</a></li>
  1625. <li><a class="reference internal" href="#type-hinting-generics-in-standard-collections">Type Hinting Generics in Standard Collections</a></li>
  1626. <li><a class="reference internal" href="#new-parser">New Parser</a></li>
  1627. </ul>
  1628. </li>
  1629. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  1630. <li><a class="reference internal" href="#new-modules">New Modules</a><ul>
  1631. <li><a class="reference internal" href="#zoneinfo">zoneinfo</a></li>
  1632. <li><a class="reference internal" href="#graphlib">graphlib</a></li>
  1633. </ul>
  1634. </li>
  1635. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  1636. <li><a class="reference internal" href="#ast">ast</a></li>
  1637. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  1638. <li><a class="reference internal" href="#compileall">compileall</a></li>
  1639. <li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li>
  1640. <li><a class="reference internal" href="#curses">curses</a></li>
  1641. <li><a class="reference internal" href="#datetime">datetime</a></li>
  1642. <li><a class="reference internal" href="#distutils">distutils</a></li>
  1643. <li><a class="reference internal" href="#fcntl">fcntl</a></li>
  1644. <li><a class="reference internal" href="#ftplib">ftplib</a></li>
  1645. <li><a class="reference internal" href="#gc">gc</a></li>
  1646. <li><a class="reference internal" href="#hashlib">hashlib</a></li>
  1647. <li><a class="reference internal" href="#http">http</a></li>
  1648. <li><a class="reference internal" href="#idle-and-idlelib">IDLE and idlelib</a></li>
  1649. <li><a class="reference internal" href="#imaplib">imaplib</a></li>
  1650. <li><a class="reference internal" href="#importlib">importlib</a></li>
  1651. <li><a class="reference internal" href="#inspect">inspect</a></li>
  1652. <li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
  1653. <li><a class="reference internal" href="#math">math</a></li>
  1654. <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
  1655. <li><a class="reference internal" href="#nntplib">nntplib</a></li>
  1656. <li><a class="reference internal" href="#os">os</a></li>
  1657. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  1658. <li><a class="reference internal" href="#pdb">pdb</a></li>
  1659. <li><a class="reference internal" href="#poplib">poplib</a></li>
  1660. <li><a class="reference internal" href="#pprint">pprint</a></li>
  1661. <li><a class="reference internal" href="#pydoc">pydoc</a></li>
  1662. <li><a class="reference internal" href="#random">random</a></li>
  1663. <li><a class="reference internal" href="#signal">signal</a></li>
  1664. <li><a class="reference internal" href="#smtplib">smtplib</a></li>
  1665. <li><a class="reference internal" href="#socket">socket</a></li>
  1666. <li><a class="reference internal" href="#time">time</a></li>
  1667. <li><a class="reference internal" href="#sys">sys</a></li>
  1668. <li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
  1669. <li><a class="reference internal" href="#typing">typing</a></li>
  1670. <li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
  1671. <li><a class="reference internal" href="#venv">venv</a></li>
  1672. <li><a class="reference internal" href="#xml">xml</a></li>
  1673. </ul>
  1674. </li>
  1675. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  1676. <li><a class="reference internal" href="#deprecated">Deprecated</a></li>
  1677. <li><a class="reference internal" href="#removed">Removed</a></li>
  1678. <li><a class="reference internal" href="#porting-to-python-3-9">Porting to Python 3.9</a><ul>
  1679. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  1680. <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
  1681. <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
  1682. </ul>
  1683. </li>
  1684. <li><a class="reference internal" href="#build-changes">Build Changes</a></li>
  1685. <li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
  1686. <li><a class="reference internal" href="#id1">New Features</a></li>
  1687. <li><a class="reference internal" href="#id2">Porting to Python 3.9</a></li>
  1688. <li><a class="reference internal" href="#id3">Removed</a></li>
  1689. </ul>
  1690. </li>
  1691. <li><a class="reference internal" href="#notable-changes-in-python-3-9-1">Notable changes in Python 3.9.1</a><ul>
  1692. <li><a class="reference internal" href="#id4">typing</a></li>
  1693. <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>
  1694. </ul>
  1695. </li>
  1696. <li><a class="reference internal" href="#notable-changes-in-python-3-9-2">Notable changes in Python 3.9.2</a><ul>
  1697. <li><a class="reference internal" href="#collections-abc">collections.abc</a></li>
  1698. <li><a class="reference internal" href="#urllib-parse">urllib.parse</a></li>
  1699. </ul>
  1700. </li>
  1701. <li><a class="reference internal" href="#notable-changes-in-python-3-9-3">Notable changes in Python 3.9.3</a></li>
  1702. <li><a class="reference internal" href="#notable-changes-in-python-3-9-5">Notable changes in Python 3.9.5</a><ul>
  1703. <li><a class="reference internal" href="#id5">urllib.parse</a></li>
  1704. </ul>
  1705. </li>
  1706. <li><a class="reference internal" href="#notable-security-feature-in-3-9-14">Notable security feature in 3.9.14</a></li>
  1707. <li><a class="reference internal" href="#notable-changes-in-3-9-17">Notable changes in 3.9.17</a><ul>
  1708. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  1709. </ul>
  1710. </li>
  1711. </ul>
  1712. </li>
  1713. </ul>
  1714. </div>
  1715. <div>
  1716. <h4>Previous topic</h4>
  1717. <p class="topless"><a href="3.10.html"
  1718. title="previous chapter">What’s New In Python 3.10</a></p>
  1719. </div>
  1720. <div>
  1721. <h4>Next topic</h4>
  1722. <p class="topless"><a href="3.8.html"
  1723. title="next chapter">What’s New In Python 3.8</a></p>
  1724. </div>
  1725. <div role="note" aria-label="source link">
  1726. <h3>This Page</h3>
  1727. <ul class="this-page-menu">
  1728. <li><a href="../bugs.html">Report a Bug</a></li>
  1729. <li>
  1730. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.9.rst"
  1731. rel="nofollow">Show Source
  1732. </a>
  1733. </li>
  1734. </ul>
  1735. </div>
  1736. </div>
  1737. <div id="sidebarbutton" title="Collapse sidebar">
  1738. <span>«</span>
  1739. </div>
  1740. </div>
  1741. <div class="clearer"></div>
  1742. </div>
  1743. <div class="related" role="navigation" aria-label="related navigation">
  1744. <h3>Navigation</h3>
  1745. <ul>
  1746. <li class="right" style="margin-right: 10px">
  1747. <a href="../genindex.html" title="General Index"
  1748. >index</a></li>
  1749. <li class="right" >
  1750. <a href="../py-modindex.html" title="Python Module Index"
  1751. >modules</a> |</li>
  1752. <li class="right" >
  1753. <a href="3.8.html" title="What’s New In Python 3.8"
  1754. >next</a> |</li>
  1755. <li class="right" >
  1756. <a href="3.10.html" title="What’s New In Python 3.10"
  1757. >previous</a> |</li>
  1758. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  1759. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  1760. <li class="switchers">
  1761. <div class="language_switcher_placeholder"></div>
  1762. <div class="version_switcher_placeholder"></div>
  1763. </li>
  1764. <li>
  1765. </li>
  1766. <li id="cpython-language-and-version">
  1767. <a href="../index.html">3.12.3 Documentation</a> &#187;
  1768. </li>
  1769. <li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> &#187;</li>
  1770. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.9</a></li>
  1771. <li class="right">
  1772. <div class="inline-search" role="search">
  1773. <form class="inline-search" action="../search.html" method="get">
  1774. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  1775. <input type="submit" value="Go" />
  1776. </form>
  1777. </div>
  1778. |
  1779. </li>
  1780. <li class="right">
  1781. <label class="theme-selector-label">
  1782. Theme
  1783. <select class="theme-selector" oninput="activateTheme(this.value)">
  1784. <option value="auto" selected>Auto</option>
  1785. <option value="light">Light</option>
  1786. <option value="dark">Dark</option>
  1787. </select>
  1788. </label> |</li>
  1789. </ul>
  1790. </div>
  1791. <div class="footer">
  1792. &copy;
  1793. <a href="../copyright.html">
  1794. Copyright
  1795. </a>
  1796. 2001-2024, Python Software Foundation.
  1797. <br />
  1798. This page is licensed under the Python Software Foundation License Version 2.
  1799. <br />
  1800. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  1801. <br />
  1802. See <a href="/license.html">History and License</a> for more information.<br />
  1803. <br />
  1804. The Python Software Foundation is a non-profit corporation.
  1805. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  1806. <br />
  1807. <br />
  1808. Last updated on Apr 09, 2024 (13:47 UTC).
  1809. <a href="/bugs.html">Found a bug</a>?
  1810. <br />
  1811. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  1812. </div>
  1813. </body>
  1814. </html>
上海开阖软件有限公司 沪ICP备12045867号-1