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.

2971 satır
341KB

  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.11" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/whatsnew/3.11.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Editor, Pablo Galindo Salgado,. This article explains the new features in Python 3.11, compared to 3.10. Python 3.11 was released on October 24, 2022. For full details, see the changelog. Summary –..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Editor, Pablo Galindo Salgado,. This article explains the new features in Python 3.11, compared to 3.10. Python 3.11 was released on October 24, 2022. For full details, see the changelog. Summary –..." />
  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.11 &#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.10" href="3.10.html" />
  33. <link rel="prev" title="What’s New In Python 3.12" href="3.12.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/whatsnew/3.11.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.11</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-657-fine-grained-error-locations-in-tracebacks">PEP 657: Fine-grained error locations in tracebacks</a></li>
  89. <li><a class="reference internal" href="#pep-654-exception-groups-and-except">PEP 654: Exception Groups and <code class="docutils literal notranslate"><span class="pre">except*</span></code></a></li>
  90. <li><a class="reference internal" href="#pep-678-exceptions-can-be-enriched-with-notes">PEP 678: Exceptions can be enriched with notes</a></li>
  91. <li><a class="reference internal" href="#windows-py-exe-launcher-improvements">Windows <code class="docutils literal notranslate"><span class="pre">py.exe</span></code> launcher improvements</a></li>
  92. </ul>
  93. </li>
  94. <li><a class="reference internal" href="#new-features-related-to-type-hints">New Features Related to Type Hints</a><ul>
  95. <li><a class="reference internal" href="#pep-646-variadic-generics">PEP 646: Variadic generics</a></li>
  96. <li><a class="reference internal" href="#pep-655-marking-individual-typeddict-items-as-required-or-not-required">PEP 655: Marking individual <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> items as required or not-required</a></li>
  97. <li><a class="reference internal" href="#pep-673-self-type">PEP 673: <code class="docutils literal notranslate"><span class="pre">Self</span></code> type</a></li>
  98. <li><a class="reference internal" href="#pep-675-arbitrary-literal-string-type">PEP 675: Arbitrary literal string type</a></li>
  99. <li><a class="reference internal" href="#pep-681-data-class-transforms">PEP 681: Data class transforms</a></li>
  100. <li><a class="reference internal" href="#pep-563-may-not-be-the-future">PEP 563 may not be the future</a></li>
  101. </ul>
  102. </li>
  103. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  104. <li><a class="reference internal" href="#other-cpython-implementation-changes">Other CPython Implementation Changes</a></li>
  105. <li><a class="reference internal" href="#new-modules">New Modules</a></li>
  106. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  107. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  108. <li><a class="reference internal" href="#contextlib">contextlib</a></li>
  109. <li><a class="reference internal" href="#dataclasses">dataclasses</a></li>
  110. <li><a class="reference internal" href="#datetime">datetime</a></li>
  111. <li><a class="reference internal" href="#enum">enum</a></li>
  112. <li><a class="reference internal" href="#fcntl">fcntl</a></li>
  113. <li><a class="reference internal" href="#fractions">fractions</a></li>
  114. <li><a class="reference internal" href="#functools">functools</a></li>
  115. <li><a class="reference internal" href="#hashlib">hashlib</a></li>
  116. <li><a class="reference internal" href="#whatsnew311-idle">IDLE and idlelib</a></li>
  117. <li><a class="reference internal" href="#inspect">inspect</a></li>
  118. <li><a class="reference internal" href="#locale">locale</a></li>
  119. <li><a class="reference internal" href="#logging">logging</a></li>
  120. <li><a class="reference internal" href="#math">math</a></li>
  121. <li><a class="reference internal" href="#operator">operator</a></li>
  122. <li><a class="reference internal" href="#os">os</a></li>
  123. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  124. <li><a class="reference internal" href="#re">re</a></li>
  125. <li><a class="reference internal" href="#shutil">shutil</a></li>
  126. <li><a class="reference internal" href="#socket">socket</a></li>
  127. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  128. <li><a class="reference internal" href="#string">string</a></li>
  129. <li><a class="reference internal" href="#sys">sys</a></li>
  130. <li><a class="reference internal" href="#sysconfig">sysconfig</a></li>
  131. <li><a class="reference internal" href="#tempfile">tempfile</a></li>
  132. <li><a class="reference internal" href="#threading">threading</a></li>
  133. <li><a class="reference internal" href="#time">time</a></li>
  134. <li><a class="reference internal" href="#tkinter">tkinter</a></li>
  135. <li><a class="reference internal" href="#traceback">traceback</a></li>
  136. <li><a class="reference internal" href="#typing">typing</a></li>
  137. <li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
  138. <li><a class="reference internal" href="#unittest">unittest</a></li>
  139. <li><a class="reference internal" href="#venv">venv</a></li>
  140. <li><a class="reference internal" href="#warnings">warnings</a></li>
  141. <li><a class="reference internal" href="#zipfile">zipfile</a></li>
  142. </ul>
  143. </li>
  144. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  145. <li><a class="reference internal" href="#faster-cpython">Faster CPython</a><ul>
  146. <li><a class="reference internal" href="#faster-startup">Faster Startup</a><ul>
  147. <li><a class="reference internal" href="#frozen-imports-static-code-objects">Frozen imports / Static code objects</a></li>
  148. </ul>
  149. </li>
  150. <li><a class="reference internal" href="#faster-runtime">Faster Runtime</a><ul>
  151. <li><a class="reference internal" href="#cheaper-lazy-python-frames">Cheaper, lazy Python frames</a></li>
  152. <li><a class="reference internal" href="#inlined-python-function-calls">Inlined Python function calls</a></li>
  153. <li><a class="reference internal" href="#pep-659-specializing-adaptive-interpreter">PEP 659: Specializing Adaptive Interpreter</a></li>
  154. </ul>
  155. </li>
  156. <li><a class="reference internal" href="#misc">Misc</a></li>
  157. <li><a class="reference internal" href="#faq">FAQ</a><ul>
  158. <li><a class="reference internal" href="#how-should-i-write-my-code-to-utilize-these-speedups">How should I write my code to utilize these speedups?</a></li>
  159. <li><a class="reference internal" href="#will-cpython-3-11-use-more-memory">Will CPython 3.11 use more memory?</a></li>
  160. <li><a class="reference internal" href="#i-don-t-see-any-speedups-in-my-workload-why">I don’t see any speedups in my workload. Why?</a></li>
  161. <li><a class="reference internal" href="#is-there-a-jit-compiler">Is there a JIT compiler?</a></li>
  162. </ul>
  163. </li>
  164. <li><a class="reference internal" href="#about">About</a></li>
  165. </ul>
  166. </li>
  167. <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a><ul>
  168. <li><a class="reference internal" href="#new-opcodes">New opcodes</a></li>
  169. <li><a class="reference internal" href="#replaced-opcodes">Replaced opcodes</a></li>
  170. <li><a class="reference internal" href="#changed-removed-opcodes">Changed/removed opcodes</a></li>
  171. </ul>
  172. </li>
  173. <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
  174. <li><a class="reference internal" href="#language-builtins">Language/Builtins</a></li>
  175. <li><a class="reference internal" href="#modules">Modules</a></li>
  176. <li><a class="reference internal" href="#standard-library">Standard Library</a></li>
  177. </ul>
  178. </li>
  179. <li><a class="reference internal" href="#pending-removal-in-python-3-12">Pending Removal in Python 3.12</a></li>
  180. <li><a class="reference internal" href="#removed">Removed</a></li>
  181. <li><a class="reference internal" href="#porting-to-python-3-11">Porting to Python 3.11</a></li>
  182. <li><a class="reference internal" href="#build-changes">Build Changes</a></li>
  183. <li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
  184. <li><a class="reference internal" href="#whatsnew311-c-api-new-features">New Features</a></li>
  185. <li><a class="reference internal" href="#whatsnew311-c-api-porting">Porting to Python 3.11</a></li>
  186. <li><a class="reference internal" href="#whatsnew311-c-api-deprecated">Deprecated</a></li>
  187. <li><a class="reference internal" href="#whatsnew311-c-api-pending-removal">Pending Removal in Python 3.12</a></li>
  188. <li><a class="reference internal" href="#whatsnew311-c-api-removed">Removed</a></li>
  189. </ul>
  190. </li>
  191. <li><a class="reference internal" href="#notable-changes-in-3-11-4">Notable changes in 3.11.4</a><ul>
  192. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  193. </ul>
  194. </li>
  195. <li><a class="reference internal" href="#notable-changes-in-3-11-5">Notable changes in 3.11.5</a><ul>
  196. <li><a class="reference internal" href="#openssl">OpenSSL</a></li>
  197. </ul>
  198. </li>
  199. </ul>
  200. </li>
  201. </ul>
  202. </div>
  203. <div>
  204. <h4>Previous topic</h4>
  205. <p class="topless"><a href="3.12.html"
  206. title="previous chapter">What’s New In Python 3.12</a></p>
  207. </div>
  208. <div>
  209. <h4>Next topic</h4>
  210. <p class="topless"><a href="3.10.html"
  211. title="next chapter">What’s New In Python 3.10</a></p>
  212. </div>
  213. <div role="note" aria-label="source link">
  214. <h3>This Page</h3>
  215. <ul class="this-page-menu">
  216. <li><a href="../bugs.html">Report a Bug</a></li>
  217. <li>
  218. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.11.rst"
  219. rel="nofollow">Show Source
  220. </a>
  221. </li>
  222. </ul>
  223. </div>
  224. </nav>
  225. </div>
  226. </div>
  227. <div class="related" role="navigation" aria-label="related navigation">
  228. <h3>Navigation</h3>
  229. <ul>
  230. <li class="right" style="margin-right: 10px">
  231. <a href="../genindex.html" title="General Index"
  232. accesskey="I">index</a></li>
  233. <li class="right" >
  234. <a href="../py-modindex.html" title="Python Module Index"
  235. >modules</a> |</li>
  236. <li class="right" >
  237. <a href="3.10.html" title="What’s New In Python 3.10"
  238. accesskey="N">next</a> |</li>
  239. <li class="right" >
  240. <a href="3.12.html" title="What’s New In Python 3.12"
  241. accesskey="P">previous</a> |</li>
  242. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  243. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  244. <li class="switchers">
  245. <div class="language_switcher_placeholder"></div>
  246. <div class="version_switcher_placeholder"></div>
  247. </li>
  248. <li>
  249. </li>
  250. <li id="cpython-language-and-version">
  251. <a href="../index.html">3.12.3 Documentation</a> &#187;
  252. </li>
  253. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> &#187;</li>
  254. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.11</a></li>
  255. <li class="right">
  256. <div class="inline-search" role="search">
  257. <form class="inline-search" action="../search.html" method="get">
  258. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  259. <input type="submit" value="Go" />
  260. </form>
  261. </div>
  262. |
  263. </li>
  264. <li class="right">
  265. <label class="theme-selector-label">
  266. Theme
  267. <select class="theme-selector" oninput="activateTheme(this.value)">
  268. <option value="auto" selected>Auto</option>
  269. <option value="light">Light</option>
  270. <option value="dark">Dark</option>
  271. </select>
  272. </label> |</li>
  273. </ul>
  274. </div>
  275. <div class="document">
  276. <div class="documentwrapper">
  277. <div class="bodywrapper">
  278. <div class="body" role="main">
  279. <section id="what-s-new-in-python-3-11">
  280. <h1>What’s New In Python 3.11<a class="headerlink" href="#what-s-new-in-python-3-11" title="Link to this heading">¶</a></h1>
  281. <dl class="field-list simple">
  282. <dt class="field-odd">Editor<span class="colon">:</span></dt>
  283. <dd class="field-odd"><p>Pablo Galindo Salgado</p>
  284. </dd>
  285. </dl>
  286. <p>This article explains the new features in Python 3.11, compared to 3.10.
  287. Python 3.11 was released on October 24, 2022.
  288. For full details, see the <a class="reference internal" href="changelog.html#changelog"><span class="std std-ref">changelog</span></a>.</p>
  289. <section id="summary-release-highlights">
  290. <span id="whatsnew311-summary"></span><h2>Summary – Release highlights<a class="headerlink" href="#summary-release-highlights" title="Link to this heading">¶</a></h2>
  291. <ul class="simple">
  292. <li><p>Python 3.11 is between 10-60% faster than Python 3.10.
  293. On average, we measured a 1.25x speedup on the standard benchmark suite.
  294. See <a class="reference internal" href="#whatsnew311-faster-cpython"><span class="std std-ref">Faster CPython</span></a> for details.</p></li>
  295. </ul>
  296. <p>New syntax features:</p>
  297. <ul class="simple">
  298. <li><p><a class="reference internal" href="#whatsnew311-pep654"><span class="std std-ref">PEP 654: Exception Groups and except*</span></a></p></li>
  299. </ul>
  300. <p>New built-in features:</p>
  301. <ul class="simple">
  302. <li><p><a class="reference internal" href="#whatsnew311-pep678"><span class="std std-ref">PEP 678: Exceptions can be enriched with notes</span></a></p></li>
  303. </ul>
  304. <p>New standard library modules:</p>
  305. <ul class="simple">
  306. <li><p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0680/"><strong>PEP 680</strong></a>: <a class="reference internal" href="../library/tomllib.html#module-tomllib" title="tomllib: Parse TOML files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tomllib</span></code></a> —
  307. Support for parsing <a class="reference external" href="https://toml.io/">TOML</a> in the Standard Library</p></li>
  308. </ul>
  309. <p>Interpreter improvements:</p>
  310. <ul class="simple">
  311. <li><p><a class="reference internal" href="#whatsnew311-pep657"><span class="std std-ref">PEP 657: Fine-grained error locations in tracebacks</span></a></p></li>
  312. <li><p>New <a class="reference internal" href="../using/cmdline.html#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a> command line option and <span class="target" id="index-1"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSAFEPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSAFEPATH</span></code></a> environment
  313. variable to <a class="reference internal" href="#whatsnew311-pythonsafepath"><span class="std std-ref">disable automatically prepending potentially unsafe paths</span></a> to <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>
  314. </ul>
  315. <p>New typing features:</p>
  316. <ul class="simple">
  317. <li><p><a class="reference internal" href="#whatsnew311-pep646"><span class="std std-ref">PEP 646: Variadic generics</span></a></p></li>
  318. <li><p><a class="reference internal" href="#whatsnew311-pep655"><span class="std std-ref">PEP 655: Marking individual TypedDict items as required or not-required</span></a></p></li>
  319. <li><p><a class="reference internal" href="#whatsnew311-pep673"><span class="std std-ref">PEP 673: Self type</span></a></p></li>
  320. <li><p><a class="reference internal" href="#whatsnew311-pep675"><span class="std std-ref">PEP 675: Arbitrary literal string type</span></a></p></li>
  321. <li><p><a class="reference internal" href="#whatsnew311-pep681"><span class="std std-ref">PEP 681: Data class transforms</span></a></p></li>
  322. </ul>
  323. <p>Important deprecations, removals and restrictions:</p>
  324. <ul class="simple">
  325. <li><p><span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a>:
  326. <a class="reference internal" href="#whatsnew311-pep594"><span class="std std-ref">Many legacy standard library modules have been deprecated</span></a> and will be removed in Python 3.13</p></li>
  327. <li><p><span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0624/"><strong>PEP 624</strong></a>:
  328. <a class="reference internal" href="#whatsnew311-pep624"><span class="std std-ref">Py_UNICODE encoder APIs have been removed</span></a></p></li>
  329. <li><p><span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0670/"><strong>PEP 670</strong></a>:
  330. <a class="reference internal" href="#whatsnew311-pep670"><span class="std std-ref">Macros converted to static inline functions</span></a></p></li>
  331. </ul>
  332. </section>
  333. <section id="new-features">
  334. <span id="whatsnew311-features"></span><h2>New Features<a class="headerlink" href="#new-features" title="Link to this heading">¶</a></h2>
  335. <section id="pep-657-fine-grained-error-locations-in-tracebacks">
  336. <span id="whatsnew311-pep657"></span><h3>PEP 657: Fine-grained error locations in tracebacks<a class="headerlink" href="#pep-657-fine-grained-error-locations-in-tracebacks" title="Link to this heading">¶</a></h3>
  337. <p>When printing tracebacks, the interpreter will now point to the exact expression
  338. that caused the error, instead of just the line. For example:</p>
  339. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
  340. <span class="n">File</span> <span class="s2">&quot;distance.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">11</span><span class="p">,</span> <span class="ow">in</span> <span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span>
  341. <span class="nb">print</span><span class="p">(</span><span class="n">manhattan_distance</span><span class="p">(</span><span class="n">p1</span><span class="p">,</span> <span class="n">p2</span><span class="p">))</span>
  342. <span class="o">^^^^^^^^^^^^^^^^^^^^^^^^^^</span>
  343. <span class="n">File</span> <span class="s2">&quot;distance.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">6</span><span class="p">,</span> <span class="ow">in</span> <span class="n">manhattan_distance</span>
  344. <span class="k">return</span> <span class="nb">abs</span><span class="p">(</span><span class="n">point_1</span><span class="o">.</span><span class="n">x</span> <span class="o">-</span> <span class="n">point_2</span><span class="o">.</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="nb">abs</span><span class="p">(</span><span class="n">point_1</span><span class="o">.</span><span class="n">y</span> <span class="o">-</span> <span class="n">point_2</span><span class="o">.</span><span class="n">y</span><span class="p">)</span>
  345. <span class="o">^^^^^^^^^</span>
  346. <span class="ne">AttributeError</span><span class="p">:</span> <span class="s1">&#39;NoneType&#39;</span> <span class="nb">object</span> <span class="n">has</span> <span class="n">no</span> <span class="n">attribute</span> <span class="s1">&#39;x&#39;</span>
  347. </pre></div>
  348. </div>
  349. <p>Previous versions of the interpreter would point to just the line, making it
  350. ambiguous which object was <code class="docutils literal notranslate"><span class="pre">None</span></code>. These enhanced errors can also be helpful
  351. when dealing with deeply nested <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> objects and multiple function calls:</p>
  352. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
  353. <span class="n">File</span> <span class="s2">&quot;query.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">37</span><span class="p">,</span> <span class="ow">in</span> <span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span>
  354. <span class="n">magic_arithmetic</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">)</span>
  355. <span class="n">File</span> <span class="s2">&quot;query.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">18</span><span class="p">,</span> <span class="ow">in</span> <span class="n">magic_arithmetic</span>
  356. <span class="k">return</span> <span class="n">add_counts</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">/</span> <span class="mi">25</span>
  357. <span class="o">^^^^^^^^^^^^^</span>
  358. <span class="n">File</span> <span class="s2">&quot;query.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">24</span><span class="p">,</span> <span class="ow">in</span> <span class="n">add_counts</span>
  359. <span class="k">return</span> <span class="mi">25</span> <span class="o">+</span> <span class="n">query_user</span><span class="p">(</span><span class="n">user1</span><span class="p">)</span> <span class="o">+</span> <span class="n">query_user</span><span class="p">(</span><span class="n">user2</span><span class="p">)</span>
  360. <span class="o">^^^^^^^^^^^^^^^^^</span>
  361. <span class="n">File</span> <span class="s2">&quot;query.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">32</span><span class="p">,</span> <span class="ow">in</span> <span class="n">query_user</span>
  362. <span class="k">return</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">query_count</span><span class="p">(</span><span class="n">db</span><span class="p">,</span> <span class="n">response</span><span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">][</span><span class="s1">&#39;b&#39;</span><span class="p">][</span><span class="s1">&#39;c&#39;</span><span class="p">][</span><span class="s1">&#39;user&#39;</span><span class="p">],</span> <span class="n">retry</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
  363. <span class="o">~~~~~~~~~~~~~~~~~~^^^^^</span>
  364. <span class="ne">TypeError</span><span class="p">:</span> <span class="s1">&#39;NoneType&#39;</span> <span class="nb">object</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">subscriptable</span>
  365. </pre></div>
  366. </div>
  367. <p>As well as complex arithmetic expressions:</p>
  368. <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">Traceback</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">last</span><span class="p">):</span>
  369. <span class="n">File</span> <span class="s2">&quot;calculation.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">54</span><span class="p">,</span> <span class="ow">in</span> <span class="o">&lt;</span><span class="n">module</span><span class="o">&gt;</span>
  370. <span class="n">result</span> <span class="o">=</span> <span class="p">(</span><span class="n">x</span> <span class="o">/</span> <span class="n">y</span> <span class="o">/</span> <span class="n">z</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">a</span> <span class="o">/</span> <span class="n">b</span> <span class="o">/</span> <span class="n">c</span><span class="p">)</span>
  371. <span class="o">~~~~~~^~~</span>
  372. <span class="ne">ZeroDivisionError</span><span class="p">:</span> <span class="n">division</span> <span class="n">by</span> <span class="n">zero</span>
  373. </pre></div>
  374. </div>
  375. <p>Additionally, the information used by the enhanced traceback feature
  376. is made available via a general API, that can be used to correlate
  377. <a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a> <a class="reference internal" href="../library/dis.html#bytecodes"><span class="std std-ref">instructions</span></a> with source code location.
  378. This information can be retrieved using:</p>
  379. <ul class="simple">
  380. <li><p>The <a class="reference internal" href="../reference/datamodel.html#codeobject.co_positions" title="codeobject.co_positions"><code class="xref py py-meth docutils literal notranslate"><span class="pre">codeobject.co_positions()</span></code></a> method in Python.</p></li>
  381. <li><p>The <a class="reference internal" href="../c-api/code.html#c.PyCode_Addr2Location" title="PyCode_Addr2Location"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_Addr2Location()</span></code></a> function in the C API.</p></li>
  382. </ul>
  383. <p>See <span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0657/"><strong>PEP 657</strong></a> for more details. (Contributed by Pablo Galindo, Batuhan Taskaya
  384. and Ammar Askar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43950">bpo-43950</a>.)</p>
  385. <div class="admonition note">
  386. <p class="admonition-title">Note</p>
  387. <p>This feature requires storing column positions in <a class="reference internal" href="../c-api/code.html#codeobjects"><span class="std std-ref">Code Objects</span></a>,
  388. which may result in a small increase in interpreter memory usage
  389. and disk usage for compiled Python files.
  390. To avoid storing the extra information
  391. and deactivate printing the extra traceback information,
  392. use the <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">no_debug_ranges</span></code></a> command line option
  393. or the <span class="target" id="index-6"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONNODEBUGRANGES"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONNODEBUGRANGES</span></code></a> environment variable.</p>
  394. </div>
  395. </section>
  396. <section id="pep-654-exception-groups-and-except">
  397. <span id="whatsnew311-pep654"></span><h3>PEP 654: Exception Groups and <code class="docutils literal notranslate"><span class="pre">except*</span></code><a class="headerlink" href="#pep-654-exception-groups-and-except" title="Link to this heading">¶</a></h3>
  398. <p><span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0654/"><strong>PEP 654</strong></a> introduces language features that enable a program
  399. to raise and handle multiple unrelated exceptions simultaneously.
  400. The builtin types <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> and <a class="reference internal" href="../library/exceptions.html#BaseExceptionGroup" title="BaseExceptionGroup"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseExceptionGroup</span></code></a>
  401. make it possible to group exceptions and raise them together,
  402. and the new <a class="reference internal" href="../reference/compound_stmts.html#except-star"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except*</span></code></a> syntax generalizes
  403. <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> to match subgroups of exception groups.</p>
  404. <p>See <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0654/"><strong>PEP 654</strong></a> for more details.</p>
  405. <p>(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45292">bpo-45292</a>. PEP written by
  406. Irit Katriel, Yury Selivanov and Guido van Rossum.)</p>
  407. </section>
  408. <section id="pep-678-exceptions-can-be-enriched-with-notes">
  409. <span id="whatsnew311-pep678"></span><h3>PEP 678: Exceptions can be enriched with notes<a class="headerlink" href="#pep-678-exceptions-can-be-enriched-with-notes" title="Link to this heading">¶</a></h3>
  410. <p>The <a class="reference internal" href="../library/exceptions.html#BaseException.add_note" title="BaseException.add_note"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add_note()</span></code></a> method is added to <a class="reference internal" href="../library/exceptions.html#BaseException" title="BaseException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BaseException</span></code></a>.
  411. It can be used to enrich exceptions with context information
  412. that is not available at the time when the exception is raised.
  413. The added notes appear in the default traceback.</p>
  414. <p>See <span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0678/"><strong>PEP 678</strong></a> for more details.</p>
  415. <p>(Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45607">bpo-45607</a>.
  416. PEP written by Zac Hatfield-Dodds.)</p>
  417. </section>
  418. <section id="windows-py-exe-launcher-improvements">
  419. <span id="whatsnew311-windows-launcher"></span><h3>Windows <code class="docutils literal notranslate"><span class="pre">py.exe</span></code> launcher improvements<a class="headerlink" href="#windows-py-exe-launcher-improvements" title="Link to this heading">¶</a></h3>
  420. <p>The copy of the <a class="reference internal" href="../using/windows.html#launcher"><span class="std std-ref">Python Launcher for Windows</span></a> included with Python 3.11 has been significantly
  421. updated. It now supports company/tag syntax as defined in <span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0514/"><strong>PEP 514</strong></a> using the
  422. <code class="samp docutils literal notranslate"><span class="pre">-V:</span><em><span class="pre">&lt;company&gt;</span></em><span class="pre">/</span><em><span class="pre">&lt;tag&gt;</span></em></code> argument instead of the limited <code class="samp docutils literal notranslate"><span class="pre">-</span><em><span class="pre">&lt;major&gt;</span></em><span class="pre">.</span><em><span class="pre">&lt;minor&gt;</span></em></code>.
  423. This allows launching distributions other than <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>,
  424. the one hosted on <a class="reference external" href="https://www.python.org">python.org</a>.</p>
  425. <p>When using <code class="docutils literal notranslate"><span class="pre">-V:</span></code> selectors, either company or tag can be omitted, but all
  426. installs will be searched. For example, <code class="docutils literal notranslate"><span class="pre">-V:OtherPython/</span></code> will select the
  427. “best” tag registered for <code class="docutils literal notranslate"><span class="pre">OtherPython</span></code>, while <code class="docutils literal notranslate"><span class="pre">-V:3.11</span></code> or <code class="docutils literal notranslate"><span class="pre">-V:/3.11</span></code>
  428. will select the “best” distribution with tag <code class="docutils literal notranslate"><span class="pre">3.11</span></code>.</p>
  429. <p>When using the legacy <code class="samp docutils literal notranslate"><span class="pre">-</span><em><span class="pre">&lt;major&gt;</span></em></code>, <code class="samp docutils literal notranslate"><span class="pre">-</span><em><span class="pre">&lt;major&gt;</span></em><span class="pre">.</span><em><span class="pre">&lt;minor&gt;</span></em></code>,
  430. <code class="samp docutils literal notranslate"><span class="pre">-</span><em><span class="pre">&lt;major&gt;</span></em><span class="pre">-</span><em><span class="pre">&lt;bitness&gt;</span></em></code> or <code class="samp docutils literal notranslate"><span class="pre">-</span><em><span class="pre">&lt;major&gt;</span></em><span class="pre">.</span><em><span class="pre">&lt;minor&gt;</span></em><span class="pre">-</span><em><span class="pre">&lt;bitness&gt;</span></em></code> arguments,
  431. all existing behaviour should be preserved from past versions,
  432. and only releases from <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code> will be selected.
  433. However, the <code class="docutils literal notranslate"><span class="pre">-64</span></code> suffix now implies “not 32-bit” (not necessarily x86-64),
  434. as there are multiple supported 64-bit platforms.
  435. 32-bit runtimes are detected by checking the runtime’s tag for a <code class="docutils literal notranslate"><span class="pre">-32</span></code> suffix.
  436. All releases of Python since 3.5 have included this in their 32-bit builds.</p>
  437. </section>
  438. </section>
  439. <section id="new-features-related-to-type-hints">
  440. <span id="whatsnew311-typing-features"></span><span id="new-feat-related-type-hints-311"></span><h2>New Features Related to Type Hints<a class="headerlink" href="#new-features-related-to-type-hints" title="Link to this heading">¶</a></h2>
  441. <p>This section covers major changes affecting <span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> type hints and
  442. 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>
  443. <section id="pep-646-variadic-generics">
  444. <span id="whatsnew311-pep646"></span><h3>PEP 646: Variadic generics<a class="headerlink" href="#pep-646-variadic-generics" title="Link to this heading">¶</a></h3>
  445. <p><span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> previously introduced <a class="reference internal" href="../library/typing.html#typing.TypeVar" title="typing.TypeVar"><code class="xref py py-data docutils literal notranslate"><span class="pre">TypeVar</span></code></a>, enabling creation
  446. of generics parameterised with a single type. <span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0646/"><strong>PEP 646</strong></a> adds
  447. <a class="reference internal" href="../library/typing.html#typing.TypeVarTuple" title="typing.TypeVarTuple"><code class="xref py py-data docutils literal notranslate"><span class="pre">TypeVarTuple</span></code></a>, enabling parameterisation
  448. with an <em>arbitrary</em> number of types. In other words,
  449. a <a class="reference internal" href="../library/typing.html#typing.TypeVarTuple" title="typing.TypeVarTuple"><code class="xref py py-data docutils literal notranslate"><span class="pre">TypeVarTuple</span></code></a> is a <em>variadic</em> type variable,
  450. enabling <em>variadic</em> generics.</p>
  451. <p>This enables a wide variety of use cases.
  452. In particular, it allows the type of array-like structures
  453. in numerical computing libraries such as NumPy and TensorFlow to be
  454. parameterised with the array <em>shape</em>. Static type checkers will now
  455. be able to catch shape-related bugs in code that uses these libraries.</p>
  456. <p>See <span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0646/"><strong>PEP 646</strong></a> for more details.</p>
  457. <p>(Contributed by Matthew Rahtz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43224">bpo-43224</a>, with contributions by
  458. Serhiy Storchaka and Jelle Zijlstra. PEP written by Mark Mendoza, Matthew
  459. Rahtz, Pradeep Kumar Srinivasan, and Vincent Siles.)</p>
  460. </section>
  461. <section id="pep-655-marking-individual-typeddict-items-as-required-or-not-required">
  462. <span id="whatsnew311-pep655"></span><h3>PEP 655: Marking individual <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> items as required or not-required<a class="headerlink" href="#pep-655-marking-individual-typeddict-items-as-required-or-not-required" title="Link to this heading">¶</a></h3>
  463. <p><a class="reference internal" href="../library/typing.html#typing.Required" title="typing.Required"><code class="xref py py-data docutils literal notranslate"><span class="pre">Required</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.NotRequired" title="typing.NotRequired"><code class="xref py py-data docutils literal notranslate"><span class="pre">NotRequired</span></code></a> provide a
  464. straightforward way to mark whether individual items in a
  465. <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> must be present. Previously, this was only possible
  466. using inheritance.</p>
  467. <p>All fields are still required by default,
  468. unless the <em>total</em> parameter is set to <code class="docutils literal notranslate"><span class="pre">False</span></code>,
  469. in which case all fields are still not-required by default.
  470. For example, the following specifies a <code class="xref py py-class docutils literal notranslate"><span class="pre">TypedDict</span></code>
  471. with one required and one not-required key:</p>
  472. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Movie</span><span class="p">(</span><span class="n">TypedDict</span><span class="p">):</span>
  473. <span class="n">title</span><span class="p">:</span> <span class="nb">str</span>
  474. <span class="n">year</span><span class="p">:</span> <span class="n">NotRequired</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span>
  475. <span class="n">m1</span><span class="p">:</span> <span class="n">Movie</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;title&quot;</span><span class="p">:</span> <span class="s2">&quot;Black Panther&quot;</span><span class="p">,</span> <span class="s2">&quot;year&quot;</span><span class="p">:</span> <span class="mi">2018</span><span class="p">}</span> <span class="c1"># OK</span>
  476. <span class="n">m2</span><span class="p">:</span> <span class="n">Movie</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;title&quot;</span><span class="p">:</span> <span class="s2">&quot;Star Wars&quot;</span><span class="p">}</span> <span class="c1"># OK (year is not required)</span>
  477. <span class="n">m3</span><span class="p">:</span> <span class="n">Movie</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;year&quot;</span><span class="p">:</span> <span class="mi">2022</span><span class="p">}</span> <span class="c1"># ERROR (missing required field title)</span>
  478. </pre></div>
  479. </div>
  480. <p>The following definition is equivalent:</p>
  481. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Movie</span><span class="p">(</span><span class="n">TypedDict</span><span class="p">,</span> <span class="n">total</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
  482. <span class="n">title</span><span class="p">:</span> <span class="n">Required</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span>
  483. <span class="n">year</span><span class="p">:</span> <span class="nb">int</span>
  484. </pre></div>
  485. </div>
  486. <p>See <span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0655/"><strong>PEP 655</strong></a> for more details.</p>
  487. <p>(Contributed by David Foster and Jelle Zijlstra in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=47087">bpo-47087</a>. PEP
  488. written by David Foster.)</p>
  489. </section>
  490. <section id="pep-673-self-type">
  491. <span id="whatsnew311-pep673"></span><h3>PEP 673: <code class="docutils literal notranslate"><span class="pre">Self</span></code> type<a class="headerlink" href="#pep-673-self-type" title="Link to this heading">¶</a></h3>
  492. <p>The new <a class="reference internal" href="../library/typing.html#typing.Self" title="typing.Self"><code class="xref py py-data docutils literal notranslate"><span class="pre">Self</span></code></a> annotation provides a simple and intuitive
  493. way to annotate methods that return an instance of their class. This
  494. behaves the same as the <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>-based approach
  495. <span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/#annotating-instance-and-class-methods"><strong>specified in PEP 484</strong></a>,
  496. but is more concise and easier to follow.</p>
  497. <p>Common use cases include alternative constructors provided as
  498. <a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">classmethod</span></code></a>s,
  499. and <a class="reference internal" href="../reference/datamodel.html#object.__enter__" title="object.__enter__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__enter__()</span></code></a> methods that return <code class="docutils literal notranslate"><span class="pre">self</span></code>:</p>
  500. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyLock</span><span class="p">:</span>
  501. <span class="k">def</span> <span class="fm">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Self</span><span class="p">:</span>
  502. <span class="bp">self</span><span class="o">.</span><span class="n">lock</span><span class="p">()</span>
  503. <span class="k">return</span> <span class="bp">self</span>
  504. <span class="o">...</span>
  505. <span class="k">class</span> <span class="nc">MyInt</span><span class="p">:</span>
  506. <span class="nd">@classmethod</span>
  507. <span class="k">def</span> <span class="nf">fromhex</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">s</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Self</span><span class="p">:</span>
  508. <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="mi">16</span><span class="p">))</span>
  509. <span class="o">...</span>
  510. </pre></div>
  511. </div>
  512. <p><a class="reference internal" href="../library/typing.html#typing.Self" title="typing.Self"><code class="xref py py-data docutils literal notranslate"><span class="pre">Self</span></code></a> can also be used to annotate method parameters
  513. or attributes of the same type as their enclosing class.</p>
  514. <p>See <span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0673/"><strong>PEP 673</strong></a> for more details.</p>
  515. <p>(Contributed by James Hilton-Balfe in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46534">bpo-46534</a>. PEP written by
  516. Pradeep Kumar Srinivasan and James Hilton-Balfe.)</p>
  517. </section>
  518. <section id="pep-675-arbitrary-literal-string-type">
  519. <span id="whatsnew311-pep675"></span><h3>PEP 675: Arbitrary literal string type<a class="headerlink" href="#pep-675-arbitrary-literal-string-type" title="Link to this heading">¶</a></h3>
  520. <p>The new <a class="reference internal" href="../library/typing.html#typing.LiteralString" title="typing.LiteralString"><code class="xref py py-data docutils literal notranslate"><span class="pre">LiteralString</span></code></a> annotation may be used to indicate
  521. that a function parameter can be of any literal string type. This allows
  522. a function to accept arbitrary literal string types, as well as strings
  523. created from other literal strings. Type checkers can then
  524. enforce that sensitive functions, such as those that execute SQL
  525. statements or shell commands, are called only with static arguments,
  526. providing protection against injection attacks.</p>
  527. <p>For example, a SQL query function could be annotated as follows:</p>
  528. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">run_query</span><span class="p">(</span><span class="n">sql</span><span class="p">:</span> <span class="n">LiteralString</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="o">...</span>
  529. <span class="o">...</span>
  530. <span class="k">def</span> <span class="nf">caller</span><span class="p">(</span>
  531. <span class="n">arbitrary_string</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span>
  532. <span class="n">query_string</span><span class="p">:</span> <span class="n">LiteralString</span><span class="p">,</span>
  533. <span class="n">table_name</span><span class="p">:</span> <span class="n">LiteralString</span><span class="p">,</span>
  534. <span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
  535. <span class="n">run_query</span><span class="p">(</span><span class="s2">&quot;SELECT * FROM students&quot;</span><span class="p">)</span> <span class="c1"># ok</span>
  536. <span class="n">run_query</span><span class="p">(</span><span class="n">query_string</span><span class="p">)</span> <span class="c1"># ok</span>
  537. <span class="n">run_query</span><span class="p">(</span><span class="s2">&quot;SELECT * FROM &quot;</span> <span class="o">+</span> <span class="n">table_name</span><span class="p">)</span> <span class="c1"># ok</span>
  538. <span class="n">run_query</span><span class="p">(</span><span class="n">arbitrary_string</span><span class="p">)</span> <span class="c1"># type checker error</span>
  539. <span class="n">run_query</span><span class="p">(</span> <span class="c1"># type checker error</span>
  540. <span class="sa">f</span><span class="s2">&quot;SELECT * FROM students WHERE name = </span><span class="si">{</span><span class="n">arbitrary_string</span><span class="si">}</span><span class="s2">&quot;</span>
  541. <span class="p">)</span>
  542. </pre></div>
  543. </div>
  544. <p>See <span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0675/"><strong>PEP 675</strong></a> for more details.</p>
  545. <p>(Contributed by Jelle Zijlstra in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=47088">bpo-47088</a>. PEP written by Pradeep
  546. Kumar Srinivasan and Graham Bleaney.)</p>
  547. </section>
  548. <section id="pep-681-data-class-transforms">
  549. <span id="whatsnew311-pep681"></span><h3>PEP 681: Data class transforms<a class="headerlink" href="#pep-681-data-class-transforms" title="Link to this heading">¶</a></h3>
  550. <p><a class="reference internal" href="../library/typing.html#typing.dataclass_transform" title="typing.dataclass_transform"><code class="xref py py-data docutils literal notranslate"><span class="pre">dataclass_transform</span></code></a> may be used to
  551. decorate a class, metaclass, or a function that is itself a decorator.
  552. The presence of <code class="docutils literal notranslate"><span class="pre">&#64;dataclass_transform()</span></code> tells a static type checker that the
  553. decorated object performs runtime “magic” that transforms a class,
  554. giving it <a class="reference internal" href="../library/dataclasses.html#dataclasses.dataclass" title="dataclasses.dataclass"><code class="xref py py-func docutils literal notranslate"><span class="pre">dataclass</span></code></a>-like behaviors.</p>
  555. <p>For example:</p>
  556. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># The create_model decorator is defined by a library.</span>
  557. <span class="nd">@typing</span><span class="o">.</span><span class="n">dataclass_transform</span><span class="p">()</span>
  558. <span class="k">def</span> <span class="nf">create_model</span><span class="p">(</span><span class="bp">cls</span><span class="p">:</span> <span class="n">Type</span><span class="p">[</span><span class="n">T</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">Type</span><span class="p">[</span><span class="n">T</span><span class="p">]:</span>
  559. <span class="bp">cls</span><span class="o">.</span><span class="fm">__init__</span> <span class="o">=</span> <span class="o">...</span>
  560. <span class="bp">cls</span><span class="o">.</span><span class="fm">__eq__</span> <span class="o">=</span> <span class="o">...</span>
  561. <span class="bp">cls</span><span class="o">.</span><span class="fm">__ne__</span> <span class="o">=</span> <span class="o">...</span>
  562. <span class="k">return</span> <span class="bp">cls</span>
  563. <span class="c1"># The create_model decorator can now be used to create new model classes:</span>
  564. <span class="nd">@create_model</span>
  565. <span class="k">class</span> <span class="nc">CustomerModel</span><span class="p">:</span>
  566. <span class="nb">id</span><span class="p">:</span> <span class="nb">int</span>
  567. <span class="n">name</span><span class="p">:</span> <span class="nb">str</span>
  568. <span class="n">c</span> <span class="o">=</span> <span class="n">CustomerModel</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="mi">327</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">&quot;Eric Idle&quot;</span><span class="p">)</span>
  569. </pre></div>
  570. </div>
  571. <p>See <span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0681/"><strong>PEP 681</strong></a> for more details.</p>
  572. <p>(Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/91860">gh-91860</a>. PEP written by
  573. Erik De Bonte and Eric Traut.)</p>
  574. </section>
  575. <section id="pep-563-may-not-be-the-future">
  576. <span id="whatsnew311-pep563-deferred"></span><h3>PEP 563 may not be the future<a class="headerlink" href="#pep-563-may-not-be-the-future" title="Link to this heading">¶</a></h3>
  577. <p><span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0563/"><strong>PEP 563</strong></a> Postponed Evaluation of Annotations
  578. (the <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">annotations</span></code> <a class="reference internal" href="../reference/simple_stmts.html#future"><span class="std std-ref">future statement</span></a>)
  579. that was originally planned for release in Python 3.10
  580. has been put on hold indefinitely.
  581. See <a class="reference external" href="https://mail.python.org/archives/list/python-dev&#64;python.org/message/VIZEBX5EYMSYIJNDBF6DMUMZOCWHARSO/">this message from the Steering Council</a>
  582. for more information.</p>
  583. </section>
  584. </section>
  585. <section id="other-language-changes">
  586. <span id="whatsnew311-other-lang-changes"></span><h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading">¶</a></h2>
  587. <ul class="simple">
  588. <li><p>Starred unpacking expressions can now be used in <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> statements.
  589. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46725">bpo-46725</a> for more details.)</p></li>
  590. <li><p>Asynchronous <a class="reference internal" href="../reference/expressions.html#comprehensions"><span class="std std-ref">comprehensions</span></a> are now allowed
  591. inside comprehensions in <a class="reference internal" href="../reference/compound_stmts.html#async-def"><span class="std std-ref">asynchronous functions</span></a>.
  592. Outer comprehensions implicitly become asynchronous in this case.
  593. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33346">bpo-33346</a>.)</p></li>
  594. <li><p>A <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> is now raised instead of an <a class="reference internal" href="../library/exceptions.html#AttributeError" title="AttributeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AttributeError</span></code></a> in
  595. <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statements and <a class="reference internal" href="../library/contextlib.html#contextlib.ExitStack.enter_context" title="contextlib.ExitStack.enter_context"><code class="xref py py-meth docutils literal notranslate"><span class="pre">contextlib.ExitStack.enter_context()</span></code></a>
  596. for objects that do not support the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> protocol,
  597. and in <a class="reference internal" href="../reference/compound_stmts.html#async-with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">with</span></code></a> statements and
  598. <a class="reference internal" href="../library/contextlib.html#contextlib.AsyncExitStack.enter_async_context" title="contextlib.AsyncExitStack.enter_async_context"><code class="xref py py-meth docutils literal notranslate"><span class="pre">contextlib.AsyncExitStack.enter_async_context()</span></code></a>
  599. for objects not supporting the <a class="reference internal" href="../glossary.html#term-asynchronous-context-manager"><span class="xref std std-term">asynchronous context manager</span></a> protocol.
  600. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12022">bpo-12022</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44471">bpo-44471</a>.)</p></li>
  601. <li><p>Added <a class="reference internal" href="../library/pickle.html#object.__getstate__" title="object.__getstate__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__getstate__()</span></code></a>, which provides the default
  602. implementation of the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__getstate__()</span></code> method. <a class="reference internal" href="../library/copy.html#module-copy" title="copy: Shallow and deep copy operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">copy</span></code></a>ing
  603. and <a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a>ing instances of subclasses of builtin types
  604. <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>, <a class="reference internal" href="../library/stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#frozenset" title="frozenset"><code class="xref py py-class docutils literal notranslate"><span class="pre">frozenset</span></code></a>,
  605. <a class="reference internal" href="../library/collections.html#collections.OrderedDict" title="collections.OrderedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.OrderedDict</span></code></a>, <a class="reference internal" href="../library/collections.html#collections.deque" title="collections.deque"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.deque</span></code></a>,
  606. <a class="reference internal" href="../library/weakref.html#weakref.WeakSet" title="weakref.WeakSet"><code class="xref py py-class docutils literal notranslate"><span class="pre">weakref.WeakSet</span></code></a>, and <a class="reference internal" href="../library/datetime.html#datetime.tzinfo" title="datetime.tzinfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.tzinfo</span></code></a> now copies and
  607. pickles instance attributes implemented as <a class="reference internal" href="../glossary.html#term-__slots__"><span class="xref std std-term">slots</span></a>.
  608. This change has an unintended side effect: It trips up a small minority
  609. of existing Python projects not expecting <a class="reference internal" href="../library/pickle.html#object.__getstate__" title="object.__getstate__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__getstate__()</span></code></a> to
  610. exist. See the later comments on <a class="reference external" href="https://github.com/python/cpython/issues/70766">gh-70766</a> for discussions of what
  611. workarounds such code may need.
  612. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26579">bpo-26579</a>.)</p></li>
  613. </ul>
  614. <ul class="simple" id="whatsnew311-pythonsafepath">
  615. <li><p>Added a <a class="reference internal" href="../using/cmdline.html#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a> command line option
  616. and a <span class="target" id="index-21"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSAFEPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSAFEPATH</span></code></a> environment variable,
  617. which disable the automatic prepending to <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>
  618. of the script’s directory when running a script,
  619. or the current directory when using <a class="reference internal" href="../using/cmdline.html#cmdoption-c"><code class="xref std std-option docutils literal notranslate"><span class="pre">-c</span></code></a> and <a class="reference internal" href="../using/cmdline.html#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a>.
  620. This ensures only stdlib and installed modules
  621. are picked up by <a class="reference internal" href="../reference/simple_stmts.html#import"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a>,
  622. and avoids unintentionally or maliciously shadowing modules
  623. with those in a local (and typically user-writable) directory.
  624. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/57684">gh-57684</a>.)</p></li>
  625. <li><p>A <code class="docutils literal notranslate"><span class="pre">&quot;z&quot;</span></code> option was added to the <a class="reference internal" href="../library/string.html#formatspec"><span class="std std-ref">Format Specification Mini-Language</span></a> that
  626. coerces negative to positive zero after rounding to the format precision.
  627. See <span class="target" id="index-22"></span><a class="pep reference external" href="https://peps.python.org/pep-0682/"><strong>PEP 682</strong></a> for more details.
  628. (Contributed by John Belmonte in <a class="reference external" href="https://github.com/python/cpython/issues/90153">gh-90153</a>.)</p></li>
  629. <li><p>Bytes are no longer accepted on <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>. Support broke sometime
  630. between Python 3.2 and 3.6, with no one noticing until after Python 3.10.0
  631. was released. In addition, bringing back support would be problematic due to
  632. interactions between <a class="reference internal" href="../using/cmdline.html#cmdoption-b"><code class="xref std std-option docutils literal notranslate"><span class="pre">-b</span></code></a> and <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a> when
  633. there is a mixture of <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> and <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> keys.
  634. (Contributed by Thomas Grainger in <a class="reference external" href="https://github.com/python/cpython/issues/91181">gh-91181</a>.)</p></li>
  635. </ul>
  636. </section>
  637. <section id="other-cpython-implementation-changes">
  638. <span id="whatsnew311-other-implementation-changes"></span><h2>Other CPython Implementation Changes<a class="headerlink" href="#other-cpython-implementation-changes" title="Link to this heading">¶</a></h2>
  639. <ul class="simple">
  640. <li><p>The special methods <a class="reference internal" href="../reference/datamodel.html#object.__complex__" title="object.__complex__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__complex__()</span></code></a> for <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a>
  641. and <a class="reference internal" href="../reference/datamodel.html#object.__bytes__" title="object.__bytes__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__bytes__()</span></code></a> for <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> are implemented to support
  642. the <a class="reference internal" href="../library/typing.html#typing.SupportsComplex" title="typing.SupportsComplex"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.SupportsComplex</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.SupportsBytes" title="typing.SupportsBytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.SupportsBytes</span></code></a> protocols.
  643. (Contributed by Mark Dickinson and Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24234">bpo-24234</a>.)</p></li>
  644. <li><p><code class="docutils literal notranslate"><span class="pre">siphash13</span></code> is added as a new internal hashing algorithm.
  645. It has similar security properties as <code class="docutils literal notranslate"><span class="pre">siphash24</span></code>,
  646. but it is slightly faster for long inputs.
  647. <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a>, and some other types
  648. now use it as the default algorithm for <a class="reference internal" href="../library/functions.html#hash" title="hash"><code class="xref py py-func docutils literal notranslate"><span class="pre">hash()</span></code></a>.
  649. <span class="target" id="index-23"></span><a class="pep reference external" href="https://peps.python.org/pep-0552/"><strong>PEP 552</strong></a> <a class="reference internal" href="../reference/import.html#pyc-invalidation"><span class="std std-ref">hash-based .pyc files</span></a>
  650. now use <code class="docutils literal notranslate"><span class="pre">siphash13</span></code> too.
  651. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29410">bpo-29410</a>.)</p></li>
  652. <li><p>When an active exception is re-raised by a <a class="reference internal" href="../reference/simple_stmts.html#raise"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">raise</span></code></a> statement with no parameters,
  653. the traceback attached to this exception is now always <code class="docutils literal notranslate"><span class="pre">sys.exc_info()[1].__traceback__</span></code>.
  654. This means that changes made to the traceback in the current <a class="reference internal" href="../reference/compound_stmts.html#except"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">except</span></code></a> clause are
  655. reflected in the re-raised exception.
  656. (Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45711">bpo-45711</a>.)</p></li>
  657. <li><p>The interpreter state’s representation of handled exceptions
  658. (aka <code class="docutils literal notranslate"><span class="pre">exc_info</span></code> or <code class="docutils literal notranslate"><span class="pre">_PyErr_StackItem</span></code>)
  659. now only has the <code class="docutils literal notranslate"><span class="pre">exc_value</span></code> field; <code class="docutils literal notranslate"><span class="pre">exc_type</span></code> and <code class="docutils literal notranslate"><span class="pre">exc_traceback</span></code>
  660. have been removed, as they can be derived from <code class="docutils literal notranslate"><span class="pre">exc_value</span></code>.
  661. (Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45711">bpo-45711</a>.)</p></li>
  662. <li><p>A new <a class="reference internal" href="../using/windows.html#install-quiet-option"><span class="std std-ref">command line option</span></a>, <code class="docutils literal notranslate"><span class="pre">AppendPath</span></code>,
  663. has been added for the Windows installer.
  664. It behaves similarly to <code class="docutils literal notranslate"><span class="pre">PrependPath</span></code>,
  665. but appends the install and scripts directories instead of prepending them.
  666. (Contributed by Bastian Neuburger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44934">bpo-44934</a>.)</p></li>
  667. <li><p>The <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths_set" title="PyConfig.module_search_paths_set"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths_set</span></code></a> field must now be set to <code class="docutils literal notranslate"><span class="pre">1</span></code> for
  668. initialization to use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths" title="PyConfig.module_search_paths"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths</span></code></a> to initialize
  669. <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>. Otherwise, initialization will recalculate the path and replace
  670. any values added to <code class="docutils literal notranslate"><span class="pre">module_search_paths</span></code>.</p></li>
  671. <li><p>The output of the <a class="reference internal" href="../using/cmdline.html#cmdoption-help"><code class="xref std std-option docutils literal notranslate"><span class="pre">--help</span></code></a> option now fits in 50 lines/80 columns.
  672. Information about <a class="reference internal" href="../using/cmdline.html#using-on-envvars"><span class="std std-ref">Python environment variables</span></a>
  673. and <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> options is now available using the respective
  674. <a class="reference internal" href="../using/cmdline.html#cmdoption-help-env"><code class="xref std std-option docutils literal notranslate"><span class="pre">--help-env</span></code></a> and <a class="reference internal" href="../using/cmdline.html#cmdoption-help-xoptions"><code class="xref std std-option docutils literal notranslate"><span class="pre">--help-xoptions</span></code></a> flags,
  675. and with the new <a class="reference internal" href="../using/cmdline.html#cmdoption-help-all"><code class="xref std std-option docutils literal notranslate"><span class="pre">--help-all</span></code></a>.
  676. (Contributed by Éric Araujo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46142">bpo-46142</a>.)</p></li>
  677. <li><p>Converting between <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> in bases other than 2
  678. (binary), 4, 8 (octal), 16 (hexadecimal), or 32 such as base 10 (decimal)
  679. now raises a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> if the number of digits in string form is
  680. above a limit to avoid potential denial of service attacks due to the
  681. algorithmic complexity. This is a mitigation for <a class="reference external" href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-10735">CVE-2020-10735</a>.
  682. This limit can be configured or disabled by environment variable, command
  683. line flag, or <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> APIs. See the <a class="reference internal" href="../library/stdtypes.html#int-max-str-digits"><span class="std std-ref">integer string conversion
  684. length limitation</span></a> documentation. The default limit
  685. is 4300 digits in string form.</p></li>
  686. </ul>
  687. </section>
  688. <section id="new-modules">
  689. <span id="whatsnew311-new-modules"></span><h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading">¶</a></h2>
  690. <ul class="simple">
  691. <li><p><a class="reference internal" href="../library/tomllib.html#module-tomllib" title="tomllib: Parse TOML files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tomllib</span></code></a>: For parsing <a class="reference external" href="https://toml.io/">TOML</a>.
  692. See <span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0680/"><strong>PEP 680</strong></a> for more details.
  693. (Contributed by Taneli Hukkinen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40059">bpo-40059</a>.)</p></li>
  694. <li><p><a class="reference internal" href="../library/wsgiref.html#module-wsgiref.types" title="wsgiref.types: WSGI types for static type checking"><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.types</span></code></a>:
  695. <span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-3333/"><strong>WSGI</strong></a>-specific types for static type checking.
  696. (Contributed by Sebastian Rittau in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42012">bpo-42012</a>.)</p></li>
  697. </ul>
  698. </section>
  699. <section id="improved-modules">
  700. <span id="whatsnew311-improved-modules"></span><h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading">¶</a></h2>
  701. <section id="asyncio">
  702. <span id="whatsnew311-asyncio"></span><h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading">¶</a></h3>
  703. <ul class="simple">
  704. <li><p>Added the <a class="reference internal" href="../library/asyncio-task.html#asyncio.TaskGroup" title="asyncio.TaskGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">TaskGroup</span></code></a> class,
  705. an <a class="reference internal" href="../reference/datamodel.html#async-context-managers"><span class="std std-ref">asynchronous context manager</span></a>
  706. holding a group of tasks that will wait for all of them upon exit.
  707. For new code this is recommended over using
  708. <a class="reference internal" href="../library/asyncio-task.html#asyncio.create_task" title="asyncio.create_task"><code class="xref py py-func docutils literal notranslate"><span class="pre">create_task()</span></code></a> and <a class="reference internal" href="../library/asyncio-task.html#asyncio.gather" title="asyncio.gather"><code class="xref py py-func docutils literal notranslate"><span class="pre">gather()</span></code></a> directly.
  709. (Contributed by Yury Selivanov and others in <a class="reference external" href="https://github.com/python/cpython/issues/90908">gh-90908</a>.)</p></li>
  710. <li><p>Added <a class="reference internal" href="../library/asyncio-task.html#asyncio.timeout" title="asyncio.timeout"><code class="xref py py-func docutils literal notranslate"><span class="pre">timeout()</span></code></a>, an asynchronous context manager for
  711. setting a timeout on asynchronous operations. For new code this is
  712. recommended over using <a class="reference internal" href="../library/asyncio-task.html#asyncio.wait_for" title="asyncio.wait_for"><code class="xref py py-func docutils literal notranslate"><span class="pre">wait_for()</span></code></a> directly.
  713. (Contributed by Andrew Svetlov in <a class="reference external" href="https://github.com/python/cpython/issues/90927">gh-90927</a>.)</p></li>
  714. <li><p>Added the <a class="reference internal" href="../library/asyncio-runner.html#asyncio.Runner" title="asyncio.Runner"><code class="xref py py-class docutils literal notranslate"><span class="pre">Runner</span></code></a> class, which exposes the machinery
  715. used by <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">run()</span></code></a>.
  716. (Contributed by Andrew Svetlov in <a class="reference external" href="https://github.com/python/cpython/issues/91218">gh-91218</a>.)</p></li>
  717. <li><p>Added the <a class="reference internal" href="../library/asyncio-sync.html#asyncio.Barrier" title="asyncio.Barrier"><code class="xref py py-class docutils literal notranslate"><span class="pre">Barrier</span></code></a> class to the synchronization
  718. primitives in the asyncio library, and the related
  719. <a class="reference internal" href="../library/asyncio-sync.html#asyncio.BrokenBarrierError" title="asyncio.BrokenBarrierError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BrokenBarrierError</span></code></a> exception.
  720. (Contributed by Yves Duprat and Andrew Svetlov in <a class="reference external" href="https://github.com/python/cpython/issues/87518">gh-87518</a>.)</p></li>
  721. <li><p>Added keyword argument <em>all_errors</em> to <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_connection" title="asyncio.loop.create_connection"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.create_connection()</span></code></a>
  722. so that multiple connection errors can be raised as an <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>.</p></li>
  723. <li><p>Added the <a class="reference internal" href="../library/asyncio-stream.html#asyncio.StreamWriter.start_tls" title="asyncio.StreamWriter.start_tls"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.StreamWriter.start_tls()</span></code></a> method for
  724. upgrading existing stream-based connections to TLS.
  725. (Contributed by Ian Good in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34975">bpo-34975</a>.)</p></li>
  726. <li><p>Added raw datagram socket functions to the event loop:
  727. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_sendto" title="asyncio.loop.sock_sendto"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sock_sendto()</span></code></a>,
  728. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_recvfrom" title="asyncio.loop.sock_recvfrom"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sock_recvfrom()</span></code></a> and
  729. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.sock_recvfrom_into" title="asyncio.loop.sock_recvfrom_into"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sock_recvfrom_into()</span></code></a>.
  730. These have implementations in <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.SelectorEventLoop" title="asyncio.SelectorEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">SelectorEventLoop</span></code></a> and
  731. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.ProactorEventLoop" title="asyncio.ProactorEventLoop"><code class="xref py py-class docutils literal notranslate"><span class="pre">ProactorEventLoop</span></code></a>.
  732. (Contributed by Alex Grönholm in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46805">bpo-46805</a>.)</p></li>
  733. <li><p>Added <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.cancelling" title="asyncio.Task.cancelling"><code class="xref py py-meth docutils literal notranslate"><span class="pre">cancelling()</span></code></a> and
  734. <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task.uncancel" title="asyncio.Task.uncancel"><code class="xref py py-meth docutils literal notranslate"><span class="pre">uncancel()</span></code></a> methods to <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">Task</span></code></a>.
  735. These are primarily intended for internal use,
  736. notably by <a class="reference internal" href="../library/asyncio-task.html#asyncio.TaskGroup" title="asyncio.TaskGroup"><code class="xref py py-class docutils literal notranslate"><span class="pre">TaskGroup</span></code></a>.</p></li>
  737. </ul>
  738. </section>
  739. <section id="contextlib">
  740. <span id="whatsnew311-contextlib"></span><h3>contextlib<a class="headerlink" href="#contextlib" title="Link to this heading">¶</a></h3>
  741. <ul class="simple">
  742. <li><p>Added non parallel-safe <a class="reference internal" href="../library/contextlib.html#contextlib.chdir" title="contextlib.chdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">chdir()</span></code></a> context manager to change
  743. the current working directory and then restore it on exit. Simple wrapper
  744. around <a class="reference internal" href="../library/os.html#os.chdir" title="os.chdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">chdir()</span></code></a>. (Contributed by Filipe Laíns in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25625">bpo-25625</a>)</p></li>
  745. </ul>
  746. </section>
  747. <section id="dataclasses">
  748. <span id="whatsnew311-dataclasses"></span><h3>dataclasses<a class="headerlink" href="#dataclasses" title="Link to this heading">¶</a></h3>
  749. <ul class="simple">
  750. <li><p>Change field default mutability check, allowing only defaults which are
  751. <a class="reference internal" href="../glossary.html#term-hashable"><span class="xref std std-term">hashable</span></a> instead of any object which is not an instance of
  752. <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>, <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> or <a class="reference internal" href="../library/stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>. (Contributed by Eric V. Smith in
  753. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44674">bpo-44674</a>.)</p></li>
  754. </ul>
  755. </section>
  756. <section id="datetime">
  757. <span id="whatsnew311-datetime"></span><h3>datetime<a class="headerlink" href="#datetime" title="Link to this heading">¶</a></h3>
  758. <ul class="simple">
  759. <li><p>Add <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>, a convenience alias for
  760. <a class="reference internal" href="../library/datetime.html#datetime.timezone.utc" title="datetime.timezone.utc"><code class="xref py py-attr docutils literal notranslate"><span class="pre">datetime.timezone.utc</span></code></a>. (Contributed by Kabir Kwatra in <a class="reference external" href="https://github.com/python/cpython/issues/91973">gh-91973</a>.)</p></li>
  761. <li><p><a class="reference internal" href="../library/datetime.html#datetime.date.fromisoformat" title="datetime.date.fromisoformat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.date.fromisoformat()</span></code></a>, <a class="reference internal" href="../library/datetime.html#datetime.time.fromisoformat" title="datetime.time.fromisoformat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.time.fromisoformat()</span></code></a> and
  762. <a class="reference internal" href="../library/datetime.html#datetime.datetime.fromisoformat" title="datetime.datetime.fromisoformat"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.fromisoformat()</span></code></a> can now be used to parse most ISO 8601
  763. formats (barring only those that support fractional hours and minutes).
  764. (Contributed by Paul Ganssle in <a class="reference external" href="https://github.com/python/cpython/issues/80010">gh-80010</a>.)</p></li>
  765. </ul>
  766. </section>
  767. <section id="enum">
  768. <span id="whatsnew311-enum"></span><h3>enum<a class="headerlink" href="#enum" title="Link to this heading">¶</a></h3>
  769. <ul class="simple">
  770. <li><p>Renamed <code class="xref py py-class docutils literal notranslate"><span class="pre">EnumMeta</span></code> to <a class="reference internal" href="../library/enum.html#enum.EnumType" title="enum.EnumType"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnumType</span></code></a>
  771. (<code class="xref py py-class docutils literal notranslate"><span class="pre">EnumMeta</span></code> kept as an alias).</p></li>
  772. <li><p>Added <a class="reference internal" href="../library/enum.html#enum.StrEnum" title="enum.StrEnum"><code class="xref py py-class docutils literal notranslate"><span class="pre">StrEnum</span></code></a>,
  773. with members that can be used as (and must be) strings.</p></li>
  774. <li><p>Added <a class="reference internal" href="../library/enum.html#enum.ReprEnum" title="enum.ReprEnum"><code class="xref py py-class docutils literal notranslate"><span class="pre">ReprEnum</span></code></a>,
  775. which only modifies the <a class="reference internal" href="../reference/datamodel.html#object.__repr__" title="object.__repr__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__repr__()</span></code></a> of members
  776. while returning their literal values (rather than names)
  777. for <a class="reference internal" href="../reference/datamodel.html#object.__str__" title="object.__str__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__str__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__format__" title="object.__format__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__format__()</span></code></a>
  778. (used by <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a>, <a class="reference internal" href="../library/functions.html#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a> and <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-string</span></a>s).</p></li>
  779. <li><p>Changed <a class="reference internal" href="../library/enum.html#enum.Enum.__format__" title="enum.Enum.__format__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Enum.__format__()</span></code></a> (the default for
  780. <a class="reference internal" href="../library/functions.html#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a>, <a class="reference internal" href="../library/stdtypes.html#str.format" title="str.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.format()</span></code></a> and <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-string</span></a>s) to always produce
  781. the same result as <a class="reference internal" href="../library/enum.html#enum.Enum.__str__" title="enum.Enum.__str__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Enum.__str__()</span></code></a>: for enums inheriting from
  782. <a class="reference internal" href="../library/enum.html#enum.ReprEnum" title="enum.ReprEnum"><code class="xref py py-class docutils literal notranslate"><span class="pre">ReprEnum</span></code></a> it will be the member’s value; for all other enums
  783. it will be the enum and member name (e.g. <code class="docutils literal notranslate"><span class="pre">Color.RED</span></code>).</p></li>
  784. <li><p>Added a new <em>boundary</em> class parameter to <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a> enums
  785. and the <a class="reference internal" href="../library/enum.html#enum.FlagBoundary" title="enum.FlagBoundary"><code class="xref py py-class docutils literal notranslate"><span class="pre">FlagBoundary</span></code></a> enum with its options,
  786. to control how to handle out-of-range flag values.</p></li>
  787. <li><p>Added the <a class="reference internal" href="../library/enum.html#enum.verify" title="enum.verify"><code class="xref py py-func docutils literal notranslate"><span class="pre">verify()</span></code></a> enum decorator
  788. and the <a class="reference internal" href="../library/enum.html#enum.EnumCheck" title="enum.EnumCheck"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnumCheck</span></code></a> enum with its options,
  789. to check enum classes against several specific constraints.</p></li>
  790. <li><p>Added the <a class="reference internal" href="../library/enum.html#enum.member" title="enum.member"><code class="xref py py-func docutils literal notranslate"><span class="pre">member()</span></code></a> and <a class="reference internal" href="../library/enum.html#enum.nonmember" title="enum.nonmember"><code class="xref py py-func docutils literal notranslate"><span class="pre">nonmember()</span></code></a> decorators,
  791. to ensure the decorated object is/is not converted to an enum member.</p></li>
  792. <li><p>Added the <a class="reference internal" href="../library/enum.html#enum.property" title="enum.property"><code class="xref py py-func docutils literal notranslate"><span class="pre">property()</span></code></a> decorator,
  793. which works like <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-func docutils literal notranslate"><span class="pre">property()</span></code></a> except for enums.
  794. Use this instead of <a class="reference internal" href="../library/types.html#types.DynamicClassAttribute" title="types.DynamicClassAttribute"><code class="xref py py-func docutils literal notranslate"><span class="pre">types.DynamicClassAttribute()</span></code></a>.</p></li>
  795. <li><p>Added the <a class="reference internal" href="../library/enum.html#enum.global_enum" title="enum.global_enum"><code class="xref py py-func docutils literal notranslate"><span class="pre">global_enum()</span></code></a> enum decorator,
  796. which adjusts <a class="reference internal" href="../reference/datamodel.html#object.__repr__" title="object.__repr__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__repr__()</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#object.__str__" title="object.__str__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__str__()</span></code></a>
  797. to show values as members of their module rather than the enum class.
  798. For example, <code class="docutils literal notranslate"><span class="pre">'re.ASCII'</span></code> for the <a class="reference internal" href="../library/re.html#re.ASCII" title="re.ASCII"><code class="xref py py-const docutils literal notranslate"><span class="pre">ASCII</span></code></a> member
  799. of <a class="reference internal" href="../library/re.html#re.RegexFlag" title="re.RegexFlag"><code class="xref py py-class docutils literal notranslate"><span class="pre">re.RegexFlag</span></code></a> rather than <code class="docutils literal notranslate"><span class="pre">'RegexFlag.ASCII'</span></code>.</p></li>
  800. <li><p>Enhanced <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a> to support
  801. <a class="reference internal" href="../library/functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a>, iteration and <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#not-in"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">not</span> <span class="pre">in</span></code></a> on its members.
  802. For example, the following now works:
  803. <code class="docutils literal notranslate"><span class="pre">len(AFlag(3))</span> <span class="pre">==</span> <span class="pre">2</span> <span class="pre">and</span> <span class="pre">list(AFlag(3))</span> <span class="pre">==</span> <span class="pre">(AFlag.ONE,</span> <span class="pre">AFlag.TWO)</span></code></p></li>
  804. <li><p>Changed <a class="reference internal" href="../library/enum.html#enum.Enum" title="enum.Enum"><code class="xref py py-class docutils literal notranslate"><span class="pre">Enum</span></code></a> and <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a>
  805. so that members are now defined
  806. before <a class="reference internal" href="../reference/datamodel.html#object.__init_subclass__" title="object.__init_subclass__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__init_subclass__()</span></code></a> is called;
  807. <a class="reference internal" href="../library/functions.html#dir" title="dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">dir()</span></code></a> now includes methods, etc., from mixed-in data types.</p></li>
  808. <li><p>Changed <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a>
  809. to only consider primary values (power of two) canonical
  810. while composite values (<code class="docutils literal notranslate"><span class="pre">3</span></code>, <code class="docutils literal notranslate"><span class="pre">6</span></code>, <code class="docutils literal notranslate"><span class="pre">10</span></code>, etc.) are considered aliases;
  811. inverted flags are coerced to their positive equivalent.</p></li>
  812. </ul>
  813. </section>
  814. <section id="fcntl">
  815. <span id="whatsnew311-fcntl"></span><h3>fcntl<a class="headerlink" href="#fcntl" title="Link to this heading">¶</a></h3>
  816. <ul class="simple">
  817. <li><p>On FreeBSD, the <code class="xref py py-data docutils literal notranslate"><span class="pre">F_DUP2FD</span></code> and <code class="xref py py-data docutils literal notranslate"><span class="pre">F_DUP2FD_CLOEXEC</span></code> flags respectively
  818. are supported, the former equals to <code class="docutils literal notranslate"><span class="pre">dup2</span></code> usage while the latter set
  819. the <code class="docutils literal notranslate"><span class="pre">FD_CLOEXEC</span></code> flag in addition.</p></li>
  820. </ul>
  821. </section>
  822. <section id="fractions">
  823. <span id="whatsnew311-fractions"></span><h3>fractions<a class="headerlink" href="#fractions" title="Link to this heading">¶</a></h3>
  824. <ul class="simple">
  825. <li><p>Support <span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-0515/"><strong>PEP 515</strong></a>-style initialization of <a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> from
  826. string. (Contributed by Sergey B Kirpichev in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44258">bpo-44258</a>.)</p></li>
  827. <li><p><a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Fraction</span></code></a> now implements an <code class="docutils literal notranslate"><span class="pre">__int__</span></code> method, so
  828. that an <code class="docutils literal notranslate"><span class="pre">isinstance(some_fraction,</span> <span class="pre">typing.SupportsInt)</span></code> check passes.
  829. (Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44547">bpo-44547</a>.)</p></li>
  830. </ul>
  831. </section>
  832. <section id="functools">
  833. <span id="whatsnew311-functools"></span><h3>functools<a class="headerlink" href="#functools" title="Link to this heading">¶</a></h3>
  834. <ul>
  835. <li><p><a class="reference internal" href="../library/functools.html#functools.singledispatch" title="functools.singledispatch"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.singledispatch()</span></code></a> now supports <a class="reference internal" href="../library/types.html#types.UnionType" title="types.UnionType"><code class="xref py py-data docutils literal notranslate"><span class="pre">types.UnionType</span></code></a>
  836. and <a class="reference internal" href="../library/typing.html#typing.Union" title="typing.Union"><code class="xref py py-data docutils literal notranslate"><span class="pre">typing.Union</span></code></a> as annotations to the dispatch argument.:</p>
  837. <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">functools</span> <span class="kn">import</span> <span class="n">singledispatch</span>
  838. <span class="gp">&gt;&gt;&gt; </span><span class="nd">@singledispatch</span>
  839. <span class="gp">... </span><span class="k">def</span> <span class="nf">fun</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
  840. <span class="gp">... </span> <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
  841. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Let me just say,&quot;</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s2">&quot; &quot;</span><span class="p">)</span>
  842. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span>
  843. <span class="gp">...</span>
  844. <span class="gp">&gt;&gt;&gt; </span><span class="nd">@fun</span><span class="o">.</span><span class="n">register</span>
  845. <span class="gp">... </span><span class="k">def</span> <span class="nf">_</span><span class="p">(</span><span class="n">arg</span><span class="p">:</span> <span class="nb">int</span> <span class="o">|</span> <span class="nb">float</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
  846. <span class="gp">... </span> <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
  847. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Strength in numbers, eh?&quot;</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s2">&quot; &quot;</span><span class="p">)</span>
  848. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span>
  849. <span class="gp">...</span>
  850. <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">Union</span>
  851. <span class="gp">&gt;&gt;&gt; </span><span class="nd">@fun</span><span class="o">.</span><span class="n">register</span>
  852. <span class="gp">... </span><span class="k">def</span> <span class="nf">_</span><span class="p">(</span><span class="n">arg</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="nb">list</span><span class="p">,</span> <span class="nb">set</span><span class="p">],</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
  853. <span class="gp">... </span> <span class="k">if</span> <span class="n">verbose</span><span class="p">:</span>
  854. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Enumerate this:&quot;</span><span class="p">)</span>
  855. <span class="gp">... </span> <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">elem</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">arg</span><span class="p">):</span>
  856. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">elem</span><span class="p">)</span>
  857. <span class="gp">...</span>
  858. </pre></div>
  859. </div>
  860. <p>(Contributed by Yurii Karabas in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46014">bpo-46014</a>.)</p>
  861. </li>
  862. </ul>
  863. </section>
  864. <section id="hashlib">
  865. <span id="whatsnew311-hashlib"></span><h3>hashlib<a class="headerlink" href="#hashlib" title="Link to this heading">¶</a></h3>
  866. <ul class="simple">
  867. <li><p><a class="reference internal" href="../library/hashlib.html#hashlib.blake2b" title="hashlib.blake2b"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.blake2b()</span></code></a> and <a class="reference internal" href="../library/hashlib.html#hashlib.blake2s" title="hashlib.blake2s"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.blake2s()</span></code></a> now prefer <a class="reference external" href="https://www.blake2.net/">libb2</a>
  868. over Python’s vendored copy.
  869. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=47095">bpo-47095</a>.)</p></li>
  870. <li><p>The internal <code class="docutils literal notranslate"><span class="pre">_sha3</span></code> module with SHA3 and SHAKE algorithms now uses
  871. <em>tiny_sha3</em> instead of the <em>Keccak Code Package</em> to reduce code and binary
  872. size. The <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> module prefers optimized SHA3 and SHAKE
  873. implementations from OpenSSL. The change affects only installations without
  874. OpenSSL support.
  875. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=47098">bpo-47098</a>.)</p></li>
  876. <li><p>Add <a class="reference internal" href="../library/hashlib.html#hashlib.file_digest" title="hashlib.file_digest"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.file_digest()</span></code></a>, a helper function for efficient hashing
  877. of files or file-like objects.
  878. (Contributed by Christian Heimes in <a class="reference external" href="https://github.com/python/cpython/issues/89313">gh-89313</a>.)</p></li>
  879. </ul>
  880. </section>
  881. <section id="whatsnew311-idle">
  882. <span id="idle-and-idlelib"></span><h3>IDLE and idlelib<a class="headerlink" href="#whatsnew311-idle" title="Link to this heading">¶</a></h3>
  883. <ul class="simple">
  884. <li><p>Apply syntax highlighting to <code class="docutils literal notranslate"><span class="pre">.pyi</span></code> files. (Contributed by Alex
  885. Waygood and Terry Jan Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45447">bpo-45447</a>.)</p></li>
  886. <li><p>Include prompts when saving Shell with inputs and outputs.
  887. (Contributed by Terry Jan Reedy in <a class="reference external" href="https://github.com/python/cpython/issues/95191">gh-95191</a>.)</p></li>
  888. </ul>
  889. </section>
  890. <section id="inspect">
  891. <span id="whatsnew311-inspect"></span><h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading">¶</a></h3>
  892. <ul>
  893. <li><p>Add <a class="reference internal" href="../library/inspect.html#inspect.getmembers_static" title="inspect.getmembers_static"><code class="xref py py-func docutils literal notranslate"><span class="pre">getmembers_static()</span></code></a> to return all members without
  894. triggering dynamic lookup via the descriptor protocol. (Contributed by
  895. Weipeng Hong in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30533">bpo-30533</a>.)</p></li>
  896. <li><p>Add <a class="reference internal" href="../library/inspect.html#inspect.ismethodwrapper" title="inspect.ismethodwrapper"><code class="xref py py-func docutils literal notranslate"><span class="pre">ismethodwrapper()</span></code></a>
  897. for checking if the type of an object is a <a class="reference internal" href="../library/types.html#types.MethodWrapperType" title="types.MethodWrapperType"><code class="xref py py-class docutils literal notranslate"><span class="pre">MethodWrapperType</span></code></a>.
  898. (Contributed by Hakan Çelik in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29418">bpo-29418</a>.)</p></li>
  899. <li><p>Change the frame-related functions in the <a class="reference internal" href="../library/inspect.html#module-inspect" title="inspect: Extract information and source code from live objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">inspect</span></code></a> module to return new
  900. <a class="reference internal" href="../library/inspect.html#inspect.FrameInfo" title="inspect.FrameInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">FrameInfo</span></code></a> and <a class="reference internal" href="../library/inspect.html#inspect.Traceback" title="inspect.Traceback"><code class="xref py py-class docutils literal notranslate"><span class="pre">Traceback</span></code></a> class instances
  901. (backwards compatible with the previous <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named tuple</span></a>-like interfaces)
  902. that includes the extended <span class="target" id="index-27"></span><a class="pep reference external" href="https://peps.python.org/pep-0657/"><strong>PEP 657</strong></a> position information (end
  903. line number, column and end column). The affected functions are:</p>
  904. <ul class="simple">
  905. <li><p><a class="reference internal" href="../library/inspect.html#inspect.getframeinfo" title="inspect.getframeinfo"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getframeinfo()</span></code></a></p></li>
  906. <li><p><a class="reference internal" href="../library/inspect.html#inspect.getouterframes" title="inspect.getouterframes"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getouterframes()</span></code></a></p></li>
  907. <li><p><a class="reference internal" href="../library/inspect.html#inspect.getinnerframes" title="inspect.getinnerframes"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getinnerframes()</span></code></a>,</p></li>
  908. <li><p><a class="reference internal" href="../library/inspect.html#inspect.stack" title="inspect.stack"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.stack()</span></code></a></p></li>
  909. <li><p><a class="reference internal" href="../library/inspect.html#inspect.trace" title="inspect.trace"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.trace()</span></code></a></p></li>
  910. </ul>
  911. <p>(Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/88116">gh-88116</a>.)</p>
  912. </li>
  913. </ul>
  914. </section>
  915. <section id="locale">
  916. <span id="whatsnew311-locale"></span><h3>locale<a class="headerlink" href="#locale" title="Link to this heading">¶</a></h3>
  917. <ul class="simple">
  918. <li><p>Add <a class="reference internal" href="../library/locale.html#locale.getencoding" title="locale.getencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getencoding()</span></code></a> to get the current locale encoding. It is similar to
  919. <code class="docutils literal notranslate"><span class="pre">locale.getpreferredencoding(False)</span></code> but ignores the
  920. <a class="reference internal" href="../library/os.html#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a>.</p></li>
  921. </ul>
  922. </section>
  923. <section id="logging">
  924. <span id="whatsnew311-logging"></span><h3>logging<a class="headerlink" href="#logging" title="Link to this heading">¶</a></h3>
  925. <ul class="simple">
  926. <li><p>Added <a class="reference internal" href="../library/logging.html#logging.getLevelNamesMapping" title="logging.getLevelNamesMapping"><code class="xref py py-func docutils literal notranslate"><span class="pre">getLevelNamesMapping()</span></code></a>
  927. to return a mapping from logging level names (e.g. <code class="docutils literal notranslate"><span class="pre">'CRITICAL'</span></code>)
  928. to the values of their corresponding <a class="reference internal" href="../library/logging.html#levels"><span class="std std-ref">Logging Levels</span></a> (e.g. <code class="docutils literal notranslate"><span class="pre">50</span></code>, by default).
  929. (Contributed by Andrei Kulakovin in <a class="reference external" href="https://github.com/python/cpython/issues/88024">gh-88024</a>.)</p></li>
  930. <li><p>Added a <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SysLogHandler.createSocket" title="logging.handlers.SysLogHandler.createSocket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">createSocket()</span></code></a> method
  931. to <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SysLogHandler" title="logging.handlers.SysLogHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SysLogHandler</span></code></a>, to match
  932. <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SocketHandler.createSocket" title="logging.handlers.SocketHandler.createSocket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SocketHandler.createSocket()</span></code></a>.
  933. It is called automatically during handler initialization
  934. and when emitting an event, if there is no active socket.
  935. (Contributed by Kirill Pinchuk in <a class="reference external" href="https://github.com/python/cpython/issues/88457">gh-88457</a>.)</p></li>
  936. </ul>
  937. </section>
  938. <section id="math">
  939. <span id="whatsnew311-math"></span><h3>math<a class="headerlink" href="#math" title="Link to this heading">¶</a></h3>
  940. <ul class="simple">
  941. <li><p>Add <a class="reference internal" href="../library/math.html#math.exp2" title="math.exp2"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.exp2()</span></code></a>: return 2 raised to the power of x.
  942. (Contributed by Gideon Mitchell in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45917">bpo-45917</a>.)</p></li>
  943. <li><p>Add <a class="reference internal" href="../library/math.html#math.cbrt" title="math.cbrt"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.cbrt()</span></code></a>: return the cube root of x.
  944. (Contributed by Ajith Ramachandran in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44357">bpo-44357</a>.)</p></li>
  945. <li><p>The behaviour of two <a class="reference internal" href="../library/math.html#math.pow" title="math.pow"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.pow()</span></code></a> corner cases was changed, for
  946. consistency with the IEEE 754 specification. The operations
  947. <code class="docutils literal notranslate"><span class="pre">math.pow(0.0,</span> <span class="pre">-math.inf)</span></code> and <code class="docutils literal notranslate"><span class="pre">math.pow(-0.0,</span> <span class="pre">-math.inf)</span></code> now return
  948. <code class="docutils literal notranslate"><span class="pre">inf</span></code>. Previously they raised <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>. (Contributed by Mark
  949. Dickinson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44339">bpo-44339</a>.)</p></li>
  950. <li><p>The <a class="reference internal" href="../library/math.html#math.nan" title="math.nan"><code class="xref py py-data docutils literal notranslate"><span class="pre">math.nan</span></code></a> value is now always available.
  951. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46917">bpo-46917</a>.)</p></li>
  952. </ul>
  953. </section>
  954. <section id="operator">
  955. <span id="whatsnew311-operator"></span><h3>operator<a class="headerlink" href="#operator" title="Link to this heading">¶</a></h3>
  956. <ul class="simple">
  957. <li><p>A new function <code class="docutils literal notranslate"><span class="pre">operator.call</span></code> has been added, such that
  958. <code class="docutils literal notranslate"><span class="pre">operator.call(obj,</span> <span class="pre">*args,</span> <span class="pre">**kwargs)</span> <span class="pre">==</span> <span class="pre">obj(*args,</span> <span class="pre">**kwargs)</span></code>.
  959. (Contributed by Antony Lee in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44019">bpo-44019</a>.)</p></li>
  960. </ul>
  961. </section>
  962. <section id="os">
  963. <span id="whatsnew311-os"></span><h3>os<a class="headerlink" href="#os" title="Link to this heading">¶</a></h3>
  964. <ul class="simple">
  965. <li><p>On Windows, <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> now uses <code class="docutils literal notranslate"><span class="pre">BCryptGenRandom()</span></code>,
  966. instead of <code class="docutils literal notranslate"><span class="pre">CryptGenRandom()</span></code> which is deprecated.
  967. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44611">bpo-44611</a>.)</p></li>
  968. </ul>
  969. </section>
  970. <section id="pathlib">
  971. <span id="whatsnew311-pathlib"></span><h3>pathlib<a class="headerlink" href="#pathlib" title="Link to this heading">¶</a></h3>
  972. <ul class="simple">
  973. <li><p><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">glob()</span></code></a> and <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">rglob()</span></code></a> return only
  974. directories if <em>pattern</em> ends with a pathname components separator:
  975. <a class="reference internal" href="../library/os.html#os.sep" title="os.sep"><code class="xref py py-data docutils literal notranslate"><span class="pre">sep</span></code></a> or <a class="reference internal" href="../library/os.html#os.altsep" title="os.altsep"><code class="xref py py-data docutils literal notranslate"><span class="pre">altsep</span></code></a>.
  976. (Contributed by Eisuke Kawasima in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22276">bpo-22276</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33392">bpo-33392</a>.)</p></li>
  977. </ul>
  978. </section>
  979. <section id="re">
  980. <span id="whatsnew311-re"></span><h3>re<a class="headerlink" href="#re" title="Link to this heading">¶</a></h3>
  981. <ul class="simple">
  982. <li><p>Atomic grouping (<code class="docutils literal notranslate"><span class="pre">(?&gt;...)</span></code>) and possessive quantifiers (<code class="docutils literal notranslate"><span class="pre">*+</span></code>, <code class="docutils literal notranslate"><span class="pre">++</span></code>,
  983. <code class="docutils literal notranslate"><span class="pre">?+</span></code>, <code class="docutils literal notranslate"><span class="pre">{m,n}+</span></code>) are now supported in regular expressions.
  984. (Contributed by Jeffrey C. Jacobs and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=433030">bpo-433030</a>.)</p></li>
  985. </ul>
  986. </section>
  987. <section id="shutil">
  988. <span id="whatsnew311-shutil"></span><h3>shutil<a class="headerlink" href="#shutil" title="Link to this heading">¶</a></h3>
  989. <ul class="simple">
  990. <li><p>Add optional parameter <em>dir_fd</em> in <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>.
  991. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46245">bpo-46245</a>.)</p></li>
  992. </ul>
  993. </section>
  994. <section id="socket">
  995. <span id="whatsnew311-socket"></span><h3>socket<a class="headerlink" href="#socket" title="Link to this heading">¶</a></h3>
  996. <ul class="simple">
  997. <li><p>Add CAN Socket support for NetBSD.
  998. (Contributed by Thomas Klausner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30512">bpo-30512</a>.)</p></li>
  999. <li><p><a class="reference internal" href="../library/socket.html#socket.create_connection" title="socket.create_connection"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_connection()</span></code></a> has an option to raise, in case of
  1000. failure to connect, an <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> containing all errors
  1001. instead of only raising the last error.
  1002. (Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=29980">bpo-29980</a>.)</p></li>
  1003. </ul>
  1004. </section>
  1005. <section id="sqlite3">
  1006. <span id="whatsnew311-sqlite3"></span><h3>sqlite3<a class="headerlink" href="#sqlite3" title="Link to this heading">¶</a></h3>
  1007. <ul class="simple">
  1008. <li><p>You can now disable the authorizer by passing <a class="reference internal" href="../library/constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a> to
  1009. <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.set_authorizer" title="sqlite3.Connection.set_authorizer"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_authorizer()</span></code></a>.
  1010. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44491">bpo-44491</a>.)</p></li>
  1011. <li><p>Collation name <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.create_collation" title="sqlite3.Connection.create_collation"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_collation()</span></code></a> can now
  1012. contain any Unicode character. Collation names with invalid characters
  1013. now raise <a class="reference internal" href="../library/exceptions.html#UnicodeEncodeError" title="UnicodeEncodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeEncodeError</span></code></a> instead of <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">sqlite3.ProgrammingError</span></code></a>.
  1014. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44688">bpo-44688</a>.)</p></li>
  1015. <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> exceptions now include the SQLite extended error code as
  1016. <a class="reference internal" href="../library/sqlite3.html#sqlite3.Error.sqlite_errorcode" title="sqlite3.Error.sqlite_errorcode"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sqlite_errorcode</span></code></a> and the SQLite error name as
  1017. <a class="reference internal" href="../library/sqlite3.html#sqlite3.Error.sqlite_errorname" title="sqlite3.Error.sqlite_errorname"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sqlite_errorname</span></code></a>.
  1018. (Contributed by Aviv Palivoda, Daniel Shahaf, and Erlend E. Aasland in
  1019. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16379">bpo-16379</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24139">bpo-24139</a>.)</p></li>
  1020. <li><p>Add <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.setlimit" title="sqlite3.Connection.setlimit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setlimit()</span></code></a> and
  1021. <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.getlimit" title="sqlite3.Connection.getlimit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getlimit()</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> for
  1022. setting and getting SQLite limits by connection basis.
  1023. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45243">bpo-45243</a>.)</p></li>
  1024. <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> now sets <a class="reference internal" href="../library/sqlite3.html#sqlite3.threadsafety" title="sqlite3.threadsafety"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sqlite3.threadsafety</span></code></a> based on the default
  1025. threading mode the underlying SQLite library has been compiled with.
  1026. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45613">bpo-45613</a>.)</p></li>
  1027. <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> C callbacks now use unraisable exceptions if callback
  1028. tracebacks are enabled. Users can now register an
  1029. <a class="reference internal" href="../library/sys.html#sys.unraisablehook" title="sys.unraisablehook"><code class="xref py py-func docutils literal notranslate"><span class="pre">unraisable</span> <span class="pre">hook</span> <span class="pre">handler</span></code></a> to improve their debug
  1030. experience.
  1031. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45828">bpo-45828</a>.)</p></li>
  1032. <li><p>Fetch across rollback no longer raises <a class="reference internal" href="../library/sqlite3.html#sqlite3.InterfaceError" title="sqlite3.InterfaceError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterfaceError</span></code></a>.
  1033. Instead we leave it to the SQLite library to handle these cases.
  1034. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44092">bpo-44092</a>.)</p></li>
  1035. <li><p>Add <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.serialize" title="sqlite3.Connection.serialize"><code class="xref py py-meth docutils literal notranslate"><span class="pre">serialize()</span></code></a> and
  1036. <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.deserialize" title="sqlite3.Connection.deserialize"><code class="xref py py-meth docutils literal notranslate"><span class="pre">deserialize()</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> for
  1037. serializing and deserializing databases.
  1038. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41930">bpo-41930</a>.)</p></li>
  1039. <li><p>Add <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.create_window_function" title="sqlite3.Connection.create_window_function"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_window_function()</span></code></a> to
  1040. <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> for creating aggregate window functions.
  1041. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=34916">bpo-34916</a>.)</p></li>
  1042. <li><p>Add <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.blobopen" title="sqlite3.Connection.blobopen"><code class="xref py py-meth docutils literal notranslate"><span class="pre">blobopen()</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>.
  1043. <a class="reference internal" href="../library/sqlite3.html#sqlite3.Blob" title="sqlite3.Blob"><code class="xref py py-class docutils literal notranslate"><span class="pre">sqlite3.Blob</span></code></a> allows incremental I/O operations on blobs.
  1044. (Contributed by Aviv Palivoda and Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24905">bpo-24905</a>.)</p></li>
  1045. </ul>
  1046. </section>
  1047. <section id="string">
  1048. <span id="whatsnew311-string"></span><h3>string<a class="headerlink" href="#string" title="Link to this heading">¶</a></h3>
  1049. <ul class="simple">
  1050. <li><p>Add <a class="reference internal" href="../library/string.html#string.Template.get_identifiers" title="string.Template.get_identifiers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_identifiers()</span></code></a>
  1051. and <a class="reference internal" href="../library/string.html#string.Template.is_valid" title="string.Template.is_valid"><code class="xref py py-meth docutils literal notranslate"><span class="pre">is_valid()</span></code></a> to <a class="reference internal" href="../library/string.html#string.Template" title="string.Template"><code class="xref py py-class docutils literal notranslate"><span class="pre">string.Template</span></code></a>,
  1052. which respectively return all valid placeholders,
  1053. and whether any invalid placeholders are present.
  1054. (Contributed by Ben Kehoe in <a class="reference external" href="https://github.com/python/cpython/issues/90465">gh-90465</a>.)</p></li>
  1055. </ul>
  1056. </section>
  1057. <section id="sys">
  1058. <span id="whatsnew311-sys"></span><h3>sys<a class="headerlink" href="#sys" title="Link to this heading">¶</a></h3>
  1059. <ul class="simple">
  1060. <li><p><a class="reference internal" href="../library/sys.html#sys.exc_info" title="sys.exc_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exc_info()</span></code></a> now derives the <code class="docutils literal notranslate"><span class="pre">type</span></code> and <code class="docutils literal notranslate"><span class="pre">traceback</span></code> fields
  1061. from the <code class="docutils literal notranslate"><span class="pre">value</span></code> (the exception instance), so when an exception is
  1062. modified while it is being handled, the changes are reflected in
  1063. the results of subsequent calls to <code class="xref py py-func docutils literal notranslate"><span class="pre">exc_info()</span></code>.
  1064. (Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45711">bpo-45711</a>.)</p></li>
  1065. <li><p>Add <a class="reference internal" href="../library/sys.html#sys.exception" title="sys.exception"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exception()</span></code></a> which returns the active exception instance
  1066. (equivalent to <code class="docutils literal notranslate"><span class="pre">sys.exc_info()[1]</span></code>).
  1067. (Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46328">bpo-46328</a>.)</p></li>
  1068. <li><p>Add the <a class="reference internal" href="../library/sys.html#sys.flags" title="sys.flags"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.flags.safe_path</span></code></a> flag.
  1069. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/57684">gh-57684</a>.)</p></li>
  1070. </ul>
  1071. </section>
  1072. <section id="sysconfig">
  1073. <span id="whatsnew311-sysconfig"></span><h3>sysconfig<a class="headerlink" href="#sysconfig" title="Link to this heading">¶</a></h3>
  1074. <ul class="simple">
  1075. <li><p>Three new <a class="reference internal" href="../library/sysconfig.html#installation-paths"><span class="std std-ref">installation schemes</span></a>
  1076. (<em>posix_venv</em>, <em>nt_venv</em> and <em>venv</em>) were added and are used when Python
  1077. creates new virtual environments or when it is running from a virtual
  1078. environment.
  1079. The first two schemes (<em>posix_venv</em> and <em>nt_venv</em>) are OS-specific
  1080. for non-Windows and Windows, the <em>venv</em> is essentially an alias to one of
  1081. them according to the OS Python runs on.
  1082. This is useful for downstream distributors who modify
  1083. <a class="reference internal" href="../library/sysconfig.html#sysconfig.get_preferred_scheme" title="sysconfig.get_preferred_scheme"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconfig.get_preferred_scheme()</span></code></a>.
  1084. Third party code that creates new virtual environments should use the new
  1085. <em>venv</em> installation scheme to determine the paths, as does <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>.
  1086. (Contributed by Miro Hrončok in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45413">bpo-45413</a>.)</p></li>
  1087. </ul>
  1088. </section>
  1089. <section id="tempfile">
  1090. <span id="whatsnew311-tempfile"></span><h3>tempfile<a class="headerlink" href="#tempfile" title="Link to this heading">¶</a></h3>
  1091. <ul class="simple">
  1092. <li><p><a class="reference internal" href="../library/tempfile.html#tempfile.SpooledTemporaryFile" title="tempfile.SpooledTemporaryFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">SpooledTemporaryFile</span></code></a> objects now fully implement the methods
  1093. of <a class="reference internal" href="../library/io.html#io.BufferedIOBase" title="io.BufferedIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.BufferedIOBase</span></code></a> or <a class="reference internal" href="../library/io.html#io.TextIOBase" title="io.TextIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.TextIOBase</span></code></a>
  1094. (depending on file mode).
  1095. This lets them work correctly with APIs that expect file-like objects,
  1096. such as compression modules.
  1097. (Contributed by Carey Metcalfe in <a class="reference external" href="https://github.com/python/cpython/issues/70363">gh-70363</a>.)</p></li>
  1098. </ul>
  1099. </section>
  1100. <section id="threading">
  1101. <span id="whatsnew311-threading"></span><h3>threading<a class="headerlink" href="#threading" title="Link to this heading">¶</a></h3>
  1102. <ul class="simple">
  1103. <li><p>On Unix, if the <code class="docutils literal notranslate"><span class="pre">sem_clockwait()</span></code> function is available in the C library
  1104. (glibc 2.30 and newer), the <a class="reference internal" href="../library/threading.html#threading.Lock.acquire" title="threading.Lock.acquire"><code class="xref py py-meth docutils literal notranslate"><span class="pre">threading.Lock.acquire()</span></code></a> method now uses
  1105. the monotonic clock (<a class="reference internal" href="../library/time.html#time.CLOCK_MONOTONIC" title="time.CLOCK_MONOTONIC"><code class="xref py py-const docutils literal notranslate"><span class="pre">time.CLOCK_MONOTONIC</span></code></a>) for the timeout, rather
  1106. than using the system clock (<a class="reference internal" href="../library/time.html#time.CLOCK_REALTIME" title="time.CLOCK_REALTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">time.CLOCK_REALTIME</span></code></a>), to not be affected
  1107. by system clock changes.
  1108. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41710">bpo-41710</a>.)</p></li>
  1109. </ul>
  1110. </section>
  1111. <section id="time">
  1112. <span id="whatsnew311-time"></span><h3>time<a class="headerlink" href="#time" title="Link to this heading">¶</a></h3>
  1113. <ul class="simple">
  1114. <li><p>On Unix, <a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.sleep()</span></code></a> now uses the <code class="docutils literal notranslate"><span class="pre">clock_nanosleep()</span></code> or
  1115. <code class="docutils literal notranslate"><span class="pre">nanosleep()</span></code> function, if available, which has a resolution of 1 nanosecond
  1116. (10<sup>-9</sup> seconds), rather than using <code class="docutils literal notranslate"><span class="pre">select()</span></code> which has a resolution
  1117. of 1 microsecond (10<sup>-6</sup> seconds).
  1118. (Contributed by Benjamin Szőke and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21302">bpo-21302</a>.)</p></li>
  1119. <li><p>On Windows 8.1 and newer, <a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.sleep()</span></code></a> now uses a waitable timer based
  1120. on <a class="reference external" href="https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/high-resolution-timers">high-resolution timers</a>
  1121. which has a resolution of 100 nanoseconds (10<sup>-7</sup> seconds). Previously,
  1122. it had a resolution of 1 millisecond (10<sup>-3</sup> seconds).
  1123. (Contributed by Benjamin Szőke, Donghee Na, Eryk Sun and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21302">bpo-21302</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45429">bpo-45429</a>.)</p></li>
  1124. </ul>
  1125. </section>
  1126. <section id="tkinter">
  1127. <span id="whatsnew311-tkinter"></span><h3>tkinter<a class="headerlink" href="#tkinter" title="Link to this heading">¶</a></h3>
  1128. <ul class="simple">
  1129. <li><p>Added method <code class="docutils literal notranslate"><span class="pre">info_patchlevel()</span></code> which returns the exact version of
  1130. the Tcl library as a named tuple similar to <a class="reference internal" href="../library/sys.html#sys.version_info" title="sys.version_info"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.version_info</span></code></a>.
  1131. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/91827">gh-91827</a>.)</p></li>
  1132. </ul>
  1133. </section>
  1134. <section id="traceback">
  1135. <span id="whatsnew311-traceback"></span><h3>traceback<a class="headerlink" href="#traceback" title="Link to this heading">¶</a></h3>
  1136. <ul class="simple">
  1137. <li><p>Add <a class="reference internal" href="../library/traceback.html#traceback.StackSummary.format_frame_summary" title="traceback.StackSummary.format_frame_summary"><code class="xref py py-func docutils literal notranslate"><span class="pre">traceback.StackSummary.format_frame_summary()</span></code></a> to allow users
  1138. to override which frames appear in the traceback, and how they are
  1139. formatted.
  1140. (Contributed by Ammar Askar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44569">bpo-44569</a>.)</p></li>
  1141. <li><p>Add <a class="reference internal" href="../library/traceback.html#traceback.TracebackException.print" title="traceback.TracebackException.print"><code class="xref py py-func docutils literal notranslate"><span class="pre">traceback.TracebackException.print()</span></code></a>, which prints the
  1142. formatted <a class="reference internal" href="../library/traceback.html#traceback.TracebackException" title="traceback.TracebackException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TracebackException</span></code></a> instance to a file.
  1143. (Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33809">bpo-33809</a>.)</p></li>
  1144. </ul>
  1145. </section>
  1146. <section id="typing">
  1147. <span id="whatsnew311-typing"></span><h3>typing<a class="headerlink" href="#typing" title="Link to this heading">¶</a></h3>
  1148. <p>For major changes, see <a class="reference internal" href="#new-feat-related-type-hints-311"><span class="std std-ref">New Features Related to Type Hints</span></a>.</p>
  1149. <ul class="simple">
  1150. <li><p>Add <a class="reference internal" href="../library/typing.html#typing.assert_never" title="typing.assert_never"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.assert_never()</span></code></a> and <a class="reference internal" href="../library/typing.html#typing.Never" title="typing.Never"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Never</span></code></a>.
  1151. <a class="reference internal" href="../library/typing.html#typing.assert_never" title="typing.assert_never"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.assert_never()</span></code></a> is useful for asking a type checker to confirm
  1152. that a line of code is not reachable. At runtime, it raises an
  1153. <a class="reference internal" href="../library/exceptions.html#AssertionError" title="AssertionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">AssertionError</span></code></a>.
  1154. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/90633">gh-90633</a>.)</p></li>
  1155. <li><p>Add <a class="reference internal" href="../library/typing.html#typing.reveal_type" title="typing.reveal_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.reveal_type()</span></code></a>. This is useful for asking a type checker
  1156. what type it has inferred for a given expression. At runtime it prints
  1157. the type of the received value.
  1158. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/90572">gh-90572</a>.)</p></li>
  1159. <li><p>Add <a class="reference internal" href="../library/typing.html#typing.assert_type" title="typing.assert_type"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.assert_type()</span></code></a>. This is useful for asking a type checker
  1160. to confirm that the type it has inferred for a given expression matches
  1161. the given type. At runtime it simply returns the received value.
  1162. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/90638">gh-90638</a>.)</p></li>
  1163. <li><p><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> types can now be generic. (Contributed by
  1164. Samodya Abeysiriwardane in <a class="reference external" href="https://github.com/python/cpython/issues/89026">gh-89026</a>.)</p></li>
  1165. <li><p><a class="reference internal" href="../library/typing.html#typing.NamedTuple" title="typing.NamedTuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">NamedTuple</span></code></a> types can now be generic.
  1166. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43923">bpo-43923</a>.)</p></li>
  1167. <li><p>Allow subclassing of <a class="reference internal" href="../library/typing.html#typing.Any" title="typing.Any"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Any</span></code></a>. This is useful for avoiding
  1168. type checker errors related to highly dynamic class, such as mocks.
  1169. (Contributed by Shantanu Jain in <a class="reference external" href="https://github.com/python/cpython/issues/91154">gh-91154</a>.)</p></li>
  1170. <li><p>The <a class="reference internal" href="../library/typing.html#typing.final" title="typing.final"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.final()</span></code></a> decorator now sets the <code class="docutils literal notranslate"><span class="pre">__final__</span></code> attributed on
  1171. the decorated object.
  1172. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/90500">gh-90500</a>.)</p></li>
  1173. <li><p>The <a class="reference internal" href="../library/typing.html#typing.get_overloads" title="typing.get_overloads"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_overloads()</span></code></a> function can be used for introspecting
  1174. the overloads of a function. <a class="reference internal" href="../library/typing.html#typing.clear_overloads" title="typing.clear_overloads"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.clear_overloads()</span></code></a> can be used
  1175. to clear all registered overloads of a function.
  1176. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://github.com/python/cpython/issues/89263">gh-89263</a>.)</p></li>
  1177. <li><p>The <a class="reference internal" href="../reference/datamodel.html#object.__init__" title="object.__init__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code></a> method of <a class="reference internal" href="../library/typing.html#typing.Protocol" title="typing.Protocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">Protocol</span></code></a> subclasses
  1178. is now preserved. (Contributed by Adrian Garcia Badarasco in <a class="reference external" href="https://github.com/python/cpython/issues/88970">gh-88970</a>.)</p></li>
  1179. <li><p>The representation of empty tuple types (<code class="docutils literal notranslate"><span class="pre">Tuple[()]</span></code>) is simplified.
  1180. This affects introspection, e.g. <code class="docutils literal notranslate"><span class="pre">get_args(Tuple[()])</span></code> now evaluates
  1181. to <code class="docutils literal notranslate"><span class="pre">()</span></code> instead of <code class="docutils literal notranslate"><span class="pre">((),)</span></code>.
  1182. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/91137">gh-91137</a>.)</p></li>
  1183. <li><p>Loosen runtime requirements for type annotations by removing the callable
  1184. check in the private <code class="docutils literal notranslate"><span class="pre">typing._type_check</span></code> function. (Contributed by
  1185. Gregory Beauregard in <a class="reference external" href="https://github.com/python/cpython/issues/90802">gh-90802</a>.)</p></li>
  1186. <li><p><a class="reference internal" href="../library/typing.html#typing.get_type_hints" title="typing.get_type_hints"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_type_hints()</span></code></a> now supports evaluating strings as forward
  1187. references in <a class="reference internal" href="../library/stdtypes.html#types-genericalias"><span class="std std-ref">PEP 585 generic aliases</span></a>.
  1188. (Contributed by Niklas Rosenstein in <a class="reference external" href="https://github.com/python/cpython/issues/85542">gh-85542</a>.)</p></li>
  1189. <li><p><a class="reference internal" href="../library/typing.html#typing.get_type_hints" title="typing.get_type_hints"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_type_hints()</span></code></a> no longer adds <a class="reference internal" href="../library/typing.html#typing.Optional" title="typing.Optional"><code class="xref py py-data docutils literal notranslate"><span class="pre">Optional</span></code></a>
  1190. to parameters with <code class="docutils literal notranslate"><span class="pre">None</span></code> as a default. (Contributed by Nikita Sobolev
  1191. in <a class="reference external" href="https://github.com/python/cpython/issues/90353">gh-90353</a>.)</p></li>
  1192. <li><p><a class="reference internal" href="../library/typing.html#typing.get_type_hints" title="typing.get_type_hints"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.get_type_hints()</span></code></a> now supports evaluating bare stringified
  1193. <a class="reference internal" href="../library/typing.html#typing.ClassVar" title="typing.ClassVar"><code class="xref py py-data docutils literal notranslate"><span class="pre">ClassVar</span></code></a> annotations. (Contributed by Gregory Beauregard
  1194. in <a class="reference external" href="https://github.com/python/cpython/issues/90711">gh-90711</a>.)</p></li>
  1195. <li><p><a class="reference internal" href="../library/typing.html#typing.no_type_check" title="typing.no_type_check"><code class="xref py py-func docutils literal notranslate"><span class="pre">typing.no_type_check()</span></code></a> no longer modifies external classes and functions.
  1196. It also now correctly marks classmethods as not to be type checked. (Contributed
  1197. by Nikita Sobolev in <a class="reference external" href="https://github.com/python/cpython/issues/90729">gh-90729</a>.)</p></li>
  1198. </ul>
  1199. </section>
  1200. <section id="unicodedata">
  1201. <span id="whatsnew311-unicodedata"></span><h3>unicodedata<a class="headerlink" href="#unicodedata" title="Link to this heading">¶</a></h3>
  1202. <ul class="simple">
  1203. <li><p>The Unicode database has been updated to version 14.0.0.
  1204. (Contributed by Benjamin Peterson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45190">bpo-45190</a>).</p></li>
  1205. </ul>
  1206. </section>
  1207. <section id="unittest">
  1208. <span id="whatsnew311-unittest"></span><h3>unittest<a class="headerlink" href="#unittest" title="Link to this heading">¶</a></h3>
  1209. <ul class="simple">
  1210. <li><p>Added methods <a class="reference internal" href="../library/unittest.html#unittest.TestCase.enterContext" title="unittest.TestCase.enterContext"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enterContext()</span></code></a> and
  1211. <a class="reference internal" href="../library/unittest.html#unittest.TestCase.enterClassContext" title="unittest.TestCase.enterClassContext"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enterClassContext()</span></code></a> of class
  1212. <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
  1213. <a class="reference internal" href="../library/unittest.html#unittest.IsolatedAsyncioTestCase.enterAsyncContext" title="unittest.IsolatedAsyncioTestCase.enterAsyncContext"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enterAsyncContext()</span></code></a> of
  1214. class <a class="reference internal" href="../library/unittest.html#unittest.IsolatedAsyncioTestCase" title="unittest.IsolatedAsyncioTestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">IsolatedAsyncioTestCase</span></code></a> and function
  1215. <a class="reference internal" href="../library/unittest.html#unittest.enterModuleContext" title="unittest.enterModuleContext"><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.enterModuleContext()</span></code></a>.
  1216. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45046">bpo-45046</a>.)</p></li>
  1217. </ul>
  1218. </section>
  1219. <section id="venv">
  1220. <span id="whatsnew311-venv"></span><h3>venv<a class="headerlink" href="#venv" title="Link to this heading">¶</a></h3>
  1221. <ul class="simple">
  1222. <li><p>When new Python virtual environments are created, the <em>venv</em>
  1223. <a class="reference internal" href="../library/sysconfig.html#installation-paths"><span class="std std-ref">sysconfig installation scheme</span></a> is used
  1224. to determine the paths inside the environment.
  1225. When Python runs in a virtual environment, the same installation scheme
  1226. is the default.
  1227. That means that downstream distributors can change the default sysconfig install
  1228. scheme without changing behavior of virtual environments.
  1229. Third party code that also creates new virtual environments should do the same.
  1230. (Contributed by Miro Hrončok in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45413">bpo-45413</a>.)</p></li>
  1231. </ul>
  1232. </section>
  1233. <section id="warnings">
  1234. <span id="whatsnew311-warnings"></span><h3>warnings<a class="headerlink" href="#warnings" title="Link to this heading">¶</a></h3>
  1235. <ul class="simple">
  1236. <li><p><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> now accepts arguments for <a class="reference internal" href="../library/warnings.html#warnings.simplefilter" title="warnings.simplefilter"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.simplefilter()</span></code></a>,
  1237. providing a more concise way to locally ignore warnings or convert them to errors.
  1238. (Contributed by Zac Hatfield-Dodds in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=47074">bpo-47074</a>.)</p></li>
  1239. </ul>
  1240. </section>
  1241. <section id="zipfile">
  1242. <span id="whatsnew311-zipfile"></span><h3>zipfile<a class="headerlink" href="#zipfile" title="Link to this heading">¶</a></h3>
  1243. <ul class="simple">
  1244. <li><p>Added support for specifying member name encoding for reading metadata
  1245. in a <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile" title="zipfile.ZipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">ZipFile</span></code></a>’s directory and file headers.
  1246. (Contributed by Stephen J. Turnbull and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28080">bpo-28080</a>.)</p></li>
  1247. <li><p>Added <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile.mkdir" title="zipfile.ZipFile.mkdir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ZipFile.mkdir()</span></code></a>
  1248. for creating new directories inside ZIP archives.
  1249. (Contributed by Sam Ezeh in <a class="reference external" href="https://github.com/python/cpython/issues/49083">gh-49083</a>.)</p></li>
  1250. <li><p>Added <a class="reference internal" href="../library/zipfile.html#zipfile.Path.stem" title="zipfile.Path.stem"><code class="xref py py-attr docutils literal notranslate"><span class="pre">stem</span></code></a>, <a class="reference internal" href="../library/zipfile.html#zipfile.Path.suffix" title="zipfile.Path.suffix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">suffix</span></code></a>
  1251. and <a class="reference internal" href="../library/zipfile.html#zipfile.Path.suffixes" title="zipfile.Path.suffixes"><code class="xref py py-attr docutils literal notranslate"><span class="pre">suffixes</span></code></a> to <a class="reference internal" href="../library/zipfile.html#zipfile.Path" title="zipfile.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">zipfile.Path</span></code></a>.
  1252. (Contributed by Miguel Brito in <a class="reference external" href="https://github.com/python/cpython/issues/88261">gh-88261</a>.)</p></li>
  1253. </ul>
  1254. </section>
  1255. </section>
  1256. <section id="optimizations">
  1257. <span id="whatsnew311-optimizations"></span><h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading">¶</a></h2>
  1258. <p>This section covers specific optimizations independent of the
  1259. <a class="reference internal" href="#whatsnew311-faster-cpython"><span class="std std-ref">Faster CPython</span></a> project, which is covered in its own section.</p>
  1260. <ul class="simple">
  1261. <li><p>The compiler now optimizes simple
  1262. <a class="reference internal" href="../library/stdtypes.html#old-string-formatting"><span class="std std-ref">printf-style % formatting</span></a> on string literals
  1263. containing only the format codes <code class="docutils literal notranslate"><span class="pre">%s</span></code>, <code class="docutils literal notranslate"><span class="pre">%r</span></code> and <code class="docutils literal notranslate"><span class="pre">%a</span></code> and makes it as
  1264. fast as a corresponding <a class="reference internal" href="../glossary.html#term-f-string"><span class="xref std std-term">f-string</span></a> expression.
  1265. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28307">bpo-28307</a>.)</p></li>
  1266. <li><p>Integer division (<code class="docutils literal notranslate"><span class="pre">//</span></code>) is better tuned for optimization by compilers.
  1267. It is now around 20% faster on x86-64 when dividing an <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>
  1268. by a value smaller than <code class="docutils literal notranslate"><span class="pre">2**30</span></code>.
  1269. (Contributed by Gregory P. Smith and Tim Peters in <a class="reference external" href="https://github.com/python/cpython/issues/90564">gh-90564</a>.)</p></li>
  1270. <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> is now nearly 30% faster for integers smaller than <code class="docutils literal notranslate"><span class="pre">2**30</span></code>.
  1271. (Contributed by Stefan Behnel in <a class="reference external" href="https://github.com/python/cpython/issues/68264">gh-68264</a>.)</p></li>
  1272. <li><p>Resizing lists is streamlined for the common case,
  1273. speeding up <code class="xref py py-meth docutils literal notranslate"><span class="pre">list.append()</span></code> by ≈15%
  1274. and simple <a class="reference internal" href="../glossary.html#term-list-comprehension"><span class="xref std std-term">list comprehension</span></a>s by up to 20-30%
  1275. (Contributed by Dennis Sweeney in <a class="reference external" href="https://github.com/python/cpython/issues/91165">gh-91165</a>.)</p></li>
  1276. <li><p>Dictionaries don’t store hash values when all keys are Unicode objects,
  1277. decreasing <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> size.
  1278. For example, <code class="docutils literal notranslate"><span class="pre">sys.getsizeof(dict.fromkeys(&quot;abcdefg&quot;))</span></code>
  1279. is reduced from 352 bytes to 272 bytes (23% smaller) on 64-bit platforms.
  1280. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46845">bpo-46845</a>.)</p></li>
  1281. <li><p>Using <a class="reference internal" href="../library/asyncio-protocol.html#asyncio.DatagramProtocol" title="asyncio.DatagramProtocol"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.DatagramProtocol</span></code></a> is now orders of magnitude faster
  1282. when transferring large files over UDP,
  1283. with speeds over 100 times higher for a ≈60 MiB file.
  1284. (Contributed by msoxzw in <a class="reference external" href="https://github.com/python/cpython/issues/91487">gh-91487</a>.)</p></li>
  1285. <li><p><a class="reference internal" href="../library/math.html#module-math" title="math: Mathematical functions (sin() etc.)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">math</span></code></a> functions <a class="reference internal" href="../library/math.html#math.comb" title="math.comb"><code class="xref py py-func docutils literal notranslate"><span class="pre">comb()</span></code></a> and <a class="reference internal" href="../library/math.html#math.perm" title="math.perm"><code class="xref py py-func docutils literal notranslate"><span class="pre">perm()</span></code></a> are now
  1286. ≈10 times faster for large arguments (with a larger speedup for larger <em>k</em>).
  1287. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37295">bpo-37295</a>.)</p></li>
  1288. <li><p>The <a class="reference internal" href="../library/statistics.html#module-statistics" title="statistics: Mathematical statistics functions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">statistics</span></code></a> functions <a class="reference internal" href="../library/statistics.html#statistics.mean" title="statistics.mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">mean()</span></code></a>,
  1289. <a class="reference internal" href="../library/statistics.html#statistics.variance" title="statistics.variance"><code class="xref py py-func docutils literal notranslate"><span class="pre">variance()</span></code></a> and <a class="reference internal" href="../library/statistics.html#statistics.stdev" title="statistics.stdev"><code class="xref py py-func docutils literal notranslate"><span class="pre">stdev()</span></code></a> now consume
  1290. iterators in one pass rather than converting them to a <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> first.
  1291. This is twice as fast and can save substantial memory.
  1292. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/90415">gh-90415</a>.)</p></li>
  1293. <li><p><a class="reference internal" href="../library/unicodedata.html#unicodedata.normalize" title="unicodedata.normalize"><code class="xref py py-func docutils literal notranslate"><span class="pre">unicodedata.normalize()</span></code></a>
  1294. now normalizes pure-ASCII strings in constant time.
  1295. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44987">bpo-44987</a>.)</p></li>
  1296. </ul>
  1297. </section>
  1298. <section id="faster-cpython">
  1299. <span id="whatsnew311-faster-cpython"></span><h2>Faster CPython<a class="headerlink" href="#faster-cpython" title="Link to this heading">¶</a></h2>
  1300. <p>CPython 3.11 is an average of
  1301. <a class="reference external" href="https://github.com/faster-cpython/ideas#published-results">25% faster</a>
  1302. than CPython 3.10 as measured with the
  1303. <a class="reference external" href="https://github.com/python/pyperformance">pyperformance</a> benchmark suite,
  1304. when compiled with GCC on Ubuntu Linux.
  1305. Depending on your workload, the overall speedup could be 10-60%.</p>
  1306. <p>This project focuses on two major areas in Python:
  1307. <a class="reference internal" href="#whatsnew311-faster-startup"><span class="std std-ref">Faster Startup</span></a> and <a class="reference internal" href="#whatsnew311-faster-runtime"><span class="std std-ref">Faster Runtime</span></a>.
  1308. Optimizations not covered by this project are listed separately under
  1309. <a class="reference internal" href="#whatsnew311-optimizations"><span class="std std-ref">Optimizations</span></a>.</p>
  1310. <section id="faster-startup">
  1311. <span id="whatsnew311-faster-startup"></span><h3>Faster Startup<a class="headerlink" href="#faster-startup" title="Link to this heading">¶</a></h3>
  1312. <section id="frozen-imports-static-code-objects">
  1313. <span id="whatsnew311-faster-imports"></span><h4>Frozen imports / Static code objects<a class="headerlink" href="#frozen-imports-static-code-objects" title="Link to this heading">¶</a></h4>
  1314. <p>Python caches <a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a> in the <a class="reference internal" href="../tutorial/modules.html#tut-pycache"><span class="std std-ref">__pycache__</span></a>
  1315. directory to speed up module loading.</p>
  1316. <p>Previously in 3.10, Python module execution looked like this:</p>
  1317. <div class="highlight-text notranslate"><div class="highlight"><pre><span></span>Read __pycache__ -&gt; Unmarshal -&gt; Heap allocated code object -&gt; Evaluate
  1318. </pre></div>
  1319. </div>
  1320. <p>In Python 3.11, the core modules essential for Python startup are “frozen”.
  1321. This means that their <a class="reference internal" href="../c-api/code.html#codeobjects"><span class="std std-ref">Code Objects</span></a> (and bytecode)
  1322. are statically allocated by the interpreter.
  1323. This reduces the steps in module execution process to:</p>
  1324. <div class="highlight-text notranslate"><div class="highlight"><pre><span></span>Statically allocated code object -&gt; Evaluate
  1325. </pre></div>
  1326. </div>
  1327. <p>Interpreter startup is now 10-15% faster in Python 3.11. This has a big
  1328. impact for short-running programs using Python.</p>
  1329. <p>(Contributed by Eric Snow, Guido van Rossum and Kumar Aditya in many issues.)</p>
  1330. </section>
  1331. </section>
  1332. <section id="faster-runtime">
  1333. <span id="whatsnew311-faster-runtime"></span><h3>Faster Runtime<a class="headerlink" href="#faster-runtime" title="Link to this heading">¶</a></h3>
  1334. <section id="cheaper-lazy-python-frames">
  1335. <span id="whatsnew311-lazy-python-frames"></span><h4>Cheaper, lazy Python frames<a class="headerlink" href="#cheaper-lazy-python-frames" title="Link to this heading">¶</a></h4>
  1336. <p>Python frames, holding execution information,
  1337. are created whenever Python calls a Python function.
  1338. The following are new frame optimizations:</p>
  1339. <ul class="simple">
  1340. <li><p>Streamlined the frame creation process.</p></li>
  1341. <li><p>Avoided memory allocation by generously re-using frame space on the C stack.</p></li>
  1342. <li><p>Streamlined the internal frame struct to contain only essential information.
  1343. Frames previously held extra debugging and memory management information.</p></li>
  1344. </ul>
  1345. <p>Old-style <a class="reference internal" href="../reference/datamodel.html#frame-objects"><span class="std std-ref">frame objects</span></a>
  1346. are now created only when requested by debuggers
  1347. or by Python introspection functions such as <a class="reference internal" href="../library/sys.html#sys._getframe" title="sys._getframe"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys._getframe()</span></code></a> and
  1348. <a class="reference internal" href="../library/inspect.html#inspect.currentframe" title="inspect.currentframe"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.currentframe()</span></code></a>. For most user code, no frame objects are
  1349. created at all. As a result, nearly all Python functions calls have sped
  1350. up significantly. We measured a 3-7% speedup in pyperformance.</p>
  1351. <p>(Contributed by Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44590">bpo-44590</a>.)</p>
  1352. </section>
  1353. <section id="inlined-python-function-calls">
  1354. <span id="whatsnew311-inline-calls"></span><span id="inline-calls"></span><h4>Inlined Python function calls<a class="headerlink" href="#inlined-python-function-calls" title="Link to this heading">¶</a></h4>
  1355. <p>During a Python function call, Python will call an evaluating C function to
  1356. interpret that function’s code. This effectively limits pure Python recursion to
  1357. what’s safe for the C stack.</p>
  1358. <p>In 3.11, when CPython detects Python code calling another Python function,
  1359. it sets up a new frame, and “jumps” to the new code inside the new frame. This
  1360. avoids calling the C interpreting function altogether.</p>
  1361. <p>Most Python function calls now consume no C stack space, speeding them up.
  1362. In simple recursive functions like fibonacci or
  1363. factorial, we observed a 1.7x speedup. This also means recursive functions
  1364. can recurse significantly deeper
  1365. (if the user increases the recursion limit with <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>).
  1366. We measured a 1-3% improvement in pyperformance.</p>
  1367. <p>(Contributed by Pablo Galindo and Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45256">bpo-45256</a>.)</p>
  1368. </section>
  1369. <section id="pep-659-specializing-adaptive-interpreter">
  1370. <span id="whatsnew311-pep659"></span><h4>PEP 659: Specializing Adaptive Interpreter<a class="headerlink" href="#pep-659-specializing-adaptive-interpreter" title="Link to this heading">¶</a></h4>
  1371. <p><span class="target" id="index-28"></span><a class="pep reference external" href="https://peps.python.org/pep-0659/"><strong>PEP 659</strong></a> is one of the key parts of the Faster CPython project. The general
  1372. idea is that while Python is a dynamic language, most code has regions where
  1373. objects and types rarely change. This concept is known as <em>type stability</em>.</p>
  1374. <p>At runtime, Python will try to look for common patterns and type stability
  1375. in the executing code. Python will then replace the current operation with a
  1376. more specialized one. This specialized operation uses fast paths available only
  1377. to those use cases/types, which generally outperform their generic
  1378. counterparts. This also brings in another concept called <em>inline caching</em>, where
  1379. Python caches the results of expensive operations directly in the
  1380. <a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a>.</p>
  1381. <p>The specializer will also combine certain common instruction pairs into one
  1382. superinstruction, reducing the overhead during execution.</p>
  1383. <p>Python will only specialize
  1384. when it sees code that is “hot” (executed multiple times). This prevents Python
  1385. from wasting time on run-once code. Python can also de-specialize when code is
  1386. too dynamic or when the use changes. Specialization is attempted periodically,
  1387. and specialization attempts are not too expensive,
  1388. allowing specialization to adapt to new circumstances.</p>
  1389. <p>(PEP written by Mark Shannon, with ideas inspired by Stefan Brunthaler.
  1390. See <span class="target" id="index-29"></span><a class="pep reference external" href="https://peps.python.org/pep-0659/"><strong>PEP 659</strong></a> for more information. Implementation by Mark Shannon and Brandt
  1391. Bucher, with additional help from Irit Katriel and Dennis Sweeney.)</p>
  1392. <table class="docutils align-default">
  1393. <thead>
  1394. <tr class="row-odd"><th class="head"><p>Operation</p></th>
  1395. <th class="head"><p>Form</p></th>
  1396. <th class="head"><p>Specialization</p></th>
  1397. <th class="head"><p>Operation speedup
  1398. (up to)</p></th>
  1399. <th class="head"><p>Contributor(s)</p></th>
  1400. </tr>
  1401. </thead>
  1402. <tbody>
  1403. <tr class="row-even"><td><p>Binary
  1404. operations</p></td>
  1405. <td><p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">+</span> <span class="pre">x</span></code></p>
  1406. <p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">-</span> <span class="pre">x</span></code></p>
  1407. <p><code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">*</span> <span class="pre">x</span></code></p>
  1408. </td>
  1409. <td><p>Binary add, multiply and subtract for common types
  1410. such as <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>, <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>
  1411. take custom fast paths for their underlying types.</p></td>
  1412. <td><p>10%</p></td>
  1413. <td><p>Mark Shannon,
  1414. Donghee Na,
  1415. Brandt Bucher,
  1416. Dennis Sweeney</p></td>
  1417. </tr>
  1418. <tr class="row-odd"><td><p>Subscript</p></td>
  1419. <td><p><code class="docutils literal notranslate"><span class="pre">a[i]</span></code></p></td>
  1420. <td><p>Subscripting container types such as <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>,
  1421. <a class="reference internal" href="../library/stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a> and <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> directly index
  1422. the underlying data structures.</p>
  1423. <p>Subscripting custom <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a>
  1424. is also inlined similar to <a class="reference internal" href="#inline-calls"><span class="std std-ref">Inlined Python function calls</span></a>.</p>
  1425. </td>
  1426. <td><p>10-25%</p></td>
  1427. <td><p>Irit Katriel,
  1428. Mark Shannon</p></td>
  1429. </tr>
  1430. <tr class="row-even"><td><p>Store
  1431. subscript</p></td>
  1432. <td><p><code class="docutils literal notranslate"><span class="pre">a[i]</span> <span class="pre">=</span> <span class="pre">z</span></code></p></td>
  1433. <td><p>Similar to subscripting specialization above.</p></td>
  1434. <td><p>10-25%</p></td>
  1435. <td><p>Dennis Sweeney</p></td>
  1436. </tr>
  1437. <tr class="row-odd"><td><p>Calls</p></td>
  1438. <td><p><code class="docutils literal notranslate"><span class="pre">f(arg)</span></code></p>
  1439. <p><code class="docutils literal notranslate"><span class="pre">C(arg)</span></code></p>
  1440. </td>
  1441. <td><p>Calls to common builtin (C) functions and types such
  1442. as <a class="reference internal" href="../library/functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> directly call their
  1443. underlying C version. This avoids going through the
  1444. internal calling convention.</p></td>
  1445. <td><p>20%</p></td>
  1446. <td><p>Mark Shannon,
  1447. Ken Jin</p></td>
  1448. </tr>
  1449. <tr class="row-even"><td><p>Load
  1450. global
  1451. variable</p></td>
  1452. <td><p><code class="docutils literal notranslate"><span class="pre">print</span></code></p>
  1453. <p><code class="docutils literal notranslate"><span class="pre">len</span></code></p>
  1454. </td>
  1455. <td><p>The object’s index in the globals/builtins namespace
  1456. is cached. Loading globals and builtins require
  1457. zero namespace lookups.</p></td>
  1458. <td><p><a class="footnote-reference brackets" href="#load-global" id="id2" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p></td>
  1459. <td><p>Mark Shannon</p></td>
  1460. </tr>
  1461. <tr class="row-odd"><td><p>Load
  1462. attribute</p></td>
  1463. <td><p><code class="docutils literal notranslate"><span class="pre">o.attr</span></code></p></td>
  1464. <td><p>Similar to loading global variables. The attribute’s
  1465. index inside the class/object’s namespace is cached.
  1466. In most cases, attribute loading will require zero
  1467. namespace lookups.</p></td>
  1468. <td><p><a class="footnote-reference brackets" href="#load-attr" id="id3" role="doc-noteref"><span class="fn-bracket">[</span>2<span class="fn-bracket">]</span></a></p></td>
  1469. <td><p>Mark Shannon</p></td>
  1470. </tr>
  1471. <tr class="row-even"><td><p>Load
  1472. methods for
  1473. call</p></td>
  1474. <td><p><code class="docutils literal notranslate"><span class="pre">o.meth()</span></code></p></td>
  1475. <td><p>The actual address of the method is cached. Method
  1476. loading now has no namespace lookups – even for
  1477. classes with long inheritance chains.</p></td>
  1478. <td><p>10-20%</p></td>
  1479. <td><p>Ken Jin,
  1480. Mark Shannon</p></td>
  1481. </tr>
  1482. <tr class="row-odd"><td><p>Store
  1483. attribute</p></td>
  1484. <td><p><code class="docutils literal notranslate"><span class="pre">o.attr</span> <span class="pre">=</span> <span class="pre">z</span></code></p></td>
  1485. <td><p>Similar to load attribute optimization.</p></td>
  1486. <td><p>2%
  1487. in pyperformance</p></td>
  1488. <td><p>Mark Shannon</p></td>
  1489. </tr>
  1490. <tr class="row-even"><td><p>Unpack
  1491. Sequence</p></td>
  1492. <td><p><code class="docutils literal notranslate"><span class="pre">*seq</span></code></p></td>
  1493. <td><p>Specialized for common containers such as
  1494. <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#tuple" title="tuple"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a>.
  1495. Avoids internal calling convention.</p></td>
  1496. <td><p>8%</p></td>
  1497. <td><p>Brandt Bucher</p></td>
  1498. </tr>
  1499. </tbody>
  1500. </table>
  1501. <aside class="footnote-list brackets">
  1502. <aside class="footnote brackets" id="load-global" role="doc-footnote">
  1503. <span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id2">1</a><span class="fn-bracket">]</span></span>
  1504. <p>A similar optimization already existed since Python 3.8.
  1505. 3.11 specializes for more forms and reduces some overhead.</p>
  1506. </aside>
  1507. <aside class="footnote brackets" id="load-attr" role="doc-footnote">
  1508. <span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id3">2</a><span class="fn-bracket">]</span></span>
  1509. <p>A similar optimization already existed since Python 3.10.
  1510. 3.11 specializes for more forms. Furthermore, all attribute loads should
  1511. be sped up by <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45947">bpo-45947</a>.</p>
  1512. </aside>
  1513. </aside>
  1514. </section>
  1515. </section>
  1516. <section id="misc">
  1517. <span id="whatsnew311-faster-cpython-misc"></span><h3>Misc<a class="headerlink" href="#misc" title="Link to this heading">¶</a></h3>
  1518. <ul class="simple">
  1519. <li><p>Objects now require less memory due to lazily created object namespaces.
  1520. Their namespace dictionaries now also share keys more freely.
  1521. (Contributed Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45340">bpo-45340</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40116">bpo-40116</a>.)</p></li>
  1522. <li><p>“Zero-cost” exceptions are implemented, eliminating the cost
  1523. of <a class="reference internal" href="../reference/compound_stmts.html#try"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">try</span></code></a> statements when no exception is raised.
  1524. (Contributed by Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40222">bpo-40222</a>.)</p></li>
  1525. <li><p>A more concise representation of exceptions in the interpreter reduced the
  1526. time required for catching an exception by about 10%.
  1527. (Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45711">bpo-45711</a>.)</p></li>
  1528. <li><p><a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a>’s regular expression matching engine has been partially refactored,
  1529. and now uses computed gotos (or “threaded code”) on supported platforms. As a
  1530. result, Python 3.11 executes the <a class="reference external" href="https://pyperformance.readthedocs.io/benchmarks.html#regex-dna">pyperformance regular expression benchmarks</a> up to 10%
  1531. faster than Python 3.10.
  1532. (Contributed by Brandt Bucher in <a class="reference external" href="https://github.com/python/cpython/issues/91404">gh-91404</a>.)</p></li>
  1533. </ul>
  1534. </section>
  1535. <section id="faq">
  1536. <span id="whatsnew311-faster-cpython-faq"></span><h3>FAQ<a class="headerlink" href="#faq" title="Link to this heading">¶</a></h3>
  1537. <section id="how-should-i-write-my-code-to-utilize-these-speedups">
  1538. <span id="faster-cpython-faq-my-code"></span><h4>How should I write my code to utilize these speedups?<a class="headerlink" href="#how-should-i-write-my-code-to-utilize-these-speedups" title="Link to this heading">¶</a></h4>
  1539. <p>Write Pythonic code that follows common best practices;
  1540. you don’t have to change your code.
  1541. The Faster CPython project optimizes for common code patterns we observe.</p>
  1542. </section>
  1543. <section id="will-cpython-3-11-use-more-memory">
  1544. <span id="faster-cpython-faq-memory"></span><h4>Will CPython 3.11 use more memory?<a class="headerlink" href="#will-cpython-3-11-use-more-memory" title="Link to this heading">¶</a></h4>
  1545. <p>Maybe not; we don’t expect memory use to exceed 20% higher than 3.10.
  1546. This is offset by memory optimizations for frame objects and object
  1547. dictionaries as mentioned above.</p>
  1548. </section>
  1549. <section id="i-don-t-see-any-speedups-in-my-workload-why">
  1550. <span id="faster-cpython-ymmv"></span><h4>I don’t see any speedups in my workload. Why?<a class="headerlink" href="#i-don-t-see-any-speedups-in-my-workload-why" title="Link to this heading">¶</a></h4>
  1551. <p>Certain code won’t have noticeable benefits. If your code spends most of
  1552. its time on I/O operations, or already does most of its
  1553. computation in a C extension library like NumPy, there won’t be significant
  1554. speedups. This project currently benefits pure-Python workloads the most.</p>
  1555. <p>Furthermore, the pyperformance figures are a geometric mean. Even within the
  1556. pyperformance benchmarks, certain benchmarks have slowed down slightly, while
  1557. others have sped up by nearly 2x!</p>
  1558. </section>
  1559. <section id="is-there-a-jit-compiler">
  1560. <span id="faster-cpython-jit"></span><h4>Is there a JIT compiler?<a class="headerlink" href="#is-there-a-jit-compiler" title="Link to this heading">¶</a></h4>
  1561. <p>No. We’re still exploring other optimizations.</p>
  1562. </section>
  1563. </section>
  1564. <section id="about">
  1565. <span id="whatsnew311-faster-cpython-about"></span><h3>About<a class="headerlink" href="#about" title="Link to this heading">¶</a></h3>
  1566. <p>Faster CPython explores optimizations for <a class="reference internal" href="../glossary.html#term-CPython"><span class="xref std std-term">CPython</span></a>. The main team is
  1567. funded by Microsoft to work on this full-time. Pablo Galindo Salgado is also
  1568. funded by Bloomberg LP to work on the project part-time. Finally, many
  1569. contributors are volunteers from the community.</p>
  1570. </section>
  1571. </section>
  1572. <section id="cpython-bytecode-changes">
  1573. <span id="whatsnew311-bytecode-changes"></span><h2>CPython bytecode changes<a class="headerlink" href="#cpython-bytecode-changes" title="Link to this heading">¶</a></h2>
  1574. <p>The bytecode now contains inline cache entries,
  1575. which take the form of the newly-added <a class="reference internal" href="../library/dis.html#opcode-CACHE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CACHE</span></code></a> instructions.
  1576. Many opcodes expect to be followed by an exact number of caches,
  1577. and instruct the interpreter to skip over them at runtime.
  1578. Populated caches can look like arbitrary instructions,
  1579. so great care should be taken when reading or modifying
  1580. raw, adaptive bytecode containing quickened data.</p>
  1581. <section id="new-opcodes">
  1582. <span id="whatsnew311-added-opcodes"></span><h3>New opcodes<a class="headerlink" href="#new-opcodes" title="Link to this heading">¶</a></h3>
  1583. <ul class="simple">
  1584. <li><p><code class="xref std std-opcode docutils literal notranslate"><span class="pre">ASYNC_GEN_WRAP</span></code>, <a class="reference internal" href="../library/dis.html#opcode-RETURN_GENERATOR"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">RETURN_GENERATOR</span></code></a> and <a class="reference internal" href="../library/dis.html#opcode-SEND"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">SEND</span></code></a>,
  1585. used in generators and co-routines.</p></li>
  1586. <li><p><a class="reference internal" href="../library/dis.html#opcode-COPY_FREE_VARS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">COPY_FREE_VARS</span></code></a>,
  1587. which avoids needing special caller-side code for closures.</p></li>
  1588. <li><p><a class="reference internal" href="../library/dis.html#opcode-JUMP_BACKWARD_NO_INTERRUPT"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_BACKWARD_NO_INTERRUPT</span></code></a>,
  1589. for use in certain loops where handling interrupts is undesirable.</p></li>
  1590. <li><p><a class="reference internal" href="../library/dis.html#opcode-MAKE_CELL"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">MAKE_CELL</span></code></a>, to create <a class="reference internal" href="../c-api/cell.html#cell-objects"><span class="std std-ref">Cell Objects</span></a>.</p></li>
  1591. <li><p><a class="reference internal" href="../library/dis.html#opcode-CHECK_EG_MATCH"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CHECK_EG_MATCH</span></code></a> and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">PREP_RERAISE_STAR</span></code>,
  1592. to handle the <a class="reference internal" href="#whatsnew311-pep654"><span class="std std-ref">new exception groups and except*</span></a>
  1593. added in <span class="target" id="index-30"></span><a class="pep reference external" href="https://peps.python.org/pep-0654/"><strong>PEP 654</strong></a>.</p></li>
  1594. <li><p><a class="reference internal" href="../library/dis.html#opcode-PUSH_EXC_INFO"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">PUSH_EXC_INFO</span></code></a>, for use in exception handlers.</p></li>
  1595. <li><p><a class="reference internal" href="../library/dis.html#opcode-RESUME"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">RESUME</span></code></a>, a no-op,
  1596. for internal tracing, debugging and optimization checks.</p></li>
  1597. </ul>
  1598. </section>
  1599. <section id="replaced-opcodes">
  1600. <span id="whatsnew311-replaced-opcodes"></span><h3>Replaced opcodes<a class="headerlink" href="#replaced-opcodes" title="Link to this heading">¶</a></h3>
  1601. <table class="docutils align-default">
  1602. <thead>
  1603. <tr class="row-odd"><th class="head"><p>Replaced Opcode(s)</p></th>
  1604. <th class="head"><p>New Opcode(s)</p></th>
  1605. <th class="head"><p>Notes</p></th>
  1606. </tr>
  1607. </thead>
  1608. <tbody>
  1609. <tr class="row-even"><td><div class="line-block">
  1610. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BINARY_*</span></code></div>
  1611. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">INPLACE_*</span></code></div>
  1612. </div>
  1613. </td>
  1614. <td><p><a class="reference internal" href="../library/dis.html#opcode-BINARY_OP"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BINARY_OP</span></code></a></p></td>
  1615. <td><p>Replaced all numeric binary/in-place
  1616. opcodes with a single opcode</p></td>
  1617. </tr>
  1618. <tr class="row-odd"><td><div class="line-block">
  1619. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FUNCTION</span></code></div>
  1620. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FUNCTION_KW</span></code></div>
  1621. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_METHOD</span></code></div>
  1622. </div>
  1623. </td>
  1624. <td><div class="line-block">
  1625. <div class="line"><a class="reference internal" href="../library/dis.html#opcode-CALL"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL</span></code></a></div>
  1626. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">KW_NAMES</span></code></div>
  1627. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">PRECALL</span></code></div>
  1628. <div class="line"><a class="reference internal" href="../library/dis.html#opcode-PUSH_NULL"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">PUSH_NULL</span></code></a></div>
  1629. </div>
  1630. </td>
  1631. <td><p>Decouples argument shifting for methods
  1632. from handling of keyword arguments;
  1633. allows better specialization of calls</p></td>
  1634. </tr>
  1635. <tr class="row-even"><td><div class="line-block">
  1636. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">DUP_TOP</span></code></div>
  1637. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">DUP_TOP_TWO</span></code></div>
  1638. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">ROT_TWO</span></code></div>
  1639. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">ROT_THREE</span></code></div>
  1640. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">ROT_FOUR</span></code></div>
  1641. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">ROT_N</span></code></div>
  1642. </div>
  1643. </td>
  1644. <td><div class="line-block">
  1645. <div class="line"><a class="reference internal" href="../library/dis.html#opcode-COPY"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">COPY</span></code></a></div>
  1646. <div class="line"><a class="reference internal" href="../library/dis.html#opcode-SWAP"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">SWAP</span></code></a></div>
  1647. </div>
  1648. </td>
  1649. <td><p>Stack manipulation instructions</p></td>
  1650. </tr>
  1651. <tr class="row-odd"><td><div class="line-block">
  1652. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_IF_NOT_EXC_MATCH</span></code></div>
  1653. </div>
  1654. </td>
  1655. <td><div class="line-block">
  1656. <div class="line"><a class="reference internal" href="../library/dis.html#opcode-CHECK_EXC_MATCH"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CHECK_EXC_MATCH</span></code></a></div>
  1657. </div>
  1658. </td>
  1659. <td><p>Now performs check but doesn’t jump</p></td>
  1660. </tr>
  1661. <tr class="row-even"><td><div class="line-block">
  1662. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_ABSOLUTE</span></code></div>
  1663. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_JUMP_IF_FALSE</span></code></div>
  1664. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_JUMP_IF_TRUE</span></code></div>
  1665. </div>
  1666. </td>
  1667. <td><div class="line-block">
  1668. <div class="line"><a class="reference internal" href="../library/dis.html#opcode-JUMP_BACKWARD"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_BACKWARD</span></code></a></div>
  1669. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_JUMP_BACKWARD_IF_*</span></code></div>
  1670. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_JUMP_FORWARD_IF_*</span></code></div>
  1671. </div>
  1672. </td>
  1673. <td><p>See <a class="footnote-reference brackets" href="#bytecode-jump" id="id4" role="doc-noteref"><span class="fn-bracket">[</span>3<span class="fn-bracket">]</span></a>;
  1674. <code class="docutils literal notranslate"><span class="pre">TRUE</span></code>, <code class="docutils literal notranslate"><span class="pre">FALSE</span></code>,
  1675. <code class="docutils literal notranslate"><span class="pre">NONE</span></code> and <code class="docutils literal notranslate"><span class="pre">NOT_NONE</span></code> variants
  1676. for each direction</p></td>
  1677. </tr>
  1678. <tr class="row-odd"><td><div class="line-block">
  1679. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">SETUP_WITH</span></code></div>
  1680. <div class="line"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">SETUP_ASYNC_WITH</span></code></div>
  1681. </div>
  1682. </td>
  1683. <td><p><a class="reference internal" href="../library/dis.html#opcode-BEFORE_WITH"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BEFORE_WITH</span></code></a></p></td>
  1684. <td><p><a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> block setup</p></td>
  1685. </tr>
  1686. </tbody>
  1687. </table>
  1688. <aside class="footnote-list brackets">
  1689. <aside class="footnote brackets" id="bytecode-jump" role="doc-footnote">
  1690. <span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="#id4">3</a><span class="fn-bracket">]</span></span>
  1691. <p>All jump opcodes are now relative, including the
  1692. existing <code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_IF_TRUE_OR_POP</span></code> and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">JUMP_IF_FALSE_OR_POP</span></code>.
  1693. The argument is now an offset from the current instruction
  1694. rather than an absolute location.</p>
  1695. </aside>
  1696. </aside>
  1697. </section>
  1698. <section id="changed-removed-opcodes">
  1699. <span id="whatsnew311-changed-removed-opcodes"></span><span id="whatsnew311-removed-opcodes"></span><span id="whatsnew311-changed-opcodes"></span><h3>Changed/removed opcodes<a class="headerlink" href="#changed-removed-opcodes" title="Link to this heading">¶</a></h3>
  1700. <ul class="simple">
  1701. <li><p>Changed <a class="reference internal" href="../library/dis.html#opcode-MATCH_CLASS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">MATCH_CLASS</span></code></a> and <a class="reference internal" href="../library/dis.html#opcode-MATCH_KEYS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">MATCH_KEYS</span></code></a>
  1702. to no longer push an additional boolean value to indicate success/failure.
  1703. Instead, <code class="docutils literal notranslate"><span class="pre">None</span></code> is pushed on failure
  1704. in place of the tuple of extracted values.</p></li>
  1705. <li><p>Changed opcodes that work with exceptions to reflect them
  1706. now being represented as one item on the stack instead of three
  1707. (see <a class="reference external" href="https://github.com/python/cpython/issues/89874">gh-89874</a>).</p></li>
  1708. <li><p>Removed <code class="xref std std-opcode docutils literal notranslate"><span class="pre">COPY_DICT_WITHOUT_KEYS</span></code>, <code class="xref std std-opcode docutils literal notranslate"><span class="pre">GEN_START</span></code>,
  1709. <code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_BLOCK</span></code>, <code class="xref std std-opcode docutils literal notranslate"><span class="pre">SETUP_FINALLY</span></code> and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">YIELD_FROM</span></code>.</p></li>
  1710. </ul>
  1711. </section>
  1712. </section>
  1713. <section id="deprecated">
  1714. <span id="whatsnew311-python-api-deprecated"></span><span id="whatsnew311-deprecated"></span><h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading">¶</a></h2>
  1715. <p>This section lists Python APIs that have been deprecated in Python 3.11.</p>
  1716. <p>Deprecated C APIs are <a class="reference internal" href="#whatsnew311-c-api-deprecated"><span class="std std-ref">listed separately</span></a>.</p>
  1717. <section id="language-builtins">
  1718. <span id="whatsnew311-deprecated-builtins"></span><span id="whatsnew311-deprecated-language"></span><h3>Language/Builtins<a class="headerlink" href="#language-builtins" title="Link to this heading">¶</a></h3>
  1719. <ul class="simple">
  1720. <li><p>Chaining <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> descriptors (introduced in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19072">bpo-19072</a>)
  1721. is now deprecated. It can no longer be used to wrap other descriptors
  1722. such as <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-class docutils literal notranslate"><span class="pre">property</span></code></a>. The core design of this feature was flawed
  1723. and caused a number of downstream problems. To “pass-through” a
  1724. <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>, consider using the <code class="xref py py-attr docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute
  1725. that was added in Python 3.10.
  1726. (Contributed by Raymond Hettinger in <a class="reference external" href="https://github.com/python/cpython/issues/89519">gh-89519</a>.)</p></li>
  1727. <li><p>Octal escapes in string and bytes literals with values larger than <code class="docutils literal notranslate"><span class="pre">0o377</span></code>
  1728. (255 in decimal) now produce 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>.
  1729. In a future Python version, they will raise 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> and
  1730. 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>.
  1731. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/81548">gh-81548</a>.)</p></li>
  1732. <li><p>The delegation of <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-func docutils literal notranslate"><span class="pre">int()</span></code></a> to <a class="reference internal" href="../reference/datamodel.html#object.__trunc__" title="object.__trunc__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__trunc__()</span></code></a> is now deprecated.
  1733. Calling <code class="docutils literal notranslate"><span class="pre">int(a)</span></code> when <code class="docutils literal notranslate"><span class="pre">type(a)</span></code> implements <code class="xref py py-meth docutils literal notranslate"><span class="pre">__trunc__()</span></code> but not
  1734. <a class="reference internal" href="../reference/datamodel.html#object.__int__" title="object.__int__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__int__()</span></code></a> or <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__index__()</span></code></a> now raises
  1735. 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>.
  1736. (Contributed by Zackery Spytz in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44977">bpo-44977</a>.)</p></li>
  1737. </ul>
  1738. </section>
  1739. <section id="modules">
  1740. <span id="whatsnew311-deprecated-modules"></span><h3>Modules<a class="headerlink" href="#modules" title="Link to this heading">¶</a></h3>
  1741. <ul id="whatsnew311-pep594">
  1742. <li><p><span class="target" id="index-31"></span><a class="pep reference external" href="https://peps.python.org/pep-0594/"><strong>PEP 594</strong></a> led to the deprecations of the following modules
  1743. slated for removal in Python 3.13:</p>
  1744. <table class="docutils align-default">
  1745. <tbody>
  1746. <tr class="row-odd"><td><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></td>
  1747. <td><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></td>
  1748. <td><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></td>
  1749. <td><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></td>
  1750. <td><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></td>
  1751. </tr>
  1752. <tr class="row-even"><td><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></td>
  1753. <td><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></td>
  1754. <td><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></td>
  1755. <td><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></td>
  1756. <td><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></td>
  1757. </tr>
  1758. <tr class="row-odd"><td><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></td>
  1759. <td><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></td>
  1760. <td><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></td>
  1761. <td><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></td>
  1762. <td><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></td>
  1763. </tr>
  1764. <tr class="row-even"><td><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></td>
  1765. <td><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></td>
  1766. <td><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></td>
  1767. <td><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></td>
  1768. <td></td>
  1769. </tr>
  1770. </tbody>
  1771. </table>
  1772. <p>(Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=47061">bpo-47061</a> and Victor Stinner in
  1773. <a class="reference external" href="https://github.com/python/cpython/issues/68966">gh-68966</a>.)</p>
  1774. </li>
  1775. <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">smtpd</span></code> modules have been
  1776. deprecated since at least Python 3.6. Their documentation and deprecation
  1777. warnings have now been updated to note they will be removed in Python 3.12.
  1778. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=47022">bpo-47022</a>.)</p></li>
  1779. <li><p>The <a class="reference internal" href="../library/2to3.html#module-lib2to3" title="lib2to3: The 2to3 library"><code class="xref py py-mod docutils literal notranslate"><span class="pre">lib2to3</span></code></a> package and <a class="reference internal" href="../library/2to3.html#to3-reference"><span class="std std-ref">2to3</span></a> tool
  1780. are now deprecated and may not be able to parse Python 3.10 or newer.
  1781. See <span class="target" id="index-32"></span><a class="pep reference external" href="https://peps.python.org/pep-0617/"><strong>PEP 617</strong></a>, introducing the new PEG parser, for details.
  1782. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40360">bpo-40360</a>.)</p></li>
  1783. <li><p>Undocumented modules <code class="xref py py-mod docutils literal notranslate"><span class="pre">sre_compile</span></code>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">sre_constants</span></code>
  1784. and <code class="xref py py-mod docutils literal notranslate"><span class="pre">sre_parse</span></code> are now deprecated.
  1785. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=47152">bpo-47152</a>.)</p></li>
  1786. </ul>
  1787. </section>
  1788. <section id="standard-library">
  1789. <span id="whatsnew311-deprecated-stdlib"></span><h3>Standard Library<a class="headerlink" href="#standard-library" title="Link to this heading">¶</a></h3>
  1790. <ul>
  1791. <li><p>The following have been deprecated in <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> since Python 3.2.
  1792. Their deprecation warnings have now been updated to note they will be removed
  1793. in Python 3.12:</p>
  1794. <ul class="simple">
  1795. <li><p>the <code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.SafeConfigParser</span></code> class</p></li>
  1796. <li><p>the <code class="xref py py-attr docutils literal notranslate"><span class="pre">configparser.ParsingError.filename</span></code> property</p></li>
  1797. <li><p>the <code class="xref py py-meth docutils literal notranslate"><span class="pre">configparser.RawConfigParser.readfp()</span></code> method</p></li>
  1798. </ul>
  1799. <p>(Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45173">bpo-45173</a>.)</p>
  1800. </li>
  1801. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.LegacyInterpolation</span></code> has been deprecated in the docstring
  1802. since Python 3.2, and is not listed 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> documentation.
  1803. It 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> and will be removed
  1804. in Python 3.13. Use <a class="reference internal" href="../library/configparser.html#configparser.BasicInterpolation" title="configparser.BasicInterpolation"><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.BasicInterpolation</span></code></a> or
  1805. <a class="reference internal" href="../library/configparser.html#configparser.ExtendedInterpolation" title="configparser.ExtendedInterpolation"><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.ExtendedInterpolation</span></code></a> instead.
  1806. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46607">bpo-46607</a>.)</p></li>
  1807. <li><p>The older set of <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> functions were deprecated
  1808. in favor of the replacements added in Python 3.9
  1809. and will be removed in a future Python version,
  1810. due to not supporting resources located within package subdirectories:</p>
  1811. <ul class="simple">
  1812. <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.contents" title="importlib.resources.contents"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.contents()</span></code></a></p></li>
  1813. <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.is_resource" title="importlib.resources.is_resource"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.is_resource()</span></code></a></p></li>
  1814. <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.open_binary" title="importlib.resources.open_binary"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.open_binary()</span></code></a></p></li>
  1815. <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.open_text" title="importlib.resources.open_text"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.open_text()</span></code></a></p></li>
  1816. <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.read_binary" title="importlib.resources.read_binary"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.read_binary()</span></code></a></p></li>
  1817. <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.read_text" title="importlib.resources.read_text"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.read_text()</span></code></a></p></li>
  1818. <li><p><a class="reference internal" href="../library/importlib.resources.html#importlib.resources.path" title="importlib.resources.path"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.resources.path()</span></code></a></p></li>
  1819. </ul>
  1820. </li>
  1821. <li><p>The <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> function is deprecated and will be
  1822. removed in Python 3.15. Use <a class="reference internal" href="../library/locale.html#locale.setlocale" title="locale.setlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.setlocale()</span></code></a>,
  1823. <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> and
  1824. <a class="reference internal" href="../library/locale.html#locale.getlocale" title="locale.getlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getlocale()</span></code></a> functions instead.
  1825. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/90817">gh-90817</a>.)</p></li>
  1826. <li><p>The <a class="reference internal" href="../library/locale.html#locale.resetlocale" title="locale.resetlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.resetlocale()</span></code></a> function is deprecated and will be
  1827. removed in Python 3.13. Use <code class="docutils literal notranslate"><span class="pre">locale.setlocale(locale.LC_ALL,</span> <span class="pre">&quot;&quot;)</span></code> instead.
  1828. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/90817">gh-90817</a>.)</p></li>
  1829. <li><p>Stricter rules will now be applied for numerical group references
  1830. and group names in <a class="reference internal" href="../library/re.html#re-syntax"><span class="std std-ref">regular expressions</span></a>.
  1831. Only sequences of ASCII digits will now be accepted as a numerical reference,
  1832. and the group name in <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> patterns and replacement strings
  1833. can only contain ASCII letters, digits and underscores.
  1834. For now, a deprecation warning is raised for syntax violating these rules.
  1835. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://github.com/python/cpython/issues/91760">gh-91760</a>.)</p></li>
  1836. <li><p>In the <a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a> module, the <code class="xref py py-func docutils literal notranslate"><span class="pre">re.template()</span></code> function
  1837. and the corresponding <code class="xref py py-const docutils literal notranslate"><span class="pre">re.TEMPLATE</span></code> and <code class="xref py py-const docutils literal notranslate"><span class="pre">re.T</span></code> flags
  1838. are deprecated, as they were undocumented and lacked an obvious purpose.
  1839. They will be removed in Python 3.13.
  1840. (Contributed by Serhiy Storchaka and Miro Hrončok in <a class="reference external" href="https://github.com/python/cpython/issues/92728">gh-92728</a>.)</p></li>
  1841. <li><p><a class="reference internal" href="../library/turtle.html#turtle.settiltangle" title="turtle.settiltangle"><code class="xref py py-func docutils literal notranslate"><span class="pre">turtle.settiltangle()</span></code></a> has been deprecated since Python 3.1;
  1842. it now emits a deprecation warning and will be removed in Python 3.13. Use
  1843. <a class="reference internal" href="../library/turtle.html#turtle.tiltangle" title="turtle.tiltangle"><code class="xref py py-func docutils literal notranslate"><span class="pre">turtle.tiltangle()</span></code></a> instead (it was earlier incorrectly marked
  1844. as deprecated, and its docstring is now corrected).
  1845. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45837">bpo-45837</a>.)</p></li>
  1846. <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>, which exists solely to provide compatibility support
  1847. between Python 2 and Python 3 code, is now deprecated. Its removal is
  1848. currently unplanned, but users are encouraged to use <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> instead
  1849. wherever possible.
  1850. (Contributed by Alex Waygood in <a class="reference external" href="https://github.com/python/cpython/issues/92332">gh-92332</a>.)</p></li>
  1851. <li><p>The keyword argument syntax for constructing <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> types
  1852. is now deprecated. Support will be removed in Python 3.13. (Contributed by
  1853. Jingchen Ye in <a class="reference external" href="https://github.com/python/cpython/issues/90224">gh-90224</a>.)</p></li>
  1854. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">webbrowser.MacOSX</span></code> is deprecated and will be removed in Python 3.13.
  1855. It is untested, undocumented, and not used by <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> itself.
  1856. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42255">bpo-42255</a>.)</p></li>
  1857. <li><p>The behavior of returning a value from a <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> and
  1858. <a class="reference internal" href="../library/unittest.html#unittest.IsolatedAsyncioTestCase" title="unittest.IsolatedAsyncioTestCase"><code class="xref py py-class docutils literal notranslate"><span class="pre">IsolatedAsyncioTestCase</span></code></a> test methods (other than the
  1859. default <code class="docutils literal notranslate"><span class="pre">None</span></code> value) is now deprecated.</p></li>
  1860. <li><p>Deprecated the following not-formally-documented <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> functions,
  1861. scheduled for removal in Python 3.13:</p>
  1862. <ul class="simple">
  1863. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.findTestCases()</span></code></p></li>
  1864. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.makeSuite()</span></code></p></li>
  1865. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.getTestCaseNames()</span></code></p></li>
  1866. </ul>
  1867. <p>Use <a class="reference internal" href="../library/unittest.html#unittest.TestLoader" title="unittest.TestLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestLoader</span></code></a> methods instead:</p>
  1868. <ul class="simple">
  1869. <li><p><a class="reference internal" href="../library/unittest.html#unittest.TestLoader.loadTestsFromModule" title="unittest.TestLoader.loadTestsFromModule"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestLoader.loadTestsFromModule()</span></code></a></p></li>
  1870. <li><p><a class="reference internal" href="../library/unittest.html#unittest.TestLoader.loadTestsFromTestCase" title="unittest.TestLoader.loadTestsFromTestCase"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestLoader.loadTestsFromTestCase()</span></code></a></p></li>
  1871. <li><p><a class="reference internal" href="../library/unittest.html#unittest.TestLoader.getTestCaseNames" title="unittest.TestLoader.getTestCaseNames"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestLoader.getTestCaseNames()</span></code></a></p></li>
  1872. </ul>
  1873. <p>(Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5846">bpo-5846</a>.)</p>
  1874. </li>
  1875. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestProgram.usageExit()</span></code> is marked deprecated, to be removed
  1876. in 3.13.
  1877. (Contributed by Carlos Damázio in <a class="reference external" href="https://github.com/python/cpython/issues/67048">gh-67048</a>.)</p></li>
  1878. </ul>
  1879. </section>
  1880. </section>
  1881. <section id="pending-removal-in-python-3-12">
  1882. <span id="whatsnew311-python-api-pending-removal"></span><span id="whatsnew311-pending-removal"></span><h2>Pending Removal in Python 3.12<a class="headerlink" href="#pending-removal-in-python-3-12" title="Link to this heading">¶</a></h2>
  1883. <p>The following Python APIs have been deprecated in earlier Python releases,
  1884. and will be removed in Python 3.12.</p>
  1885. <p>C APIs pending removal are
  1886. <a class="reference internal" href="#whatsnew311-c-api-pending-removal"><span class="std std-ref">listed separately</span></a>.</p>
  1887. <ul>
  1888. <li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">asynchat</span></code> module</p></li>
  1889. <li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncore</span></code> module</p></li>
  1890. <li><p>The <a class="reference internal" href="3.10.html#distutils-deprecated"><span class="std std-ref">entire distutils package</span></a></p></li>
  1891. <li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> module</p></li>
  1892. <li><p>The <a class="reference internal" href="../library/typing.html#typing.IO" title="typing.IO"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.io</span></code></a> namespace</p></li>
  1893. <li><p>The <a class="reference internal" href="../library/typing.html#typing.Pattern" title="typing.Pattern"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.re</span></code></a> namespace</p></li>
  1894. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.log()</span></code></p></li>
  1895. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.find_loader()</span></code></p></li>
  1896. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.module_repr()</span></code></p></li>
  1897. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder.find_module()</span></code></p></li>
  1898. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_loader()</span></code></p></li>
  1899. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_module()</span></code></p></li>
  1900. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.BuiltinImporter.find_module()</span></code></p></li>
  1901. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.BuiltinLoader.module_repr()</span></code></p></li>
  1902. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.FileFinder.find_loader()</span></code></p></li>
  1903. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.FileFinder.find_module()</span></code></p></li>
  1904. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.FrozenImporter.find_module()</span></code></p></li>
  1905. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.FrozenLoader.module_repr()</span></code></p></li>
  1906. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.PathFinder.find_module()</span></code></p></li>
  1907. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.WindowsRegistryFinder.find_module()</span></code></p></li>
  1908. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.module_for_loader()</span></code></p></li>
  1909. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.set_loader_wrapper()</span></code></p></li>
  1910. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.set_package_wrapper()</span></code></p></li>
  1911. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">pkgutil.ImpImporter</span></code></p></li>
  1912. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">pkgutil.ImpLoader</span></code></p></li>
  1913. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">pathlib.Path.link_to()</span></code></p></li>
  1914. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">sqlite3.enable_shared_cache()</span></code></p></li>
  1915. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">sqlite3.OptimizedUnicode()</span></code></p></li>
  1916. <li><p><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONTHREADDEBUG</span></code> environment variable</p></li>
  1917. <li><p>The following deprecated aliases in <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>:</p>
  1918. <blockquote>
  1919. <div><table class="docutils align-default">
  1920. <thead>
  1921. <tr class="row-odd"><th class="head"><p>Deprecated alias</p></th>
  1922. <th class="head"><p>Method Name</p></th>
  1923. <th class="head"><p>Deprecated in</p></th>
  1924. </tr>
  1925. </thead>
  1926. <tbody>
  1927. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">failUnless</span></code></p></td>
  1928. <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>
  1929. <td><p>3.1</p></td>
  1930. </tr>
  1931. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">failIf</span></code></p></td>
  1932. <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>
  1933. <td><p>3.1</p></td>
  1934. </tr>
  1935. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">failUnlessEqual</span></code></p></td>
  1936. <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>
  1937. <td><p>3.1</p></td>
  1938. </tr>
  1939. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">failIfEqual</span></code></p></td>
  1940. <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>
  1941. <td><p>3.1</p></td>
  1942. </tr>
  1943. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">failUnlessAlmostEqual</span></code></p></td>
  1944. <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>
  1945. <td><p>3.1</p></td>
  1946. </tr>
  1947. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">failIfAlmostEqual</span></code></p></td>
  1948. <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>
  1949. <td><p>3.1</p></td>
  1950. </tr>
  1951. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">failUnlessRaises</span></code></p></td>
  1952. <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>
  1953. <td><p>3.1</p></td>
  1954. </tr>
  1955. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">assert_</span></code></p></td>
  1956. <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>
  1957. <td><p>3.2</p></td>
  1958. </tr>
  1959. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">assertEquals</span></code></p></td>
  1960. <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>
  1961. <td><p>3.2</p></td>
  1962. </tr>
  1963. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">assertNotEquals</span></code></p></td>
  1964. <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>
  1965. <td><p>3.2</p></td>
  1966. </tr>
  1967. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">assertAlmostEquals</span></code></p></td>
  1968. <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>
  1969. <td><p>3.2</p></td>
  1970. </tr>
  1971. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">assertNotAlmostEquals</span></code></p></td>
  1972. <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>
  1973. <td><p>3.2</p></td>
  1974. </tr>
  1975. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">assertRegexpMatches</span></code></p></td>
  1976. <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>
  1977. <td><p>3.2</p></td>
  1978. </tr>
  1979. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">assertRaisesRegexp</span></code></p></td>
  1980. <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>
  1981. <td><p>3.2</p></td>
  1982. </tr>
  1983. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">assertNotRegexpMatches</span></code></p></td>
  1984. <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>
  1985. <td><p>3.5</p></td>
  1986. </tr>
  1987. </tbody>
  1988. </table>
  1989. </div></blockquote>
  1990. </li>
  1991. </ul>
  1992. </section>
  1993. <section id="removed">
  1994. <span id="whatsnew311-python-api-removed"></span><span id="whatsnew311-removed"></span><h2>Removed<a class="headerlink" href="#removed" title="Link to this heading">¶</a></h2>
  1995. <p>This section lists Python APIs that have been removed in Python 3.11.</p>
  1996. <p>Removed C APIs are <a class="reference internal" href="#whatsnew311-c-api-removed"><span class="std std-ref">listed separately</span></a>.</p>
  1997. <ul>
  1998. <li><p>Removed the <code class="xref py py-func docutils literal notranslate"><span class="pre">&#64;asyncio.coroutine()</span></code> <a class="reference internal" href="../glossary.html#term-decorator"><span class="xref std std-term">decorator</span></a>
  1999. enabling legacy generator-based coroutines to be compatible with
  2000. <a class="reference internal" href="../reference/compound_stmts.html#async"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span></code></a> / <a class="reference internal" href="../reference/expressions.html#await"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">await</span></code></a> code.
  2001. The function has been deprecated since Python 3.8 and the removal was
  2002. initially scheduled for Python 3.10. Use <a class="reference internal" href="../reference/compound_stmts.html#async-def"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">async</span> <span class="pre">def</span></code></a> instead.
  2003. (Contributed by Illia Volochii in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43216">bpo-43216</a>.)</p></li>
  2004. <li><p>Removed <code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.coroutines.CoroWrapper</span></code> used for wrapping legacy
  2005. generator-based coroutine objects in the debug mode.
  2006. (Contributed by Illia Volochii in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43216">bpo-43216</a>.)</p></li>
  2007. <li><p>Due to significant security concerns, the <em>reuse_address</em> parameter of
  2008. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_datagram_endpoint" title="asyncio.loop.create_datagram_endpoint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.create_datagram_endpoint()</span></code></a>, disabled in Python 3.9, is
  2009. now entirely removed. This is because of the behavior of the socket option
  2010. <code class="docutils literal notranslate"><span class="pre">SO_REUSEADDR</span></code> in UDP.
  2011. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45129">bpo-45129</a>.)</p></li>
  2012. <li><p>Removed the <code class="xref py py-mod docutils literal notranslate"><span class="pre">binhex</span></code> module, deprecated in Python 3.9.
  2013. Also removed the related, similarly-deprecated <a class="reference internal" href="../library/binascii.html#module-binascii" title="binascii: Tools for converting between binary and various ASCII-encoded binary representations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">binascii</span></code></a> functions:</p>
  2014. <ul class="simple">
  2015. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">binascii.a2b_hqx()</span></code></p></li>
  2016. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">binascii.b2a_hqx()</span></code></p></li>
  2017. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">binascii.rlecode_hqx()</span></code></p></li>
  2018. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">binascii.rldecode_hqx()</span></code></p></li>
  2019. </ul>
  2020. <p>The <a class="reference internal" href="../library/binascii.html#binascii.crc_hqx" title="binascii.crc_hqx"><code class="xref py py-func docutils literal notranslate"><span class="pre">binascii.crc_hqx()</span></code></a> function remains available.</p>
  2021. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45085">bpo-45085</a>.)</p>
  2022. </li>
  2023. <li><p>Removed the <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code> <code class="docutils literal notranslate"><span class="pre">bdist_msi</span></code> command deprecated in Python 3.9.
  2024. Use <code class="docutils literal notranslate"><span class="pre">bdist_wheel</span></code> (wheel packages) instead.
  2025. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45124">bpo-45124</a>.)</p></li>
  2026. <li><p>Removed the <a class="reference internal" href="../reference/datamodel.html#object.__getitem__" title="object.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a> methods of
  2027. <a class="reference internal" href="../library/xml.dom.pulldom.html#xml.dom.pulldom.DOMEventStream" title="xml.dom.pulldom.DOMEventStream"><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.dom.pulldom.DOMEventStream</span></code></a>, <a class="reference internal" href="../library/wsgiref.html#wsgiref.util.FileWrapper" title="wsgiref.util.FileWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">wsgiref.util.FileWrapper</span></code></a>
  2028. and <a class="reference internal" href="../library/fileinput.html#fileinput.FileInput" title="fileinput.FileInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">fileinput.FileInput</span></code></a>, deprecated since Python 3.9.
  2029. (Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45132">bpo-45132</a>.)</p></li>
  2030. <li><p>Removed the deprecated <a class="reference internal" href="../library/gettext.html#module-gettext" title="gettext: Multilingual internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gettext</span></code></a> functions
  2031. <code class="xref py py-func docutils literal notranslate"><span class="pre">lgettext()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">ldgettext()</span></code>,
  2032. <code class="xref py py-func docutils literal notranslate"><span class="pre">lngettext()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">ldngettext()</span></code>.
  2033. Also removed the <code class="xref py py-func docutils literal notranslate"><span class="pre">bind_textdomain_codeset()</span></code> function,
  2034. the <code class="xref py py-meth docutils literal notranslate"><span class="pre">NullTranslations.output_charset()</span></code> and
  2035. <code class="xref py py-meth docutils literal notranslate"><span class="pre">NullTranslations.set_output_charset()</span></code> methods,
  2036. and the <em>codeset</em> parameter of <code class="xref py py-func docutils literal notranslate"><span class="pre">translation()</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">install()</span></code>,
  2037. since they are only used for the <code class="xref py py-func docutils literal notranslate"><span class="pre">l*gettext()</span></code> functions.
  2038. (Contributed by Donghee Na and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44235">bpo-44235</a>.)</p></li>
  2039. <li><p>Removed from the <a class="reference internal" href="../library/inspect.html#module-inspect" title="inspect: Extract information and source code from live objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">inspect</span></code></a> module:</p>
  2040. <ul class="simple">
  2041. <li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">getargspec()</span></code> function, deprecated since Python 3.0;
  2042. use <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.signature()</span></code></a> or <a class="reference internal" href="../library/inspect.html#inspect.getfullargspec" title="inspect.getfullargspec"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getfullargspec()</span></code></a> instead.</p></li>
  2043. <li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">formatargspec()</span></code> function, deprecated since Python 3.5;
  2044. use the <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.signature()</span></code></a> function
  2045. or the <a class="reference internal" href="../library/inspect.html#inspect.Signature" title="inspect.Signature"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.Signature</span></code></a> object directly.</p></li>
  2046. <li><p>The undocumented <code class="xref py py-meth docutils literal notranslate"><span class="pre">Signature.from_builtin()</span></code>
  2047. and <code class="xref py py-meth docutils literal notranslate"><span class="pre">Signature.from_function()</span></code> methods, deprecated since Python 3.5;
  2048. use the <a class="reference internal" href="../library/inspect.html#inspect.Signature.from_callable" title="inspect.Signature.from_callable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Signature.from_callable()</span></code></a>
  2049. method instead.</p></li>
  2050. </ul>
  2051. <p>(Contributed by Hugo van Kemenade in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45320">bpo-45320</a>.)</p>
  2052. </li>
  2053. <li><p>Removed the <a class="reference internal" href="../reference/datamodel.html#object.__class_getitem__" title="object.__class_getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__class_getitem__()</span></code></a> method
  2054. from <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>,
  2055. because it was not used and added by mistake in previous versions.
  2056. (Contributed by Nikita Sobolev in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46483">bpo-46483</a>.)</p></li>
  2057. <li><p>Removed the <code class="xref py py-class docutils literal notranslate"><span class="pre">MailmanProxy</span></code> class in the <code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code> module,
  2058. as it is unusable without the external <code class="xref py py-mod docutils literal notranslate"><span class="pre">mailman</span></code> package.
  2059. (Contributed by Donghee Na in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35800">bpo-35800</a>.)</p></li>
  2060. <li><p>Removed the deprecated <code class="xref py py-meth docutils literal notranslate"><span class="pre">split()</span></code> method of <code class="xref py py-class docutils literal notranslate"><span class="pre">_tkinter.TkappType</span></code>.
  2061. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=38371">bpo-38371</a>.)</p></li>
  2062. <li><p>Removed namespace package support from <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> discovery.
  2063. It was introduced in Python 3.4 but has been broken since Python 3.7.
  2064. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23882">bpo-23882</a>.)</p></li>
  2065. <li><p>Removed the undocumented private <code class="xref py py-meth docutils literal notranslate"><span class="pre">float.__set_format__()</span></code> method,
  2066. previously known as <code class="xref py py-meth docutils literal notranslate"><span class="pre">float.__setformat__()</span></code> in Python 3.7.
  2067. Its docstring said: “You probably don’t want to use this function.
  2068. It exists mainly to be used in Python’s test suite.”
  2069. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46852">bpo-46852</a>.)</p></li>
  2070. <li><p>The <code class="xref std std-option docutils literal notranslate"><span class="pre">--experimental-isolated-subinterpreters</span></code> configure flag
  2071. (and corresponding <code class="xref c c-macro docutils literal notranslate"><span class="pre">EXPERIMENTAL_ISOLATED_SUBINTERPRETERS</span></code> macro)
  2072. have been removed.</p></li>
  2073. <li><p><a class="reference external" href="https://pypi.org/project/pynche/">Pynche</a>
  2074. — The Pythonically Natural Color and Hue Editor — has been moved out
  2075. of <code class="docutils literal notranslate"><span class="pre">Tools/scripts</span></code> and is <a class="reference external" href="https://gitlab.com/warsaw/pynche/-/tree/main">being developed independently</a> from the Python source tree.</p></li>
  2076. </ul>
  2077. </section>
  2078. <section id="porting-to-python-3-11">
  2079. <span id="whatsnew311-python-api-porting"></span><span id="whatsnew311-porting"></span><h2>Porting to Python 3.11<a class="headerlink" href="#porting-to-python-3-11" title="Link to this heading">¶</a></h2>
  2080. <p>This section lists previously described changes and other bugfixes
  2081. in the Python API that may require changes to your Python code.</p>
  2082. <p>Porting notes for the C API are
  2083. <a class="reference internal" href="#whatsnew311-c-api-porting"><span class="std std-ref">listed separately</span></a>.</p>
  2084. <ul class="simple">
  2085. <li><p><a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a>, <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>, <a class="reference internal" href="../library/codecs.html#codecs.open" title="codecs.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">codecs.open()</span></code></a> and
  2086. <a class="reference internal" href="../library/fileinput.html#fileinput.FileInput" title="fileinput.FileInput"><code class="xref py py-class docutils literal notranslate"><span class="pre">fileinput.FileInput</span></code></a> no longer accept <code class="docutils literal notranslate"><span class="pre">'U'</span></code> (“universal newline”)
  2087. in the file mode. In Python 3, “universal newline” mode is used by default
  2088. whenever a file is opened in text mode,
  2089. and the <code class="docutils literal notranslate"><span class="pre">'U'</span></code> flag has been deprecated since Python 3.3.
  2090. The <a class="reference internal" href="../library/functions.html#open-newline-parameter"><span class="std std-ref">newline parameter</span></a>
  2091. to these functions controls how universal newlines work.
  2092. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37330">bpo-37330</a>.)</p></li>
  2093. <li><p><a class="reference internal" href="../library/ast.html#ast.AST" title="ast.AST"><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.AST</span></code></a> node positions are now validated when provided to
  2094. <a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> and other related functions. If invalid positions are detected,
  2095. a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> will be raised. (Contributed by Pablo Galindo in <a class="reference external" href="https://github.com/python/cpython/issues/93351">gh-93351</a>)</p></li>
  2096. <li><p>Prohibited passing non-<a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">concurrent.futures.ThreadPoolExecutor</span></code></a>
  2097. executors to <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.set_default_executor" title="asyncio.loop.set_default_executor"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.set_default_executor()</span></code></a>
  2098. following a deprecation in Python 3.8.
  2099. (Contributed by Illia Volochii in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43234">bpo-43234</a>.)</p></li>
  2100. <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>: The <a class="reference internal" href="../library/calendar.html#calendar.LocaleTextCalendar" title="calendar.LocaleTextCalendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">calendar.LocaleTextCalendar</span></code></a> and
  2101. <a class="reference internal" href="../library/calendar.html#calendar.LocaleHTMLCalendar" title="calendar.LocaleHTMLCalendar"><code class="xref py py-class docutils literal notranslate"><span class="pre">calendar.LocaleHTMLCalendar</span></code></a> classes now use
  2102. <a class="reference internal" href="../library/locale.html#locale.getlocale" title="locale.getlocale"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.getlocale()</span></code></a>, instead of using <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>,
  2103. if no locale is specified.
  2104. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46659">bpo-46659</a>.)</p></li>
  2105. <li><p>The <a class="reference internal" href="../library/pdb.html#module-pdb" title="pdb: The Python debugger for interactive interpreters."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pdb</span></code></a> module now reads the <code class="file docutils literal notranslate"><span class="pre">.pdbrc</span></code> configuration file with
  2106. the <code class="docutils literal notranslate"><span class="pre">'UTF-8'</span></code> encoding.
  2107. (Contributed by Srinivas Reddy Thatiparthy (శ్రీనివాస్ రెడ్డి తాటిపర్తి) in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41137">bpo-41137</a>.)</p></li>
  2108. <li><p>The <em>population</em> parameter of <a class="reference internal" href="../library/random.html#random.sample" title="random.sample"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.sample()</span></code></a> must be a sequence,
  2109. and automatic conversion of <a class="reference internal" href="../library/stdtypes.html#set" title="set"><code class="xref py py-class docutils literal notranslate"><span class="pre">set</span></code></a>s to <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a>s
  2110. is no longer supported. Also, if the sample size
  2111. is larger than the population size, a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised.
  2112. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40465">bpo-40465</a>.)</p></li>
  2113. <li><p>The <em>random</em> optional parameter of <a class="reference internal" href="../library/random.html#random.shuffle" title="random.shuffle"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.shuffle()</span></code></a> was removed.
  2114. It was previously an arbitrary random function to use for the shuffle;
  2115. now, <a class="reference internal" href="../library/random.html#random.random" title="random.random"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.random()</span></code></a> (its previous default) will always be used.</p></li>
  2116. <li><p>In <a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a> <a class="reference internal" href="../library/re.html#re-syntax"><span class="std std-ref">Regular Expression Syntax</span></a>, global inline flags (e.g. <code class="docutils literal notranslate"><span class="pre">(?i)</span></code>)
  2117. can now only be used at the start of regular expressions.
  2118. Using them elsewhere has been deprecated since Python 3.6.
  2119. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=47066">bpo-47066</a>.)</p></li>
  2120. <li><p>In the <a class="reference internal" href="../library/re.html#module-re" title="re: Regular expression operations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">re</span></code></a> module, several long-standing bugs where fixed that,
  2121. in rare cases, could cause capture groups to get the wrong result.
  2122. Therefore, this could change the captured output in these cases.
  2123. (Contributed by Ma Lin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35859">bpo-35859</a>.)</p></li>
  2124. </ul>
  2125. </section>
  2126. <section id="build-changes">
  2127. <span id="whatsnew311-build-changes"></span><h2>Build Changes<a class="headerlink" href="#build-changes" title="Link to this heading">¶</a></h2>
  2128. <ul>
  2129. <li><p>CPython now has <span class="target" id="index-33"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/"><strong>PEP 11</strong></a> <span class="target" id="index-34"></span><a class="pep reference external" href="https://peps.python.org/pep-0011/#tier-3"><strong>Tier 3 support</strong></a> for
  2130. cross compiling to the <a class="reference external" href="https://webassembly.org/">WebAssembly</a> platforms
  2131. <a class="reference external" href="https://emscripten.org/">Emscripten</a>
  2132. (<code class="docutils literal notranslate"><span class="pre">wasm32-unknown-emscripten</span></code>, i.e. Python in the browser)
  2133. and <a class="reference external" href="https://wasi.dev/">WebAssembly System Interface (WASI)</a>
  2134. (<code class="docutils literal notranslate"><span class="pre">wasm32-unknown-wasi</span></code>).
  2135. The effort is inspired by previous work like <a class="reference external" href="https://pyodide.org/">Pyodide</a>.
  2136. These platforms provide a limited subset of POSIX APIs; Python standard
  2137. libraries features and modules related to networking, processes, threading,
  2138. signals, mmap, and users/groups are not available or don’t work.
  2139. (Emscripten contributed by Christian Heimes and Ethan Smith in <a class="reference external" href="https://github.com/python/cpython/issues/84461">gh-84461</a>
  2140. and WASI contributed by Christian Heimes in <a class="reference external" href="https://github.com/python/cpython/issues/90473">gh-90473</a>;
  2141. platforms promoted in <a class="reference external" href="https://github.com/python/cpython/issues/95085">gh-95085</a>)</p></li>
  2142. <li><p>Building CPython now requires:</p>
  2143. <ul class="simple">
  2144. <li><p>A <a class="reference external" href="https://en.cppreference.com/w/c/11">C11</a> compiler and standard library.
  2145. <a class="reference external" href="https://en.wikipedia.org/wiki/C11_(C_standard_revision)#Optional_features">Optional C11 features</a>
  2146. are not required.
  2147. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46656">bpo-46656</a>,
  2148. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45440">bpo-45440</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46640">bpo-46640</a>.)</p></li>
  2149. <li><p>Support for <a class="reference external" href="https://en.wikipedia.org/wiki/IEEE_754">IEEE 754</a>
  2150. floating point numbers.
  2151. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46917">bpo-46917</a>.)</p></li>
  2152. </ul>
  2153. </li>
  2154. <li><p>The <code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_NO_NAN</span></code> macro has been removed.
  2155. Since CPython now requires IEEE 754 floats, NaN values are always available.
  2156. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46656">bpo-46656</a>.)</p></li>
  2157. <li><p>The <a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> package now requires <a class="reference external" href="https://www.tcl.tk">Tcl/Tk</a>
  2158. version 8.5.12 or newer.
  2159. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46996">bpo-46996</a>.)</p></li>
  2160. <li><p>Build dependencies, compiler flags, and linker flags for most stdlib
  2161. extension modules are now detected by <strong class="program">configure</strong>. libffi, libnsl,
  2162. libsqlite3, zlib, bzip2, liblzma, libcrypt, Tcl/Tk, and uuid flags
  2163. are detected by <a class="reference external" href="https://www.freedesktop.org/wiki/Software/pkg-config/">pkg-config</a> (when available).
  2164. <a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> now requires a pkg-config command
  2165. to detect development settings for <a class="reference external" href="https://www.tcl.tk">Tcl/Tk</a> headers and libraries.
  2166. (Contributed by Christian Heimes and Erlend Egeberg Aasland in
  2167. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45847">bpo-45847</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45747">bpo-45747</a>, and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45763">bpo-45763</a>.)</p></li>
  2168. <li><p>libpython is no longer linked against libcrypt.
  2169. (Contributed by Mike Gilbert in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45433">bpo-45433</a>.)</p></li>
  2170. <li><p>CPython can now be built with the
  2171. <a class="reference external" href="https://clang.llvm.org/docs/ThinLTO.html">ThinLTO</a> option
  2172. via passing <code class="docutils literal notranslate"><span class="pre">thin</span></code> to <a class="reference internal" href="../using/configure.html#cmdoption-with-lto"><code class="xref std std-option docutils literal notranslate"><span class="pre">--with-lto</span></code></a>, i.e. <code class="docutils literal notranslate"><span class="pre">--with-lto=thin</span></code>.
  2173. (Contributed by Donghee Na and Brett Holman in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44340">bpo-44340</a>.)</p></li>
  2174. <li><p>Freelists for object structs can now be disabled. A new <strong class="program">configure</strong>
  2175. option <a class="reference internal" href="../using/configure.html#cmdoption-without-freelists"><code class="xref std std-option docutils literal notranslate"><span class="pre">--without-freelists</span></code></a> can be used to disable all freelists
  2176. except empty tuple singleton.
  2177. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45522">bpo-45522</a>.)</p></li>
  2178. <li><p><code class="docutils literal notranslate"><span class="pre">Modules/Setup</span></code> and <code class="docutils literal notranslate"><span class="pre">Modules/makesetup</span></code> have been improved and tied up.
  2179. Extension modules can now be built through <code class="docutils literal notranslate"><span class="pre">makesetup</span></code>. All except some
  2180. test modules can be linked statically into a main binary or library.
  2181. (Contributed by Brett Cannon and Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45548">bpo-45548</a>,
  2182. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45570">bpo-45570</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45571">bpo-45571</a>, and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43974">bpo-43974</a>.)</p>
  2183. <div class="admonition note">
  2184. <p class="admonition-title">Note</p>
  2185. <p>Use the environment variables <code class="xref std std-envvar docutils literal notranslate"><span class="pre">TCLTK_CFLAGS</span></code> and
  2186. <code class="xref std std-envvar docutils literal notranslate"><span class="pre">TCLTK_LIBS</span></code> to manually specify the location of Tcl/Tk headers
  2187. and libraries. The <strong class="program">configure</strong> options
  2188. <code class="xref std std-option docutils literal notranslate"><span class="pre">--with-tcltk-includes</span></code> and <code class="xref std std-option docutils literal notranslate"><span class="pre">--with-tcltk-libs</span></code>
  2189. have been removed.</p>
  2190. <p>On RHEL 7 and CentOS 7 the development packages do not provide <code class="docutils literal notranslate"><span class="pre">tcl.pc</span></code>
  2191. and <code class="docutils literal notranslate"><span class="pre">tk.pc</span></code>; use <code class="docutils literal notranslate"><span class="pre">TCLTK_LIBS=&quot;-ltk8.5</span> <span class="pre">-ltkstub8.5</span> <span class="pre">-ltcl8.5&quot;</span></code>.
  2192. The directory <code class="docutils literal notranslate"><span class="pre">Misc/rhel7</span></code> contains <code class="docutils literal notranslate"><span class="pre">.pc</span></code> files and instructions
  2193. on how to build Python with RHEL 7’s and CentOS 7’s Tcl/Tk and OpenSSL.</p>
  2194. </div>
  2195. </li>
  2196. <li><p>CPython will now use 30-bit digits by default for the Python <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>
  2197. implementation. Previously, the default was to use 30-bit digits on platforms
  2198. with <code class="docutils literal notranslate"><span class="pre">SIZEOF_VOID_P</span> <span class="pre">&gt;=</span> <span class="pre">8</span></code>, and 15-bit digits otherwise. It’s still possible
  2199. to explicitly request use of 15-bit digits via either the
  2200. <a class="reference internal" href="../using/configure.html#cmdoption-enable-big-digits"><code class="xref std std-option docutils literal notranslate"><span class="pre">--enable-big-digits</span></code></a> option to the configure script
  2201. or (for Windows) the <code class="docutils literal notranslate"><span class="pre">PYLONG_BITS_IN_DIGIT</span></code> variable in <code class="docutils literal notranslate"><span class="pre">PC/pyconfig.h</span></code>,
  2202. but this option may be removed at some point in the future.
  2203. (Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45569">bpo-45569</a>.)</p></li>
  2204. </ul>
  2205. </section>
  2206. <section id="c-api-changes">
  2207. <span id="whatsnew311-c-api"></span><h2>C API Changes<a class="headerlink" href="#c-api-changes" title="Link to this heading">¶</a></h2>
  2208. <section id="whatsnew311-c-api-new-features">
  2209. <span id="id5"></span><h3>New Features<a class="headerlink" href="#whatsnew311-c-api-new-features" title="Link to this heading">¶</a></h3>
  2210. <ul>
  2211. <li><p>Add a new <a class="reference internal" href="../c-api/type.html#c.PyType_GetName" title="PyType_GetName"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetName()</span></code></a> function to get type’s short name.
  2212. (Contributed by Hai Shi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42035">bpo-42035</a>.)</p></li>
  2213. <li><p>Add a new <a class="reference internal" href="../c-api/type.html#c.PyType_GetQualName" title="PyType_GetQualName"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetQualName()</span></code></a> function to get type’s qualified name.
  2214. (Contributed by Hai Shi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42035">bpo-42035</a>.)</p></li>
  2215. <li><p>Add new <a class="reference internal" href="../c-api/init.html#c.PyThreadState_EnterTracing" title="PyThreadState_EnterTracing"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_EnterTracing()</span></code></a> and
  2216. <a class="reference internal" href="../c-api/init.html#c.PyThreadState_LeaveTracing" title="PyThreadState_LeaveTracing"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_LeaveTracing()</span></code></a> functions to the limited C API to
  2217. suspend and resume tracing and profiling.
  2218. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43760">bpo-43760</a>.)</p></li>
  2219. <li><p>Added the <a class="reference internal" href="../c-api/apiabiversion.html#c.Py_Version" title="Py_Version"><code class="xref c c-data docutils literal notranslate"><span class="pre">Py_Version</span></code></a> constant which bears the same value as
  2220. <a class="reference internal" href="../c-api/apiabiversion.html#c.PY_VERSION_HEX" title="PY_VERSION_HEX"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PY_VERSION_HEX</span></code></a>.
  2221. (Contributed by Gabriele N. Tornetta in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43931">bpo-43931</a>.)</p></li>
  2222. <li><p><a class="reference internal" href="../c-api/buffer.html#c.Py_buffer" title="Py_buffer"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_buffer</span></code></a> and APIs are now part of the limited API and the stable
  2223. ABI:</p>
  2224. <ul class="simple">
  2225. <li><p><a class="reference internal" href="../c-api/buffer.html#c.PyObject_CheckBuffer" title="PyObject_CheckBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CheckBuffer()</span></code></a></p></li>
  2226. <li><p><a class="reference internal" href="../c-api/buffer.html#c.PyObject_GetBuffer" title="PyObject_GetBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_GetBuffer()</span></code></a></p></li>
  2227. <li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_GetPointer" title="PyBuffer_GetPointer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_GetPointer()</span></code></a></p></li>
  2228. <li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_SizeFromFormat" title="PyBuffer_SizeFromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_SizeFromFormat()</span></code></a></p></li>
  2229. <li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_ToContiguous" title="PyBuffer_ToContiguous"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_ToContiguous()</span></code></a></p></li>
  2230. <li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_FromContiguous" title="PyBuffer_FromContiguous"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_FromContiguous()</span></code></a></p></li>
  2231. <li><p><a class="reference internal" href="../c-api/buffer.html#c.PyObject_CopyData" title="PyObject_CopyData"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_CopyData()</span></code></a></p></li>
  2232. <li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_IsContiguous" title="PyBuffer_IsContiguous"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_IsContiguous()</span></code></a></p></li>
  2233. <li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_FillContiguousStrides" title="PyBuffer_FillContiguousStrides"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_FillContiguousStrides()</span></code></a></p></li>
  2234. <li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_FillInfo" title="PyBuffer_FillInfo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_FillInfo()</span></code></a></p></li>
  2235. <li><p><a class="reference internal" href="../c-api/buffer.html#c.PyBuffer_Release" title="PyBuffer_Release"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyBuffer_Release()</span></code></a></p></li>
  2236. <li><p><a class="reference internal" href="../c-api/memoryview.html#c.PyMemoryView_FromBuffer" title="PyMemoryView_FromBuffer"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMemoryView_FromBuffer()</span></code></a></p></li>
  2237. <li><p><a class="reference internal" href="../c-api/typeobj.html#c.PyBufferProcs.bf_getbuffer" title="PyBufferProcs.bf_getbuffer"><code class="xref c c-member docutils literal notranslate"><span class="pre">bf_getbuffer</span></code></a> and
  2238. <a class="reference internal" href="../c-api/typeobj.html#c.PyBufferProcs.bf_releasebuffer" title="PyBufferProcs.bf_releasebuffer"><code class="xref c c-member docutils literal notranslate"><span class="pre">bf_releasebuffer</span></code></a> type slots</p></li>
  2239. </ul>
  2240. <p>(Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45459">bpo-45459</a>.)</p>
  2241. </li>
  2242. <li><p>Added the <a class="reference internal" href="../c-api/type.html#c.PyType_GetModuleByDef" title="PyType_GetModuleByDef"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetModuleByDef()</span></code></a> function, used to get the module
  2243. in which a method was defined, in cases where this information is not
  2244. available directly (via <a class="reference internal" href="../c-api/structures.html#c.PyCMethod" title="PyCMethod"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyCMethod</span></code></a>).
  2245. (Contributed by Petr Viktorin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46613">bpo-46613</a>.)</p></li>
  2246. <li><p>Add new functions to pack and unpack C double (serialize and deserialize):
  2247. <a class="reference internal" href="../c-api/float.html#c.PyFloat_Pack2" title="PyFloat_Pack2"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_Pack2()</span></code></a>, <a class="reference internal" href="../c-api/float.html#c.PyFloat_Pack4" title="PyFloat_Pack4"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_Pack4()</span></code></a>, <a class="reference internal" href="../c-api/float.html#c.PyFloat_Pack8" title="PyFloat_Pack8"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_Pack8()</span></code></a>,
  2248. <a class="reference internal" href="../c-api/float.html#c.PyFloat_Unpack2" title="PyFloat_Unpack2"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_Unpack2()</span></code></a>, <a class="reference internal" href="../c-api/float.html#c.PyFloat_Unpack4" title="PyFloat_Unpack4"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_Unpack4()</span></code></a> and
  2249. <a class="reference internal" href="../c-api/float.html#c.PyFloat_Unpack8" title="PyFloat_Unpack8"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFloat_Unpack8()</span></code></a>.
  2250. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46906">bpo-46906</a>.)</p></li>
  2251. <li><p>Add new functions to get frame object attributes:
  2252. <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBuiltins" title="PyFrame_GetBuiltins"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBuiltins()</span></code></a>, <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetGenerator" title="PyFrame_GetGenerator"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetGenerator()</span></code></a>,
  2253. <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetGlobals" title="PyFrame_GetGlobals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetGlobals()</span></code></a>, <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLasti" title="PyFrame_GetLasti"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLasti()</span></code></a>.</p></li>
  2254. <li><p>Added two new functions to get and set the active exception instance:
  2255. <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_GetHandledException" title="PyErr_GetHandledException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetHandledException()</span></code></a> and <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetHandledException" title="PyErr_SetHandledException"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetHandledException()</span></code></a>.
  2256. These are alternatives to <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetExcInfo" title="PyErr_SetExcInfo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetExcInfo()</span></code></a> and
  2257. <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_GetExcInfo" title="PyErr_GetExcInfo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetExcInfo()</span></code></a> which work with the legacy 3-tuple
  2258. representation of exceptions.
  2259. (Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46343">bpo-46343</a>.)</p></li>
  2260. <li><p>Added the <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.safe_path" title="PyConfig.safe_path"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.safe_path</span></code></a> member.
  2261. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/57684">gh-57684</a>.)</p></li>
  2262. </ul>
  2263. </section>
  2264. <section id="whatsnew311-c-api-porting">
  2265. <span id="id6"></span><h3>Porting to Python 3.11<a class="headerlink" href="#whatsnew311-c-api-porting" title="Link to this heading">¶</a></h3>
  2266. <ul id="whatsnew311-pep670">
  2267. <li><p>Some macros have been converted to static inline functions to avoid
  2268. <a class="reference external" href="https://gcc.gnu.org/onlinedocs/cpp/Macro-Pitfalls.html">macro pitfalls</a>.
  2269. The change should be mostly transparent to users,
  2270. as the replacement functions will cast their arguments to the expected types
  2271. to avoid compiler warnings due to static type checks.
  2272. However, when the limited C API is set to &gt;=3.11,
  2273. these casts are not done,
  2274. and callers will need to cast arguments to their expected types.
  2275. See <span class="target" id="index-35"></span><a class="pep reference external" href="https://peps.python.org/pep-0670/"><strong>PEP 670</strong></a> for more details.
  2276. (Contributed by Victor Stinner and Erlend E. Aasland in <a class="reference external" href="https://github.com/python/cpython/issues/89653">gh-89653</a>.)</p></li>
  2277. <li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetExcInfo" title="PyErr_SetExcInfo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetExcInfo()</span></code></a> no longer uses the <code class="docutils literal notranslate"><span class="pre">type</span></code> and <code class="docutils literal notranslate"><span class="pre">traceback</span></code>
  2278. arguments, the interpreter now derives those values from the exception
  2279. instance (the <code class="docutils literal notranslate"><span class="pre">value</span></code> argument). The function still steals references
  2280. of all three arguments.
  2281. (Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45711">bpo-45711</a>.)</p></li>
  2282. <li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_GetExcInfo" title="PyErr_GetExcInfo"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_GetExcInfo()</span></code></a> now derives the <code class="docutils literal notranslate"><span class="pre">type</span></code> and <code class="docutils literal notranslate"><span class="pre">traceback</span></code>
  2283. fields of the result from the exception instance (the <code class="docutils literal notranslate"><span class="pre">value</span></code> field).
  2284. (Contributed by Irit Katriel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45711">bpo-45711</a>.)</p></li>
  2285. <li><p><a class="reference internal" href="../c-api/import.html#c._frozen" title="_frozen"><code class="xref c c-struct docutils literal notranslate"><span class="pre">_frozen</span></code></a> has a new <code class="docutils literal notranslate"><span class="pre">is_package</span></code> field to indicate whether
  2286. or not the frozen module is a package. Previously, a negative value
  2287. in the <code class="docutils literal notranslate"><span class="pre">size</span></code> field was the indicator. Now only non-negative values
  2288. be used for <code class="docutils literal notranslate"><span class="pre">size</span></code>.
  2289. (Contributed by Kumar Aditya in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46608">bpo-46608</a>.)</p></li>
  2290. <li><p><a class="reference internal" href="../c-api/init.html#c._PyFrameEvalFunction" title="_PyFrameEvalFunction"><code class="xref c c-func docutils literal notranslate"><span class="pre">_PyFrameEvalFunction()</span></code></a> now takes <code class="docutils literal notranslate"><span class="pre">_PyInterpreterFrame*</span></code>
  2291. as its second parameter, instead of <code class="docutils literal notranslate"><span class="pre">PyFrameObject*</span></code>.
  2292. See <span class="target" id="index-36"></span><a class="pep reference external" href="https://peps.python.org/pep-0523/"><strong>PEP 523</strong></a> for more details of how to use this function pointer type.</p></li>
  2293. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_New()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_NewWithPosOnlyArgs()</span></code> now take
  2294. an additional <code class="docutils literal notranslate"><span class="pre">exception_table</span></code> argument.
  2295. Using these functions should be avoided, if at all possible.
  2296. To get a custom code object: create a code object using the compiler,
  2297. then get a modified version with the <code class="docutils literal notranslate"><span class="pre">replace</span></code> method.</p></li>
  2298. <li><p><a class="reference internal" href="../c-api/code.html#c.PyCodeObject" title="PyCodeObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyCodeObject</span></code></a> no longer has the <code class="docutils literal notranslate"><span class="pre">co_code</span></code>, <code class="docutils literal notranslate"><span class="pre">co_varnames</span></code>,
  2299. <code class="docutils literal notranslate"><span class="pre">co_cellvars</span></code> and <code class="docutils literal notranslate"><span class="pre">co_freevars</span></code> fields. Instead, use
  2300. <a class="reference internal" href="../c-api/code.html#c.PyCode_GetCode" title="PyCode_GetCode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_GetCode()</span></code></a>, <a class="reference internal" href="../c-api/code.html#c.PyCode_GetVarnames" title="PyCode_GetVarnames"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_GetVarnames()</span></code></a>,
  2301. <a class="reference internal" href="../c-api/code.html#c.PyCode_GetCellvars" title="PyCode_GetCellvars"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_GetCellvars()</span></code></a> and <a class="reference internal" href="../c-api/code.html#c.PyCode_GetFreevars" title="PyCode_GetFreevars"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyCode_GetFreevars()</span></code></a> respectively
  2302. to access them via the C API.
  2303. (Contributed by Brandt Bucher in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46841">bpo-46841</a> and Ken Jin in <a class="reference external" href="https://github.com/python/cpython/issues/92154">gh-92154</a>
  2304. and <a class="reference external" href="https://github.com/python/cpython/issues/94936">gh-94936</a>.)</p></li>
  2305. <li><p>The old trashcan macros (<code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_SAFE_BEGIN</span></code>/<code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_SAFE_END</span></code>)
  2306. are now deprecated. They should be replaced by the new macros
  2307. <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_BEGIN</span></code> and <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_END</span></code>.</p>
  2308. <p>A tp_dealloc function that has the old macros, such as:</p>
  2309. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">static</span> <span class="n">void</span>
  2310. <span class="n">mytype_dealloc</span><span class="p">(</span><span class="n">mytype</span> <span class="o">*</span><span class="n">p</span><span class="p">)</span>
  2311. <span class="p">{</span>
  2312. <span class="n">PyObject_GC_UnTrack</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
  2313. <span class="n">Py_TRASHCAN_SAFE_BEGIN</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
  2314. <span class="o">...</span>
  2315. <span class="n">Py_TRASHCAN_SAFE_END</span>
  2316. <span class="p">}</span>
  2317. </pre></div>
  2318. </div>
  2319. <p>should migrate to the new macros as follows:</p>
  2320. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">static</span> <span class="n">void</span>
  2321. <span class="n">mytype_dealloc</span><span class="p">(</span><span class="n">mytype</span> <span class="o">*</span><span class="n">p</span><span class="p">)</span>
  2322. <span class="p">{</span>
  2323. <span class="n">PyObject_GC_UnTrack</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
  2324. <span class="n">Py_TRASHCAN_BEGIN</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">mytype_dealloc</span><span class="p">)</span>
  2325. <span class="o">...</span>
  2326. <span class="n">Py_TRASHCAN_END</span>
  2327. <span class="p">}</span>
  2328. </pre></div>
  2329. </div>
  2330. <p>Note that <code class="docutils literal notranslate"><span class="pre">Py_TRASHCAN_BEGIN</span></code> has a second argument which
  2331. should be the deallocation function it is in.</p>
  2332. <p>To support older Python versions in the same codebase, you
  2333. can define the following macros and use them throughout
  2334. the code (credit: these were copied from the <code class="docutils literal notranslate"><span class="pre">mypy</span></code> codebase):</p>
  2335. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX &gt;= 0x03080000</span>
  2336. <span class="c1"># define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_BEGIN(op, dealloc)</span>
  2337. <span class="c1"># define CPy_TRASHCAN_END(op) Py_TRASHCAN_END</span>
  2338. <span class="c1">#else</span>
  2339. <span class="c1"># define CPy_TRASHCAN_BEGIN(op, dealloc) Py_TRASHCAN_SAFE_BEGIN(op)</span>
  2340. <span class="c1"># define CPy_TRASHCAN_END(op) Py_TRASHCAN_SAFE_END(op)</span>
  2341. <span class="c1">#endif</span>
  2342. </pre></div>
  2343. </div>
  2344. </li>
  2345. <li><p>The <a class="reference internal" href="../c-api/type.html#c.PyType_Ready" title="PyType_Ready"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_Ready()</span></code></a> function now raises an error if a type is defined
  2346. with the <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_HAVE_GC" title="Py_TPFLAGS_HAVE_GC"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_HAVE_GC</span></code></a> flag set but has no traverse function
  2347. (<a class="reference internal" href="../c-api/typeobj.html#c.PyTypeObject.tp_traverse" title="PyTypeObject.tp_traverse"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyTypeObject.tp_traverse</span></code></a>).
  2348. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44263">bpo-44263</a>.)</p></li>
  2349. <li><p>Heap types with the <a class="reference internal" href="../c-api/typeobj.html#c.Py_TPFLAGS_IMMUTABLETYPE" title="Py_TPFLAGS_IMMUTABLETYPE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_TPFLAGS_IMMUTABLETYPE</span></code></a> flag can now inherit
  2350. the <span class="target" id="index-37"></span><a class="pep reference external" href="https://peps.python.org/pep-0590/"><strong>PEP 590</strong></a> vectorcall protocol. Previously, this was only possible for
  2351. <a class="reference internal" href="../c-api/typeobj.html#static-types"><span class="std std-ref">static types</span></a>.
  2352. (Contributed by Erlend E. Aasland in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43908">bpo-43908</a>)</p></li>
  2353. <li><p>Since <a class="reference internal" href="../c-api/structures.html#c.Py_TYPE" title="Py_TYPE"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_TYPE()</span></code></a> is changed to a inline static function,
  2354. <code class="docutils literal notranslate"><span class="pre">Py_TYPE(obj)</span> <span class="pre">=</span> <span class="pre">new_type</span></code> must be replaced with
  2355. <code class="docutils literal notranslate"><span class="pre">Py_SET_TYPE(obj,</span> <span class="pre">new_type)</span></code>: see the <a class="reference internal" href="../c-api/structures.html#c.Py_SET_TYPE" title="Py_SET_TYPE"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SET_TYPE()</span></code></a> function
  2356. (available since Python 3.9). For backward compatibility, this macro can be
  2357. used:</p>
  2358. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX &lt; 0x030900A4 &amp;&amp; !defined(Py_SET_TYPE)</span>
  2359. <span class="n">static</span> <span class="n">inline</span> <span class="n">void</span> <span class="n">_Py_SET_TYPE</span><span class="p">(</span><span class="n">PyObject</span> <span class="o">*</span><span class="n">ob</span><span class="p">,</span> <span class="n">PyTypeObject</span> <span class="o">*</span><span class="nb">type</span><span class="p">)</span>
  2360. <span class="p">{</span> <span class="n">ob</span><span class="o">-&gt;</span><span class="n">ob_type</span> <span class="o">=</span> <span class="nb">type</span><span class="p">;</span> <span class="p">}</span>
  2361. <span class="c1">#define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type)</span>
  2362. <span class="c1">#endif</span>
  2363. </pre></div>
  2364. </div>
  2365. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39573">bpo-39573</a>.)</p>
  2366. </li>
  2367. <li><p>Since <a class="reference internal" href="../c-api/structures.html#c.Py_SIZE" title="Py_SIZE"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SIZE()</span></code></a> is changed to a inline static function,
  2368. <code class="docutils literal notranslate"><span class="pre">Py_SIZE(obj)</span> <span class="pre">=</span> <span class="pre">new_size</span></code> must be replaced with
  2369. <code class="docutils literal notranslate"><span class="pre">Py_SET_SIZE(obj,</span> <span class="pre">new_size)</span></code>: see the <a class="reference internal" href="../c-api/structures.html#c.Py_SET_SIZE" title="Py_SET_SIZE"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SET_SIZE()</span></code></a> function
  2370. (available since Python 3.9). For backward compatibility, this macro can be
  2371. used:</p>
  2372. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX &lt; 0x030900A4 &amp;&amp; !defined(Py_SET_SIZE)</span>
  2373. <span class="n">static</span> <span class="n">inline</span> <span class="n">void</span> <span class="n">_Py_SET_SIZE</span><span class="p">(</span><span class="n">PyVarObject</span> <span class="o">*</span><span class="n">ob</span><span class="p">,</span> <span class="n">Py_ssize_t</span> <span class="n">size</span><span class="p">)</span>
  2374. <span class="p">{</span> <span class="n">ob</span><span class="o">-&gt;</span><span class="n">ob_size</span> <span class="o">=</span> <span class="n">size</span><span class="p">;</span> <span class="p">}</span>
  2375. <span class="c1">#define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size)</span>
  2376. <span class="c1">#endif</span>
  2377. </pre></div>
  2378. </div>
  2379. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=39573">bpo-39573</a>.)</p>
  2380. </li>
  2381. <li><p><code class="docutils literal notranslate"><span class="pre">&lt;Python.h&gt;</span></code> no longer includes the header files <code class="docutils literal notranslate"><span class="pre">&lt;stdlib.h&gt;</span></code>,
  2382. <code class="docutils literal notranslate"><span class="pre">&lt;stdio.h&gt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;errno.h&gt;</span></code> and <code class="docutils literal notranslate"><span class="pre">&lt;string.h&gt;</span></code> when the <code class="docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code>
  2383. macro is set to <code class="docutils literal notranslate"><span class="pre">0x030b0000</span></code> (Python 3.11) or higher. C extensions should
  2384. explicitly include the header files after <code class="docutils literal notranslate"><span class="pre">#include</span> <span class="pre">&lt;Python.h&gt;</span></code>.
  2385. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45434">bpo-45434</a>.)</p></li>
  2386. <li><p>The non-limited API files <code class="docutils literal notranslate"><span class="pre">cellobject.h</span></code>, <code class="docutils literal notranslate"><span class="pre">classobject.h</span></code>, <code class="docutils literal notranslate"><span class="pre">code.h</span></code>, <code class="docutils literal notranslate"><span class="pre">context.h</span></code>,
  2387. <code class="docutils literal notranslate"><span class="pre">funcobject.h</span></code>, <code class="docutils literal notranslate"><span class="pre">genobject.h</span></code> and <code class="docutils literal notranslate"><span class="pre">longintrepr.h</span></code> have been moved to
  2388. the <code class="docutils literal notranslate"><span class="pre">Include/cpython</span></code> directory. Moreover, the <code class="docutils literal notranslate"><span class="pre">eval.h</span></code> header file was
  2389. removed. These files must not be included directly, as they are already
  2390. included in <code class="docutils literal notranslate"><span class="pre">Python.h</span></code>: <a class="reference internal" href="../c-api/intro.html#api-includes"><span class="std std-ref">Include Files</span></a>. If they have
  2391. been included directly, consider including <code class="docutils literal notranslate"><span class="pre">Python.h</span></code> instead.
  2392. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35134">bpo-35134</a>.)</p></li>
  2393. <li><p>The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_CHECK_INTERNED()</span></code> macro has been excluded from the
  2394. limited C API. It was never usable there, because it used internal structures
  2395. which are not available in the limited C API.
  2396. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46007">bpo-46007</a>.)</p></li>
  2397. <li><p>The following frame functions and type are now directly available with
  2398. <code class="docutils literal notranslate"><span class="pre">#include</span> <span class="pre">&lt;Python.h&gt;</span></code>, it’s no longer needed to add
  2399. <code class="docutils literal notranslate"><span class="pre">#include</span> <span class="pre">&lt;frameobject.h&gt;</span></code>:</p>
  2400. <ul class="simple">
  2401. <li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_Check" title="PyFrame_Check"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_Check()</span></code></a></p></li>
  2402. <li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBack" title="PyFrame_GetBack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBack()</span></code></a></p></li>
  2403. <li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBuiltins" title="PyFrame_GetBuiltins"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBuiltins()</span></code></a></p></li>
  2404. <li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetGenerator" title="PyFrame_GetGenerator"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetGenerator()</span></code></a></p></li>
  2405. <li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetGlobals" title="PyFrame_GetGlobals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetGlobals()</span></code></a></p></li>
  2406. <li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLasti" title="PyFrame_GetLasti"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLasti()</span></code></a></p></li>
  2407. <li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLocals()</span></code></a></p></li>
  2408. <li><p><a class="reference internal" href="../c-api/frame.html#c.PyFrame_Type" title="PyFrame_Type"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyFrame_Type</span></code></a></p></li>
  2409. </ul>
  2410. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/93937">gh-93937</a>.)</p>
  2411. </li>
  2412. </ul>
  2413. <ul id="pyframeobject-3-11-hiding">
  2414. <li><p>The <a class="reference internal" href="../c-api/frame.html#c.PyFrameObject" title="PyFrameObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyFrameObject</span></code></a> structure members have been removed from the
  2415. public C API.</p>
  2416. <p>While the documentation notes that the <a class="reference internal" href="../c-api/frame.html#c.PyFrameObject" title="PyFrameObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyFrameObject</span></code></a> fields are
  2417. subject to change at any time, they have been stable for a long time and were
  2418. used in several popular extensions.</p>
  2419. <p>In Python 3.11, the frame struct was reorganized to allow performance
  2420. optimizations. Some fields were removed entirely, as they were details of the
  2421. old implementation.</p>
  2422. <p><a class="reference internal" href="../c-api/frame.html#c.PyFrameObject" title="PyFrameObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyFrameObject</span></code></a> fields:</p>
  2423. <ul class="simple">
  2424. <li><p><code class="docutils literal notranslate"><span class="pre">f_back</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBack" title="PyFrame_GetBack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBack()</span></code></a>.</p></li>
  2425. <li><p><code class="docutils literal notranslate"><span class="pre">f_blockstack</span></code>: removed.</p></li>
  2426. <li><p><code class="docutils literal notranslate"><span class="pre">f_builtins</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBuiltins" title="PyFrame_GetBuiltins"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBuiltins()</span></code></a>.</p></li>
  2427. <li><p><code class="docutils literal notranslate"><span class="pre">f_code</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetCode" title="PyFrame_GetCode"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetCode()</span></code></a>.</p></li>
  2428. <li><p><code class="docutils literal notranslate"><span class="pre">f_gen</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetGenerator" title="PyFrame_GetGenerator"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetGenerator()</span></code></a>.</p></li>
  2429. <li><p><code class="docutils literal notranslate"><span class="pre">f_globals</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetGlobals" title="PyFrame_GetGlobals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetGlobals()</span></code></a>.</p></li>
  2430. <li><p><code class="docutils literal notranslate"><span class="pre">f_iblock</span></code>: removed.</p></li>
  2431. <li><p><code class="docutils literal notranslate"><span class="pre">f_lasti</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLasti" title="PyFrame_GetLasti"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLasti()</span></code></a>.
  2432. Code using <code class="docutils literal notranslate"><span class="pre">f_lasti</span></code> with <code class="docutils literal notranslate"><span class="pre">PyCode_Addr2Line()</span></code> should use
  2433. <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLineNumber" title="PyFrame_GetLineNumber"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLineNumber()</span></code></a> instead; it may be faster.</p></li>
  2434. <li><p><code class="docutils literal notranslate"><span class="pre">f_lineno</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLineNumber" title="PyFrame_GetLineNumber"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLineNumber()</span></code></a></p></li>
  2435. <li><p><code class="docutils literal notranslate"><span class="pre">f_locals</span></code>: use <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLocals()</span></code></a>.</p></li>
  2436. <li><p><code class="docutils literal notranslate"><span class="pre">f_stackdepth</span></code>: removed.</p></li>
  2437. <li><p><code class="docutils literal notranslate"><span class="pre">f_state</span></code>: no public API (renamed to <code class="docutils literal notranslate"><span class="pre">f_frame.f_state</span></code>).</p></li>
  2438. <li><p><code class="docutils literal notranslate"><span class="pre">f_trace</span></code>: no public API.</p></li>
  2439. <li><p><code class="docutils literal notranslate"><span class="pre">f_trace_lines</span></code>: use <code class="docutils literal notranslate"><span class="pre">PyObject_GetAttrString((PyObject*)frame,</span> <span class="pre">&quot;f_trace_lines&quot;)</span></code>.</p></li>
  2440. <li><p><code class="docutils literal notranslate"><span class="pre">f_trace_opcodes</span></code>: use <code class="docutils literal notranslate"><span class="pre">PyObject_GetAttrString((PyObject*)frame,</span> <span class="pre">&quot;f_trace_opcodes&quot;)</span></code>.</p></li>
  2441. <li><p><code class="docutils literal notranslate"><span class="pre">f_localsplus</span></code>: no public API (renamed to <code class="docutils literal notranslate"><span class="pre">f_frame.localsplus</span></code>).</p></li>
  2442. <li><p><code class="docutils literal notranslate"><span class="pre">f_valuestack</span></code>: removed.</p></li>
  2443. </ul>
  2444. <p>The Python frame object is now created lazily. A side effect is that the
  2445. <a class="reference internal" href="../reference/datamodel.html#frame.f_back" title="frame.f_back"><code class="xref py py-attr docutils literal notranslate"><span class="pre">f_back</span></code></a> member must not be accessed directly,
  2446. since its value is now also
  2447. computed lazily. The <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetBack" title="PyFrame_GetBack"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetBack()</span></code></a> function must be called
  2448. instead.</p>
  2449. <p>Debuggers that accessed the <a class="reference internal" href="../reference/datamodel.html#frame.f_locals" title="frame.f_locals"><code class="xref py py-attr docutils literal notranslate"><span class="pre">f_locals</span></code></a> directly <em>must</em> call
  2450. <a class="reference internal" href="../c-api/frame.html#c.PyFrame_GetLocals" title="PyFrame_GetLocals"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_GetLocals()</span></code></a> instead. They no longer need to call
  2451. <code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_FastToLocalsWithError()</span></code> or <code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_LocalsToFast()</span></code>,
  2452. in fact they should not call those functions. The necessary updating of the
  2453. frame is now managed by the virtual machine.</p>
  2454. <p>Code defining <code class="docutils literal notranslate"><span class="pre">PyFrame_GetCode()</span></code> on Python 3.8 and older:</p>
  2455. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX &lt; 0x030900B1</span>
  2456. <span class="n">static</span> <span class="n">inline</span> <span class="n">PyCodeObject</span><span class="o">*</span> <span class="n">PyFrame_GetCode</span><span class="p">(</span><span class="n">PyFrameObject</span> <span class="o">*</span><span class="n">frame</span><span class="p">)</span>
  2457. <span class="p">{</span>
  2458. <span class="n">Py_INCREF</span><span class="p">(</span><span class="n">frame</span><span class="o">-&gt;</span><span class="n">f_code</span><span class="p">);</span>
  2459. <span class="k">return</span> <span class="n">frame</span><span class="o">-&gt;</span><span class="n">f_code</span><span class="p">;</span>
  2460. <span class="p">}</span>
  2461. <span class="c1">#endif</span>
  2462. </pre></div>
  2463. </div>
  2464. <p>Code defining <code class="docutils literal notranslate"><span class="pre">PyFrame_GetBack()</span></code> on Python 3.8 and older:</p>
  2465. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX &lt; 0x030900B1</span>
  2466. <span class="n">static</span> <span class="n">inline</span> <span class="n">PyFrameObject</span><span class="o">*</span> <span class="n">PyFrame_GetBack</span><span class="p">(</span><span class="n">PyFrameObject</span> <span class="o">*</span><span class="n">frame</span><span class="p">)</span>
  2467. <span class="p">{</span>
  2468. <span class="n">Py_XINCREF</span><span class="p">(</span><span class="n">frame</span><span class="o">-&gt;</span><span class="n">f_back</span><span class="p">);</span>
  2469. <span class="k">return</span> <span class="n">frame</span><span class="o">-&gt;</span><span class="n">f_back</span><span class="p">;</span>
  2470. <span class="p">}</span>
  2471. <span class="c1">#endif</span>
  2472. </pre></div>
  2473. </div>
  2474. <p>Or use the <a class="reference external" href="https://github.com/python/pythoncapi-compat">pythoncapi_compat project</a> to get these two
  2475. functions on older Python versions.</p>
  2476. </li>
  2477. <li><p>Changes of the <a class="reference internal" href="../c-api/init.html#c.PyThreadState" title="PyThreadState"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyThreadState</span></code></a> structure members:</p>
  2478. <ul class="simple">
  2479. <li><p><code class="docutils literal notranslate"><span class="pre">frame</span></code>: removed, use <a class="reference internal" href="../c-api/init.html#c.PyThreadState_GetFrame" title="PyThreadState_GetFrame"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_GetFrame()</span></code></a> (function added
  2480. to Python 3.9 by <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40429">bpo-40429</a>).
  2481. Warning: the function returns a <a class="reference internal" href="../glossary.html#term-strong-reference"><span class="xref std std-term">strong reference</span></a>, need to call
  2482. <a class="reference internal" href="../c-api/refcounting.html#c.Py_XDECREF" title="Py_XDECREF"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_XDECREF()</span></code></a>.</p></li>
  2483. <li><p><code class="docutils literal notranslate"><span class="pre">tracing</span></code>: changed, use <a class="reference internal" href="../c-api/init.html#c.PyThreadState_EnterTracing" title="PyThreadState_EnterTracing"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_EnterTracing()</span></code></a>
  2484. and <a class="reference internal" href="../c-api/init.html#c.PyThreadState_LeaveTracing" title="PyThreadState_LeaveTracing"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThreadState_LeaveTracing()</span></code></a>
  2485. (functions added to Python 3.11 by <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=43760">bpo-43760</a>).</p></li>
  2486. <li><p><code class="docutils literal notranslate"><span class="pre">recursion_depth</span></code>: removed,
  2487. use <code class="docutils literal notranslate"><span class="pre">(tstate-&gt;recursion_limit</span> <span class="pre">-</span> <span class="pre">tstate-&gt;recursion_remaining)</span></code> instead.</p></li>
  2488. <li><p><code class="docutils literal notranslate"><span class="pre">stackcheck_counter</span></code>: removed.</p></li>
  2489. </ul>
  2490. <p>Code defining <code class="docutils literal notranslate"><span class="pre">PyThreadState_GetFrame()</span></code> on Python 3.8 and older:</p>
  2491. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX &lt; 0x030900B1</span>
  2492. <span class="n">static</span> <span class="n">inline</span> <span class="n">PyFrameObject</span><span class="o">*</span> <span class="n">PyThreadState_GetFrame</span><span class="p">(</span><span class="n">PyThreadState</span> <span class="o">*</span><span class="n">tstate</span><span class="p">)</span>
  2493. <span class="p">{</span>
  2494. <span class="n">Py_XINCREF</span><span class="p">(</span><span class="n">tstate</span><span class="o">-&gt;</span><span class="n">frame</span><span class="p">);</span>
  2495. <span class="k">return</span> <span class="n">tstate</span><span class="o">-&gt;</span><span class="n">frame</span><span class="p">;</span>
  2496. <span class="p">}</span>
  2497. <span class="c1">#endif</span>
  2498. </pre></div>
  2499. </div>
  2500. <p>Code defining <code class="docutils literal notranslate"><span class="pre">PyThreadState_EnterTracing()</span></code> and
  2501. <code class="docutils literal notranslate"><span class="pre">PyThreadState_LeaveTracing()</span></code> on Python 3.10 and older:</p>
  2502. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#if PY_VERSION_HEX &lt; 0x030B00A2</span>
  2503. <span class="n">static</span> <span class="n">inline</span> <span class="n">void</span> <span class="n">PyThreadState_EnterTracing</span><span class="p">(</span><span class="n">PyThreadState</span> <span class="o">*</span><span class="n">tstate</span><span class="p">)</span>
  2504. <span class="p">{</span>
  2505. <span class="n">tstate</span><span class="o">-&gt;</span><span class="n">tracing</span><span class="o">++</span><span class="p">;</span>
  2506. <span class="c1">#if PY_VERSION_HEX &gt;= 0x030A00A1</span>
  2507. <span class="n">tstate</span><span class="o">-&gt;</span><span class="n">cframe</span><span class="o">-&gt;</span><span class="n">use_tracing</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
  2508. <span class="c1">#else</span>
  2509. <span class="n">tstate</span><span class="o">-&gt;</span><span class="n">use_tracing</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
  2510. <span class="c1">#endif</span>
  2511. <span class="p">}</span>
  2512. <span class="n">static</span> <span class="n">inline</span> <span class="n">void</span> <span class="n">PyThreadState_LeaveTracing</span><span class="p">(</span><span class="n">PyThreadState</span> <span class="o">*</span><span class="n">tstate</span><span class="p">)</span>
  2513. <span class="p">{</span>
  2514. <span class="nb">int</span> <span class="n">use_tracing</span> <span class="o">=</span> <span class="p">(</span><span class="n">tstate</span><span class="o">-&gt;</span><span class="n">c_tracefunc</span> <span class="o">!=</span> <span class="n">NULL</span> <span class="o">||</span> <span class="n">tstate</span><span class="o">-&gt;</span><span class="n">c_profilefunc</span> <span class="o">!=</span> <span class="n">NULL</span><span class="p">);</span>
  2515. <span class="n">tstate</span><span class="o">-&gt;</span><span class="n">tracing</span><span class="o">--</span><span class="p">;</span>
  2516. <span class="c1">#if PY_VERSION_HEX &gt;= 0x030A00A1</span>
  2517. <span class="n">tstate</span><span class="o">-&gt;</span><span class="n">cframe</span><span class="o">-&gt;</span><span class="n">use_tracing</span> <span class="o">=</span> <span class="n">use_tracing</span><span class="p">;</span>
  2518. <span class="c1">#else</span>
  2519. <span class="n">tstate</span><span class="o">-&gt;</span><span class="n">use_tracing</span> <span class="o">=</span> <span class="n">use_tracing</span><span class="p">;</span>
  2520. <span class="c1">#endif</span>
  2521. <span class="p">}</span>
  2522. <span class="c1">#endif</span>
  2523. </pre></div>
  2524. </div>
  2525. <p>Or use <a class="reference external" href="https://github.com/python/pythoncapi-compat">the pythoncapi-compat project</a> to get these functions
  2526. on old Python functions.</p>
  2527. </li>
  2528. <li><p>Distributors are encouraged to build Python with the optimized Blake2
  2529. library <a class="reference external" href="https://www.blake2.net/">libb2</a>.</p></li>
  2530. <li><p>The <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths_set" title="PyConfig.module_search_paths_set"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths_set</span></code></a> field must now be set to 1 for
  2531. initialization to use <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths" title="PyConfig.module_search_paths"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths</span></code></a> to initialize
  2532. <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>. Otherwise, initialization will recalculate the path and replace
  2533. any values added to <code class="docutils literal notranslate"><span class="pre">module_search_paths</span></code>.</p></li>
  2534. <li><p><a class="reference internal" href="../c-api/init_config.html#c.PyConfig_Read" title="PyConfig_Read"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Read()</span></code></a> no longer calculates the initial search path, and will not
  2535. fill any values into <a class="reference internal" href="../c-api/init_config.html#c.PyConfig.module_search_paths" title="PyConfig.module_search_paths"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths</span></code></a>. To calculate default
  2536. paths and then modify them, finish initialization and use <a class="reference internal" href="../c-api/sys.html#c.PySys_GetObject" title="PySys_GetObject"><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_GetObject()</span></code></a>
  2537. to retrieve <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> as a Python list object and modify it directly.</p></li>
  2538. </ul>
  2539. </section>
  2540. <section id="whatsnew311-c-api-deprecated">
  2541. <span id="id7"></span><h3>Deprecated<a class="headerlink" href="#whatsnew311-c-api-deprecated" title="Link to this heading">¶</a></h3>
  2542. <ul>
  2543. <li><p>Deprecate the following functions to configure the Python initialization:</p>
  2544. <ul class="simple">
  2545. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddWarnOptionUnicode()</span></code></p></li>
  2546. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddWarnOption()</span></code></p></li>
  2547. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_AddXOption()</span></code></p></li>
  2548. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_HasWarnOptions()</span></code></p></li>
  2549. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_SetArgvEx()</span></code></p></li>
  2550. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_SetArgv()</span></code></p></li>
  2551. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PySys_SetPath()</span></code></p></li>
  2552. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetPath()</span></code></p></li>
  2553. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetProgramName()</span></code></p></li>
  2554. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetPythonHome()</span></code></p></li>
  2555. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetStandardStreamEncoding()</span></code></p></li>
  2556. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">_Py_SetProgramFullPath()</span></code></p></li>
  2557. </ul>
  2558. <p>Use the new <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> API of the <a class="reference internal" href="../c-api/init_config.html#init-config"><span class="std std-ref">Python Initialization Configuration</span></a> instead (<span class="target" id="index-38"></span><a class="pep reference external" href="https://peps.python.org/pep-0587/"><strong>PEP 587</strong></a>).
  2559. (Contributed by Victor Stinner in <a class="reference external" href="https://github.com/python/cpython/issues/88279">gh-88279</a>.)</p>
  2560. </li>
  2561. <li><p>Deprecate the <code class="docutils literal notranslate"><span class="pre">ob_shash</span></code> member of the <a class="reference internal" href="../c-api/bytes.html#c.PyBytesObject" title="PyBytesObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyBytesObject</span></code></a>. Use <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.
  2562. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=46864">bpo-46864</a>.)</p></li>
  2563. </ul>
  2564. </section>
  2565. <section id="whatsnew311-c-api-pending-removal">
  2566. <span id="id8"></span><h3>Pending Removal in Python 3.12<a class="headerlink" href="#whatsnew311-c-api-pending-removal" title="Link to this heading">¶</a></h3>
  2567. <p>The following C APIs have been deprecated in earlier Python releases,
  2568. and will be removed in Python 3.12.</p>
  2569. <ul class="simple">
  2570. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AS_DATA()</span></code></p></li>
  2571. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AS_UNICODE()</span></code></p></li>
  2572. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicodeAndSize()</span></code></p></li>
  2573. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicode()</span></code></p></li>
  2574. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromUnicode()</span></code></p></li>
  2575. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GET_DATA_SIZE()</span></code></p></li>
  2576. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GET_SIZE()</span></code></p></li>
  2577. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetSize()</span></code></p></li>
  2578. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_IS_COMPACT()</span></code></p></li>
  2579. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_IS_READY()</span></code></p></li>
  2580. <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></p></li>
  2581. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_WSTR_LENGTH()</span></code></p></li>
  2582. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">_PyUnicode_AsUnicode()</span></code></p></li>
  2583. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_WCHAR_KIND</span></code></p></li>
  2584. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicodeObject" title="PyUnicodeObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyUnicodeObject</span></code></a></p></li>
  2585. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_InternImmortal()</span></code></p></li>
  2586. </ul>
  2587. </section>
  2588. <section id="whatsnew311-c-api-removed">
  2589. <span id="id9"></span><h3>Removed<a class="headerlink" href="#whatsnew311-c-api-removed" title="Link to this heading">¶</a></h3>
  2590. <ul>
  2591. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_BlockSetup()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyFrame_BlockPop()</span></code> have been
  2592. removed.
  2593. (Contributed by Mark Shannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40222">bpo-40222</a>.)</p></li>
  2594. <li><p>Remove the following math macros using the <code class="docutils literal notranslate"><span class="pre">errno</span></code> variable:</p>
  2595. <ul class="simple">
  2596. <li><p><code class="docutils literal notranslate"><span class="pre">Py_ADJUST_ERANGE1()</span></code></p></li>
  2597. <li><p><code class="docutils literal notranslate"><span class="pre">Py_ADJUST_ERANGE2()</span></code></p></li>
  2598. <li><p><code class="docutils literal notranslate"><span class="pre">Py_OVERFLOWED()</span></code></p></li>
  2599. <li><p><code class="docutils literal notranslate"><span class="pre">Py_SET_ERANGE_IF_OVERFLOW()</span></code></p></li>
  2600. <li><p><code class="docutils literal notranslate"><span class="pre">Py_SET_ERRNO_ON_MATH_ERROR()</span></code></p></li>
  2601. </ul>
  2602. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45412">bpo-45412</a>.)</p>
  2603. </li>
  2604. <li><p>Remove <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_COPY()</span></code> and <code class="docutils literal notranslate"><span class="pre">Py_UNICODE_FILL()</span></code> macros, deprecated
  2605. since Python 3.3. Use <code class="docutils literal notranslate"><span class="pre">PyUnicode_CopyCharacters()</span></code> or <code class="docutils literal notranslate"><span class="pre">memcpy()</span></code>
  2606. (<code class="docutils literal notranslate"><span class="pre">wchar_t*</span></code> string), and <code class="docutils literal notranslate"><span class="pre">PyUnicode_Fill()</span></code> functions instead.
  2607. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=41123">bpo-41123</a>.)</p></li>
  2608. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">pystrhex.h</span></code> header file. It only contains private functions.
  2609. C extensions should only include the main <code class="docutils literal notranslate"><span class="pre">&lt;Python.h&gt;</span></code> header file.
  2610. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45434">bpo-45434</a>.)</p></li>
  2611. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">Py_FORCE_DOUBLE()</span></code> macro. It was used by the
  2612. <code class="docutils literal notranslate"><span class="pre">Py_IS_INFINITY()</span></code> macro.
  2613. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45440">bpo-45440</a>.)</p></li>
  2614. <li><p>The following items are no longer available when <a class="reference internal" href="../c-api/stable.html#c.Py_LIMITED_API" title="Py_LIMITED_API"><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_LIMITED_API</span></code></a>
  2615. is defined:</p>
  2616. <ul class="simple">
  2617. <li><p><a class="reference internal" href="../c-api/marshal.html#c.PyMarshal_WriteLongToFile" title="PyMarshal_WriteLongToFile"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMarshal_WriteLongToFile()</span></code></a></p></li>
  2618. <li><p><a class="reference internal" href="../c-api/marshal.html#c.PyMarshal_WriteObjectToFile" title="PyMarshal_WriteObjectToFile"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMarshal_WriteObjectToFile()</span></code></a></p></li>
  2619. <li><p><a class="reference internal" href="../c-api/marshal.html#c.PyMarshal_ReadObjectFromString" title="PyMarshal_ReadObjectFromString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMarshal_ReadObjectFromString()</span></code></a></p></li>
  2620. <li><p><a class="reference internal" href="../c-api/marshal.html#c.PyMarshal_WriteObjectToString" title="PyMarshal_WriteObjectToString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMarshal_WriteObjectToString()</span></code></a></p></li>
  2621. <li><p>the <code class="docutils literal notranslate"><span class="pre">Py_MARSHAL_VERSION</span></code> macro</p></li>
  2622. </ul>
  2623. <p>These are not part of the <a class="reference internal" href="../c-api/stable.html#limited-api-list"><span class="std std-ref">limited API</span></a>.</p>
  2624. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45474">bpo-45474</a>.)</p>
  2625. </li>
  2626. <li><p>Exclude <a class="reference internal" href="../c-api/weakref.html#c.PyWeakref_GET_OBJECT" title="PyWeakref_GET_OBJECT"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyWeakref_GET_OBJECT()</span></code></a> from the limited C API. It never
  2627. worked since the <code class="xref c c-type docutils literal notranslate"><span class="pre">PyWeakReference</span></code> structure is opaque in the
  2628. limited C API.
  2629. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=35134">bpo-35134</a>.)</p></li>
  2630. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">PyHeapType_GET_MEMBERS()</span></code> macro. It was exposed in the
  2631. public C API by mistake, it must only be used by Python internally.
  2632. Use the <code class="docutils literal notranslate"><span class="pre">PyTypeObject.tp_members</span></code> member instead.
  2633. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=40170">bpo-40170</a>.)</p></li>
  2634. <li><p>Remove the <code class="docutils literal notranslate"><span class="pre">HAVE_PY_SET_53BIT_PRECISION</span></code> macro (moved to the internal C
  2635. API).
  2636. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=45412">bpo-45412</a>.)</p></li>
  2637. </ul>
  2638. <ul id="whatsnew311-pep624">
  2639. <li><p>Remove the <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> encoder APIs,
  2640. as they have been deprecated since Python 3.3,
  2641. are little used
  2642. and are inefficient relative to the recommended alternatives.</p>
  2643. <p>The removed functions are:</p>
  2644. <ul class="simple">
  2645. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_Encode()</span></code></p></li>
  2646. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeASCII()</span></code></p></li>
  2647. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeLatin1()</span></code></p></li>
  2648. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF7()</span></code></p></li>
  2649. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF8()</span></code></p></li>
  2650. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF16()</span></code></p></li>
  2651. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF32()</span></code></p></li>
  2652. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUnicodeEscape()</span></code></p></li>
  2653. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeRawUnicodeEscape()</span></code></p></li>
  2654. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeCharmap()</span></code></p></li>
  2655. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_TranslateCharmap()</span></code></p></li>
  2656. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeDecimal()</span></code></p></li>
  2657. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">PyUnicode_TransformDecimalToASCII()</span></code></p></li>
  2658. </ul>
  2659. <p>See <span class="target" id="index-39"></span><a class="pep reference external" href="https://peps.python.org/pep-0624/"><strong>PEP 624</strong></a> for details and
  2660. <span class="target" id="index-40"></span><a class="pep reference external" href="https://peps.python.org/pep-0624/#alternative-apis"><strong>migration guidance</strong></a>.
  2661. (Contributed by Inada Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=44029">bpo-44029</a>.)</p>
  2662. </li>
  2663. </ul>
  2664. </section>
  2665. </section>
  2666. <section id="notable-changes-in-3-11-4">
  2667. <h2>Notable changes in 3.11.4<a class="headerlink" href="#notable-changes-in-3-11-4" title="Link to this heading">¶</a></h2>
  2668. <section id="tarfile">
  2669. <h3>tarfile<a class="headerlink" href="#tarfile" title="Link to this heading">¶</a></h3>
  2670. <ul class="simple">
  2671. <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>,
  2672. have a new a <em>filter</em> argument that allows limiting tar features than may be
  2673. surprising or dangerous, such as creating files outside the destination
  2674. directory.
  2675. See <a class="reference internal" href="../library/tarfile.html#tarfile-extraction-filter"><span class="std std-ref">Extraction filters</span></a> for details.
  2676. In Python 3.12, use without the <em>filter</em> argument will show a
  2677. <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>.
  2678. In Python 3.14, the default will switch to <code class="docutils literal notranslate"><span class="pre">'data'</span></code>.
  2679. (Contributed by Petr Viktorin in <span class="target" id="index-41"></span><a class="pep reference external" href="https://peps.python.org/pep-0706/"><strong>PEP 706</strong></a>.)</p></li>
  2680. </ul>
  2681. </section>
  2682. </section>
  2683. <section id="notable-changes-in-3-11-5">
  2684. <h2>Notable changes in 3.11.5<a class="headerlink" href="#notable-changes-in-3-11-5" title="Link to this heading">¶</a></h2>
  2685. <section id="openssl">
  2686. <h3>OpenSSL<a class="headerlink" href="#openssl" title="Link to this heading">¶</a></h3>
  2687. <ul class="simple">
  2688. <li><p>Windows builds and macOS installers from python.org now use OpenSSL 3.0.</p></li>
  2689. </ul>
  2690. </section>
  2691. </section>
  2692. </section>
  2693. <div class="clearer"></div>
  2694. </div>
  2695. </div>
  2696. </div>
  2697. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  2698. <div class="sphinxsidebarwrapper">
  2699. <div>
  2700. <h3><a href="../contents.html">Table of Contents</a></h3>
  2701. <ul>
  2702. <li><a class="reference internal" href="#">What’s New In Python 3.11</a><ul>
  2703. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  2704. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  2705. <li><a class="reference internal" href="#pep-657-fine-grained-error-locations-in-tracebacks">PEP 657: Fine-grained error locations in tracebacks</a></li>
  2706. <li><a class="reference internal" href="#pep-654-exception-groups-and-except">PEP 654: Exception Groups and <code class="docutils literal notranslate"><span class="pre">except*</span></code></a></li>
  2707. <li><a class="reference internal" href="#pep-678-exceptions-can-be-enriched-with-notes">PEP 678: Exceptions can be enriched with notes</a></li>
  2708. <li><a class="reference internal" href="#windows-py-exe-launcher-improvements">Windows <code class="docutils literal notranslate"><span class="pre">py.exe</span></code> launcher improvements</a></li>
  2709. </ul>
  2710. </li>
  2711. <li><a class="reference internal" href="#new-features-related-to-type-hints">New Features Related to Type Hints</a><ul>
  2712. <li><a class="reference internal" href="#pep-646-variadic-generics">PEP 646: Variadic generics</a></li>
  2713. <li><a class="reference internal" href="#pep-655-marking-individual-typeddict-items-as-required-or-not-required">PEP 655: Marking individual <code class="docutils literal notranslate"><span class="pre">TypedDict</span></code> items as required or not-required</a></li>
  2714. <li><a class="reference internal" href="#pep-673-self-type">PEP 673: <code class="docutils literal notranslate"><span class="pre">Self</span></code> type</a></li>
  2715. <li><a class="reference internal" href="#pep-675-arbitrary-literal-string-type">PEP 675: Arbitrary literal string type</a></li>
  2716. <li><a class="reference internal" href="#pep-681-data-class-transforms">PEP 681: Data class transforms</a></li>
  2717. <li><a class="reference internal" href="#pep-563-may-not-be-the-future">PEP 563 may not be the future</a></li>
  2718. </ul>
  2719. </li>
  2720. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  2721. <li><a class="reference internal" href="#other-cpython-implementation-changes">Other CPython Implementation Changes</a></li>
  2722. <li><a class="reference internal" href="#new-modules">New Modules</a></li>
  2723. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  2724. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  2725. <li><a class="reference internal" href="#contextlib">contextlib</a></li>
  2726. <li><a class="reference internal" href="#dataclasses">dataclasses</a></li>
  2727. <li><a class="reference internal" href="#datetime">datetime</a></li>
  2728. <li><a class="reference internal" href="#enum">enum</a></li>
  2729. <li><a class="reference internal" href="#fcntl">fcntl</a></li>
  2730. <li><a class="reference internal" href="#fractions">fractions</a></li>
  2731. <li><a class="reference internal" href="#functools">functools</a></li>
  2732. <li><a class="reference internal" href="#hashlib">hashlib</a></li>
  2733. <li><a class="reference internal" href="#whatsnew311-idle">IDLE and idlelib</a></li>
  2734. <li><a class="reference internal" href="#inspect">inspect</a></li>
  2735. <li><a class="reference internal" href="#locale">locale</a></li>
  2736. <li><a class="reference internal" href="#logging">logging</a></li>
  2737. <li><a class="reference internal" href="#math">math</a></li>
  2738. <li><a class="reference internal" href="#operator">operator</a></li>
  2739. <li><a class="reference internal" href="#os">os</a></li>
  2740. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  2741. <li><a class="reference internal" href="#re">re</a></li>
  2742. <li><a class="reference internal" href="#shutil">shutil</a></li>
  2743. <li><a class="reference internal" href="#socket">socket</a></li>
  2744. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  2745. <li><a class="reference internal" href="#string">string</a></li>
  2746. <li><a class="reference internal" href="#sys">sys</a></li>
  2747. <li><a class="reference internal" href="#sysconfig">sysconfig</a></li>
  2748. <li><a class="reference internal" href="#tempfile">tempfile</a></li>
  2749. <li><a class="reference internal" href="#threading">threading</a></li>
  2750. <li><a class="reference internal" href="#time">time</a></li>
  2751. <li><a class="reference internal" href="#tkinter">tkinter</a></li>
  2752. <li><a class="reference internal" href="#traceback">traceback</a></li>
  2753. <li><a class="reference internal" href="#typing">typing</a></li>
  2754. <li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
  2755. <li><a class="reference internal" href="#unittest">unittest</a></li>
  2756. <li><a class="reference internal" href="#venv">venv</a></li>
  2757. <li><a class="reference internal" href="#warnings">warnings</a></li>
  2758. <li><a class="reference internal" href="#zipfile">zipfile</a></li>
  2759. </ul>
  2760. </li>
  2761. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  2762. <li><a class="reference internal" href="#faster-cpython">Faster CPython</a><ul>
  2763. <li><a class="reference internal" href="#faster-startup">Faster Startup</a><ul>
  2764. <li><a class="reference internal" href="#frozen-imports-static-code-objects">Frozen imports / Static code objects</a></li>
  2765. </ul>
  2766. </li>
  2767. <li><a class="reference internal" href="#faster-runtime">Faster Runtime</a><ul>
  2768. <li><a class="reference internal" href="#cheaper-lazy-python-frames">Cheaper, lazy Python frames</a></li>
  2769. <li><a class="reference internal" href="#inlined-python-function-calls">Inlined Python function calls</a></li>
  2770. <li><a class="reference internal" href="#pep-659-specializing-adaptive-interpreter">PEP 659: Specializing Adaptive Interpreter</a></li>
  2771. </ul>
  2772. </li>
  2773. <li><a class="reference internal" href="#misc">Misc</a></li>
  2774. <li><a class="reference internal" href="#faq">FAQ</a><ul>
  2775. <li><a class="reference internal" href="#how-should-i-write-my-code-to-utilize-these-speedups">How should I write my code to utilize these speedups?</a></li>
  2776. <li><a class="reference internal" href="#will-cpython-3-11-use-more-memory">Will CPython 3.11 use more memory?</a></li>
  2777. <li><a class="reference internal" href="#i-don-t-see-any-speedups-in-my-workload-why">I don’t see any speedups in my workload. Why?</a></li>
  2778. <li><a class="reference internal" href="#is-there-a-jit-compiler">Is there a JIT compiler?</a></li>
  2779. </ul>
  2780. </li>
  2781. <li><a class="reference internal" href="#about">About</a></li>
  2782. </ul>
  2783. </li>
  2784. <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a><ul>
  2785. <li><a class="reference internal" href="#new-opcodes">New opcodes</a></li>
  2786. <li><a class="reference internal" href="#replaced-opcodes">Replaced opcodes</a></li>
  2787. <li><a class="reference internal" href="#changed-removed-opcodes">Changed/removed opcodes</a></li>
  2788. </ul>
  2789. </li>
  2790. <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
  2791. <li><a class="reference internal" href="#language-builtins">Language/Builtins</a></li>
  2792. <li><a class="reference internal" href="#modules">Modules</a></li>
  2793. <li><a class="reference internal" href="#standard-library">Standard Library</a></li>
  2794. </ul>
  2795. </li>
  2796. <li><a class="reference internal" href="#pending-removal-in-python-3-12">Pending Removal in Python 3.12</a></li>
  2797. <li><a class="reference internal" href="#removed">Removed</a></li>
  2798. <li><a class="reference internal" href="#porting-to-python-3-11">Porting to Python 3.11</a></li>
  2799. <li><a class="reference internal" href="#build-changes">Build Changes</a></li>
  2800. <li><a class="reference internal" href="#c-api-changes">C API Changes</a><ul>
  2801. <li><a class="reference internal" href="#whatsnew311-c-api-new-features">New Features</a></li>
  2802. <li><a class="reference internal" href="#whatsnew311-c-api-porting">Porting to Python 3.11</a></li>
  2803. <li><a class="reference internal" href="#whatsnew311-c-api-deprecated">Deprecated</a></li>
  2804. <li><a class="reference internal" href="#whatsnew311-c-api-pending-removal">Pending Removal in Python 3.12</a></li>
  2805. <li><a class="reference internal" href="#whatsnew311-c-api-removed">Removed</a></li>
  2806. </ul>
  2807. </li>
  2808. <li><a class="reference internal" href="#notable-changes-in-3-11-4">Notable changes in 3.11.4</a><ul>
  2809. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  2810. </ul>
  2811. </li>
  2812. <li><a class="reference internal" href="#notable-changes-in-3-11-5">Notable changes in 3.11.5</a><ul>
  2813. <li><a class="reference internal" href="#openssl">OpenSSL</a></li>
  2814. </ul>
  2815. </li>
  2816. </ul>
  2817. </li>
  2818. </ul>
  2819. </div>
  2820. <div>
  2821. <h4>Previous topic</h4>
  2822. <p class="topless"><a href="3.12.html"
  2823. title="previous chapter">What’s New In Python 3.12</a></p>
  2824. </div>
  2825. <div>
  2826. <h4>Next topic</h4>
  2827. <p class="topless"><a href="3.10.html"
  2828. title="next chapter">What’s New In Python 3.10</a></p>
  2829. </div>
  2830. <div role="note" aria-label="source link">
  2831. <h3>This Page</h3>
  2832. <ul class="this-page-menu">
  2833. <li><a href="../bugs.html">Report a Bug</a></li>
  2834. <li>
  2835. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.11.rst"
  2836. rel="nofollow">Show Source
  2837. </a>
  2838. </li>
  2839. </ul>
  2840. </div>
  2841. </div>
  2842. <div id="sidebarbutton" title="Collapse sidebar">
  2843. <span>«</span>
  2844. </div>
  2845. </div>
  2846. <div class="clearer"></div>
  2847. </div>
  2848. <div class="related" role="navigation" aria-label="related navigation">
  2849. <h3>Navigation</h3>
  2850. <ul>
  2851. <li class="right" style="margin-right: 10px">
  2852. <a href="../genindex.html" title="General Index"
  2853. >index</a></li>
  2854. <li class="right" >
  2855. <a href="../py-modindex.html" title="Python Module Index"
  2856. >modules</a> |</li>
  2857. <li class="right" >
  2858. <a href="3.10.html" title="What’s New In Python 3.10"
  2859. >next</a> |</li>
  2860. <li class="right" >
  2861. <a href="3.12.html" title="What’s New In Python 3.12"
  2862. >previous</a> |</li>
  2863. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  2864. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  2865. <li class="switchers">
  2866. <div class="language_switcher_placeholder"></div>
  2867. <div class="version_switcher_placeholder"></div>
  2868. </li>
  2869. <li>
  2870. </li>
  2871. <li id="cpython-language-and-version">
  2872. <a href="../index.html">3.12.3 Documentation</a> &#187;
  2873. </li>
  2874. <li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> &#187;</li>
  2875. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.11</a></li>
  2876. <li class="right">
  2877. <div class="inline-search" role="search">
  2878. <form class="inline-search" action="../search.html" method="get">
  2879. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  2880. <input type="submit" value="Go" />
  2881. </form>
  2882. </div>
  2883. |
  2884. </li>
  2885. <li class="right">
  2886. <label class="theme-selector-label">
  2887. Theme
  2888. <select class="theme-selector" oninput="activateTheme(this.value)">
  2889. <option value="auto" selected>Auto</option>
  2890. <option value="light">Light</option>
  2891. <option value="dark">Dark</option>
  2892. </select>
  2893. </label> |</li>
  2894. </ul>
  2895. </div>
  2896. <div class="footer">
  2897. &copy;
  2898. <a href="../copyright.html">
  2899. Copyright
  2900. </a>
  2901. 2001-2024, Python Software Foundation.
  2902. <br />
  2903. This page is licensed under the Python Software Foundation License Version 2.
  2904. <br />
  2905. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  2906. <br />
  2907. See <a href="/license.html">History and License</a> for more information.<br />
  2908. <br />
  2909. The Python Software Foundation is a non-profit corporation.
  2910. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  2911. <br />
  2912. <br />
  2913. Last updated on Apr 09, 2024 (13:47 UTC).
  2914. <a href="/bugs.html">Found a bug</a>?
  2915. <br />
  2916. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  2917. </div>
  2918. </body>
  2919. </html>
上海开阖软件有限公司 沪ICP备12045867号-1