gooderp18绿色标准版
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

2579 lines
305KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="What’s New In Python 3.10" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/whatsnew/3.10.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Editor, Pablo Galindo Salgado,. This article explains the new features in Python 3.10, compared to 3.9. Python 3.10 was released on October 4, 2021. For full details, see the changelog. Summary – R..." />
  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, Pablo Galindo Salgado,. This article explains the new features in Python 3.10, compared to 3.9. Python 3.10 was released on October 4, 2021. For full details, see the changelog. Summary – R..." />
  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.10 &#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.9" href="3.9.html" />
  33. <link rel="prev" title="What’s New In Python 3.11" href="3.11.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/whatsnew/3.10.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.10</a><ul>
  86. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  87. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  88. <li><a class="reference internal" href="#parenthesized-context-managers">Parenthesized context managers</a></li>
  89. <li><a class="reference internal" href="#better-error-messages">Better error messages</a><ul>
  90. <li><a class="reference internal" href="#syntaxerrors">SyntaxErrors</a></li>
  91. <li><a class="reference internal" href="#indentationerrors">IndentationErrors</a></li>
  92. <li><a class="reference internal" href="#attributeerrors">AttributeErrors</a></li>
  93. <li><a class="reference internal" href="#nameerrors">NameErrors</a></li>
  94. </ul>
  95. </li>
  96. <li><a class="reference internal" href="#pep-626-precise-line-numbers-for-debugging-and-other-tools">PEP 626: Precise line numbers for debugging and other tools</a></li>
  97. <li><a class="reference internal" href="#pep-634-structural-pattern-matching">PEP 634: Structural Pattern Matching</a><ul>
  98. <li><a class="reference internal" href="#syntax-and-operations">Syntax and operations</a></li>
  99. <li><a class="reference internal" href="#declarative-approach">Declarative approach</a></li>
  100. <li><a class="reference internal" href="#simple-pattern-match-to-a-literal">Simple pattern: match to a literal</a><ul>
  101. <li><a class="reference internal" href="#behavior-without-the-wildcard">Behavior without the wildcard</a></li>
  102. </ul>
  103. </li>
  104. <li><a class="reference internal" href="#patterns-with-a-literal-and-variable">Patterns with a literal and variable</a></li>
  105. <li><a class="reference internal" href="#patterns-and-classes">Patterns and classes</a><ul>
  106. <li><a class="reference internal" href="#patterns-with-positional-parameters">Patterns with positional parameters</a></li>
  107. </ul>
  108. </li>
  109. <li><a class="reference internal" href="#nested-patterns">Nested patterns</a></li>
  110. <li><a class="reference internal" href="#complex-patterns-and-the-wildcard">Complex patterns and the wildcard</a></li>
  111. <li><a class="reference internal" href="#guard">Guard</a></li>
  112. <li><a class="reference internal" href="#other-key-features">Other Key Features</a></li>
  113. </ul>
  114. </li>
  115. <li><a class="reference internal" href="#optional-encodingwarning-and-encoding-locale-option">Optional <code class="docutils literal notranslate"><span class="pre">EncodingWarning</span></code> and <code class="docutils literal notranslate"><span class="pre">encoding=&quot;locale&quot;</span></code> option</a></li>
  116. </ul>
  117. </li>
  118. <li><a class="reference internal" href="#new-features-related-to-type-hints">New Features Related to Type Hints</a><ul>
  119. <li><a class="reference internal" href="#pep-604-new-type-union-operator">PEP 604: New Type Union Operator</a></li>
  120. <li><a class="reference internal" href="#pep-612-parameter-specification-variables">PEP 612: Parameter Specification Variables</a></li>
  121. <li><a class="reference internal" href="#pep-613-typealias">PEP 613: TypeAlias</a></li>
  122. <li><a class="reference internal" href="#pep-647-user-defined-type-guards">PEP 647: User-Defined Type Guards</a></li>
  123. </ul>
  124. </li>
  125. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  126. <li><a class="reference internal" href="#new-modules">New Modules</a></li>
  127. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  128. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  129. <li><a class="reference internal" href="#argparse">argparse</a></li>
  130. <li><a class="reference internal" href="#array">array</a></li>
  131. <li><a class="reference internal" href="#asynchat-asyncore-smtpd">asynchat, asyncore, smtpd</a></li>
  132. <li><a class="reference internal" href="#base64">base64</a></li>
  133. <li><a class="reference internal" href="#bdb">bdb</a></li>
  134. <li><a class="reference internal" href="#bisect">bisect</a></li>
  135. <li><a class="reference internal" href="#codecs">codecs</a></li>
  136. <li><a class="reference internal" href="#collections-abc">collections.abc</a></li>
  137. <li><a class="reference internal" href="#contextlib">contextlib</a></li>
  138. <li><a class="reference internal" href="#curses">curses</a></li>
  139. <li><a class="reference internal" href="#dataclasses">dataclasses</a><ul>
  140. <li><a class="reference internal" href="#slots">__slots__</a></li>
  141. <li><a class="reference internal" href="#keyword-only-fields">Keyword-only fields</a></li>
  142. </ul>
  143. </li>
  144. <li><a class="reference internal" href="#distutils">distutils</a></li>
  145. <li><a class="reference internal" href="#doctest">doctest</a></li>
  146. <li><a class="reference internal" href="#encodings">encodings</a></li>
  147. <li><a class="reference internal" href="#enum">enum</a></li>
  148. <li><a class="reference internal" href="#fileinput">fileinput</a></li>
  149. <li><a class="reference internal" href="#faulthandler">faulthandler</a></li>
  150. <li><a class="reference internal" href="#gc">gc</a></li>
  151. <li><a class="reference internal" href="#glob">glob</a></li>
  152. <li><a class="reference internal" href="#hashlib">hashlib</a></li>
  153. <li><a class="reference internal" href="#hmac">hmac</a></li>
  154. <li><a class="reference internal" href="#idle-and-idlelib">IDLE and idlelib</a></li>
  155. <li><a class="reference internal" href="#importlib-metadata">importlib.metadata</a></li>
  156. <li><a class="reference internal" href="#inspect">inspect</a></li>
  157. <li><a class="reference internal" href="#itertools">itertools</a></li>
  158. <li><a class="reference internal" href="#linecache">linecache</a></li>
  159. <li><a class="reference internal" href="#os">os</a></li>
  160. <li><a class="reference internal" href="#os-path">os.path</a></li>
  161. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  162. <li><a class="reference internal" href="#platform">platform</a></li>
  163. <li><a class="reference internal" href="#pprint">pprint</a></li>
  164. <li><a class="reference internal" href="#py-compile">py_compile</a></li>
  165. <li><a class="reference internal" href="#pyclbr">pyclbr</a></li>
  166. <li><a class="reference internal" href="#shelve">shelve</a></li>
  167. <li><a class="reference internal" href="#statistics">statistics</a></li>
  168. <li><a class="reference internal" href="#site">site</a></li>
  169. <li><a class="reference internal" href="#socket">socket</a></li>
  170. <li><a class="reference internal" href="#ssl">ssl</a></li>
  171. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  172. <li><a class="reference internal" href="#sys">sys</a></li>
  173. <li><a class="reference internal" href="#thread">_thread</a></li>
  174. <li><a class="reference internal" href="#threading">threading</a></li>
  175. <li><a class="reference internal" href="#traceback">traceback</a></li>
  176. <li><a class="reference internal" href="#types">types</a></li>
  177. <li><a class="reference internal" href="#typing">typing</a></li>
  178. <li><a class="reference internal" href="#unittest">unittest</a></li>
  179. <li><a class="reference internal" href="#urllib-parse">urllib.parse</a></li>
  180. <li><a class="reference internal" href="#xml">xml</a></li>
  181. <li><a class="reference internal" href="#zipimport">zipimport</a></li>
  182. </ul>
  183. </li>
  184. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  185. <li><a class="reference internal" href="#deprecated">Deprecated</a></li>
  186. <li><a class="reference internal" href="#removed">Removed</a></li>
  187. <li><a class="reference internal" href="#porting-to-python-3-10">Porting to Python 3.10</a><ul>
  188. <li><a class="reference internal" href="#changes-in-the-python-syntax">Changes in the Python syntax</a></li>
  189. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  190. <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
  191. </ul>
  192. </li>
  193. <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
  194. <li><a class="reference internal" href="#build-changes">Build Changes</a></li>
  195. <li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
  196. <li><a class="reference internal" href="#pep-652-maintaining-the-stable-abi">PEP 652: Maintaining the Stable ABI</a></li>
  197. <li><a class="reference internal" href="#id1">New Features</a></li>
  198. <li><a class="reference internal" href="#id2">Porting to Python 3.10</a></li>
  199. <li><a class="reference internal" href="#id3">Deprecated</a></li>
  200. <li><a class="reference internal" href="#id4">Removed</a></li>
  201. </ul>
  202. </li>
  203. <li><a class="reference internal" href="#notable-security-feature-in-3-10-7">Notable security feature in 3.10.7</a></li>
  204. <li><a class="reference internal" href="#notable-security-feature-in-3-10-8">Notable security feature in 3.10.8</a></li>
  205. <li><a class="reference internal" href="#notable-changes-in-3-10-12">Notable changes in 3.10.12</a><ul>
  206. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  207. </ul>
  208. </li>
  209. </ul>
  210. </li>
  211. </ul>
  212. </div>
  213. <div>
  214. <h4>Previous topic</h4>
  215. <p class="topless"><a href="3.11.html"
  216. title="previous chapter">What’s New In Python 3.11</a></p>
  217. </div>
  218. <div>
  219. <h4>Next topic</h4>
  220. <p class="topless"><a href="3.9.html"
  221. title="next chapter">What’s New In Python 3.9</a></p>
  222. </div>
  223. <div role="note" aria-label="source link">
  224. <h3>This Page</h3>
  225. <ul class="this-page-menu">
  226. <li><a href="../bugs.html">Report a Bug</a></li>
  227. <li>
  228. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.10.rst"
  229. rel="nofollow">Show Source
  230. </a>
  231. </li>
  232. </ul>
  233. </div>
  234. </nav>
  235. </div>
  236. </div>
  237. <div class="related" role="navigation" aria-label="related navigation">
  238. <h3>Navigation</h3>
  239. <ul>
  240. <li class="right" style="margin-right: 10px">
  241. <a href="../genindex.html" title="General Index"
  242. accesskey="I">index</a></li>
  243. <li class="right" >
  244. <a href="../py-modindex.html" title="Python Module Index"
  245. >modules</a> |</li>
  246. <li class="right" >
  247. <a href="3.9.html" title="What’s New In Python 3.9"
  248. accesskey="N">next</a> |</li>
  249. <li class="right" >
  250. <a href="3.11.html" title="What’s New In Python 3.11"
  251. accesskey="P">previous</a> |</li>
  252. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  253. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  254. <li class="switchers">
  255. <div class="language_switcher_placeholder"></div>
  256. <div class="version_switcher_placeholder"></div>
  257. </li>
  258. <li>
  259. </li>
  260. <li id="cpython-language-and-version">
  261. <a href="../index.html">3.12.3 Documentation</a> &#187;
  262. </li>
  263. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> &#187;</li>
  264. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.10</a></li>
  265. <li class="right">
  266. <div class="inline-search" role="search">
  267. <form class="inline-search" action="../search.html" method="get">
  268. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  269. <input type="submit" value="Go" />
  270. </form>
  271. </div>
  272. |
  273. </li>
  274. <li class="right">
  275. <label class="theme-selector-label">
  276. Theme
  277. <select class="theme-selector" oninput="activateTheme(this.value)">
  278. <option value="auto" selected>Auto</option>
  279. <option value="light">Light</option>
  280. <option value="dark">Dark</option>
  281. </select>
  282. </label> |</li>
  283. </ul>
  284. </div>
  285. <div class="document">
  286. <div class="documentwrapper">
  287. <div class="bodywrapper">
  288. <div class="body" role="main">
  289. <section id="what-s-new-in-python-3-10">
  290. <h1>What’s New In Python 3.10<a class="headerlink" href="#what-s-new-in-python-3-10" title="Link to this heading">¶</a></h1>
  291. <dl class="field-list simple">
  292. <dt class="field-odd">Editor<span class="colon">:</span></dt>
  293. <dd class="field-odd"><p>Pablo Galindo Salgado</p>
  294. </dd>
  295. </dl>
  296. <p>This article explains the new features in Python 3.10, compared to 3.9.
  297. Python 3.10 was released on October 4, 2021.
  298. For full details, see the <a class="reference internal" href="changelog.html#changelog"><span class="std std-ref">changelog</span></a>.</p>
  299. <section id="summary-release-highlights">
  300. <h2>Summary – Release highlights<a class="headerlink" href="#summary-release-highlights" title="Link to this heading">¶</a></h2>
  301. <p>New syntax features:</p>
  302. <ul class="simple">
  303. <li><p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0634/"><strong>PEP 634</strong></a>, Structural Pattern Matching: Specification</p></li>
  304. <li><p><span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0635/"><strong>PEP 635</strong></a>, Structural Pattern Matching: Motivation and Rationale</p></li>
  305. <li><p><span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0636/"><strong>PEP 636</strong></a>, Structural Pattern Matching: Tutorial</p></li>
  306. <li><p><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12782">bpo-12782</a>, Parenthesized context managers are now officially allowed.</p></li>
  307. </ul>
  308. <p>New features in the standard library:</p>
  309. <ul class="simple">
  310. <li><p><span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0618/"><strong>PEP 618</strong></a>, Add Optional Length-Checking To zip.</p></li>
  311. </ul>
  312. <p>Interpreter improvements:</p>
  313. <ul class="simple">
  314. <li><p><span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0626/"><strong>PEP 626</strong></a>, Precise line numbers for debugging and other tools.</p></li>
  315. </ul>
  316. <p>New typing features:</p>
  317. <ul class="simple">
  318. <li><p><span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0604/"><strong>PEP 604</strong></a>, Allow writing union types as X | Y</p></li>
  319. <li><p><span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0612/"><strong>PEP 612</strong></a>, Parameter Specification Variables</p></li>
  320. <li><p><span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0613/"><strong>PEP 613</strong></a>, Explicit Type Aliases</p></li>
  321. <li><p><span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0647/"><strong>PEP 647</strong></a>, User-Defined Type Guards</p></li>
  322. </ul>
  323. <p>Important deprecations, removals or restrictions:</p>
  324. <ul class="simple">
  325. <li><p><span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0644/"><strong>PEP 644</strong></a>, Require OpenSSL 1.1.1 or newer</p></li>
  326. <li><p><span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0632/"><strong>PEP 632</strong></a>, Deprecate distutils module.</p></li>
  327. <li><p><span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0623/"><strong>PEP 623</strong></a>, Deprecate and prepare for the removal of the wstr member in PyUnicodeObject.</p></li>
  328. <li><p><span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0624/"><strong>PEP 624</strong></a>, Remove Py_UNICODE encoder APIs</p></li>
  329. <li><p><span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0597/"><strong>PEP 597</strong></a>, Add optional EncodingWarning</p></li>
  330. </ul>
  331. </section>
  332. <section id="new-features">
  333. <h2>New Features<a class="headerlink" href="#new-features" title="Link to this heading">¶</a></h2>
  334. <section id="parenthesized-context-managers">
  335. <span id="whatsnew310-pep563"></span><h3>Parenthesized context managers<a class="headerlink" href="#parenthesized-context-managers" title="Link to this heading">¶</a></h3>
  336. <p>Using enclosing parentheses for continuation across multiple lines
  337. in context managers is now supported. This allows formatting a long
  338. collection of context managers in multiple lines in a similar way
  339. as it was previously possible with import statements. For instance,
  340. all these examples are now valid:</p>
  341. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="p">(</span><span class="n">CtxManager</span><span class="p">()</span> <span class="k">as</span> <span class="n">example</span><span class="p">):</span>
  342. <span class="o">...</span>
  343. <span class="k">with</span> <span class="p">(</span>
  344. <span class="n">CtxManager1</span><span class="p">(),</span>
  345. <span class="n">CtxManager2</span><span class="p">()</span>
  346. <span class="p">):</span>
  347. <span class="o">...</span>
  348. <span class="k">with</span> <span class="p">(</span><span class="n">CtxManager1</span><span class="p">()</span> <span class="k">as</span> <span class="n">example</span><span class="p">,</span>
  349. <span class="n">CtxManager2</span><span class="p">()):</span>
  350. <span class="o">...</span>
  351. <span class="k">with</span> <span class="p">(</span><span class="n">CtxManager1</span><span class="p">(),</span>
  352. <span class="n">CtxManager2</span><span class="p">()</span> <span class="k">as</span> <span class="n">example</span><span class="p">):</span>
  353. <span class="o">...</span>
  354. <span class="k">with</span> <span class="p">(</span>
  355. <span class="n">CtxManager1</span><span class="p">()</span> <span class="k">as</span> <span class="n">example1</span><span class="p">,</span>
  356. <span class="n">CtxManager2</span><span class="p">()</span> <span class="k">as</span> <span class="n">example2</span>
  357. <span class="p">):</span>
  358. <span class="o">...</span>
  359. </pre></div>
  360. </div>
  361. <p>it is also possible to use a trailing comma at the end of the
  362. enclosed group:</p>
  363. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="p">(</span>
  364. <span class="n">CtxManager1</span><span class="p">()</span> <span class="k">as</span> <span class="n">example1</span><span class="p">,</span>
  365. <span class="n">CtxManager2</span><span class="p">()</span> <span class="k">as</span> <span class="n">example2</span><span class="p">,</span>
  366. <span class="n">CtxManager3</span><span class="p">()</span> <span class="k">as</span> <span class="n">example3</span><span class="p">,</span>
  367. <span class="p">):</span>
  368. <span class="o">...</span>
  369. </pre></div>
  370. </div>
  371. <p>This new syntax uses the non LL(1) capacities of the new parser.
  372. Check <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.</p>
  373. <p>(Contributed by Guido van Rossum, Pablo Galindo and Lysandros Nikolaou
  374. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12782">bpo-12782</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40334">bpo-40334</a>.)</p>
  375. </section>
  376. <section id="better-error-messages">
  377. <h3>Better error messages<a class="headerlink" href="#better-error-messages" title="Link to this heading">¶</a></h3>
  378. <section id="syntaxerrors">
  379. <h4>SyntaxErrors<a class="headerlink" href="#syntaxerrors" title="Link to this heading">¶</a></h4>
  380. <p>When parsing code that contains unclosed parentheses or brackets the interpreter
  381. now includes the location of the unclosed bracket of parentheses instead of displaying
  382. <em>SyntaxError: unexpected EOF while parsing</em> or pointing to some incorrect location.
  383. For instance, consider the following code (notice the unclosed ‘{‘):</p>
  384. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">expected</span> <span class="o">=</span> <span class="p">{</span><span class="mi">9</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">18</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">19</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">27</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">28</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">29</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">36</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">37</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span>
  385. <span class="mi">38</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">39</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">45</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">46</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">47</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">48</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">49</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">54</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span>
  386. <span class="n">some_other_code</span> <span class="o">=</span> <span class="n">foo</span><span class="p">()</span>
  387. </pre></div>
  388. </div>
  389. <p>Previous versions of the interpreter reported confusing places as the location of
  390. the syntax error:</p>
  391. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">File</span> <span class="s2">&quot;example.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">3</span>
  392. <span class="n">some_other_code</span> <span class="o">=</span> <span class="n">foo</span><span class="p">()</span>
  393. <span class="o">^</span>
  394. <span class="ne">SyntaxError</span><span class="p">:</span> <span class="n">invalid</span> <span class="n">syntax</span>
  395. </pre></div>
  396. </div>
  397. <p>but in Python 3.10 a more informative error is emitted:</p>
  398. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">File</span> <span class="s2">&quot;example.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">1</span>
  399. <span class="n">expected</span> <span class="o">=</span> <span class="p">{</span><span class="mi">9</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">18</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">19</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">27</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">28</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">29</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">36</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">37</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span>
  400. <span class="o">^</span>
  401. <span class="ne">SyntaxError</span><span class="p">:</span> <span class="s1">&#39;{&#39;</span> <span class="n">was</span> <span class="n">never</span> <span class="n">closed</span>
  402. </pre></div>
  403. </div>
  404. <p>In a similar way, errors involving unclosed string literals (single and triple
  405. quoted) now point to the start of the string instead of reporting EOF/EOL.</p>
  406. <p>These improvements are inspired by previous work in the PyPy interpreter.</p>
  407. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42864">bpo-42864</a> and Batuhan Taskaya in
  408. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40176">bpo-40176</a>.)</p>
  409. <p><a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> exceptions raised by the interpreter will now highlight the
  410. full error range of the expression that constitutes the syntax error itself,
  411. instead of just where the problem is detected. In this way, instead of displaying
  412. (before Python 3.10):</p>
  413. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">foo</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">z</span> <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">),</span> <span class="n">t</span><span class="p">,</span> <span class="n">w</span><span class="p">)</span>
  414. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>
  415. <span class="w"> </span><span class="n">foo</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">z</span> <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">),</span> <span class="n">t</span><span class="p">,</span> <span class="n">w</span><span class="p">)</span>
  416. <span class="w"> </span><span class="pm">^</span>
  417. <span class="gr">SyntaxError</span>: <span class="n">Generator expression must be parenthesized</span>
  418. </pre></div>
  419. </div>
  420. <p>now Python 3.10 will display the exception as:</p>
  421. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">foo</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">z</span> <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">),</span> <span class="n">t</span><span class="p">,</span> <span class="n">w</span><span class="p">)</span>
  422. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>
  423. <span class="w"> </span><span class="n">foo</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">z</span> <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">),</span> <span class="n">t</span><span class="p">,</span> <span class="n">w</span><span class="p">)</span>
  424. <span class="w"> </span><span class="pm">^^^^^^^^^^^^^^^^^^^^</span>
  425. <span class="gr">SyntaxError</span>: <span class="n">Generator expression must be parenthesized</span>
  426. </pre></div>
  427. </div>
  428. <p>This improvement was contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43914">bpo-43914</a>.</p>
  429. <p>A considerable amount of new specialized messages for <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> exceptions
  430. have been incorporated. Some of the most notable ones are as follows:</p>
  431. <ul>
  432. <li><p>Missing <code class="docutils literal notranslate"><span class="pre">:</span></code> before blocks:</p>
  433. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">if</span> <span class="n">rocket</span><span class="o">.</span><span class="n">position</span> <span class="o">&gt;</span> <span class="n">event_horizon</span>
  434. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>
  435. <span class="w"> </span><span class="k">if</span> <span class="n">rocket</span><span class="o">.</span><span class="n">position</span> <span class="o">&gt;</span> <span class="n">event_horizon</span>
  436. <span class="w"> </span><span class="pm">^</span>
  437. <span class="gr">SyntaxError</span>: <span class="n">expected &#39;:&#39;</span>
  438. </pre></div>
  439. </div>
  440. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42997">bpo-42997</a>.)</p>
  441. </li>
  442. <li><p>Unparenthesised tuples in comprehensions targets:</p>
  443. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="p">{</span><span class="n">x</span><span class="p">,</span><span class="n">y</span> <span class="k">for</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="s1">&#39;abcd&#39;</span><span class="p">,</span> <span class="s1">&#39;1234&#39;</span><span class="p">)}</span>
  444. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>
  445. <span class="w"> </span><span class="p">{</span><span class="n">x</span><span class="p">,</span><span class="n">y</span> <span class="k">for</span> <span class="n">x</span><span class="p">,</span><span class="n">y</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="s1">&#39;abcd&#39;</span><span class="p">,</span> <span class="s1">&#39;1234&#39;</span><span class="p">)}</span>
  446. <span class="w"> </span><span class="pm">^</span>
  447. <span class="gr">SyntaxError</span>: <span class="n">did you forget parentheses around the comprehension target?</span>
  448. </pre></div>
  449. </div>
  450. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43017">bpo-43017</a>.)</p>
  451. </li>
  452. <li><p>Missing commas in collection literals and between expressions:</p>
  453. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">items</span> <span class="o">=</span> <span class="p">{</span>
  454. <span class="gp">... </span><span class="n">x</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
  455. <span class="gp">... </span><span class="n">y</span><span class="p">:</span> <span class="mi">2</span>
  456. <span class="gp">... </span><span class="n">z</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
  457. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">3</span>
  458. <span class="w"> </span><span class="n">y</span><span class="p">:</span> <span class="mi">2</span>
  459. <span class="w"> </span><span class="pm">^</span>
  460. <span class="gr">SyntaxError</span>: <span class="n">invalid syntax. Perhaps you forgot a comma?</span>
  461. </pre></div>
  462. </div>
  463. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43822">bpo-43822</a>.)</p>
  464. </li>
  465. <li><p>Multiple Exception types without parentheses:</p>
  466. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">try</span><span class="p">:</span>
  467. <span class="gp">... </span> <span class="n">build_dyson_sphere</span><span class="p">()</span>
  468. <span class="gp">... </span><span class="k">except</span> <span class="n">NotEnoughScienceError</span><span class="p">,</span> <span class="n">NotEnoughResourcesError</span><span class="p">:</span>
  469. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">3</span>
  470. <span class="w"> </span><span class="k">except</span> <span class="n">NotEnoughScienceError</span><span class="p">,</span> <span class="n">NotEnoughResourcesError</span><span class="p">:</span>
  471. <span class="w"> </span><span class="pm">^</span>
  472. <span class="gr">SyntaxError</span>: <span class="n">multiple exception types must be parenthesized</span>
  473. </pre></div>
  474. </div>
  475. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43149">bpo-43149</a>.)</p>
  476. </li>
  477. <li><p>Missing <code class="docutils literal notranslate"><span class="pre">:</span></code> and values in dictionary literals:</p>
  478. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="p">{</span>
  479. <span class="gp">... </span><span class="n">x</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
  480. <span class="gp">... </span><span class="n">y</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
  481. <span class="gp">... </span><span class="n">z</span><span class="p">:</span>
  482. <span class="gp">... </span><span class="p">}</span>
  483. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">4</span>
  484. <span class="w"> </span><span class="n">z</span><span class="p">:</span>
  485. <span class="w"> </span><span class="pm">^</span>
  486. <span class="gr">SyntaxError</span>: <span class="n">expression expected after dictionary key and &#39;:&#39;</span>
  487. <span class="gp">&gt;&gt;&gt; </span><span class="n">values</span> <span class="o">=</span> <span class="p">{</span><span class="n">x</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span> <span class="n">z</span> <span class="n">w</span><span class="p">:</span><span class="mi">3</span><span class="p">}</span>
  488. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>
  489. <span class="w"> </span><span class="n">values</span> <span class="o">=</span> <span class="p">{</span><span class="n">x</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span> <span class="n">z</span> <span class="n">w</span><span class="p">:</span><span class="mi">3</span><span class="p">}</span>
  490. <span class="w"> </span><span class="pm">^</span>
  491. <span class="gr">SyntaxError</span>: <span class="n">&#39;:&#39; expected after dictionary key</span>
  492. </pre></div>
  493. </div>
  494. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43823">bpo-43823</a>.)</p>
  495. </li>
  496. <li><p><code class="docutils literal notranslate"><span class="pre">try</span></code> blocks without <code class="docutils literal notranslate"><span class="pre">except</span></code> or <code class="docutils literal notranslate"><span class="pre">finally</span></code> blocks:</p>
  497. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">try</span><span class="p">:</span>
  498. <span class="gp">... </span> <span class="n">x</span> <span class="o">=</span> <span class="mi">2</span>
  499. <span class="gp">... </span><span class="n">something</span> <span class="o">=</span> <span class="mi">3</span>
  500. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">3</span>
  501. <span class="w"> </span><span class="n">something</span> <span class="o">=</span> <span class="mi">3</span>
  502. <span class="w"> </span><span class="pm">^^^^^^^^^</span>
  503. <span class="gr">SyntaxError</span>: <span class="n">expected &#39;except&#39; or &#39;finally&#39; block</span>
  504. </pre></div>
  505. </div>
  506. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44305">bpo-44305</a>.)</p>
  507. </li>
  508. <li><p>Usage of <code class="docutils literal notranslate"><span class="pre">=</span></code> instead of <code class="docutils literal notranslate"><span class="pre">==</span></code> in comparisons:</p>
  509. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">if</span> <span class="n">rocket</span><span class="o">.</span><span class="n">position</span> <span class="o">=</span> <span class="n">event_horizon</span><span class="p">:</span>
  510. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>
  511. <span class="w"> </span><span class="k">if</span> <span class="n">rocket</span><span class="o">.</span><span class="n">position</span> <span class="o">=</span> <span class="n">event_horizon</span><span class="p">:</span>
  512. <span class="w"> </span><span class="pm">^</span>
  513. <span class="gr">SyntaxError</span>: <span class="n">cannot assign to attribute here. Maybe you meant &#39;==&#39; instead of &#39;=&#39;?</span>
  514. </pre></div>
  515. </div>
  516. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43797">bpo-43797</a>.)</p>
  517. </li>
  518. <li><p>Usage of <code class="docutils literal notranslate"><span class="pre">*</span></code> in f-strings:</p>
  519. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="sa">f</span><span class="s2">&quot;Black holes </span><span class="si">{</span><span class="o">*</span><span class="n">all_black_holes</span><span class="si">}</span><span class="s2"> and revelations&quot;</span>
  520. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>
  521. <span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">all_black_holes</span><span class="p">)</span>
  522. <span class="w"> </span><span class="pm">^</span>
  523. <span class="gr">SyntaxError</span>: <span class="n">f-string: cannot use starred expression here</span>
  524. </pre></div>
  525. </div>
  526. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41064">bpo-41064</a>.)</p>
  527. </li>
  528. </ul>
  529. </section>
  530. <section id="indentationerrors">
  531. <h4>IndentationErrors<a class="headerlink" href="#indentationerrors" title="Link to this heading">¶</a></h4>
  532. <p>Many <a class="reference internal" href="../library/exceptions.html#IndentationError" title="IndentationError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IndentationError</span></code></a> exceptions now have more context regarding what kind of block
  533. was expecting an indentation, including the location of the statement:</p>
  534. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">foo</span><span class="p">():</span>
  535. <span class="gp">... </span> <span class="k">if</span> <span class="n">lel</span><span class="p">:</span>
  536. <span class="gp">... </span> <span class="n">x</span> <span class="o">=</span> <span class="mi">2</span>
  537. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">3</span>
  538. <span class="w"> </span><span class="n">x</span> <span class="o">=</span> <span class="mi">2</span>
  539. <span class="w"> </span><span class="pm">^</span>
  540. <span class="gr">IndentationError</span>: <span class="n">expected an indented block after &#39;if&#39; statement in line 2</span>
  541. </pre></div>
  542. </div>
  543. </section>
  544. <section id="attributeerrors">
  545. <h4>AttributeErrors<a class="headerlink" href="#attributeerrors" title="Link to this heading">¶</a></h4>
  546. <p>When printing <a class="reference internal" href="../library/exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a>, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Display()</span></code> will offer
  547. suggestions of similar attribute names in the object that the exception was
  548. raised from:</p>
  549. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">collections</span><span class="o">.</span><span class="n">namedtoplo</span>
  550. <span class="gt">Traceback (most recent call last):</span>
  551. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  552. <span class="gr">AttributeError</span>: <span class="n">module &#39;collections&#39; has no attribute &#39;namedtoplo&#39;. Did you mean: namedtuple?</span>
  553. </pre></div>
  554. </div>
  555. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38530">bpo-38530</a>.)</p>
  556. <div class="admonition warning">
  557. <p class="admonition-title">Warning</p>
  558. <p>Notice this won’t work if <code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Display()</span></code> is not called to display the error
  559. which can happen if some other custom error display function is used. This is a common
  560. scenario in some REPLs like IPython.</p>
  561. </div>
  562. </section>
  563. <section id="nameerrors">
  564. <h4>NameErrors<a class="headerlink" href="#nameerrors" title="Link to this heading">¶</a></h4>
  565. <p>When printing <a class="reference internal" href="../library/exceptions.html#NameError" title="NameError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NameError</span></code></a> raised by the interpreter, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Display()</span></code>
  566. will offer suggestions of similar variable names in the function that the exception
  567. was raised from:</p>
  568. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">schwarzschild_black_hole</span> <span class="o">=</span> <span class="kc">None</span>
  569. <span class="gp">&gt;&gt;&gt; </span><span class="n">schwarschild_black_hole</span>
  570. <span class="gt">Traceback (most recent call last):</span>
  571. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  572. <span class="gr">NameError</span>: <span class="n">name &#39;schwarschild_black_hole&#39; is not defined. Did you mean: schwarzschild_black_hole?</span>
  573. </pre></div>
  574. </div>
  575. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38530">bpo-38530</a>.)</p>
  576. <div class="admonition warning">
  577. <p class="admonition-title">Warning</p>
  578. <p>Notice this won’t work if <code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Display()</span></code> is not called to display the error,
  579. which can happen if some other custom error display function is used. This is a common
  580. scenario in some REPLs like IPython.</p>
  581. </div>
  582. </section>
  583. </section>
  584. <section id="pep-626-precise-line-numbers-for-debugging-and-other-tools">
  585. <h3>PEP 626: Precise line numbers for debugging and other tools<a class="headerlink" href="#pep-626-precise-line-numbers-for-debugging-and-other-tools" title="Link to this heading">¶</a></h3>
  586. <p>PEP 626 brings more precise and reliable line numbers for debugging, profiling and coverage tools.
  587. Tracing events, with the correct line number, are generated for all lines of code executed and only for lines of code that are executed.</p>
  588. <p>The <a class="reference internal" href="../reference/datamodel.html#frame.f_lineno" title="frame.f_lineno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">f_lineno</span></code></a> attribute of frame objects will always contain the
  589. expected line number.</p>
  590. <p>The <a class="reference internal" href="../reference/datamodel.html#codeobject.co_lnotab" title="codeobject.co_lnotab"><code class="xref py py-attr docutils literal notranslate"><span class="pre">co_lnotab</span></code></a> attribute of
  591. <a class="reference internal" href="../reference/datamodel.html#code-objects"><span class="std std-ref">code objects</span></a> is deprecated and
  592. will be removed in 3.12.
  593. Code that needs to convert from offset to line number should use the new
  594. <a class="reference internal" href="../reference/datamodel.html#codeobject.co_lines" title="codeobject.co_lines"><code class="xref py py-meth docutils literal notranslate"><span class="pre">co_lines()</span></code></a> method instead.</p>
  595. </section>
  596. <section id="pep-634-structural-pattern-matching">
  597. <h3>PEP 634: Structural Pattern Matching<a class="headerlink" href="#pep-634-structural-pattern-matching" title="Link to this heading">¶</a></h3>
  598. <p>Structural pattern matching has been added in the form of a <em>match statement</em>
  599. and <em>case statements</em> of patterns with associated actions. Patterns
  600. consist of sequences, mappings, primitive data types as well as class instances.
  601. Pattern matching enables programs to extract information from complex data types,
  602. branch on the structure of data, and apply specific actions based on different
  603. forms of data.</p>
  604. <section id="syntax-and-operations">
  605. <h4>Syntax and operations<a class="headerlink" href="#syntax-and-operations" title="Link to this heading">¶</a></h4>
  606. <p>The generic syntax of pattern matching is:</p>
  607. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">match</span> <span class="n">subject</span><span class="p">:</span>
  608. <span class="k">case</span> <span class="o">&lt;</span><span class="n">pattern_1</span><span class="o">&gt;</span><span class="p">:</span>
  609. <span class="o">&lt;</span><span class="n">action_1</span><span class="o">&gt;</span>
  610. <span class="k">case</span> <span class="o">&lt;</span><span class="n">pattern_2</span><span class="o">&gt;</span><span class="p">:</span>
  611. <span class="o">&lt;</span><span class="n">action_2</span><span class="o">&gt;</span>
  612. <span class="k">case</span> <span class="o">&lt;</span><span class="n">pattern_3</span><span class="o">&gt;</span><span class="p">:</span>
  613. <span class="o">&lt;</span><span class="n">action_3</span><span class="o">&gt;</span>
  614. <span class="k">case</span><span class="w"> </span><span class="k">_</span><span class="p">:</span>
  615. <span class="o">&lt;</span><span class="n">action_wildcard</span><span class="o">&gt;</span>
  616. </pre></div>
  617. </div>
  618. <p>A match statement takes an expression and compares its value to successive
  619. patterns given as one or more case blocks. Specifically, pattern matching
  620. operates by:</p>
  621. <ol class="arabic simple">
  622. <li><p>using data with type and shape (the <code class="docutils literal notranslate"><span class="pre">subject</span></code>)</p></li>
  623. <li><p>evaluating the <code class="docutils literal notranslate"><span class="pre">subject</span></code> in the <code class="docutils literal notranslate"><span class="pre">match</span></code> statement</p></li>
  624. <li><p>comparing the subject with each pattern in a <code class="docutils literal notranslate"><span class="pre">case</span></code> statement
  625. from top to bottom until a match is confirmed.</p></li>
  626. <li><p>executing the action associated with the pattern of the confirmed
  627. match</p></li>
  628. <li><p>If an exact match is not confirmed, the last case, a wildcard <code class="docutils literal notranslate"><span class="pre">_</span></code>,
  629. if provided, will be used as the matching case. If an exact match is
  630. not confirmed and a wildcard case does not exist, the entire match
  631. block is a no-op.</p></li>
  632. </ol>
  633. </section>
  634. <section id="declarative-approach">
  635. <h4>Declarative approach<a class="headerlink" href="#declarative-approach" title="Link to this heading">¶</a></h4>
  636. <p>Readers may be aware of pattern matching through the simple example of matching
  637. a subject (data object) to a literal (pattern) with the switch statement found
  638. in C, Java or JavaScript (and many other languages). Often the switch statement
  639. is used for comparison of an object/expression with case statements containing
  640. literals.</p>
  641. <p>More powerful examples of pattern matching can be found in languages such as
  642. Scala and Elixir. With structural pattern matching, the approach is “declarative” and
  643. explicitly states the conditions (the patterns) for data to match.</p>
  644. <p>While an “imperative” series of instructions using nested “if” statements
  645. could be used to accomplish something similar to structural pattern matching,
  646. it is less clear than the “declarative” approach. Instead the “declarative”
  647. approach states the conditions to meet for a match and is more readable through
  648. its explicit patterns. While structural pattern matching can be used in its
  649. simplest form comparing a variable to a literal in a case statement, its
  650. true value for Python lies in its handling of the subject’s type and shape.</p>
  651. </section>
  652. <section id="simple-pattern-match-to-a-literal">
  653. <h4>Simple pattern: match to a literal<a class="headerlink" href="#simple-pattern-match-to-a-literal" title="Link to this heading">¶</a></h4>
  654. <p>Let’s look at this example as pattern matching in its simplest form: a value,
  655. the subject, being matched to several literals, the patterns. In the example
  656. below, <code class="docutils literal notranslate"><span class="pre">status</span></code> is the subject of the match statement. The patterns are
  657. each of the case statements, where literals represent request status codes.
  658. The associated action to the case is executed after a match:</p>
  659. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">http_error</span><span class="p">(</span><span class="n">status</span><span class="p">):</span>
  660. <span class="k">match</span> <span class="n">status</span><span class="p">:</span>
  661. <span class="k">case</span> <span class="mi">400</span><span class="p">:</span>
  662. <span class="k">return</span> <span class="s2">&quot;Bad request&quot;</span>
  663. <span class="k">case</span> <span class="mi">404</span><span class="p">:</span>
  664. <span class="k">return</span> <span class="s2">&quot;Not found&quot;</span>
  665. <span class="k">case</span> <span class="mi">418</span><span class="p">:</span>
  666. <span class="k">return</span> <span class="s2">&quot;I&#39;m a teapot&quot;</span>
  667. <span class="k">case</span><span class="w"> </span><span class="k">_</span><span class="p">:</span>
  668. <span class="k">return</span> <span class="s2">&quot;Something&#39;s wrong with the internet&quot;</span>
  669. </pre></div>
  670. </div>
  671. <p>If the above function is passed a <code class="docutils literal notranslate"><span class="pre">status</span></code> of 418, “I’m a teapot” is returned.
  672. If the above function is passed a <code class="docutils literal notranslate"><span class="pre">status</span></code> of 500, the case statement with
  673. <code class="docutils literal notranslate"><span class="pre">_</span></code> will match as a wildcard, and “Something’s wrong with the internet” is
  674. returned.
  675. Note the last block: the variable name, <code class="docutils literal notranslate"><span class="pre">_</span></code>, acts as a <em>wildcard</em> and insures
  676. the subject will always match. The use of <code class="docutils literal notranslate"><span class="pre">_</span></code> is optional.</p>
  677. <p>You can combine several literals in a single pattern using <code class="docutils literal notranslate"><span class="pre">|</span></code> (“or”):</p>
  678. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">case</span> <span class="mi">401</span> <span class="o">|</span> <span class="mi">403</span> <span class="o">|</span> <span class="mi">404</span><span class="p">:</span>
  679. <span class="k">return</span> <span class="s2">&quot;Not allowed&quot;</span>
  680. </pre></div>
  681. </div>
  682. <section id="behavior-without-the-wildcard">
  683. <h5>Behavior without the wildcard<a class="headerlink" href="#behavior-without-the-wildcard" title="Link to this heading">¶</a></h5>
  684. <p>If we modify the above example by removing the last case block, the example
  685. becomes:</p>
  686. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">http_error</span><span class="p">(</span><span class="n">status</span><span class="p">):</span>
  687. <span class="k">match</span> <span class="n">status</span><span class="p">:</span>
  688. <span class="k">case</span> <span class="mi">400</span><span class="p">:</span>
  689. <span class="k">return</span> <span class="s2">&quot;Bad request&quot;</span>
  690. <span class="k">case</span> <span class="mi">404</span><span class="p">:</span>
  691. <span class="k">return</span> <span class="s2">&quot;Not found&quot;</span>
  692. <span class="k">case</span> <span class="mi">418</span><span class="p">:</span>
  693. <span class="k">return</span> <span class="s2">&quot;I&#39;m a teapot&quot;</span>
  694. </pre></div>
  695. </div>
  696. <p>Without the use of <code class="docutils literal notranslate"><span class="pre">_</span></code> in a case statement, a match may not exist. If no
  697. match exists, the behavior is a no-op. For example, if <code class="docutils literal notranslate"><span class="pre">status</span></code> of 500 is
  698. passed, a no-op occurs.</p>
  699. </section>
  700. </section>
  701. <section id="patterns-with-a-literal-and-variable">
  702. <h4>Patterns with a literal and variable<a class="headerlink" href="#patterns-with-a-literal-and-variable" title="Link to this heading">¶</a></h4>
  703. <p>Patterns can look like unpacking assignments, and a pattern may be used to bind
  704. variables. In this example, a data point can be unpacked to its x-coordinate
  705. and y-coordinate:</p>
  706. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># point is an (x, y) tuple</span>
  707. <span class="k">match</span> <span class="n">point</span><span class="p">:</span>
  708. <span class="k">case</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">):</span>
  709. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Origin&quot;</span><span class="p">)</span>
  710. <span class="k">case</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
  711. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Y=</span><span class="si">{</span><span class="n">y</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
  712. <span class="k">case</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">):</span>
  713. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;X=</span><span class="si">{</span><span class="n">x</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
  714. <span class="k">case</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
  715. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;X=</span><span class="si">{</span><span class="n">x</span><span class="si">}</span><span class="s2">, Y=</span><span class="si">{</span><span class="n">y</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
  716. <span class="k">case</span><span class="w"> </span><span class="k">_</span><span class="p">:</span>
  717. <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Not a point&quot;</span><span class="p">)</span>
  718. </pre></div>
  719. </div>
  720. <p>The first pattern has two literals, <code class="docutils literal notranslate"><span class="pre">(0,</span> <span class="pre">0)</span></code>, and may be thought of as an
  721. extension of the literal pattern shown above. The next two patterns combine a
  722. literal and a variable, and the variable <em>binds</em> a value from the subject
  723. (<code class="docutils literal notranslate"><span class="pre">point</span></code>). The fourth pattern captures two values, which makes it
  724. conceptually similar to the unpacking assignment <code class="docutils literal notranslate"><span class="pre">(x,</span> <span class="pre">y)</span> <span class="pre">=</span> <span class="pre">point</span></code>.</p>
  725. </section>
  726. <section id="patterns-and-classes">
  727. <h4>Patterns and classes<a class="headerlink" href="#patterns-and-classes" title="Link to this heading">¶</a></h4>
  728. <p>If you are using classes to structure your data, you can use as a pattern
  729. the class name followed by an argument list resembling a constructor. This
  730. pattern has the ability to capture class attributes into variables:</p>
  731. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Point</span><span class="p">:</span>
  732. <span class="n">x</span><span class="p">:</span> <span class="nb">int</span>
  733. <span class="n">y</span><span class="p">:</span> <span class="nb">int</span>
  734. <span class="k">def</span> <span class="nf">location</span><span class="p">(</span><span class="n">point</span><span class="p">):</span>
  735. <span class="k">match</span> <span class="n">point</span><span class="p">:</span>
  736. <span class="k">case</span> <span class="n">Point</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
  737. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Origin is the point&#39;s location.&quot;</span><span class="p">)</span>
  738. <span class="k">case</span> <span class="n">Point</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">):</span>
  739. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Y=</span><span class="si">{</span><span class="n">y</span><span class="si">}</span><span class="s2"> and the point is on the y-axis.&quot;</span><span class="p">)</span>
  740. <span class="k">case</span> <span class="n">Point</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
  741. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;X=</span><span class="si">{</span><span class="n">x</span><span class="si">}</span><span class="s2"> and the point is on the x-axis.&quot;</span><span class="p">)</span>
  742. <span class="k">case</span> <span class="n">Point</span><span class="p">():</span>
  743. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;The point is located somewhere else on the plane.&quot;</span><span class="p">)</span>
  744. <span class="k">case</span><span class="w"> </span><span class="k">_</span><span class="p">:</span>
  745. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Not a point&quot;</span><span class="p">)</span>
  746. </pre></div>
  747. </div>
  748. <section id="patterns-with-positional-parameters">
  749. <h5>Patterns with positional parameters<a class="headerlink" href="#patterns-with-positional-parameters" title="Link to this heading">¶</a></h5>
  750. <p>You can use positional parameters with some builtin classes that provide an
  751. ordering for their attributes (e.g. dataclasses). You can also define a specific
  752. position for attributes in patterns by setting the <code class="docutils literal notranslate"><span class="pre">__match_args__</span></code> special
  753. attribute in your classes. If it’s set to (“x”, “y”), the following patterns
  754. are all equivalent (and all bind the <code class="docutils literal notranslate"><span class="pre">y</span></code> attribute to the <code class="docutils literal notranslate"><span class="pre">var</span></code> variable):</p>
  755. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Point</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">var</span><span class="p">)</span>
  756. <span class="n">Point</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">var</span><span class="p">)</span>
  757. <span class="n">Point</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">var</span><span class="p">)</span>
  758. <span class="n">Point</span><span class="p">(</span><span class="n">y</span><span class="o">=</span><span class="n">var</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
  759. </pre></div>
  760. </div>
  761. </section>
  762. </section>
  763. <section id="nested-patterns">
  764. <h4>Nested patterns<a class="headerlink" href="#nested-patterns" title="Link to this heading">¶</a></h4>
  765. <p>Patterns can be arbitrarily nested. For example, if our data is a short
  766. list of points, it could be matched like this:</p>
  767. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">match</span> <span class="n">points</span><span class="p">:</span>
  768. <span class="k">case</span> <span class="p">[]:</span>
  769. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;No points in the list.&quot;</span><span class="p">)</span>
  770. <span class="k">case</span> <span class="p">[</span><span class="n">Point</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)]:</span>
  771. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;The origin is the only point in the list.&quot;</span><span class="p">)</span>
  772. <span class="k">case</span> <span class="p">[</span><span class="n">Point</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)]:</span>
  773. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;A single point </span><span class="si">{</span><span class="n">x</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">y</span><span class="si">}</span><span class="s2"> is in the list.&quot;</span><span class="p">)</span>
  774. <span class="k">case</span> <span class="p">[</span><span class="n">Point</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">y1</span><span class="p">),</span> <span class="n">Point</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">y2</span><span class="p">)]:</span>
  775. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Two points on the Y axis at </span><span class="si">{</span><span class="n">y1</span><span class="si">}</span><span class="s2">, </span><span class="si">{</span><span class="n">y2</span><span class="si">}</span><span class="s2"> are in the list.&quot;</span><span class="p">)</span>
  776. <span class="k">case</span><span class="w"> </span><span class="k">_</span><span class="p">:</span>
  777. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Something else is found in the list.&quot;</span><span class="p">)</span>
  778. </pre></div>
  779. </div>
  780. </section>
  781. <section id="complex-patterns-and-the-wildcard">
  782. <h4>Complex patterns and the wildcard<a class="headerlink" href="#complex-patterns-and-the-wildcard" title="Link to this heading">¶</a></h4>
  783. <p>To this point, the examples have used <code class="docutils literal notranslate"><span class="pre">_</span></code> alone in the last case statement.
  784. A wildcard can be used in more complex patterns, such as <code class="docutils literal notranslate"><span class="pre">('error',</span> <span class="pre">code,</span> <span class="pre">_)</span></code>.
  785. For example:</p>
  786. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">match</span> <span class="n">test_variable</span><span class="p">:</span>
  787. <span class="k">case</span> <span class="p">(</span><span class="s1">&#39;warning&#39;</span><span class="p">,</span> <span class="n">code</span><span class="p">,</span> <span class="mi">40</span><span class="p">):</span>
  788. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;A warning has been received.&quot;</span><span class="p">)</span>
  789. <span class="k">case</span><span class="w"> </span><span class="p">(</span><span class="s1">&#39;error&#39;</span><span class="p">,</span> <span class="n">code</span><span class="p">,</span> <span class="k">_</span><span class="p">):</span>
  790. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;An error </span><span class="si">{</span><span class="n">code</span><span class="si">}</span><span class="s2"> occurred.&quot;</span><span class="p">)</span>
  791. </pre></div>
  792. </div>
  793. <p>In the above case, <code class="docutils literal notranslate"><span class="pre">test_variable</span></code> will match for (‘error’, code, 100) and
  794. (‘error’, code, 800).</p>
  795. </section>
  796. <section id="guard">
  797. <h4>Guard<a class="headerlink" href="#guard" title="Link to this heading">¶</a></h4>
  798. <p>We can add an <code class="docutils literal notranslate"><span class="pre">if</span></code> clause to a pattern, known as a “guard”. If the
  799. guard is false, <code class="docutils literal notranslate"><span class="pre">match</span></code> goes on to try the next case block. Note
  800. that value capture happens before the guard is evaluated:</p>
  801. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">match</span> <span class="n">point</span><span class="p">:</span>
  802. <span class="k">case</span> <span class="n">Point</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span> <span class="k">if</span> <span class="n">x</span> <span class="o">==</span> <span class="n">y</span><span class="p">:</span>
  803. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;The point is located on the diagonal Y=X at </span><span class="si">{</span><span class="n">x</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
  804. <span class="k">case</span> <span class="n">Point</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
  805. <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Point is not on the diagonal.&quot;</span><span class="p">)</span>
  806. </pre></div>
  807. </div>
  808. </section>
  809. <section id="other-key-features">
  810. <h4>Other Key Features<a class="headerlink" href="#other-key-features" title="Link to this heading">¶</a></h4>
  811. <p>Several other key features:</p>
  812. <ul>
  813. <li><p>Like unpacking assignments, tuple and list patterns have exactly the
  814. same meaning and actually match arbitrary sequences. Technically,
  815. the subject must be a sequence.
  816. Therefore, an important exception is that patterns don’t match iterators.
  817. Also, to prevent a common mistake, sequence patterns don’t match strings.</p></li>
  818. <li><p>Sequence patterns support wildcards: <code class="docutils literal notranslate"><span class="pre">[x,</span> <span class="pre">y,</span> <span class="pre">*rest]</span></code> and <code class="docutils literal notranslate"><span class="pre">(x,</span> <span class="pre">y,</span>
  819. <span class="pre">*rest)</span></code> work similar to wildcards in unpacking assignments. The
  820. name after <code class="docutils literal notranslate"><span class="pre">*</span></code> may also be <code class="docutils literal notranslate"><span class="pre">_</span></code>, so <code class="docutils literal notranslate"><span class="pre">(x,</span> <span class="pre">y,</span> <span class="pre">*_)</span></code> matches a sequence
  821. of at least two items without binding the remaining items.</p></li>
  822. <li><p>Mapping patterns: <code class="docutils literal notranslate"><span class="pre">{&quot;bandwidth&quot;:</span> <span class="pre">b,</span> <span class="pre">&quot;latency&quot;:</span> <span class="pre">l}</span></code> captures the
  823. <code class="docutils literal notranslate"><span class="pre">&quot;bandwidth&quot;</span></code> and <code class="docutils literal notranslate"><span class="pre">&quot;latency&quot;</span></code> values from a dict. Unlike sequence
  824. patterns, extra keys are ignored. A wildcard <code class="docutils literal notranslate"><span class="pre">**rest</span></code> is also
  825. supported. (But <code class="docutils literal notranslate"><span class="pre">**_</span></code> would be redundant, so is not allowed.)</p></li>
  826. <li><p>Subpatterns may be captured using the <code class="docutils literal notranslate"><span class="pre">as</span></code> keyword:</p>
  827. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">case</span> <span class="p">(</span><span class="n">Point</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">y1</span><span class="p">),</span> <span class="n">Point</span><span class="p">(</span><span class="n">x2</span><span class="p">,</span> <span class="n">y2</span><span class="p">)</span> <span class="k">as</span> <span class="n">p2</span><span class="p">):</span> <span class="o">...</span>
  828. </pre></div>
  829. </div>
  830. <p>This binds x1, y1, x2, y2 like you would expect without the <code class="docutils literal notranslate"><span class="pre">as</span></code> clause,
  831. and p2 to the entire second item of the subject.</p>
  832. </li>
  833. <li><p>Most literals are compared by equality. However, the singletons <code class="docutils literal notranslate"><span class="pre">True</span></code>,
  834. <code class="docutils literal notranslate"><span class="pre">False</span></code> and <code class="docutils literal notranslate"><span class="pre">None</span></code> are compared by identity.</p></li>
  835. <li><p>Named constants may be used in patterns. These named constants must be
  836. dotted names to prevent the constant from being interpreted as a capture
  837. variable:</p>
  838. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">enum</span> <span class="kn">import</span> <span class="n">Enum</span>
  839. <span class="k">class</span> <span class="nc">Color</span><span class="p">(</span><span class="n">Enum</span><span class="p">):</span>
  840. <span class="n">RED</span> <span class="o">=</span> <span class="mi">0</span>
  841. <span class="n">GREEN</span> <span class="o">=</span> <span class="mi">1</span>
  842. <span class="n">BLUE</span> <span class="o">=</span> <span class="mi">2</span>
  843. <span class="n">color</span> <span class="o">=</span> <span class="n">Color</span><span class="o">.</span><span class="n">GREEN</span>
  844. <span class="k">match</span> <span class="n">color</span><span class="p">:</span>
  845. <span class="k">case</span> <span class="n">Color</span><span class="o">.</span><span class="n">RED</span><span class="p">:</span>
  846. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;I see red!&quot;</span><span class="p">)</span>
  847. <span class="k">case</span> <span class="n">Color</span><span class="o">.</span><span class="n">GREEN</span><span class="p">:</span>
  848. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Grass is green&quot;</span><span class="p">)</span>
  849. <span class="k">case</span> <span class="n">Color</span><span class="o">.</span><span class="n">BLUE</span><span class="p">:</span>
  850. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;I&#39;m feeling the blues :(&quot;</span><span class="p">)</span>
  851. </pre></div>
  852. </div>
  853. </li>
  854. </ul>
  855. <p>For the full specification see <span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0634/"><strong>PEP 634</strong></a>. Motivation and rationale
  856. are in <span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0635/"><strong>PEP 635</strong></a>, and a longer tutorial is in <span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0636/"><strong>PEP 636</strong></a>.</p>
  857. </section>
  858. </section>
  859. <section id="optional-encodingwarning-and-encoding-locale-option">
  860. <span id="whatsnew310-pep597"></span><h3>Optional <code class="docutils literal notranslate"><span class="pre">EncodingWarning</span></code> and <code class="docutils literal notranslate"><span class="pre">encoding=&quot;locale&quot;</span></code> option<a class="headerlink" href="#optional-encodingwarning-and-encoding-locale-option" title="Link to this heading">¶</a></h3>
  861. <p>The default encoding of <code class="xref py py-class docutils literal notranslate"><span class="pre">TextIOWrapper</span></code> and <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> is
  862. platform and locale dependent. Since UTF-8 is used on most Unix
  863. platforms, omitting <code class="docutils literal notranslate"><span class="pre">encoding</span></code> option when opening UTF-8 files
  864. (e.g. JSON, YAML, TOML, Markdown) is a very common bug. For example:</p>
  865. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># BUG: &quot;rb&quot; mode or encoding=&quot;utf-8&quot; should be used.</span>
  866. <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&quot;data.json&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
  867. <span class="n">data</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
  868. </pre></div>
  869. </div>
  870. <p>To find this type of bug, an optional <code class="docutils literal notranslate"><span class="pre">EncodingWarning</span></code> is added.
  871. It is emitted when <a class="reference internal" href="../library/sys.html#sys.flags" title="sys.flags"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.flags.warn_default_encoding</span></code></a>
  872. is true and locale-specific default encoding is used.</p>
  873. <p><code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">warn_default_encoding</span></code> option and <span class="target" id="index-18"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONWARNDEFAULTENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONWARNDEFAULTENCODING</span></code></a>
  874. are added to enable the warning.</p>
  875. <p>See <a class="reference internal" href="../library/io.html#io-text-encoding"><span class="std std-ref">Text Encoding</span></a> for more information.</p>
  876. </section>
  877. </section>
  878. <section id="new-features-related-to-type-hints">
  879. <span id="new-feat-related-type-hints"></span><h2>New Features Related to Type Hints<a class="headerlink" href="#new-features-related-to-type-hints" title="Link to this heading">¶</a></h2>
  880. <p>This section covers major changes affecting <span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> type hints and
  881. 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.</p>
  882. <section id="pep-604-new-type-union-operator">
  883. <h3>PEP 604: New Type Union Operator<a class="headerlink" href="#pep-604-new-type-union-operator" title="Link to this heading">¶</a></h3>
  884. <p>A new type union operator was introduced which enables the syntax <code class="docutils literal notranslate"><span class="pre">X</span> <span class="pre">|</span> <span class="pre">Y</span></code>.
  885. This provides a cleaner way of expressing ‘either type X or type Y’ instead of
  886. using <a class="reference internal" href="../library/typing.html#typing.Union" title="typing.Union"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.Union</span></code></a>, especially in type hints.</p>
  887. <p>In previous versions of Python, to apply a type hint for functions accepting
  888. arguments of multiple types, <a class="reference internal" href="../library/typing.html#typing.Union" title="typing.Union"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.Union</span></code></a> was used:</p>
  889. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">square</span><span class="p">(</span><span class="n">number</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">Union</span><span class="p">[</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">]:</span>
  890. <span class="k">return</span> <span class="n">number</span> <span class="o">**</span> <span class="mi">2</span>
  891. </pre></div>
  892. </div>
  893. <p>Type hints can now be written in a more succinct manner:</p>
  894. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">square</span><span class="p">(</span><span class="n">number</span><span class="p">:</span> <span class="nb">int</span> <span class="o">|</span> <span class="nb">float</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">int</span> <span class="o">|</span> <span class="nb">float</span><span class="p">:</span>
  895. <span class="k">return</span> <span class="n">number</span> <span class="o">**</span> <span class="mi">2</span>
  896. </pre></div>
  897. </div>
  898. <p>This new syntax is also accepted as the second argument to <a class="reference internal" href="../library/functions.html#isinstance" title="isinstance"><code class="xref py py-func docutils literal notranslate"><span class="pre">isinstance()</span></code></a>
  899. and <a class="reference internal" href="../library/functions.html#issubclass" title="issubclass"><code class="xref py py-func docutils literal notranslate"><span class="pre">issubclass()</span></code></a>:</p>
  900. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">isinstance</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">int</span> <span class="o">|</span> <span class="nb">str</span><span class="p">)</span>
  901. <span class="go">True</span>
  902. </pre></div>
  903. </div>
  904. <p>See <a class="reference internal" href="../library/stdtypes.html#types-union"><span class="std std-ref">Union Type</span></a> and <span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0604/"><strong>PEP 604</strong></a> for more details.</p>
  905. <p>(Contributed by Maggie Moss and Philippe Prados in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41428">bpo-41428</a>,
  906. with additions by Yurii Karabas and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44490">bpo-44490</a>.)</p>
  907. </section>
  908. <section id="pep-612-parameter-specification-variables">
  909. <h3>PEP 612: Parameter Specification Variables<a class="headerlink" href="#pep-612-parameter-specification-variables" title="Link to this heading">¶</a></h3>
  910. <p>Two new options to improve the information provided to static type checkers for
  911. <span class="target" id="index-21"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a>‘s <code class="docutils literal notranslate"><span class="pre">Callable</span></code> have been added to the <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module.</p>
  912. <p>The first is the parameter specification variable. They are used to forward the
  913. parameter types of one callable to another callable – a pattern commonly
  914. found in higher order functions and decorators. Examples of usage can be found
  915. in <a class="reference internal" href="../library/typing.html#typing.ParamSpec" title="typing.ParamSpec"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.ParamSpec</span></code></a>. Previously, there was no easy way to type annotate
  916. dependency of parameter types in such a precise manner.</p>
  917. <p>The second option is the new <code class="docutils literal notranslate"><span class="pre">Concatenate</span></code> operator. It’s used in conjunction
  918. with parameter specification variables to type annotate a higher order callable
  919. which adds or removes parameters of another callable. Examples of usage can
  920. be found in <a class="reference internal" href="../library/typing.html#typing.Concatenate" title="typing.Concatenate"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Concatenate</span></code></a>.</p>
  921. <p>See <a class="reference internal" href="../library/typing.html#typing.Callable" title="typing.Callable"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Callable</span></code></a>, <a class="reference internal" href="../library/typing.html#typing.ParamSpec" title="typing.ParamSpec"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.ParamSpec</span></code></a>,
  922. <a class="reference internal" href="../library/typing.html#typing.Concatenate" title="typing.Concatenate"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Concatenate</span></code></a>, <a class="reference internal" href="../library/typing.html#typing.ParamSpecArgs" title="typing.ParamSpecArgs"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.ParamSpecArgs</span></code></a>,
  923. <a class="reference internal" href="../library/typing.html#typing.ParamSpecKwargs" title="typing.ParamSpecKwargs"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.ParamSpecKwargs</span></code></a>, and <span class="target" id="index-22"></span><a class="pep reference external" href="https://peps.python.org/pep-0612/"><strong>PEP 612</strong></a> for more details.</p>
  924. <p>(Contributed by Ken Jin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41559">bpo-41559</a>, with minor enhancements by Jelle
  925. Zijlstra in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43783">bpo-43783</a>. PEP written by Mark Mendoza.)</p>
  926. </section>
  927. <section id="pep-613-typealias">
  928. <h3>PEP 613: TypeAlias<a class="headerlink" href="#pep-613-typealias" title="Link to this heading">¶</a></h3>
  929. <p><span class="target" id="index-23"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> introduced the concept of type aliases, only requiring them to be
  930. top-level unannotated assignments. This simplicity sometimes made it difficult
  931. for type checkers to distinguish between type aliases and ordinary assignments,
  932. especially when forward references or invalid types were involved. Compare:</p>
  933. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">StrCache</span> <span class="o">=</span> <span class="s1">&#39;Cache[str]&#39;</span> <span class="c1"># a type alias</span>
  934. <span class="n">LOG_PREFIX</span> <span class="o">=</span> <span class="s1">&#39;LOG[DEBUG]&#39;</span> <span class="c1"># a module constant</span>
  935. </pre></div>
  936. </div>
  937. <p>Now 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 has a special value <code class="xref py py-data docutils literal notranslate"><span class="pre">TypeAlias</span></code>
  938. which lets you declare type aliases more explicitly:</p>
  939. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">StrCache</span><span class="p">:</span> <span class="n">TypeAlias</span> <span class="o">=</span> <span class="s1">&#39;Cache[str]&#39;</span> <span class="c1"># a type alias</span>
  940. <span class="n">LOG_PREFIX</span> <span class="o">=</span> <span class="s1">&#39;LOG[DEBUG]&#39;</span> <span class="c1"># a module constant</span>
  941. </pre></div>
  942. </div>
  943. <p>See <span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0613/"><strong>PEP 613</strong></a> for more details.</p>
  944. <p>(Contributed by Mikhail Golubev in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41923">bpo-41923</a>.)</p>
  945. </section>
  946. <section id="pep-647-user-defined-type-guards">
  947. <h3>PEP 647: User-Defined Type Guards<a class="headerlink" href="#pep-647-user-defined-type-guards" title="Link to this heading">¶</a></h3>
  948. <p><code class="xref py py-data docutils literal notranslate"><span class="pre">TypeGuard</span></code> has been added to the <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module to annotate
  949. type guard functions and improve information provided to static type checkers
  950. during type narrowing. For more information, please see <code class="xref py py-data docutils literal notranslate"><span class="pre">TypeGuard</span></code>‘s
  951. documentation, and <span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-0647/"><strong>PEP 647</strong></a>.</p>
  952. <p>(Contributed by Ken Jin and Guido van Rossum in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43766">bpo-43766</a>.
  953. PEP written by Eric Traut.)</p>
  954. </section>
  955. </section>
  956. <section id="other-language-changes">
  957. <h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading">¶</a></h2>
  958. <ul class="simple">
  959. <li><p>The <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> type has a new method <a class="reference internal" href="../library/stdtypes.html#int.bit_count" title="int.bit_count"><code class="xref py py-meth docutils literal notranslate"><span class="pre">int.bit_count()</span></code></a>, returning the
  960. number of ones in the binary expansion of a given integer, also known
  961. as the population count. (Contributed by Niklas Fiekas in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29882">bpo-29882</a>.)</p></li>
  962. <li><p>The views returned by <a class="reference internal" href="../library/stdtypes.html#dict.keys" title="dict.keys"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.keys()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#dict.values" title="dict.values"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.values()</span></code></a> and
  963. <a class="reference internal" href="../library/stdtypes.html#dict.items" title="dict.items"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.items()</span></code></a> now all have a <code class="docutils literal notranslate"><span class="pre">mapping</span></code> attribute that gives a
  964. <a class="reference internal" href="../library/types.html#types.MappingProxyType" title="types.MappingProxyType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.MappingProxyType</span></code></a> object wrapping the original
  965. dictionary. (Contributed by Dennis Sweeney in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40890">bpo-40890</a>.)</p></li>
  966. <li><p><span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-0618/"><strong>PEP 618</strong></a>: The <a class="reference internal" href="../library/functions.html#zip" title="zip"><code class="xref py py-func docutils literal notranslate"><span class="pre">zip()</span></code></a> function now has an optional <code class="docutils literal notranslate"><span class="pre">strict</span></code> flag, used
  967. to require that all the iterables have an equal length.</p></li>
  968. <li><p>Builtin and extension functions that take integer arguments no longer accept
  969. <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">Decimal</span></code></a>s, <a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a>s and other
  970. objects that can be converted to integers only with a loss (e.g. that have
  971. the <a class="reference internal" href="../reference/datamodel.html#object.__int__" title="object.__int__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__int__()</span></code></a> method but do not have the
  972. <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> method).
  973. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37999">bpo-37999</a>.)</p></li>
  974. <li><p>If <a class="reference internal" href="../reference/datamodel.html#object.__ipow__" title="object.__ipow__"><code class="xref py py-func docutils literal notranslate"><span class="pre">object.__ipow__()</span></code></a> 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>, the operator will
  975. correctly fall back to <a class="reference internal" href="../reference/datamodel.html#object.__pow__" title="object.__pow__"><code class="xref py py-func docutils literal notranslate"><span class="pre">object.__pow__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__rpow__" title="object.__rpow__"><code class="xref py py-func docutils literal notranslate"><span class="pre">object.__rpow__()</span></code></a> as expected.
  976. (Contributed by Alex Shkop in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38302">bpo-38302</a>.)</p></li>
  977. <li><p>Assignment expressions can now be used unparenthesized within set literals
  978. and set comprehensions, as well as in sequence indexes (but not slices).</p></li>
  979. <li><p>Functions have a new <code class="docutils literal notranslate"><span class="pre">__builtins__</span></code> attribute which is used to look for
  980. builtin symbols when a function is executed, instead of looking into
  981. <code class="docutils literal notranslate"><span class="pre">__globals__['__builtins__']</span></code>. The attribute is initialized from
  982. <code class="docutils literal notranslate"><span class="pre">__globals__[&quot;__builtins__&quot;]</span></code> if it exists, else from the current builtins.
  983. (Contributed by Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42990">bpo-42990</a>.)</p></li>
  984. <li><p>Two new builtin functions – <a class="reference internal" href="../library/functions.html#aiter" title="aiter"><code class="xref py py-func docutils literal notranslate"><span class="pre">aiter()</span></code></a> and <a class="reference internal" href="../library/functions.html#anext" title="anext"><code class="xref py py-func docutils literal notranslate"><span class="pre">anext()</span></code></a> have been added
  985. to provide asynchronous counterparts to <a class="reference internal" href="../library/functions.html#iter" title="iter"><code class="xref py py-func docutils literal notranslate"><span class="pre">iter()</span></code></a> and <a class="reference internal" href="../library/functions.html#next" title="next"><code class="xref py py-func docutils literal notranslate"><span class="pre">next()</span></code></a>,
  986. respectively.
  987. (Contributed by Joshua Bronson, Daniel Pope, and Justin Wang in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31861">bpo-31861</a>.)</p></li>
  988. <li><p>Static methods (<a class="reference internal" href="../library/functions.html#staticmethod" title="staticmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">&#64;staticmethod</span></code></a>) and class methods
  989. (<a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">&#64;classmethod</span></code></a>) now inherit the method attributes
  990. (<code class="docutils literal notranslate"><span class="pre">__module__</span></code>, <code class="docutils literal notranslate"><span class="pre">__name__</span></code>, <code class="docutils literal notranslate"><span class="pre">__qualname__</span></code>, <code class="docutils literal notranslate"><span class="pre">__doc__</span></code>,
  991. <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code>) and have a new <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute.
  992. Moreover, static methods are now callable as regular functions.
  993. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43682">bpo-43682</a>.)</p></li>
  994. <li><p>Annotations for complex targets (everything beside <code class="docutils literal notranslate"><span class="pre">simple</span> <span class="pre">name</span></code> targets
  995. defined by <span class="target" id="index-27"></span><a class="pep reference external" href="https://peps.python.org/pep-0526/"><strong>PEP 526</strong></a>) no longer cause any runtime effects with <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">annotations</span></code>.
  996. (Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42737">bpo-42737</a>.)</p></li>
  997. <li><p>Class and module objects now lazy-create empty annotations dicts on demand.
  998. The annotations dicts are stored in the object’s <code class="docutils literal notranslate"><span class="pre">__dict__</span></code> for
  999. backwards compatibility. This improves the best practices for working
  1000. with <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code>; for more information, please see
  1001. <a class="reference internal" href="../howto/annotations.html#annotations-howto"><span class="std std-ref">Annotations Best Practices</span></a>.
  1002. (Contributed by Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43901">bpo-43901</a>.)</p></li>
  1003. <li><p>Annotations consist of <code class="docutils literal notranslate"><span class="pre">yield</span></code>, <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code>, <code class="docutils literal notranslate"><span class="pre">await</span></code> or named expressions
  1004. are now forbidden under <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">annotations</span></code> due to their side
  1005. effects.
  1006. (Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42725">bpo-42725</a>.)</p></li>
  1007. <li><p>Usage of unbound variables, <code class="docutils literal notranslate"><span class="pre">super()</span></code> and other expressions that might
  1008. alter the processing of symbol table as annotations are now rendered
  1009. effectless under <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">annotations</span></code>.
  1010. (Contributed by Batuhan Taskaya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42725">bpo-42725</a>.)</p></li>
  1011. <li><p>Hashes of NaN values of both <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> type and
  1012. <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">decimal.Decimal</span></code></a> type now depend on object identity. Formerly, they
  1013. always hashed to <code class="docutils literal notranslate"><span class="pre">0</span></code> even though NaN values are not equal to one another.
  1014. This caused potentially quadratic runtime behavior due to excessive hash
  1015. collisions when creating dictionaries and sets containing multiple NaNs.
  1016. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43475">bpo-43475</a>.)</p></li>
  1017. <li><p>A <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> (instead of a <a class="reference internal" href="../library/exceptions.html#NameError" title="NameError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NameError</span></code></a>) will be raised when deleting
  1018. the <a class="reference internal" href="../library/constants.html#debug__" title="__debug__"><code class="xref py py-const docutils literal notranslate"><span class="pre">__debug__</span></code></a> constant. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45000">bpo-45000</a>.)</p></li>
  1019. <li><p><a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a> exceptions now have <code class="docutils literal notranslate"><span class="pre">end_lineno</span></code> and
  1020. <code class="docutils literal notranslate"><span class="pre">end_offset</span></code> attributes. They will be <code class="docutils literal notranslate"><span class="pre">None</span></code> if not determined.
  1021. (Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43914">bpo-43914</a>.)</p></li>
  1022. </ul>
  1023. </section>
  1024. <section id="new-modules">
  1025. <h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading">¶</a></h2>
  1026. <ul class="simple">
  1027. <li><p>None.</p></li>
  1028. </ul>
  1029. </section>
  1030. <section id="improved-modules">
  1031. <h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading">¶</a></h2>
  1032. <section id="asyncio">
  1033. <h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading">¶</a></h3>
  1034. <p>Add missing <code class="xref py py-meth docutils literal notranslate"><span class="pre">connect_accepted_socket()</span></code>
  1035. method.
  1036. (Contributed by Alex Grönholm in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41332">bpo-41332</a>.)</p>
  1037. </section>
  1038. <section id="argparse">
  1039. <h3>argparse<a class="headerlink" href="#argparse" title="Link to this heading">¶</a></h3>
  1040. <p>Misleading phrase “optional arguments” was replaced with “options” in argparse help. Some tests might require adaptation if they rely on exact output match.
  1041. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9694">bpo-9694</a>.)</p>
  1042. </section>
  1043. <section id="array">
  1044. <h3>array<a class="headerlink" href="#array" title="Link to this heading">¶</a></h3>
  1045. <p>The <a class="reference internal" href="../library/array.html#array.array.index" title="array.array.index"><code class="xref py py-meth docutils literal notranslate"><span class="pre">index()</span></code></a> method of <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> now has
  1046. optional <em>start</em> and <em>stop</em> parameters.
  1047. (Contributed by Anders Lorentsen and Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31956">bpo-31956</a>.)</p>
  1048. </section>
  1049. <section id="asynchat-asyncore-smtpd">
  1050. <h3>asynchat, asyncore, smtpd<a class="headerlink" href="#asynchat-asyncore-smtpd" title="Link to this heading">¶</a></h3>
  1051. <p>These modules have been marked as deprecated in their module documentation
  1052. since Python 3.6. An import-time <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-class docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> has now been
  1053. added to all three of these modules.</p>
  1054. </section>
  1055. <section id="base64">
  1056. <h3>base64<a class="headerlink" href="#base64" title="Link to this heading">¶</a></h3>
  1057. <p>Add <a class="reference internal" href="../library/base64.html#base64.b32hexencode" title="base64.b32hexencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">base64.b32hexencode()</span></code></a> and <a class="reference internal" href="../library/base64.html#base64.b32hexdecode" title="base64.b32hexdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">base64.b32hexdecode()</span></code></a> to support the
  1058. Base32 Encoding with Extended Hex Alphabet.</p>
  1059. </section>
  1060. <section id="bdb">
  1061. <h3>bdb<a class="headerlink" href="#bdb" title="Link to this heading">¶</a></h3>
  1062. <p>Add <code class="xref py py-meth docutils literal notranslate"><span class="pre">clearBreakpoints()</span></code> to reset all set breakpoints.
  1063. (Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24160">bpo-24160</a>.)</p>
  1064. </section>
  1065. <section id="bisect">
  1066. <h3>bisect<a class="headerlink" href="#bisect" title="Link to this heading">¶</a></h3>
  1067. <p>Added the possibility of providing a <em>key</em> function to the APIs in the <a class="reference internal" href="../library/bisect.html#module-bisect" title="bisect: Array bisection algorithms for binary searching."><code class="xref py py-mod docutils literal notranslate"><span class="pre">bisect</span></code></a>
  1068. module. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4356">bpo-4356</a>.)</p>
  1069. </section>
  1070. <section id="codecs">
  1071. <h3>codecs<a class="headerlink" href="#codecs" title="Link to this heading">¶</a></h3>
  1072. <p>Add a <a class="reference internal" href="../library/codecs.html#codecs.unregister" title="codecs.unregister"><code class="xref py py-func docutils literal notranslate"><span class="pre">codecs.unregister()</span></code></a> function to unregister a codec search function.
  1073. (Contributed by Hai Shi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41842">bpo-41842</a>.)</p>
  1074. </section>
  1075. <section id="collections-abc">
  1076. <h3>collections.abc<a class="headerlink" href="#collections-abc" title="Link to this heading">¶</a></h3>
  1077. <p>The <code class="docutils literal notranslate"><span class="pre">__args__</span></code> of the <a class="reference internal" href="../library/stdtypes.html#types-genericalias"><span class="std std-ref">parameterized generic</span></a> for
  1078. <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> are now consistent with <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>.
  1079. <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
  1080. 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
  1081. <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
  1082. <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
  1083. 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
  1084. 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. Note
  1085. that 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> may be raised for invalid forms of parameterizing
  1086. <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 passed silently in Python 3.9.
  1087. (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>
  1088. </section>
  1089. <section id="contextlib">
  1090. <h3>contextlib<a class="headerlink" href="#contextlib" title="Link to this heading">¶</a></h3>
  1091. <p>Add a <a class="reference internal" href="../library/contextlib.html#contextlib.aclosing" title="contextlib.aclosing"><code class="xref py py-func docutils literal notranslate"><span class="pre">contextlib.aclosing()</span></code></a> context manager to safely close async generators
  1092. and objects representing asynchronously released resources.
  1093. (Contributed by Joongi Kim and John Belmonte in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41229">bpo-41229</a>.)</p>
  1094. <p>Add asynchronous context manager support to <a class="reference internal" href="../library/contextlib.html#contextlib.nullcontext" title="contextlib.nullcontext"><code class="xref py py-func docutils literal notranslate"><span class="pre">contextlib.nullcontext()</span></code></a>.
  1095. (Contributed by Tom Gringauz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41543">bpo-41543</a>.)</p>
  1096. <p>Add <code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncContextDecorator</span></code>, for supporting usage of async context managers
  1097. as decorators.</p>
  1098. </section>
  1099. <section id="curses">
  1100. <h3>curses<a class="headerlink" href="#curses" title="Link to this heading">¶</a></h3>
  1101. <p>The extended color functions added in ncurses 6.1 will be used transparently
  1102. by <a class="reference internal" href="../library/curses.html#curses.color_content" title="curses.color_content"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.color_content()</span></code></a>, <a class="reference internal" href="../library/curses.html#curses.init_color" title="curses.init_color"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.init_color()</span></code></a>,
  1103. <a class="reference internal" href="../library/curses.html#curses.init_pair" title="curses.init_pair"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.init_pair()</span></code></a>, and <a class="reference internal" href="../library/curses.html#curses.pair_content" title="curses.pair_content"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.pair_content()</span></code></a>. A new function,
  1104. <a class="reference internal" href="../library/curses.html#curses.has_extended_color_support" title="curses.has_extended_color_support"><code class="xref py py-func docutils literal notranslate"><span class="pre">curses.has_extended_color_support()</span></code></a>, indicates whether extended color
  1105. support is provided by the underlying ncurses library.
  1106. (Contributed by Jeffrey Kintscher and Hans Petter Jansson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36982">bpo-36982</a>.)</p>
  1107. <p>The <code class="docutils literal notranslate"><span class="pre">BUTTON5_*</span></code> constants are now exposed in the <a class="reference internal" href="../library/curses.html#module-curses" title="curses: An interface to the curses library, providing portable terminal handling. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses</span></code></a> module if
  1108. they are provided by the underlying curses library.
  1109. (Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39273">bpo-39273</a>.)</p>
  1110. </section>
  1111. <section id="dataclasses">
  1112. <h3>dataclasses<a class="headerlink" href="#dataclasses" title="Link to this heading">¶</a></h3>
  1113. <section id="slots">
  1114. <h4>__slots__<a class="headerlink" href="#slots" title="Link to this heading">¶</a></h4>
  1115. <p>Added <code class="docutils literal notranslate"><span class="pre">slots</span></code> parameter in <a class="reference internal" href="../library/dataclasses.html#dataclasses.dataclass" title="dataclasses.dataclass"><code class="xref py py-func docutils literal notranslate"><span class="pre">dataclasses.dataclass()</span></code></a> decorator.
  1116. (Contributed by Yurii Karabas in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42269">bpo-42269</a>)</p>
  1117. </section>
  1118. <section id="keyword-only-fields">
  1119. <h4>Keyword-only fields<a class="headerlink" href="#keyword-only-fields" title="Link to this heading">¶</a></h4>
  1120. <p>dataclasses now supports fields that are keyword-only in the
  1121. generated __init__ method. There are a number of ways of specifying
  1122. keyword-only fields.</p>
  1123. <p>You can say that every field is keyword-only:</p>
  1124. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">dataclasses</span> <span class="kn">import</span> <span class="n">dataclass</span>
  1125. <span class="nd">@dataclass</span><span class="p">(</span><span class="n">kw_only</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
  1126. <span class="k">class</span> <span class="nc">Birthday</span><span class="p">:</span>
  1127. <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>
  1128. <span class="n">birthday</span><span class="p">:</span> <span class="n">datetime</span><span class="o">.</span><span class="n">date</span>
  1129. </pre></div>
  1130. </div>
  1131. <p>Both <code class="docutils literal notranslate"><span class="pre">name</span></code> and <code class="docutils literal notranslate"><span class="pre">birthday</span></code> are keyword-only parameters to the
  1132. generated __init__ method.</p>
  1133. <p>You can specify keyword-only on a per-field basis:</p>
  1134. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">dataclasses</span> <span class="kn">import</span> <span class="n">dataclass</span><span class="p">,</span> <span class="n">field</span>
  1135. <span class="nd">@dataclass</span>
  1136. <span class="k">class</span> <span class="nc">Birthday</span><span class="p">:</span>
  1137. <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>
  1138. <span class="n">birthday</span><span class="p">:</span> <span class="n">datetime</span><span class="o">.</span><span class="n">date</span> <span class="o">=</span> <span class="n">field</span><span class="p">(</span><span class="n">kw_only</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
  1139. </pre></div>
  1140. </div>
  1141. <p>Here only <code class="docutils literal notranslate"><span class="pre">birthday</span></code> is keyword-only. If you set <code class="docutils literal notranslate"><span class="pre">kw_only</span></code> on
  1142. individual fields, be aware that there are rules about re-ordering
  1143. fields due to keyword-only fields needing to follow non-keyword-only
  1144. fields. See the full dataclasses documentation for details.</p>
  1145. <p>You can also specify that all fields following a KW_ONLY marker are
  1146. keyword-only. This will probably be the most common usage:</p>
  1147. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">dataclasses</span> <span class="kn">import</span> <span class="n">dataclass</span><span class="p">,</span> <span class="n">KW_ONLY</span>
  1148. <span class="nd">@dataclass</span>
  1149. <span class="k">class</span> <span class="nc">Point</span><span class="p">:</span>
  1150. <span class="n">x</span><span class="p">:</span> <span class="nb">float</span>
  1151. <span class="n">y</span><span class="p">:</span> <span class="nb">float</span>
  1152. <span class="n">_</span><span class="p">:</span> <span class="n">KW_ONLY</span>
  1153. <span class="n">z</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.0</span>
  1154. <span class="n">t</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.0</span>
  1155. </pre></div>
  1156. </div>
  1157. <p>Here, <code class="docutils literal notranslate"><span class="pre">z</span></code> and <code class="docutils literal notranslate"><span class="pre">t</span></code> are keyword-only parameters, while <code class="docutils literal notranslate"><span class="pre">x</span></code> and
  1158. <code class="docutils literal notranslate"><span class="pre">y</span></code> are not.
  1159. (Contributed by Eric V. Smith in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43532">bpo-43532</a>.)</p>
  1160. </section>
  1161. </section>
  1162. <section id="distutils">
  1163. <span id="distutils-deprecated"></span><h3>distutils<a class="headerlink" href="#distutils" title="Link to this heading">¶</a></h3>
  1164. <p>The entire <code class="docutils literal notranslate"><span class="pre">distutils</span></code> package is deprecated, to be removed in Python
  1165. 3.12. Its functionality for specifying package builds has already been
  1166. completely replaced by third-party packages <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> and
  1167. <code class="docutils literal notranslate"><span class="pre">packaging</span></code>, and most other commonly used APIs are available elsewhere
  1168. in the standard library (such as <a class="reference internal" href="../library/platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code></a>, <a class="reference internal" href="../library/shutil.html#module-shutil" title="shutil: High-level file operations, including copying."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shutil</span></code></a>,
  1169. <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> or <a class="reference internal" href="../library/sysconfig.html#module-sysconfig" title="sysconfig: Python's configuration information"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sysconfig</span></code></a>). There are no plans to migrate
  1170. any other functionality from <code class="docutils literal notranslate"><span class="pre">distutils</span></code>, and applications that are
  1171. using other functions should plan to make private copies of the code.
  1172. Refer to <span class="target" id="index-28"></span><a class="pep reference external" href="https://peps.python.org/pep-0632/"><strong>PEP 632</strong></a> for discussion.</p>
  1173. <p>The <code class="docutils literal notranslate"><span class="pre">bdist_wininst</span></code> command deprecated in Python 3.8 has been removed.
  1174. The <code class="docutils literal notranslate"><span class="pre">bdist_wheel</span></code> command is now recommended to distribute binary packages
  1175. on Windows.
  1176. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42802">bpo-42802</a>.)</p>
  1177. </section>
  1178. <section id="doctest">
  1179. <h3>doctest<a class="headerlink" href="#doctest" title="Link to this heading">¶</a></h3>
  1180. <p>When a module does not define <code class="docutils literal notranslate"><span class="pre">__loader__</span></code>, fall back to <code class="docutils literal notranslate"><span class="pre">__spec__.loader</span></code>.
  1181. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42133">bpo-42133</a>.)</p>
  1182. </section>
  1183. <section id="encodings">
  1184. <h3>encodings<a class="headerlink" href="#encodings" title="Link to this heading">¶</a></h3>
  1185. <p><code class="xref py py-func docutils literal notranslate"><span class="pre">encodings.normalize_encoding()</span></code> now ignores non-ASCII characters.
  1186. (Contributed by Hai Shi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39337">bpo-39337</a>.)</p>
  1187. </section>
  1188. <section id="enum">
  1189. <h3>enum<a class="headerlink" href="#enum" title="Link to this heading">¶</a></h3>
  1190. <p><code class="xref py py-class docutils literal notranslate"><span class="pre">Enum</span></code> <code class="xref py py-func docutils literal notranslate"><span class="pre">__repr__()</span></code> now returns <code class="docutils literal notranslate"><span class="pre">enum_name.member_name</span></code> and
  1191. <code class="xref py py-func docutils literal notranslate"><span class="pre">__str__()</span></code> now returns <code class="docutils literal notranslate"><span class="pre">member_name</span></code>. Stdlib enums available as
  1192. module constants have a <a class="reference internal" href="../library/functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a> of <code class="docutils literal notranslate"><span class="pre">module_name.member_name</span></code>.
  1193. (Contributed by Ethan Furman in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40066">bpo-40066</a>.)</p>
  1194. <p>Add <a class="reference internal" href="../library/enum.html#enum.StrEnum" title="enum.StrEnum"><code class="xref py py-class docutils literal notranslate"><span class="pre">enum.StrEnum</span></code></a> for enums where all members are strings.
  1195. (Contributed by Ethan Furman in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41816">bpo-41816</a>.)</p>
  1196. </section>
  1197. <section id="fileinput">
  1198. <h3>fileinput<a class="headerlink" href="#fileinput" title="Link to this heading">¶</a></h3>
  1199. <p>Add <em>encoding</em> and <em>errors</em> parameters in <a class="reference internal" href="../library/fileinput.html#fileinput.input" title="fileinput.input"><code class="xref py py-func docutils literal notranslate"><span class="pre">fileinput.input()</span></code></a> and
  1200. <a class="reference internal" href="../library/fileinput.html#fileinput.FileInput" title="fileinput.FileInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">fileinput.FileInput</span></code></a>.
  1201. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43712">bpo-43712</a>.)</p>
  1202. <p><a class="reference internal" href="../library/fileinput.html#fileinput.hook_compressed" title="fileinput.hook_compressed"><code class="xref py py-func docutils literal notranslate"><span class="pre">fileinput.hook_compressed()</span></code></a> now returns <code class="xref py py-class docutils literal notranslate"><span class="pre">TextIOWrapper</span></code> object
  1203. when <em>mode</em> is “r” and file is compressed, like uncompressed files.
  1204. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5758">bpo-5758</a>.)</p>
  1205. </section>
  1206. <section id="faulthandler">
  1207. <h3>faulthandler<a class="headerlink" href="#faulthandler" title="Link to this heading">¶</a></h3>
  1208. <p>The <a class="reference internal" href="../library/faulthandler.html#module-faulthandler" title="faulthandler: Dump the Python traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code></a> module now detects if a fatal error occurs during a
  1209. garbage collector collection.
  1210. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44466">bpo-44466</a>.)</p>
  1211. </section>
  1212. <section id="gc">
  1213. <h3>gc<a class="headerlink" href="#gc" title="Link to this heading">¶</a></h3>
  1214. <p>Add audit hooks for <a class="reference internal" href="../library/gc.html#gc.get_objects" title="gc.get_objects"><code class="xref py py-func docutils literal notranslate"><span class="pre">gc.get_objects()</span></code></a>, <a class="reference internal" href="../library/gc.html#gc.get_referrers" title="gc.get_referrers"><code class="xref py py-func docutils literal notranslate"><span class="pre">gc.get_referrers()</span></code></a> and
  1215. <a class="reference internal" href="../library/gc.html#gc.get_referents" title="gc.get_referents"><code class="xref py py-func docutils literal notranslate"><span class="pre">gc.get_referents()</span></code></a>. (Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43439">bpo-43439</a>.)</p>
  1216. </section>
  1217. <section id="glob">
  1218. <h3>glob<a class="headerlink" href="#glob" title="Link to this heading">¶</a></h3>
  1219. <p>Add the <em>root_dir</em> and <em>dir_fd</em> parameters in <a class="reference internal" href="../library/glob.html#glob.glob" title="glob.glob"><code class="xref py py-func docutils literal notranslate"><span class="pre">glob()</span></code></a> and
  1220. <a class="reference internal" href="../library/glob.html#glob.iglob" title="glob.iglob"><code class="xref py py-func docutils literal notranslate"><span class="pre">iglob()</span></code></a> which allow to specify the root directory for searching.
  1221. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38144">bpo-38144</a>.)</p>
  1222. </section>
  1223. <section id="hashlib">
  1224. <h3>hashlib<a class="headerlink" href="#hashlib" title="Link to this heading">¶</a></h3>
  1225. <p>The hashlib module requires OpenSSL 1.1.1 or newer.
  1226. (Contributed by Christian Heimes in <span class="target" id="index-29"></span><a class="pep reference external" href="https://peps.python.org/pep-0644/"><strong>PEP 644</strong></a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43669">bpo-43669</a>.)</p>
  1227. <p>The hashlib module has preliminary support for OpenSSL 3.0.0.
  1228. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38820">bpo-38820</a> and other issues.)</p>
  1229. <p>The pure-Python fallback of <a class="reference internal" href="../library/hashlib.html#hashlib.pbkdf2_hmac" title="hashlib.pbkdf2_hmac"><code class="xref py py-func docutils literal notranslate"><span class="pre">pbkdf2_hmac()</span></code></a> is deprecated. In
  1230. the future PBKDF2-HMAC will only be available when Python has been built with
  1231. OpenSSL support.
  1232. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43880">bpo-43880</a>.)</p>
  1233. </section>
  1234. <section id="hmac">
  1235. <h3>hmac<a class="headerlink" href="#hmac" title="Link to this heading">¶</a></h3>
  1236. <p>The hmac module now uses OpenSSL’s HMAC implementation internally.
  1237. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40645">bpo-40645</a>.)</p>
  1238. </section>
  1239. <section id="idle-and-idlelib">
  1240. <h3>IDLE and idlelib<a class="headerlink" href="#idle-and-idlelib" title="Link to this heading">¶</a></h3>
  1241. <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’).
  1242. User hooks were previously ignored. (Contributed by Ken Hilton in
  1243. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43008">bpo-43008</a>.)</p>
  1244. <p>Rearrange the settings dialog. Split the General tab into Windows
  1245. and Shell/Ed tabs. Move help sources, which extend the Help menu, to the
  1246. Extensions tab. Make space for new options and shorten the dialog. The
  1247. latter makes the dialog better fit small screens. (Contributed by Terry Jan
  1248. 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
  1249. the new Windows tab. (Contributed by Mark Roseman and Terry Jan Reedy in
  1250. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33962">bpo-33962</a>.)</p>
  1251. <p>The changes above were backported to a 3.9 maintenance release.</p>
  1252. <p>Add a Shell sidebar. Move the primary prompt (‘&gt;&gt;&gt;’) to the sidebar.
  1253. Add secondary prompts (’…’) to the sidebar. Left click and optional
  1254. drag selects one or more lines of text, as with the editor
  1255. line number sidebar. Right click after selecting text lines displays
  1256. a context menu with ‘copy with prompts’. This zips together prompts
  1257. from the sidebar with lines from the selected text. This option also
  1258. appears on the context menu for the text. (Contributed by Tal Einat
  1259. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37903">bpo-37903</a>.)</p>
  1260. <p>Use spaces instead of tabs to indent interactive code. This makes
  1261. interactive code entries ‘look right’. Making this feasible was a
  1262. major motivation for adding the shell sidebar. (Contributed by
  1263. Terry Jan Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37892">bpo-37892</a>.)</p>
  1264. <p>Highlight the new <a class="reference internal" href="../reference/lexical_analysis.html#soft-keywords"><span class="std std-ref">soft keywords</span></a> <a class="reference internal" href="../reference/compound_stmts.html#match"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">match</span></code></a>,
  1265. <a class="reference internal" href="../reference/compound_stmts.html#match"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">case</span></code></a>, and <a class="reference internal" href="../reference/compound_stmts.html#wildcard-patterns"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">_</span></code></a> in
  1266. pattern-matching statements. However, this highlighting is not perfect
  1267. and will be incorrect in some rare cases, including some <code class="docutils literal notranslate"><span class="pre">_</span></code>-s in
  1268. <code class="docutils literal notranslate"><span class="pre">case</span></code> patterns. (Contributed by Tal Einat in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44010">bpo-44010</a>.)</p>
  1269. <p>New in 3.10 maintenance releases.</p>
  1270. <p>Apply syntax highlighting to <code class="docutils literal notranslate"><span class="pre">.pyi</span></code> files. (Contributed by Alex
  1271. 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>
  1272. <p>Include prompts when saving Shell with inputs and outputs.
  1273. (Contributed by Terry Jan Reedy in <a class="reference external" href="https://github.com/python/cpython/issues/95191">gh-95191</a>.)</p>
  1274. </section>
  1275. <section id="importlib-metadata">
  1276. <h3>importlib.metadata<a class="headerlink" href="#importlib-metadata" title="Link to this heading">¶</a></h3>
  1277. <p>Feature parity with <code class="docutils literal notranslate"><span class="pre">importlib_metadata</span></code> 4.6
  1278. (<a class="reference external" href="https://importlib-metadata.readthedocs.io/en/latest/history.html">history</a>).</p>
  1279. <p><a class="reference internal" href="../library/importlib.metadata.html#entry-points"><span class="std std-ref">importlib.metadata entry points</span></a>
  1280. now provide a nicer experience
  1281. for selecting entry points by group and name through a new
  1282. <code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.metadata.EntryPoints</span></code> class. See the Compatibility
  1283. Note in the docs for more info on the deprecation and usage.</p>
  1284. <p>Added <code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.metadata.packages_distributions()</span></code> for resolving
  1285. top-level Python modules and packages to their
  1286. <code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.metadata.Distribution</span></code>.</p>
  1287. </section>
  1288. <section id="inspect">
  1289. <h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading">¶</a></h3>
  1290. <p>When a module does not define <code class="docutils literal notranslate"><span class="pre">__loader__</span></code>, fall back to <code class="docutils literal notranslate"><span class="pre">__spec__.loader</span></code>.
  1291. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42133">bpo-42133</a>.)</p>
  1292. <p>Add <a class="reference internal" href="../library/inspect.html#inspect.get_annotations" title="inspect.get_annotations"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.get_annotations()</span></code></a>, which safely computes the annotations
  1293. defined on an object. It works around the quirks of accessing the annotations
  1294. on various types of objects, and makes very few assumptions about the object
  1295. it examines. <a class="reference internal" href="../library/inspect.html#inspect.get_annotations" title="inspect.get_annotations"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.get_annotations()</span></code></a> can also correctly un-stringize
  1296. stringized annotations. <a class="reference internal" href="../library/inspect.html#inspect.get_annotations" title="inspect.get_annotations"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.get_annotations()</span></code></a> is now considered
  1297. best practice for accessing the annotations dict defined on any Python object;
  1298. for more information on best practices for working with annotations, please see
  1299. <a class="reference internal" href="../howto/annotations.html#annotations-howto"><span class="std std-ref">Annotations Best Practices</span></a>.
  1300. Relatedly, <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.signature()</span></code></a>,
  1301. <a class="reference internal" href="../library/inspect.html#inspect.Signature.from_callable" title="inspect.Signature.from_callable"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.Signature.from_callable()</span></code></a>, and <code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.Signature.from_function()</span></code>
  1302. now call <a class="reference internal" href="../library/inspect.html#inspect.get_annotations" title="inspect.get_annotations"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.get_annotations()</span></code></a> to retrieve annotations. This means
  1303. <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.signature()</span></code></a> and <a class="reference internal" href="../library/inspect.html#inspect.Signature.from_callable" title="inspect.Signature.from_callable"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.Signature.from_callable()</span></code></a> can
  1304. also now un-stringize stringized annotations.
  1305. (Contributed by Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43817">bpo-43817</a>.)</p>
  1306. </section>
  1307. <section id="itertools">
  1308. <h3>itertools<a class="headerlink" href="#itertools" title="Link to this heading">¶</a></h3>
  1309. <p>Add <a class="reference internal" href="../library/itertools.html#itertools.pairwise" title="itertools.pairwise"><code class="xref py py-func docutils literal notranslate"><span class="pre">itertools.pairwise()</span></code></a>.
  1310. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38200">bpo-38200</a>.)</p>
  1311. </section>
  1312. <section id="linecache">
  1313. <h3>linecache<a class="headerlink" href="#linecache" title="Link to this heading">¶</a></h3>
  1314. <p>When a module does not define <code class="docutils literal notranslate"><span class="pre">__loader__</span></code>, fall back to <code class="docutils literal notranslate"><span class="pre">__spec__.loader</span></code>.
  1315. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42133">bpo-42133</a>.)</p>
  1316. </section>
  1317. <section id="os">
  1318. <h3>os<a class="headerlink" href="#os" title="Link to this heading">¶</a></h3>
  1319. <p>Add <a class="reference internal" href="../library/os.html#os.cpu_count" title="os.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.cpu_count()</span></code></a> support for VxWorks RTOS.
  1320. (Contributed by Peixing Xin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41440">bpo-41440</a>.)</p>
  1321. <p>Add a new function <a class="reference internal" href="../library/os.html#os.eventfd" title="os.eventfd"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.eventfd()</span></code></a> and related helpers to wrap the
  1322. <code class="docutils literal notranslate"><span class="pre">eventfd2</span></code> syscall on Linux.
  1323. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41001">bpo-41001</a>.)</p>
  1324. <p>Add <a class="reference internal" href="../library/os.html#os.splice" title="os.splice"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.splice()</span></code></a> that allows to move data between two file
  1325. descriptors without copying between kernel address space and user
  1326. address space, where one of the file descriptors must refer to a
  1327. pipe. (Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41625">bpo-41625</a>.)</p>
  1328. <p>Add <a class="reference internal" href="../library/os.html#os.O_EVTONLY" title="os.O_EVTONLY"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_EVTONLY</span></code></a>, <a class="reference internal" href="../library/os.html#os.O_FSYNC" title="os.O_FSYNC"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_FSYNC</span></code></a>, <a class="reference internal" href="../library/os.html#os.O_SYMLINK" title="os.O_SYMLINK"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_SYMLINK</span></code></a>
  1329. and <a class="reference internal" href="../library/os.html#os.O_NOFOLLOW_ANY" title="os.O_NOFOLLOW_ANY"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_NOFOLLOW_ANY</span></code></a> for macOS.
  1330. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43106">bpo-43106</a>.)</p>
  1331. </section>
  1332. <section id="os-path">
  1333. <h3>os.path<a class="headerlink" href="#os-path" title="Link to this heading">¶</a></h3>
  1334. <p><a class="reference internal" href="../library/os.path.html#os.path.realpath" title="os.path.realpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.realpath()</span></code></a> now accepts a <em>strict</em> keyword-only argument. When set
  1335. to <code class="docutils literal notranslate"><span class="pre">True</span></code>, <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is raised if a path doesn’t exist or a symlink loop
  1336. is encountered.
  1337. (Contributed by Barney Gale in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43757">bpo-43757</a>.)</p>
  1338. </section>
  1339. <section id="pathlib">
  1340. <h3>pathlib<a class="headerlink" href="#pathlib" title="Link to this heading">¶</a></h3>
  1341. <p>Add slice support to <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.parents" title="pathlib.PurePath.parents"><code class="xref py py-attr docutils literal notranslate"><span class="pre">PurePath.parents</span></code></a>.
  1342. (Contributed by Joshua Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35498">bpo-35498</a>.)</p>
  1343. <p>Add negative indexing support to <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.parents" title="pathlib.PurePath.parents"><code class="xref py py-attr docutils literal notranslate"><span class="pre">PurePath.parents</span></code></a>.
  1344. (Contributed by Yaroslav Pankovych in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21041">bpo-21041</a>.)</p>
  1345. <p>Add <a class="reference internal" href="../library/pathlib.html#pathlib.Path.hardlink_to" title="pathlib.Path.hardlink_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Path.hardlink_to</span></code></a> method that
  1346. supersedes <code class="xref py py-meth docutils literal notranslate"><span class="pre">link_to()</span></code>. The new method has the same argument
  1347. order as <a class="reference internal" href="../library/pathlib.html#pathlib.Path.symlink_to" title="pathlib.Path.symlink_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">symlink_to()</span></code></a>.
  1348. (Contributed by Barney Gale in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39950">bpo-39950</a>.)</p>
  1349. <p><a class="reference internal" href="../library/pathlib.html#pathlib.Path.stat" title="pathlib.Path.stat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.stat()</span></code></a> and <a class="reference internal" href="../library/pathlib.html#pathlib.Path.chmod" title="pathlib.Path.chmod"><code class="xref py py-meth docutils literal notranslate"><span class="pre">chmod()</span></code></a> now accept a
  1350. <em>follow_symlinks</em> keyword-only argument for consistency with corresponding
  1351. functions in the <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module.
  1352. (Contributed by Barney Gale in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39906">bpo-39906</a>.)</p>
  1353. </section>
  1354. <section id="platform">
  1355. <h3>platform<a class="headerlink" href="#platform" title="Link to this heading">¶</a></h3>
  1356. <p>Add <a class="reference internal" href="../library/platform.html#platform.freedesktop_os_release" title="platform.freedesktop_os_release"><code class="xref py py-func docutils literal notranslate"><span class="pre">platform.freedesktop_os_release()</span></code></a> to retrieve operation system
  1357. identification from <a class="reference external" href="https://www.freedesktop.org/software/systemd/man/os-release.html">freedesktop.org os-release</a> standard file.
  1358. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28468">bpo-28468</a>.)</p>
  1359. </section>
  1360. <section id="pprint">
  1361. <h3>pprint<a class="headerlink" href="#pprint" title="Link to this heading">¶</a></h3>
  1362. <p><a class="reference internal" href="../library/pprint.html#pprint.pprint" title="pprint.pprint"><code class="xref py py-func docutils literal notranslate"><span class="pre">pprint.pprint()</span></code></a> now accepts a new <code class="docutils literal notranslate"><span class="pre">underscore_numbers</span></code> keyword argument.
  1363. (Contributed by sblondon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42914">bpo-42914</a>.)</p>
  1364. <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/dataclasses.html#dataclasses.dataclass" title="dataclasses.dataclass"><code class="xref py py-class docutils literal notranslate"><span class="pre">dataclasses.dataclass</span></code></a> instances.
  1365. (Contributed by Lewis Gaul in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43080">bpo-43080</a>.)</p>
  1366. </section>
  1367. <section id="py-compile">
  1368. <h3>py_compile<a class="headerlink" href="#py-compile" title="Link to this heading">¶</a></h3>
  1369. <p>Add <code class="docutils literal notranslate"><span class="pre">--quiet</span></code> option to command-line interface of <a class="reference internal" href="../library/py_compile.html#module-py_compile" title="py_compile: Generate byte-code files from Python source files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code></a>.
  1370. (Contributed by Gregory Schevchenko in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38731">bpo-38731</a>.)</p>
  1371. </section>
  1372. <section id="pyclbr">
  1373. <h3>pyclbr<a class="headerlink" href="#pyclbr" title="Link to this heading">¶</a></h3>
  1374. <p>Add an <code class="docutils literal notranslate"><span class="pre">end_lineno</span></code> attribute to the <code class="docutils literal notranslate"><span class="pre">Function</span></code> and <code class="docutils literal notranslate"><span class="pre">Class</span></code>
  1375. objects in the tree returned by <a class="reference internal" href="../library/pyclbr.html#pyclbr.readmodule" title="pyclbr.readmodule"><code class="xref py py-func docutils literal notranslate"><span class="pre">pyclbr.readmodule()</span></code></a> and
  1376. <a class="reference internal" href="../library/pyclbr.html#pyclbr.readmodule_ex" title="pyclbr.readmodule_ex"><code class="xref py py-func docutils literal notranslate"><span class="pre">pyclbr.readmodule_ex()</span></code></a>. It matches the existing (start) <code class="docutils literal notranslate"><span class="pre">lineno</span></code>.
  1377. (Contributed by Aviral Srivastava in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38307">bpo-38307</a>.)</p>
  1378. </section>
  1379. <section id="shelve">
  1380. <h3>shelve<a class="headerlink" href="#shelve" title="Link to this heading">¶</a></h3>
  1381. <p>The <a class="reference internal" href="../library/shelve.html#module-shelve" title="shelve: Python object persistence."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shelve</span></code></a> module now uses <a class="reference internal" href="../library/pickle.html#pickle.DEFAULT_PROTOCOL" title="pickle.DEFAULT_PROTOCOL"><code class="xref py py-const docutils literal notranslate"><span class="pre">pickle.DEFAULT_PROTOCOL</span></code></a> by default
  1382. instead of <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> protocol <code class="docutils literal notranslate"><span class="pre">3</span></code> when creating shelves.
  1383. (Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34204">bpo-34204</a>.)</p>
  1384. </section>
  1385. <section id="statistics">
  1386. <h3>statistics<a class="headerlink" href="#statistics" title="Link to this heading">¶</a></h3>
  1387. <p>Add <a class="reference internal" href="../library/statistics.html#statistics.covariance" title="statistics.covariance"><code class="xref py py-func docutils literal notranslate"><span class="pre">covariance()</span></code></a>, Pearson’s
  1388. <a class="reference internal" href="../library/statistics.html#statistics.correlation" title="statistics.correlation"><code class="xref py py-func docutils literal notranslate"><span class="pre">correlation()</span></code></a>, and simple
  1389. <a class="reference internal" href="../library/statistics.html#statistics.linear_regression" title="statistics.linear_regression"><code class="xref py py-func docutils literal notranslate"><span class="pre">linear_regression()</span></code></a> functions.
  1390. (Contributed by Tymoteusz Wołodźko in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38490">bpo-38490</a>.)</p>
  1391. </section>
  1392. <section id="site">
  1393. <h3>site<a class="headerlink" href="#site" title="Link to this heading">¶</a></h3>
  1394. <p>When a module does not define <code class="docutils literal notranslate"><span class="pre">__loader__</span></code>, fall back to <code class="docutils literal notranslate"><span class="pre">__spec__.loader</span></code>.
  1395. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42133">bpo-42133</a>.)</p>
  1396. </section>
  1397. <section id="socket">
  1398. <h3>socket<a class="headerlink" href="#socket" title="Link to this heading">¶</a></h3>
  1399. <p>The exception <a class="reference internal" href="../library/socket.html#socket.timeout" title="socket.timeout"><code class="xref py py-exc docutils literal notranslate"><span class="pre">socket.timeout</span></code></a> is now an alias of <a class="reference internal" href="../library/exceptions.html#TimeoutError" title="TimeoutError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TimeoutError</span></code></a>.
  1400. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42413">bpo-42413</a>.)</p>
  1401. <p>Add option to create MPTCP sockets with <code class="docutils literal notranslate"><span class="pre">IPPROTO_MPTCP</span></code>
  1402. (Contributed by Rui Cunha in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43571">bpo-43571</a>.)</p>
  1403. <p>Add <code class="docutils literal notranslate"><span class="pre">IP_RECVTOS</span></code> option to receive the type of service (ToS) or DSCP/ECN fields
  1404. (Contributed by Georg Sauthoff in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44077">bpo-44077</a>.)</p>
  1405. </section>
  1406. <section id="ssl">
  1407. <h3>ssl<a class="headerlink" href="#ssl" title="Link to this heading">¶</a></h3>
  1408. <p>The ssl module requires OpenSSL 1.1.1 or newer.
  1409. (Contributed by Christian Heimes in <span class="target" id="index-30"></span><a class="pep reference external" href="https://peps.python.org/pep-0644/"><strong>PEP 644</strong></a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43669">bpo-43669</a>.)</p>
  1410. <p>The ssl module has preliminary support for OpenSSL 3.0.0 and new option
  1411. <a class="reference internal" href="../library/ssl.html#ssl.OP_IGNORE_UNEXPECTED_EOF" title="ssl.OP_IGNORE_UNEXPECTED_EOF"><code class="xref py py-const docutils literal notranslate"><span class="pre">OP_IGNORE_UNEXPECTED_EOF</span></code></a>.
  1412. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38820">bpo-38820</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43794">bpo-43794</a>,
  1413. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43788">bpo-43788</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43791">bpo-43791</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43799">bpo-43799</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43920">bpo-43920</a>,
  1414. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43789">bpo-43789</a>, and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43811">bpo-43811</a>.)</p>
  1415. <p>Deprecated function and use of deprecated constants now result in
  1416. a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>. <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.options" title="ssl.SSLContext.options"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ssl.SSLContext.options</span></code></a> has
  1417. <a class="reference internal" href="../library/ssl.html#ssl.OP_NO_SSLv2" title="ssl.OP_NO_SSLv2"><code class="xref py py-data docutils literal notranslate"><span class="pre">OP_NO_SSLv2</span></code></a> and <a class="reference internal" href="../library/ssl.html#ssl.OP_NO_SSLv3" title="ssl.OP_NO_SSLv3"><code class="xref py py-data docutils literal notranslate"><span class="pre">OP_NO_SSLv3</span></code></a> set by default and
  1418. therefore cannot warn about setting the flag again. The
  1419. <a class="reference internal" href="#whatsnew310-deprecated"><span class="std std-ref">deprecation section</span></a> has a list of deprecated
  1420. features.
  1421. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43880">bpo-43880</a>.)</p>
  1422. <p>The ssl module now has more secure default settings. Ciphers without forward
  1423. secrecy or SHA-1 MAC are disabled by default. Security level 2 prohibits
  1424. weak RSA, DH, and ECC keys with less than 112 bits of security.
  1425. <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLContext</span></code></a> defaults to minimum protocol version TLS 1.2.
  1426. Settings are based on Hynek Schlawack’s research.
  1427. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43998">bpo-43998</a>.)</p>
  1428. <p>The deprecated protocols SSL 3.0, TLS 1.0, and TLS 1.1 are no longer
  1429. officially supported. Python does not block them actively. However
  1430. OpenSSL build options, distro configurations, vendor patches, and cipher
  1431. suites may prevent a successful handshake.</p>
  1432. <p>Add a <em>timeout</em> parameter to the <a class="reference internal" href="../library/ssl.html#ssl.get_server_certificate" title="ssl.get_server_certificate"><code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.get_server_certificate()</span></code></a> function.
  1433. (Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31870">bpo-31870</a>.)</p>
  1434. <p>The ssl module uses heap-types and multi-phase initialization.
  1435. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42333">bpo-42333</a>.)</p>
  1436. <p>A new verify flag <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_X509_PARTIAL_CHAIN" title="ssl.VERIFY_X509_PARTIAL_CHAIN"><code class="xref py py-const docutils literal notranslate"><span class="pre">VERIFY_X509_PARTIAL_CHAIN</span></code></a> has been added.
  1437. (Contributed by l0x in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40849">bpo-40849</a>.)</p>
  1438. </section>
  1439. <section id="sqlite3">
  1440. <h3>sqlite3<a class="headerlink" href="#sqlite3" title="Link to this heading">¶</a></h3>
  1441. <p>Add audit events for <code class="xref py py-func docutils literal notranslate"><span class="pre">connect/handle()</span></code>,
  1442. <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.enable_load_extension" title="sqlite3.Connection.enable_load_extension"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enable_load_extension()</span></code></a>, and
  1443. <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.load_extension" title="sqlite3.Connection.load_extension"><code class="xref py py-meth docutils literal notranslate"><span class="pre">load_extension()</span></code></a>.
  1444. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43762">bpo-43762</a>.)</p>
  1445. </section>
  1446. <section id="sys">
  1447. <h3>sys<a class="headerlink" href="#sys" title="Link to this heading">¶</a></h3>
  1448. <p>Add <a class="reference internal" href="../library/sys.html#sys.orig_argv" title="sys.orig_argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.orig_argv</span></code></a> attribute: the list of the original command line
  1449. arguments passed to the Python executable.
  1450. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23427">bpo-23427</a>.)</p>
  1451. <p>Add <a class="reference internal" href="../library/sys.html#sys.stdlib_module_names" title="sys.stdlib_module_names"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdlib_module_names</span></code></a>, containing the list of the standard library
  1452. module names.
  1453. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42955">bpo-42955</a>.)</p>
  1454. </section>
  1455. <section id="thread">
  1456. <h3>_thread<a class="headerlink" href="#thread" title="Link to this heading">¶</a></h3>
  1457. <p><a class="reference internal" href="../library/_thread.html#thread.interrupt_main" title="_thread.interrupt_main"><code class="xref py py-func docutils literal notranslate"><span class="pre">_thread.interrupt_main()</span></code></a> now takes an optional signal number to
  1458. simulate (the default is still <a class="reference internal" href="../library/signal.html#signal.SIGINT" title="signal.SIGINT"><code class="xref py py-const docutils literal notranslate"><span class="pre">signal.SIGINT</span></code></a>).
  1459. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43356">bpo-43356</a>.)</p>
  1460. </section>
  1461. <section id="threading">
  1462. <h3>threading<a class="headerlink" href="#threading" title="Link to this heading">¶</a></h3>
  1463. <p>Add <a class="reference internal" href="../library/threading.html#threading.gettrace" title="threading.gettrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.gettrace()</span></code></a> and <a class="reference internal" href="../library/threading.html#threading.getprofile" title="threading.getprofile"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.getprofile()</span></code></a> to
  1464. retrieve the functions set by <a class="reference internal" href="../library/threading.html#threading.settrace" title="threading.settrace"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.settrace()</span></code></a> and
  1465. <a class="reference internal" href="../library/threading.html#threading.setprofile" title="threading.setprofile"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.setprofile()</span></code></a> respectively.
  1466. (Contributed by Mario Corchero in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42251">bpo-42251</a>.)</p>
  1467. <p>Add <a class="reference internal" href="../library/threading.html#threading.__excepthook__" title="threading.__excepthook__"><code class="xref py py-data docutils literal notranslate"><span class="pre">threading.__excepthook__</span></code></a> to allow retrieving the original value
  1468. of <a class="reference internal" href="../library/threading.html#threading.excepthook" title="threading.excepthook"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.excepthook()</span></code></a> in case it is set to a broken or a different
  1469. value.
  1470. (Contributed by Mario Corchero in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42308">bpo-42308</a>.)</p>
  1471. </section>
  1472. <section id="traceback">
  1473. <h3>traceback<a class="headerlink" href="#traceback" title="Link to this heading">¶</a></h3>
  1474. <p>The <a class="reference internal" href="../library/traceback.html#traceback.format_exception" title="traceback.format_exception"><code class="xref py py-func docutils literal notranslate"><span class="pre">format_exception()</span></code></a>,
  1475. <a class="reference internal" href="../library/traceback.html#traceback.format_exception_only" title="traceback.format_exception_only"><code class="xref py py-func docutils literal notranslate"><span class="pre">format_exception_only()</span></code></a>, and
  1476. <a class="reference internal" href="../library/traceback.html#traceback.print_exception" title="traceback.print_exception"><code class="xref py py-func docutils literal notranslate"><span class="pre">print_exception()</span></code></a> functions can now take an exception object
  1477. as a positional-only argument.
  1478. (Contributed by Zackery Spytz and Matthias Bussonnier in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26389">bpo-26389</a>.)</p>
  1479. </section>
  1480. <section id="types">
  1481. <h3>types<a class="headerlink" href="#types" title="Link to this heading">¶</a></h3>
  1482. <p>Reintroduce the <a class="reference internal" href="../library/types.html#types.EllipsisType" title="types.EllipsisType"><code class="xref py py-data docutils literal notranslate"><span class="pre">types.EllipsisType</span></code></a>, <a class="reference internal" href="../library/types.html#types.NoneType" title="types.NoneType"><code class="xref py py-data docutils literal notranslate"><span class="pre">types.NoneType</span></code></a>
  1483. and <a class="reference internal" href="../library/types.html#types.NotImplementedType" title="types.NotImplementedType"><code class="xref py py-data docutils literal notranslate"><span class="pre">types.NotImplementedType</span></code></a> classes, providing a new set
  1484. of types readily interpretable by type checkers.
  1485. (Contributed by Bas van Beek in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41810">bpo-41810</a>.)</p>
  1486. </section>
  1487. <section id="typing">
  1488. <h3>typing<a class="headerlink" href="#typing" title="Link to this heading">¶</a></h3>
  1489. <p>For major changes, see <a class="reference internal" href="#new-feat-related-type-hints"><span class="std std-ref">New Features Related to Type Hints</span></a>.</p>
  1490. <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-31"></span><a class="pep reference external" href="https://peps.python.org/pep-0586/"><strong>PEP 586</strong></a>
  1491. and to match the behavior of static type checkers specified in the PEP.</p>
  1492. <ol class="arabic">
  1493. <li><p><code class="docutils literal notranslate"><span class="pre">Literal</span></code> now de-duplicates parameters.</p></li>
  1494. <li><p>Equality comparisons between <code class="docutils literal notranslate"><span class="pre">Literal</span></code> objects are now order independent.</p></li>
  1495. <li><p><code class="docutils literal notranslate"><span class="pre">Literal</span></code> comparisons now respect types. For example,
  1496. <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
  1497. now <code class="docutils literal notranslate"><span class="pre">False</span></code>. To support this change, the internally used type cache now
  1498. supports differentiating types.</p></li>
  1499. <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
  1500. 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>.
  1501. Note that declaring <code class="docutils literal notranslate"><span class="pre">Literal</span></code> with unhashable parameters will not throw
  1502. an error:</p>
  1503. <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>
  1504. <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>
  1505. <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>
  1506. <span class="gt">Traceback (most recent call last):</span>
  1507. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  1508. <span class="gr">TypeError</span>: <span class="n">unhashable type: &#39;set&#39;</span>
  1509. </pre></div>
  1510. </div>
  1511. </li>
  1512. </ol>
  1513. <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>
  1514. <p>Add new function <a class="reference internal" href="../library/typing.html#typing.is_typeddict" title="typing.is_typeddict"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.is_typeddict()</span></code></a> to introspect if an annotation
  1515. is a <a class="reference internal" href="../library/typing.html#typing.TypedDict" title="typing.TypedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.TypedDict</span></code></a>.
  1516. (Contributed by Patrick Reader in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41792">bpo-41792</a>.)</p>
  1517. <p>Subclasses of <code class="docutils literal notranslate"><span class="pre">typing.Protocol</span></code> which only have data variables declared
  1518. will now raise a <code class="docutils literal notranslate"><span class="pre">TypeError</span></code> when checked with <code class="docutils literal notranslate"><span class="pre">isinstance</span></code> unless they
  1519. are decorated with <code class="xref py py-func docutils literal notranslate"><span class="pre">runtime_checkable()</span></code>. Previously, these checks
  1520. passed silently. Users should decorate their
  1521. subclasses with the <code class="xref py py-func docutils literal notranslate"><span class="pre">runtime_checkable()</span></code> decorator
  1522. if they want runtime protocols.
  1523. (Contributed by Yurii Karabas in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38908">bpo-38908</a>.)</p>
  1524. <p>Importing from the <code class="docutils literal notranslate"><span class="pre">typing.io</span></code> and <code class="docutils literal notranslate"><span class="pre">typing.re</span></code> submodules will now emit
  1525. <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>. These submodules have been deprecated since
  1526. Python 3.8 and will be removed in a future version of Python. Anything
  1527. belonging to those submodules should be imported directly from
  1528. <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> instead.
  1529. (Contributed by Sebastian Rittau in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38291">bpo-38291</a>.)</p>
  1530. </section>
  1531. <section id="unittest">
  1532. <h3>unittest<a class="headerlink" href="#unittest" title="Link to this heading">¶</a></h3>
  1533. <p>Add new method <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertNoLogs" title="unittest.TestCase.assertNoLogs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertNoLogs()</span></code></a> to complement the
  1534. existing <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertLogs" title="unittest.TestCase.assertLogs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertLogs()</span></code></a>. (Contributed by Kit Yan Choi
  1535. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39385">bpo-39385</a>.)</p>
  1536. </section>
  1537. <section id="urllib-parse">
  1538. <h3>urllib.parse<a class="headerlink" href="#urllib-parse" title="Link to this heading">¶</a></h3>
  1539. <p>Python versions earlier than Python 3.10 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
  1540. 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
  1541. <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
  1542. newer W3C recommendations, this has been changed to allow only a single
  1543. separator key, with <code class="docutils literal notranslate"><span class="pre">&amp;</span></code> as the default. This change also affects
  1544. <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
  1545. functions internally. For more details, please see their respective
  1546. documentation.
  1547. (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>
  1548. <p>The presence of newline or tab characters in parts of a URL allows for some
  1549. forms of attacks. Following the WHATWG specification that updates <span class="target" id="index-32"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc3986.html"><strong>RFC 3986</strong></a>,
  1550. 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
  1551. 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
  1552. characters are controlled by a new module level variable
  1553. <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>
  1554. </section>
  1555. <section id="xml">
  1556. <h3>xml<a class="headerlink" href="#xml" title="Link to this heading">¶</a></h3>
  1557. <p>Add a <a class="reference internal" href="../library/xml.sax.handler.html#xml.sax.handler.LexicalHandler" title="xml.sax.handler.LexicalHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">LexicalHandler</span></code></a> class to the
  1558. <a class="reference internal" href="../library/xml.sax.handler.html#module-xml.sax.handler" title="xml.sax.handler: Base classes for SAX event handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax.handler</span></code></a> module.
  1559. (Contributed by Jonathan Gossage and Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35018">bpo-35018</a>.)</p>
  1560. </section>
  1561. <section id="zipimport">
  1562. <h3>zipimport<a class="headerlink" href="#zipimport" title="Link to this heading">¶</a></h3>
  1563. <p>Add methods related to <span class="target" id="index-33"></span><a class="pep reference external" href="https://peps.python.org/pep-0451/"><strong>PEP 451</strong></a>: <a class="reference internal" href="../library/zipimport.html#zipimport.zipimporter.find_spec" title="zipimport.zipimporter.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">find_spec()</span></code></a>,
  1564. <a class="reference internal" href="../library/zipimport.html#zipimport.zipimporter.create_module" title="zipimport.zipimporter.create_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">zipimport.zipimporter.create_module()</span></code></a>, and
  1565. <a class="reference internal" href="../library/zipimport.html#zipimport.zipimporter.exec_module" title="zipimport.zipimporter.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">zipimport.zipimporter.exec_module()</span></code></a>.
  1566. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42131">bpo-42131</a>.)</p>
  1567. <p>Add <a class="reference internal" href="../library/zipimport.html#zipimport.zipimporter.invalidate_caches" title="zipimport.zipimporter.invalidate_caches"><code class="xref py py-meth docutils literal notranslate"><span class="pre">invalidate_caches()</span></code></a> method.
  1568. (Contributed by Desmond Cheong in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14678">bpo-14678</a>.)</p>
  1569. </section>
  1570. </section>
  1571. <section id="optimizations">
  1572. <h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading">¶</a></h2>
  1573. <ul class="simple">
  1574. <li><p>Constructors <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-func 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-func 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-func docutils literal notranslate"><span class="pre">bytearray()</span></code></a> are now faster
  1575. (around 30–40% for small objects).
  1576. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41334">bpo-41334</a>.)</p></li>
  1577. <li><p>The <a class="reference internal" href="../library/runpy.html#module-runpy" title="runpy: Locate and run Python modules without importing them first."><code class="xref py py-mod docutils literal notranslate"><span class="pre">runpy</span></code></a> module now imports fewer modules.
  1578. The <code class="docutils literal notranslate"><span class="pre">python3</span> <span class="pre">-m</span> <span class="pre">module-name</span></code> command startup time is 1.4x faster in
  1579. average. On Linux, <code class="docutils literal notranslate"><span class="pre">python3</span> <span class="pre">-I</span> <span class="pre">-m</span> <span class="pre">module-name</span></code> imports 69 modules on Python
  1580. 3.9, whereas it only imports 51 modules (-18) on Python 3.10.
  1581. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41006">bpo-41006</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41718">bpo-41718</a>.)</p></li>
  1582. <li><p>The <code class="docutils literal notranslate"><span class="pre">LOAD_ATTR</span></code> instruction now uses new “per opcode cache” mechanism. It
  1583. is about 36% faster now for regular attributes and 44% faster for slots.
  1584. (Contributed by Pablo Galindo and Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42093">bpo-42093</a> and Guido
  1585. van Rossum in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42927">bpo-42927</a>, based on ideas implemented originally in PyPy
  1586. and MicroPython.)</p></li>
  1587. <li><p>When building Python with <a class="reference internal" href="../using/configure.html#cmdoption-enable-optimizations"><code class="xref std std-option docutils literal notranslate"><span class="pre">--enable-optimizations</span></code></a> now
  1588. <code class="docutils literal notranslate"><span class="pre">-fno-semantic-interposition</span></code> is added to both the compile and link line.
  1589. This speeds builds of the Python interpreter created with <a class="reference internal" href="../using/configure.html#cmdoption-enable-shared"><code class="xref std std-option docutils literal notranslate"><span class="pre">--enable-shared</span></code></a>
  1590. with <code class="docutils literal notranslate"><span class="pre">gcc</span></code> by up to 30%. See <a class="reference external" href="https://developers.redhat.com/blog/2020/06/25/red-hat-enterprise-linux-8-2-brings-faster-python-3-8-run-speeds/">this article</a>
  1591. for more details. (Contributed by Victor Stinner and Pablo Galindo in
  1592. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38980">bpo-38980</a>.)</p></li>
  1593. <li><p>Use a new output buffer management code for <a class="reference internal" href="../library/bz2.html#module-bz2" title="bz2: Interfaces for bzip2 compression and decompression."><code class="xref py py-mod docutils literal notranslate"><span class="pre">bz2</span></code></a> / <a class="reference internal" href="../library/lzma.html#module-lzma" title="lzma: A Python wrapper for the liblzma compression library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">lzma</span></code></a> /
  1594. <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> modules, and add <code class="docutils literal notranslate"><span class="pre">.readall()</span></code> function to
  1595. <code class="docutils literal notranslate"><span class="pre">_compression.DecompressReader</span></code> class. bz2 decompression is now 1.09x ~ 1.17x
  1596. faster, lzma decompression 1.20x ~ 1.32x faster, <code class="docutils literal notranslate"><span class="pre">GzipFile.read(-1)</span></code> 1.11x
  1597. ~ 1.18x faster. (Contributed by Ma Lin, reviewed by Gregory P. Smith, in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41486">bpo-41486</a>)</p></li>
  1598. <li><p>When using stringized annotations, annotations dicts for functions are no longer
  1599. created when the function is created. Instead, they are stored as a tuple of
  1600. strings, and the function object lazily converts this into the annotations dict
  1601. on demand. This optimization cuts the CPU time needed to define an annotated
  1602. function by half.
  1603. (Contributed by Yurii Karabas and Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42202">bpo-42202</a>.)</p></li>
  1604. <li><p>Substring search functions such as <code class="docutils literal notranslate"><span class="pre">str1</span> <span class="pre">in</span> <span class="pre">str2</span></code> and <code class="docutils literal notranslate"><span class="pre">str2.find(str1)</span></code>
  1605. now sometimes use Crochemore &amp; Perrin’s “Two-Way” string searching
  1606. algorithm to avoid quadratic behavior on long strings. (Contributed
  1607. by Dennis Sweeney in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41972">bpo-41972</a>)</p></li>
  1608. <li><p>Add micro-optimizations to <code class="docutils literal notranslate"><span class="pre">_PyType_Lookup()</span></code> to improve type attribute cache lookup
  1609. performance in the common case of cache hits. This makes the interpreter 1.04 times faster
  1610. on average. (Contributed by Dino Viehland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43452">bpo-43452</a>.)</p></li>
  1611. <li><p>The following built-in functions now support the faster <span class="target" id="index-34"></span><a class="pep reference external" href="https://peps.python.org/pep-0590/"><strong>PEP 590</strong></a> vectorcall calling convention:
  1612. <a class="reference internal" href="../library/functions.html#map" title="map"><code class="xref py py-func docutils literal notranslate"><span class="pre">map()</span></code></a>, <a class="reference internal" href="../library/functions.html#filter" title="filter"><code class="xref py py-func docutils literal notranslate"><span class="pre">filter()</span></code></a>, <a class="reference internal" href="../library/functions.html#reversed" title="reversed"><code class="xref py py-func docutils literal notranslate"><span class="pre">reversed()</span></code></a>, <a class="reference internal" href="../library/functions.html#bool" title="bool"><code class="xref py py-func docutils literal notranslate"><span class="pre">bool()</span></code></a> and <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-func docutils literal notranslate"><span class="pre">float()</span></code></a>.
  1613. (Contributed by Donghee Na and Jeroen Demeyer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43575">bpo-43575</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43287">bpo-43287</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41922">bpo-41922</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41873">bpo-41873</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41870">bpo-41870</a>.)</p></li>
  1614. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">BZ2File</span></code> performance is improved by removing internal <code class="docutils literal notranslate"><span class="pre">RLock</span></code>.
  1615. This makes <code class="xref py py-class docutils literal notranslate"><span class="pre">BZ2File</span></code> thread unsafe in the face of multiple simultaneous
  1616. readers or writers, just like its equivalent classes in <a class="reference internal" href="../library/gzip.html#module-gzip" title="gzip: Interfaces for gzip compression and decompression using file objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gzip</span></code></a> and
  1617. <a class="reference internal" href="../library/lzma.html#module-lzma" title="lzma: A Python wrapper for the liblzma compression library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">lzma</span></code></a> have always been. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43785">bpo-43785</a>.)</p></li>
  1618. </ul>
  1619. </section>
  1620. <section id="deprecated">
  1621. <span id="whatsnew310-deprecated"></span><h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading">¶</a></h2>
  1622. <ul>
  1623. <li><p>Currently Python accepts numeric literals immediately followed by keywords,
  1624. for example <code class="docutils literal notranslate"><span class="pre">0in</span> <span class="pre">x</span></code>, <code class="docutils literal notranslate"><span class="pre">1or</span> <span class="pre">x</span></code>, <code class="docutils literal notranslate"><span class="pre">0if</span> <span class="pre">1else</span> <span class="pre">2</span></code>. It allows confusing
  1625. and ambiguous expressions like <code class="docutils literal notranslate"><span class="pre">[0x1for</span> <span class="pre">x</span> <span class="pre">in</span> <span class="pre">y]</span></code> (which can be
  1626. interpreted as <code class="docutils literal notranslate"><span class="pre">[0x1</span> <span class="pre">for</span> <span class="pre">x</span> <span class="pre">in</span> <span class="pre">y]</span></code> or <code class="docutils literal notranslate"><span class="pre">[0x1f</span> <span class="pre">or</span> <span class="pre">x</span> <span class="pre">in</span> <span class="pre">y]</span></code>). Starting in
  1627. this release, a deprecation warning is raised if the numeric literal is
  1628. immediately followed by one of keywords <a class="reference internal" href="../reference/expressions.html#and"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">and</span></code></a>, <a class="reference internal" href="../reference/compound_stmts.html#else"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">else</span></code></a>,
  1629. <a class="reference internal" href="../reference/compound_stmts.html#for"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">for</span></code></a>, <a class="reference internal" href="../reference/compound_stmts.html#if"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">if</span></code></a>, <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>, <a class="reference internal" href="../reference/expressions.html#is"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">is</span></code></a> and <a class="reference internal" href="../reference/expressions.html#or"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">or</span></code></a>.
  1630. In future releases it will be changed to syntax warning, and finally to
  1631. syntax error.
  1632. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43833">bpo-43833</a>.)</p></li>
  1633. <li><p>Starting in this release, there will be a concerted effort to begin
  1634. cleaning up old import semantics that were kept for Python 2.7
  1635. compatibility. Specifically,
  1636. <code class="xref py py-meth docutils literal notranslate"><span class="pre">find_loader()</span></code>/<code class="xref py py-meth docutils literal notranslate"><span class="pre">find_module()</span></code>
  1637. (superseded by <code class="xref py py-meth docutils literal notranslate"><span class="pre">find_spec()</span></code>),
  1638. <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.load_module" title="importlib.abc.Loader.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">load_module()</span></code></a>
  1639. (superseded by <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.exec_module" title="importlib.abc.Loader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exec_module()</span></code></a>),
  1640. <code class="xref py py-meth docutils literal notranslate"><span class="pre">module_repr()</span></code> (which the import system
  1641. takes care of for you), the <code class="docutils literal notranslate"><span class="pre">__package__</span></code> attribute
  1642. (superseded by <code class="docutils literal notranslate"><span class="pre">__spec__.parent</span></code>), the <code class="docutils literal notranslate"><span class="pre">__loader__</span></code> attribute
  1643. (superseded by <code class="docutils literal notranslate"><span class="pre">__spec__.loader</span></code>), and the <code class="docutils literal notranslate"><span class="pre">__cached__</span></code> attribute
  1644. (superseded by <code class="docutils literal notranslate"><span class="pre">__spec__.cached</span></code>) will slowly be removed (as well
  1645. as other classes and methods in <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>).
  1646. <a class="reference internal" href="../library/exceptions.html#ImportWarning" title="ImportWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportWarning</span></code></a> and/or <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 be raised
  1647. as appropriate to help identify code which needs updating during
  1648. this transition.</p></li>
  1649. <li><p>The entire <code class="docutils literal notranslate"><span class="pre">distutils</span></code> namespace is deprecated, to be removed in
  1650. Python 3.12. Refer to the <a class="reference internal" href="#distutils-deprecated"><span class="std std-ref">module changes</span></a>
  1651. section for more information.</p></li>
  1652. <li><p>Non-integer arguments to <a class="reference internal" href="../library/random.html#random.randrange" title="random.randrange"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.randrange()</span></code></a> are deprecated.
  1653. The <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> is deprecated in favor of 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>.
  1654. (Contributed by Serhiy Storchaka and Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37319">bpo-37319</a>.)</p></li>
  1655. <li><p>The various <code class="docutils literal notranslate"><span class="pre">load_module()</span></code> methods of <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> have been
  1656. documented as deprecated since Python 3.6, but will now also trigger
  1657. 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>. Use
  1658. <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.exec_module" title="importlib.abc.Loader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exec_module()</span></code></a> instead.
  1659. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26131">bpo-26131</a>.)</p></li>
  1660. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">zimport.zipimporter.load_module()</span></code> has been deprecated in
  1661. preference for <a class="reference internal" href="../library/zipimport.html#zipimport.zipimporter.exec_module" title="zipimport.zipimporter.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exec_module()</span></code></a>.
  1662. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26131">bpo-26131</a>.)</p></li>
  1663. <li><p>The use of <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.load_module" title="importlib.abc.Loader.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">load_module()</span></code></a> by the import
  1664. system now triggers an <a class="reference internal" href="../library/exceptions.html#ImportWarning" title="ImportWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportWarning</span></code></a> as
  1665. <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.exec_module" title="importlib.abc.Loader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exec_module()</span></code></a> is preferred.
  1666. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26131">bpo-26131</a>.)</p></li>
  1667. <li><p>The use of <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder.find_module()</span></code> and
  1668. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_module()</span></code> by the import system now
  1669. trigger an <a class="reference internal" href="../library/exceptions.html#ImportWarning" title="ImportWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportWarning</span></code></a> as
  1670. <a class="reference internal" href="../library/importlib.html#importlib.abc.MetaPathFinder.find_spec" title="importlib.abc.MetaPathFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder.find_spec()</span></code></a> and
  1671. <a class="reference internal" href="../library/importlib.html#importlib.abc.PathEntryFinder.find_spec" title="importlib.abc.PathEntryFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_spec()</span></code></a>
  1672. are preferred, respectively. You can use
  1673. <a class="reference internal" href="../library/importlib.html#importlib.util.spec_from_loader" title="importlib.util.spec_from_loader"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.spec_from_loader()</span></code></a> to help in porting.
  1674. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42134">bpo-42134</a>.)</p></li>
  1675. <li><p>The use of <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_loader()</span></code> by the import
  1676. system now triggers an <a class="reference internal" href="../library/exceptions.html#ImportWarning" title="ImportWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportWarning</span></code></a> as
  1677. <a class="reference internal" href="../library/importlib.html#importlib.abc.PathEntryFinder.find_spec" title="importlib.abc.PathEntryFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_spec()</span></code></a> is preferred. You can use
  1678. <a class="reference internal" href="../library/importlib.html#importlib.util.spec_from_loader" title="importlib.util.spec_from_loader"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.spec_from_loader()</span></code></a> to help in porting.
  1679. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43672">bpo-43672</a>.)</p></li>
  1680. <li><p>The various implementations of
  1681. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder.find_module()</span></code> (
  1682. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.BuiltinImporter.find_module()</span></code>,
  1683. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.FrozenImporter.find_module()</span></code>,
  1684. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.WindowsRegistryFinder.find_module()</span></code>,
  1685. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.PathFinder.find_module()</span></code>,
  1686. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder.find_module()</span></code> ),
  1687. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_module()</span></code> (
  1688. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.FileFinder.find_module()</span></code> ), and
  1689. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_loader()</span></code> (
  1690. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.FileFinder.find_loader()</span></code> )
  1691. now raise <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 are slated for removal in
  1692. Python 3.12 (previously they were documented as deprecated in Python 3.4).
  1693. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42135">bpo-42135</a>.)</p></li>
  1694. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.Finder</span></code> is deprecated (including its sole method,
  1695. <code class="xref py py-meth docutils literal notranslate"><span class="pre">find_module()</span></code>). Both
  1696. <a class="reference internal" href="../library/importlib.html#importlib.abc.MetaPathFinder" title="importlib.abc.MetaPathFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder</span></code></a> and <a class="reference internal" href="../library/importlib.html#importlib.abc.PathEntryFinder" title="importlib.abc.PathEntryFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder</span></code></a>
  1697. no longer inherit from the class. Users should inherit from one of these two
  1698. classes as appropriate instead.
  1699. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42135">bpo-42135</a>.)</p></li>
  1700. <li><p>The deprecations of <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.find_loader()</span></code>,
  1701. <code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.set_package_wrapper()</span></code>,
  1702. <code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.set_loader_wrapper()</span></code>,
  1703. <code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.module_for_loader()</span></code>,
  1704. <code class="xref py py-class docutils literal notranslate"><span class="pre">pkgutil.ImpImporter</span></code>, and
  1705. <code class="xref py py-class docutils literal notranslate"><span class="pre">pkgutil.ImpLoader</span></code> have all been updated to list Python 3.12 as the
  1706. slated version of removal (they began raising <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> in
  1707. previous versions of Python).
  1708. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43720">bpo-43720</a>.)</p></li>
  1709. <li><p>The import system now uses the <code class="docutils literal notranslate"><span class="pre">__spec__</span></code> attribute on modules before
  1710. falling back on <code class="xref py py-meth docutils literal notranslate"><span class="pre">module_repr()</span></code> for a module’s
  1711. <code class="docutils literal notranslate"><span class="pre">__repr__()</span></code> method. Removal of the use of <code class="docutils literal notranslate"><span class="pre">module_repr()</span></code> is scheduled
  1712. for Python 3.12.
  1713. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42137">bpo-42137</a>.)</p></li>
  1714. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.module_repr()</span></code>,
  1715. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.FrozenLoader.module_repr()</span></code>, and
  1716. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.BuiltinLoader.module_repr()</span></code> are deprecated and
  1717. slated for removal in Python 3.12.
  1718. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42136">bpo-42136</a>.)</p></li>
  1719. <li><p><code class="docutils literal notranslate"><span class="pre">sqlite3.OptimizedUnicode</span></code> has been undocumented and obsolete since Python
  1720. 3.3, when it was made an alias to <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>. It is now deprecated,
  1721. scheduled for removal in Python 3.12.
  1722. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42264">bpo-42264</a>.)</p></li>
  1723. <li><p>The undocumented built-in function <code class="docutils literal notranslate"><span class="pre">sqlite3.enable_shared_cache</span></code> is now
  1724. deprecated, scheduled for removal in Python 3.12. Its use is strongly
  1725. discouraged by the SQLite3 documentation. See <a class="reference external" href="https://sqlite.org/c3ref/enable_shared_cache.html">the SQLite3 docs</a> for more details.
  1726. If a shared cache must be used, open the database in URI mode using the
  1727. <code class="docutils literal notranslate"><span class="pre">cache=shared</span></code> query parameter.
  1728. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24464">bpo-24464</a>.)</p></li>
  1729. <li><p>The following <code class="docutils literal notranslate"><span class="pre">threading</span></code> methods are now deprecated:</p>
  1730. <ul class="simple">
  1731. <li><p><code class="docutils literal notranslate"><span class="pre">threading.currentThread</span></code> =&gt; <a class="reference internal" href="../library/threading.html#threading.current_thread" title="threading.current_thread"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.current_thread()</span></code></a></p></li>
  1732. <li><p><code class="docutils literal notranslate"><span class="pre">threading.activeCount</span></code> =&gt; <a class="reference internal" href="../library/threading.html#threading.active_count" title="threading.active_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.active_count()</span></code></a></p></li>
  1733. <li><p><code class="docutils literal notranslate"><span class="pre">threading.Condition.notifyAll</span></code> =&gt;
  1734. <a class="reference internal" href="../library/threading.html#threading.Condition.notify_all" title="threading.Condition.notify_all"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Condition.notify_all()</span></code></a></p></li>
  1735. <li><p><code class="docutils literal notranslate"><span class="pre">threading.Event.isSet</span></code> =&gt; <a class="reference internal" href="../library/threading.html#threading.Event.is_set" title="threading.Event.is_set"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Event.is_set()</span></code></a></p></li>
  1736. <li><p><code class="docutils literal notranslate"><span class="pre">threading.Thread.setName</span></code> =&gt; <a class="reference internal" href="../library/threading.html#threading.Thread.name" title="threading.Thread.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">threading.Thread.name</span></code></a></p></li>
  1737. <li><p><code class="docutils literal notranslate"><span class="pre">threading.thread.getName</span></code> =&gt; <a class="reference internal" href="../library/threading.html#threading.Thread.name" title="threading.Thread.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">threading.Thread.name</span></code></a></p></li>
  1738. <li><p><code class="docutils literal notranslate"><span class="pre">threading.Thread.isDaemon</span></code> =&gt; <a class="reference internal" href="../library/threading.html#threading.Thread.daemon" title="threading.Thread.daemon"><code class="xref py py-attr docutils literal notranslate"><span class="pre">threading.Thread.daemon</span></code></a></p></li>
  1739. <li><p><code class="docutils literal notranslate"><span class="pre">threading.Thread.setDaemon</span></code> =&gt; <a class="reference internal" href="../library/threading.html#threading.Thread.daemon" title="threading.Thread.daemon"><code class="xref py py-attr docutils literal notranslate"><span class="pre">threading.Thread.daemon</span></code></a></p></li>
  1740. </ul>
  1741. <p>(Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/87889">gh-87889</a>.)</p>
  1742. </li>
  1743. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.link_to()</span></code> is deprecated and slated for removal in
  1744. Python 3.12. Use <a class="reference internal" href="../library/pathlib.html#pathlib.Path.hardlink_to" title="pathlib.Path.hardlink_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.hardlink_to()</span></code></a> instead.
  1745. (Contributed by Barney Gale in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39950">bpo-39950</a>.)</p></li>
  1746. <li><p><code class="docutils literal notranslate"><span class="pre">cgi.log()</span></code> is deprecated and slated for removal in Python 3.12.
  1747. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41139">bpo-41139</a>.)</p></li>
  1748. <li><p>The following <a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a> features have been deprecated since Python 3.6,
  1749. Python 3.7, or OpenSSL 1.1.0 and will be removed in 3.11:</p>
  1750. <ul class="simple">
  1751. <li><p><a class="reference internal" href="../library/ssl.html#ssl.OP_NO_SSLv2" title="ssl.OP_NO_SSLv2"><code class="xref py py-data docutils literal notranslate"><span class="pre">OP_NO_SSLv2</span></code></a>, <a class="reference internal" href="../library/ssl.html#ssl.OP_NO_SSLv3" title="ssl.OP_NO_SSLv3"><code class="xref py py-data docutils literal notranslate"><span class="pre">OP_NO_SSLv3</span></code></a>, <a class="reference internal" href="../library/ssl.html#ssl.OP_NO_TLSv1" title="ssl.OP_NO_TLSv1"><code class="xref py py-data docutils literal notranslate"><span class="pre">OP_NO_TLSv1</span></code></a>,
  1752. <a class="reference internal" href="../library/ssl.html#ssl.OP_NO_TLSv1_1" title="ssl.OP_NO_TLSv1_1"><code class="xref py py-data docutils literal notranslate"><span class="pre">OP_NO_TLSv1_1</span></code></a>, <a class="reference internal" href="../library/ssl.html#ssl.OP_NO_TLSv1_2" title="ssl.OP_NO_TLSv1_2"><code class="xref py py-data docutils literal notranslate"><span class="pre">OP_NO_TLSv1_2</span></code></a>, and
  1753. <a class="reference internal" href="../library/ssl.html#ssl.OP_NO_TLSv1_3" title="ssl.OP_NO_TLSv1_3"><code class="xref py py-data docutils literal notranslate"><span class="pre">OP_NO_TLSv1_3</span></code></a> are replaced by
  1754. <code class="xref py py-attr docutils literal notranslate"><span class="pre">sslSSLContext.minimum_version</span></code> and
  1755. <code class="xref py py-attr docutils literal notranslate"><span class="pre">sslSSLContext.maximum_version</span></code>.</p></li>
  1756. <li><p><code class="xref py py-data docutils literal notranslate"><span class="pre">PROTOCOL_SSLv2</span></code>, <a class="reference internal" href="../library/ssl.html#ssl.PROTOCOL_SSLv3" title="ssl.PROTOCOL_SSLv3"><code class="xref py py-data docutils literal notranslate"><span class="pre">PROTOCOL_SSLv3</span></code></a>,
  1757. <a class="reference internal" href="../library/ssl.html#ssl.PROTOCOL_SSLv23" title="ssl.PROTOCOL_SSLv23"><code class="xref py py-data docutils literal notranslate"><span class="pre">PROTOCOL_SSLv23</span></code></a>, <a class="reference internal" href="../library/ssl.html#ssl.PROTOCOL_TLSv1" title="ssl.PROTOCOL_TLSv1"><code class="xref py py-data docutils literal notranslate"><span class="pre">PROTOCOL_TLSv1</span></code></a>,
  1758. <a class="reference internal" href="../library/ssl.html#ssl.PROTOCOL_TLSv1_1" title="ssl.PROTOCOL_TLSv1_1"><code class="xref py py-data docutils literal notranslate"><span class="pre">PROTOCOL_TLSv1_1</span></code></a>, <a class="reference internal" href="../library/ssl.html#ssl.PROTOCOL_TLSv1_2" title="ssl.PROTOCOL_TLSv1_2"><code class="xref py py-data docutils literal notranslate"><span class="pre">PROTOCOL_TLSv1_2</span></code></a>, and
  1759. <a class="reference internal" href="../library/ssl.html#ssl.PROTOCOL_TLS" title="ssl.PROTOCOL_TLS"><code class="xref py py-const docutils literal notranslate"><span class="pre">PROTOCOL_TLS</span></code></a> are deprecated in favor of
  1760. <a class="reference internal" href="../library/ssl.html#ssl.PROTOCOL_TLS_CLIENT" title="ssl.PROTOCOL_TLS_CLIENT"><code class="xref py py-const docutils literal notranslate"><span class="pre">PROTOCOL_TLS_CLIENT</span></code></a> and <a class="reference internal" href="../library/ssl.html#ssl.PROTOCOL_TLS_SERVER" title="ssl.PROTOCOL_TLS_SERVER"><code class="xref py py-const docutils literal notranslate"><span class="pre">PROTOCOL_TLS_SERVER</span></code></a></p></li>
  1761. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">wrap_socket()</span></code> is replaced by <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.wrap_socket" title="ssl.SSLContext.wrap_socket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLContext.wrap_socket()</span></code></a></p></li>
  1762. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">match_hostname()</span></code></p></li>
  1763. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">RAND_pseudo_bytes()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">RAND_egd()</span></code></p></li>
  1764. <li><p>NPN features like <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.selected_npn_protocol" title="ssl.SSLSocket.selected_npn_protocol"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLSocket.selected_npn_protocol()</span></code></a> and
  1765. <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_npn_protocols" title="ssl.SSLContext.set_npn_protocols"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLContext.set_npn_protocols()</span></code></a> are replaced by ALPN.</p></li>
  1766. </ul>
  1767. </li>
  1768. <li><p>The threading debug (<code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONTHREADDEBUG</span></code> environment variable) is
  1769. deprecated in Python 3.10 and will be removed in Python 3.12. This feature
  1770. requires a <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug build of Python</span></a>.
  1771. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44584">bpo-44584</a>.)</p></li>
  1772. <li><p>Importing from the <code class="docutils literal notranslate"><span class="pre">typing.io</span></code> and <code class="docutils literal notranslate"><span class="pre">typing.re</span></code> submodules will now emit
  1773. <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>. These submodules will be removed in a future version
  1774. of Python. Anything belonging to these submodules should be imported directly
  1775. from <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> instead.
  1776. (Contributed by Sebastian Rittau in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38291">bpo-38291</a>.)</p></li>
  1777. </ul>
  1778. </section>
  1779. <section id="removed">
  1780. <span id="whatsnew310-removed"></span><h2>Removed<a class="headerlink" href="#removed" title="Link to this heading">¶</a></h2>
  1781. <ul>
  1782. <li><p>Removed special methods <code class="docutils literal notranslate"><span class="pre">__int__</span></code>, <code class="docutils literal notranslate"><span class="pre">__float__</span></code>, <code class="docutils literal notranslate"><span class="pre">__floordiv__</span></code>,
  1783. <code class="docutils literal notranslate"><span class="pre">__mod__</span></code>, <code class="docutils literal notranslate"><span class="pre">__divmod__</span></code>, <code class="docutils literal notranslate"><span class="pre">__rfloordiv__</span></code>, <code class="docutils literal notranslate"><span class="pre">__rmod__</span></code> and
  1784. <code class="docutils literal notranslate"><span class="pre">__rdivmod__</span></code> of the <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a> class. They always raised
  1785. 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>.
  1786. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41974">bpo-41974</a>.)</p></li>
  1787. <li><p>The <code class="docutils literal notranslate"><span class="pre">ParserBase.error()</span></code> method from the private and undocumented <code class="docutils literal notranslate"><span class="pre">_markupbase</span></code>
  1788. module has been removed. <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> is the only subclass of
  1789. <code class="docutils literal notranslate"><span class="pre">ParserBase</span></code> and its <code class="docutils literal notranslate"><span class="pre">error()</span></code> implementation was already removed in
  1790. Python 3.5.
  1791. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31844">bpo-31844</a>.)</p></li>
  1792. <li><p>Removed the <code class="docutils literal notranslate"><span class="pre">unicodedata.ucnhash_CAPI</span></code> attribute which was an internal
  1793. PyCapsule object. The related private <code class="docutils literal notranslate"><span class="pre">_PyUnicode_Name_CAPI</span></code> structure was
  1794. moved to the internal C API.
  1795. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42157">bpo-42157</a>.)</p></li>
  1796. <li><p>Removed the <code class="docutils literal notranslate"><span class="pre">parser</span></code> module, which was deprecated in 3.9 due to the
  1797. switch to the new PEG parser, as well as all the C source and header files
  1798. that were only being used by the old parser, including <code class="docutils literal notranslate"><span class="pre">node.h</span></code>, <code class="docutils literal notranslate"><span class="pre">parser.h</span></code>,
  1799. <code class="docutils literal notranslate"><span class="pre">graminit.h</span></code> and <code class="docutils literal notranslate"><span class="pre">grammar.h</span></code>.</p></li>
  1800. <li><p>Removed the Public C API functions <code class="docutils literal notranslate"><span class="pre">PyParser_SimpleParseStringFlags</span></code>,
  1801. <code class="docutils literal notranslate"><span class="pre">PyParser_SimpleParseStringFlagsFilename</span></code>,
  1802. <code class="docutils literal notranslate"><span class="pre">PyParser_SimpleParseFileFlags</span></code> and <code class="docutils literal notranslate"><span class="pre">PyNode_Compile</span></code>
  1803. that were deprecated in 3.9 due to the switch to the new PEG parser.</p></li>
  1804. <li><p>Removed the <code class="docutils literal notranslate"><span class="pre">formatter</span></code> module, which was deprecated in Python 3.4.
  1805. It is somewhat obsolete, little used, and not tested. It was originally
  1806. scheduled to be removed in Python 3.6, but such removals were delayed until
  1807. after Python 2.7 EOL. Existing users should copy whatever classes they use
  1808. into their code.
  1809. (Contributed by Donghee Na and Terry J. Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42299">bpo-42299</a>.)</p></li>
  1810. <li><p>Removed the <code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_GetWarningsModule()</span></code> function that was useless
  1811. now due to the <code class="xref py py-mod docutils literal notranslate"><span class="pre">_warnings</span></code> module was converted to a builtin module in 2.6.
  1812. (Contributed by Hai Shi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42599">bpo-42599</a>.)</p></li>
  1813. <li><p>Remove deprecated aliases to <a class="reference internal" href="../library/collections.abc.html#collections-abstract-base-classes"><span class="std std-ref">Collections Abstract Base Classes</span></a> from
  1814. 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.
  1815. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37324">bpo-37324</a>.)</p></li>
  1816. <li><p>The <code class="docutils literal notranslate"><span class="pre">loop</span></code> parameter has been removed from most of <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a>‘s
  1817. <a class="reference internal" href="../library/asyncio-api-index.html"><span class="doc">high-level API</span></a> following deprecation
  1818. in Python 3.8. The motivation behind this change is multifold:</p>
  1819. <ol class="arabic simple">
  1820. <li><p>This simplifies the high-level API.</p></li>
  1821. <li><p>The functions in the high-level API have been implicitly getting the
  1822. current thread’s running event loop since Python 3.7. There isn’t a need to
  1823. pass the event loop to the API in most normal use cases.</p></li>
  1824. <li><p>Event loop passing is error-prone especially when dealing with loops
  1825. running in different threads.</p></li>
  1826. </ol>
  1827. <p>Note that the low-level API will still accept <code class="docutils literal notranslate"><span class="pre">loop</span></code>.
  1828. See <a class="reference internal" href="#changes-python-api"><span class="std std-ref">Changes in the Python API</span></a> for examples of how to replace existing code.</p>
  1829. <p>(Contributed by Yurii Karabas, Andrew Svetlov, Yury Selivanov and Kyle Stanley
  1830. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42392">bpo-42392</a>.)</p>
  1831. </li>
  1832. </ul>
  1833. </section>
  1834. <section id="porting-to-python-3-10">
  1835. <h2>Porting to Python 3.10<a class="headerlink" href="#porting-to-python-3-10" title="Link to this heading">¶</a></h2>
  1836. <p>This section lists previously described changes and other bugfixes
  1837. that may require changes to your code.</p>
  1838. <section id="changes-in-the-python-syntax">
  1839. <h3>Changes in the Python syntax<a class="headerlink" href="#changes-in-the-python-syntax" title="Link to this heading">¶</a></h3>
  1840. <ul class="simple">
  1841. <li><p>Deprecation warning is now emitted when compiling previously valid syntax
  1842. if the numeric literal is immediately followed by a keyword (like in <code class="docutils literal notranslate"><span class="pre">0in</span> <span class="pre">x</span></code>).
  1843. In future releases it will be changed to syntax warning, and finally to a
  1844. syntax error. To get rid of the warning and make the code compatible with
  1845. future releases just add a space between the numeric literal and the
  1846. following keyword.
  1847. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43833">bpo-43833</a>.)</p></li>
  1848. </ul>
  1849. </section>
  1850. <section id="changes-in-the-python-api">
  1851. <span id="changes-python-api"></span><h3>Changes in the Python API<a class="headerlink" href="#changes-in-the-python-api" title="Link to this heading">¶</a></h3>
  1852. <ul>
  1853. <li><p>The <em>etype</em> parameters of the <a class="reference internal" href="../library/traceback.html#traceback.format_exception" title="traceback.format_exception"><code class="xref py py-func docutils literal notranslate"><span class="pre">format_exception()</span></code></a>,
  1854. <a class="reference internal" href="../library/traceback.html#traceback.format_exception_only" title="traceback.format_exception_only"><code class="xref py py-func docutils literal notranslate"><span class="pre">format_exception_only()</span></code></a>, and
  1855. <a class="reference internal" href="../library/traceback.html#traceback.print_exception" title="traceback.print_exception"><code class="xref py py-func docutils literal notranslate"><span class="pre">print_exception()</span></code></a> functions in the <a class="reference internal" href="../library/traceback.html#module-traceback" title="traceback: Print or retrieve a stack traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">traceback</span></code></a> module
  1856. have been renamed to <em>exc</em>.
  1857. (Contributed by Zackery Spytz and Matthias Bussonnier in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26389">bpo-26389</a>.)</p></li>
  1858. <li><p><a class="reference internal" href="../library/atexit.html#module-atexit" title="atexit: Register and execute cleanup functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">atexit</span></code></a>: At Python exit, if a callback registered with
  1859. <a class="reference internal" href="../library/atexit.html#atexit.register" title="atexit.register"><code class="xref py py-func docutils literal notranslate"><span class="pre">atexit.register()</span></code></a> fails, its exception is now logged. Previously, only
  1860. some exceptions were logged, and the last exception was always silently
  1861. ignored.
  1862. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42639">bpo-42639</a>.)</p></li>
  1863. <li><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
  1864. 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
  1865. <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
  1866. <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>. Code which
  1867. 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> need to account
  1868. for this change. Furthermore, <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> may be raised for invalid forms
  1869. 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 passed
  1870. silently in Python 3.9.
  1871. (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></li>
  1872. <li><p><a class="reference internal" href="../library/socket.html#socket.htons" title="socket.htons"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.htons()</span></code></a> and <a class="reference internal" href="../library/socket.html#socket.ntohs" title="socket.ntohs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.ntohs()</span></code></a> now raise <a class="reference internal" href="../library/exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a>
  1873. instead of <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> if the given parameter will not fit in
  1874. a 16-bit unsigned integer.
  1875. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42393">bpo-42393</a>.)</p></li>
  1876. <li><p>The <code class="docutils literal notranslate"><span class="pre">loop</span></code> parameter has been removed from most of <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a>‘s
  1877. <a class="reference internal" href="../library/asyncio-api-index.html"><span class="doc">high-level API</span></a> following deprecation
  1878. in Python 3.8.</p>
  1879. <p>A coroutine that currently looks like this:</p>
  1880. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">async</span> <span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="n">loop</span><span class="p">):</span>
  1881. <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="n">loop</span><span class="p">)</span>
  1882. </pre></div>
  1883. </div>
  1884. <p>Should be replaced with this:</p>
  1885. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">async</span> <span class="k">def</span> <span class="nf">foo</span><span class="p">():</span>
  1886. <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
  1887. </pre></div>
  1888. </div>
  1889. <p>If <code class="docutils literal notranslate"><span class="pre">foo()</span></code> was specifically designed <em>not</em> to run in the current thread’s
  1890. running event loop (e.g. running in another thread’s event loop), consider
  1891. using <a class="reference internal" href="../library/asyncio-task.html#asyncio.run_coroutine_threadsafe" title="asyncio.run_coroutine_threadsafe"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.run_coroutine_threadsafe()</span></code></a> instead.</p>
  1892. <p>(Contributed by Yurii Karabas, Andrew Svetlov, Yury Selivanov and Kyle Stanley
  1893. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42392">bpo-42392</a>.)</p>
  1894. </li>
  1895. <li><p>The <a class="reference internal" href="../library/types.html#types.FunctionType" title="types.FunctionType"><code class="xref py py-data docutils literal notranslate"><span class="pre">types.FunctionType</span></code></a> constructor now inherits the current builtins
  1896. if the <em>globals</em> dictionary has no <code class="docutils literal notranslate"><span class="pre">&quot;__builtins__&quot;</span></code> key, rather than using
  1897. <code class="docutils literal notranslate"><span class="pre">{&quot;None&quot;:</span> <span class="pre">None}</span></code> as builtins: same behavior as <a class="reference internal" href="../library/functions.html#eval" title="eval"><code class="xref py py-func docutils literal notranslate"><span class="pre">eval()</span></code></a> and
  1898. <a class="reference internal" href="../library/functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a> functions. Defining a function with <code class="docutils literal notranslate"><span class="pre">def</span> <span class="pre">function(...):</span> <span class="pre">...</span></code>
  1899. in Python is not affected, globals cannot be overridden with this syntax: it
  1900. also inherits the current builtins.
  1901. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42990">bpo-42990</a>.)</p></li>
  1902. </ul>
  1903. </section>
  1904. <section id="changes-in-the-c-api">
  1905. <h3>Changes in the C API<a class="headerlink" href="#changes-in-the-c-api" title="Link to this heading">¶</a></h3>
  1906. <ul>
  1907. <li><p>The C API functions <code class="docutils literal notranslate"><span class="pre">PyParser_SimpleParseStringFlags</span></code>,
  1908. <code class="docutils literal notranslate"><span class="pre">PyParser_SimpleParseStringFlagsFilename</span></code>,
  1909. <code class="docutils literal notranslate"><span class="pre">PyParser_SimpleParseFileFlags</span></code>, <code class="docutils literal notranslate"><span class="pre">PyNode_Compile</span></code> and the type
  1910. used by these functions, <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">_node</span></code>, were removed due to the switch
  1911. to the new PEG parser.</p>
  1912. <p>Source should be now be compiled directly to a code object using, for
  1913. example, <a class="reference internal" href="../c-api/veryhigh.html#c.Py_CompileString" title="Py_CompileString"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_CompileString()</span></code></a>. The resulting code object can then be
  1914. evaluated using, for example, <a class="reference internal" href="../c-api/veryhigh.html#c.PyEval_EvalCode" title="PyEval_EvalCode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_EvalCode()</span></code></a>.</p>
  1915. <p>Specifically:</p>
  1916. <ul>
  1917. <li><p>A call to <code class="docutils literal notranslate"><span class="pre">PyParser_SimpleParseStringFlags</span></code> followed by
  1918. <code class="docutils literal notranslate"><span class="pre">PyNode_Compile</span></code> can be replaced by calling <a class="reference internal" href="../c-api/veryhigh.html#c.Py_CompileString" title="Py_CompileString"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_CompileString()</span></code></a>.</p></li>
  1919. <li><p>There is no direct replacement for <code class="docutils literal notranslate"><span class="pre">PyParser_SimpleParseFileFlags</span></code>.
  1920. To compile code from a <code class="docutils literal notranslate"><span class="pre">FILE</span> <span class="pre">*</span></code> argument, you will need to read
  1921. the file in C and pass the resulting buffer to <a class="reference internal" href="../c-api/veryhigh.html#c.Py_CompileString" title="Py_CompileString"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_CompileString()</span></code></a>.</p></li>
  1922. <li><p>To compile a file given a <code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*</span></code> filename, explicitly open the file, read
  1923. it and compile the result. One way to do this is using the <a class="reference internal" href="../library/io.html#module-io" title="io: Core tools for working with streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">io</span></code></a>
  1924. module with <a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModule" title="PyImport_ImportModule"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModule()</span></code></a>, <a class="reference internal" href="../c-api/call.html#c.PyObject_CallMethod" title="PyObject_CallMethod"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CallMethod()</span></code></a>,
  1925. <a class="reference internal" href="../c-api/bytes.html#c.PyBytes_AsString" title="PyBytes_AsString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBytes_AsString()</span></code></a> and <a class="reference internal" href="../c-api/veryhigh.html#c.Py_CompileString" title="Py_CompileString"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_CompileString()</span></code></a>,
  1926. as sketched below. (Declarations and error handling are omitted.)</p>
  1927. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">io_module</span> <span class="o">=</span> <span class="n">Import_ImportModule</span><span class="p">(</span><span class="s2">&quot;io&quot;</span><span class="p">);</span>
  1928. <span class="n">fileobject</span> <span class="o">=</span> <span class="n">PyObject_CallMethod</span><span class="p">(</span><span class="n">io_module</span><span class="p">,</span> <span class="s2">&quot;open&quot;</span><span class="p">,</span> <span class="s2">&quot;ss&quot;</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;rb&quot;</span><span class="p">);</span>
  1929. <span class="n">source_bytes_object</span> <span class="o">=</span> <span class="n">PyObject_CallMethod</span><span class="p">(</span><span class="n">fileobject</span><span class="p">,</span> <span class="s2">&quot;read&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">);</span>
  1930. <span class="n">result</span> <span class="o">=</span> <span class="n">PyObject_CallMethod</span><span class="p">(</span><span class="n">fileobject</span><span class="p">,</span> <span class="s2">&quot;close&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">);</span>
  1931. <span class="n">source_buf</span> <span class="o">=</span> <span class="n">PyBytes_AsString</span><span class="p">(</span><span class="n">source_bytes_object</span><span class="p">);</span>
  1932. <span class="n">code</span> <span class="o">=</span> <span class="n">Py_CompileString</span><span class="p">(</span><span class="n">source_buf</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">Py_file_input</span><span class="p">);</span>
  1933. </pre></div>
  1934. </div>
  1935. </li>
  1936. <li><p>For <code class="docutils literal notranslate"><span class="pre">FrameObject</span></code> objects, the <a class="reference internal" href="../reference/datamodel.html#frame.f_lasti" title="frame.f_lasti"><code class="xref py py-attr docutils literal notranslate"><span class="pre">f_lasti</span></code></a> member now represents a wordcode
  1937. offset instead of a simple offset into the bytecode string. This means that this
  1938. number needs to be multiplied by 2 to be used with APIs that expect a byte offset
  1939. instead (like <a class="reference internal" href="../c-api/code.html#c.PyCode_Addr2Line" title="PyCode_Addr2Line"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_Addr2Line()</span></code></a> for example). Notice as well that the
  1940. <code class="xref py py-attr docutils literal notranslate"><span class="pre">f_lasti</span></code> member of <code class="docutils literal notranslate"><span class="pre">FrameObject</span></code> objects is not considered stable: please
  1941. use <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> instead.</p></li>
  1942. </ul>
  1943. </li>
  1944. </ul>
  1945. </section>
  1946. </section>
  1947. <section id="cpython-bytecode-changes">
  1948. <h2>CPython bytecode changes<a class="headerlink" href="#cpython-bytecode-changes" title="Link to this heading">¶</a></h2>
  1949. <ul class="simple">
  1950. <li><p>The <code class="docutils literal notranslate"><span class="pre">MAKE_FUNCTION</span></code> instruction now accepts either a dict or a tuple of
  1951. strings as the function’s annotations.
  1952. (Contributed by Yurii Karabas and Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42202">bpo-42202</a>.)</p></li>
  1953. </ul>
  1954. </section>
  1955. <section id="build-changes">
  1956. <h2>Build Changes<a class="headerlink" href="#build-changes" title="Link to this heading">¶</a></h2>
  1957. <ul>
  1958. <li><p><span class="target" id="index-35"></span><a class="pep reference external" href="https://peps.python.org/pep-0644/"><strong>PEP 644</strong></a>: Python now requires OpenSSL 1.1.1 or newer. OpenSSL 1.0.2 is no
  1959. longer supported.
  1960. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43669">bpo-43669</a>.)</p></li>
  1961. <li><p>The C99 functions <code class="xref c c-func docutils literal notranslate"><span class="pre">snprintf()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">vsnprintf()</span></code> are now required
  1962. to build Python.
  1963. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36020">bpo-36020</a>.)</p></li>
  1964. <li><p><a class="reference internal" href="../library/sqlite3.html#module-sqlite3" title="sqlite3: A DB-API 2.0 implementation using SQLite 3.x."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlite3</span></code></a> requires SQLite 3.7.15 or higher. (Contributed by Sergey Fedoseev
  1965. and Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40744">bpo-40744</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40810">bpo-40810</a>.)</p></li>
  1966. <li><p>The <a class="reference internal" href="../library/atexit.html#module-atexit" title="atexit: Register and execute cleanup functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">atexit</span></code></a> module must now always be built as a built-in module.
  1967. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42639">bpo-42639</a>.)</p></li>
  1968. <li><p>Add <a class="reference internal" href="../using/configure.html#cmdoption-disable-test-modules"><code class="xref std std-option docutils literal notranslate"><span class="pre">--disable-test-modules</span></code></a> option to the <code class="docutils literal notranslate"><span class="pre">configure</span></code> script:
  1969. don’t build nor install test modules.
  1970. (Contributed by Xavier de Gaye, Thomas Petazzoni and Peixing Xin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27640">bpo-27640</a>.)</p></li>
  1971. <li><p>Add <a class="reference internal" href="../using/configure.html#cmdoption-with-wheel-pkg-dir"><code class="xref std std-option docutils literal notranslate"><span class="pre">--with-wheel-pkg-dir=PATH</span> <span class="pre">option</span></code></a>
  1972. to the <code class="docutils literal notranslate"><span class="pre">./configure</span></code> script. If
  1973. specified, the <a class="reference internal" href="../library/ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the &quot;pip&quot; installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a> module looks for <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> and <code class="docutils literal notranslate"><span class="pre">pip</span></code>
  1974. wheel packages in this directory: if both are present, these wheel packages
  1975. are used instead of ensurepip bundled wheel packages.</p>
  1976. <p>Some Linux distribution packaging policies recommend against bundling
  1977. dependencies. For example, Fedora installs wheel packages in the
  1978. <code class="docutils literal notranslate"><span class="pre">/usr/share/python-wheels/</span></code> directory and don’t install the
  1979. <code class="docutils literal notranslate"><span class="pre">ensurepip._bundled</span></code> package.</p>
  1980. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42856">bpo-42856</a>.)</p>
  1981. </li>
  1982. <li><p>Add a new <a class="reference internal" href="../using/configure.html#cmdoption-without-static-libpython"><code class="xref std std-option docutils literal notranslate"><span class="pre">configure</span> <span class="pre">--without-static-libpython</span> <span class="pre">option</span></code></a> to not build the <code class="docutils literal notranslate"><span class="pre">libpythonMAJOR.MINOR.a</span></code>
  1983. static library and not install the <code class="docutils literal notranslate"><span class="pre">python.o</span></code> object file.</p>
  1984. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43103">bpo-43103</a>.)</p>
  1985. </li>
  1986. <li><p>The <code class="docutils literal notranslate"><span class="pre">configure</span></code> script now uses the <code class="docutils literal notranslate"><span class="pre">pkg-config</span></code> utility, if available,
  1987. to detect the location of Tcl/Tk headers and libraries. As before, those
  1988. locations can be explicitly specified with the <code class="docutils literal notranslate"><span class="pre">--with-tcltk-includes</span></code>
  1989. and <code class="docutils literal notranslate"><span class="pre">--with-tcltk-libs</span></code> configuration options.
  1990. (Contributed by Manolis Stamatogiannakis in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42603">bpo-42603</a>.)</p></li>
  1991. <li><p>Add <a class="reference internal" href="../using/configure.html#cmdoption-with-openssl-rpath"><code class="xref std std-option docutils literal notranslate"><span class="pre">--with-openssl-rpath</span></code></a> option to <code class="docutils literal notranslate"><span class="pre">configure</span></code> script. The option
  1992. simplifies building Python with a custom OpenSSL installation, e.g.
  1993. <code class="docutils literal notranslate"><span class="pre">./configure</span> <span class="pre">--with-openssl=/path/to/openssl</span> <span class="pre">--with-openssl-rpath=auto</span></code>.
  1994. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43466">bpo-43466</a>.)</p></li>
  1995. </ul>
  1996. </section>
  1997. <section id="c-api-changes">
  1998. <h2>C API Changes<a class="headerlink" href="#c-api-changes" title="Link to this heading">¶</a></h2>
  1999. <section id="pep-652-maintaining-the-stable-abi">
  2000. <h3>PEP 652: Maintaining the Stable ABI<a class="headerlink" href="#pep-652-maintaining-the-stable-abi" title="Link to this heading">¶</a></h3>
  2001. <p>The Stable ABI (Application Binary Interface) for extension modules or
  2002. embedding Python is now explicitly defined.
  2003. <a class="reference internal" href="../c-api/stable.html#stable"><span class="std std-ref">C API Stability</span></a> describes C API and ABI stability guarantees along with best
  2004. practices for using the Stable ABI.</p>
  2005. <p>(Contributed by Petr Viktorin in <span class="target" id="index-36"></span><a class="pep reference external" href="https://peps.python.org/pep-0652/"><strong>PEP 652</strong></a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43795">bpo-43795</a>.)</p>
  2006. </section>
  2007. <section id="id1">
  2008. <h3>New Features<a class="headerlink" href="#id1" title="Link to this heading">¶</a></h3>
  2009. <ul>
  2010. <li><p>The result of <a class="reference internal" href="../c-api/number.html#c.PyNumber_Index" title="PyNumber_Index"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyNumber_Index()</span></code></a> now always has exact type <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>.
  2011. Previously, the result could have been an instance of a subclass of <code class="docutils literal notranslate"><span class="pre">int</span></code>.
  2012. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40792">bpo-40792</a>.)</p></li>
  2013. <li><p>Add a new <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.orig_argv" title="PyConfig.orig_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">orig_argv</span></code></a> member to the <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>
  2014. structure: the list of the original command line arguments passed to the
  2015. Python executable.
  2016. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23427">bpo-23427</a>.)</p></li>
  2017. <li><p>The <a class="reference internal" href="../c-api/datetime.html#c.PyDateTime_DATE_GET_TZINFO" title="PyDateTime_DATE_GET_TZINFO"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDateTime_DATE_GET_TZINFO()</span></code></a> and
  2018. <a class="reference internal" href="../c-api/datetime.html#c.PyDateTime_TIME_GET_TZINFO" title="PyDateTime_TIME_GET_TZINFO"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDateTime_TIME_GET_TZINFO()</span></code></a> macros have been added for accessing
  2019. the <code class="docutils literal notranslate"><span class="pre">tzinfo</span></code> attributes 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> and
  2020. <a class="reference internal" href="../library/datetime.html#datetime.time" title="datetime.time"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.time</span></code></a> objects.
  2021. (Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30155">bpo-30155</a>.)</p></li>
  2022. <li><p>Add a <a class="reference internal" href="../c-api/codec.html#c.PyCodec_Unregister" title="PyCodec_Unregister"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCodec_Unregister()</span></code></a> function to unregister a codec
  2023. search function.
  2024. (Contributed by Hai Shi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41842">bpo-41842</a>.)</p></li>
  2025. <li><p>The <a class="reference internal" href="../c-api/iter.html#c.PyIter_Send" title="PyIter_Send"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyIter_Send()</span></code></a> function was added to allow
  2026. sending value into iterator without raising <code class="docutils literal notranslate"><span class="pre">StopIteration</span></code> exception.
  2027. (Contributed by Vladimir Matveev in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41756">bpo-41756</a>.)</p></li>
  2028. <li><p>Add <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUTF8AndSize" title="PyUnicode_AsUTF8AndSize"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUTF8AndSize()</span></code></a> to the limited C API.
  2029. (Contributed by Alex Gaynor in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41784">bpo-41784</a>.)</p></li>
  2030. <li><p>Add <a class="reference internal" href="../c-api/module.html#c.PyModule_AddObjectRef" title="PyModule_AddObjectRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_AddObjectRef()</span></code></a> function: similar to
  2031. <a class="reference internal" href="../c-api/module.html#c.PyModule_AddObject" title="PyModule_AddObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_AddObject()</span></code></a> but don’t steal a reference to the value on
  2032. success.
  2033. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1635741">bpo-1635741</a>.)</p></li>
  2034. <li><p>Add <a class="reference internal" href="../c-api/refcounting.html#c.Py_NewRef" title="Py_NewRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_NewRef()</span></code></a> and <a class="reference internal" href="../c-api/refcounting.html#c.Py_XNewRef" title="Py_XNewRef"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_XNewRef()</span></code></a> functions to increment the
  2035. reference count of an object and return the object.
  2036. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42262">bpo-42262</a>.)</p></li>
  2037. <li><p>The <a class="reference internal" href="../c-api/type.html#c.PyType_FromSpecWithBases" title="PyType_FromSpecWithBases"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromSpecWithBases()</span></code></a> and <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>
  2038. functions now accept a single class as the <em>bases</em> argument.
  2039. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42423">bpo-42423</a>.)</p></li>
  2040. <li><p>The <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> function now accepts NULL <code class="docutils literal notranslate"><span class="pre">tp_doc</span></code>
  2041. slot.
  2042. (Contributed by Hai Shi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41832">bpo-41832</a>.)</p></li>
  2043. <li><p>The <a class="reference internal" href="../c-api/type.html#c.PyType_GetSlot" title="PyType_GetSlot"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetSlot()</span></code></a> function can accept
  2044. <a class="reference internal" href="../c-api/typeobj.html#static-types"><span class="std std-ref">static types</span></a>.
  2045. (Contributed by Hai Shi and Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41073">bpo-41073</a>.)</p></li>
  2046. <li><p>Add a new <a class="reference internal" href="../c-api/set.html#c.PySet_CheckExact" title="PySet_CheckExact"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySet_CheckExact()</span></code></a> function to the C-API to check if an
  2047. object is an instance of <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> but not an instance of a subtype.
  2048. (Contributed by Pablo Galindo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43277">bpo-43277</a>.)</p></li>
  2049. <li><p>Add <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetInterruptEx" title="PyErr_SetInterruptEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetInterruptEx()</span></code></a> which allows passing a signal number
  2050. to simulate.
  2051. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43356">bpo-43356</a>.)</p></li>
  2052. <li><p>The limited C API is now supported if <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">Python is built in debug mode</span></a> (if the <code class="docutils literal notranslate"><span class="pre">Py_DEBUG</span></code> macro is defined). In the limited C API,
  2053. the <a class="reference internal" href="../c-api/refcounting.html#c.Py_INCREF" title="Py_INCREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_INCREF()</span></code></a> and <a class="reference internal" href="../c-api/refcounting.html#c.Py_DECREF" title="Py_DECREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DECREF()</span></code></a> functions are now implemented
  2054. as opaque function
  2055. calls, rather than accessing directly the <a class="reference internal" href="../c-api/typeobj.html#c.PyObject.ob_refcnt" title="PyObject.ob_refcnt"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyObject.ob_refcnt</span></code></a>
  2056. member, if Python is built in debug mode and the <code class="docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code> macro
  2057. targets Python 3.10 or newer. It became possible to support the limited C API
  2058. in debug mode because the <a class="reference internal" href="../c-api/structures.html#c.PyObject" title="PyObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyObject</span></code></a> structure is the same in release
  2059. and debug mode since Python 3.8 (see <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=36465">bpo-36465</a>).</p>
  2060. <p>The limited C API is still not supported in the <a class="reference internal" href="../using/configure.html#cmdoption-with-trace-refs"><code class="xref std std-option docutils literal notranslate"><span class="pre">--with-trace-refs</span></code></a>
  2061. special build (<code class="docutils literal notranslate"><span class="pre">Py_TRACE_REFS</span></code> macro).
  2062. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43688">bpo-43688</a>.)</p>
  2063. </li>
  2064. <li><p>Add the <a class="reference internal" href="../c-api/structures.html#c.Py_Is" title="Py_Is"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Is(x,</span> <span class="pre">y)</span></code></a> function to test if the <em>x</em> object is
  2065. the <em>y</em> object, the same as <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">is</span> <span class="pre">y</span></code> in Python. Add also the
  2066. <a class="reference internal" href="../c-api/structures.html#c.Py_IsNone" title="Py_IsNone"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_IsNone()</span></code></a>, <a class="reference internal" href="../c-api/structures.html#c.Py_IsTrue" title="Py_IsTrue"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_IsTrue()</span></code></a>, <a class="reference internal" href="../c-api/structures.html#c.Py_IsFalse" title="Py_IsFalse"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_IsFalse()</span></code></a> functions to
  2067. test if an object is, respectively, the <code class="docutils literal notranslate"><span class="pre">None</span></code> singleton, the <code class="docutils literal notranslate"><span class="pre">True</span></code>
  2068. singleton or the <code class="docutils literal notranslate"><span class="pre">False</span></code> singleton.
  2069. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43753">bpo-43753</a>.)</p></li>
  2070. <li><p>Add new functions to control the garbage collector from C code:
  2071. <a class="reference internal" href="../c-api/gcsupport.html#c.PyGC_Enable" title="PyGC_Enable"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyGC_Enable()</span></code></a>,
  2072. <a class="reference internal" href="../c-api/gcsupport.html#c.PyGC_Disable" title="PyGC_Disable"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyGC_Disable()</span></code></a>,
  2073. <a class="reference internal" href="../c-api/gcsupport.html#c.PyGC_IsEnabled" title="PyGC_IsEnabled"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyGC_IsEnabled()</span></code></a>.
  2074. These functions allow to activate, deactivate and query the state of the garbage collector from C code without
  2075. having to import the <a class="reference internal" href="../library/gc.html#module-gc" title="gc: Interface to the cycle-detecting garbage collector."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gc</span></code></a> module.</p></li>
  2076. <li><p>Add a new <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_DISALLOW_INSTANTIATION" title="Py_TPFLAGS_DISALLOW_INSTANTIATION"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_DISALLOW_INSTANTIATION</span></code></a> type flag to disallow
  2077. creating type instances.
  2078. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43916">bpo-43916</a>.)</p></li>
  2079. <li><p>Add a new <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_IMMUTABLETYPE" title="Py_TPFLAGS_IMMUTABLETYPE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_IMMUTABLETYPE</span></code></a> type flag for creating immutable
  2080. type objects: type attributes cannot be set nor deleted.
  2081. (Contributed by Victor Stinner and Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43908">bpo-43908</a>.)</p></li>
  2082. </ul>
  2083. </section>
  2084. <section id="id2">
  2085. <h3>Porting to Python 3.10<a class="headerlink" href="#id2" title="Link to this heading">¶</a></h3>
  2086. <ul>
  2087. <li><p>The <code class="docutils literal notranslate"><span class="pre">PY_SSIZE_T_CLEAN</span></code> macro must now be defined to use
  2088. <a class="reference internal" href="../c-api/arg.html#c.PyArg_ParseTuple" title="PyArg_ParseTuple"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTuple()</span></code></a> and <a class="reference internal" href="../c-api/arg.html#c.Py_BuildValue" title="Py_BuildValue"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_BuildValue()</span></code></a> formats which use
  2089. <code class="docutils literal notranslate"><span class="pre">#</span></code>: <code class="docutils literal notranslate"><span class="pre">es#</span></code>, <code class="docutils literal notranslate"><span class="pre">et#</span></code>, <code class="docutils literal notranslate"><span class="pre">s#</span></code>, <code class="docutils literal notranslate"><span class="pre">u#</span></code>, <code class="docutils literal notranslate"><span class="pre">y#</span></code>, <code class="docutils literal notranslate"><span class="pre">z#</span></code>, <code class="docutils literal notranslate"><span class="pre">U#</span></code> and <code class="docutils literal notranslate"><span class="pre">Z#</span></code>.
  2090. See <a class="reference internal" href="../c-api/arg.html#arg-parsing"><span class="std std-ref">Parsing arguments and building values</span></a> and <span class="target" id="index-37"></span><a class="pep reference external" href="https://peps.python.org/pep-0353/"><strong>PEP 353</strong></a>.
  2091. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40943">bpo-40943</a>.)</p></li>
  2092. <li><p>Since <a class="reference internal" href="../c-api/refcounting.html#c.Py_REFCNT" title="Py_REFCNT"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_REFCNT()</span></code></a> is changed to the inline static function,
  2093. <code class="docutils literal notranslate"><span class="pre">Py_REFCNT(obj)</span> <span class="pre">=</span> <span class="pre">new_refcnt</span></code> must be replaced with <code class="docutils literal notranslate"><span class="pre">Py_SET_REFCNT(obj,</span> <span class="pre">new_refcnt)</span></code>:
  2094. see <a class="reference internal" href="../c-api/refcounting.html#c.Py_SET_REFCNT" title="Py_SET_REFCNT"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SET_REFCNT()</span></code></a> (available since Python 3.9). For backward
  2095. compatibility, this macro can be used:</p>
  2096. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX &lt; 0x030900A4</span>
  2097. <span class="c1"># define Py_SET_REFCNT(obj, refcnt) ((Py_REFCNT(obj) = (refcnt)), (void)0)</span>
  2098. <span class="c1">#endif</span>
  2099. </pre></div>
  2100. </div>
  2101. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39573">bpo-39573</a>.)</p>
  2102. </li>
  2103. <li><p>Calling <a class="reference internal" href="../c-api/dict.html#c.PyDict_GetItem" title="PyDict_GetItem"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_GetItem()</span></code></a> without <a class="reference internal" href="../glossary.html#term-GIL"><span class="xref std std-term">GIL</span></a> held had been allowed
  2104. for historical reason. It is no longer allowed.
  2105. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40839">bpo-40839</a>.)</p></li>
  2106. <li><p><code class="docutils literal notranslate"><span class="pre">PyUnicode_FromUnicode(NULL,</span> <span class="pre">size)</span></code> and <code class="docutils literal notranslate"><span class="pre">PyUnicode_FromStringAndSize(NULL,</span> <span class="pre">size)</span></code>
  2107. raise <code class="docutils literal notranslate"><span class="pre">DeprecationWarning</span></code> now. Use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_New" title="PyUnicode_New"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_New()</span></code></a> to allocate
  2108. Unicode object without initial data.
  2109. (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>
  2110. <li><p>The private <code class="docutils literal notranslate"><span class="pre">_PyUnicode_Name_CAPI</span></code> structure of the PyCapsule API
  2111. <code class="docutils literal notranslate"><span class="pre">unicodedata.ucnhash_CAPI</span></code> has been moved to the internal C API.
  2112. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42157">bpo-42157</a>.)</p></li>
  2113. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_GetPath" title="Py_GetPath"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetPath()</span></code></a>, <a class="reference internal" href="../c-api/init.html#c.Py_GetPrefix" title="Py_GetPrefix"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetPrefix()</span></code></a>, <a class="reference internal" href="../c-api/init.html#c.Py_GetExecPrefix" title="Py_GetExecPrefix"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetExecPrefix()</span></code></a>,
  2114. <a class="reference internal" href="../c-api/init.html#c.Py_GetProgramFullPath" title="Py_GetProgramFullPath"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetProgramFullPath()</span></code></a>, <a class="reference internal" href="../c-api/init.html#c.Py_GetPythonHome" title="Py_GetPythonHome"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetPythonHome()</span></code></a> and
  2115. <a class="reference internal" href="../c-api/init.html#c.Py_GetProgramName" title="Py_GetProgramName"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetProgramName()</span></code></a> functions now return <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if called before
  2116. <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> (before Python is initialized). Use the new
  2117. <a class="reference internal" href="../c-api/init_config.html#init-config"><span class="std std-ref">Python Initialization Configuration</span></a> API to get the <a class="reference internal" href="../c-api/init_config.html#init-path-config"><span class="std std-ref">Python Path Configuration</span></a>.
  2118. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42260">bpo-42260</a>.)</p></li>
  2119. <li><p><a class="reference internal" href="../c-api/list.html#c.PyList_SET_ITEM" title="PyList_SET_ITEM"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyList_SET_ITEM()</span></code></a>, <a class="reference internal" href="../c-api/tuple.html#c.PyTuple_SET_ITEM" title="PyTuple_SET_ITEM"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyTuple_SET_ITEM()</span></code></a> and
  2120. <a class="reference internal" href="../c-api/cell.html#c.PyCell_SET" title="PyCell_SET"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCell_SET()</span></code></a> macros can no longer be used as l-value or r-value.
  2121. For example, <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">=</span> <span class="pre">PyList_SET_ITEM(a,</span> <span class="pre">b,</span> <span class="pre">c)</span></code> and
  2122. <code class="docutils literal notranslate"><span class="pre">PyList_SET_ITEM(a,</span> <span class="pre">b,</span> <span class="pre">c)</span> <span class="pre">=</span> <span class="pre">x</span></code> now fail with a compiler error. It prevents
  2123. bugs like <code class="docutils literal notranslate"><span class="pre">if</span> <span class="pre">(PyList_SET_ITEM</span> <span class="pre">(a,</span> <span class="pre">b,</span> <span class="pre">c)</span> <span class="pre">&lt;</span> <span class="pre">0)</span> <span class="pre">...</span></code> test.
  2124. (Contributed by Zackery Spytz and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30459">bpo-30459</a>.)</p></li>
  2125. <li><p>The non-limited API files <code class="docutils literal notranslate"><span class="pre">odictobject.h</span></code>, <code class="docutils literal notranslate"><span class="pre">parser_interface.h</span></code>,
  2126. <code class="docutils literal notranslate"><span class="pre">picklebufobject.h</span></code>, <code class="docutils literal notranslate"><span class="pre">pyarena.h</span></code>, <code class="docutils literal notranslate"><span class="pre">pyctype.h</span></code>, <code class="docutils literal notranslate"><span class="pre">pydebug.h</span></code>,
  2127. <code class="docutils literal notranslate"><span class="pre">pyfpe.h</span></code>, and <code class="docutils literal notranslate"><span class="pre">pytime.h</span></code> have been moved to the <code class="docutils literal notranslate"><span class="pre">Include/cpython</span></code>
  2128. directory. These files must not be included directly, as they are already
  2129. included in <code class="docutils literal notranslate"><span class="pre">Python.h</span></code>; see <a class="reference internal" href="../c-api/intro.html#api-includes"><span class="std std-ref">Include Files</span></a>. If they have
  2130. been included directly, consider including <code class="docutils literal notranslate"><span class="pre">Python.h</span></code> instead.
  2131. (Contributed by Nicholas Sim in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35134">bpo-35134</a>.)</p></li>
  2132. <li><p>Use the <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_IMMUTABLETYPE" title="Py_TPFLAGS_IMMUTABLETYPE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_IMMUTABLETYPE</span></code></a> type flag to create immutable type
  2133. objects. Do not rely on <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_HEAPTYPE" title="Py_TPFLAGS_HEAPTYPE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_HEAPTYPE</span></code></a> to decide if a type
  2134. object is mutable or not; check if <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_IMMUTABLETYPE" title="Py_TPFLAGS_IMMUTABLETYPE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_IMMUTABLETYPE</span></code></a> is set
  2135. instead.
  2136. (Contributed by Victor Stinner and Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43908">bpo-43908</a>.)</p></li>
  2137. <li><p>The undocumented function <code class="docutils literal notranslate"><span class="pre">Py_FrozenMain</span></code> has been removed from the
  2138. limited API. The function is mainly useful for custom builds of Python.
  2139. (Contributed by Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26241">bpo-26241</a>.)</p></li>
  2140. </ul>
  2141. </section>
  2142. <section id="id3">
  2143. <h3>Deprecated<a class="headerlink" href="#id3" title="Link to this heading">¶</a></h3>
  2144. <ul class="simple">
  2145. <li><p>The <code class="docutils literal notranslate"><span class="pre">PyUnicode_InternImmortal()</span></code> function is now deprecated
  2146. and will be removed in Python 3.12: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_InternInPlace" title="PyUnicode_InternInPlace"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_InternInPlace()</span></code></a>
  2147. instead.
  2148. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41692">bpo-41692</a>.)</p></li>
  2149. </ul>
  2150. </section>
  2151. <section id="id4">
  2152. <h3>Removed<a class="headerlink" href="#id4" title="Link to this heading">¶</a></h3>
  2153. <ul>
  2154. <li><p>Removed <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_str*</span></code> functions manipulating <code class="docutils literal notranslate"><span class="pre">Py_UNICODE*</span></code> strings.
  2155. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41123">bpo-41123</a>.)</p>
  2156. <ul class="simple">
  2157. <li><p><code class="docutils literal notranslate"><span class="pre">Py_UNICODE_strlen</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GetLength" title="PyUnicode_GetLength"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetLength()</span></code></a> or
  2158. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GET_LENGTH" title="PyUnicode_GET_LENGTH"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_GET_LENGTH</span></code></a></p></li>
  2159. <li><p><code class="docutils literal notranslate"><span class="pre">Py_UNICODE_strcat</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_CopyCharacters" title="PyUnicode_CopyCharacters"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_CopyCharacters()</span></code></a> or
  2160. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a></p></li>
  2161. <li><p><code class="docutils literal notranslate"><span class="pre">Py_UNICODE_strcpy</span></code>, <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_strncpy</span></code>: use
  2162. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_CopyCharacters" title="PyUnicode_CopyCharacters"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_CopyCharacters()</span></code></a> or <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Substring" title="PyUnicode_Substring"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Substring()</span></code></a></p></li>
  2163. <li><p><code class="docutils literal notranslate"><span class="pre">Py_UNICODE_strcmp</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Compare" title="PyUnicode_Compare"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Compare()</span></code></a></p></li>
  2164. <li><p><code class="docutils literal notranslate"><span class="pre">Py_UNICODE_strncmp</span></code>: use <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></p></li>
  2165. <li><p><code class="docutils literal notranslate"><span class="pre">Py_UNICODE_strchr</span></code>, <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_strrchr</span></code>: use
  2166. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FindChar" title="PyUnicode_FindChar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FindChar()</span></code></a></p></li>
  2167. </ul>
  2168. </li>
  2169. <li><p>Removed <code class="docutils literal notranslate"><span class="pre">PyUnicode_GetMax()</span></code>. Please migrate to new (<span class="target" id="index-38"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a>) APIs.
  2170. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41103">bpo-41103</a>.)</p></li>
  2171. <li><p>Removed <code class="docutils literal notranslate"><span class="pre">PyLong_FromUnicode()</span></code>. Please migrate to <a class="reference internal" href="../c-api/long.html#c.PyLong_FromUnicodeObject" title="PyLong_FromUnicodeObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyLong_FromUnicodeObject()</span></code></a>.
  2172. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41103">bpo-41103</a>.)</p></li>
  2173. <li><p>Removed <code class="docutils literal notranslate"><span class="pre">PyUnicode_AsUnicodeCopy()</span></code>. Please use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUCS4Copy" title="PyUnicode_AsUCS4Copy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUCS4Copy()</span></code></a> or
  2174. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsWideCharString" title="PyUnicode_AsWideCharString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsWideCharString()</span></code></a>
  2175. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41103">bpo-41103</a>.)</p></li>
  2176. <li><p>Removed <code class="docutils literal notranslate"><span class="pre">_Py_CheckRecursionLimit</span></code> variable: it has been replaced by
  2177. <code class="docutils literal notranslate"><span class="pre">ceval.recursion_limit</span></code> of the <a class="reference internal" href="../c-api/init.html#c.PyInterpreterState" title="PyInterpreterState"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyInterpreterState</span></code></a> structure.
  2178. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41834">bpo-41834</a>.)</p></li>
  2179. <li><p>Removed undocumented macros <code class="docutils literal notranslate"><span class="pre">Py_ALLOW_RECURSION</span></code> and
  2180. <code class="docutils literal notranslate"><span class="pre">Py_END_ALLOW_RECURSION</span></code> and the <code class="docutils literal notranslate"><span class="pre">recursion_critical</span></code> field of the
  2181. <a class="reference internal" href="../c-api/init.html#c.PyInterpreterState" title="PyInterpreterState"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyInterpreterState</span></code></a> structure.
  2182. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41936">bpo-41936</a>.)</p></li>
  2183. <li><p>Removed the undocumented <code class="docutils literal notranslate"><span class="pre">PyOS_InitInterrupts()</span></code> function. Initializing
  2184. Python already implicitly installs signal handlers: see
  2185. <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.install_signal_handlers" title="PyConfig.install_signal_handlers"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.install_signal_handlers</span></code></a>.
  2186. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41713">bpo-41713</a>.)</p></li>
  2187. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">PyAST_Validate()</span></code> function. It is no longer possible to build a
  2188. AST object (<code class="docutils literal notranslate"><span class="pre">mod_ty</span></code> type) with the public C API. The function was already
  2189. excluded from the limited C API (<span class="target" id="index-39"></span><a class="pep reference external" href="https://peps.python.org/pep-0384/"><strong>PEP 384</strong></a>).
  2190. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43244">bpo-43244</a>.)</p></li>
  2191. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">symtable.h</span></code> header file and the undocumented functions:</p>
  2192. <ul class="simple">
  2193. <li><p><code class="docutils literal notranslate"><span class="pre">PyST_GetScope()</span></code></p></li>
  2194. <li><p><code class="docutils literal notranslate"><span class="pre">PySymtable_Build()</span></code></p></li>
  2195. <li><p><code class="docutils literal notranslate"><span class="pre">PySymtable_BuildObject()</span></code></p></li>
  2196. <li><p><code class="docutils literal notranslate"><span class="pre">PySymtable_Free()</span></code></p></li>
  2197. <li><p><code class="docutils literal notranslate"><span class="pre">Py_SymtableString()</span></code></p></li>
  2198. <li><p><code class="docutils literal notranslate"><span class="pre">Py_SymtableStringObject()</span></code></p></li>
  2199. </ul>
  2200. <p>The <code class="docutils literal notranslate"><span class="pre">Py_SymtableString()</span></code> function was part the stable ABI by mistake but
  2201. it could not be used, because the <code class="docutils literal notranslate"><span class="pre">symtable.h</span></code> header file was excluded
  2202. from the limited C API.</p>
  2203. <p>Use Python <a class="reference internal" href="../library/symtable.html#module-symtable" title="symtable: Interface to the compiler's internal symbol tables."><code class="xref py py-mod docutils literal notranslate"><span class="pre">symtable</span></code></a> module instead.
  2204. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43244">bpo-43244</a>.)</p>
  2205. </li>
  2206. <li><p>Remove <a class="reference internal" href="../c-api/veryhigh.html#c.PyOS_ReadlineFunctionPointer" title="PyOS_ReadlineFunctionPointer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_ReadlineFunctionPointer()</span></code></a> from the limited C API headers
  2207. and from <code class="docutils literal notranslate"><span class="pre">python3.dll</span></code>, the library that provides the stable ABI on
  2208. Windows. Since the function takes a <code class="docutils literal notranslate"><span class="pre">FILE*</span></code> argument, its ABI stability
  2209. cannot be guaranteed.
  2210. (Contributed by Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43868">bpo-43868</a>.)</p></li>
  2211. <li><p>Remove <code class="docutils literal notranslate"><span class="pre">ast.h</span></code>, <code class="docutils literal notranslate"><span class="pre">asdl.h</span></code>, and <code class="docutils literal notranslate"><span class="pre">Python-ast.h</span></code> header files.
  2212. These functions were undocumented and excluded from the limited C API.
  2213. Most names defined by these header files were not prefixed by <code class="docutils literal notranslate"><span class="pre">Py</span></code> and so
  2214. could create names conflicts. For example, <code class="docutils literal notranslate"><span class="pre">Python-ast.h</span></code> defined a
  2215. <code class="docutils literal notranslate"><span class="pre">Yield</span></code> macro which was conflict with the <code class="docutils literal notranslate"><span class="pre">Yield</span></code> name used by the
  2216. Windows <code class="docutils literal notranslate"><span class="pre">&lt;winbase.h&gt;</span></code> header. Use the Python <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 instead.
  2217. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43244">bpo-43244</a>.)</p></li>
  2218. <li><p>Remove the compiler and parser functions using <code class="docutils literal notranslate"><span class="pre">struct</span> <span class="pre">_mod</span></code> type, because
  2219. the public AST C API was removed:</p>
  2220. <ul class="simple">
  2221. <li><p><code class="docutils literal notranslate"><span class="pre">PyAST_Compile()</span></code></p></li>
  2222. <li><p><code class="docutils literal notranslate"><span class="pre">PyAST_CompileEx()</span></code></p></li>
  2223. <li><p><code class="docutils literal notranslate"><span class="pre">PyAST_CompileObject()</span></code></p></li>
  2224. <li><p><code class="docutils literal notranslate"><span class="pre">PyFuture_FromAST()</span></code></p></li>
  2225. <li><p><code class="docutils literal notranslate"><span class="pre">PyFuture_FromASTObject()</span></code></p></li>
  2226. <li><p><code class="docutils literal notranslate"><span class="pre">PyParser_ASTFromFile()</span></code></p></li>
  2227. <li><p><code class="docutils literal notranslate"><span class="pre">PyParser_ASTFromFileObject()</span></code></p></li>
  2228. <li><p><code class="docutils literal notranslate"><span class="pre">PyParser_ASTFromFilename()</span></code></p></li>
  2229. <li><p><code class="docutils literal notranslate"><span class="pre">PyParser_ASTFromString()</span></code></p></li>
  2230. <li><p><code class="docutils literal notranslate"><span class="pre">PyParser_ASTFromStringObject()</span></code></p></li>
  2231. </ul>
  2232. <p>These functions were undocumented and excluded from the limited C API.
  2233. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43244">bpo-43244</a>.)</p>
  2234. </li>
  2235. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">pyarena.h</span></code> header file with functions:</p>
  2236. <ul class="simple">
  2237. <li><p><code class="docutils literal notranslate"><span class="pre">PyArena_New()</span></code></p></li>
  2238. <li><p><code class="docutils literal notranslate"><span class="pre">PyArena_Free()</span></code></p></li>
  2239. <li><p><code class="docutils literal notranslate"><span class="pre">PyArena_Malloc()</span></code></p></li>
  2240. <li><p><code class="docutils literal notranslate"><span class="pre">PyArena_AddPyObject()</span></code></p></li>
  2241. </ul>
  2242. <p>These functions were undocumented, excluded from the limited C API, and were
  2243. only used internally by the compiler.
  2244. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43244">bpo-43244</a>.)</p>
  2245. </li>
  2246. <li><p>The <code class="docutils literal notranslate"><span class="pre">PyThreadState.use_tracing</span></code> member has been removed to optimize Python.
  2247. (Contributed by Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43760">bpo-43760</a>.)</p></li>
  2248. </ul>
  2249. </section>
  2250. </section>
  2251. <section id="notable-security-feature-in-3-10-7">
  2252. <h2>Notable security feature in 3.10.7<a class="headerlink" href="#notable-security-feature-in-3-10-7" title="Link to this heading">¶</a></h2>
  2253. <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
  2254. (binary), 4, 8 (octal), 16 (hexadecimal), or 32 such as base 10 (decimal)
  2255. 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
  2256. above a limit to avoid potential denial of service attacks due to the
  2257. 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>.
  2258. This limit can be configured or disabled by environment variable, command
  2259. 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
  2260. length limitation</span></a> documentation. The default limit
  2261. is 4300 digits in string form.</p>
  2262. </section>
  2263. <section id="notable-security-feature-in-3-10-8">
  2264. <h2>Notable security feature in 3.10.8<a class="headerlink" href="#notable-security-feature-in-3-10-8" title="Link to this heading">¶</a></h2>
  2265. <p>The deprecated <code class="xref py py-mod docutils literal notranslate"><span class="pre">mailcap</span></code> module now refuses to inject unsafe text
  2266. (filenames, MIME types, parameters) into shell commands. Instead of using such
  2267. text, it will warn and act as if a match was not found (or for test commands,
  2268. as if the test failed).
  2269. (Contributed by Petr Viktorin in <a class="reference external" href="https://github.com/python/cpython/issues/98966">gh-98966</a>.)</p>
  2270. </section>
  2271. <section id="notable-changes-in-3-10-12">
  2272. <h2>Notable changes in 3.10.12<a class="headerlink" href="#notable-changes-in-3-10-12" title="Link to this heading">¶</a></h2>
  2273. <section id="tarfile">
  2274. <h3>tarfile<a class="headerlink" href="#tarfile" title="Link to this heading">¶</a></h3>
  2275. <ul class="simple">
  2276. <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>,
  2277. have a new a <em>filter</em> argument that allows limiting tar features than may be
  2278. surprising or dangerous, such as creating files outside the destination
  2279. directory.
  2280. See <a class="reference internal" href="../library/tarfile.html#tarfile-extraction-filter"><span class="std std-ref">Extraction filters</span></a> for details.
  2281. In Python 3.12, use without the <em>filter</em> argument will show a
  2282. <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>.
  2283. In Python 3.14, the default will switch to <code class="docutils literal notranslate"><span class="pre">'data'</span></code>.
  2284. (Contributed by Petr Viktorin in <span class="target" id="index-40"></span><a class="pep reference external" href="https://peps.python.org/pep-0706/"><strong>PEP 706</strong></a>.)</p></li>
  2285. </ul>
  2286. </section>
  2287. </section>
  2288. </section>
  2289. <div class="clearer"></div>
  2290. </div>
  2291. </div>
  2292. </div>
  2293. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  2294. <div class="sphinxsidebarwrapper">
  2295. <div>
  2296. <h3><a href="../contents.html">Table of Contents</a></h3>
  2297. <ul>
  2298. <li><a class="reference internal" href="#">What’s New In Python 3.10</a><ul>
  2299. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  2300. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  2301. <li><a class="reference internal" href="#parenthesized-context-managers">Parenthesized context managers</a></li>
  2302. <li><a class="reference internal" href="#better-error-messages">Better error messages</a><ul>
  2303. <li><a class="reference internal" href="#syntaxerrors">SyntaxErrors</a></li>
  2304. <li><a class="reference internal" href="#indentationerrors">IndentationErrors</a></li>
  2305. <li><a class="reference internal" href="#attributeerrors">AttributeErrors</a></li>
  2306. <li><a class="reference internal" href="#nameerrors">NameErrors</a></li>
  2307. </ul>
  2308. </li>
  2309. <li><a class="reference internal" href="#pep-626-precise-line-numbers-for-debugging-and-other-tools">PEP 626: Precise line numbers for debugging and other tools</a></li>
  2310. <li><a class="reference internal" href="#pep-634-structural-pattern-matching">PEP 634: Structural Pattern Matching</a><ul>
  2311. <li><a class="reference internal" href="#syntax-and-operations">Syntax and operations</a></li>
  2312. <li><a class="reference internal" href="#declarative-approach">Declarative approach</a></li>
  2313. <li><a class="reference internal" href="#simple-pattern-match-to-a-literal">Simple pattern: match to a literal</a><ul>
  2314. <li><a class="reference internal" href="#behavior-without-the-wildcard">Behavior without the wildcard</a></li>
  2315. </ul>
  2316. </li>
  2317. <li><a class="reference internal" href="#patterns-with-a-literal-and-variable">Patterns with a literal and variable</a></li>
  2318. <li><a class="reference internal" href="#patterns-and-classes">Patterns and classes</a><ul>
  2319. <li><a class="reference internal" href="#patterns-with-positional-parameters">Patterns with positional parameters</a></li>
  2320. </ul>
  2321. </li>
  2322. <li><a class="reference internal" href="#nested-patterns">Nested patterns</a></li>
  2323. <li><a class="reference internal" href="#complex-patterns-and-the-wildcard">Complex patterns and the wildcard</a></li>
  2324. <li><a class="reference internal" href="#guard">Guard</a></li>
  2325. <li><a class="reference internal" href="#other-key-features">Other Key Features</a></li>
  2326. </ul>
  2327. </li>
  2328. <li><a class="reference internal" href="#optional-encodingwarning-and-encoding-locale-option">Optional <code class="docutils literal notranslate"><span class="pre">EncodingWarning</span></code> and <code class="docutils literal notranslate"><span class="pre">encoding=&quot;locale&quot;</span></code> option</a></li>
  2329. </ul>
  2330. </li>
  2331. <li><a class="reference internal" href="#new-features-related-to-type-hints">New Features Related to Type Hints</a><ul>
  2332. <li><a class="reference internal" href="#pep-604-new-type-union-operator">PEP 604: New Type Union Operator</a></li>
  2333. <li><a class="reference internal" href="#pep-612-parameter-specification-variables">PEP 612: Parameter Specification Variables</a></li>
  2334. <li><a class="reference internal" href="#pep-613-typealias">PEP 613: TypeAlias</a></li>
  2335. <li><a class="reference internal" href="#pep-647-user-defined-type-guards">PEP 647: User-Defined Type Guards</a></li>
  2336. </ul>
  2337. </li>
  2338. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  2339. <li><a class="reference internal" href="#new-modules">New Modules</a></li>
  2340. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  2341. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  2342. <li><a class="reference internal" href="#argparse">argparse</a></li>
  2343. <li><a class="reference internal" href="#array">array</a></li>
  2344. <li><a class="reference internal" href="#asynchat-asyncore-smtpd">asynchat, asyncore, smtpd</a></li>
  2345. <li><a class="reference internal" href="#base64">base64</a></li>
  2346. <li><a class="reference internal" href="#bdb">bdb</a></li>
  2347. <li><a class="reference internal" href="#bisect">bisect</a></li>
  2348. <li><a class="reference internal" href="#codecs">codecs</a></li>
  2349. <li><a class="reference internal" href="#collections-abc">collections.abc</a></li>
  2350. <li><a class="reference internal" href="#contextlib">contextlib</a></li>
  2351. <li><a class="reference internal" href="#curses">curses</a></li>
  2352. <li><a class="reference internal" href="#dataclasses">dataclasses</a><ul>
  2353. <li><a class="reference internal" href="#slots">__slots__</a></li>
  2354. <li><a class="reference internal" href="#keyword-only-fields">Keyword-only fields</a></li>
  2355. </ul>
  2356. </li>
  2357. <li><a class="reference internal" href="#distutils">distutils</a></li>
  2358. <li><a class="reference internal" href="#doctest">doctest</a></li>
  2359. <li><a class="reference internal" href="#encodings">encodings</a></li>
  2360. <li><a class="reference internal" href="#enum">enum</a></li>
  2361. <li><a class="reference internal" href="#fileinput">fileinput</a></li>
  2362. <li><a class="reference internal" href="#faulthandler">faulthandler</a></li>
  2363. <li><a class="reference internal" href="#gc">gc</a></li>
  2364. <li><a class="reference internal" href="#glob">glob</a></li>
  2365. <li><a class="reference internal" href="#hashlib">hashlib</a></li>
  2366. <li><a class="reference internal" href="#hmac">hmac</a></li>
  2367. <li><a class="reference internal" href="#idle-and-idlelib">IDLE and idlelib</a></li>
  2368. <li><a class="reference internal" href="#importlib-metadata">importlib.metadata</a></li>
  2369. <li><a class="reference internal" href="#inspect">inspect</a></li>
  2370. <li><a class="reference internal" href="#itertools">itertools</a></li>
  2371. <li><a class="reference internal" href="#linecache">linecache</a></li>
  2372. <li><a class="reference internal" href="#os">os</a></li>
  2373. <li><a class="reference internal" href="#os-path">os.path</a></li>
  2374. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  2375. <li><a class="reference internal" href="#platform">platform</a></li>
  2376. <li><a class="reference internal" href="#pprint">pprint</a></li>
  2377. <li><a class="reference internal" href="#py-compile">py_compile</a></li>
  2378. <li><a class="reference internal" href="#pyclbr">pyclbr</a></li>
  2379. <li><a class="reference internal" href="#shelve">shelve</a></li>
  2380. <li><a class="reference internal" href="#statistics">statistics</a></li>
  2381. <li><a class="reference internal" href="#site">site</a></li>
  2382. <li><a class="reference internal" href="#socket">socket</a></li>
  2383. <li><a class="reference internal" href="#ssl">ssl</a></li>
  2384. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  2385. <li><a class="reference internal" href="#sys">sys</a></li>
  2386. <li><a class="reference internal" href="#thread">_thread</a></li>
  2387. <li><a class="reference internal" href="#threading">threading</a></li>
  2388. <li><a class="reference internal" href="#traceback">traceback</a></li>
  2389. <li><a class="reference internal" href="#types">types</a></li>
  2390. <li><a class="reference internal" href="#typing">typing</a></li>
  2391. <li><a class="reference internal" href="#unittest">unittest</a></li>
  2392. <li><a class="reference internal" href="#urllib-parse">urllib.parse</a></li>
  2393. <li><a class="reference internal" href="#xml">xml</a></li>
  2394. <li><a class="reference internal" href="#zipimport">zipimport</a></li>
  2395. </ul>
  2396. </li>
  2397. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  2398. <li><a class="reference internal" href="#deprecated">Deprecated</a></li>
  2399. <li><a class="reference internal" href="#removed">Removed</a></li>
  2400. <li><a class="reference internal" href="#porting-to-python-3-10">Porting to Python 3.10</a><ul>
  2401. <li><a class="reference internal" href="#changes-in-the-python-syntax">Changes in the Python syntax</a></li>
  2402. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  2403. <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
  2404. </ul>
  2405. </li>
  2406. <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
  2407. <li><a class="reference internal" href="#build-changes">Build Changes</a></li>
  2408. <li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
  2409. <li><a class="reference internal" href="#pep-652-maintaining-the-stable-abi">PEP 652: Maintaining the Stable ABI</a></li>
  2410. <li><a class="reference internal" href="#id1">New Features</a></li>
  2411. <li><a class="reference internal" href="#id2">Porting to Python 3.10</a></li>
  2412. <li><a class="reference internal" href="#id3">Deprecated</a></li>
  2413. <li><a class="reference internal" href="#id4">Removed</a></li>
  2414. </ul>
  2415. </li>
  2416. <li><a class="reference internal" href="#notable-security-feature-in-3-10-7">Notable security feature in 3.10.7</a></li>
  2417. <li><a class="reference internal" href="#notable-security-feature-in-3-10-8">Notable security feature in 3.10.8</a></li>
  2418. <li><a class="reference internal" href="#notable-changes-in-3-10-12">Notable changes in 3.10.12</a><ul>
  2419. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  2420. </ul>
  2421. </li>
  2422. </ul>
  2423. </li>
  2424. </ul>
  2425. </div>
  2426. <div>
  2427. <h4>Previous topic</h4>
  2428. <p class="topless"><a href="3.11.html"
  2429. title="previous chapter">What’s New In Python 3.11</a></p>
  2430. </div>
  2431. <div>
  2432. <h4>Next topic</h4>
  2433. <p class="topless"><a href="3.9.html"
  2434. title="next chapter">What’s New In Python 3.9</a></p>
  2435. </div>
  2436. <div role="note" aria-label="source link">
  2437. <h3>This Page</h3>
  2438. <ul class="this-page-menu">
  2439. <li><a href="../bugs.html">Report a Bug</a></li>
  2440. <li>
  2441. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.10.rst"
  2442. rel="nofollow">Show Source
  2443. </a>
  2444. </li>
  2445. </ul>
  2446. </div>
  2447. </div>
  2448. <div id="sidebarbutton" title="Collapse sidebar">
  2449. <span>«</span>
  2450. </div>
  2451. </div>
  2452. <div class="clearer"></div>
  2453. </div>
  2454. <div class="related" role="navigation" aria-label="related navigation">
  2455. <h3>Navigation</h3>
  2456. <ul>
  2457. <li class="right" style="margin-right: 10px">
  2458. <a href="../genindex.html" title="General Index"
  2459. >index</a></li>
  2460. <li class="right" >
  2461. <a href="../py-modindex.html" title="Python Module Index"
  2462. >modules</a> |</li>
  2463. <li class="right" >
  2464. <a href="3.9.html" title="What’s New In Python 3.9"
  2465. >next</a> |</li>
  2466. <li class="right" >
  2467. <a href="3.11.html" title="What’s New In Python 3.11"
  2468. >previous</a> |</li>
  2469. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  2470. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  2471. <li class="switchers">
  2472. <div class="language_switcher_placeholder"></div>
  2473. <div class="version_switcher_placeholder"></div>
  2474. </li>
  2475. <li>
  2476. </li>
  2477. <li id="cpython-language-and-version">
  2478. <a href="../index.html">3.12.3 Documentation</a> &#187;
  2479. </li>
  2480. <li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> &#187;</li>
  2481. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.10</a></li>
  2482. <li class="right">
  2483. <div class="inline-search" role="search">
  2484. <form class="inline-search" action="../search.html" method="get">
  2485. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  2486. <input type="submit" value="Go" />
  2487. </form>
  2488. </div>
  2489. |
  2490. </li>
  2491. <li class="right">
  2492. <label class="theme-selector-label">
  2493. Theme
  2494. <select class="theme-selector" oninput="activateTheme(this.value)">
  2495. <option value="auto" selected>Auto</option>
  2496. <option value="light">Light</option>
  2497. <option value="dark">Dark</option>
  2498. </select>
  2499. </label> |</li>
  2500. </ul>
  2501. </div>
  2502. <div class="footer">
  2503. &copy;
  2504. <a href="../copyright.html">
  2505. Copyright
  2506. </a>
  2507. 2001-2024, Python Software Foundation.
  2508. <br />
  2509. This page is licensed under the Python Software Foundation License Version 2.
  2510. <br />
  2511. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  2512. <br />
  2513. See <a href="/license.html">History and License</a> for more information.<br />
  2514. <br />
  2515. The Python Software Foundation is a non-profit corporation.
  2516. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  2517. <br />
  2518. <br />
  2519. Last updated on Apr 09, 2024 (13:47 UTC).
  2520. <a href="/bugs.html">Found a bug</a>?
  2521. <br />
  2522. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  2523. </div>
  2524. </body>
  2525. </html>
上海开阖软件有限公司 沪ICP备12045867号-1