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

2864 lines
363KB

  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.12" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/whatsnew/3.12.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Editor, Adam Turner,. This article explains the new features in Python 3.12, compared to 3.11. Python 3.12 was released on October 2, 2023. For full details, see the changelog. Summary – Release hi..." />
  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, Adam Turner,. This article explains the new features in Python 3.12, compared to 3.11. Python 3.12 was released on October 2, 2023. For full details, see the changelog. Summary – Release hi..." />
  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.12 &#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.11" href="3.11.html" />
  33. <link rel="prev" title="What’s New in Python" href="index.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/whatsnew/3.12.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.12</a><ul>
  86. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  87. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  88. <li><a class="reference internal" href="#pep-695-type-parameter-syntax">PEP 695: Type Parameter Syntax</a></li>
  89. <li><a class="reference internal" href="#pep-701-syntactic-formalization-of-f-strings">PEP 701: Syntactic formalization of f-strings</a></li>
  90. <li><a class="reference internal" href="#pep-684-a-per-interpreter-gil">PEP 684: A Per-Interpreter GIL</a></li>
  91. <li><a class="reference internal" href="#pep-669-low-impact-monitoring-for-cpython">PEP 669: Low impact monitoring for CPython</a></li>
  92. <li><a class="reference internal" href="#pep-688-making-the-buffer-protocol-accessible-in-python">PEP 688: Making the buffer protocol accessible in Python</a></li>
  93. <li><a class="reference internal" href="#pep-709-comprehension-inlining">PEP 709: Comprehension inlining</a></li>
  94. <li><a class="reference internal" href="#improved-error-messages">Improved Error Messages</a></li>
  95. </ul>
  96. </li>
  97. <li><a class="reference internal" href="#new-features-related-to-type-hints">New Features Related to Type Hints</a><ul>
  98. <li><a class="reference internal" href="#pep-692-using-typeddict-for-more-precise-kwargs-typing">PEP 692: Using <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> for more precise <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> typing</a></li>
  99. <li><a class="reference internal" href="#pep-698-override-decorator-for-static-typing">PEP 698: Override Decorator for Static Typing</a></li>
  100. </ul>
  101. </li>
  102. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  103. <li><a class="reference internal" href="#new-modules">New Modules</a></li>
  104. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  105. <li><a class="reference internal" href="#array">array</a></li>
  106. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  107. <li><a class="reference internal" href="#calendar">calendar</a></li>
  108. <li><a class="reference internal" href="#csv">csv</a></li>
  109. <li><a class="reference internal" href="#dis">dis</a></li>
  110. <li><a class="reference internal" href="#fractions">fractions</a></li>
  111. <li><a class="reference internal" href="#importlib-resources">importlib.resources</a></li>
  112. <li><a class="reference internal" href="#inspect">inspect</a></li>
  113. <li><a class="reference internal" href="#itertools">itertools</a></li>
  114. <li><a class="reference internal" href="#math">math</a></li>
  115. <li><a class="reference internal" href="#os">os</a></li>
  116. <li><a class="reference internal" href="#os-path">os.path</a></li>
  117. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  118. <li><a class="reference internal" href="#pdb">pdb</a></li>
  119. <li><a class="reference internal" href="#random">random</a></li>
  120. <li><a class="reference internal" href="#shutil">shutil</a></li>
  121. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  122. <li><a class="reference internal" href="#statistics">statistics</a></li>
  123. <li><a class="reference internal" href="#sys">sys</a></li>
  124. <li><a class="reference internal" href="#tempfile">tempfile</a></li>
  125. <li><a class="reference internal" href="#threading">threading</a></li>
  126. <li><a class="reference internal" href="#tkinter">tkinter</a></li>
  127. <li><a class="reference internal" href="#tokenize">tokenize</a></li>
  128. <li><a class="reference internal" href="#types">types</a></li>
  129. <li><a class="reference internal" href="#typing">typing</a></li>
  130. <li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
  131. <li><a class="reference internal" href="#unittest">unittest</a></li>
  132. <li><a class="reference internal" href="#uuid">uuid</a></li>
  133. </ul>
  134. </li>
  135. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  136. <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
  137. <li><a class="reference internal" href="#demos-and-tools">Demos and Tools</a></li>
  138. <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
  139. <li><a class="reference internal" href="#pending-removal-in-python-3-13">Pending Removal in Python 3.13</a></li>
  140. <li><a class="reference internal" href="#pending-removal-in-python-3-14">Pending Removal in Python 3.14</a></li>
  141. <li><a class="reference internal" href="#pending-removal-in-python-3-15">Pending Removal in Python 3.15</a></li>
  142. <li><a class="reference internal" href="#pending-removal-in-future-versions">Pending Removal in Future Versions</a></li>
  143. </ul>
  144. </li>
  145. <li><a class="reference internal" href="#removed">Removed</a><ul>
  146. <li><a class="reference internal" href="#asynchat-and-asyncore">asynchat and asyncore</a></li>
  147. <li><a class="reference internal" href="#configparser">configparser</a></li>
  148. <li><a class="reference internal" href="#distutils">distutils</a></li>
  149. <li><a class="reference internal" href="#ensurepip">ensurepip</a></li>
  150. <li><a class="reference internal" href="#enum">enum</a></li>
  151. <li><a class="reference internal" href="#ftplib">ftplib</a></li>
  152. <li><a class="reference internal" href="#gzip">gzip</a></li>
  153. <li><a class="reference internal" href="#hashlib">hashlib</a></li>
  154. <li><a class="reference internal" href="#importlib">importlib</a></li>
  155. <li><a class="reference internal" href="#imp">imp</a></li>
  156. <li><a class="reference internal" href="#io">io</a></li>
  157. <li><a class="reference internal" href="#locale">locale</a></li>
  158. <li><a class="reference internal" href="#smtpd">smtpd</a></li>
  159. <li><a class="reference internal" href="#id2">sqlite3</a></li>
  160. <li><a class="reference internal" href="#ssl">ssl</a></li>
  161. <li><a class="reference internal" href="#id3">unittest</a></li>
  162. <li><a class="reference internal" href="#webbrowser">webbrowser</a></li>
  163. <li><a class="reference internal" href="#xml-etree-elementtree">xml.etree.ElementTree</a></li>
  164. <li><a class="reference internal" href="#zipimport">zipimport</a></li>
  165. <li><a class="reference internal" href="#others">Others</a></li>
  166. </ul>
  167. </li>
  168. <li><a class="reference internal" href="#porting-to-python-3-12">Porting to Python 3.12</a><ul>
  169. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  170. </ul>
  171. </li>
  172. <li><a class="reference internal" href="#build-changes">Build Changes</a></li>
  173. <li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
  174. <li><a class="reference internal" href="#id4">New Features</a></li>
  175. <li><a class="reference internal" href="#id5">Porting to Python 3.12</a></li>
  176. <li><a class="reference internal" href="#id6">Deprecated</a><ul>
  177. <li><a class="reference internal" href="#id7">Pending Removal in Python 3.14</a></li>
  178. <li><a class="reference internal" href="#id8">Pending Removal in Python 3.15</a></li>
  179. <li><a class="reference internal" href="#id9">Pending Removal in Future Versions</a></li>
  180. </ul>
  181. </li>
  182. <li><a class="reference internal" href="#id10">Removed</a></li>
  183. </ul>
  184. </li>
  185. </ul>
  186. </li>
  187. </ul>
  188. </div>
  189. <div>
  190. <h4>Previous topic</h4>
  191. <p class="topless"><a href="index.html"
  192. title="previous chapter">What’s New in Python</a></p>
  193. </div>
  194. <div>
  195. <h4>Next topic</h4>
  196. <p class="topless"><a href="3.11.html"
  197. title="next chapter">What’s New In Python 3.11</a></p>
  198. </div>
  199. <div role="note" aria-label="source link">
  200. <h3>This Page</h3>
  201. <ul class="this-page-menu">
  202. <li><a href="../bugs.html">Report a Bug</a></li>
  203. <li>
  204. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.12.rst"
  205. rel="nofollow">Show Source
  206. </a>
  207. </li>
  208. </ul>
  209. </div>
  210. </nav>
  211. </div>
  212. </div>
  213. <div class="related" role="navigation" aria-label="related navigation">
  214. <h3>Navigation</h3>
  215. <ul>
  216. <li class="right" style="margin-right: 10px">
  217. <a href="../genindex.html" title="General Index"
  218. accesskey="I">index</a></li>
  219. <li class="right" >
  220. <a href="../py-modindex.html" title="Python Module Index"
  221. >modules</a> |</li>
  222. <li class="right" >
  223. <a href="3.11.html" title="What’s New In Python 3.11"
  224. accesskey="N">next</a> |</li>
  225. <li class="right" >
  226. <a href="index.html" title="What’s New in Python"
  227. accesskey="P">previous</a> |</li>
  228. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  229. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  230. <li class="switchers">
  231. <div class="language_switcher_placeholder"></div>
  232. <div class="version_switcher_placeholder"></div>
  233. </li>
  234. <li>
  235. </li>
  236. <li id="cpython-language-and-version">
  237. <a href="../index.html">3.12.3 Documentation</a> &#187;
  238. </li>
  239. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> &#187;</li>
  240. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.12</a></li>
  241. <li class="right">
  242. <div class="inline-search" role="search">
  243. <form class="inline-search" action="../search.html" method="get">
  244. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  245. <input type="submit" value="Go" />
  246. </form>
  247. </div>
  248. |
  249. </li>
  250. <li class="right">
  251. <label class="theme-selector-label">
  252. Theme
  253. <select class="theme-selector" oninput="activateTheme(this.value)">
  254. <option value="auto" selected>Auto</option>
  255. <option value="light">Light</option>
  256. <option value="dark">Dark</option>
  257. </select>
  258. </label> |</li>
  259. </ul>
  260. </div>
  261. <div class="document">
  262. <div class="documentwrapper">
  263. <div class="bodywrapper">
  264. <div class="body" role="main">
  265. <section id="what-s-new-in-python-3-12">
  266. <h1>What’s New In Python 3.12<a class="headerlink" href="#what-s-new-in-python-3-12" title="Link to this heading">¶</a></h1>
  267. <dl class="field-list simple">
  268. <dt class="field-odd">Editor<span class="colon">:</span></dt>
  269. <dd class="field-odd"><p>Adam Turner</p>
  270. </dd>
  271. </dl>
  272. <p>This article explains the new features in Python 3.12, compared to 3.11.
  273. Python 3.12 was released on October 2, 2023.
  274. For full details, see the <a class="reference internal" href="changelog.html#changelog"><span class="std std-ref">changelog</span></a>.</p>
  275. <div class="admonition seealso">
  276. <p class="admonition-title">See also</p>
  277. <p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0693/"><strong>PEP 693</strong></a> – Python 3.12 Release Schedule</p>
  278. </div>
  279. <section id="summary-release-highlights">
  280. <h2>Summary – Release highlights<a class="headerlink" href="#summary-release-highlights" title="Link to this heading">¶</a></h2>
  281. <p>Python 3.12 is the latest stable release of the Python programming language,
  282. with a mix of changes to the language and the standard library.
  283. The library changes focus on cleaning up deprecated APIs, usability, and correctness.
  284. Of note, the <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code> package has been removed from the standard library.
  285. Filesystem support in <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> and <a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> has seen a number of improvements,
  286. and several modules have better performance.</p>
  287. <p>The language changes focus on usability,
  288. as <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-strings</span></a> have had many limitations removed
  289. and ‘Did you mean …’ suggestions continue to improve.
  290. The new <a class="reference internal" href="#whatsnew312-pep695"><span class="std std-ref">type parameter syntax</span></a>
  291. and <a class="reference internal" href="../reference/simple_stmts.html#type"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">type</span></code></a> statement improve ergonomics for using <a class="reference internal" href="../glossary.html#term-generic-type"><span class="xref std std-term">generic types</span></a> and <a class="reference internal" href="../glossary.html#term-type-alias"><span class="xref std std-term">type aliases</span></a> with static type checkers.</p>
  292. <p>This article doesn’t attempt to provide a complete specification of all new features,
  293. but instead gives a convenient overview.
  294. For full details, you should refer to the documentation,
  295. such as the <a class="reference internal" href="../library/index.html#library-index"><span class="std std-ref">Library Reference</span></a>
  296. and <a class="reference internal" href="../reference/index.html#reference-index"><span class="std std-ref">Language Reference</span></a>.
  297. If you want to understand the complete implementation and design rationale for a change,
  298. refer to the PEP for a particular new feature;
  299. but note that PEPs usually are not kept up-to-date
  300. once a feature has been fully implemented.</p>
  301. <hr class="docutils" />
  302. <p>New syntax features:</p>
  303. <ul class="simple">
  304. <li><p><a class="reference internal" href="#whatsnew312-pep695"><span class="std std-ref">PEP 695</span></a>, type parameter syntax and the <a class="reference internal" href="../reference/simple_stmts.html#type"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">type</span></code></a> statement</p></li>
  305. </ul>
  306. <p>New grammar features:</p>
  307. <ul class="simple">
  308. <li><p><a class="reference internal" href="#whatsnew312-pep701"><span class="std std-ref">PEP 701</span></a>, <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-strings</span></a> in the grammar</p></li>
  309. </ul>
  310. <p>Interpreter improvements:</p>
  311. <ul class="simple">
  312. <li><p><a class="reference internal" href="#whatsnew312-pep684"><span class="std std-ref">PEP 684</span></a>, a unique per-interpreter <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">GIL</span></a></p></li>
  313. <li><p><a class="reference internal" href="#whatsnew312-pep669"><span class="std std-ref">PEP 669</span></a>, low impact monitoring</p></li>
  314. <li><p><a class="reference internal" href="#improved-error-messages">Improved ‘Did you mean …’ suggestions</a>
  315. for <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>, <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>, and <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</p></li>
  316. </ul>
  317. <p>Python data model improvements:</p>
  318. <ul class="simple">
  319. <li><p><a class="reference internal" href="#whatsnew312-pep688"><span class="std std-ref">PEP 688</span></a>, using the <a class="reference internal" href="../c-api/buffer.html#bufferobjects"><span class="std std-ref">buffer protocol</span></a> from Python</p></li>
  320. </ul>
  321. <p>Significant improvements in the standard library:</p>
  322. <ul class="simple">
  323. <li><p>The <a class="reference internal" href="../library/pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> class now supports subclassing</p></li>
  324. <li><p>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 received several improvements for Windows support</p></li>
  325. <li><p>A <a class="reference internal" href="../library/sqlite3.html#sqlite3-cli"><span class="std std-ref">command-line interface</span></a> has been added to the
  326. <a class="reference internal" href="../library/sqlite3.html#module-sqlite3" title="sqlite3: A DB-API 2.0 implementation using SQLite 3.x."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlite3</span></code></a> module</p></li>
  327. <li><p><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> checks against <a class="reference internal" href="../library/typing.html#typing.runtime_checkable" title="typing.runtime_checkable"><code class="xref py py-func docutils literal notranslate"><span class="pre">runtime-checkable</span> <span class="pre">protocols</span></code></a> enjoy a speed up of between two and 20 times</p></li>
  328. <li><p>The <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> package has had a number of performance improvements,
  329. with some benchmarks showing a 75% speed up.</p></li>
  330. <li><p>A <a class="reference internal" href="../library/uuid.html#uuid-cli"><span class="std std-ref">command-line interface</span></a> has been added to the
  331. <a class="reference internal" href="../library/uuid.html#module-uuid" title="uuid: UUID objects (universally unique identifiers) according to RFC 4122"><code class="xref py py-mod docutils literal notranslate"><span class="pre">uuid</span></code></a> module</p></li>
  332. <li><p>Due to the changes in <a class="reference internal" href="#whatsnew312-pep701"><span class="std std-ref">PEP 701</span></a>,
  333. producing tokens via the <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> module is up to 64% faster.</p></li>
  334. </ul>
  335. <p>Security improvements:</p>
  336. <ul class="simple">
  337. <li><p>Replace the builtin <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> implementations of
  338. SHA1, SHA3, SHA2-384, SHA2-512, and MD5 with formally verified code from the
  339. <a class="reference external" href="https://github.com/hacl-star/hacl-star/">HACL*</a> project.
  340. These builtin implementations remain as fallbacks that are only used when
  341. OpenSSL does not provide them.</p></li>
  342. </ul>
  343. <p>C API improvements:</p>
  344. <ul class="simple">
  345. <li><p><a class="reference internal" href="#whatsnew312-pep697"><span class="std std-ref">PEP 697</span></a>, unstable C API tier</p></li>
  346. <li><p><a class="reference internal" href="#whatsnew312-pep683"><span class="std std-ref">PEP 683</span></a>, immortal objects</p></li>
  347. </ul>
  348. <p>CPython implementation improvements:</p>
  349. <ul class="simple">
  350. <li><p><a class="reference internal" href="#whatsnew312-pep709"><span class="std std-ref">PEP 709</span></a>, comprehension inlining</p></li>
  351. <li><p><a class="reference internal" href="../howto/perf_profiling.html#perf-profiling"><span class="std std-ref">CPython support</span></a> for the Linux <code class="docutils literal notranslate"><span class="pre">perf</span></code> profiler</p></li>
  352. <li><p>Implement stack overflow protection on supported platforms</p></li>
  353. </ul>
  354. <p>New typing features:</p>
  355. <ul class="simple">
  356. <li><p><a class="reference internal" href="#whatsnew312-pep692"><span class="std std-ref">PEP 692</span></a>, using <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">TypedDict</span></code></a> to
  357. annotate <a class="reference internal" href="../glossary.html#term-argument"><span class="xref std std-term">**kwargs</span></a></p></li>
  358. <li><p><a class="reference internal" href="#whatsnew312-pep698"><span class="std std-ref">PEP 698</span></a>, <a class="reference internal" href="../library/typing.html#typing.override" title="typing.override"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.override()</span></code></a> decorator</p></li>
  359. </ul>
  360. <p>Important deprecations, removals or restrictions:</p>
  361. <ul class="simple">
  362. <li><p><span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0623/"><strong>PEP 623</strong></a>: Remove <code class="docutils literal notranslate"><span class="pre">wstr</span></code> from Unicode objects in Python’s C API,
  363. reducing the size of every <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> object by at least 8 bytes.</p></li>
  364. <li><p><span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0632/"><strong>PEP 632</strong></a>: Remove the <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code> package.
  365. See <a class="reference external" href="https://peps.python.org/pep-0632/#migration-advice">the migration guide</a>
  366. for advice replacing the APIs it provided.
  367. The third-party <a class="reference external" href="https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html">Setuptools</a>
  368. package continues to provide <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code>,
  369. if you still require it in Python 3.12 and beyond.</p></li>
  370. <li><p><a class="reference external" href="https://github.com/python/cpython/issues/95299">gh-95299</a>: Do not pre-install <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> in virtual environments
  371. created with <a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a>.
  372. This means that <code class="docutils literal notranslate"><span class="pre">distutils</span></code>, <code class="docutils literal notranslate"><span class="pre">setuptools</span></code>, <code class="docutils literal notranslate"><span class="pre">pkg_resources</span></code>,
  373. and <code class="docutils literal notranslate"><span class="pre">easy_install</span></code> will no longer available by default; to access these
  374. run <code class="docutils literal notranslate"><span class="pre">pip</span> <span class="pre">install</span> <span class="pre">setuptools</span></code> in the <a class="reference internal" href="../library/venv.html#venv-explanation"><span class="std std-ref">activated</span></a>
  375. virtual environment.</p></li>
  376. <li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">asynchat</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncore</span></code>, and <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> modules have been
  377. removed, along with several <a class="reference internal" href="../library/unittest.html#unittest.TestCase" title="unittest.TestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">unittest.TestCase</span></code></a>
  378. <a class="reference internal" href="#unittest-testcase-removed-aliases">method aliases</a>.</p></li>
  379. </ul>
  380. </section>
  381. <section id="new-features">
  382. <h2>New Features<a class="headerlink" href="#new-features" title="Link to this heading">¶</a></h2>
  383. <section id="pep-695-type-parameter-syntax">
  384. <span id="whatsnew312-pep695"></span><h3>PEP 695: Type Parameter Syntax<a class="headerlink" href="#pep-695-type-parameter-syntax" title="Link to this heading">¶</a></h3>
  385. <p>Generic classes and functions under <span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> were declared using a verbose syntax
  386. that left the scope of type parameters unclear and required explicit declarations of
  387. variance.</p>
  388. <p><span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0695/"><strong>PEP 695</strong></a> introduces a new, more compact and explicit way to create
  389. <a class="reference internal" href="../reference/compound_stmts.html#generic-classes"><span class="std std-ref">generic classes</span></a> and <a class="reference internal" href="../reference/compound_stmts.html#generic-functions"><span class="std std-ref">functions</span></a>:</p>
  390. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">max</span><span class="p">[</span><span class="n">T</span><span class="p">](</span><span class="n">args</span><span class="p">:</span> <span class="n">Iterable</span><span class="p">[</span><span class="n">T</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">T</span><span class="p">:</span>
  391. <span class="o">...</span>
  392. <span class="k">class</span> <span class="nc">list</span><span class="p">[</span><span class="n">T</span><span class="p">]:</span>
  393. <span class="k">def</span> <span class="fm">__getitem__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">index</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="o">/</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">T</span><span class="p">:</span>
  394. <span class="o">...</span>
  395. <span class="k">def</span> <span class="nf">append</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">element</span><span class="p">:</span> <span class="n">T</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
  396. <span class="o">...</span>
  397. </pre></div>
  398. </div>
  399. <p>In addition, the PEP introduces a new way to declare <a class="reference internal" href="../library/typing.html#type-aliases"><span class="std std-ref">type aliases</span></a>
  400. using the <a class="reference internal" href="../reference/simple_stmts.html#type"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">type</span></code></a> statement, which creates an instance of
  401. <a class="reference internal" href="../library/typing.html#typing.TypeAliasType" title="typing.TypeAliasType"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeAliasType</span></code></a>:</p>
  402. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">type</span> <span class="n">Point</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">[</span><span class="nb">float</span><span class="p">,</span> <span class="nb">float</span><span class="p">]</span>
  403. </pre></div>
  404. </div>
  405. <p>Type aliases can also be <a class="reference internal" href="../reference/compound_stmts.html#generic-type-aliases"><span class="std std-ref">generic</span></a>:</p>
  406. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">type</span> <span class="n">Point</span><span class="p">[</span><span class="n">T</span><span class="p">]</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">[</span><span class="n">T</span><span class="p">,</span> <span class="n">T</span><span class="p">]</span>
  407. </pre></div>
  408. </div>
  409. <p>The new syntax allows declaring <a class="reference internal" href="../library/typing.html#typing.TypeVarTuple" title="typing.TypeVarTuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeVarTuple</span></code></a>
  410. and <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">ParamSpec</span></code></a> parameters, as well as <a class="reference internal" href="../library/typing.html#typing.TypeVar" title="typing.TypeVar"><code class="xref py py-class docutils literal notranslate"><span class="pre">TypeVar</span></code></a>
  411. parameters with bounds or constraints:</p>
  412. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="nb">type</span> <span class="n">IntFunc</span><span class="p">[</span><span class="o">**</span><span class="n">P</span><span class="p">]</span> <span class="o">=</span> <span class="n">Callable</span><span class="p">[</span><span class="n">P</span><span class="p">,</span> <span class="nb">int</span><span class="p">]</span> <span class="c1"># ParamSpec</span>
  413. <span class="nb">type</span> <span class="n">LabeledTuple</span><span class="p">[</span><span class="o">*</span><span class="n">Ts</span><span class="p">]</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">Ts</span><span class="p">]</span> <span class="c1"># TypeVarTuple</span>
  414. <span class="nb">type</span> <span class="n">HashableSequence</span><span class="p">[</span><span class="n">T</span><span class="p">:</span> <span class="n">Hashable</span><span class="p">]</span> <span class="o">=</span> <span class="n">Sequence</span><span class="p">[</span><span class="n">T</span><span class="p">]</span> <span class="c1"># TypeVar with bound</span>
  415. <span class="nb">type</span> <span class="n">IntOrStrSequence</span><span class="p">[</span><span class="n">T</span><span class="p">:</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="nb">str</span><span class="p">)]</span> <span class="o">=</span> <span class="n">Sequence</span><span class="p">[</span><span class="n">T</span><span class="p">]</span> <span class="c1"># TypeVar with constraints</span>
  416. </pre></div>
  417. </div>
  418. <p>The value of type aliases and the bound and constraints of type variables
  419. created through this syntax are evaluated only on demand (see
  420. <a class="reference internal" href="../reference/executionmodel.html#lazy-evaluation"><span class="std std-ref">lazy evaluation</span></a>). This means type aliases are able to
  421. refer to other types defined later in the file.</p>
  422. <p>Type parameters declared through a type parameter list are visible within the
  423. scope of the declaration and any nested scopes, but not in the outer scope. For
  424. example, they can be used in the type annotations for the methods of a generic
  425. class or in the class body. However, they cannot be used in the module scope after
  426. the class is defined. See <a class="reference internal" href="../reference/compound_stmts.html#type-params"><span class="std std-ref">Type parameter lists</span></a> for a detailed description of the
  427. runtime semantics of type parameters.</p>
  428. <p>In order to support these scoping semantics, a new kind of scope is introduced,
  429. the <a class="reference internal" href="../reference/executionmodel.html#annotation-scopes"><span class="std std-ref">annotation scope</span></a>. Annotation scopes behave for the
  430. most part like function scopes, but interact differently with enclosing class scopes.
  431. In Python 3.13, <a class="reference internal" href="../glossary.html#term-annotation"><span class="xref std std-term">annotations</span></a> will also be evaluated in
  432. annotation scopes.</p>
  433. <p>See <span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0695/"><strong>PEP 695</strong></a> for more details.</p>
  434. <p>(PEP written by Eric Traut. Implementation by Jelle Zijlstra, Eric Traut,
  435. and others in <a class="reference external" href="https://github.com/python/cpython/issues/103764">gh-103764</a>.)</p>
  436. </section>
  437. <section id="pep-701-syntactic-formalization-of-f-strings">
  438. <span id="whatsnew312-pep701"></span><h3>PEP 701: Syntactic formalization of f-strings<a class="headerlink" href="#pep-701-syntactic-formalization-of-f-strings" title="Link to this heading">¶</a></h3>
  439. <p><span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a> lifts some restrictions on the usage of <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-strings</span></a>.
  440. Expression components inside f-strings can now be any valid Python expression,
  441. including strings reusing the same quote as the containing f-string,
  442. multi-line expressions, comments, backslashes, and unicode escape sequences.
  443. Let’s cover these in detail:</p>
  444. <ul>
  445. <li><p>Quote reuse: in Python 3.11, reusing the same quotes as the enclosing f-string
  446. raises a <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>, forcing the user to either use other available
  447. quotes (like using double quotes or triple quotes if the f-string uses single
  448. quotes). In Python 3.12, you can now do things like this:</p>
  449. <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">songs</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Take me back to Eden&#39;</span><span class="p">,</span> <span class="s1">&#39;Alkaline&#39;</span><span class="p">,</span> <span class="s1">&#39;Ascensionism&#39;</span><span class="p">]</span>
  450. <span class="gp">&gt;&gt;&gt; </span><span class="sa">f</span><span class="s2">&quot;This is the playlist: </span><span class="si">{</span><span class="s2">&quot;, &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">songs</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span>
  451. <span class="go">&#39;This is the playlist: Take me back to Eden, Alkaline, Ascensionism&#39;</span>
  452. </pre></div>
  453. </div>
  454. <p>Note that before this change there was no explicit limit in how f-strings can
  455. be nested, but the fact that string quotes cannot be reused inside the
  456. expression component of f-strings made it impossible to nest f-strings
  457. arbitrarily. In fact, this is the most nested f-string that could be written:</p>
  458. <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="sa">f</span><span class="s2">&quot;&quot;&quot;</span><span class="si">{</span><span class="sa">f</span><span class="s1">&#39;&#39;&#39;</span><span class="si">{</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="mi">1</span><span class="o">+</span><span class="mi">1</span><span class="si">}</span><span class="s2">&quot;</span><span class="si">}</span><span class="s1">&#39;</span><span class="si">}</span><span class="s1">&#39;&#39;&#39;</span><span class="si">}</span><span class="s2">&quot;&quot;&quot;</span>
  459. <span class="go">&#39;2&#39;</span>
  460. </pre></div>
  461. </div>
  462. <p>As now f-strings can contain any valid Python expression inside expression
  463. components, it is now possible to nest f-strings arbitrarily:</p>
  464. <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="mi">1</span><span class="o">+</span><span class="mi">1</span><span class="si">}</span><span class="s2">&quot;</span><span class="si">}</span><span class="s2">&quot;</span><span class="si">}</span><span class="s2">&quot;</span><span class="si">}</span><span class="s2">&quot;</span><span class="si">}</span><span class="s2">&quot;</span><span class="si">}</span><span class="s2">&quot;</span>
  465. <span class="go">&#39;2&#39;</span>
  466. </pre></div>
  467. </div>
  468. </li>
  469. <li><p>Multi-line expressions and comments: In Python 3.11, f-string expressions
  470. must be defined in a single line, even if the expression within the f-string
  471. could normally span multiple lines
  472. (like literal lists being defined over multiple lines),
  473. making them harder to read. In Python 3.12 you can now define f-strings
  474. spanning multiple lines, and add inline comments:</p>
  475. <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span>&gt;&gt;&gt; f&quot;This is the playlist: {&quot;, &quot;.join([
  476. ... &#39;Take me back to Eden&#39;, # My, my, those eyes like fire
  477. ... &#39;Alkaline&#39;, # Not acid nor alkaline
  478. ... &#39;Ascensionism&#39; # Take to the broken skies at last
  479. ... ])}&quot;
  480. &#39;This is the playlist: Take me back to Eden, Alkaline, Ascensionism&#39;
  481. </pre></div>
  482. </div>
  483. </li>
  484. <li><p>Backslashes and unicode characters: before Python 3.12 f-string expressions
  485. couldn’t contain any <code class="docutils literal notranslate"><span class="pre">\</span></code> character. This also affected unicode <a class="reference internal" href="../reference/lexical_analysis.html#escape-sequences"><span class="std std-ref">escape
  486. sequences</span></a> (such as <code class="docutils literal notranslate"><span class="pre">\N{snowman}</span></code>) as these contain
  487. the <code class="docutils literal notranslate"><span class="pre">\N</span></code> part that previously could not be part of expression components of
  488. f-strings. Now, you can define expressions like this:</p>
  489. <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;This is the playlist: </span><span class="si">{</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">songs</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
  490. <span class="go">This is the playlist: Take me back to Eden</span>
  491. <span class="go">Alkaline</span>
  492. <span class="go">Ascensionism</span>
  493. <span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;This is the playlist: </span><span class="si">{</span><span class="s2">&quot;</span><span class="se">\N{BLACK HEART SUIT}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">songs</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
  494. <span class="go">This is the playlist: Take me back to Eden♥Alkaline♥Ascensionism</span>
  495. </pre></div>
  496. </div>
  497. </li>
  498. </ul>
  499. <p>See <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a> for more details.</p>
  500. <p>As a positive side-effect of how this feature has been implemented (by parsing f-strings
  501. with <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0617/"><strong>the PEG parser</strong></a>), now error messages for f-strings are more precise
  502. and include the exact location of the error. For example, in Python 3.11, the following
  503. f-string raises a <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>:</p>
  504. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">my_string</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">x</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="n">y</span><span class="si">}</span><span class="s2">&quot;</span> <span class="o">+</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="mi">1</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="si">}</span><span class="s2">&quot;</span>
  505. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>
  506. <span class="w"> </span><span class="p">(</span><span class="n">x</span> <span class="n">z</span> <span class="n">y</span><span class="p">)</span>
  507. <span class="w"> </span><span class="pm">^^^</span>
  508. <span class="gr">SyntaxError</span>: <span class="n">f-string: invalid syntax. Perhaps you forgot a comma?</span>
  509. </pre></div>
  510. </div>
  511. <p>but the error message doesn’t include the exact location of the error within the line and
  512. also has the expression artificially surrounded by parentheses. In Python 3.12, as f-strings
  513. are parsed with the PEG parser, error messages can be more precise and show the entire line:</p>
  514. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">my_string</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">x</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="n">y</span><span class="si">}</span><span class="s2">&quot;</span> <span class="o">+</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="mi">1</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="si">}</span><span class="s2">&quot;</span>
  515. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>
  516. <span class="w"> </span><span class="n">my_string</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">x</span><span class="w"> </span><span class="n">z</span><span class="w"> </span><span class="n">y</span><span class="si">}</span><span class="s2">&quot;</span> <span class="o">+</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="mi">1</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="si">}</span><span class="s2">&quot;</span>
  517. <span class="w"> </span><span class="pm">^^^</span>
  518. <span class="gr">SyntaxError</span>: <span class="n">invalid syntax. Perhaps you forgot a comma?</span>
  519. </pre></div>
  520. </div>
  521. <p>(Contributed by Pablo Galindo, Batuhan Taskaya, Lysandros Nikolaou, Cristián
  522. Maureira-Fredes and Marta Gómez in <a class="reference external" href="https://github.com/python/cpython/issues/102856">gh-102856</a>. PEP written by Pablo Galindo,
  523. Batuhan Taskaya, Lysandros Nikolaou and Marta Gómez).</p>
  524. </section>
  525. <section id="pep-684-a-per-interpreter-gil">
  526. <span id="whatsnew312-pep684"></span><h3>PEP 684: A Per-Interpreter GIL<a class="headerlink" href="#pep-684-a-per-interpreter-gil" title="Link to this heading">¶</a></h3>
  527. <p><span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0684/"><strong>PEP 684</strong></a> introduces a per-interpreter <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">GIL</span></a>,
  528. so that sub-interpreters may now be created with a unique GIL per interpreter.
  529. This allows Python programs to take full advantage of multiple CPU
  530. cores. This is currently only available through the C-API,
  531. though a Python API is <span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0554/"><strong>anticipated for 3.13</strong></a>.</p>
  532. <p>Use the new <a class="reference internal" href="../c-api/init.html#c.Py_NewInterpreterFromConfig" title="Py_NewInterpreterFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_NewInterpreterFromConfig()</span></code></a> function to
  533. create an interpreter with its own GIL:</p>
  534. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">PyInterpreterConfig</span><span class="w"> </span><span class="n">config</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span>
  535. <span class="w"> </span><span class="p">.</span><span class="n">check_multi_interp_extensions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span>
  536. <span class="w"> </span><span class="p">.</span><span class="n">gil</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyInterpreterConfig_OWN_GIL</span><span class="p">,</span>
  537. <span class="p">};</span>
  538. <span class="n">PyThreadState</span><span class="w"> </span><span class="o">*</span><span class="n">tstate</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">NULL</span><span class="p">;</span>
  539. <span class="n">PyStatus</span><span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Py_NewInterpreterFromConfig</span><span class="p">(</span><span class="o">&amp;</span><span class="n">tstate</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  540. <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  541. <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">-1</span><span class="p">;</span>
  542. <span class="p">}</span>
  543. <span class="cm">/* The new interpreter is now active in the current thread. */</span>
  544. </pre></div>
  545. </div>
  546. <p>For further examples how to use the C-API for sub-interpreters with a
  547. per-interpreter GIL, see <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Modules/_xxsubinterpretersmodule.c">Modules/_xxsubinterpretersmodule.c</a>.</p>
  548. <p>(Contributed by Eric Snow in <a class="reference external" href="https://github.com/python/cpython/issues/104210">gh-104210</a>, etc.)</p>
  549. </section>
  550. <section id="pep-669-low-impact-monitoring-for-cpython">
  551. <span id="whatsnew312-pep669"></span><h3>PEP 669: Low impact monitoring for CPython<a class="headerlink" href="#pep-669-low-impact-monitoring-for-cpython" title="Link to this heading">¶</a></h3>
  552. <p><span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0669/"><strong>PEP 669</strong></a> defines a new <a class="reference internal" href="../library/sys.monitoring.html#module-sys.monitoring" title="sys.monitoring: Access and control event monitoring"><code class="xref py py-mod docutils literal notranslate"><span class="pre">API</span></code></a> for profilers,
  553. debuggers, and other tools to monitor events in CPython.
  554. It covers a wide range of events, including calls,
  555. returns, lines, exceptions, jumps, and more.
  556. This means that you only pay for what you use, providing support
  557. for near-zero overhead debuggers and coverage tools.
  558. See <a class="reference internal" href="../library/sys.monitoring.html#module-sys.monitoring" title="sys.monitoring: Access and control event monitoring"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys.monitoring</span></code></a> for details.</p>
  559. <p>(Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/103082">gh-103082</a>.)</p>
  560. </section>
  561. <section id="pep-688-making-the-buffer-protocol-accessible-in-python">
  562. <span id="whatsnew312-pep688"></span><h3>PEP 688: Making the buffer protocol accessible in Python<a class="headerlink" href="#pep-688-making-the-buffer-protocol-accessible-in-python" title="Link to this heading">¶</a></h3>
  563. <p><span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0688/"><strong>PEP 688</strong></a> introduces a way to use the <a class="reference internal" href="../c-api/buffer.html#bufferobjects"><span class="std std-ref">buffer protocol</span></a>
  564. from Python code. Classes that implement the <a class="reference internal" href="../reference/datamodel.html#object.__buffer__" title="object.__buffer__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__buffer__()</span></code></a> method
  565. are now usable as buffer types.</p>
  566. <p>The new <a class="reference internal" href="../library/collections.abc.html#collections.abc.Buffer" title="collections.abc.Buffer"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Buffer</span></code></a> ABC provides a standard
  567. way to represent buffer objects, for example in type annotations.
  568. The new <a class="reference internal" href="../library/inspect.html#inspect.BufferFlags" title="inspect.BufferFlags"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.BufferFlags</span></code></a> enum represents the flags that
  569. can be used to customize buffer creation.
  570. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/102500">gh-102500</a>.)</p>
  571. </section>
  572. <section id="pep-709-comprehension-inlining">
  573. <span id="whatsnew312-pep709"></span><h3>PEP 709: Comprehension inlining<a class="headerlink" href="#pep-709-comprehension-inlining" title="Link to this heading">¶</a></h3>
  574. <p>Dictionary, list, and set comprehensions are now inlined, rather than creating a
  575. new single-use function object for each execution of the comprehension. This
  576. speeds up execution of a comprehension by up to two times.
  577. See <span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0709/"><strong>PEP 709</strong></a> for further details.</p>
  578. <p>Comprehension iteration variables remain isolated and don’t overwrite a
  579. variable of the same name in the outer scope, nor are they visible after the
  580. comprehension. Inlining does result in a few visible behavior changes:</p>
  581. <ul class="simple">
  582. <li><p>There is no longer a separate frame for the comprehension in tracebacks,
  583. and tracing/profiling no longer shows the comprehension as a function call.</p></li>
  584. <li><p>The <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 will no longer produce child symbol tables for each
  585. comprehension; instead, the comprehension’s locals will be included in the
  586. parent function’s symbol table.</p></li>
  587. <li><p>Calling <a class="reference internal" href="../library/functions.html#locals" title="locals"><code class="xref py py-func docutils literal notranslate"><span class="pre">locals()</span></code></a> inside a comprehension now includes variables
  588. from outside the comprehension, and no longer includes the synthetic <code class="docutils literal notranslate"><span class="pre">.0</span></code>
  589. variable for the comprehension “argument”.</p></li>
  590. <li><p>A comprehension iterating directly over <code class="docutils literal notranslate"><span class="pre">locals()</span></code> (e.g. <code class="docutils literal notranslate"><span class="pre">[k</span> <span class="pre">for</span> <span class="pre">k</span> <span class="pre">in</span>
  591. <span class="pre">locals()]</span></code>) may see “RuntimeError: dictionary changed size during iteration”
  592. when run under tracing (e.g. code coverage measurement). This is the same
  593. behavior already seen in e.g. <code class="docutils literal notranslate"><span class="pre">for</span> <span class="pre">k</span> <span class="pre">in</span> <span class="pre">locals():</span></code>. To avoid the error, first
  594. create a list of keys to iterate over: <code class="docutils literal notranslate"><span class="pre">keys</span> <span class="pre">=</span> <span class="pre">list(locals());</span> <span class="pre">[k</span> <span class="pre">for</span> <span class="pre">k</span> <span class="pre">in</span>
  595. <span class="pre">keys]</span></code>.</p></li>
  596. </ul>
  597. <p>(Contributed by Carl Meyer and Vladimir Matveev in <span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0709/"><strong>PEP 709</strong></a>.)</p>
  598. </section>
  599. <section id="improved-error-messages">
  600. <h3>Improved Error Messages<a class="headerlink" href="#improved-error-messages" title="Link to this heading">¶</a></h3>
  601. <ul>
  602. <li><p>Modules from the standard library are now potentially suggested as part of
  603. the error messages displayed by the interpreter when 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> is
  604. raised to the top level. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/98254">gh-98254</a>.)</p>
  605. <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">sys</span><span class="o">.</span><span class="n">version_info</span>
  606. <span class="gt">Traceback (most recent call last):</span>
  607. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  608. <span class="gr">NameError</span>: <span class="n">name &#39;sys&#39; is not defined. Did you forget to import &#39;sys&#39;?</span>
  609. </pre></div>
  610. </div>
  611. </li>
  612. <li><p>Improve the error suggestion for <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> exceptions for instances.
  613. Now if 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> is raised in a method and the instance has an
  614. attribute that’s exactly equal to the name in the exception, the suggestion
  615. will include <code class="docutils literal notranslate"><span class="pre">self.&lt;NAME&gt;</span></code> instead of the closest match in the method
  616. scope. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/99139">gh-99139</a>.)</p>
  617. <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">A</span><span class="p">:</span>
  618. <span class="gp">... </span> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  619. <span class="gp">... </span> <span class="bp">self</span><span class="o">.</span><span class="n">blech</span> <span class="o">=</span> <span class="mi">1</span>
  620. <span class="gp">...</span>
  621. <span class="gp">... </span> <span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  622. <span class="gp">... </span> <span class="n">somethin</span> <span class="o">=</span> <span class="n">blech</span>
  623. <span class="gp">...</span>
  624. <span class="gp">&gt;&gt;&gt; </span><span class="n">A</span><span class="p">()</span><span class="o">.</span><span class="n">foo</span><span class="p">()</span>
  625. <span class="gt">Traceback (most recent call last):</span>
  626. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>
  627. <span class="w"> </span><span class="n">somethin</span> <span class="o">=</span> <span class="n">blech</span>
  628. <span class="w"> </span><span class="pm">^^^^^</span>
  629. <span class="gr">NameError</span>: <span class="n">name &#39;blech&#39; is not defined. Did you mean: &#39;self.blech&#39;?</span>
  630. </pre></div>
  631. </div>
  632. </li>
  633. <li><p>Improve the <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> error message when the user types <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">x</span>
  634. <span class="pre">from</span> <span class="pre">y</span></code> instead of <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">y</span> <span class="pre">import</span> <span class="pre">x</span></code>. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/98931">gh-98931</a>.)</p>
  635. <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">a.y.z</span> <span class="kn">from</span> <span class="nn">b.y.z</span>
  636. <span class="gt">Traceback (most recent call last):</span>
  637. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>
  638. <span class="w"> </span><span class="kn">import</span> <span class="nn">a.y.z</span> <span class="kn">from</span> <span class="nn">b.y.z</span>
  639. <span class="w"> </span><span class="pm">^^^^^^^^^^^^^^^^^^^^^^^</span>
  640. <span class="gr">SyntaxError</span>: <span class="n">Did you mean to use &#39;from ... import ...&#39; instead?</span>
  641. </pre></div>
  642. </div>
  643. </li>
  644. <li><p><a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> exceptions raised from failed <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">&lt;module&gt;</span> <span class="pre">import</span>
  645. <span class="pre">&lt;name&gt;</span></code> statements now include suggestions for the value of <code class="docutils literal notranslate"><span class="pre">&lt;name&gt;</span></code> based on the
  646. available names in <code class="docutils literal notranslate"><span class="pre">&lt;module&gt;</span></code>. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/91058">gh-91058</a>.)</p>
  647. <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">chainmap</span>
  648. <span class="gt">Traceback (most recent call last):</span>
  649. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  650. <span class="gr">ImportError</span>: <span class="n">cannot import name &#39;chainmap&#39; from &#39;collections&#39;. Did you mean: &#39;ChainMap&#39;?</span>
  651. </pre></div>
  652. </div>
  653. </li>
  654. </ul>
  655. </section>
  656. </section>
  657. <section id="new-features-related-to-type-hints">
  658. <h2>New Features Related to Type Hints<a class="headerlink" href="#new-features-related-to-type-hints" title="Link to this heading">¶</a></h2>
  659. <p>This section covers major changes affecting <span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>type hints</strong></a> and
  660. 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>
  661. <section id="pep-692-using-typeddict-for-more-precise-kwargs-typing">
  662. <span id="whatsnew312-pep692"></span><h3>PEP 692: Using <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> for more precise <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> typing<a class="headerlink" href="#pep-692-using-typeddict-for-more-precise-kwargs-typing" title="Link to this heading">¶</a></h3>
  663. <p>Typing <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> in a function signature as introduced by <span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> allowed
  664. for valid annotations only in cases where all of the <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> were of the
  665. same type.</p>
  666. <p><span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0692/"><strong>PEP 692</strong></a> specifies a more precise way of typing <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> by relying on
  667. typed dictionaries:</p>
  668. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">TypedDict</span><span class="p">,</span> <span class="n">Unpack</span>
  669. <span class="k">class</span> <span class="nc">Movie</span><span class="p">(</span><span class="n">TypedDict</span><span class="p">):</span>
  670. <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>
  671. <span class="n">year</span><span class="p">:</span> <span class="nb">int</span>
  672. <span class="k">def</span> <span class="nf">foo</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Unpack</span><span class="p">[</span><span class="n">Movie</span><span class="p">]):</span> <span class="o">...</span>
  673. </pre></div>
  674. </div>
  675. <p>See <span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0692/"><strong>PEP 692</strong></a> for more details.</p>
  676. <p>(Contributed by Franek Magiera in <a class="reference external" href="https://github.com/python/cpython/issues/103629">gh-103629</a>.)</p>
  677. </section>
  678. <section id="pep-698-override-decorator-for-static-typing">
  679. <span id="whatsnew312-pep698"></span><h3>PEP 698: Override Decorator for Static Typing<a class="headerlink" href="#pep-698-override-decorator-for-static-typing" title="Link to this heading">¶</a></h3>
  680. <p>A new decorator <a class="reference internal" href="../library/typing.html#typing.override" title="typing.override"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.override()</span></code></a> 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>
  681. module. It indicates to type checkers that the method is intended to override
  682. a method in a superclass. This allows type checkers to catch mistakes where
  683. a method that is intended to override something in a base class
  684. does not in fact do so.</p>
  685. <p>Example:</p>
  686. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">override</span>
  687. <span class="k">class</span> <span class="nc">Base</span><span class="p">:</span>
  688. <span class="k">def</span> <span class="nf">get_color</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
  689. <span class="k">return</span> <span class="s2">&quot;blue&quot;</span>
  690. <span class="k">class</span> <span class="nc">GoodChild</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
  691. <span class="nd">@override</span> <span class="c1"># ok: overrides Base.get_color</span>
  692. <span class="k">def</span> <span class="nf">get_color</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
  693. <span class="k">return</span> <span class="s2">&quot;yellow&quot;</span>
  694. <span class="k">class</span> <span class="nc">BadChild</span><span class="p">(</span><span class="n">Base</span><span class="p">):</span>
  695. <span class="nd">@override</span> <span class="c1"># type checker error: does not override Base.get_color</span>
  696. <span class="k">def</span> <span class="nf">get_colour</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
  697. <span class="k">return</span> <span class="s2">&quot;red&quot;</span>
  698. </pre></div>
  699. </div>
  700. <p>See <span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0698/"><strong>PEP 698</strong></a> for more details.</p>
  701. <p>(Contributed by Steven Troxler in <a class="reference external" href="https://github.com/python/cpython/issues/101561">gh-101561</a>.)</p>
  702. </section>
  703. </section>
  704. <section id="other-language-changes">
  705. <h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading">¶</a></h2>
  706. <ul class="simple">
  707. <li><p>The parser now raises <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> when parsing source code containing
  708. null bytes. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/96670">gh-96670</a>.)</p></li>
  709. <li><p>A backslash-character pair that is not a valid escape sequence now generates
  710. a <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a>, 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>.
  711. For example, <code class="docutils literal notranslate"><span class="pre">re.compile(&quot;\d+\.\d+&quot;)</span></code> now emits a <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a>
  712. (<code class="docutils literal notranslate"><span class="pre">&quot;\d&quot;</span></code> is an invalid escape sequence, use raw strings for regular
  713. expression: <code class="docutils literal notranslate"><span class="pre">re.compile(r&quot;\d+\.\d+&quot;)</span></code>).
  714. In a future Python version, <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> will eventually be raised,
  715. instead of <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a>.
  716. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/98401">gh-98401</a>.)</p></li>
  717. <li><p>Octal escapes with value larger than <code class="docutils literal notranslate"><span class="pre">0o377</span></code> (ex: <code class="docutils literal notranslate"><span class="pre">&quot;\477&quot;</span></code>), deprecated
  718. in Python 3.11, now produce a <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a>, instead of
  719. <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>.
  720. In a future Python version they will be eventually 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>.
  721. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/98401">gh-98401</a>.)</p></li>
  722. <li><p>Variables used in the target part of comprehensions that are not stored to
  723. can now be used in assignment expressions (<code class="docutils literal notranslate"><span class="pre">:=</span></code>).
  724. For example, in <code class="docutils literal notranslate"><span class="pre">[(b</span> <span class="pre">:=</span> <span class="pre">1)</span> <span class="pre">for</span> <span class="pre">a,</span> <span class="pre">b.prop</span> <span class="pre">in</span> <span class="pre">some_iter]</span></code>, the assignment to
  725. <code class="docutils literal notranslate"><span class="pre">b</span></code> is now allowed. Note that assigning to variables stored to in the target
  726. part of comprehensions (like <code class="docutils literal notranslate"><span class="pre">a</span></code>) is still disallowed, as per <span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0572/"><strong>PEP 572</strong></a>.
  727. (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/100581">gh-100581</a>.)</p></li>
  728. <li><p>Exceptions raised in a class or type’s <code class="docutils literal notranslate"><span class="pre">__set_name__</span></code> method are no longer
  729. wrapped by a <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>. Context information is added to the
  730. exception as a <span class="target" id="index-21"></span><a class="pep reference external" href="https://peps.python.org/pep-0678/"><strong>PEP 678</strong></a> note. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/77757">gh-77757</a>.)</p></li>
  731. <li><p>When a <code class="docutils literal notranslate"><span class="pre">try-except*</span></code> construct handles the entire <a class="reference internal" href="../library/exceptions.html#ExceptionGroup" title="ExceptionGroup"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExceptionGroup</span></code></a>
  732. and raises one other exception, that exception is no longer wrapped in an
  733. <a class="reference internal" href="../library/exceptions.html#ExceptionGroup" title="ExceptionGroup"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExceptionGroup</span></code></a>. Also changed in version 3.11.4. (Contributed by Irit
  734. Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/103590">gh-103590</a>.)</p></li>
  735. <li><p>The Garbage Collector now runs only on the eval breaker mechanism of the
  736. Python bytecode evaluation loop instead of object allocations. The GC can
  737. also run when <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_CheckSignals" title="PyErr_CheckSignals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_CheckSignals()</span></code></a> is called so C extensions that
  738. need to run for a long time without executing any Python code also have a
  739. chance to execute the GC periodically. (Contributed by Pablo Galindo in
  740. <a class="reference external" href="https://github.com/python/cpython/issues/97922">gh-97922</a>.)</p></li>
  741. <li><p>All builtin and extension callables expecting boolean parameters now accept
  742. arguments of any type instead of just <a class="reference internal" href="../library/functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a> and <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>.
  743. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/60203">gh-60203</a>.)</p></li>
  744. <li><p><a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-class docutils literal notranslate"><span class="pre">memoryview</span></code></a> now supports the half-float type (the “e” format code).
  745. (Contributed by Donghee Na and Antoine Pitrou in <a class="reference external" href="https://github.com/python/cpython/issues/90751">gh-90751</a>.)</p></li>
  746. <li><p><a class="reference internal" href="../library/functions.html#slice" title="slice"><code class="xref py py-class docutils literal notranslate"><span class="pre">slice</span></code></a> objects are now hashable, allowing them to be used as dict keys and
  747. set items. (Contributed by Will Bradshaw, Furkan Onder, and Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/101264">gh-101264</a>.)</p></li>
  748. <li><p><a class="reference internal" href="../library/functions.html#sum" title="sum"><code class="xref py py-func docutils literal notranslate"><span class="pre">sum()</span></code></a> now uses Neumaier summation to improve accuracy and commutativity
  749. when summing floats or mixed ints and floats.
  750. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/100425">gh-100425</a>.)</p></li>
  751. <li><p><a class="reference internal" href="../library/ast.html#ast.parse" title="ast.parse"><code class="xref py py-func docutils literal notranslate"><span class="pre">ast.parse()</span></code></a> now raises <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 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>
  752. when parsing source code containing null bytes. (Contributed by Pablo Galindo
  753. in <a class="reference external" href="https://github.com/python/cpython/issues/96670">gh-96670</a>.)</p></li>
  754. <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>,
  755. have a new a <em>filter</em> argument that allows limiting tar features than may be
  756. surprising or dangerous, such as creating files outside the destination
  757. directory.
  758. See <a class="reference internal" href="../library/tarfile.html#tarfile-extraction-filter"><span class="std std-ref">tarfile extraction filters</span></a> for details.
  759. In Python 3.14, the default will switch to <code class="docutils literal notranslate"><span class="pre">'data'</span></code>.
  760. (Contributed by Petr Viktorin in <span class="target" id="index-22"></span><a class="pep reference external" href="https://peps.python.org/pep-0706/"><strong>PEP 706</strong></a>.)</p></li>
  761. <li><p><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> instances are now hashable if the underlying
  762. mapping is hashable.
  763. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/87995">gh-87995</a>.)</p></li>
  764. <li><p>Add <a class="reference internal" href="../howto/perf_profiling.html#perf-profiling"><span class="std std-ref">support for the perf profiler</span></a> through the new
  765. environment variable <span class="target" id="index-23"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPERFSUPPORT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPERFSUPPORT</span></code></a>
  766. and command-line option <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">perf</span></code></a>,
  767. as well as the new <a class="reference internal" href="../library/sys.html#sys.activate_stack_trampoline" title="sys.activate_stack_trampoline"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.activate_stack_trampoline()</span></code></a>,
  768. <a class="reference internal" href="../library/sys.html#sys.deactivate_stack_trampoline" title="sys.deactivate_stack_trampoline"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.deactivate_stack_trampoline()</span></code></a>,
  769. and <a class="reference internal" href="../library/sys.html#sys.is_stack_trampoline_active" title="sys.is_stack_trampoline_active"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.is_stack_trampoline_active()</span></code></a> functions.
  770. (Design by Pablo Galindo. Contributed by Pablo Galindo and Christian Heimes
  771. with contributions from Gregory P. Smith [Google] and Mark Shannon
  772. in <a class="reference external" href="https://github.com/python/cpython/issues/96123">gh-96123</a>.)</p></li>
  773. </ul>
  774. </section>
  775. <section id="new-modules">
  776. <h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading">¶</a></h2>
  777. <ul class="simple">
  778. <li><p>None.</p></li>
  779. </ul>
  780. </section>
  781. <section id="improved-modules">
  782. <h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading">¶</a></h2>
  783. <section id="array">
  784. <h3>array<a class="headerlink" href="#array" title="Link to this heading">¶</a></h3>
  785. <ul class="simple">
  786. <li><p>The <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> class now supports subscripting, making it a
  787. <a class="reference internal" href="../glossary.html#term-generic-type"><span class="xref std std-term">generic type</span></a>. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/98658">gh-98658</a>.)</p></li>
  788. </ul>
  789. </section>
  790. <section id="asyncio">
  791. <h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading">¶</a></h3>
  792. <ul class="simple">
  793. <li><p>The performance of writing to sockets in <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> has been
  794. significantly improved. <code class="docutils literal notranslate"><span class="pre">asyncio</span></code> now avoids unnecessary copying when
  795. writing to sockets and uses <a class="reference internal" href="../library/socket.html#socket.socket.sendmsg" title="socket.socket.sendmsg"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sendmsg()</span></code></a> if the platform
  796. supports it. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/91166">gh-91166</a>.)</p></li>
  797. <li><p>Add <a class="reference internal" href="../library/asyncio-task.html#asyncio.eager_task_factory" title="asyncio.eager_task_factory"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.eager_task_factory()</span></code></a> and <a class="reference internal" href="../library/asyncio-task.html#asyncio.create_eager_task_factory" title="asyncio.create_eager_task_factory"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.create_eager_task_factory()</span></code></a>
  798. functions to allow opting an event loop in to eager task execution,
  799. making some use-cases 2x to 5x faster.
  800. (Contributed by Jacob Bower &amp; Itamar Oren in <a class="reference external" href="https://github.com/python/cpython/issues/102853">gh-102853</a>, <a class="reference external" href="https://github.com/python/cpython/issues/104140">gh-104140</a>, and <a class="reference external" href="https://github.com/python/cpython/issues/104138">gh-104138</a>)</p></li>
  801. <li><p>On Linux, <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> uses <a class="reference internal" href="../library/asyncio-policy.html#asyncio.PidfdChildWatcher" title="asyncio.PidfdChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.PidfdChildWatcher</span></code></a> by default
  802. if <a class="reference internal" href="../library/os.html#os.pidfd_open" title="os.pidfd_open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pidfd_open()</span></code></a> is available and functional instead of
  803. <a class="reference internal" href="../library/asyncio-policy.html#asyncio.ThreadedChildWatcher" title="asyncio.ThreadedChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.ThreadedChildWatcher</span></code></a>.
  804. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/98024">gh-98024</a>.)</p></li>
  805. <li><p>The event loop now uses the best available child watcher for each platform
  806. (<a class="reference internal" href="../library/asyncio-policy.html#asyncio.PidfdChildWatcher" title="asyncio.PidfdChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.PidfdChildWatcher</span></code></a> if supported and
  807. <a class="reference internal" href="../library/asyncio-policy.html#asyncio.ThreadedChildWatcher" title="asyncio.ThreadedChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.ThreadedChildWatcher</span></code></a> otherwise), so manually
  808. configuring a child watcher is not recommended.
  809. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/94597">gh-94597</a>.)</p></li>
  810. <li><p>Add <em>loop_factory</em> parameter to <a class="reference internal" href="../library/asyncio-runner.html#asyncio.run" title="asyncio.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.run()</span></code></a> to allow specifying
  811. a custom event loop factory.
  812. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/99388">gh-99388</a>.)</p></li>
  813. <li><p>Add C implementation of <a class="reference internal" href="../library/asyncio-task.html#asyncio.current_task" title="asyncio.current_task"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.current_task()</span></code></a> for 4x-6x speedup.
  814. (Contributed by Itamar Oren and Pranav Thulasiram Bhat in <a class="reference external" href="https://github.com/python/cpython/issues/100344">gh-100344</a>.)</p></li>
  815. <li><p><a class="reference internal" href="../library/asyncio-task.html#asyncio.iscoroutine" title="asyncio.iscoroutine"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.iscoroutine()</span></code></a> now returns <code class="docutils literal notranslate"><span class="pre">False</span></code> for generators as
  816. <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> does not support legacy generator-based coroutines.
  817. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/102748">gh-102748</a>.)</p></li>
  818. <li><p><a class="reference internal" href="../library/asyncio-task.html#asyncio.wait" title="asyncio.wait"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.wait()</span></code></a> and <a class="reference internal" href="../library/asyncio-task.html#asyncio.as_completed" title="asyncio.as_completed"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.as_completed()</span></code></a> now accepts generators
  819. yielding tasks.
  820. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/78530">gh-78530</a>.)</p></li>
  821. </ul>
  822. </section>
  823. <section id="calendar">
  824. <h3>calendar<a class="headerlink" href="#calendar" title="Link to this heading">¶</a></h3>
  825. <ul class="simple">
  826. <li><p>Add enums <a class="reference internal" href="../library/calendar.html#calendar.Month" title="calendar.Month"><code class="xref py py-data docutils literal notranslate"><span class="pre">calendar.Month</span></code></a> and <a class="reference internal" href="../library/calendar.html#calendar.Day" title="calendar.Day"><code class="xref py py-data docutils literal notranslate"><span class="pre">calendar.Day</span></code></a>
  827. defining months of the year and days of the week.
  828. (Contributed by Prince Roshan in <a class="reference external" href="https://github.com/python/cpython/issues/103636">gh-103636</a>.)</p></li>
  829. </ul>
  830. </section>
  831. <section id="csv">
  832. <h3>csv<a class="headerlink" href="#csv" title="Link to this heading">¶</a></h3>
  833. <ul class="simple">
  834. <li><p>Add <a class="reference internal" href="../library/csv.html#csv.QUOTE_NOTNULL" title="csv.QUOTE_NOTNULL"><code class="xref py py-const docutils literal notranslate"><span class="pre">csv.QUOTE_NOTNULL</span></code></a> and <a class="reference internal" href="../library/csv.html#csv.QUOTE_STRINGS" title="csv.QUOTE_STRINGS"><code class="xref py py-const docutils literal notranslate"><span class="pre">csv.QUOTE_STRINGS</span></code></a> flags to
  835. provide finer grained control of <code class="docutils literal notranslate"><span class="pre">None</span></code> and empty strings by
  836. <a class="reference internal" href="../library/csv.html#csv.writer" title="csv.writer"><code class="xref py py-class docutils literal notranslate"><span class="pre">csv.writer</span></code></a> objects.</p></li>
  837. </ul>
  838. </section>
  839. <section id="dis">
  840. <h3>dis<a class="headerlink" href="#dis" title="Link to this heading">¶</a></h3>
  841. <ul class="simple">
  842. <li><p>Pseudo instruction opcodes (which are used by the compiler but
  843. do not appear in executable bytecode) are now exposed in the
  844. <a class="reference internal" href="../library/dis.html#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> module.
  845. <a class="reference internal" href="../library/dis.html#opcode-HAVE_ARGUMENT"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">HAVE_ARGUMENT</span></code></a> is still relevant to real opcodes,
  846. but it is not useful for pseudo instructions. Use the new
  847. <a class="reference internal" href="../library/dis.html#dis.hasarg" title="dis.hasarg"><code class="xref py py-data docutils literal notranslate"><span class="pre">dis.hasarg</span></code></a> collection instead.
  848. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/94216">gh-94216</a>.)</p></li>
  849. <li><p>Add the <a class="reference internal" href="../library/dis.html#dis.hasexc" title="dis.hasexc"><code class="xref py py-data docutils literal notranslate"><span class="pre">dis.hasexc</span></code></a> collection to signify instructions that set
  850. an exception handler. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/94216">gh-94216</a>.)</p></li>
  851. </ul>
  852. </section>
  853. <section id="fractions">
  854. <h3>fractions<a class="headerlink" href="#fractions" title="Link to this heading">¶</a></h3>
  855. <ul class="simple">
  856. <li><p>Objects of type <a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">fractions.Fraction</span></code></a> now support float-style
  857. formatting. (Contributed by Mark Dickinson in <a class="reference external" href="https://github.com/python/cpython/issues/100161">gh-100161</a>.)</p></li>
  858. </ul>
  859. </section>
  860. <section id="importlib-resources">
  861. <h3>importlib.resources<a class="headerlink" href="#importlib-resources" title="Link to this heading">¶</a></h3>
  862. <ul class="simple">
  863. <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.as_file" title="importlib.resources.as_file"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.as_file()</span></code></a> now supports resource directories.
  864. (Contributed by Jason R. Coombs in <a class="reference external" href="https://github.com/python/cpython/issues/97930">gh-97930</a>.)</p></li>
  865. <li><p>Rename first parameter of <a class="reference internal" href="../library/importlib.resources.html#importlib.resources.files" title="importlib.resources.files"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.files()</span></code></a> to <em>anchor</em>.
  866. (Contributed by Jason R. Coombs in <a class="reference external" href="https://github.com/python/cpython/issues/100598">gh-100598</a>.)</p></li>
  867. </ul>
  868. </section>
  869. <section id="inspect">
  870. <h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading">¶</a></h3>
  871. <ul class="simple">
  872. <li><p>Add <a class="reference internal" href="../library/inspect.html#inspect.markcoroutinefunction" title="inspect.markcoroutinefunction"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.markcoroutinefunction()</span></code></a> to mark sync functions that return
  873. a <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> for use with <a class="reference internal" href="../library/inspect.html#inspect.iscoroutinefunction" title="inspect.iscoroutinefunction"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.iscoroutinefunction()</span></code></a>.
  874. (Contributed Carlton Gibson in <a class="reference external" href="https://github.com/python/cpython/issues/99247">gh-99247</a>.)</p></li>
  875. <li><p>Add <a class="reference internal" href="../library/inspect.html#inspect.getasyncgenstate" title="inspect.getasyncgenstate"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getasyncgenstate()</span></code></a> and <a class="reference internal" href="../library/inspect.html#inspect.getasyncgenlocals" title="inspect.getasyncgenlocals"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getasyncgenlocals()</span></code></a>
  876. for determining the current state of asynchronous generators.
  877. (Contributed by Thomas Krennwallner in <a class="reference external" href="https://github.com/python/cpython/issues/79940">gh-79940</a>.)</p></li>
  878. <li><p>The performance of <a class="reference internal" href="../library/inspect.html#inspect.getattr_static" title="inspect.getattr_static"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getattr_static()</span></code></a> has been considerably
  879. improved. Most calls to the function should be at least 2x faster than they
  880. were in Python 3.11, and some may be 6x faster or more. (Contributed by Alex
  881. Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/103193">gh-103193</a>.)</p></li>
  882. </ul>
  883. </section>
  884. <section id="itertools">
  885. <h3>itertools<a class="headerlink" href="#itertools" title="Link to this heading">¶</a></h3>
  886. <ul class="simple">
  887. <li><p>Add <a class="reference internal" href="../library/itertools.html#itertools.batched" title="itertools.batched"><code class="xref py py-class docutils literal notranslate"><span class="pre">itertools.batched()</span></code></a> for collecting into even-sized
  888. tuples where the last batch may be shorter than the rest.
  889. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/98363">gh-98363</a>.)</p></li>
  890. </ul>
  891. </section>
  892. <section id="math">
  893. <h3>math<a class="headerlink" href="#math" title="Link to this heading">¶</a></h3>
  894. <ul class="simple">
  895. <li><p>Add <a class="reference internal" href="../library/math.html#math.sumprod" title="math.sumprod"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.sumprod()</span></code></a> for computing a sum of products.
  896. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/100485">gh-100485</a>.)</p></li>
  897. <li><p>Extend <a class="reference internal" href="../library/math.html#math.nextafter" title="math.nextafter"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.nextafter()</span></code></a> to include a <em>steps</em> argument
  898. for moving up or down multiple steps at a time.
  899. (By Matthias Goergens, Mark Dickinson, and Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/94906">gh-94906</a>.)</p></li>
  900. </ul>
  901. </section>
  902. <section id="os">
  903. <h3>os<a class="headerlink" href="#os" title="Link to this heading">¶</a></h3>
  904. <ul class="simple">
  905. <li><p>Add <a class="reference internal" href="../library/os.html#os.PIDFD_NONBLOCK" title="os.PIDFD_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">os.PIDFD_NONBLOCK</span></code></a> to open a file descriptor
  906. for a process with <a class="reference internal" href="../library/os.html#os.pidfd_open" title="os.pidfd_open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.pidfd_open()</span></code></a> in non-blocking mode.
  907. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/93312">gh-93312</a>.)</p></li>
  908. <li><p><a class="reference internal" href="../library/os.html#os.DirEntry" title="os.DirEntry"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.DirEntry</span></code></a> now includes an <a class="reference internal" href="../library/os.html#os.DirEntry.is_junction" title="os.DirEntry.is_junction"><code class="xref py py-meth docutils literal notranslate"><span class="pre">os.DirEntry.is_junction()</span></code></a>
  909. method to check if the entry is a junction.
  910. (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/99547">gh-99547</a>.)</p></li>
  911. <li><p>Add <a class="reference internal" href="../library/os.html#os.listdrives" title="os.listdrives"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listdrives()</span></code></a>, <a class="reference internal" href="../library/os.html#os.listvolumes" title="os.listvolumes"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listvolumes()</span></code></a> and <a class="reference internal" href="../library/os.html#os.listmounts" title="os.listmounts"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listmounts()</span></code></a>
  912. functions on Windows for enumerating drives, volumes and mount points.
  913. (Contributed by Steve Dower in <a class="reference external" href="https://github.com/python/cpython/issues/102519">gh-102519</a>.)</p></li>
  914. <li><p><a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> and <a class="reference internal" href="../library/os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.lstat()</span></code></a> are now more accurate on Windows.
  915. The <code class="docutils literal notranslate"><span class="pre">st_birthtime</span></code> field will now be filled with the creation time
  916. of the file, and <code class="docutils literal notranslate"><span class="pre">st_ctime</span></code> is deprecated but still contains the
  917. creation time (but in the future will return the last metadata change,
  918. for consistency with other platforms). <code class="docutils literal notranslate"><span class="pre">st_dev</span></code> may be up to 64 bits
  919. and <code class="docutils literal notranslate"><span class="pre">st_ino</span></code> up to 128 bits depending on your file system, and
  920. <code class="docutils literal notranslate"><span class="pre">st_rdev</span></code> is always set to zero rather than incorrect values.
  921. Both functions may be significantly faster on newer releases of
  922. Windows. (Contributed by Steve Dower in <a class="reference external" href="https://github.com/python/cpython/issues/99726">gh-99726</a>.)</p></li>
  923. </ul>
  924. </section>
  925. <section id="os-path">
  926. <h3>os.path<a class="headerlink" href="#os-path" title="Link to this heading">¶</a></h3>
  927. <ul class="simple">
  928. <li><p>Add <a class="reference internal" href="../library/os.path.html#os.path.isjunction" title="os.path.isjunction"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.isjunction()</span></code></a> to check if a given path is a junction.
  929. (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/99547">gh-99547</a>.)</p></li>
  930. <li><p>Add <a class="reference internal" href="../library/os.path.html#os.path.splitroot" title="os.path.splitroot"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.splitroot()</span></code></a> to split a path into a triad
  931. <code class="docutils literal notranslate"><span class="pre">(drive,</span> <span class="pre">root,</span> <span class="pre">tail)</span></code>. (Contributed by Barney Gale in <a class="reference external" href="https://github.com/python/cpython/issues/101000">gh-101000</a>.)</p></li>
  932. </ul>
  933. </section>
  934. <section id="pathlib">
  935. <h3>pathlib<a class="headerlink" href="#pathlib" title="Link to this heading">¶</a></h3>
  936. <ul class="simple">
  937. <li><p>Add support for subclassing <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath" title="pathlib.PurePath"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.PurePath</span></code></a> and
  938. <a class="reference internal" href="../library/pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a>, plus their Posix- and Windows-specific variants.
  939. Subclasses may override the <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.with_segments" title="pathlib.PurePath.with_segments"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.PurePath.with_segments()</span></code></a> method
  940. to pass information between path instances.</p></li>
  941. <li><p>Add <a class="reference internal" href="../library/pathlib.html#pathlib.Path.walk" title="pathlib.Path.walk"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.walk()</span></code></a> for walking the directory trees and generating
  942. all file or directory names within them, similar to <a class="reference internal" href="../library/os.html#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.walk()</span></code></a>.
  943. (Contributed by Stanislav Zmiev in <a class="reference external" href="https://github.com/python/cpython/issues/90385">gh-90385</a>.)</p></li>
  944. <li><p>Add <em>walk_up</em> optional parameter to <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.relative_to" title="pathlib.PurePath.relative_to"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.PurePath.relative_to()</span></code></a>
  945. to allow the insertion of <code class="docutils literal notranslate"><span class="pre">..</span></code> entries in the result; this behavior is
  946. more consistent with <a class="reference internal" href="../library/os.path.html#os.path.relpath" title="os.path.relpath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.relpath()</span></code></a>.
  947. (Contributed by Domenico Ragusa in <a class="reference external" href="https://github.com/python/cpython/issues/84538">gh-84538</a>.)</p></li>
  948. <li><p>Add <a class="reference internal" href="../library/pathlib.html#pathlib.Path.is_junction" title="pathlib.Path.is_junction"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.is_junction()</span></code></a> as a proxy to <a class="reference internal" href="../library/os.path.html#os.path.isjunction" title="os.path.isjunction"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.isjunction()</span></code></a>.
  949. (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/99547">gh-99547</a>.)</p></li>
  950. <li><p>Add <em>case_sensitive</em> optional parameter to <a class="reference internal" href="../library/pathlib.html#pathlib.Path.glob" title="pathlib.Path.glob"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.glob()</span></code></a>,
  951. <a class="reference internal" href="../library/pathlib.html#pathlib.Path.rglob" title="pathlib.Path.rglob"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.rglob()</span></code></a> and <a class="reference internal" href="../library/pathlib.html#pathlib.PurePath.match" title="pathlib.PurePath.match"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.PurePath.match()</span></code></a> for matching
  952. the path’s case sensitivity, allowing for more precise control over the matching process.</p></li>
  953. </ul>
  954. </section>
  955. <section id="pdb">
  956. <h3>pdb<a class="headerlink" href="#pdb" title="Link to this heading">¶</a></h3>
  957. <ul class="simple">
  958. <li><p>Add convenience variables to hold values temporarily for debug session
  959. and provide quick access to values like the current frame or the return
  960. value.
  961. (Contributed by Tian Gao in <a class="reference external" href="https://github.com/python/cpython/issues/103693">gh-103693</a>.)</p></li>
  962. </ul>
  963. </section>
  964. <section id="random">
  965. <h3>random<a class="headerlink" href="#random" title="Link to this heading">¶</a></h3>
  966. <ul class="simple">
  967. <li><p>Add <a class="reference internal" href="../library/random.html#random.binomialvariate" title="random.binomialvariate"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.binomialvariate()</span></code></a>.
  968. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/81620">gh-81620</a>.)</p></li>
  969. <li><p>Add a default of <code class="docutils literal notranslate"><span class="pre">lambd=1.0</span></code> to <a class="reference internal" href="../library/random.html#random.expovariate" title="random.expovariate"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.expovariate()</span></code></a>.
  970. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/100234">gh-100234</a>.)</p></li>
  971. </ul>
  972. </section>
  973. <section id="shutil">
  974. <h3>shutil<a class="headerlink" href="#shutil" title="Link to this heading">¶</a></h3>
  975. <ul>
  976. <li><p><a class="reference internal" href="../library/shutil.html#shutil.make_archive" title="shutil.make_archive"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.make_archive()</span></code></a> now passes the <em>root_dir</em> argument to custom
  977. archivers which support it.
  978. In this case it no longer temporarily changes the current working directory
  979. of the process to <em>root_dir</em> to perform archiving.
  980. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/74696">gh-74696</a>.)</p></li>
  981. <li><p><a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.rmtree()</span></code></a> now accepts a new argument <em>onexc</em> which is an
  982. error handler like <em>onerror</em> but which expects an exception instance
  983. rather than a <em>(typ, val, tb)</em> triplet. <em>onerror</em> is deprecated.
  984. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102828">gh-102828</a>.)</p></li>
  985. <li><p><a class="reference internal" href="../library/shutil.html#shutil.which" title="shutil.which"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.which()</span></code></a> now consults the <em>PATHEXT</em> environment variable to
  986. find matches within <em>PATH</em> on Windows even when the given <em>cmd</em> includes
  987. a directory component.
  988. (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/103179">gh-103179</a>.)</p>
  989. <p><a class="reference internal" href="../library/shutil.html#shutil.which" title="shutil.which"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.which()</span></code></a> will call <code class="docutils literal notranslate"><span class="pre">NeedCurrentDirectoryForExePathW</span></code> when
  990. querying for executables on Windows to determine if the current working
  991. directory should be prepended to the search path.
  992. (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/103179">gh-103179</a>.)</p>
  993. <p><a class="reference internal" href="../library/shutil.html#shutil.which" title="shutil.which"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.which()</span></code></a> will return a path matching the <em>cmd</em> with a component
  994. from <code class="docutils literal notranslate"><span class="pre">PATHEXT</span></code> prior to a direct match elsewhere in the search path on
  995. Windows.
  996. (Contributed by Charles Machalow in <a class="reference external" href="https://github.com/python/cpython/issues/103179">gh-103179</a>.)</p>
  997. </li>
  998. </ul>
  999. </section>
  1000. <section id="sqlite3">
  1001. <h3>sqlite3<a class="headerlink" href="#sqlite3" title="Link to this heading">¶</a></h3>
  1002. <ul class="simple">
  1003. <li><p>Add a <a class="reference internal" href="../library/sqlite3.html#sqlite3-cli"><span class="std std-ref">command-line interface</span></a>.
  1004. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/77617">gh-77617</a>.)</p></li>
  1005. <li><p>Add the <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.autocommit" title="sqlite3.Connection.autocommit"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sqlite3.Connection.autocommit</span></code></a> attribute
  1006. to <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection" title="sqlite3.Connection"><code class="xref py py-class docutils literal notranslate"><span class="pre">sqlite3.Connection</span></code></a>
  1007. and the <em>autocommit</em> parameter to <a class="reference internal" href="../library/sqlite3.html#sqlite3.connect" title="sqlite3.connect"><code class="xref py py-func docutils literal notranslate"><span class="pre">sqlite3.connect()</span></code></a>
  1008. to control <span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0249/"><strong>PEP 249</strong></a>-compliant
  1009. <a class="reference internal" href="../library/sqlite3.html#sqlite3-transaction-control-autocommit"><span class="std std-ref">transaction handling</span></a>.
  1010. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/83638">gh-83638</a>.)</p></li>
  1011. <li><p>Add <em>entrypoint</em> keyword-only parameter to
  1012. <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">sqlite3.Connection.load_extension()</span></code></a>,
  1013. for overriding the SQLite extension entry point.
  1014. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/103015">gh-103015</a>.)</p></li>
  1015. <li><p>Add <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.getconfig" title="sqlite3.Connection.getconfig"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sqlite3.Connection.getconfig()</span></code></a> and
  1016. <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.setconfig" title="sqlite3.Connection.setconfig"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sqlite3.Connection.setconfig()</span></code></a> to <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection" title="sqlite3.Connection"><code class="xref py py-class docutils literal notranslate"><span class="pre">sqlite3.Connection</span></code></a>
  1017. to make configuration changes to a database connection.
  1018. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/103489">gh-103489</a>.)</p></li>
  1019. </ul>
  1020. </section>
  1021. <section id="statistics">
  1022. <h3>statistics<a class="headerlink" href="#statistics" title="Link to this heading">¶</a></h3>
  1023. <ul class="simple">
  1024. <li><p>Extend <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">statistics.correlation()</span></code></a> to include as a <code class="docutils literal notranslate"><span class="pre">ranked</span></code> method
  1025. for computing the Spearman correlation of ranked data.
  1026. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/95861">gh-95861</a>.)</p></li>
  1027. </ul>
  1028. </section>
  1029. <section id="sys">
  1030. <h3>sys<a class="headerlink" href="#sys" title="Link to this heading">¶</a></h3>
  1031. <ul class="simple">
  1032. <li><p>Add the <a class="reference internal" href="../library/sys.monitoring.html#module-sys.monitoring" title="sys.monitoring: Access and control event monitoring"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys.monitoring</span></code></a> namespace to expose the new <a class="reference internal" href="#whatsnew312-pep669"><span class="std std-ref">PEP 669</span></a> monitoring API.
  1033. (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/103082">gh-103082</a>.)</p></li>
  1034. <li><p>Add <a class="reference internal" href="../library/sys.html#sys.activate_stack_trampoline" title="sys.activate_stack_trampoline"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.activate_stack_trampoline()</span></code></a> and
  1035. <a class="reference internal" href="../library/sys.html#sys.deactivate_stack_trampoline" title="sys.deactivate_stack_trampoline"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.deactivate_stack_trampoline()</span></code></a> for activating and deactivating
  1036. stack profiler trampolines,
  1037. and <a class="reference internal" href="../library/sys.html#sys.is_stack_trampoline_active" title="sys.is_stack_trampoline_active"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.is_stack_trampoline_active()</span></code></a> for querying if stack profiler
  1038. trampolines are active.
  1039. (Contributed by Pablo Galindo and Christian Heimes
  1040. with contributions from Gregory P. Smith [Google] and Mark Shannon
  1041. in <a class="reference external" href="https://github.com/python/cpython/issues/96123">gh-96123</a>.)</p></li>
  1042. <li><p>Add <a class="reference internal" href="../library/sys.html#sys.last_exc" title="sys.last_exc"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_exc</span></code></a> which holds the last unhandled exception that
  1043. was raised (for post-mortem debugging use cases). Deprecate the
  1044. three fields that have the same information in its legacy form:
  1045. <a class="reference internal" href="../library/sys.html#sys.last_type" title="sys.last_type"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_type</span></code></a>, <a class="reference internal" href="../library/sys.html#sys.last_value" title="sys.last_value"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_value</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.last_traceback" title="sys.last_traceback"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_traceback</span></code></a>.
  1046. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102778">gh-102778</a>.)</p></li>
  1047. <li><p><a class="reference internal" href="../library/sys.html#sys._current_exceptions" title="sys._current_exceptions"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys._current_exceptions()</span></code></a> now returns a mapping from thread-id to an
  1048. exception instance, rather than to a <code class="docutils literal notranslate"><span class="pre">(typ,</span> <span class="pre">exc,</span> <span class="pre">tb)</span></code> tuple.
  1049. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/103176">gh-103176</a>.)</p></li>
  1050. <li><p><a class="reference internal" href="../library/sys.html#sys.setrecursionlimit" title="sys.setrecursionlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.setrecursionlimit()</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.getrecursionlimit" title="sys.getrecursionlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getrecursionlimit()</span></code></a>.
  1051. The recursion limit now applies only to Python code. Builtin functions do
  1052. not use the recursion limit, but are protected by a different mechanism
  1053. that prevents recursion from causing a virtual machine crash.</p></li>
  1054. </ul>
  1055. </section>
  1056. <section id="tempfile">
  1057. <h3>tempfile<a class="headerlink" href="#tempfile" title="Link to this heading">¶</a></h3>
  1058. <ul class="simple">
  1059. <li><p>The <a class="reference internal" href="../library/tempfile.html#tempfile.NamedTemporaryFile" title="tempfile.NamedTemporaryFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">tempfile.NamedTemporaryFile</span></code></a> function has a new optional parameter
  1060. <em>delete_on_close</em> (Contributed by Evgeny Zorin in <a class="reference external" href="https://github.com/python/cpython/issues/58451">gh-58451</a>.)</p></li>
  1061. <li><p><a class="reference internal" href="../library/tempfile.html#tempfile.mkdtemp" title="tempfile.mkdtemp"><code class="xref py py-func docutils literal notranslate"><span class="pre">tempfile.mkdtemp()</span></code></a> now always returns an absolute path, even if the
  1062. argument provided to the <em>dir</em> parameter is a relative path.</p></li>
  1063. </ul>
  1064. </section>
  1065. <section id="threading">
  1066. <span id="whatsnew-typing-py312"></span><h3>threading<a class="headerlink" href="#threading" title="Link to this heading">¶</a></h3>
  1067. <ul class="simple">
  1068. <li><p>Add <a class="reference internal" href="../library/threading.html#threading.settrace_all_threads" title="threading.settrace_all_threads"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.settrace_all_threads()</span></code></a> and
  1069. <a class="reference internal" href="../library/threading.html#threading.setprofile_all_threads" title="threading.setprofile_all_threads"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.setprofile_all_threads()</span></code></a> that allow to set tracing and
  1070. profiling functions in all running threads in addition to the calling one.
  1071. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/93503">gh-93503</a>.)</p></li>
  1072. </ul>
  1073. </section>
  1074. <section id="tkinter">
  1075. <h3>tkinter<a class="headerlink" href="#tkinter" title="Link to this heading">¶</a></h3>
  1076. <ul class="simple">
  1077. <li><p><code class="docutils literal notranslate"><span class="pre">tkinter.Canvas.coords()</span></code> now flattens its arguments.
  1078. It now accepts not only coordinates as separate arguments
  1079. (<code class="docutils literal notranslate"><span class="pre">x1,</span> <span class="pre">y1,</span> <span class="pre">x2,</span> <span class="pre">y2,</span> <span class="pre">...</span></code>) and a sequence of coordinates
  1080. (<code class="docutils literal notranslate"><span class="pre">[x1,</span> <span class="pre">y1,</span> <span class="pre">x2,</span> <span class="pre">y2,</span> <span class="pre">...]</span></code>), but also coordinates grouped in pairs
  1081. (<code class="docutils literal notranslate"><span class="pre">(x1,</span> <span class="pre">y1),</span> <span class="pre">(x2,</span> <span class="pre">y2),</span> <span class="pre">...</span></code> and <code class="docutils literal notranslate"><span class="pre">[(x1,</span> <span class="pre">y1),</span> <span class="pre">(x2,</span> <span class="pre">y2),</span> <span class="pre">...]</span></code>),
  1082. like <code class="docutils literal notranslate"><span class="pre">create_*()</span></code> methods.
  1083. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/94473">gh-94473</a>.)</p></li>
  1084. </ul>
  1085. </section>
  1086. <section id="tokenize">
  1087. <h3>tokenize<a class="headerlink" href="#tokenize" title="Link to this heading">¶</a></h3>
  1088. <ul class="simple">
  1089. <li><p>The <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> module includes the changes introduced in <span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a>.
  1090. (Contributed by Marta Gómez Macías and Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/102856">gh-102856</a>.)
  1091. See <a class="reference internal" href="#whatsnew312-porting-to-python312"><span class="std std-ref">Porting to Python 3.12</span></a> for more information on the
  1092. changes to the <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> module.</p></li>
  1093. </ul>
  1094. </section>
  1095. <section id="types">
  1096. <h3>types<a class="headerlink" href="#types" title="Link to this heading">¶</a></h3>
  1097. <ul class="simple">
  1098. <li><p>Add <a class="reference internal" href="../library/types.html#types.get_original_bases" title="types.get_original_bases"><code class="xref py py-func docutils literal notranslate"><span class="pre">types.get_original_bases()</span></code></a> to allow for further introspection of
  1099. <a class="reference internal" href="../library/typing.html#user-defined-generics"><span class="std std-ref">User-defined generic types</span></a> when subclassed. (Contributed by
  1100. James Hilton-Balfe and Alex Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/101827">gh-101827</a>.)</p></li>
  1101. </ul>
  1102. </section>
  1103. <section id="typing">
  1104. <h3>typing<a class="headerlink" href="#typing" title="Link to this heading">¶</a></h3>
  1105. <ul>
  1106. <li><p><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> checks against
  1107. <a class="reference internal" href="../library/typing.html#typing.runtime_checkable" title="typing.runtime_checkable"><code class="xref py py-func docutils literal notranslate"><span class="pre">runtime-checkable</span> <span class="pre">protocols</span></code></a> now use
  1108. <a class="reference internal" href="../library/inspect.html#inspect.getattr_static" title="inspect.getattr_static"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getattr_static()</span></code></a> rather than <a class="reference internal" href="../library/functions.html#hasattr" title="hasattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">hasattr()</span></code></a> to lookup whether
  1109. attributes exist. This means that descriptors and <a class="reference internal" href="../reference/datamodel.html#object.__getattr__" title="object.__getattr__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getattr__()</span></code></a>
  1110. methods are no longer unexpectedly evaluated during <code class="docutils literal notranslate"><span class="pre">isinstance()</span></code> checks
  1111. against runtime-checkable protocols. However, it may also mean that some
  1112. objects which used to be considered instances of a runtime-checkable protocol
  1113. may no longer be considered instances of that protocol on Python 3.12+, and
  1114. vice versa. Most users are unlikely to be affected by this change.
  1115. (Contributed by Alex Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/102433">gh-102433</a>.)</p></li>
  1116. <li><p>The members of a runtime-checkable protocol are now considered “frozen” at
  1117. runtime as soon as the class has been created. Monkey-patching attributes
  1118. onto a runtime-checkable protocol will still work, but will have no impact on
  1119. <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> checks comparing objects to the protocol. For example:</p>
  1120. <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">Protocol</span><span class="p">,</span> <span class="n">runtime_checkable</span>
  1121. <span class="gp">&gt;&gt;&gt; </span><span class="nd">@runtime_checkable</span>
  1122. <span class="gp">... </span><span class="k">class</span> <span class="nc">HasX</span><span class="p">(</span><span class="n">Protocol</span><span class="p">):</span>
  1123. <span class="gp">... </span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>
  1124. <span class="gp">...</span>
  1125. <span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">Foo</span><span class="p">:</span> <span class="o">...</span>
  1126. <span class="gp">...</span>
  1127. <span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">Foo</span><span class="p">()</span>
  1128. <span class="gp">&gt;&gt;&gt; </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">HasX</span><span class="p">)</span>
  1129. <span class="go">False</span>
  1130. <span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="o">.</span><span class="n">x</span> <span class="o">=</span> <span class="mi">1</span>
  1131. <span class="gp">&gt;&gt;&gt; </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">HasX</span><span class="p">)</span>
  1132. <span class="go">True</span>
  1133. <span class="gp">&gt;&gt;&gt; </span><span class="n">HasX</span><span class="o">.</span><span class="n">y</span> <span class="o">=</span> <span class="mi">2</span>
  1134. <span class="gp">&gt;&gt;&gt; </span><span class="nb">isinstance</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">HasX</span><span class="p">)</span> <span class="c1"># unchanged, even though HasX now also has a &quot;y&quot; attribute</span>
  1135. <span class="go">True</span>
  1136. </pre></div>
  1137. </div>
  1138. <p>This change was made in order to speed up <code class="docutils literal notranslate"><span class="pre">isinstance()</span></code> checks against
  1139. runtime-checkable protocols.</p>
  1140. </li>
  1141. <li><p>The performance profile of <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> checks against
  1142. <a class="reference internal" href="../library/typing.html#typing.runtime_checkable" title="typing.runtime_checkable"><code class="xref py py-func docutils literal notranslate"><span class="pre">runtime-checkable</span> <span class="pre">protocols</span></code></a> has changed
  1143. significantly. Most <code class="docutils literal notranslate"><span class="pre">isinstance()</span></code> checks against protocols with only a few
  1144. members should be at least 2x faster than in 3.11, and some may be 20x
  1145. faster or more. However, <code class="docutils literal notranslate"><span class="pre">isinstance()</span></code> checks against protocols with fourteen
  1146. or more members may be slower than in Python 3.11. (Contributed by Alex
  1147. Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/74690">gh-74690</a> and <a class="reference external" href="https://github.com/python/cpython/issues/103193">gh-103193</a>.)</p></li>
  1148. <li><p>All <a class="reference internal" href="../library/typing.html#typing.TypedDict" title="typing.TypedDict"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.TypedDict</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.NamedTuple" title="typing.NamedTuple"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.NamedTuple</span></code></a> classes now have the
  1149. <code class="docutils literal notranslate"><span class="pre">__orig_bases__</span></code> attribute. (Contributed by Adrian Garcia Badaracco in
  1150. <a class="reference external" href="https://github.com/python/cpython/issues/103699">gh-103699</a>.)</p></li>
  1151. <li><p>Add <code class="docutils literal notranslate"><span class="pre">frozen_default</span></code> parameter to <a class="reference internal" href="../library/typing.html#typing.dataclass_transform" title="typing.dataclass_transform"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.dataclass_transform()</span></code></a>.
  1152. (Contributed by Erik De Bonte in <a class="reference external" href="https://github.com/python/cpython/issues/99957">gh-99957</a>.)</p></li>
  1153. </ul>
  1154. </section>
  1155. <section id="unicodedata">
  1156. <h3>unicodedata<a class="headerlink" href="#unicodedata" title="Link to this heading">¶</a></h3>
  1157. <ul class="simple">
  1158. <li><p>The Unicode database has been updated to version 15.0.0. (Contributed by
  1159. Benjamin Peterson in <a class="reference external" href="https://github.com/python/cpython/issues/96734">gh-96734</a>).</p></li>
  1160. </ul>
  1161. </section>
  1162. <section id="unittest">
  1163. <h3>unittest<a class="headerlink" href="#unittest" title="Link to this heading">¶</a></h3>
  1164. <p>Add a <code class="docutils literal notranslate"><span class="pre">--durations</span></code> command line option, showing the N slowest test cases:</p>
  1165. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python3</span> <span class="o">-</span><span class="n">m</span> <span class="n">unittest</span> <span class="o">--</span><span class="n">durations</span><span class="o">=</span><span class="mi">3</span> <span class="n">lib</span><span class="o">.</span><span class="n">tests</span><span class="o">.</span><span class="n">test_threading</span>
  1166. <span class="o">.....</span>
  1167. <span class="n">Slowest</span> <span class="n">test</span> <span class="n">durations</span>
  1168. <span class="o">----------------------------------------------------------------------</span>
  1169. <span class="mf">1.210</span><span class="n">s</span> <span class="n">test_timeout</span> <span class="p">(</span><span class="n">Lib</span><span class="o">.</span><span class="n">test</span><span class="o">.</span><span class="n">test_threading</span><span class="o">.</span><span class="n">BarrierTests</span><span class="p">)</span>
  1170. <span class="mf">1.003</span><span class="n">s</span> <span class="n">test_default_timeout</span> <span class="p">(</span><span class="n">Lib</span><span class="o">.</span><span class="n">test</span><span class="o">.</span><span class="n">test_threading</span><span class="o">.</span><span class="n">BarrierTests</span><span class="p">)</span>
  1171. <span class="mf">0.518</span><span class="n">s</span> <span class="n">test_timeout</span> <span class="p">(</span><span class="n">Lib</span><span class="o">.</span><span class="n">test</span><span class="o">.</span><span class="n">test_threading</span><span class="o">.</span><span class="n">EventTests</span><span class="p">)</span>
  1172. <span class="p">(</span><span class="mf">0.000</span> <span class="n">durations</span> <span class="n">hidden</span><span class="o">.</span> <span class="n">Use</span> <span class="o">-</span><span class="n">v</span> <span class="n">to</span> <span class="n">show</span> <span class="n">these</span> <span class="n">durations</span><span class="o">.</span><span class="p">)</span>
  1173. <span class="o">----------------------------------------------------------------------</span>
  1174. <span class="n">Ran</span> <span class="mi">158</span> <span class="n">tests</span> <span class="ow">in</span> <span class="mf">9.869</span><span class="n">s</span>
  1175. <span class="n">OK</span> <span class="p">(</span><span class="n">skipped</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
  1176. </pre></div>
  1177. </div>
  1178. <p>(Contributed by Giampaolo Rodola in <a class="reference external" href="https://github.com/python/cpython/issues/48330">gh-48330</a>)</p>
  1179. </section>
  1180. <section id="uuid">
  1181. <h3>uuid<a class="headerlink" href="#uuid" title="Link to this heading">¶</a></h3>
  1182. <ul class="simple">
  1183. <li><p>Add a <a class="reference internal" href="../library/uuid.html#uuid-cli"><span class="std std-ref">command-line interface</span></a>.
  1184. (Contributed by Adam Chhina in <a class="reference external" href="https://github.com/python/cpython/issues/88597">gh-88597</a>.)</p></li>
  1185. </ul>
  1186. </section>
  1187. </section>
  1188. <section id="optimizations">
  1189. <h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading">¶</a></h2>
  1190. <ul class="simple">
  1191. <li><p>Remove <code class="docutils literal notranslate"><span class="pre">wstr</span></code> and <code class="docutils literal notranslate"><span class="pre">wstr_length</span></code> members from Unicode objects.
  1192. It reduces object size by 8 or 16 bytes on 64bit platform. (<span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-0623/"><strong>PEP 623</strong></a>)
  1193. (Contributed by Inada Naoki in <a class="reference external" href="https://github.com/python/cpython/issues/92536">gh-92536</a>.)</p></li>
  1194. <li><p>Add experimental support for using the BOLT binary optimizer in the build
  1195. process, which improves performance by 1-5%.
  1196. (Contributed by Kevin Modzelewski in <a class="reference external" href="https://github.com/python/cpython/issues/90536">gh-90536</a> and tuned by Donghee Na in <a class="reference external" href="https://github.com/python/cpython/issues/101525">gh-101525</a>)</p></li>
  1197. <li><p>Speed up the regular expression substitution (functions <a class="reference internal" href="../library/re.html#re.sub" title="re.sub"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.sub()</span></code></a> and
  1198. <a class="reference internal" href="../library/re.html#re.subn" title="re.subn"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.subn()</span></code></a> and corresponding <code class="xref py py-class docutils literal notranslate"><span class="pre">re.Pattern</span></code> methods) for
  1199. replacement strings containing group references by 2–3 times.
  1200. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/91524">gh-91524</a>.)</p></li>
  1201. <li><p>Speed up <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a> creation by deferring expensive string formatting.
  1202. (Contributed by Itamar Oren in <a class="reference external" href="https://github.com/python/cpython/issues/103793">gh-103793</a>.)</p></li>
  1203. <li><p>The <a class="reference internal" href="../library/tokenize.html#tokenize.tokenize" title="tokenize.tokenize"><code class="xref py py-func docutils literal notranslate"><span class="pre">tokenize.tokenize()</span></code></a> and <a class="reference internal" href="../library/tokenize.html#tokenize.generate_tokens" title="tokenize.generate_tokens"><code class="xref py py-func docutils literal notranslate"><span class="pre">tokenize.generate_tokens()</span></code></a> functions are
  1204. up to 64% faster as a side effect of the changes required to cover <span class="target" id="index-27"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a> in
  1205. the <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> module. (Contributed by Marta Gómez Macías and Pablo Galindo
  1206. in <a class="reference external" href="https://github.com/python/cpython/issues/102856">gh-102856</a>.)</p></li>
  1207. <li><p>Speed up <a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a> method calls and attribute loads via the
  1208. new <a class="reference internal" href="../library/dis.html#opcode-LOAD_SUPER_ATTR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_SUPER_ATTR</span></code></a> instruction. (Contributed by Carl Meyer and
  1209. Vladimir Matveev in <a class="reference external" href="https://github.com/python/cpython/issues/103497">gh-103497</a>.)</p></li>
  1210. </ul>
  1211. </section>
  1212. <section id="cpython-bytecode-changes">
  1213. <h2>CPython bytecode changes<a class="headerlink" href="#cpython-bytecode-changes" title="Link to this heading">¶</a></h2>
  1214. <ul class="simple">
  1215. <li><p>Remove the <code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_METHOD</span></code> instruction. It has been merged into
  1216. <a class="reference internal" href="../library/dis.html#opcode-LOAD_ATTR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_ATTR</span></code></a>. <a class="reference internal" href="../library/dis.html#opcode-LOAD_ATTR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_ATTR</span></code></a> will now behave like the old
  1217. <code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_METHOD</span></code> instruction if the low bit of its oparg is set.
  1218. (Contributed by Ken Jin in <a class="reference external" href="https://github.com/python/cpython/issues/93429">gh-93429</a>.)</p></li>
  1219. <li><p>Remove the <code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_IF_FALSE_OR_POP</span></code> and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_IF_TRUE_OR_POP</span></code>
  1220. instructions. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102859">gh-102859</a>.)</p></li>
  1221. <li><p>Remove the <code class="xref std std-opcode docutils literal notranslate"><span class="pre">PRECALL</span></code> instruction. (Contributed by Mark Shannon in
  1222. <a class="reference external" href="https://github.com/python/cpython/issues/92925">gh-92925</a>.)</p></li>
  1223. <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-BINARY_SLICE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BINARY_SLICE</span></code></a> and <a class="reference internal" href="../library/dis.html#opcode-STORE_SLICE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">STORE_SLICE</span></code></a> instructions.
  1224. (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/94163">gh-94163</a>.)</p></li>
  1225. <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-CALL_INTRINSIC_1"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_INTRINSIC_1</span></code></a> instructions.
  1226. (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/99005">gh-99005</a>.)</p></li>
  1227. <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-CALL_INTRINSIC_2"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_INTRINSIC_2</span></code></a> instruction.
  1228. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/101799">gh-101799</a>.)</p></li>
  1229. <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-CLEANUP_THROW"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CLEANUP_THROW</span></code></a> instruction.
  1230. (Contributed by Brandt Bucher in <a class="reference external" href="https://github.com/python/cpython/issues/90997">gh-90997</a>.)</p></li>
  1231. <li><p>Add the <code class="xref std std-opcode docutils literal notranslate"><span class="pre">END_SEND</span></code> instruction.
  1232. (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/103082">gh-103082</a>.)</p></li>
  1233. <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-LOAD_FAST_AND_CLEAR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_FAST_AND_CLEAR</span></code></a> instruction as part of the
  1234. implementation of <span class="target" id="index-28"></span><a class="pep reference external" href="https://peps.python.org/pep-0709/"><strong>PEP 709</strong></a>. (Contributed by Carl Meyer in <a class="reference external" href="https://github.com/python/cpython/issues/101441">gh-101441</a>.)</p></li>
  1235. <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-LOAD_FAST_CHECK"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_FAST_CHECK</span></code></a> instruction.
  1236. (Contributed by Dennis Sweeney in <a class="reference external" href="https://github.com/python/cpython/issues/93143">gh-93143</a>.)</p></li>
  1237. <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-LOAD_FROM_DICT_OR_DEREF"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_FROM_DICT_OR_DEREF</span></code></a>, <a class="reference internal" href="../library/dis.html#opcode-LOAD_FROM_DICT_OR_GLOBALS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_FROM_DICT_OR_GLOBALS</span></code></a>,
  1238. and <a class="reference internal" href="../library/dis.html#opcode-LOAD_LOCALS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_LOCALS</span></code></a> opcodes as part of the implementation of <span class="target" id="index-29"></span><a class="pep reference external" href="https://peps.python.org/pep-0695/"><strong>PEP 695</strong></a>.
  1239. Remove the <code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_CLASSDEREF</span></code> opcode, which can be replaced with
  1240. <a class="reference internal" href="../library/dis.html#opcode-LOAD_LOCALS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_LOCALS</span></code></a> plus <a class="reference internal" href="../library/dis.html#opcode-LOAD_FROM_DICT_OR_DEREF"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_FROM_DICT_OR_DEREF</span></code></a>. (Contributed
  1241. by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/103764">gh-103764</a>.)</p></li>
  1242. <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-LOAD_SUPER_ATTR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_SUPER_ATTR</span></code></a> instruction. (Contributed by Carl Meyer and
  1243. Vladimir Matveev in <a class="reference external" href="https://github.com/python/cpython/issues/103497">gh-103497</a>.)</p></li>
  1244. <li><p>Add the <a class="reference internal" href="../library/dis.html#opcode-RETURN_CONST"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">RETURN_CONST</span></code></a> instruction. (Contributed by Wenyang Wang in <a class="reference external" href="https://github.com/python/cpython/issues/101632">gh-101632</a>.)</p></li>
  1245. </ul>
  1246. </section>
  1247. <section id="demos-and-tools">
  1248. <h2>Demos and Tools<a class="headerlink" href="#demos-and-tools" title="Link to this heading">¶</a></h2>
  1249. <ul class="simple">
  1250. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">Tools/demo/</span></code> directory which contained old demo scripts. A copy
  1251. can be found in the <a class="reference external" href="https://github.com/gvanrossum/old-demos">old-demos project</a>.
  1252. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/97681">gh-97681</a>.)</p></li>
  1253. <li><p>Remove outdated example scripts of the <code class="docutils literal notranslate"><span class="pre">Tools/scripts/</span></code> directory.
  1254. A copy can be found in the <a class="reference external" href="https://github.com/gvanrossum/old-demos">old-demos project</a>.
  1255. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/97669">gh-97669</a>.)</p></li>
  1256. </ul>
  1257. </section>
  1258. <section id="deprecated">
  1259. <h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading">¶</a></h2>
  1260. <ul>
  1261. <li><p><a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a>: The <em>type</em>, <em>choices</em>, and <em>metavar</em> parameters
  1262. of <code class="xref py py-class docutils literal notranslate"><span class="pre">argparse.BooleanOptionalAction</span></code> are deprecated
  1263. and will be removed in 3.14.
  1264. (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/92248">gh-92248</a>.)</p></li>
  1265. <li><p><a class="reference internal" href="../library/ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a>: The following <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> features have been deprecated in documentation since
  1266. Python 3.8, now cause 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> to be emitted at runtime
  1267. when they are accessed or used, and will be removed in Python 3.14:</p>
  1268. <ul class="simple">
  1269. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Num</span></code></p></li>
  1270. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Str</span></code></p></li>
  1271. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Bytes</span></code></p></li>
  1272. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.NameConstant</span></code></p></li>
  1273. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Ellipsis</span></code></p></li>
  1274. </ul>
  1275. <p>Use <a class="reference internal" href="../library/ast.html#ast.Constant" title="ast.Constant"><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Constant</span></code></a> instead.
  1276. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/90953">gh-90953</a>.)</p>
  1277. </li>
  1278. <li><p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a>:</p>
  1279. <ul class="simple">
  1280. <li><p>The child watcher classes <a class="reference internal" href="../library/asyncio-policy.html#asyncio.MultiLoopChildWatcher" title="asyncio.MultiLoopChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.MultiLoopChildWatcher</span></code></a>,
  1281. <a class="reference internal" href="../library/asyncio-policy.html#asyncio.FastChildWatcher" title="asyncio.FastChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.FastChildWatcher</span></code></a>, <a class="reference internal" href="../library/asyncio-policy.html#asyncio.AbstractChildWatcher" title="asyncio.AbstractChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.AbstractChildWatcher</span></code></a>
  1282. and <a class="reference internal" href="../library/asyncio-policy.html#asyncio.SafeChildWatcher" title="asyncio.SafeChildWatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.SafeChildWatcher</span></code></a> are deprecated and
  1283. will be removed in Python 3.14.
  1284. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/94597">gh-94597</a>.)</p></li>
  1285. <li><p><a class="reference internal" href="../library/asyncio-policy.html#asyncio.set_child_watcher" title="asyncio.set_child_watcher"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.set_child_watcher()</span></code></a>, <a class="reference internal" href="../library/asyncio-policy.html#asyncio.get_child_watcher" title="asyncio.get_child_watcher"><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.get_child_watcher()</span></code></a>,
  1286. <a class="reference internal" href="../library/asyncio-policy.html#asyncio.AbstractEventLoopPolicy.set_child_watcher" title="asyncio.AbstractEventLoopPolicy.set_child_watcher"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.AbstractEventLoopPolicy.set_child_watcher()</span></code></a> and
  1287. <a class="reference internal" href="../library/asyncio-policy.html#asyncio.AbstractEventLoopPolicy.get_child_watcher" title="asyncio.AbstractEventLoopPolicy.get_child_watcher"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.AbstractEventLoopPolicy.get_child_watcher()</span></code></a> are deprecated
  1288. and will be removed in Python 3.14.
  1289. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/94597">gh-94597</a>.)</p></li>
  1290. <li><p>The <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.get_event_loop" title="asyncio.get_event_loop"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_event_loop()</span></code></a> method of the
  1291. default event loop policy now emits a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> if there
  1292. is no current event loop set and it decides to create one.
  1293. (Contributed by Serhiy Storchaka and Guido van Rossum in <a class="reference external" href="https://github.com/python/cpython/issues/100160">gh-100160</a>.)</p></li>
  1294. </ul>
  1295. </li>
  1296. <li><p><a class="reference internal" href="../library/calendar.html#module-calendar" title="calendar: Functions for working with calendars, including some emulation of the Unix cal program."><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code></a>: <code class="docutils literal notranslate"><span class="pre">calendar.January</span></code> and <code class="docutils literal notranslate"><span class="pre">calendar.February</span></code> constants are deprecated and
  1297. replaced by <a class="reference internal" href="../library/calendar.html#calendar.JANUARY" title="calendar.JANUARY"><code class="xref py py-data docutils literal notranslate"><span class="pre">calendar.JANUARY</span></code></a> and <a class="reference internal" href="../library/calendar.html#calendar.FEBRUARY" title="calendar.FEBRUARY"><code class="xref py py-data docutils literal notranslate"><span class="pre">calendar.FEBRUARY</span></code></a>.
  1298. (Contributed by Prince Roshan in <a class="reference external" href="https://github.com/python/cpython/issues/103636">gh-103636</a>.)</p></li>
  1299. <li><p><a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a>: Deprecated <a class="reference internal" href="../library/collections.abc.html#collections.abc.ByteString" title="collections.abc.ByteString"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.ByteString</span></code></a>.
  1300. Prefer <code class="xref py py-class docutils literal notranslate"><span class="pre">Sequence</span></code> or <a class="reference internal" href="../library/collections.abc.html#collections.abc.Buffer" title="collections.abc.Buffer"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Buffer</span></code></a>.
  1301. For use in typing, prefer a union, like <code class="docutils literal notranslate"><span class="pre">bytes</span> <span class="pre">|</span> <span class="pre">bytearray</span></code>, or <a class="reference internal" href="../library/collections.abc.html#collections.abc.Buffer" title="collections.abc.Buffer"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Buffer</span></code></a>.
  1302. (Contributed by Shantanu Jain in <a class="reference external" href="https://github.com/python/cpython/issues/91896">gh-91896</a>.)</p></li>
  1303. <li><p><a class="reference internal" href="../library/datetime.html#module-datetime" title="datetime: Basic date and time types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code></a>: <a class="reference internal" href="../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>’s <a class="reference internal" href="../library/datetime.html#datetime.datetime.utcnow" title="datetime.datetime.utcnow"><code class="xref py py-meth docutils literal notranslate"><span class="pre">utcnow()</span></code></a> and
  1304. <a class="reference internal" href="../library/datetime.html#datetime.datetime.utcfromtimestamp" title="datetime.datetime.utcfromtimestamp"><code class="xref py py-meth docutils literal notranslate"><span class="pre">utcfromtimestamp()</span></code></a> are deprecated and will be
  1305. removed in a future version. Instead, use timezone-aware objects to represent
  1306. datetimes in UTC: respectively, call <a class="reference internal" href="../library/datetime.html#datetime.datetime.now" title="datetime.datetime.now"><code class="xref py py-meth docutils literal notranslate"><span class="pre">now()</span></code></a> and
  1307. <a class="reference internal" href="../library/datetime.html#datetime.datetime.fromtimestamp" title="datetime.datetime.fromtimestamp"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fromtimestamp()</span></code></a> with the <em>tz</em> parameter set to
  1308. <a class="reference internal" href="../library/datetime.html#datetime.UTC" title="datetime.UTC"><code class="xref py py-const docutils literal notranslate"><span class="pre">datetime.UTC</span></code></a>.
  1309. (Contributed by Paul Ganssle in <a class="reference external" href="https://github.com/python/cpython/issues/103857">gh-103857</a>.)</p></li>
  1310. <li><p><a class="reference internal" href="../library/email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a>: Deprecate the <em>isdst</em> parameter in <a class="reference internal" href="../library/email.utils.html#email.utils.localtime" title="email.utils.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">email.utils.localtime()</span></code></a>.
  1311. (Contributed by Alan Williams in <a class="reference external" href="https://github.com/python/cpython/issues/72346">gh-72346</a>.)</p></li>
  1312. <li><p><a class="reference internal" href="../library/importlib.html#module-importlib.abc" title="importlib.abc: Abstract base classes related to import"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.abc</span></code></a>: Deprecated the following classes, scheduled for removal in
  1313. Python 3.14:</p>
  1314. <ul class="simple">
  1315. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.ResourceReader</span></code></p></li>
  1316. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.Traversable</span></code></p></li>
  1317. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.TraversableResources</span></code></p></li>
  1318. </ul>
  1319. <p>Use <a class="reference internal" href="../library/importlib.resources.abc.html#module-importlib.resources.abc" title="importlib.resources.abc: Abstract base classes for resources"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources.abc</span></code></a> classes instead:</p>
  1320. <ul class="simple">
  1321. <li><p><a class="reference internal" href="../library/importlib.resources.abc.html#importlib.resources.abc.Traversable" title="importlib.resources.abc.Traversable"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.resources.abc.Traversable</span></code></a></p></li>
  1322. <li><p><a class="reference internal" href="../library/importlib.resources.abc.html#importlib.resources.abc.TraversableResources" title="importlib.resources.abc.TraversableResources"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.resources.abc.TraversableResources</span></code></a></p></li>
  1323. </ul>
  1324. <p>(Contributed by Jason R. Coombs and Hugo van Kemenade in <a class="reference external" href="https://github.com/python/cpython/issues/93963">gh-93963</a>.)</p>
  1325. </li>
  1326. <li><p><a class="reference internal" href="../library/itertools.html#module-itertools" title="itertools: Functions creating iterators for efficient looping."><code class="xref py py-mod docutils literal notranslate"><span class="pre">itertools</span></code></a>: Deprecate the support for copy, deepcopy, and pickle operations,
  1327. which is undocumented, inefficient, historically buggy, and inconsistent.
  1328. This will be removed in 3.14 for a significant reduction in code
  1329. volume and maintenance burden.
  1330. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/101588">gh-101588</a>.)</p></li>
  1331. <li><p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a>: In Python 3.14, the default <a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a>
  1332. start method will change to a safer one on Linux, BSDs,
  1333. and other non-macOS POSIX platforms where <code class="docutils literal notranslate"><span class="pre">'fork'</span></code> is currently
  1334. the default (<a class="reference external" href="https://github.com/python/cpython/issues/84559">gh-84559</a>). Adding a runtime warning about this was deemed too
  1335. disruptive as the majority of code is not expected to care. Use the
  1336. <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.get_context" title="multiprocessing.get_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_context()</span></code></a> or
  1337. <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.set_start_method" title="multiprocessing.set_start_method"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_start_method()</span></code></a> APIs to explicitly specify when
  1338. your code <em>requires</em> <code class="docutils literal notranslate"><span class="pre">'fork'</span></code>. See <a class="reference internal" href="../library/multiprocessing.html#multiprocessing-start-methods"><span class="std std-ref">contexts and start methods</span></a>.</p></li>
  1339. <li><p><a class="reference internal" href="../library/pkgutil.html#module-pkgutil" title="pkgutil: Utilities for the import system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pkgutil</span></code></a>: <a class="reference internal" href="../library/pkgutil.html#pkgutil.find_loader" title="pkgutil.find_loader"><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.find_loader()</span></code></a> and <a class="reference internal" href="../library/pkgutil.html#pkgutil.get_loader" title="pkgutil.get_loader"><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.get_loader()</span></code></a>
  1340. are deprecated and will be removed in Python 3.14;
  1341. use <a class="reference internal" href="../library/importlib.html#importlib.util.find_spec" title="importlib.util.find_spec"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.find_spec()</span></code></a> instead.
  1342. (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/97850">gh-97850</a>.)</p></li>
  1343. <li><p><a class="reference internal" href="../library/pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Unix. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pty</span></code></a>: The module has two undocumented <code class="docutils literal notranslate"><span class="pre">master_open()</span></code> and <code class="docutils literal notranslate"><span class="pre">slave_open()</span></code>
  1344. functions that have been deprecated since Python 2 but only gained a
  1345. proper <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 3.12. Remove them in 3.14.
  1346. (Contributed by Soumendra Ganguly and Gregory P. Smith in <a class="reference external" href="https://github.com/python/cpython/issues/85984">gh-85984</a>.)</p></li>
  1347. <li><p><a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a>:</p>
  1348. <ul class="simple">
  1349. <li><p>The <code class="docutils literal notranslate"><span class="pre">st_ctime</span></code> fields return by <a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> and <a class="reference internal" href="../library/os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.lstat()</span></code></a> on
  1350. Windows are deprecated. In a future release, they will contain the last
  1351. metadata change time, consistent with other platforms. For now, they still
  1352. contain the creation time, which is also available in the new <code class="docutils literal notranslate"><span class="pre">st_birthtime</span></code>
  1353. field. (Contributed by Steve Dower in <a class="reference external" href="https://github.com/python/cpython/issues/99726">gh-99726</a>.)</p></li>
  1354. <li><p>On POSIX platforms, <a class="reference internal" href="../library/os.html#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fork()</span></code></a> can now raise a
  1355. <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> when it can detect being called from a
  1356. multithreaded process. There has always been a fundamental incompatibility
  1357. with the POSIX platform when doing so. Even if such code <em>appeared</em> to work.
  1358. We added the warning to to raise awareness as issues encounted by code doing
  1359. this are becoming more frequent. See the <a class="reference internal" href="../library/os.html#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fork()</span></code></a> documentation for
  1360. more details along with <a class="reference external" href="https://discuss.python.org/t/33555">this discussion on fork being incompatible with threads</a> for <em>why</em> we’re now surfacing this
  1361. longstanding platform compatibility problem to developers.</p></li>
  1362. </ul>
  1363. <p>When this warning appears due to usage of <a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> or
  1364. <a class="reference internal" href="../library/concurrent.futures.html#module-concurrent.futures" title="concurrent.futures: Execute computations concurrently using threads or processes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">concurrent.futures</span></code></a> the fix is to use a different
  1365. <a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> start method such as <code class="docutils literal notranslate"><span class="pre">&quot;spawn&quot;</span></code> or <code class="docutils literal notranslate"><span class="pre">&quot;forkserver&quot;</span></code>.</p>
  1366. </li>
  1367. <li><p><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>: The <em>onerror</em> argument of <a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.rmtree()</span></code></a> is deprecated;
  1368. use <em>onexc</em> instead. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102828">gh-102828</a>.)</p></li>
  1369. <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>:</p>
  1370. <ul class="simple">
  1371. <li><p><a class="reference internal" href="../library/sqlite3.html#sqlite3-default-converters"><span class="std std-ref">default adapters and converters</span></a> are now deprecated.
  1372. Instead, use the <a class="reference internal" href="../library/sqlite3.html#sqlite3-adapter-converter-recipes"><span class="std std-ref">Adapter and converter recipes</span></a>
  1373. and tailor them to your needs.
  1374. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/90016">gh-90016</a>.)</p></li>
  1375. <li><p>In <a class="reference internal" href="../library/sqlite3.html#sqlite3.Cursor.execute" title="sqlite3.Cursor.execute"><code class="xref py py-meth docutils literal notranslate"><span class="pre">execute()</span></code></a>, <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> is now emitted
  1376. when <a class="reference internal" href="../library/sqlite3.html#sqlite3-placeholders"><span class="std std-ref">named placeholders</span></a> are used together with
  1377. parameters supplied as a <a class="reference internal" href="../glossary.html#term-sequence"><span class="xref std std-term">sequence</span></a> instead of as a <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>.
  1378. Starting from Python 3.14, using named placeholders with parameters supplied
  1379. as a sequence will raise a <a class="reference internal" href="../library/sqlite3.html#sqlite3.ProgrammingError" title="sqlite3.ProgrammingError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ProgrammingError</span></code></a>.
  1380. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/101698">gh-101698</a>.)</p></li>
  1381. </ul>
  1382. </li>
  1383. <li><p><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>: The <a class="reference internal" href="../library/sys.html#sys.last_type" title="sys.last_type"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_type</span></code></a>, <a class="reference internal" href="../library/sys.html#sys.last_value" title="sys.last_value"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_value</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.last_traceback" title="sys.last_traceback"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_traceback</span></code></a>
  1384. fields are deprecated. Use <a class="reference internal" href="../library/sys.html#sys.last_exc" title="sys.last_exc"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.last_exc</span></code></a> instead.
  1385. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102778">gh-102778</a>.)</p></li>
  1386. <li><p><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>: Extracting tar archives without specifying <em>filter</em> is deprecated until
  1387. Python 3.14, when <code class="docutils literal notranslate"><span class="pre">'data'</span></code> filter will become the default.
  1388. See <a class="reference internal" href="../library/tarfile.html#tarfile-extraction-filter"><span class="std std-ref">Extraction filters</span></a> for details.</p></li>
  1389. <li><p><a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a>:</p>
  1390. <ul class="simple">
  1391. <li><p><a class="reference internal" href="../library/typing.html#typing.Hashable" title="typing.Hashable"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Hashable</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.Sized" title="typing.Sized"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Sized</span></code></a>, aliases for
  1392. <a class="reference internal" href="../library/collections.abc.html#collections.abc.Hashable" title="collections.abc.Hashable"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Hashable</span></code></a> and <a class="reference internal" href="../library/collections.abc.html#collections.abc.Sized" title="collections.abc.Sized"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Sized</span></code></a> respectively, are
  1393. deprecated. (<a class="reference external" href="https://github.com/python/cpython/issues/94309">gh-94309</a>.)</p></li>
  1394. <li><p><a class="reference internal" href="../library/typing.html#typing.ByteString" title="typing.ByteString"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.ByteString</span></code></a>, deprecated since Python 3.9, now causes a
  1395. <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> to be emitted when it is used.
  1396. (Contributed by Alex Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/91896">gh-91896</a>.)</p></li>
  1397. </ul>
  1398. </li>
  1399. <li><p><a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code></a>: The module now emits <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>
  1400. when testing the truth value of an <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.Element" title="xml.etree.ElementTree.Element"><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.etree.ElementTree.Element</span></code></a>.
  1401. Before, the Python implementation emitted <a class="reference internal" href="../library/exceptions.html#FutureWarning" title="FutureWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FutureWarning</span></code></a>, and the C
  1402. implementation emitted nothing.
  1403. (Contributed by Jacob Walls in <a class="reference external" href="https://github.com/python/cpython/issues/83122">gh-83122</a>.)</p></li>
  1404. <li><p>The 3-arg signatures (type, value, traceback) of <a class="reference internal" href="../reference/datamodel.html#coroutine.throw" title="coroutine.throw"><code class="xref py py-meth docutils literal notranslate"><span class="pre">coroutine</span> <span class="pre">throw()</span></code></a>, <a class="reference internal" href="../reference/expressions.html#generator.throw" title="generator.throw"><code class="xref py py-meth docutils literal notranslate"><span class="pre">generator</span> <span class="pre">throw()</span></code></a> and
  1405. <a class="reference internal" href="../reference/expressions.html#agen.athrow" title="agen.athrow"><code class="xref py py-meth docutils literal notranslate"><span class="pre">async</span> <span class="pre">generator</span> <span class="pre">throw()</span></code></a> are deprecated and
  1406. may be removed in a future version of Python. Use the single-arg versions
  1407. of these functions instead. (Contributed by Ofey Chan in <a class="reference external" href="https://github.com/python/cpython/issues/89874">gh-89874</a>.)</p></li>
  1408. <li><p><a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> is now raised when <code class="docutils literal notranslate"><span class="pre">__package__</span></code> on a
  1409. module differs from <code class="docutils literal notranslate"><span class="pre">__spec__.parent</span></code> (previously it was
  1410. <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>).
  1411. (Contributed by Brett Cannon in <a class="reference external" href="https://github.com/python/cpython/issues/65961">gh-65961</a>.)</p></li>
  1412. <li><p>Setting <code class="docutils literal notranslate"><span class="pre">__package__</span></code> or <code class="docutils literal notranslate"><span class="pre">__cached__</span></code> on a module is deprecated,
  1413. and will cease to be set or taken into consideration by the import system in Python 3.14.
  1414. (Contributed by Brett Cannon in <a class="reference external" href="https://github.com/python/cpython/issues/65961">gh-65961</a>.)</p></li>
  1415. <li><p>The bitwise inversion operator (<code class="docutils literal notranslate"><span class="pre">~</span></code>) on bool is deprecated. It will throw an
  1416. error in Python 3.14. Use <code class="docutils literal notranslate"><span class="pre">not</span></code> for logical negation of bools instead.
  1417. In the rare case that you really need the bitwise inversion of the underlying
  1418. <code class="docutils literal notranslate"><span class="pre">int</span></code>, convert to int explicitly: <code class="docutils literal notranslate"><span class="pre">~int(x)</span></code>. (Contributed by Tim Hoffmann
  1419. in <a class="reference external" href="https://github.com/python/cpython/issues/103487">gh-103487</a>.)</p></li>
  1420. <li><p>Accessing <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> on code objects was deprecated in
  1421. Python 3.10 via <span class="target" id="index-30"></span><a class="pep reference external" href="https://peps.python.org/pep-0626/"><strong>PEP 626</strong></a>,
  1422. but it only got a proper <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 3.12,
  1423. therefore it will be removed in 3.14.
  1424. (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/101866">gh-101866</a>.)</p></li>
  1425. </ul>
  1426. <section id="pending-removal-in-python-3-13">
  1427. <h3>Pending Removal in Python 3.13<a class="headerlink" href="#pending-removal-in-python-3-13" title="Link to this heading">¶</a></h3>
  1428. <p>The following modules and APIs have been deprecated in earlier Python releases,
  1429. and will be removed in Python 3.13.</p>
  1430. <p>Modules (see <span class="target" id="index-31"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a>):</p>
  1431. <ul class="simple">
  1432. <li><p><a class="reference internal" href="../library/aifc.html#module-aifc" title="aifc: Read and write audio files in AIFF or AIFC format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">aifc</span></code></a></p></li>
  1433. <li><p><a class="reference internal" href="../library/audioop.html#module-audioop" title="audioop: Manipulate raw audio data. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code></a></p></li>
  1434. <li><p><a class="reference internal" href="../library/cgi.html#module-cgi" title="cgi: Helpers for running Python scripts via the Common Gateway Interface. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cgi</span></code></a></p></li>
  1435. <li><p><a class="reference internal" href="../library/cgitb.html#module-cgitb" title="cgitb: Configurable traceback handler for CGI scripts. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cgitb</span></code></a></p></li>
  1436. <li><p><a class="reference internal" href="../library/chunk.html#module-chunk" title="chunk: Module to read IFF chunks. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">chunk</span></code></a></p></li>
  1437. <li><p><a class="reference internal" href="../library/crypt.html#module-crypt" title="crypt: The crypt() function used to check Unix passwords. (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">crypt</span></code></a></p></li>
  1438. <li><p><a class="reference internal" href="../library/imghdr.html#module-imghdr" title="imghdr: Determine the type of image contained in a file or byte stream. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">imghdr</span></code></a></p></li>
  1439. <li><p><a class="reference internal" href="../library/mailcap.html#module-mailcap" title="mailcap: Mailcap file handling. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mailcap</span></code></a></p></li>
  1440. <li><p><a class="reference internal" href="../library/msilib.html#module-msilib" title="msilib: Creation of Microsoft Installer files, and CAB files. (deprecated) (Windows)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">msilib</span></code></a></p></li>
  1441. <li><p><a class="reference internal" href="../library/nis.html#module-nis" title="nis: Interface to Sun's NIS (Yellow Pages) library. (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">nis</span></code></a></p></li>
  1442. <li><p><a class="reference internal" href="../library/nntplib.html#module-nntplib" title="nntplib: NNTP protocol client (requires sockets). (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">nntplib</span></code></a></p></li>
  1443. <li><p><a class="reference internal" href="../library/ossaudiodev.html#module-ossaudiodev" title="ossaudiodev: Access to OSS-compatible audio devices. (deprecated) (Linux, FreeBSD)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ossaudiodev</span></code></a></p></li>
  1444. <li><p><a class="reference internal" href="../library/pipes.html#module-pipes" title="pipes: A Python interface to Unix shell pipelines. (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code></a></p></li>
  1445. <li><p><a class="reference internal" href="../library/sndhdr.html#module-sndhdr" title="sndhdr: Determine type of a sound file. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sndhdr</span></code></a></p></li>
  1446. <li><p><a class="reference internal" href="../library/spwd.html#module-spwd" title="spwd: The shadow password database (getspnam() and friends). (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">spwd</span></code></a></p></li>
  1447. <li><p><a class="reference internal" href="../library/sunau.html#module-sunau" title="sunau: Provide an interface to the Sun AU sound format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sunau</span></code></a></p></li>
  1448. <li><p><a class="reference internal" href="../library/telnetlib.html#module-telnetlib" title="telnetlib: Telnet client class. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">telnetlib</span></code></a></p></li>
  1449. <li><p><a class="reference internal" href="../library/uu.html#module-uu" title="uu: Encode and decode files in uuencode format. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">uu</span></code></a></p></li>
  1450. <li><p><a class="reference internal" href="../library/xdrlib.html#module-xdrlib" title="xdrlib: Encoders and decoders for the External Data Representation (XDR). (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">xdrlib</span></code></a></p></li>
  1451. </ul>
  1452. <p>Other modules:</p>
  1453. <ul class="simple">
  1454. <li><p><code class="xref py py-mod docutils literal notranslate"><span class="pre">lib2to3</span></code>, and the <strong class="program">2to3</strong> program (<a class="reference external" href="https://github.com/python/cpython/issues/84540">gh-84540</a>)</p></li>
  1455. </ul>
  1456. <p>APIs:</p>
  1457. <ul>
  1458. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.LegacyInterpolation</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/90765">gh-90765</a>)</p></li>
  1459. <li><p><code class="docutils literal notranslate"><span class="pre">locale.resetlocale()</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/90817">gh-90817</a>)</p></li>
  1460. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">turtle.RawTurtle.settiltangle()</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/50096">gh-50096</a>)</p></li>
  1461. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.findTestCases()</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/50096">gh-50096</a>)</p></li>
  1462. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.getTestCaseNames()</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/50096">gh-50096</a>)</p></li>
  1463. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.makeSuite()</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/50096">gh-50096</a>)</p></li>
  1464. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestProgram.usageExit()</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/67048">gh-67048</a>)</p></li>
  1465. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">webbrowser.MacOSX</span></code> (<a class="reference external" href="https://github.com/python/cpython/issues/86421">gh-86421</a>)</p></li>
  1466. <li><p><a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">classmethod</span></code></a> descriptor chaining (<a class="reference external" href="https://github.com/python/cpython/issues/89519">gh-89519</a>)</p></li>
  1467. <li><p><a class="reference internal" href="../library/importlib.resources.html#module-importlib.resources" title="importlib.resources: Package resource reading, opening, and access"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.resources</span></code></a> deprecated methods:</p>
  1468. <ul class="simple">
  1469. <li><p><code class="docutils literal notranslate"><span class="pre">contents()</span></code></p></li>
  1470. <li><p><code class="docutils literal notranslate"><span class="pre">is_resource()</span></code></p></li>
  1471. <li><p><code class="docutils literal notranslate"><span class="pre">open_binary()</span></code></p></li>
  1472. <li><p><code class="docutils literal notranslate"><span class="pre">open_text()</span></code></p></li>
  1473. <li><p><code class="docutils literal notranslate"><span class="pre">path()</span></code></p></li>
  1474. <li><p><code class="docutils literal notranslate"><span class="pre">read_binary()</span></code></p></li>
  1475. <li><p><code class="docutils literal notranslate"><span class="pre">read_text()</span></code></p></li>
  1476. </ul>
  1477. <p>Use <a class="reference internal" href="../library/importlib.resources.html#importlib.resources.files" title="importlib.resources.files"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.files()</span></code></a> instead. Refer to <a class="reference external" href="https://importlib-resources.readthedocs.io/en/latest/using.html#migrating-from-legacy">importlib-resources: Migrating from Legacy</a> (<a class="reference external" href="https://github.com/python/cpython/issues/106531">gh-106531</a>)</p>
  1478. </li>
  1479. </ul>
  1480. </section>
  1481. <section id="pending-removal-in-python-3-14">
  1482. <h3>Pending Removal in Python 3.14<a class="headerlink" href="#pending-removal-in-python-3-14" title="Link to this heading">¶</a></h3>
  1483. <p>The following APIs have been deprecated
  1484. and will be removed in Python 3.14.</p>
  1485. <ul class="simple">
  1486. <li><p><a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a>: The <em>type</em>, <em>choices</em>, and <em>metavar</em> parameters
  1487. of <code class="xref py py-class docutils literal notranslate"><span class="pre">argparse.BooleanOptionalAction</span></code></p></li>
  1488. <li><p><a class="reference internal" href="../library/ast.html#module-ast" title="ast: Abstract Syntax Tree classes and manipulation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code></a>:</p>
  1489. <ul>
  1490. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Num</span></code></p></li>
  1491. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Str</span></code></p></li>
  1492. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Bytes</span></code></p></li>
  1493. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.NameConstant</span></code></p></li>
  1494. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Ellipsis</span></code></p></li>
  1495. </ul>
  1496. </li>
  1497. <li><p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a>:</p>
  1498. <ul>
  1499. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.MultiLoopChildWatcher</span></code></p></li>
  1500. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.FastChildWatcher</span></code></p></li>
  1501. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.AbstractChildWatcher</span></code></p></li>
  1502. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.SafeChildWatcher</span></code></p></li>
  1503. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.set_child_watcher()</span></code></p></li>
  1504. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">asyncio.get_child_watcher()</span></code>,</p></li>
  1505. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.AbstractEventLoopPolicy.set_child_watcher()</span></code></p></li>
  1506. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.AbstractEventLoopPolicy.get_child_watcher()</span></code></p></li>
  1507. </ul>
  1508. </li>
  1509. <li><p><a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a>: <code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.ByteString</span></code>.</p></li>
  1510. <li><p><a class="reference internal" href="../library/email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a>: the <em>isdst</em> parameter in <a class="reference internal" href="../library/email.utils.html#email.utils.localtime" title="email.utils.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">email.utils.localtime()</span></code></a>.</p></li>
  1511. <li><p><a class="reference internal" href="../library/importlib.html#module-importlib.abc" title="importlib.abc: Abstract base classes related to import"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.abc</span></code></a>:</p>
  1512. <ul>
  1513. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.ResourceReader</span></code></p></li>
  1514. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.Traversable</span></code></p></li>
  1515. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.TraversableResources</span></code></p></li>
  1516. </ul>
  1517. </li>
  1518. <li><p><a class="reference internal" href="../library/itertools.html#module-itertools" title="itertools: Functions creating iterators for efficient looping."><code class="xref py py-mod docutils literal notranslate"><span class="pre">itertools</span></code></a>: Support for copy, deepcopy, and pickle operations.</p></li>
  1519. <li><p><a class="reference internal" href="../library/pkgutil.html#module-pkgutil" title="pkgutil: Utilities for the import system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pkgutil</span></code></a>:</p>
  1520. <ul>
  1521. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.find_loader()</span></code></p></li>
  1522. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.get_loader()</span></code>.</p></li>
  1523. </ul>
  1524. </li>
  1525. <li><p><a class="reference internal" href="../library/pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Unix. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pty</span></code></a>:</p>
  1526. <ul>
  1527. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">pty.master_open()</span></code></p></li>
  1528. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">pty.slave_open()</span></code></p></li>
  1529. </ul>
  1530. </li>
  1531. <li><p><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>: The <em>onerror</em> argument of <a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.rmtree()</span></code></a></p></li>
  1532. <li><p><a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a>: <code class="xref py py-class docutils literal notranslate"><span class="pre">typing.ByteString</span></code></p></li>
  1533. <li><p><a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code></a>: Testing the truth value of an <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.Element" title="xml.etree.ElementTree.Element"><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.etree.ElementTree.Element</span></code></a>.</p></li>
  1534. <li><p>The <code class="docutils literal notranslate"><span class="pre">__package__</span></code> and <code class="docutils literal notranslate"><span class="pre">__cached__</span></code> attributes on module objects.</p></li>
  1535. <li><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 code objects.</p></li>
  1536. </ul>
  1537. </section>
  1538. <section id="pending-removal-in-python-3-15">
  1539. <h3>Pending Removal in Python 3.15<a class="headerlink" href="#pending-removal-in-python-3-15" title="Link to this heading">¶</a></h3>
  1540. <p>The following APIs have been deprecated
  1541. and will be removed in Python 3.15.</p>
  1542. <p>APIs:</p>
  1543. <ul class="simple">
  1544. <li><p><a class="reference internal" href="../library/locale.html#locale.getdefaultlocale" title="locale.getdefaultlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getdefaultlocale()</span></code></a> (<a class="reference external" href="https://github.com/python/cpython/issues/90817">gh-90817</a>)</p></li>
  1545. </ul>
  1546. </section>
  1547. <section id="pending-removal-in-future-versions">
  1548. <h3>Pending Removal in Future Versions<a class="headerlink" href="#pending-removal-in-future-versions" title="Link to this heading">¶</a></h3>
  1549. <p>The following APIs were deprecated in earlier Python versions and will be removed,
  1550. although there is currently no date scheduled for their removal.</p>
  1551. <ul class="simple">
  1552. <li><p><a class="reference internal" href="../library/array.html#module-array" title="array: Space efficient arrays of uniformly typed numeric values."><code class="xref py py-mod docutils literal notranslate"><span class="pre">array</span></code></a>’s <code class="docutils literal notranslate"><span class="pre">'u'</span></code> format code (<a class="reference external" href="https://github.com/python/cpython/issues/57281">gh-57281</a>)</p></li>
  1553. <li><p><a class="reference internal" href="../library/typing.html#typing.Text" title="typing.Text"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Text</span></code></a> (<a class="reference external" href="https://github.com/python/cpython/issues/92332">gh-92332</a>)</p></li>
  1554. <li><p>Currently Python accepts numeric literals immediately followed by keywords,
  1555. 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
  1556. 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
  1557. 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>).
  1558. A syntax warning is raised if the numeric literal is
  1559. 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>,
  1560. <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>.
  1561. In a future release it will be changed to a syntax error. (<a class="reference external" href="https://github.com/python/cpython/issues/87999">gh-87999</a>)</p></li>
  1562. </ul>
  1563. </section>
  1564. </section>
  1565. <section id="removed">
  1566. <h2>Removed<a class="headerlink" href="#removed" title="Link to this heading">¶</a></h2>
  1567. <section id="asynchat-and-asyncore">
  1568. <h3>asynchat and asyncore<a class="headerlink" href="#asynchat-and-asyncore" title="Link to this heading">¶</a></h3>
  1569. <ul class="simple">
  1570. <li><p>These two modules have been removed
  1571. according to the schedule in <span class="target" id="index-32"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a>,
  1572. having been deprecated in Python 3.6.
  1573. Use <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> instead.
  1574. (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/96580">gh-96580</a>.)</p></li>
  1575. </ul>
  1576. </section>
  1577. <section id="configparser">
  1578. <h3>configparser<a class="headerlink" href="#configparser" title="Link to this heading">¶</a></h3>
  1579. <ul class="simple">
  1580. <li><p>Several names deprecated in the <a class="reference internal" href="../library/configparser.html#module-configparser" title="configparser: Configuration file parser."><code class="xref py py-mod docutils literal notranslate"><span class="pre">configparser</span></code></a> way back in 3.2 have
  1581. been removed per <a class="reference external" href="https://github.com/python/cpython/issues/89336">gh-89336</a>:</p>
  1582. <ul>
  1583. <li><p><a class="reference internal" href="../library/configparser.html#configparser.ParsingError" title="configparser.ParsingError"><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.ParsingError</span></code></a> no longer has a <code class="docutils literal notranslate"><span class="pre">filename</span></code> attribute
  1584. or argument. Use the <code class="docutils literal notranslate"><span class="pre">source</span></code> attribute and argument instead.</p></li>
  1585. <li><p><a class="reference internal" href="../library/configparser.html#module-configparser" title="configparser: Configuration file parser."><code class="xref py py-mod docutils literal notranslate"><span class="pre">configparser</span></code></a> no longer has a <code class="docutils literal notranslate"><span class="pre">SafeConfigParser</span></code> class. Use the
  1586. shorter <a class="reference internal" href="../library/configparser.html#configparser.ConfigParser" title="configparser.ConfigParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">ConfigParser</span></code></a> name instead.</p></li>
  1587. <li><p><a class="reference internal" href="../library/configparser.html#configparser.ConfigParser" title="configparser.ConfigParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.ConfigParser</span></code></a> no longer has a <code class="docutils literal notranslate"><span class="pre">readfp</span></code> method.
  1588. Use <a class="reference internal" href="../library/configparser.html#configparser.ConfigParser.read_file" title="configparser.ConfigParser.read_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">read_file()</span></code></a> instead.</p></li>
  1589. </ul>
  1590. </li>
  1591. </ul>
  1592. </section>
  1593. <section id="distutils">
  1594. <h3>distutils<a class="headerlink" href="#distutils" title="Link to this heading">¶</a></h3>
  1595. <ul class="simple">
  1596. <li><p>Remove the <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code> package. It was deprecated in Python 3.10 by
  1597. <span class="target" id="index-33"></span><a class="pep reference external" href="https://peps.python.org/pep-0632/"><strong>PEP 632</strong></a> “Deprecate distutils module”. For projects still using
  1598. <code class="docutils literal notranslate"><span class="pre">distutils</span></code> and cannot be updated to something else, the <code class="docutils literal notranslate"><span class="pre">setuptools</span></code>
  1599. project can be installed: it still provides <code class="docutils literal notranslate"><span class="pre">distutils</span></code>.
  1600. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/92584">gh-92584</a>.)</p></li>
  1601. </ul>
  1602. </section>
  1603. <section id="ensurepip">
  1604. <h3>ensurepip<a class="headerlink" href="#ensurepip" title="Link to this heading">¶</a></h3>
  1605. <ul>
  1606. <li><p>Remove the bundled setuptools wheel from <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>,
  1607. and stop installing setuptools in environments created by <a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a>.</p>
  1608. <p><code class="docutils literal notranslate"><span class="pre">pip</span> <span class="pre">(&gt;=</span> <span class="pre">22.1)</span></code> does not require setuptools to be installed in the
  1609. environment. <code class="docutils literal notranslate"><span class="pre">setuptools</span></code>-based (and <code class="docutils literal notranslate"><span class="pre">distutils</span></code>-based) packages
  1610. can still be used with <code class="docutils literal notranslate"><span class="pre">pip</span> <span class="pre">install</span></code>, since pip will provide
  1611. <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> in the build environment it uses for building a
  1612. package.</p>
  1613. <p><code class="docutils literal notranslate"><span class="pre">easy_install</span></code>, <code class="docutils literal notranslate"><span class="pre">pkg_resources</span></code>, <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> and <code class="docutils literal notranslate"><span class="pre">distutils</span></code>
  1614. are no longer provided by default in environments created with
  1615. <code class="docutils literal notranslate"><span class="pre">venv</span></code> or bootstrapped with <code class="docutils literal notranslate"><span class="pre">ensurepip</span></code>, since they are part of
  1616. the <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> package. For projects relying on these at runtime,
  1617. the <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> project should be declared as a dependency and
  1618. installed separately (typically, using pip).</p>
  1619. <p>(Contributed by Pradyun Gedam in <a class="reference external" href="https://github.com/python/cpython/issues/95299">gh-95299</a>.)</p>
  1620. </li>
  1621. </ul>
  1622. </section>
  1623. <section id="enum">
  1624. <h3>enum<a class="headerlink" href="#enum" title="Link to this heading">¶</a></h3>
  1625. <ul class="simple">
  1626. <li><p>Remove <a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a>’s <code class="docutils literal notranslate"><span class="pre">EnumMeta.__getattr__</span></code>, which is no longer needed for
  1627. enum attribute access.
  1628. (Contributed by Ethan Furman in <a class="reference external" href="https://github.com/python/cpython/issues/95083">gh-95083</a>.)</p></li>
  1629. </ul>
  1630. </section>
  1631. <section id="ftplib">
  1632. <h3>ftplib<a class="headerlink" href="#ftplib" title="Link to this heading">¶</a></h3>
  1633. <ul class="simple">
  1634. <li><p>Remove <a class="reference internal" href="../library/ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a>’s <code class="docutils literal notranslate"><span class="pre">FTP_TLS.ssl_version</span></code> class attribute: use the
  1635. <em>context</em> parameter instead.
  1636. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94172">gh-94172</a>.)</p></li>
  1637. </ul>
  1638. </section>
  1639. <section id="gzip">
  1640. <h3>gzip<a class="headerlink" href="#gzip" title="Link to this heading">¶</a></h3>
  1641. <ul class="simple">
  1642. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">filename</span></code> attribute of <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>’s <a class="reference internal" href="../library/gzip.html#gzip.GzipFile" title="gzip.GzipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">gzip.GzipFile</span></code></a>,
  1643. deprecated since Python 2.6, use the <a class="reference internal" href="../library/gzip.html#gzip.GzipFile.name" title="gzip.GzipFile.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> attribute
  1644. instead. In write mode, the <code class="docutils literal notranslate"><span class="pre">filename</span></code> attribute added <code class="docutils literal notranslate"><span class="pre">'.gz'</span></code> file
  1645. extension if it was not present.
  1646. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94196">gh-94196</a>.)</p></li>
  1647. </ul>
  1648. </section>
  1649. <section id="hashlib">
  1650. <h3>hashlib<a class="headerlink" href="#hashlib" title="Link to this heading">¶</a></h3>
  1651. <ul class="simple">
  1652. <li><p>Remove the pure Python implementation of <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a>’s
  1653. <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">hashlib.pbkdf2_hmac()</span></code></a>, deprecated in Python 3.10. Python 3.10 and
  1654. newer requires OpenSSL 1.1.1 (<span class="target" id="index-34"></span><a class="pep reference external" href="https://peps.python.org/pep-0644/"><strong>PEP 644</strong></a>): this OpenSSL version provides
  1655. a C implementation 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> which is faster.
  1656. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94199">gh-94199</a>.)</p></li>
  1657. </ul>
  1658. </section>
  1659. <section id="importlib">
  1660. <h3>importlib<a class="headerlink" href="#importlib" title="Link to this heading">¶</a></h3>
  1661. <ul class="simple">
  1662. <li><p>Many previously deprecated cleanups 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> have now been
  1663. completed:</p>
  1664. <ul>
  1665. <li><p>References to, and support for <code class="xref py py-meth docutils literal notranslate"><span class="pre">module_repr()</span></code> has been removed.
  1666. (Contributed by Barry Warsaw in <a class="reference external" href="https://github.com/python/cpython/issues/97850">gh-97850</a>.)</p></li>
  1667. <li><p><code class="docutils literal notranslate"><span class="pre">importlib.util.set_package</span></code>, <code class="docutils literal notranslate"><span class="pre">importlib.util.set_loader</span></code> and
  1668. <code class="docutils literal notranslate"><span class="pre">importlib.util.module_for_loader</span></code> have all been removed. (Contributed by
  1669. Brett Cannon and Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/65961">gh-65961</a> and <a class="reference external" href="https://github.com/python/cpython/issues/97850">gh-97850</a>.)</p></li>
  1670. <li><p>Support for <code class="docutils literal notranslate"><span class="pre">find_loader()</span></code> and <code class="docutils literal notranslate"><span class="pre">find_module()</span></code> APIs have been
  1671. removed. (Contributed by Barry Warsaw in <a class="reference external" href="https://github.com/python/cpython/issues/98040">gh-98040</a>.)</p></li>
  1672. <li><p><code class="docutils literal notranslate"><span class="pre">importlib.abc.Finder</span></code>, <code class="docutils literal notranslate"><span class="pre">pkgutil.ImpImporter</span></code>, and <code class="docutils literal notranslate"><span class="pre">pkgutil.ImpLoader</span></code>
  1673. have been removed. (Contributed by Barry Warsaw in <a class="reference external" href="https://github.com/python/cpython/issues/98040">gh-98040</a>.)</p></li>
  1674. </ul>
  1675. </li>
  1676. </ul>
  1677. </section>
  1678. <section id="imp">
  1679. <h3>imp<a class="headerlink" href="#imp" title="Link to this heading">¶</a></h3>
  1680. <ul>
  1681. <li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> module has been removed. (Contributed by Barry Warsaw in
  1682. <a class="reference external" href="https://github.com/python/cpython/issues/98040">gh-98040</a>.)</p>
  1683. <p>To migrate, consult the following correspondence table:</p>
  1684. <blockquote>
  1685. <div><table class="docutils align-default">
  1686. <thead>
  1687. <tr class="row-odd"><th class="head"><p>imp</p></th>
  1688. <th class="head"><p>importlib</p></th>
  1689. </tr>
  1690. </thead>
  1691. <tbody>
  1692. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imp.NullImporter</span></code></p></td>
  1693. <td><p>Insert <code class="docutils literal notranslate"><span class="pre">None</span></code> into <code class="docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></p></td>
  1694. </tr>
  1695. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">imp.cache_from_source()</span></code></p></td>
  1696. <td><p><a class="reference internal" href="../library/importlib.html#importlib.util.cache_from_source" title="importlib.util.cache_from_source"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.cache_from_source()</span></code></a></p></td>
  1697. </tr>
  1698. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imp.find_module()</span></code></p></td>
  1699. <td><p><a class="reference internal" href="../library/importlib.html#importlib.util.find_spec" title="importlib.util.find_spec"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.find_spec()</span></code></a></p></td>
  1700. </tr>
  1701. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">imp.get_magic()</span></code></p></td>
  1702. <td><p><a class="reference internal" href="../library/importlib.html#importlib.util.MAGIC_NUMBER" title="importlib.util.MAGIC_NUMBER"><code class="xref py py-attr docutils literal notranslate"><span class="pre">importlib.util.MAGIC_NUMBER</span></code></a></p></td>
  1703. </tr>
  1704. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imp.get_suffixes()</span></code></p></td>
  1705. <td><p><a class="reference internal" href="../library/importlib.html#importlib.machinery.SOURCE_SUFFIXES" title="importlib.machinery.SOURCE_SUFFIXES"><code class="xref py py-attr docutils literal notranslate"><span class="pre">importlib.machinery.SOURCE_SUFFIXES</span></code></a>, <a class="reference internal" href="../library/importlib.html#importlib.machinery.EXTENSION_SUFFIXES" title="importlib.machinery.EXTENSION_SUFFIXES"><code class="xref py py-attr docutils literal notranslate"><span class="pre">importlib.machinery.EXTENSION_SUFFIXES</span></code></a>, and <a class="reference internal" href="../library/importlib.html#importlib.machinery.BYTECODE_SUFFIXES" title="importlib.machinery.BYTECODE_SUFFIXES"><code class="xref py py-attr docutils literal notranslate"><span class="pre">importlib.machinery.BYTECODE_SUFFIXES</span></code></a></p></td>
  1706. </tr>
  1707. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">imp.get_tag()</span></code></p></td>
  1708. <td><p><a class="reference internal" href="../library/sys.html#sys.implementation" title="sys.implementation"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.implementation.cache_tag</span></code></a></p></td>
  1709. </tr>
  1710. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imp.load_module()</span></code></p></td>
  1711. <td><p><a class="reference internal" href="../library/importlib.html#importlib.import_module" title="importlib.import_module"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.import_module()</span></code></a></p></td>
  1712. </tr>
  1713. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">imp.new_module(name)</span></code></p></td>
  1714. <td><p><code class="docutils literal notranslate"><span class="pre">types.ModuleType(name)</span></code></p></td>
  1715. </tr>
  1716. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imp.reload()</span></code></p></td>
  1717. <td><p><a class="reference internal" href="../library/importlib.html#importlib.reload" title="importlib.reload"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.reload()</span></code></a></p></td>
  1718. </tr>
  1719. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">imp.source_from_cache()</span></code></p></td>
  1720. <td><p><a class="reference internal" href="../library/importlib.html#importlib.util.source_from_cache" title="importlib.util.source_from_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.source_from_cache()</span></code></a></p></td>
  1721. </tr>
  1722. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">imp.load_source()</span></code></p></td>
  1723. <td><p><em>See below</em></p></td>
  1724. </tr>
  1725. </tbody>
  1726. </table>
  1727. </div></blockquote>
  1728. <p>Replace <code class="docutils literal notranslate"><span class="pre">imp.load_source()</span></code> with:</p>
  1729. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">importlib.util</span>
  1730. <span class="kn">import</span> <span class="nn">importlib.machinery</span>
  1731. <span class="k">def</span> <span class="nf">load_source</span><span class="p">(</span><span class="n">modname</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
  1732. <span class="n">loader</span> <span class="o">=</span> <span class="n">importlib</span><span class="o">.</span><span class="n">machinery</span><span class="o">.</span><span class="n">SourceFileLoader</span><span class="p">(</span><span class="n">modname</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
  1733. <span class="n">spec</span> <span class="o">=</span> <span class="n">importlib</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="n">spec_from_file_location</span><span class="p">(</span><span class="n">modname</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">loader</span><span class="o">=</span><span class="n">loader</span><span class="p">)</span>
  1734. <span class="n">module</span> <span class="o">=</span> <span class="n">importlib</span><span class="o">.</span><span class="n">util</span><span class="o">.</span><span class="n">module_from_spec</span><span class="p">(</span><span class="n">spec</span><span class="p">)</span>
  1735. <span class="c1"># The module is always executed and not cached in sys.modules.</span>
  1736. <span class="c1"># Uncomment the following line to cache the module.</span>
  1737. <span class="c1"># sys.modules[module.__name__] = module</span>
  1738. <span class="n">loader</span><span class="o">.</span><span class="n">exec_module</span><span class="p">(</span><span class="n">module</span><span class="p">)</span>
  1739. <span class="k">return</span> <span class="n">module</span>
  1740. </pre></div>
  1741. </div>
  1742. </li>
  1743. <li><p>Remove <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> functions and attributes with no replacements:</p>
  1744. <ul class="simple">
  1745. <li><p>Undocumented functions:</p>
  1746. <ul>
  1747. <li><p><code class="docutils literal notranslate"><span class="pre">imp.init_builtin()</span></code></p></li>
  1748. <li><p><code class="docutils literal notranslate"><span class="pre">imp.load_compiled()</span></code></p></li>
  1749. <li><p><code class="docutils literal notranslate"><span class="pre">imp.load_dynamic()</span></code></p></li>
  1750. <li><p><code class="docutils literal notranslate"><span class="pre">imp.load_package()</span></code></p></li>
  1751. </ul>
  1752. </li>
  1753. <li><p><code class="docutils literal notranslate"><span class="pre">imp.lock_held()</span></code>, <code class="docutils literal notranslate"><span class="pre">imp.acquire_lock()</span></code>, <code class="docutils literal notranslate"><span class="pre">imp.release_lock()</span></code>:
  1754. the locking scheme has changed in Python 3.3 to per-module locks.</p></li>
  1755. <li><p><code class="docutils literal notranslate"><span class="pre">imp.find_module()</span></code> constants: <code class="docutils literal notranslate"><span class="pre">SEARCH_ERROR</span></code>, <code class="docutils literal notranslate"><span class="pre">PY_SOURCE</span></code>,
  1756. <code class="docutils literal notranslate"><span class="pre">PY_COMPILED</span></code>, <code class="docutils literal notranslate"><span class="pre">C_EXTENSION</span></code>, <code class="docutils literal notranslate"><span class="pre">PY_RESOURCE</span></code>, <code class="docutils literal notranslate"><span class="pre">PKG_DIRECTORY</span></code>,
  1757. <code class="docutils literal notranslate"><span class="pre">C_BUILTIN</span></code>, <code class="docutils literal notranslate"><span class="pre">PY_FROZEN</span></code>, <code class="docutils literal notranslate"><span class="pre">PY_CODERESOURCE</span></code>, <code class="docutils literal notranslate"><span class="pre">IMP_HOOK</span></code>.</p></li>
  1758. </ul>
  1759. </li>
  1760. </ul>
  1761. </section>
  1762. <section id="io">
  1763. <h3>io<a class="headerlink" href="#io" title="Link to this heading">¶</a></h3>
  1764. <ul class="simple">
  1765. <li><p>Remove <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>’s <code class="docutils literal notranslate"><span class="pre">io.OpenWrapper</span></code> and <code class="docutils literal notranslate"><span class="pre">_pyio.OpenWrapper</span></code>, deprecated in Python
  1766. 3.10: just use <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> instead. The <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> (<a class="reference internal" href="../library/io.html#io.open" title="io.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">io.open()</span></code></a>)
  1767. function is a built-in function. Since Python 3.10, <code class="xref py py-func docutils literal notranslate"><span class="pre">_pyio.open()</span></code> is
  1768. also a static method.
  1769. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94169">gh-94169</a>.)</p></li>
  1770. </ul>
  1771. </section>
  1772. <section id="locale">
  1773. <h3>locale<a class="headerlink" href="#locale" title="Link to this heading">¶</a></h3>
  1774. <ul class="simple">
  1775. <li><p>Remove <a class="reference internal" href="../library/locale.html#module-locale" title="locale: Internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">locale</span></code></a>’s <code class="xref py py-func docutils literal notranslate"><span class="pre">locale.format()</span></code> function, deprecated in Python 3.7:
  1776. use <a class="reference internal" href="../library/locale.html#locale.format_string" title="locale.format_string"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.format_string()</span></code></a> instead.
  1777. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94226">gh-94226</a>.)</p></li>
  1778. </ul>
  1779. </section>
  1780. <section id="smtpd">
  1781. <h3>smtpd<a class="headerlink" href="#smtpd" title="Link to this heading">¶</a></h3>
  1782. <ul class="simple">
  1783. <li><p>The <code class="docutils literal notranslate"><span class="pre">smtpd</span></code> module has been removed according to the schedule in <span class="target" id="index-35"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a>,
  1784. having been deprecated in Python 3.4.7 and 3.5.4.
  1785. Use <a class="reference external" href="https://pypi.org/project/aiosmtpd/">aiosmtpd</a> PyPI module or any other
  1786. <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>-based server instead.
  1787. (Contributed by Oleg Iarygin in <a class="reference external" href="https://github.com/python/cpython/issues/93243">gh-93243</a>.)</p></li>
  1788. </ul>
  1789. </section>
  1790. <section id="id2">
  1791. <h3>sqlite3<a class="headerlink" href="#id2" title="Link to this heading">¶</a></h3>
  1792. <ul>
  1793. <li><p>The following undocumented <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> features, deprecated in Python
  1794. 3.10, are now removed:</p>
  1795. <ul class="simple">
  1796. <li><p><code class="docutils literal notranslate"><span class="pre">sqlite3.enable_shared_cache()</span></code></p></li>
  1797. <li><p><code class="docutils literal notranslate"><span class="pre">sqlite3.OptimizedUnicode</span></code></p></li>
  1798. </ul>
  1799. <p>If a shared cache must be used, open the database in URI mode using the
  1800. <code class="docutils literal notranslate"><span class="pre">cache=shared</span></code> query parameter.</p>
  1801. <p>The <code class="docutils literal notranslate"><span class="pre">sqlite3.OptimizedUnicode</span></code> text factory has been an alias for
  1802. <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> since Python 3.3. Code that previously set the text factory to
  1803. <code class="docutils literal notranslate"><span class="pre">OptimizedUnicode</span></code> can either use <code class="docutils literal notranslate"><span class="pre">str</span></code> explicitly, or rely on the
  1804. default value which is also <code class="docutils literal notranslate"><span class="pre">str</span></code>.</p>
  1805. <p>(Contributed by Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/92548">gh-92548</a>.)</p>
  1806. </li>
  1807. </ul>
  1808. </section>
  1809. <section id="ssl">
  1810. <h3>ssl<a class="headerlink" href="#ssl" title="Link to this heading">¶</a></h3>
  1811. <ul class="simple">
  1812. <li><p>Remove <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>’s <code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.RAND_pseudo_bytes()</span></code> function, deprecated in Python 3.6:
  1813. use <a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.urandom()</span></code></a> or <a class="reference internal" href="../library/ssl.html#ssl.RAND_bytes" title="ssl.RAND_bytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.RAND_bytes()</span></code></a> instead.
  1814. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94199">gh-94199</a>.)</p></li>
  1815. <li><p>Remove the <code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.match_hostname()</span></code> function.
  1816. It was deprecated in Python 3.7. OpenSSL performs
  1817. hostname matching since Python 3.7, Python no longer uses the
  1818. <code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.match_hostname()</span></code> function.
  1819. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94199">gh-94199</a>.)</p></li>
  1820. <li><p>Remove the <code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.wrap_socket()</span></code> function, deprecated in Python 3.7:
  1821. instead, create a <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> object and call its
  1822. <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.wrap_socket" title="ssl.SSLContext.wrap_socket"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext.wrap_socket</span></code></a> method. Any package that still uses
  1823. <code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.wrap_socket()</span></code> is broken and insecure. The function neither sends a
  1824. SNI TLS extension nor validates server hostname. Code is subject to <a class="reference external" href="https://cwe.mitre.org/data/definitions/295.html">CWE-295</a>: Improper Certificate
  1825. Validation.
  1826. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94199">gh-94199</a>.)</p></li>
  1827. </ul>
  1828. </section>
  1829. <section id="id3">
  1830. <h3>unittest<a class="headerlink" href="#id3" title="Link to this heading">¶</a></h3>
  1831. <ul>
  1832. <li><p>Remove many long-deprecated <a class="reference internal" href="../library/unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code></a> features:</p>
  1833. <ul id="unittest-testcase-removed-aliases">
  1834. <li><p>A number of <a class="reference internal" href="../library/unittest.html#unittest.TestCase" title="unittest.TestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestCase</span></code></a> method aliases:</p>
  1835. <table class="docutils align-default">
  1836. <thead>
  1837. <tr class="row-odd"><th class="head"><p>Deprecated alias</p></th>
  1838. <th class="head"><p>Method Name</p></th>
  1839. <th class="head"><p>Deprecated in</p></th>
  1840. </tr>
  1841. </thead>
  1842. <tbody>
  1843. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">failUnless</span></code></p></td>
  1844. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertTrue" title="unittest.TestCase.assertTrue"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertTrue()</span></code></a></p></td>
  1845. <td><p>3.1</p></td>
  1846. </tr>
  1847. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">failIf</span></code></p></td>
  1848. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertFalse" title="unittest.TestCase.assertFalse"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertFalse()</span></code></a></p></td>
  1849. <td><p>3.1</p></td>
  1850. </tr>
  1851. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">failUnlessEqual</span></code></p></td>
  1852. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertEqual" title="unittest.TestCase.assertEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertEqual()</span></code></a></p></td>
  1853. <td><p>3.1</p></td>
  1854. </tr>
  1855. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">failIfEqual</span></code></p></td>
  1856. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertNotEqual" title="unittest.TestCase.assertNotEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertNotEqual()</span></code></a></p></td>
  1857. <td><p>3.1</p></td>
  1858. </tr>
  1859. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">failUnlessAlmostEqual</span></code></p></td>
  1860. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertAlmostEqual" title="unittest.TestCase.assertAlmostEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertAlmostEqual()</span></code></a></p></td>
  1861. <td><p>3.1</p></td>
  1862. </tr>
  1863. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">failIfAlmostEqual</span></code></p></td>
  1864. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertNotAlmostEqual" title="unittest.TestCase.assertNotAlmostEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertNotAlmostEqual()</span></code></a></p></td>
  1865. <td><p>3.1</p></td>
  1866. </tr>
  1867. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">failUnlessRaises</span></code></p></td>
  1868. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertRaises" title="unittest.TestCase.assertRaises"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertRaises()</span></code></a></p></td>
  1869. <td><p>3.1</p></td>
  1870. </tr>
  1871. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">assert_</span></code></p></td>
  1872. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertTrue" title="unittest.TestCase.assertTrue"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertTrue()</span></code></a></p></td>
  1873. <td><p>3.2</p></td>
  1874. </tr>
  1875. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">assertEquals</span></code></p></td>
  1876. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertEqual" title="unittest.TestCase.assertEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertEqual()</span></code></a></p></td>
  1877. <td><p>3.2</p></td>
  1878. </tr>
  1879. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">assertNotEquals</span></code></p></td>
  1880. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertNotEqual" title="unittest.TestCase.assertNotEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertNotEqual()</span></code></a></p></td>
  1881. <td><p>3.2</p></td>
  1882. </tr>
  1883. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">assertAlmostEquals</span></code></p></td>
  1884. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertAlmostEqual" title="unittest.TestCase.assertAlmostEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertAlmostEqual()</span></code></a></p></td>
  1885. <td><p>3.2</p></td>
  1886. </tr>
  1887. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">assertNotAlmostEquals</span></code></p></td>
  1888. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertNotAlmostEqual" title="unittest.TestCase.assertNotAlmostEqual"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertNotAlmostEqual()</span></code></a></p></td>
  1889. <td><p>3.2</p></td>
  1890. </tr>
  1891. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">assertRegexpMatches</span></code></p></td>
  1892. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertRegex" title="unittest.TestCase.assertRegex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertRegex()</span></code></a></p></td>
  1893. <td><p>3.2</p></td>
  1894. </tr>
  1895. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">assertRaisesRegexp</span></code></p></td>
  1896. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertRaisesRegex" title="unittest.TestCase.assertRaisesRegex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertRaisesRegex()</span></code></a></p></td>
  1897. <td><p>3.2</p></td>
  1898. </tr>
  1899. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">assertNotRegexpMatches</span></code></p></td>
  1900. <td><p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertNotRegex" title="unittest.TestCase.assertNotRegex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertNotRegex()</span></code></a></p></td>
  1901. <td><p>3.5</p></td>
  1902. </tr>
  1903. </tbody>
  1904. </table>
  1905. <p>You can use <a class="reference external" href="https://github.com/isidentical/teyit">https://github.com/isidentical/teyit</a> to automatically modernise
  1906. your unit tests.</p>
  1907. </li>
  1908. <li><p>Undocumented and broken <a class="reference internal" href="../library/unittest.html#unittest.TestCase" title="unittest.TestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestCase</span></code></a> method
  1909. <code class="docutils literal notranslate"><span class="pre">assertDictContainsSubset</span></code> (deprecated in Python 3.2).</p></li>
  1910. <li><p>Undocumented <a class="reference internal" href="../library/unittest.html#unittest.TestLoader.loadTestsFromModule" title="unittest.TestLoader.loadTestsFromModule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TestLoader.loadTestsFromModule</span></code></a> parameter <em>use_load_tests</em>
  1911. (deprecated and ignored since Python 3.2).</p></li>
  1912. <li><p>An alias of the <a class="reference internal" href="../library/unittest.html#unittest.TextTestResult" title="unittest.TextTestResult"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextTestResult</span></code></a> class:
  1913. <code class="docutils literal notranslate"><span class="pre">_TextTestResult</span></code> (deprecated in Python 3.2).</p></li>
  1914. </ul>
  1915. <p>(Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/89325">gh-89325</a>.)</p>
  1916. </li>
  1917. </ul>
  1918. </section>
  1919. <section id="webbrowser">
  1920. <h3>webbrowser<a class="headerlink" href="#webbrowser" title="Link to this heading">¶</a></h3>
  1921. <ul class="simple">
  1922. <li><p>Remove support for obsolete browsers from <a class="reference internal" href="../library/webbrowser.html#module-webbrowser" title="webbrowser: Easy-to-use controller for web browsers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code></a>.
  1923. The removed browsers include: Grail, Mosaic, Netscape, Galeon, Skipstone,
  1924. Iceape, Firebird, and Firefox versions 35 and below (<a class="reference external" href="https://github.com/python/cpython/issues/102871">gh-102871</a>).</p></li>
  1925. </ul>
  1926. </section>
  1927. <section id="xml-etree-elementtree">
  1928. <h3>xml.etree.ElementTree<a class="headerlink" href="#xml-etree-elementtree" title="Link to this heading">¶</a></h3>
  1929. <ul class="simple">
  1930. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">ElementTree.Element.copy()</span></code> method of the
  1931. pure Python implementation, deprecated in Python 3.10, use the
  1932. <a class="reference internal" href="../library/copy.html#copy.copy" title="copy.copy"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy.copy()</span></code></a> function instead. The C implementation of <a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code></a>
  1933. has no <code class="docutils literal notranslate"><span class="pre">copy()</span></code> method, only a <code class="docutils literal notranslate"><span class="pre">__copy__()</span></code> method.
  1934. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94383">gh-94383</a>.)</p></li>
  1935. </ul>
  1936. </section>
  1937. <section id="zipimport">
  1938. <h3>zipimport<a class="headerlink" href="#zipimport" title="Link to this heading">¶</a></h3>
  1939. <ul class="simple">
  1940. <li><p>Remove <a class="reference internal" href="../library/zipimport.html#module-zipimport" title="zipimport: Support for importing Python modules from ZIP archives."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipimport</span></code></a>’s <code class="docutils literal notranslate"><span class="pre">find_loader()</span></code> and <code class="docutils literal notranslate"><span class="pre">find_module()</span></code> methods,
  1941. deprecated in Python 3.10: use the <code class="docutils literal notranslate"><span class="pre">find_spec()</span></code> method instead. See
  1942. <span class="target" id="index-36"></span><a class="pep reference external" href="https://peps.python.org/pep-0451/"><strong>PEP 451</strong></a> for the rationale.
  1943. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94379">gh-94379</a>.)</p></li>
  1944. </ul>
  1945. </section>
  1946. <section id="others">
  1947. <h3>Others<a class="headerlink" href="#others" title="Link to this heading">¶</a></h3>
  1948. <ul class="simple">
  1949. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">suspicious</span></code> rule from the documentation <code class="file docutils literal notranslate"><span class="pre">Makefile</span></code> and
  1950. <code class="file docutils literal notranslate"><span class="pre">Doc/tools/rstlint.py</span></code>, both in favor of <a class="reference external" href="https://github.com/sphinx-contrib/sphinx-lint">sphinx-lint</a>.
  1951. (Contributed by Julien Palard in <a class="reference external" href="https://github.com/python/cpython/issues/98179">gh-98179</a>.)</p></li>
  1952. <li><p>Remove the <em>keyfile</em> and <em>certfile</em> parameters from the
  1953. <a class="reference internal" href="../library/ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a>, <a class="reference internal" href="../library/imaplib.html#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a>, <a class="reference internal" href="../library/poplib.html#module-poplib" title="poplib: POP3 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code></a> and <a class="reference internal" href="../library/smtplib.html#module-smtplib" title="smtplib: SMTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtplib</span></code></a> modules,
  1954. and the <em>key_file</em>, <em>cert_file</em> and <em>check_hostname</em> parameters from the
  1955. <a class="reference internal" href="../library/http.client.html#module-http.client" title="http.client: HTTP and HTTPS protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.client</span></code></a> module,
  1956. all deprecated since Python 3.6. Use the <em>context</em> parameter
  1957. (<em>ssl_context</em> in <a class="reference internal" href="../library/imaplib.html#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a>) instead.
  1958. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94172">gh-94172</a>.)</p></li>
  1959. <li><p>Remove <code class="docutils literal notranslate"><span class="pre">Jython</span></code> compatibility hacks from several stdlib modules and tests.
  1960. (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/99482">gh-99482</a>.)</p></li>
  1961. <li><p>Remove <code class="docutils literal notranslate"><span class="pre">_use_broken_old_ctypes_structure_semantics_</span></code> flag
  1962. from <a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a> module.
  1963. (Contributed by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/99285">gh-99285</a>.)</p></li>
  1964. </ul>
  1965. </section>
  1966. </section>
  1967. <section id="porting-to-python-3-12">
  1968. <span id="whatsnew312-porting-to-python312"></span><h2>Porting to Python 3.12<a class="headerlink" href="#porting-to-python-3-12" title="Link to this heading">¶</a></h2>
  1969. <p>This section lists previously described changes and other bugfixes
  1970. that may require changes to your code.</p>
  1971. <section id="changes-in-the-python-api">
  1972. <h3>Changes in the Python API<a class="headerlink" href="#changes-in-the-python-api" title="Link to this heading">¶</a></h3>
  1973. <ul>
  1974. <li><p>More strict rules are now applied for numerical group references and
  1975. group names in regular expressions.
  1976. Only sequence of ASCII digits is now accepted as a numerical reference.
  1977. The group name in bytes patterns and replacement strings can now only
  1978. contain ASCII letters and digits and underscore.
  1979. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/91760">gh-91760</a>.)</p></li>
  1980. <li><p>Remove <code class="docutils literal notranslate"><span class="pre">randrange()</span></code> functionality deprecated since Python 3.10. Formerly,
  1981. <code class="docutils literal notranslate"><span class="pre">randrange(10.0)</span></code> losslessly converted to <code class="docutils literal notranslate"><span class="pre">randrange(10)</span></code>. Now, it raises a
  1982. <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>. Also, the exception raised for non-integer values such as
  1983. <code class="docutils literal notranslate"><span class="pre">randrange(10.5)</span></code> or <code class="docutils literal notranslate"><span class="pre">randrange('10')</span></code> has been changed from <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> to
  1984. <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>. This also prevents bugs where <code class="docutils literal notranslate"><span class="pre">randrange(1e25)</span></code> would silently
  1985. select from a larger range than <code class="docutils literal notranslate"><span class="pre">randrange(10**25)</span></code>.
  1986. (Originally suggested by Serhiy Storchaka <a class="reference external" href="https://github.com/python/cpython/issues/86388">gh-86388</a>.)</p></li>
  1987. <li><p><a class="reference internal" href="../library/argparse.html#argparse.ArgumentParser" title="argparse.ArgumentParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">argparse.ArgumentParser</span></code></a> changed encoding and error handler
  1988. for reading arguments from file (e.g. <code class="docutils literal notranslate"><span class="pre">fromfile_prefix_chars</span></code> option)
  1989. from default text encoding (e.g. <a class="reference internal" href="../library/locale.html#locale.getpreferredencoding" title="locale.getpreferredencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getpreferredencoding(False)</span></code></a>)
  1990. to <a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">filesystem encoding and error handler</span></a>.
  1991. Argument files should be encoded in UTF-8 instead of ANSI Codepage on Windows.</p></li>
  1992. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">asyncore</span></code>-based <code class="docutils literal notranslate"><span class="pre">smtpd</span></code> module deprecated in Python 3.4.7
  1993. and 3.5.4. A recommended replacement is the
  1994. <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>-based <a class="reference external" href="https://pypi.org/project/aiosmtpd/">aiosmtpd</a> PyPI module.</p></li>
  1995. <li><p><a class="reference internal" href="../library/shlex.html#shlex.split" title="shlex.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">shlex.split()</span></code></a>: Passing <code class="docutils literal notranslate"><span class="pre">None</span></code> for <em>s</em> argument now raises an
  1996. exception, rather than reading <a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a>. The feature was deprecated
  1997. in Python 3.9.
  1998. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/94352">gh-94352</a>.)</p></li>
  1999. <li><p>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 no longer accepts bytes-like paths, like
  2000. <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-class docutils literal notranslate"><span class="pre">memoryview</span></code></a> types: only the exact
  2001. <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> type is accepted for bytes strings.
  2002. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/98393">gh-98393</a>.)</p></li>
  2003. <li><p><a class="reference internal" href="../library/syslog.html#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog.openlog()</span></code></a> and <a class="reference internal" href="../library/syslog.html#syslog.closelog" title="syslog.closelog"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog.closelog()</span></code></a> now fail if used in subinterpreters.
  2004. <a class="reference internal" href="../library/syslog.html#syslog.syslog" title="syslog.syslog"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog.syslog()</span></code></a> may still be used in subinterpreters,
  2005. but now only if <a class="reference internal" href="../library/syslog.html#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog.openlog()</span></code></a> has already been called in the main interpreter.
  2006. These new restrictions do not apply to the main interpreter,
  2007. so only a very small set of users might be affected.
  2008. This change helps with interpreter isolation. Furthermore, <a class="reference internal" href="../library/syslog.html#module-syslog" title="syslog: An interface to the Unix syslog library routines. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">syslog</span></code></a> is a wrapper
  2009. around process-global resources, which are best managed from the main interpreter.
  2010. (Contributed by Donghee Na in <a class="reference external" href="https://github.com/python/cpython/issues/99127">gh-99127</a>.)</p></li>
  2011. <li><p>The undocumented locking behavior of <a class="reference internal" href="../library/functools.html#functools.cached_property" title="functools.cached_property"><code class="xref py py-func docutils literal notranslate"><span class="pre">cached_property()</span></code></a>
  2012. is removed, because it locked across all instances of the class, leading to high
  2013. lock contention. This means that a cached property getter function could now run
  2014. more than once for a single instance, if two threads race. For most simple
  2015. cached properties (e.g. those that are idempotent and simply calculate a value
  2016. based on other attributes of the instance) this will be fine. If
  2017. synchronization is needed, implement locking within the cached property getter
  2018. function or around multi-threaded access points.</p></li>
  2019. <li><p><a class="reference internal" href="../library/sys.html#sys._current_exceptions" title="sys._current_exceptions"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys._current_exceptions()</span></code></a> now returns a mapping from thread-id to an
  2020. exception instance, rather than to a <code class="docutils literal notranslate"><span class="pre">(typ,</span> <span class="pre">exc,</span> <span class="pre">tb)</span></code> tuple.
  2021. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/103176">gh-103176</a>.)</p></li>
  2022. <li><p>When extracting tar files using <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> or
  2023. <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>, pass the <em>filter</em> argument to limit features
  2024. that may be surprising or dangerous.
  2025. See <a class="reference internal" href="../library/tarfile.html#tarfile-extraction-filter"><span class="std std-ref">Extraction filters</span></a> for details.</p></li>
  2026. <li><p>The output of the <a class="reference internal" href="../library/tokenize.html#tokenize.tokenize" title="tokenize.tokenize"><code class="xref py py-func docutils literal notranslate"><span class="pre">tokenize.tokenize()</span></code></a> and <a class="reference internal" href="../library/tokenize.html#tokenize.generate_tokens" title="tokenize.generate_tokens"><code class="xref py py-func docutils literal notranslate"><span class="pre">tokenize.generate_tokens()</span></code></a>
  2027. functions is now changed due to the changes introduced in <span class="target" id="index-37"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a>. This
  2028. means that <code class="docutils literal notranslate"><span class="pre">STRING</span></code> tokens are not emitted any more for f-strings and the
  2029. tokens described in <span class="target" id="index-38"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a> are now produced instead: <code class="docutils literal notranslate"><span class="pre">FSTRING_START</span></code>,
  2030. <code class="docutils literal notranslate"><span class="pre">FSTRING_MIDDLE</span></code> and <code class="docutils literal notranslate"><span class="pre">FSTRING_END</span></code> are now emitted for f-string “string”
  2031. parts in addition to the appropriate tokens for the tokenization in the
  2032. expression components. For example for the f-string <code class="docutils literal notranslate"><span class="pre">f&quot;start</span> <span class="pre">{1+1}</span> <span class="pre">end&quot;</span></code>
  2033. the old version of the tokenizer emitted:</p>
  2034. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">18</span><span class="p">:</span> <span class="n">STRING</span> <span class="s1">&#39;f&quot;start {1+1} end&quot;&#39;</span>
  2035. </pre></div>
  2036. </div>
  2037. <p>while the new version emits:</p>
  2038. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">:</span> <span class="n">FSTRING_START</span> <span class="s1">&#39;f&quot;&#39;</span>
  2039. <span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">8</span><span class="p">:</span> <span class="n">FSTRING_MIDDLE</span> <span class="s1">&#39;start &#39;</span>
  2040. <span class="mi">1</span><span class="p">,</span><span class="mi">8</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">9</span><span class="p">:</span> <span class="n">OP</span> <span class="s1">&#39;{&#39;</span>
  2041. <span class="mi">1</span><span class="p">,</span><span class="mi">9</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">10</span><span class="p">:</span> <span class="n">NUMBER</span> <span class="s1">&#39;1&#39;</span>
  2042. <span class="mi">1</span><span class="p">,</span><span class="mi">10</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">11</span><span class="p">:</span> <span class="n">OP</span> <span class="s1">&#39;+&#39;</span>
  2043. <span class="mi">1</span><span class="p">,</span><span class="mi">11</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">12</span><span class="p">:</span> <span class="n">NUMBER</span> <span class="s1">&#39;1&#39;</span>
  2044. <span class="mi">1</span><span class="p">,</span><span class="mi">12</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">13</span><span class="p">:</span> <span class="n">OP</span> <span class="s1">&#39;}&#39;</span>
  2045. <span class="mi">1</span><span class="p">,</span><span class="mi">13</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">17</span><span class="p">:</span> <span class="n">FSTRING_MIDDLE</span> <span class="s1">&#39; end&#39;</span>
  2046. <span class="mi">1</span><span class="p">,</span><span class="mi">17</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">18</span><span class="p">:</span> <span class="n">FSTRING_END</span> <span class="s1">&#39;&quot;&#39;</span>
  2047. </pre></div>
  2048. </div>
  2049. <p>Additionally, there may be some minor behavioral changes as a consequence of the
  2050. changes required to support <span class="target" id="index-39"></span><a class="pep reference external" href="https://peps.python.org/pep-0701/"><strong>PEP 701</strong></a>. Some of these changes include:</p>
  2051. <ul class="simple">
  2052. <li><p>The <code class="docutils literal notranslate"><span class="pre">type</span></code> attribute of the tokens emitted when tokenizing some invalid Python
  2053. characters such as <code class="docutils literal notranslate"><span class="pre">!</span></code> has changed from <code class="docutils literal notranslate"><span class="pre">ERRORTOKEN</span></code> to <code class="docutils literal notranslate"><span class="pre">OP</span></code>.</p></li>
  2054. <li><p>Incomplete single-line strings now also raise <a class="reference internal" href="../library/tokenize.html#tokenize.TokenError" title="tokenize.TokenError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">tokenize.TokenError</span></code></a> as incomplete
  2055. multiline strings do.</p></li>
  2056. <li><p>Some incomplete or invalid Python code now raises <a class="reference internal" href="../library/tokenize.html#tokenize.TokenError" title="tokenize.TokenError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">tokenize.TokenError</span></code></a> instead of
  2057. returning arbitrary <code class="docutils literal notranslate"><span class="pre">ERRORTOKEN</span></code> tokens when tokenizing it.</p></li>
  2058. <li><p>Mixing tabs and spaces as indentation in the same file is not supported anymore and will
  2059. raise a <a class="reference internal" href="../library/exceptions.html#TabError" title="TabError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TabError</span></code></a>.</p></li>
  2060. </ul>
  2061. </li>
  2062. <li><p>The <a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a> module now expects the <code class="xref py py-mod docutils literal notranslate"><span class="pre">_thread</span></code> module to have
  2063. an <code class="docutils literal notranslate"><span class="pre">_is_main_interpreter</span></code> attribute. It is a function with no
  2064. arguments that returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if the current interpreter is the
  2065. main interpreter.</p>
  2066. <p>Any library or application that provides a custom <code class="docutils literal notranslate"><span class="pre">_thread</span></code> module
  2067. should provide <code class="docutils literal notranslate"><span class="pre">_is_main_interpreter()</span></code>.
  2068. (See <a class="reference external" href="https://github.com/python/cpython/issues/112826">gh-112826</a>.)</p>
  2069. </li>
  2070. </ul>
  2071. </section>
  2072. </section>
  2073. <section id="build-changes">
  2074. <h2>Build Changes<a class="headerlink" href="#build-changes" title="Link to this heading">¶</a></h2>
  2075. <ul>
  2076. <li><p>Python no longer uses <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> to build shared C extension modules.
  2077. Build parameters like headers and libraries are detected in <code class="docutils literal notranslate"><span class="pre">configure</span></code>
  2078. script. Extensions are built by <code class="file docutils literal notranslate"><span class="pre">Makefile</span></code>. Most extensions use
  2079. <code class="docutils literal notranslate"><span class="pre">pkg-config</span></code> and fall back to manual detection.
  2080. (Contributed by Christian Heimes in <a class="reference external" href="https://github.com/python/cpython/issues/93939">gh-93939</a>.)</p></li>
  2081. <li><p><code class="docutils literal notranslate"><span class="pre">va_start()</span></code> with two parameters, like <code class="docutils literal notranslate"><span class="pre">va_start(args,</span> <span class="pre">format),</span></code>
  2082. is now required to build Python.
  2083. <code class="docutils literal notranslate"><span class="pre">va_start()</span></code> is no longer called with a single parameter.
  2084. (Contributed by Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/93207">gh-93207</a>.)</p></li>
  2085. <li><p>CPython now uses the ThinLTO option as the default link time optimization policy
  2086. if the Clang compiler accepts the flag.
  2087. (Contributed by Donghee Na in <a class="reference external" href="https://github.com/python/cpython/issues/89536">gh-89536</a>.)</p></li>
  2088. <li><p>Add <code class="docutils literal notranslate"><span class="pre">COMPILEALL_OPTS</span></code> variable in <code class="file docutils literal notranslate"><span class="pre">Makefile</span></code> to override <a class="reference internal" href="../library/compileall.html#module-compileall" title="compileall: Tools for byte-compiling all Python source files in a directory tree."><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code></a>
  2089. options (default: <code class="docutils literal notranslate"><span class="pre">-j0</span></code>) in <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">install</span></code>. Also merged the 3
  2090. <code class="docutils literal notranslate"><span class="pre">compileall</span></code> commands into a single command to build .pyc files for all
  2091. optimization levels (0, 1, 2) at once.
  2092. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/99289">gh-99289</a>.)</p></li>
  2093. <li><p>Add platform triplets for 64-bit LoongArch:</p>
  2094. <ul class="simple">
  2095. <li><p>loongarch64-linux-gnusf</p></li>
  2096. <li><p>loongarch64-linux-gnuf32</p></li>
  2097. <li><p>loongarch64-linux-gnu</p></li>
  2098. </ul>
  2099. <p>(Contributed by Zhang Na in <a class="reference external" href="https://github.com/python/cpython/issues/90656">gh-90656</a>.)</p>
  2100. </li>
  2101. <li><p><code class="docutils literal notranslate"><span class="pre">PYTHON_FOR_REGEN</span></code> now require Python 3.10 or newer.</p></li>
  2102. <li><p>Autoconf 2.71 and aclocal 1.16.4 is now required to regenerate
  2103. <code class="file docutils literal notranslate"><span class="pre">!configure</span></code>.
  2104. (Contributed by Christian Heimes in <a class="reference external" href="https://github.com/python/cpython/issues/89886">gh-89886</a>.)</p></li>
  2105. <li><p>Windows builds and macOS installers from python.org now use OpenSSL 3.0.</p></li>
  2106. </ul>
  2107. </section>
  2108. <section id="c-api-changes">
  2109. <h2>C API Changes<a class="headerlink" href="#c-api-changes" title="Link to this heading">¶</a></h2>
  2110. <section id="id4">
  2111. <h3>New Features<a class="headerlink" href="#id4" title="Link to this heading">¶</a></h3>
  2112. <ul id="whatsnew312-pep697">
  2113. <li><p><span class="target" id="index-40"></span><a class="pep reference external" href="https://peps.python.org/pep-0697/"><strong>PEP 697</strong></a>: Introduce the <a class="reference internal" href="../c-api/stable.html#unstable-c-api"><span class="std std-ref">Unstable C API tier</span></a>,
  2114. intended for low-level tools like debuggers and JIT compilers.
  2115. This API may change in each minor release of CPython without deprecation
  2116. warnings.
  2117. Its contents are marked by the <code class="docutils literal notranslate"><span class="pre">PyUnstable_</span></code> prefix in names.</p>
  2118. <p>Code object constructors:</p>
  2119. <ul class="simple">
  2120. <li><p><code class="docutils literal notranslate"><span class="pre">PyUnstable_Code_New()</span></code> (renamed from <code class="docutils literal notranslate"><span class="pre">PyCode_New</span></code>)</p></li>
  2121. <li><p><code class="docutils literal notranslate"><span class="pre">PyUnstable_Code_NewWithPosOnlyArgs()</span></code> (renamed from <code class="docutils literal notranslate"><span class="pre">PyCode_NewWithPosOnlyArgs</span></code>)</p></li>
  2122. </ul>
  2123. <p>Extra storage for code objects (<span class="target" id="index-41"></span><a class="pep reference external" href="https://peps.python.org/pep-0523/"><strong>PEP 523</strong></a>):</p>
  2124. <ul class="simple">
  2125. <li><p><code class="docutils literal notranslate"><span class="pre">PyUnstable_Eval_RequestCodeExtraIndex()</span></code> (renamed from <code class="docutils literal notranslate"><span class="pre">_PyEval_RequestCodeExtraIndex</span></code>)</p></li>
  2126. <li><p><code class="docutils literal notranslate"><span class="pre">PyUnstable_Code_GetExtra()</span></code> (renamed from <code class="docutils literal notranslate"><span class="pre">_PyCode_GetExtra</span></code>)</p></li>
  2127. <li><p><code class="docutils literal notranslate"><span class="pre">PyUnstable_Code_SetExtra()</span></code> (renamed from <code class="docutils literal notranslate"><span class="pre">_PyCode_SetExtra</span></code>)</p></li>
  2128. </ul>
  2129. <p>The original names will continue to be available until the respective
  2130. API changes.</p>
  2131. <p>(Contributed by Petr Viktorin in <a class="reference external" href="https://github.com/python/cpython/issues/101101">gh-101101</a>.)</p>
  2132. </li>
  2133. <li><p><span class="target" id="index-42"></span><a class="pep reference external" href="https://peps.python.org/pep-0697/"><strong>PEP 697</strong></a>: Add an API for extending types whose instance memory layout is
  2134. opaque:</p>
  2135. <ul class="simple">
  2136. <li><p><a class="reference internal" href="../c-api/type.html#c.PyType_Spec.basicsize" title="PyType_Spec.basicsize"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyType_Spec.basicsize</span></code></a> can be zero or negative to specify
  2137. inheriting or extending the base class size.</p></li>
  2138. <li><p><a class="reference internal" href="../c-api/object.html#c.PyObject_GetTypeData" title="PyObject_GetTypeData"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetTypeData()</span></code></a> and <a class="reference internal" href="../c-api/object.html#c.PyType_GetTypeDataSize" title="PyType_GetTypeDataSize"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetTypeDataSize()</span></code></a>
  2139. added to allow access to subclass-specific instance data.</p></li>
  2140. <li><p><a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_ITEMS_AT_END" title="Py_TPFLAGS_ITEMS_AT_END"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_ITEMS_AT_END</span></code></a> and <a class="reference internal" href="../c-api/object.html#c.PyObject_GetItemData" title="PyObject_GetItemData"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetItemData()</span></code></a>
  2141. added to allow safely extending certain variable-sized types, including
  2142. <a class="reference internal" href="../c-api/type.html#c.PyType_Type" title="PyType_Type"><code class="xref c c-var docutils literal notranslate"><span class="pre">PyType_Type</span></code></a>.</p></li>
  2143. <li><p><a class="reference internal" href="../c-api/structures.html#c.Py_RELATIVE_OFFSET" title="Py_RELATIVE_OFFSET"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_RELATIVE_OFFSET</span></code></a> added to allow defining
  2144. <a class="reference internal" href="../c-api/structures.html#c.PyMemberDef" title="PyMemberDef"><code class="xref c c-type docutils literal notranslate"><span class="pre">members</span></code></a> in terms of a subclass-specific struct.</p></li>
  2145. </ul>
  2146. <p>(Contributed by Petr Viktorin in <a class="reference external" href="https://github.com/python/cpython/issues/103509">gh-103509</a>.)</p>
  2147. </li>
  2148. <li><p>Add the new <a class="reference internal" href="../c-api/stable.html#limited-c-api"><span class="std std-ref">limited C API</span></a> function <a class="reference internal" href="../c-api/type.html#c.PyType_FromMetaclass" title="PyType_FromMetaclass"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromMetaclass()</span></code></a>,
  2149. which generalizes the existing <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> using
  2150. an additional metaclass argument.
  2151. (Contributed by Wenzel Jakob in <a class="reference external" href="https://github.com/python/cpython/issues/93012">gh-93012</a>.)</p></li>
  2152. <li><p>API for creating objects that can be called using
  2153. <a class="reference internal" href="../c-api/call.html#vectorcall"><span class="std std-ref">the vectorcall protocol</span></a> was added to the
  2154. <a class="reference internal" href="../c-api/stable.html#stable"><span class="std std-ref">Limited API</span></a>:</p>
  2155. <ul class="simple">
  2156. <li><p><a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_HAVE_VECTORCALL" title="Py_TPFLAGS_HAVE_VECTORCALL"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_HAVE_VECTORCALL</span></code></a></p></li>
  2157. <li><p><a class="reference internal" href="../c-api/call.html#c.PyVectorcall_NARGS" title="PyVectorcall_NARGS"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyVectorcall_NARGS()</span></code></a></p></li>
  2158. <li><p><a class="reference internal" href="../c-api/call.html#c.PyVectorcall_Call" title="PyVectorcall_Call"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyVectorcall_Call()</span></code></a></p></li>
  2159. <li><p><a class="reference internal" href="../c-api/call.html#c.vectorcallfunc" title="vectorcallfunc"><code class="xref c c-type docutils literal notranslate"><span class="pre">vectorcallfunc</span></code></a></p></li>
  2160. </ul>
  2161. <p>The <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_HAVE_VECTORCALL" title="Py_TPFLAGS_HAVE_VECTORCALL"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_HAVE_VECTORCALL</span></code></a> flag is now removed from a class
  2162. when the class’s <a class="reference internal" href="../reference/datamodel.html#object.__call__" title="object.__call__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__call__()</span></code></a> method is reassigned.
  2163. This makes vectorcall safe to use with mutable types (i.e. heap types
  2164. without the immutable flag, <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>).
  2165. Mutable types that do not override <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_call" title="PyTypeObject.tp_call"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_call</span></code></a> now
  2166. inherit the <code class="docutils literal notranslate"><span class="pre">Py_TPFLAGS_HAVE_VECTORCALL</span></code> flag.
  2167. (Contributed by Petr Viktorin in <a class="reference external" href="https://github.com/python/cpython/issues/93274">gh-93274</a>.)</p>
  2168. <p>The <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_MANAGED_DICT" title="Py_TPFLAGS_MANAGED_DICT"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_MANAGED_DICT</span></code></a> and <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_MANAGED_WEAKREF" title="Py_TPFLAGS_MANAGED_WEAKREF"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_MANAGED_WEAKREF</span></code></a>
  2169. flags have been added. This allows extensions classes to support object
  2170. <code class="docutils literal notranslate"><span class="pre">__dict__</span></code> and weakrefs with less bookkeeping,
  2171. using less memory and with faster access.</p>
  2172. </li>
  2173. <li><p>API for performing calls using
  2174. <a class="reference internal" href="../c-api/call.html#vectorcall"><span class="std std-ref">the vectorcall protocol</span></a> was added to the
  2175. <a class="reference internal" href="../c-api/stable.html#stable"><span class="std std-ref">Limited API</span></a>:</p>
  2176. <ul class="simple">
  2177. <li><p><a class="reference internal" href="../c-api/call.html#c.PyObject_Vectorcall" title="PyObject_Vectorcall"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Vectorcall()</span></code></a></p></li>
  2178. <li><p><a class="reference internal" href="../c-api/call.html#c.PyObject_VectorcallMethod" title="PyObject_VectorcallMethod"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_VectorcallMethod()</span></code></a></p></li>
  2179. <li><p><a class="reference internal" href="../c-api/call.html#c.PY_VECTORCALL_ARGUMENTS_OFFSET" title="PY_VECTORCALL_ARGUMENTS_OFFSET"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PY_VECTORCALL_ARGUMENTS_OFFSET</span></code></a></p></li>
  2180. </ul>
  2181. <p>This means that both the incoming and outgoing ends of the vector call
  2182. protocol are now available in the <a class="reference internal" href="../c-api/stable.html#stable"><span class="std std-ref">Limited API</span></a>. (Contributed
  2183. by Wenzel Jakob in <a class="reference external" href="https://github.com/python/cpython/issues/98586">gh-98586</a>.)</p>
  2184. </li>
  2185. <li><p>Add two new public functions,
  2186. <a class="reference internal" href="../c-api/init.html#c.PyEval_SetProfileAllThreads" title="PyEval_SetProfileAllThreads"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_SetProfileAllThreads()</span></code></a> and
  2187. <a class="reference internal" href="../c-api/init.html#c.PyEval_SetTraceAllThreads" title="PyEval_SetTraceAllThreads"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_SetTraceAllThreads()</span></code></a>, that allow to set tracing and profiling
  2188. functions in all running threads in addition to the calling one. (Contributed
  2189. by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/93503">gh-93503</a>.)</p></li>
  2190. <li><p>Add new function <a class="reference internal" href="../c-api/function.html#c.PyFunction_SetVectorcall" title="PyFunction_SetVectorcall"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFunction_SetVectorcall()</span></code></a> to the C API
  2191. which sets the vectorcall field of a given <a class="reference internal" href="../c-api/function.html#c.PyFunctionObject" title="PyFunctionObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyFunctionObject</span></code></a>.
  2192. (Contributed by Andrew Frost in <a class="reference external" href="https://github.com/python/cpython/issues/92257">gh-92257</a>.)</p></li>
  2193. <li><p>The C API now permits registering callbacks via <a class="reference internal" href="../c-api/dict.html#c.PyDict_AddWatcher" title="PyDict_AddWatcher"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_AddWatcher()</span></code></a>,
  2194. <a class="reference internal" href="../c-api/dict.html#c.PyDict_Watch" title="PyDict_Watch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyDict_Watch()</span></code></a> and related APIs to be called whenever a dictionary
  2195. is modified. This is intended for use by optimizing interpreters, JIT
  2196. compilers, or debuggers.
  2197. (Contributed by Carl Meyer in <a class="reference external" href="https://github.com/python/cpython/issues/91052">gh-91052</a>.)</p></li>
  2198. <li><p>Add <a class="reference internal" href="../c-api/type.html#c.PyType_AddWatcher" title="PyType_AddWatcher"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_AddWatcher()</span></code></a> and <a class="reference internal" href="../c-api/type.html#c.PyType_Watch" title="PyType_Watch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_Watch()</span></code></a> API to register
  2199. callbacks to receive notification on changes to a type.
  2200. (Contributed by Carl Meyer in <a class="reference external" href="https://github.com/python/cpython/issues/91051">gh-91051</a>.)</p></li>
  2201. <li><p>Add <a class="reference internal" href="../c-api/code.html#c.PyCode_AddWatcher" title="PyCode_AddWatcher"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_AddWatcher()</span></code></a> and <a class="reference internal" href="../c-api/code.html#c.PyCode_ClearWatcher" title="PyCode_ClearWatcher"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_ClearWatcher()</span></code></a>
  2202. APIs to register callbacks to receive notification on creation and
  2203. destruction of code objects.
  2204. (Contributed by Itamar Oren in <a class="reference external" href="https://github.com/python/cpython/issues/91054">gh-91054</a>.)</p></li>
  2205. <li><p>Add <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetVar" title="PyFrame_GetVar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetVar()</span></code></a> and <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetVarString" title="PyFrame_GetVarString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetVarString()</span></code></a> functions to
  2206. get a frame variable by its name.
  2207. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/91248">gh-91248</a>.)</p></li>
  2208. <li><p>Add <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_GetRaisedException" title="PyErr_GetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetRaisedException()</span></code></a> and <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetRaisedException" title="PyErr_SetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetRaisedException()</span></code></a>
  2209. for saving and restoring the current exception.
  2210. These functions return and accept a single exception object,
  2211. rather than the triple arguments of the now-deprecated
  2212. <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Fetch" title="PyErr_Fetch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Fetch()</span></code></a> and <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Restore" title="PyErr_Restore"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Restore()</span></code></a>.
  2213. This is less error prone and a bit more efficient.
  2214. (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/101578">gh-101578</a>.)</p></li>
  2215. <li><p>Add <code class="docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions1</span></code>, which takes an exception instance,
  2216. to replace the legacy-API <code class="docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions</span></code>, which is now
  2217. deprecated. (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/101578">gh-101578</a>.)</p></li>
  2218. <li><p>Add <a class="reference internal" href="../c-api/exceptions.html#c.PyException_GetArgs" title="PyException_GetArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyException_GetArgs()</span></code></a> and <a class="reference internal" href="../c-api/exceptions.html#c.PyException_SetArgs" title="PyException_SetArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyException_SetArgs()</span></code></a>
  2219. as convenience functions for retrieving and modifying
  2220. the <a class="reference internal" href="../library/exceptions.html#BaseException.args" title="BaseException.args"><code class="xref py py-attr docutils literal notranslate"><span class="pre">args</span></code></a> passed to the exception’s constructor.
  2221. (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/101578">gh-101578</a>.)</p></li>
  2222. <li><p>Add <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_DisplayException" title="PyErr_DisplayException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_DisplayException()</span></code></a>, which takes an exception instance,
  2223. to replace the legacy-api <code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Display()</span></code>. (Contributed by
  2224. Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102755">gh-102755</a>).</p></li>
  2225. </ul>
  2226. <ul id="whatsnew312-pep683">
  2227. <li><p><span class="target" id="index-43"></span><a class="pep reference external" href="https://peps.python.org/pep-0683/"><strong>PEP 683</strong></a>: Introduce <em>Immortal Objects</em>, which allows objects
  2228. to bypass reference counts, and related changes to the C-API:</p>
  2229. <ul class="simple">
  2230. <li><dl class="simple">
  2231. <dt><code class="docutils literal notranslate"><span class="pre">_Py_IMMORTAL_REFCNT</span></code>: The reference count that defines an object</dt><dd><p>as immortal.</p>
  2232. </dd>
  2233. </dl>
  2234. </li>
  2235. <li><p><code class="docutils literal notranslate"><span class="pre">_Py_IsImmortal</span></code> Checks if an object has the immortal reference count.</p></li>
  2236. <li><dl class="simple">
  2237. <dt><code class="docutils literal notranslate"><span class="pre">PyObject_HEAD_INIT</span></code> This will now initialize reference count to</dt><dd><p><code class="docutils literal notranslate"><span class="pre">_Py_IMMORTAL_REFCNT</span></code> when used with <code class="docutils literal notranslate"><span class="pre">Py_BUILD_CORE</span></code>.</p>
  2238. </dd>
  2239. </dl>
  2240. </li>
  2241. <li><dl class="simple">
  2242. <dt><code class="docutils literal notranslate"><span class="pre">SSTATE_INTERNED_IMMORTAL</span></code> An identifier for interned unicode objects</dt><dd><p>that are immortal.</p>
  2243. </dd>
  2244. </dl>
  2245. </li>
  2246. <li><dl class="simple">
  2247. <dt><code class="docutils literal notranslate"><span class="pre">SSTATE_INTERNED_IMMORTAL_STATIC</span></code> An identifier for interned unicode</dt><dd><p>objects that are immortal and static</p>
  2248. </dd>
  2249. </dl>
  2250. </li>
  2251. <li><dl class="simple">
  2252. <dt><code class="docutils literal notranslate"><span class="pre">sys.getunicodeinternedsize</span></code> This returns the total number of unicode</dt><dd><p>objects that have been interned. This is now needed for <code class="file docutils literal notranslate"><span class="pre">refleak.py</span></code> to
  2253. correctly track reference counts and allocated blocks</p>
  2254. </dd>
  2255. </dl>
  2256. </li>
  2257. </ul>
  2258. <p>(Contributed by Eddie Elizondo in <a class="reference external" href="https://github.com/python/cpython/issues/84436">gh-84436</a>.)</p>
  2259. </li>
  2260. <li><p><span class="target" id="index-44"></span><a class="pep reference external" href="https://peps.python.org/pep-0684/"><strong>PEP 684</strong></a>: Add the new <a class="reference internal" href="../c-api/init.html#c.Py_NewInterpreterFromConfig" title="Py_NewInterpreterFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_NewInterpreterFromConfig()</span></code></a>
  2261. function and <a class="reference internal" href="../c-api/init.html#c.PyInterpreterConfig" title="PyInterpreterConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyInterpreterConfig</span></code></a>, which may be used
  2262. to create sub-interpreters with their own GILs.
  2263. (See <a class="reference internal" href="#whatsnew312-pep684"><span class="std std-ref">PEP 684: A Per-Interpreter GIL</span></a> for more info.)
  2264. (Contributed by Eric Snow in <a class="reference external" href="https://github.com/python/cpython/issues/104110">gh-104110</a>.)</p></li>
  2265. <li><p>In the limited C API version 3.12, <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
  2266. <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 as opaque function calls to
  2267. hide implementation details.
  2268. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/105387">gh-105387</a>.)</p></li>
  2269. </ul>
  2270. </section>
  2271. <section id="id5">
  2272. <h3>Porting to Python 3.12<a class="headerlink" href="#id5" title="Link to this heading">¶</a></h3>
  2273. <ul>
  2274. <li><p>Legacy Unicode APIs based on <code class="docutils literal notranslate"><span class="pre">Py_UNICODE*</span></code> representation has been removed.
  2275. Please migrate to APIs based on UTF-8 or <code class="docutils literal notranslate"><span class="pre">wchar_t*</span></code>.</p></li>
  2276. <li><p>Argument parsing functions like <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> doesn’t support
  2277. <code class="docutils literal notranslate"><span class="pre">Py_UNICODE*</span></code> based format (e.g. <code class="docutils literal notranslate"><span class="pre">u</span></code>, <code class="docutils literal notranslate"><span class="pre">Z</span></code>) anymore. Please migrate
  2278. to other formats for Unicode like <code class="docutils literal notranslate"><span class="pre">s</span></code>, <code class="docutils literal notranslate"><span class="pre">z</span></code>, <code class="docutils literal notranslate"><span class="pre">es</span></code>, and <code class="docutils literal notranslate"><span class="pre">U</span></code>.</p></li>
  2279. <li><p><code class="docutils literal notranslate"><span class="pre">tp_weaklist</span></code> for all static builtin types is always <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.
  2280. This is an internal-only field on <code class="docutils literal notranslate"><span class="pre">PyTypeObject</span></code>
  2281. but we’re pointing out the change in case someone happens to be
  2282. accessing the field directly anyway. To avoid breakage, consider
  2283. using the existing public C-API instead, or, if necessary, the
  2284. (internal-only) <code class="docutils literal notranslate"><span class="pre">_PyObject_GET_WEAKREFS_LISTPTR()</span></code> macro.</p></li>
  2285. <li><p>This internal-only <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_subclasses" title="PyTypeObject.tp_subclasses"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_subclasses</span></code></a> may now not be
  2286. a valid object pointer. Its type was changed to <span class="c-expr sig sig-inline c"><span class="kt">void</span><span class="p">*</span></span> to
  2287. reflect this. We mention this in case someone happens to be accessing the
  2288. internal-only field directly.</p>
  2289. <p>To get a list of subclasses, call the Python method
  2290. <a class="reference internal" href="../library/stdtypes.html#class.__subclasses__" title="class.__subclasses__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__subclasses__()</span></code></a> (using <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>,
  2291. for example).</p>
  2292. </li>
  2293. <li><p>Add support of more formatting options (left aligning, octals, uppercase
  2294. hexadecimals, <code class="xref c c-type docutils literal notranslate"><span class="pre">intmax_t</span></code>, <code class="xref c c-type docutils literal notranslate"><span class="pre">ptrdiff_t</span></code>, <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code> C
  2295. strings, variable width and precision) in <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a> and
  2296. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormatV" title="PyUnicode_FromFormatV"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormatV()</span></code></a>.
  2297. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/98836">gh-98836</a>.)</p></li>
  2298. <li><p>An unrecognized format character in <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a> and
  2299. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormatV" title="PyUnicode_FromFormatV"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormatV()</span></code></a> now sets a <a class="reference internal" href="../library/exceptions.html#SystemError" title="SystemError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemError</span></code></a>.
  2300. In previous versions it caused all the rest of the format string to be
  2301. copied as-is to the result string, and any extra arguments discarded.
  2302. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/95781">gh-95781</a>.)</p></li>
  2303. <li><p>Fix wrong sign placement in <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a> and
  2304. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormatV" title="PyUnicode_FromFormatV"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormatV()</span></code></a>.
  2305. (Contributed by Philip Georgi in <a class="reference external" href="https://github.com/python/cpython/issues/95504">gh-95504</a>.)</p></li>
  2306. <li><p>Extension classes wanting to add a <code class="docutils literal notranslate"><span class="pre">__dict__</span></code> or weak reference slot
  2307. should use <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_MANAGED_DICT" title="Py_TPFLAGS_MANAGED_DICT"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_MANAGED_DICT</span></code></a> and
  2308. <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_MANAGED_WEAKREF" title="Py_TPFLAGS_MANAGED_WEAKREF"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_MANAGED_WEAKREF</span></code></a> instead of <code class="docutils literal notranslate"><span class="pre">tp_dictoffset</span></code> and
  2309. <code class="docutils literal notranslate"><span class="pre">tp_weaklistoffset</span></code>, respectively.
  2310. The use of <code class="docutils literal notranslate"><span class="pre">tp_dictoffset</span></code> and <code class="docutils literal notranslate"><span class="pre">tp_weaklistoffset</span></code> is still
  2311. supported, but does not fully support multiple inheritance
  2312. (<a class="reference external" href="https://github.com/python/cpython/issues/95589">gh-95589</a>), and performance may be worse.
  2313. Classes declaring <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_MANAGED_DICT" title="Py_TPFLAGS_MANAGED_DICT"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_MANAGED_DICT</span></code></a> should call
  2314. <code class="xref c c-func docutils literal notranslate"><span class="pre">_PyObject_VisitManagedDict()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">_PyObject_ClearManagedDict()</span></code>
  2315. to traverse and clear their instance’s dictionaries.
  2316. To clear weakrefs, call <a class="reference internal" href="../c-api/weakref.html#c.PyObject_ClearWeakRefs" title="PyObject_ClearWeakRefs"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_ClearWeakRefs()</span></code></a>, as before.</p></li>
  2317. <li><p>The <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FSDecoder" title="PyUnicode_FSDecoder"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FSDecoder()</span></code></a> function no longer accepts bytes-like
  2318. paths, like <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-class docutils literal notranslate"><span class="pre">memoryview</span></code></a> types: only the exact
  2319. <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> type is accepted for bytes strings.
  2320. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/98393">gh-98393</a>.)</p></li>
  2321. <li><p>The <a class="reference internal" href="../c-api/refcounting.html#c.Py_CLEAR" title="Py_CLEAR"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_CLEAR</span></code></a>, <a class="reference internal" href="../c-api/refcounting.html#c.Py_SETREF" title="Py_SETREF"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_SETREF</span></code></a> and <a class="reference internal" href="../c-api/refcounting.html#c.Py_XSETREF" title="Py_XSETREF"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_XSETREF</span></code></a>
  2322. macros now only evaluate their arguments once. If an argument has side
  2323. effects, these side effects are no longer duplicated.
  2324. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/98724">gh-98724</a>.)</p></li>
  2325. <li><p>The interpreter’s error indicator is now always normalized. This means
  2326. that <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetObject" title="PyErr_SetObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetObject()</span></code></a>, <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetString" title="PyErr_SetString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetString()</span></code></a> and the other
  2327. functions that set the error indicator now normalize the exception
  2328. before storing it. (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/101578">gh-101578</a>.)</p></li>
  2329. <li><p><code class="docutils literal notranslate"><span class="pre">_Py_RefTotal</span></code> is no longer authoritative and only kept around
  2330. for ABI compatibility. Note that it is an internal global and only
  2331. available on debug builds. If you happen to be using it then you’ll
  2332. need to start using <code class="docutils literal notranslate"><span class="pre">_Py_GetGlobalRefTotal()</span></code>.</p></li>
  2333. <li><p>The following functions now select an appropriate metaclass for the newly
  2334. created type:</p>
  2335. <ul class="simple">
  2336. <li><p><a class="reference internal" href="../c-api/type.html#c.PyType_FromSpec" title="PyType_FromSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromSpec()</span></code></a></p></li>
  2337. <li><p><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></p></li>
  2338. <li><p><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></p></li>
  2339. </ul>
  2340. <p>Creating classes whose metaclass overrides <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_new" title="PyTypeObject.tp_new"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_new</span></code></a>
  2341. is deprecated, and in Python 3.14+ it will be disallowed.
  2342. Note that these functions ignore <code class="docutils literal notranslate"><span class="pre">tp_new</span></code> of the metaclass, possibly
  2343. allowing incomplete initialization.</p>
  2344. <p>Note that <a class="reference internal" href="../c-api/type.html#c.PyType_FromMetaclass" title="PyType_FromMetaclass"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromMetaclass()</span></code></a> (added in Python 3.12)
  2345. already disallows creating classes whose metaclass overrides <code class="docutils literal notranslate"><span class="pre">tp_new</span></code>
  2346. (<a class="reference internal" href="../reference/datamodel.html#object.__new__" title="object.__new__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__new__()</span></code></a> in Python).</p>
  2347. <p>Since <code class="docutils literal notranslate"><span class="pre">tp_new</span></code> overrides almost everything <code class="docutils literal notranslate"><span class="pre">PyType_From*</span></code> functions do,
  2348. the two are incompatible with each other.
  2349. The existing behavior – ignoring the metaclass for several steps
  2350. of type creation – is unsafe in general, since (meta)classes assume that
  2351. <code class="docutils literal notranslate"><span class="pre">tp_new</span></code> was called.
  2352. There is no simple general workaround. One of the following may work for you:</p>
  2353. <ul class="simple">
  2354. <li><p>If you control the metaclass, avoid using <code class="docutils literal notranslate"><span class="pre">tp_new</span></code> in it:</p>
  2355. <ul>
  2356. <li><p>If initialization can be skipped, it can be done in
  2357. <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_init" title="PyTypeObject.tp_init"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_init</span></code></a> instead.</p></li>
  2358. <li><p>If the metaclass doesn’t need to be instantiated from Python,
  2359. set its <code class="docutils literal notranslate"><span class="pre">tp_new</span></code> to <code class="docutils literal notranslate"><span class="pre">NULL</span></code> using
  2360. the <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> flag.
  2361. This makes it acceptable for <code class="docutils literal notranslate"><span class="pre">PyType_From*</span></code> functions.</p></li>
  2362. </ul>
  2363. </li>
  2364. <li><p>Avoid <code class="docutils literal notranslate"><span class="pre">PyType_From*</span></code> functions: if you don’t need C-specific features
  2365. (slots or setting the instance size), create types by <a class="reference internal" href="../c-api/call.html#call"><span class="std std-ref">calling</span></a>
  2366. the metaclass.</p></li>
  2367. <li><p>If you <em>know</em> the <code class="docutils literal notranslate"><span class="pre">tp_new</span></code> can be skipped safely, filter the deprecation
  2368. warning out using <a class="reference internal" href="../library/warnings.html#warnings.catch_warnings" title="warnings.catch_warnings"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.catch_warnings()</span></code></a> from Python.</p></li>
  2369. </ul>
  2370. </li>
  2371. <li><p><a class="reference internal" href="../c-api/veryhigh.html#c.PyOS_InputHook" title="PyOS_InputHook"><code class="xref c c-var docutils literal notranslate"><span class="pre">PyOS_InputHook</span></code></a> and <a class="reference internal" href="../c-api/veryhigh.html#c.PyOS_ReadlineFunctionPointer" title="PyOS_ReadlineFunctionPointer"><code class="xref c c-var docutils literal notranslate"><span class="pre">PyOS_ReadlineFunctionPointer</span></code></a> are no
  2372. longer called in <a class="reference internal" href="../c-api/init.html#sub-interpreter-support"><span class="std std-ref">subinterpreters</span></a>. This is
  2373. because clients generally rely on process-wide global state (since these
  2374. callbacks have no way of recovering extension module state).</p>
  2375. <p>This also avoids situations where extensions may find themselves running in a
  2376. subinterpreter that they don’t support (or haven’t yet been loaded in). See
  2377. <a class="reference external" href="https://github.com/python/cpython/issues/104668">gh-104668</a> for more info.</p>
  2378. </li>
  2379. <li><p><a class="reference internal" href="../c-api/long.html#c.PyLongObject" title="PyLongObject"><code class="xref c c-struct docutils literal notranslate"><span class="pre">PyLongObject</span></code></a> has had its internals changed for better performance.
  2380. Although the internals of <a class="reference internal" href="../c-api/long.html#c.PyLongObject" title="PyLongObject"><code class="xref c c-struct docutils literal notranslate"><span class="pre">PyLongObject</span></code></a> are private, they are used
  2381. by some extension modules.
  2382. The internal fields should no longer be accessed directly, instead the API
  2383. functions beginning <code class="docutils literal notranslate"><span class="pre">PyLong_...</span></code> should be used instead.
  2384. Two new <em>unstable</em> API functions are provided for efficient access to the
  2385. value of <a class="reference internal" href="../c-api/long.html#c.PyLongObject" title="PyLongObject"><code class="xref c c-struct docutils literal notranslate"><span class="pre">PyLongObject</span></code></a>s which fit into a single machine word:</p>
  2386. <ul class="simple">
  2387. <li><p><a class="reference internal" href="../c-api/long.html#c.PyUnstable_Long_IsCompact" title="PyUnstable_Long_IsCompact"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnstable_Long_IsCompact()</span></code></a></p></li>
  2388. <li><p><a class="reference internal" href="../c-api/long.html#c.PyUnstable_Long_CompactValue" title="PyUnstable_Long_CompactValue"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnstable_Long_CompactValue()</span></code></a></p></li>
  2389. </ul>
  2390. </li>
  2391. <li><p>Custom allocators, set via <a class="reference internal" href="../c-api/memory.html#c.PyMem_SetAllocator" title="PyMem_SetAllocator"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_SetAllocator()</span></code></a>, are now
  2392. required to be thread-safe, regardless of memory domain. Allocators
  2393. that don’t have their own state, including “hooks”, are not affected.
  2394. If your custom allocator is not already thread-safe and you need
  2395. guidance then please create a new GitHub issue
  2396. and CC <code class="docutils literal notranslate"><span class="pre">&#64;ericsnowcurrently</span></code>.</p></li>
  2397. </ul>
  2398. </section>
  2399. <section id="id6">
  2400. <h3>Deprecated<a class="headerlink" href="#id6" title="Link to this heading">¶</a></h3>
  2401. <ul>
  2402. <li><p>In accordance with <span class="target" id="index-45"></span><a class="pep reference external" href="https://peps.python.org/pep-0699/"><strong>PEP 699</strong></a>, the <code class="docutils literal notranslate"><span class="pre">ma_version_tag</span></code> field in <a class="reference internal" href="../c-api/dict.html#c.PyDictObject" title="PyDictObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyDictObject</span></code></a>
  2403. is deprecated for extension modules. Accessing this field will generate a compiler
  2404. warning at compile time. This field will be removed in Python 3.14.
  2405. (Contributed by Ramvikrams and Kumar Aditya in <a class="reference external" href="https://github.com/python/cpython/issues/101193">gh-101193</a>. PEP by Ken Jin.)</p></li>
  2406. <li><p>Deprecate global configuration variable:</p>
  2407. <ul class="simple">
  2408. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_DebugFlag" title="Py_DebugFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_DebugFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.parser_debug" title="PyConfig.parser_debug"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.parser_debug</span></code></a></p></li>
  2409. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_VerboseFlag" title="Py_VerboseFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_VerboseFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.verbose" title="PyConfig.verbose"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.verbose</span></code></a></p></li>
  2410. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_QuietFlag" title="Py_QuietFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_QuietFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.quiet" title="PyConfig.quiet"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.quiet</span></code></a></p></li>
  2411. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_InteractiveFlag" title="Py_InteractiveFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_InteractiveFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.interactive" title="PyConfig.interactive"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.interactive</span></code></a></p></li>
  2412. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_InspectFlag" title="Py_InspectFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_InspectFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.inspect" title="PyConfig.inspect"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.inspect</span></code></a></p></li>
  2413. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_OptimizeFlag" title="Py_OptimizeFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_OptimizeFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.optimization_level" title="PyConfig.optimization_level"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.optimization_level</span></code></a></p></li>
  2414. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_NoSiteFlag" title="Py_NoSiteFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_NoSiteFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.site_import" title="PyConfig.site_import"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.site_import</span></code></a></p></li>
  2415. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_BytesWarningFlag" title="Py_BytesWarningFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_BytesWarningFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.bytes_warning" title="PyConfig.bytes_warning"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.bytes_warning</span></code></a></p></li>
  2416. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_FrozenFlag" title="Py_FrozenFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_FrozenFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.pathconfig_warnings" title="PyConfig.pathconfig_warnings"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.pathconfig_warnings</span></code></a></p></li>
  2417. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_IgnoreEnvironmentFlag" title="Py_IgnoreEnvironmentFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_IgnoreEnvironmentFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.use_environment" title="PyConfig.use_environment"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.use_environment</span></code></a></p></li>
  2418. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_DontWriteBytecodeFlag" title="Py_DontWriteBytecodeFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_DontWriteBytecodeFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.write_bytecode" title="PyConfig.write_bytecode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.write_bytecode</span></code></a></p></li>
  2419. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_NoUserSiteDirectory" title="Py_NoUserSiteDirectory"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_NoUserSiteDirectory</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.user_site_directory" title="PyConfig.user_site_directory"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.user_site_directory</span></code></a></p></li>
  2420. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_UnbufferedStdioFlag" title="Py_UnbufferedStdioFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_UnbufferedStdioFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.buffered_stdio" title="PyConfig.buffered_stdio"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.buffered_stdio</span></code></a></p></li>
  2421. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_HashRandomizationFlag" title="Py_HashRandomizationFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_HashRandomizationFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.use_hash_seed" title="PyConfig.use_hash_seed"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.use_hash_seed</span></code></a>
  2422. and <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.hash_seed" title="PyConfig.hash_seed"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.hash_seed</span></code></a></p></li>
  2423. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_IsolatedFlag" title="Py_IsolatedFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_IsolatedFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.isolated" title="PyConfig.isolated"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.isolated</span></code></a></p></li>
  2424. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_LegacyWindowsFSEncodingFlag" title="Py_LegacyWindowsFSEncodingFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_LegacyWindowsFSEncodingFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig.legacy_windows_fs_encoding" title="PyPreConfig.legacy_windows_fs_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.legacy_windows_fs_encoding</span></code></a></p></li>
  2425. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_LegacyWindowsStdioFlag" title="Py_LegacyWindowsStdioFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_LegacyWindowsStdioFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.legacy_windows_stdio" title="PyConfig.legacy_windows_stdio"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.legacy_windows_stdio</span></code></a></p></li>
  2426. <li><p><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_FileSystemDefaultEncoding</span></code>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.filesystem_encoding</span></code></a></p></li>
  2427. <li><p><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_HasFileSystemDefaultEncoding</span></code>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.filesystem_encoding</span></code></a></p></li>
  2428. <li><p><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_FileSystemDefaultEncodeErrors</span></code>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_errors" title="PyConfig.filesystem_errors"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.filesystem_errors</span></code></a></p></li>
  2429. <li><p><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_UTF8Mode</span></code>: use <a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig.utf8_mode" title="PyPreConfig.utf8_mode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.utf8_mode</span></code></a> (see <a class="reference internal" href="../c-api/init_config.html#c.Py_PreInitialize" title="Py_PreInitialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitialize()</span></code></a>)</p></li>
  2430. </ul>
  2431. <p>The <a class="reference internal" href="../c-api/init_config.html#c.Py_InitializeFromConfig" title="Py_InitializeFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_InitializeFromConfig()</span></code></a> API should be used with
  2432. <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> instead.
  2433. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/77782">gh-77782</a>.)</p>
  2434. </li>
  2435. <li><p>Creating <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_IMMUTABLETYPE" title="Py_TPFLAGS_IMMUTABLETYPE"><code class="xref c c-data docutils literal notranslate"><span class="pre">immutable</span> <span class="pre">types</span></code></a> with mutable
  2436. bases is deprecated and will be disabled in Python 3.14. (<a class="reference external" href="https://github.com/python/cpython/issues/95388">gh-95388</a>)</p></li>
  2437. <li><p>The <code class="file docutils literal notranslate"><span class="pre">structmember.h</span></code> header is deprecated, though it continues to be
  2438. available and there are no plans to remove it.</p>
  2439. <p>Its contents are now available just by including <code class="file docutils literal notranslate"><span class="pre">Python.h</span></code>,
  2440. with a <code class="docutils literal notranslate"><span class="pre">Py</span></code> prefix added if it was missing:</p>
  2441. <ul class="simple">
  2442. <li><p><a class="reference internal" href="../c-api/structures.html#c.PyMemberDef" title="PyMemberDef"><code class="xref c c-struct docutils literal notranslate"><span class="pre">PyMemberDef</span></code></a>, <a class="reference internal" href="../c-api/structures.html#c.PyMember_GetOne" title="PyMember_GetOne"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMember_GetOne()</span></code></a> and
  2443. <a class="reference internal" href="../c-api/structures.html#c.PyMember_SetOne" title="PyMember_SetOne"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMember_SetOne()</span></code></a></p></li>
  2444. <li><p>Type macros like <a class="reference internal" href="../c-api/structures.html#c.Py_T_INT" title="Py_T_INT"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_T_INT</span></code></a>, <a class="reference internal" href="../c-api/structures.html#c.Py_T_DOUBLE" title="Py_T_DOUBLE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_T_DOUBLE</span></code></a>, etc.
  2445. (previously <code class="docutils literal notranslate"><span class="pre">T_INT</span></code>, <code class="docutils literal notranslate"><span class="pre">T_DOUBLE</span></code>, etc.)</p></li>
  2446. <li><p>The flags <a class="reference internal" href="../c-api/structures.html#c.Py_READONLY" title="Py_READONLY"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_READONLY</span></code></a> (previously <code class="docutils literal notranslate"><span class="pre">READONLY</span></code>) and
  2447. <a class="reference internal" href="../c-api/structures.html#c.Py_AUDIT_READ" title="Py_AUDIT_READ"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_AUDIT_READ</span></code></a> (previously all uppercase)</p></li>
  2448. </ul>
  2449. <p>Several items are not exposed from <code class="file docutils literal notranslate"><span class="pre">Python.h</span></code>:</p>
  2450. <ul class="simple">
  2451. <li><p><a class="reference internal" href="../c-api/structures.html#c.T_OBJECT" title="T_OBJECT"><code class="xref c c-macro docutils literal notranslate"><span class="pre">T_OBJECT</span></code></a> (use <a class="reference internal" href="../c-api/structures.html#c.Py_T_OBJECT_EX" title="Py_T_OBJECT_EX"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_T_OBJECT_EX</span></code></a>)</p></li>
  2452. <li><p><a class="reference internal" href="../c-api/structures.html#c.T_NONE" title="T_NONE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">T_NONE</span></code></a> (previously undocumented, and pretty quirky)</p></li>
  2453. <li><p>The macro <code class="docutils literal notranslate"><span class="pre">WRITE_RESTRICTED</span></code> which does nothing.</p></li>
  2454. <li><p>The macros <code class="docutils literal notranslate"><span class="pre">RESTRICTED</span></code> and <code class="docutils literal notranslate"><span class="pre">READ_RESTRICTED</span></code>, equivalents of
  2455. <a class="reference internal" href="../c-api/structures.html#c.Py_AUDIT_READ" title="Py_AUDIT_READ"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_AUDIT_READ</span></code></a>.</p></li>
  2456. <li><p>In some configurations, <code class="docutils literal notranslate"><span class="pre">&lt;stddef.h&gt;</span></code> is not included from <code class="file docutils literal notranslate"><span class="pre">Python.h</span></code>.
  2457. It should be included manually when using <code class="docutils literal notranslate"><span class="pre">offsetof()</span></code>.</p></li>
  2458. </ul>
  2459. <p>The deprecated header continues to provide its original
  2460. contents under the original names.
  2461. Your old code can stay unchanged, unless the extra include and non-namespaced
  2462. macros bother you greatly.</p>
  2463. <p>(Contributed in <a class="reference external" href="https://github.com/python/cpython/issues/47146">gh-47146</a> by Petr Viktorin, based on
  2464. earlier work by Alexander Belopolsky and Matthias Braun.)</p>
  2465. </li>
  2466. <li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Fetch" title="PyErr_Fetch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Fetch()</span></code></a> and <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Restore" title="PyErr_Restore"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Restore()</span></code></a> are deprecated.
  2467. Use <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_GetRaisedException" title="PyErr_GetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetRaisedException()</span></code></a> and
  2468. <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetRaisedException" title="PyErr_SetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetRaisedException()</span></code></a> instead.
  2469. (Contributed by Mark Shannon in <a class="reference external" href="https://github.com/python/cpython/issues/101578">gh-101578</a>.)</p></li>
  2470. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Display()</span></code> is deprecated. Use <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_DisplayException" title="PyErr_DisplayException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_DisplayException()</span></code></a>
  2471. instead. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102755">gh-102755</a>).</p></li>
  2472. <li><p><code class="docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions</span></code> is deprecated. Use <code class="docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions1</span></code>
  2473. instead. (Contributed by Irit Katriel in <a class="reference external" href="https://github.com/python/cpython/issues/102192">gh-102192</a>.)</p></li>
  2474. <li><p>Using <a class="reference internal" href="../c-api/type.html#c.PyType_FromSpec" title="PyType_FromSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromSpec()</span></code></a>, <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>
  2475. or <a class="reference internal" href="../c-api/type.html#c.PyType_FromModuleAndSpec" title="PyType_FromModuleAndSpec"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_FromModuleAndSpec()</span></code></a> to create a class whose metaclass
  2476. overrides <a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_new" title="PyTypeObject.tp_new"><code class="xref c c-member docutils literal notranslate"><span class="pre">tp_new</span></code></a> is deprecated.
  2477. Call the metaclass instead.</p></li>
  2478. </ul>
  2479. <section id="id7">
  2480. <h4>Pending Removal in Python 3.14<a class="headerlink" href="#id7" title="Link to this heading">¶</a></h4>
  2481. <ul>
  2482. <li><p>The <code class="docutils literal notranslate"><span class="pre">ma_version_tag</span></code> field in <a class="reference internal" href="../c-api/dict.html#c.PyDictObject" title="PyDictObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyDictObject</span></code></a> for extension modules
  2483. (<span class="target" id="index-46"></span><a class="pep reference external" href="https://peps.python.org/pep-0699/"><strong>PEP 699</strong></a>; <a class="reference external" href="https://github.com/python/cpython/issues/101193">gh-101193</a>).</p></li>
  2484. <li><p>Global configuration variables:</p>
  2485. <ul class="simple">
  2486. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_DebugFlag" title="Py_DebugFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_DebugFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.parser_debug" title="PyConfig.parser_debug"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.parser_debug</span></code></a></p></li>
  2487. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_VerboseFlag" title="Py_VerboseFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_VerboseFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.verbose" title="PyConfig.verbose"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.verbose</span></code></a></p></li>
  2488. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_QuietFlag" title="Py_QuietFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_QuietFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.quiet" title="PyConfig.quiet"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.quiet</span></code></a></p></li>
  2489. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_InteractiveFlag" title="Py_InteractiveFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_InteractiveFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.interactive" title="PyConfig.interactive"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.interactive</span></code></a></p></li>
  2490. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_InspectFlag" title="Py_InspectFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_InspectFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.inspect" title="PyConfig.inspect"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.inspect</span></code></a></p></li>
  2491. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_OptimizeFlag" title="Py_OptimizeFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_OptimizeFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.optimization_level" title="PyConfig.optimization_level"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.optimization_level</span></code></a></p></li>
  2492. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_NoSiteFlag" title="Py_NoSiteFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_NoSiteFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.site_import" title="PyConfig.site_import"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.site_import</span></code></a></p></li>
  2493. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_BytesWarningFlag" title="Py_BytesWarningFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_BytesWarningFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.bytes_warning" title="PyConfig.bytes_warning"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.bytes_warning</span></code></a></p></li>
  2494. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_FrozenFlag" title="Py_FrozenFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_FrozenFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.pathconfig_warnings" title="PyConfig.pathconfig_warnings"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.pathconfig_warnings</span></code></a></p></li>
  2495. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_IgnoreEnvironmentFlag" title="Py_IgnoreEnvironmentFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_IgnoreEnvironmentFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.use_environment" title="PyConfig.use_environment"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.use_environment</span></code></a></p></li>
  2496. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_DontWriteBytecodeFlag" title="Py_DontWriteBytecodeFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_DontWriteBytecodeFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.write_bytecode" title="PyConfig.write_bytecode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.write_bytecode</span></code></a></p></li>
  2497. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_NoUserSiteDirectory" title="Py_NoUserSiteDirectory"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_NoUserSiteDirectory</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.user_site_directory" title="PyConfig.user_site_directory"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.user_site_directory</span></code></a></p></li>
  2498. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_UnbufferedStdioFlag" title="Py_UnbufferedStdioFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_UnbufferedStdioFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.buffered_stdio" title="PyConfig.buffered_stdio"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.buffered_stdio</span></code></a></p></li>
  2499. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_HashRandomizationFlag" title="Py_HashRandomizationFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_HashRandomizationFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.use_hash_seed" title="PyConfig.use_hash_seed"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.use_hash_seed</span></code></a>
  2500. and <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.hash_seed" title="PyConfig.hash_seed"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.hash_seed</span></code></a></p></li>
  2501. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_IsolatedFlag" title="Py_IsolatedFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_IsolatedFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.isolated" title="PyConfig.isolated"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.isolated</span></code></a></p></li>
  2502. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_LegacyWindowsFSEncodingFlag" title="Py_LegacyWindowsFSEncodingFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_LegacyWindowsFSEncodingFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig.legacy_windows_fs_encoding" title="PyPreConfig.legacy_windows_fs_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.legacy_windows_fs_encoding</span></code></a></p></li>
  2503. <li><p><a class="reference internal" href="../c-api/init.html#c.Py_LegacyWindowsStdioFlag" title="Py_LegacyWindowsStdioFlag"><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_LegacyWindowsStdioFlag</span></code></a>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.legacy_windows_stdio" title="PyConfig.legacy_windows_stdio"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.legacy_windows_stdio</span></code></a></p></li>
  2504. <li><p><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_FileSystemDefaultEncoding</span></code>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.filesystem_encoding</span></code></a></p></li>
  2505. <li><p><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_HasFileSystemDefaultEncoding</span></code>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.filesystem_encoding</span></code></a></p></li>
  2506. <li><p><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_FileSystemDefaultEncodeErrors</span></code>: use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.filesystem_errors" title="PyConfig.filesystem_errors"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.filesystem_errors</span></code></a></p></li>
  2507. <li><p><code class="xref c c-var docutils literal notranslate"><span class="pre">Py_UTF8Mode</span></code>: use <a class="reference internal" href="../c-api/init_config.html#c.PyPreConfig.utf8_mode" title="PyPreConfig.utf8_mode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.utf8_mode</span></code></a> (see <a class="reference internal" href="../c-api/init_config.html#c.Py_PreInitialize" title="Py_PreInitialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitialize()</span></code></a>)</p></li>
  2508. </ul>
  2509. <p>The <a class="reference internal" href="../c-api/init_config.html#c.Py_InitializeFromConfig" title="Py_InitializeFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_InitializeFromConfig()</span></code></a> API should be used with
  2510. <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> instead.</p>
  2511. </li>
  2512. <li><p>Creating <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_IMMUTABLETYPE" title="Py_TPFLAGS_IMMUTABLETYPE"><code class="xref c c-data docutils literal notranslate"><span class="pre">immutable</span> <span class="pre">types</span></code></a> with mutable
  2513. bases (<a class="reference external" href="https://github.com/python/cpython/issues/95388">gh-95388</a>).</p></li>
  2514. </ul>
  2515. </section>
  2516. <section id="id8">
  2517. <h4>Pending Removal in Python 3.15<a class="headerlink" href="#id8" title="Link to this heading">¶</a></h4>
  2518. <ul class="simple">
  2519. <li><p><a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModuleNoBlock" title="PyImport_ImportModuleNoBlock"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModuleNoBlock()</span></code></a>: use <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></p></li>
  2520. <li><p><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE_WIDE</span></code> type: use <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code></p></li>
  2521. <li><p><a class="reference internal" href="../c-api/unicode.html#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE</span></code></a> type: use <code class="xref c c-type docutils literal notranslate"><span class="pre">wchar_t</span></code></p></li>
  2522. <li><p>Python initialization functions:</p>
  2523. <ul>
  2524. <li><p><a class="reference internal" href="../c-api/sys.html#c.PySys_ResetWarnOptions" title="PySys_ResetWarnOptions"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_ResetWarnOptions()</span></code></a>: clear <a class="reference internal" href="../library/sys.html#sys.warnoptions" title="sys.warnoptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.warnoptions</span></code></a> and
  2525. <code class="xref py py-data docutils literal notranslate"><span class="pre">warnings.filters</span></code></p></li>
  2526. <li><p><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>: get <a class="reference internal" href="../library/sys.html#sys.exec_prefix" title="sys.exec_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.exec_prefix</span></code></a></p></li>
  2527. <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>: get <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a></p></li>
  2528. <li><p><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>: get <a class="reference internal" href="../library/sys.html#sys.prefix" title="sys.prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.prefix</span></code></a></p></li>
  2529. <li><p><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>: get <a class="reference internal" href="../library/sys.html#sys.executable" title="sys.executable"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.executable</span></code></a></p></li>
  2530. <li><p><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>: get <a class="reference internal" href="../library/sys.html#sys.executable" title="sys.executable"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.executable</span></code></a></p></li>
  2531. <li><p><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>: get <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.home" title="PyConfig.home"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.home</span></code></a> or
  2532. the <span class="target" id="index-47"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHOME</span></code></a> environment variable</p></li>
  2533. </ul>
  2534. </li>
  2535. </ul>
  2536. </section>
  2537. <section id="id9">
  2538. <h4>Pending Removal in Future Versions<a class="headerlink" href="#id9" title="Link to this heading">¶</a></h4>
  2539. <p>The following APIs are deprecated and will be removed,
  2540. although there is currently no date scheduled for their removal.</p>
  2541. <ul class="simple">
  2542. <li><p><a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_HAVE_FINALIZE" title="Py_TPFLAGS_HAVE_FINALIZE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_HAVE_FINALIZE</span></code></a>: unneeded since Python 3.8</p></li>
  2543. <li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Fetch" title="PyErr_Fetch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Fetch()</span></code></a>: use <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_GetRaisedException" title="PyErr_GetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetRaisedException()</span></code></a></p></li>
  2544. <li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_NormalizeException" title="PyErr_NormalizeException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_NormalizeException()</span></code></a>: use <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_GetRaisedException" title="PyErr_GetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetRaisedException()</span></code></a></p></li>
  2545. <li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Restore" title="PyErr_Restore"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Restore()</span></code></a>: use <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetRaisedException" title="PyErr_SetRaisedException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetRaisedException()</span></code></a></p></li>
  2546. <li><p><a class="reference internal" href="../c-api/module.html#c.PyModule_GetFilename" title="PyModule_GetFilename"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_GetFilename()</span></code></a>: use <a class="reference internal" href="../c-api/module.html#c.PyModule_GetFilenameObject" title="PyModule_GetFilenameObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyModule_GetFilenameObject()</span></code></a></p></li>
  2547. <li><p><a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork" title="PyOS_AfterFork"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork()</span></code></a>: use <a class="reference internal" href="../c-api/sys.html#c.PyOS_AfterFork_Child" title="PyOS_AfterFork_Child"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_AfterFork_Child()</span></code></a></p></li>
  2548. <li><p><a class="reference internal" href="../c-api/slice.html#c.PySlice_GetIndicesEx" title="PySlice_GetIndicesEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_GetIndicesEx()</span></code></a>: use <a class="reference internal" href="../c-api/slice.html#c.PySlice_Unpack" title="PySlice_Unpack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_Unpack()</span></code></a> and <a class="reference internal" href="../c-api/slice.html#c.PySlice_AdjustIndices" title="PySlice_AdjustIndices"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySlice_AdjustIndices()</span></code></a></p></li>
  2549. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsDecodedObject()</span></code>: use <a class="reference internal" href="../c-api/codec.html#c.PyCodec_Decode" title="PyCodec_Decode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCodec_Decode()</span></code></a></p></li>
  2550. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsDecodedUnicode()</span></code>: use <a class="reference internal" href="../c-api/codec.html#c.PyCodec_Decode" title="PyCodec_Decode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCodec_Decode()</span></code></a></p></li>
  2551. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsEncodedObject()</span></code>: use <a class="reference internal" href="../c-api/codec.html#c.PyCodec_Encode" title="PyCodec_Encode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCodec_Encode()</span></code></a></p></li>
  2552. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsEncodedUnicode()</span></code>: use <a class="reference internal" href="../c-api/codec.html#c.PyCodec_Encode" title="PyCodec_Encode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCodec_Encode()</span></code></a></p></li>
  2553. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_READY" title="PyUnicode_READY"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_READY()</span></code></a>: unneeded since Python 3.12</p></li>
  2554. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Display()</span></code>: use <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_DisplayException" title="PyErr_DisplayException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_DisplayException()</span></code></a></p></li>
  2555. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions()</span></code>: use <code class="docutils literal notranslate"><span class="pre">_PyErr_ChainExceptions1</span></code></p></li>
  2556. <li><p><code class="xref c c-member docutils literal notranslate"><span class="pre">PyBytesObject.ob_shash</span></code> member:
  2557. call <a class="reference internal" href="../c-api/object.html#c.PyObject_Hash" title="PyObject_Hash"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Hash()</span></code></a> instead</p></li>
  2558. <li><p><code class="xref c c-member docutils literal notranslate"><span class="pre">PyDictObject.ma_version_tag</span></code> member</p></li>
  2559. <li><p>Thread Local Storage (TLS) API:</p>
  2560. <ul>
  2561. <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_create_key" title="PyThread_create_key"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_create_key()</span></code></a>: use <a class="reference internal" href="../c-api/init.html#c.PyThread_tss_alloc" title="PyThread_tss_alloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_tss_alloc()</span></code></a></p></li>
  2562. <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_delete_key" title="PyThread_delete_key"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_delete_key()</span></code></a>: use <a class="reference internal" href="../c-api/init.html#c.PyThread_tss_free" title="PyThread_tss_free"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_tss_free()</span></code></a></p></li>
  2563. <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_set_key_value" title="PyThread_set_key_value"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_set_key_value()</span></code></a>: use <a class="reference internal" href="../c-api/init.html#c.PyThread_tss_set" title="PyThread_tss_set"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_tss_set()</span></code></a></p></li>
  2564. <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_get_key_value" title="PyThread_get_key_value"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_get_key_value()</span></code></a>: use <a class="reference internal" href="../c-api/init.html#c.PyThread_tss_get" title="PyThread_tss_get"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_tss_get()</span></code></a></p></li>
  2565. <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_delete_key_value" title="PyThread_delete_key_value"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_delete_key_value()</span></code></a>: use <a class="reference internal" href="../c-api/init.html#c.PyThread_tss_delete" title="PyThread_tss_delete"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_tss_delete()</span></code></a></p></li>
  2566. <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_ReInitTLS" title="PyThread_ReInitTLS"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_ReInitTLS()</span></code></a>: unneeded since Python 3.7</p></li>
  2567. </ul>
  2568. </li>
  2569. </ul>
  2570. </section>
  2571. </section>
  2572. <section id="id10">
  2573. <h3>Removed<a class="headerlink" href="#id10" title="Link to this heading">¶</a></h3>
  2574. <ul class="simple">
  2575. <li><p>Remove the <code class="file docutils literal notranslate"><span class="pre">token.h</span></code> header file. There was never any public tokenizer C
  2576. API. The <code class="file docutils literal notranslate"><span class="pre">token.h</span></code> header file was only designed to be used by Python
  2577. internals.
  2578. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/92651">gh-92651</a>.)</p></li>
  2579. <li><p>Legacy Unicode APIs have been removed. See <span class="target" id="index-48"></span><a class="pep reference external" href="https://peps.python.org/pep-0623/"><strong>PEP 623</strong></a> for detail.</p>
  2580. <ul>
  2581. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_WCHAR_KIND</span></code></p></li>
  2582. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AS_UNICODE()</span></code></p></li>
  2583. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicode()</span></code></p></li>
  2584. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicodeAndSize()</span></code></p></li>
  2585. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AS_DATA()</span></code></p></li>
  2586. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromUnicode()</span></code></p></li>
  2587. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GET_SIZE()</span></code></p></li>
  2588. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetSize()</span></code></p></li>
  2589. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GET_DATA_SIZE()</span></code></p></li>
  2590. </ul>
  2591. </li>
  2592. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">PyUnicode_InternImmortal()</span></code> function macro.
  2593. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/85858">gh-85858</a>.)</p></li>
  2594. </ul>
  2595. </section>
  2596. </section>
  2597. </section>
  2598. <div class="clearer"></div>
  2599. </div>
  2600. </div>
  2601. </div>
  2602. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  2603. <div class="sphinxsidebarwrapper">
  2604. <div>
  2605. <h3><a href="../contents.html">Table of Contents</a></h3>
  2606. <ul>
  2607. <li><a class="reference internal" href="#">What’s New In Python 3.12</a><ul>
  2608. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  2609. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  2610. <li><a class="reference internal" href="#pep-695-type-parameter-syntax">PEP 695: Type Parameter Syntax</a></li>
  2611. <li><a class="reference internal" href="#pep-701-syntactic-formalization-of-f-strings">PEP 701: Syntactic formalization of f-strings</a></li>
  2612. <li><a class="reference internal" href="#pep-684-a-per-interpreter-gil">PEP 684: A Per-Interpreter GIL</a></li>
  2613. <li><a class="reference internal" href="#pep-669-low-impact-monitoring-for-cpython">PEP 669: Low impact monitoring for CPython</a></li>
  2614. <li><a class="reference internal" href="#pep-688-making-the-buffer-protocol-accessible-in-python">PEP 688: Making the buffer protocol accessible in Python</a></li>
  2615. <li><a class="reference internal" href="#pep-709-comprehension-inlining">PEP 709: Comprehension inlining</a></li>
  2616. <li><a class="reference internal" href="#improved-error-messages">Improved Error Messages</a></li>
  2617. </ul>
  2618. </li>
  2619. <li><a class="reference internal" href="#new-features-related-to-type-hints">New Features Related to Type Hints</a><ul>
  2620. <li><a class="reference internal" href="#pep-692-using-typeddict-for-more-precise-kwargs-typing">PEP 692: Using <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> for more precise <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> typing</a></li>
  2621. <li><a class="reference internal" href="#pep-698-override-decorator-for-static-typing">PEP 698: Override Decorator for Static Typing</a></li>
  2622. </ul>
  2623. </li>
  2624. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  2625. <li><a class="reference internal" href="#new-modules">New Modules</a></li>
  2626. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  2627. <li><a class="reference internal" href="#array">array</a></li>
  2628. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  2629. <li><a class="reference internal" href="#calendar">calendar</a></li>
  2630. <li><a class="reference internal" href="#csv">csv</a></li>
  2631. <li><a class="reference internal" href="#dis">dis</a></li>
  2632. <li><a class="reference internal" href="#fractions">fractions</a></li>
  2633. <li><a class="reference internal" href="#importlib-resources">importlib.resources</a></li>
  2634. <li><a class="reference internal" href="#inspect">inspect</a></li>
  2635. <li><a class="reference internal" href="#itertools">itertools</a></li>
  2636. <li><a class="reference internal" href="#math">math</a></li>
  2637. <li><a class="reference internal" href="#os">os</a></li>
  2638. <li><a class="reference internal" href="#os-path">os.path</a></li>
  2639. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  2640. <li><a class="reference internal" href="#pdb">pdb</a></li>
  2641. <li><a class="reference internal" href="#random">random</a></li>
  2642. <li><a class="reference internal" href="#shutil">shutil</a></li>
  2643. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  2644. <li><a class="reference internal" href="#statistics">statistics</a></li>
  2645. <li><a class="reference internal" href="#sys">sys</a></li>
  2646. <li><a class="reference internal" href="#tempfile">tempfile</a></li>
  2647. <li><a class="reference internal" href="#threading">threading</a></li>
  2648. <li><a class="reference internal" href="#tkinter">tkinter</a></li>
  2649. <li><a class="reference internal" href="#tokenize">tokenize</a></li>
  2650. <li><a class="reference internal" href="#types">types</a></li>
  2651. <li><a class="reference internal" href="#typing">typing</a></li>
  2652. <li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
  2653. <li><a class="reference internal" href="#unittest">unittest</a></li>
  2654. <li><a class="reference internal" href="#uuid">uuid</a></li>
  2655. </ul>
  2656. </li>
  2657. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  2658. <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
  2659. <li><a class="reference internal" href="#demos-and-tools">Demos and Tools</a></li>
  2660. <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
  2661. <li><a class="reference internal" href="#pending-removal-in-python-3-13">Pending Removal in Python 3.13</a></li>
  2662. <li><a class="reference internal" href="#pending-removal-in-python-3-14">Pending Removal in Python 3.14</a></li>
  2663. <li><a class="reference internal" href="#pending-removal-in-python-3-15">Pending Removal in Python 3.15</a></li>
  2664. <li><a class="reference internal" href="#pending-removal-in-future-versions">Pending Removal in Future Versions</a></li>
  2665. </ul>
  2666. </li>
  2667. <li><a class="reference internal" href="#removed">Removed</a><ul>
  2668. <li><a class="reference internal" href="#asynchat-and-asyncore">asynchat and asyncore</a></li>
  2669. <li><a class="reference internal" href="#configparser">configparser</a></li>
  2670. <li><a class="reference internal" href="#distutils">distutils</a></li>
  2671. <li><a class="reference internal" href="#ensurepip">ensurepip</a></li>
  2672. <li><a class="reference internal" href="#enum">enum</a></li>
  2673. <li><a class="reference internal" href="#ftplib">ftplib</a></li>
  2674. <li><a class="reference internal" href="#gzip">gzip</a></li>
  2675. <li><a class="reference internal" href="#hashlib">hashlib</a></li>
  2676. <li><a class="reference internal" href="#importlib">importlib</a></li>
  2677. <li><a class="reference internal" href="#imp">imp</a></li>
  2678. <li><a class="reference internal" href="#io">io</a></li>
  2679. <li><a class="reference internal" href="#locale">locale</a></li>
  2680. <li><a class="reference internal" href="#smtpd">smtpd</a></li>
  2681. <li><a class="reference internal" href="#id2">sqlite3</a></li>
  2682. <li><a class="reference internal" href="#ssl">ssl</a></li>
  2683. <li><a class="reference internal" href="#id3">unittest</a></li>
  2684. <li><a class="reference internal" href="#webbrowser">webbrowser</a></li>
  2685. <li><a class="reference internal" href="#xml-etree-elementtree">xml.etree.ElementTree</a></li>
  2686. <li><a class="reference internal" href="#zipimport">zipimport</a></li>
  2687. <li><a class="reference internal" href="#others">Others</a></li>
  2688. </ul>
  2689. </li>
  2690. <li><a class="reference internal" href="#porting-to-python-3-12">Porting to Python 3.12</a><ul>
  2691. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  2692. </ul>
  2693. </li>
  2694. <li><a class="reference internal" href="#build-changes">Build Changes</a></li>
  2695. <li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
  2696. <li><a class="reference internal" href="#id4">New Features</a></li>
  2697. <li><a class="reference internal" href="#id5">Porting to Python 3.12</a></li>
  2698. <li><a class="reference internal" href="#id6">Deprecated</a><ul>
  2699. <li><a class="reference internal" href="#id7">Pending Removal in Python 3.14</a></li>
  2700. <li><a class="reference internal" href="#id8">Pending Removal in Python 3.15</a></li>
  2701. <li><a class="reference internal" href="#id9">Pending Removal in Future Versions</a></li>
  2702. </ul>
  2703. </li>
  2704. <li><a class="reference internal" href="#id10">Removed</a></li>
  2705. </ul>
  2706. </li>
  2707. </ul>
  2708. </li>
  2709. </ul>
  2710. </div>
  2711. <div>
  2712. <h4>Previous topic</h4>
  2713. <p class="topless"><a href="index.html"
  2714. title="previous chapter">What’s New in Python</a></p>
  2715. </div>
  2716. <div>
  2717. <h4>Next topic</h4>
  2718. <p class="topless"><a href="3.11.html"
  2719. title="next chapter">What’s New In Python 3.11</a></p>
  2720. </div>
  2721. <div role="note" aria-label="source link">
  2722. <h3>This Page</h3>
  2723. <ul class="this-page-menu">
  2724. <li><a href="../bugs.html">Report a Bug</a></li>
  2725. <li>
  2726. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.12.rst"
  2727. rel="nofollow">Show Source
  2728. </a>
  2729. </li>
  2730. </ul>
  2731. </div>
  2732. </div>
  2733. <div id="sidebarbutton" title="Collapse sidebar">
  2734. <span>«</span>
  2735. </div>
  2736. </div>
  2737. <div class="clearer"></div>
  2738. </div>
  2739. <div class="related" role="navigation" aria-label="related navigation">
  2740. <h3>Navigation</h3>
  2741. <ul>
  2742. <li class="right" style="margin-right: 10px">
  2743. <a href="../genindex.html" title="General Index"
  2744. >index</a></li>
  2745. <li class="right" >
  2746. <a href="../py-modindex.html" title="Python Module Index"
  2747. >modules</a> |</li>
  2748. <li class="right" >
  2749. <a href="3.11.html" title="What’s New In Python 3.11"
  2750. >next</a> |</li>
  2751. <li class="right" >
  2752. <a href="index.html" title="What’s New in Python"
  2753. >previous</a> |</li>
  2754. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  2755. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  2756. <li class="switchers">
  2757. <div class="language_switcher_placeholder"></div>
  2758. <div class="version_switcher_placeholder"></div>
  2759. </li>
  2760. <li>
  2761. </li>
  2762. <li id="cpython-language-and-version">
  2763. <a href="../index.html">3.12.3 Documentation</a> &#187;
  2764. </li>
  2765. <li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> &#187;</li>
  2766. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.12</a></li>
  2767. <li class="right">
  2768. <div class="inline-search" role="search">
  2769. <form class="inline-search" action="../search.html" method="get">
  2770. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  2771. <input type="submit" value="Go" />
  2772. </form>
  2773. </div>
  2774. |
  2775. </li>
  2776. <li class="right">
  2777. <label class="theme-selector-label">
  2778. Theme
  2779. <select class="theme-selector" oninput="activateTheme(this.value)">
  2780. <option value="auto" selected>Auto</option>
  2781. <option value="light">Light</option>
  2782. <option value="dark">Dark</option>
  2783. </select>
  2784. </label> |</li>
  2785. </ul>
  2786. </div>
  2787. <div class="footer">
  2788. &copy;
  2789. <a href="../copyright.html">
  2790. Copyright
  2791. </a>
  2792. 2001-2024, Python Software Foundation.
  2793. <br />
  2794. This page is licensed under the Python Software Foundation License Version 2.
  2795. <br />
  2796. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  2797. <br />
  2798. See <a href="/license.html">History and License</a> for more information.<br />
  2799. <br />
  2800. The Python Software Foundation is a non-profit corporation.
  2801. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  2802. <br />
  2803. <br />
  2804. Last updated on Apr 09, 2024 (13:47 UTC).
  2805. <a href="/bugs.html">Found a bug</a>?
  2806. <br />
  2807. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  2808. </div>
  2809. </body>
  2810. </html>
上海开阖软件有限公司 沪ICP备12045867号-1