gooderp18绿色标准版
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

2591 lines
335KB

  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.4" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/whatsnew/3.4.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Author, R. David Murray < rdmurray@bitdance.com> (Editor),. This article explains the new features in Python 3.4, compared to 3.3. Python 3.4 was released on March 16, 2014. For full details, see t..." />
  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="Author, R. David Murray < rdmurray@bitdance.com> (Editor),. This article explains the new features in Python 3.4, compared to 3.3. Python 3.4 was released on March 16, 2014. For full details, see t..." />
  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.4 &#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.3" href="3.3.html" />
  33. <link rel="prev" title="What’s New In Python 3.5" href="3.5.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/whatsnew/3.4.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.4</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-453-explicit-bootstrapping-of-pip-in-python-installations">PEP 453: Explicit Bootstrapping of PIP in Python Installations</a><ul>
  89. <li><a class="reference internal" href="#bootstrapping-pip-by-default">Bootstrapping pip By Default</a></li>
  90. <li><a class="reference internal" href="#documentation-changes">Documentation Changes</a></li>
  91. </ul>
  92. </li>
  93. <li><a class="reference internal" href="#pep-446-newly-created-file-descriptors-are-non-inheritable">PEP 446: Newly Created File Descriptors Are Non-Inheritable</a></li>
  94. <li><a class="reference internal" href="#improvements-to-codec-handling">Improvements to Codec Handling</a></li>
  95. <li><a class="reference internal" href="#pep-451-a-modulespec-type-for-the-import-system">PEP 451: A ModuleSpec Type for the Import System</a></li>
  96. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  97. </ul>
  98. </li>
  99. <li><a class="reference internal" href="#new-modules">New Modules</a><ul>
  100. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  101. <li><a class="reference internal" href="#ensurepip">ensurepip</a></li>
  102. <li><a class="reference internal" href="#enum">enum</a></li>
  103. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  104. <li><a class="reference internal" href="#selectors">selectors</a></li>
  105. <li><a class="reference internal" href="#statistics">statistics</a></li>
  106. <li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
  107. </ul>
  108. </li>
  109. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  110. <li><a class="reference internal" href="#abc">abc</a></li>
  111. <li><a class="reference internal" href="#aifc">aifc</a></li>
  112. <li><a class="reference internal" href="#argparse">argparse</a></li>
  113. <li><a class="reference internal" href="#audioop">audioop</a></li>
  114. <li><a class="reference internal" href="#base64">base64</a></li>
  115. <li><a class="reference internal" href="#collections">collections</a></li>
  116. <li><a class="reference internal" href="#colorsys">colorsys</a></li>
  117. <li><a class="reference internal" href="#contextlib">contextlib</a></li>
  118. <li><a class="reference internal" href="#dbm">dbm</a></li>
  119. <li><a class="reference internal" href="#dis">dis</a></li>
  120. <li><a class="reference internal" href="#doctest">doctest</a></li>
  121. <li><a class="reference internal" href="#email">email</a></li>
  122. <li><a class="reference internal" href="#filecmp">filecmp</a></li>
  123. <li><a class="reference internal" href="#functools">functools</a></li>
  124. <li><a class="reference internal" href="#gc">gc</a></li>
  125. <li><a class="reference internal" href="#glob">glob</a></li>
  126. <li><a class="reference internal" href="#hashlib">hashlib</a></li>
  127. <li><a class="reference internal" href="#hmac">hmac</a></li>
  128. <li><a class="reference internal" href="#html">html</a></li>
  129. <li><a class="reference internal" href="#http">http</a></li>
  130. <li><a class="reference internal" href="#idlelib-and-idle">idlelib and IDLE</a></li>
  131. <li><a class="reference internal" href="#importlib">importlib</a></li>
  132. <li><a class="reference internal" href="#inspect">inspect</a></li>
  133. <li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
  134. <li><a class="reference internal" href="#logging">logging</a></li>
  135. <li><a class="reference internal" href="#marshal">marshal</a></li>
  136. <li><a class="reference internal" href="#mmap">mmap</a></li>
  137. <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
  138. <li><a class="reference internal" href="#operator">operator</a></li>
  139. <li><a class="reference internal" href="#os">os</a></li>
  140. <li><a class="reference internal" href="#pdb">pdb</a></li>
  141. <li><a class="reference internal" href="#pickle">pickle</a></li>
  142. <li><a class="reference internal" href="#plistlib">plistlib</a></li>
  143. <li><a class="reference internal" href="#poplib">poplib</a></li>
  144. <li><a class="reference internal" href="#pprint">pprint</a></li>
  145. <li><a class="reference internal" href="#pty">pty</a></li>
  146. <li><a class="reference internal" href="#pydoc">pydoc</a></li>
  147. <li><a class="reference internal" href="#re">re</a></li>
  148. <li><a class="reference internal" href="#resource">resource</a></li>
  149. <li><a class="reference internal" href="#select">select</a></li>
  150. <li><a class="reference internal" href="#shelve">shelve</a></li>
  151. <li><a class="reference internal" href="#shutil">shutil</a></li>
  152. <li><a class="reference internal" href="#smtpd">smtpd</a></li>
  153. <li><a class="reference internal" href="#smtplib">smtplib</a></li>
  154. <li><a class="reference internal" href="#socket">socket</a></li>
  155. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  156. <li><a class="reference internal" href="#ssl">ssl</a></li>
  157. <li><a class="reference internal" href="#stat">stat</a></li>
  158. <li><a class="reference internal" href="#struct">struct</a></li>
  159. <li><a class="reference internal" href="#subprocess">subprocess</a></li>
  160. <li><a class="reference internal" href="#sunau">sunau</a></li>
  161. <li><a class="reference internal" href="#sys">sys</a></li>
  162. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  163. <li><a class="reference internal" href="#textwrap">textwrap</a></li>
  164. <li><a class="reference internal" href="#threading">threading</a></li>
  165. <li><a class="reference internal" href="#traceback">traceback</a></li>
  166. <li><a class="reference internal" href="#types">types</a></li>
  167. <li><a class="reference internal" href="#urllib">urllib</a></li>
  168. <li><a class="reference internal" href="#unittest">unittest</a></li>
  169. <li><a class="reference internal" href="#venv">venv</a></li>
  170. <li><a class="reference internal" href="#wave">wave</a></li>
  171. <li><a class="reference internal" href="#weakref">weakref</a></li>
  172. <li><a class="reference internal" href="#xml-etree">xml.etree</a></li>
  173. <li><a class="reference internal" href="#zipfile">zipfile</a></li>
  174. </ul>
  175. </li>
  176. <li><a class="reference internal" href="#cpython-implementation-changes">CPython Implementation Changes</a><ul>
  177. <li><a class="reference internal" href="#pep-445-customization-of-cpython-memory-allocators">PEP 445: Customization of CPython Memory Allocators</a></li>
  178. <li><a class="reference internal" href="#pep-442-safe-object-finalization">PEP 442: Safe Object Finalization</a></li>
  179. <li><a class="reference internal" href="#pep-456-secure-and-interchangeable-hash-algorithm">PEP 456: Secure and Interchangeable Hash Algorithm</a></li>
  180. <li><a class="reference internal" href="#pep-436-argument-clinic">PEP 436: Argument Clinic</a></li>
  181. <li><a class="reference internal" href="#other-build-and-c-api-changes">Other Build and C API Changes</a></li>
  182. <li><a class="reference internal" href="#other-improvements">Other Improvements</a></li>
  183. <li><a class="reference internal" href="#significant-optimizations">Significant Optimizations</a></li>
  184. </ul>
  185. </li>
  186. <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
  187. <li><a class="reference internal" href="#deprecations-in-the-python-api">Deprecations in the Python API</a></li>
  188. <li><a class="reference internal" href="#deprecated-features">Deprecated Features</a></li>
  189. </ul>
  190. </li>
  191. <li><a class="reference internal" href="#removed">Removed</a><ul>
  192. <li><a class="reference internal" href="#operating-systems-no-longer-supported">Operating Systems No Longer Supported</a></li>
  193. <li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
  194. <li><a class="reference internal" href="#code-cleanups">Code Cleanups</a></li>
  195. </ul>
  196. </li>
  197. <li><a class="reference internal" href="#porting-to-python-3-4">Porting to Python 3.4</a><ul>
  198. <li><a class="reference internal" href="#changes-in-python-command-behavior">Changes in ‘python’ Command Behavior</a></li>
  199. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  200. <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
  201. </ul>
  202. </li>
  203. <li><a class="reference internal" href="#changed-in-3-4-3">Changed in 3.4.3</a><ul>
  204. <li><a class="reference internal" href="#pep-476-enabling-certificate-verification-by-default-for-stdlib-http-clients">PEP 476: Enabling certificate verification by default for stdlib http clients</a></li>
  205. </ul>
  206. </li>
  207. </ul>
  208. </li>
  209. </ul>
  210. </div>
  211. <div>
  212. <h4>Previous topic</h4>
  213. <p class="topless"><a href="3.5.html"
  214. title="previous chapter">What’s New In Python 3.5</a></p>
  215. </div>
  216. <div>
  217. <h4>Next topic</h4>
  218. <p class="topless"><a href="3.3.html"
  219. title="next chapter">What’s New In Python 3.3</a></p>
  220. </div>
  221. <div role="note" aria-label="source link">
  222. <h3>This Page</h3>
  223. <ul class="this-page-menu">
  224. <li><a href="../bugs.html">Report a Bug</a></li>
  225. <li>
  226. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.4.rst"
  227. rel="nofollow">Show Source
  228. </a>
  229. </li>
  230. </ul>
  231. </div>
  232. </nav>
  233. </div>
  234. </div>
  235. <div class="related" role="navigation" aria-label="related navigation">
  236. <h3>Navigation</h3>
  237. <ul>
  238. <li class="right" style="margin-right: 10px">
  239. <a href="../genindex.html" title="General Index"
  240. accesskey="I">index</a></li>
  241. <li class="right" >
  242. <a href="../py-modindex.html" title="Python Module Index"
  243. >modules</a> |</li>
  244. <li class="right" >
  245. <a href="3.3.html" title="What’s New In Python 3.3"
  246. accesskey="N">next</a> |</li>
  247. <li class="right" >
  248. <a href="3.5.html" title="What’s New In Python 3.5"
  249. accesskey="P">previous</a> |</li>
  250. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  251. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  252. <li class="switchers">
  253. <div class="language_switcher_placeholder"></div>
  254. <div class="version_switcher_placeholder"></div>
  255. </li>
  256. <li>
  257. </li>
  258. <li id="cpython-language-and-version">
  259. <a href="../index.html">3.12.3 Documentation</a> &#187;
  260. </li>
  261. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> &#187;</li>
  262. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.4</a></li>
  263. <li class="right">
  264. <div class="inline-search" role="search">
  265. <form class="inline-search" action="../search.html" method="get">
  266. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  267. <input type="submit" value="Go" />
  268. </form>
  269. </div>
  270. |
  271. </li>
  272. <li class="right">
  273. <label class="theme-selector-label">
  274. Theme
  275. <select class="theme-selector" oninput="activateTheme(this.value)">
  276. <option value="auto" selected>Auto</option>
  277. <option value="light">Light</option>
  278. <option value="dark">Dark</option>
  279. </select>
  280. </label> |</li>
  281. </ul>
  282. </div>
  283. <div class="document">
  284. <div class="documentwrapper">
  285. <div class="bodywrapper">
  286. <div class="body" role="main">
  287. <section id="what-s-new-in-python-3-4">
  288. <h1>What’s New In Python 3.4<a class="headerlink" href="#what-s-new-in-python-3-4" title="Link to this heading">¶</a></h1>
  289. <dl class="field-list simple">
  290. <dt class="field-odd">Author<span class="colon">:</span></dt>
  291. <dd class="field-odd"><p>R. David Murray &lt;<a class="reference external" href="mailto:rdmurray&#37;&#52;&#48;bitdance&#46;com">rdmurray<span>&#64;</span>bitdance<span>&#46;</span>com</a>&gt; (Editor)</p>
  292. </dd>
  293. </dl>
  294. <p>This article explains the new features in Python 3.4, compared to 3.3.
  295. Python 3.4 was released on March 16, 2014. For full details, see the
  296. <a class="reference external" href="https://docs.python.org/3.4/whatsnew/changelog.html">changelog</a>.</p>
  297. <div class="admonition seealso">
  298. <p class="admonition-title">See also</p>
  299. <p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0429/"><strong>PEP 429</strong></a> – Python 3.4 Release Schedule</p>
  300. </div>
  301. <section id="summary-release-highlights">
  302. <h2>Summary – Release Highlights<a class="headerlink" href="#summary-release-highlights" title="Link to this heading">¶</a></h2>
  303. <p>New syntax features:</p>
  304. <ul class="simple">
  305. <li><p>No new syntax features were added in Python 3.4.</p></li>
  306. </ul>
  307. <p>Other new features:</p>
  308. <ul class="simple">
  309. <li><p><a class="reference internal" href="#whatsnew-pep-453"><span class="std std-ref">pip should always be available</span></a> (<span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0453/"><strong>PEP 453</strong></a>).</p></li>
  310. <li><p><a class="reference internal" href="#whatsnew-pep-446"><span class="std std-ref">Newly created file descriptors are non-inheritable</span></a>
  311. (<span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0446/"><strong>PEP 446</strong></a>).</p></li>
  312. <li><p>command line option for <a class="reference internal" href="#whatsnew-isolated-mode"><span class="std std-ref">isolated mode</span></a>
  313. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16499">bpo-16499</a>).</p></li>
  314. <li><p><a class="reference internal" href="#codec-handling-improvements"><span class="std std-ref">improvements in the handling of codecs</span></a>
  315. that are not text encodings (multiple issues).</p></li>
  316. <li><p><a class="reference internal" href="#whatsnew-pep-451"><span class="std std-ref">A ModuleSpec Type</span></a> for the Import System
  317. (<span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0451/"><strong>PEP 451</strong></a>). (Affects importer authors.)</p></li>
  318. <li><p>The <a class="reference internal" href="../library/marshal.html#module-marshal" title="marshal: Convert Python objects to streams of bytes and back (with different constraints)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">marshal</span></code></a> format has been made <a class="reference internal" href="#whatsnew-marshal-3"><span class="std std-ref">more compact and efficient</span></a> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16475">bpo-16475</a>).</p></li>
  319. </ul>
  320. <p>New library modules:</p>
  321. <ul class="simple">
  322. <li><p><a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a>: <a class="reference internal" href="#whatsnew-asyncio"><span class="std std-ref">New provisional API for asynchronous IO</span></a> (<span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-3156/"><strong>PEP 3156</strong></a>).</p></li>
  323. <li><p><a class="reference internal" href="../library/ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the &quot;pip&quot; installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a>: <a class="reference internal" href="#whatsnew-ensurepip"><span class="std std-ref">Bootstrapping the pip installer</span></a>
  324. (<span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0453/"><strong>PEP 453</strong></a>).</p></li>
  325. <li><p><a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a>: <a class="reference internal" href="#whatsnew-enum"><span class="std std-ref">Support for enumeration types</span></a>
  326. (<span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0435/"><strong>PEP 435</strong></a>).</p></li>
  327. <li><p><a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a>: <a class="reference internal" href="#whatsnew-pathlib"><span class="std std-ref">Object-oriented filesystem paths</span></a>
  328. (<span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0428/"><strong>PEP 428</strong></a>).</p></li>
  329. <li><p><a class="reference internal" href="../library/selectors.html#module-selectors" title="selectors: High-level I/O multiplexing."><code class="xref py py-mod docutils literal notranslate"><span class="pre">selectors</span></code></a>: <a class="reference internal" href="#whatsnew-selectors"><span class="std std-ref">High-level and efficient I/O multiplexing</span></a>, built upon the <a class="reference internal" href="../library/select.html#module-select" title="select: Wait for I/O completion on multiple streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code></a> module primitives (part
  330. of <span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-3156/"><strong>PEP 3156</strong></a>).</p></li>
  331. <li><p><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>: A basic <a class="reference internal" href="#whatsnew-statistics"><span class="std std-ref">numerically stable statistics library</span></a> (<span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0450/"><strong>PEP 450</strong></a>).</p></li>
  332. <li><p><a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a>: <a class="reference internal" href="#whatsnew-tracemalloc"><span class="std std-ref">Trace Python memory allocations</span></a> (<span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0454/"><strong>PEP 454</strong></a>).</p></li>
  333. </ul>
  334. <p>Significantly improved library modules:</p>
  335. <ul class="simple">
  336. <li><p><a class="reference internal" href="#whatsnew-singledispatch"><span class="std std-ref">Single-dispatch generic functions</span></a> in
  337. <a class="reference internal" href="../library/functools.html#module-functools" title="functools: Higher-order functions and operations on callable objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">functools</span></code></a> (<span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0443/"><strong>PEP 443</strong></a>).</p></li>
  338. <li><p>New <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> <a class="reference internal" href="#whatsnew-protocol-4"><span class="std std-ref">protocol 4</span></a> (<span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-3154/"><strong>PEP 3154</strong></a>).</p></li>
  339. <li><p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> now has <a class="reference internal" href="#whatsnew-multiprocessing-no-fork"><span class="std std-ref">an option to avoid using os.fork
  340. on Unix</span></a> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8713">bpo-8713</a>).</p></li>
  341. <li><p><a class="reference internal" href="../library/email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a> has a new submodule, <a class="reference internal" href="../library/email.contentmanager.html#module-email.contentmanager" title="email.contentmanager: Storing and Retrieving Content from MIME Parts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">contentmanager</span></code></a>, and
  342. a new <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-mod docutils literal notranslate"><span class="pre">Message</span></code></a> subclass
  343. (<code class="xref py py-class docutils literal notranslate"><span class="pre">EmailMessage</span></code>) that <a class="reference internal" href="#whatsnew-email-contentmanager"><span class="std std-ref">simplify MIME
  344. handling</span></a> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18891">bpo-18891</a>).</p></li>
  345. <li><p>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> and <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> modules are now capable of
  346. correct introspection of a much wider variety of callable objects,
  347. which improves the output of the Python <a class="reference internal" href="../library/functions.html#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a> system.</p></li>
  348. <li><p>The <a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ipaddress</span></code></a> module API has been declared stable</p></li>
  349. </ul>
  350. <p>Security improvements:</p>
  351. <ul class="simple">
  352. <li><p><a class="reference internal" href="#whatsnew-pep-456"><span class="std std-ref">Secure and interchangeable hash algorithm</span></a>
  353. (<span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0456/"><strong>PEP 456</strong></a>).</p></li>
  354. <li><p><a class="reference internal" href="#whatsnew-pep-446"><span class="std std-ref">Make newly created file descriptors non-inheritable</span></a>
  355. (<span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0446/"><strong>PEP 446</strong></a>) to avoid leaking file descriptors to child processes.</p></li>
  356. <li><p>New command line option for <a class="reference internal" href="#whatsnew-isolated-mode"><span class="std std-ref">isolated mode</span></a>,
  357. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16499">bpo-16499</a>).</p></li>
  358. <li><p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> now has <a class="reference internal" href="#whatsnew-multiprocessing-no-fork"><span class="std std-ref">an option to avoid using os.fork
  359. on Unix</span></a>. <em>spawn</em> and <em>forkserver</em> are
  360. more secure because they avoid sharing data with child processes.</p></li>
  361. <li><p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> child processes on Windows no longer inherit
  362. all of the parent’s inheritable handles, only the necessary ones.</p></li>
  363. <li><p>A new <a class="reference internal" href="../library/hashlib.html#hashlib.pbkdf2_hmac" title="hashlib.pbkdf2_hmac"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.pbkdf2_hmac()</span></code></a> function provides
  364. the <a class="reference external" href="https://en.wikipedia.org/wiki/PBKDF2">PKCS#5 password-based key derivation function 2</a>.</p></li>
  365. <li><p><a class="reference internal" href="#whatsnew-tls-11-12"><span class="std std-ref">TLSv1.1 and TLSv1.2 support</span></a> for <a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a>.</p></li>
  366. <li><p><a class="reference internal" href="#whatsnew34-win-cert-store"><span class="std std-ref">Retrieving certificates from the Windows system cert store support</span></a> for <a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a>.</p></li>
  367. <li><p><a class="reference internal" href="#whatsnew34-sni"><span class="std std-ref">Server-side SNI (Server Name Indication) support</span></a> for <a class="reference internal" href="../library/ssl.html#module-ssl" title="ssl: TLS/SSL wrapper for socket objects"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ssl</span></code></a>.</p></li>
  368. <li><p>The <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> class has a <a class="reference internal" href="#whatsnew34-sslcontext"><span class="std std-ref">lot of improvements</span></a>.</p></li>
  369. <li><p>All modules in the standard library that support SSL now support server
  370. certificate verification, including hostname matching
  371. (<code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.match_hostname()</span></code>) and CRLs (Certificate Revocation lists, see
  372. <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.load_verify_locations" title="ssl.SSLContext.load_verify_locations"><code class="xref py py-func docutils literal notranslate"><span class="pre">ssl.SSLContext.load_verify_locations()</span></code></a>).</p></li>
  373. </ul>
  374. <p>CPython implementation improvements:</p>
  375. <ul class="simple">
  376. <li><p><a class="reference internal" href="#whatsnew-pep-442"><span class="std std-ref">Safe object finalization</span></a> (<span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0442/"><strong>PEP 442</strong></a>).</p></li>
  377. <li><p>Leveraging <span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0442/"><strong>PEP 442</strong></a>, in most cases <a class="reference internal" href="#whatsnew-pep-442"><span class="std std-ref">module globals are no longer set
  378. to None during finalization</span></a> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18214">bpo-18214</a>).</p></li>
  379. <li><p><a class="reference internal" href="#whatsnew-pep-445"><span class="std std-ref">Configurable memory allocators</span></a> (<span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0445/"><strong>PEP 445</strong></a>).</p></li>
  380. <li><p><a class="reference internal" href="#whatsnew-pep-436"><span class="std std-ref">Argument Clinic</span></a> (<span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0436/"><strong>PEP 436</strong></a>).</p></li>
  381. </ul>
  382. <p>Please read on for a comprehensive list of user-facing changes, including many
  383. other smaller improvements, CPython optimizations, deprecations, and potential
  384. porting issues.</p>
  385. </section>
  386. <section id="new-features">
  387. <h2>New Features<a class="headerlink" href="#new-features" title="Link to this heading">¶</a></h2>
  388. <section id="pep-453-explicit-bootstrapping-of-pip-in-python-installations">
  389. <span id="whatsnew-pep-453"></span><h3>PEP 453: Explicit Bootstrapping of PIP in Python Installations<a class="headerlink" href="#pep-453-explicit-bootstrapping-of-pip-in-python-installations" title="Link to this heading">¶</a></h3>
  390. <section id="bootstrapping-pip-by-default">
  391. <h4>Bootstrapping pip By Default<a class="headerlink" href="#bootstrapping-pip-by-default" title="Link to this heading">¶</a></h4>
  392. <p>The new <a class="reference internal" href="../library/ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the &quot;pip&quot; installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a> module (defined in <span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0453/"><strong>PEP 453</strong></a>) provides a standard
  393. cross-platform mechanism to bootstrap the pip installer into Python
  394. installations and virtual environments. The version of <code class="docutils literal notranslate"><span class="pre">pip</span></code> included
  395. with Python 3.4.0 is <code class="docutils literal notranslate"><span class="pre">pip</span></code> 1.5.4, and future 3.4.x maintenance releases
  396. will update the bundled version to the latest version of <code class="docutils literal notranslate"><span class="pre">pip</span></code> that is
  397. available at the time of creating the release candidate.</p>
  398. <p>By default, the commands <code class="docutils literal notranslate"><span class="pre">pipX</span></code> and <code class="docutils literal notranslate"><span class="pre">pipX.Y</span></code> will be installed on all
  399. platforms (where X.Y stands for the version of the Python installation),
  400. along with the <code class="docutils literal notranslate"><span class="pre">pip</span></code> Python package and its dependencies. On Windows and
  401. in virtual environments on all platforms, the unversioned <code class="docutils literal notranslate"><span class="pre">pip</span></code> command
  402. will also be installed. On other platforms, the system wide unversioned
  403. <code class="docutils literal notranslate"><span class="pre">pip</span></code> command typically refers to the separately installed Python 2
  404. version.</p>
  405. <p>The <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> command line utility and the <a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a>
  406. module make use of the <a class="reference internal" href="../library/ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the &quot;pip&quot; installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a> module to make <code class="docutils literal notranslate"><span class="pre">pip</span></code> readily
  407. available in virtual environments. When using the command line utility,
  408. <code class="docutils literal notranslate"><span class="pre">pip</span></code> is installed by default, while when using the <a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a> module
  409. <a class="reference internal" href="../library/venv.html#venv-api"><span class="std std-ref">API</span></a> installation of <code class="docutils literal notranslate"><span class="pre">pip</span></code> must be requested explicitly.</p>
  410. <p>For CPython <a class="reference internal" href="../using/unix.html#building-python-on-unix"><span class="std std-ref">source builds on POSIX systems</span></a>,
  411. the <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">install</span></code> and <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">altinstall</span></code> commands bootstrap <code class="docutils literal notranslate"><span class="pre">pip</span></code> by
  412. default. This behaviour can be controlled through configure options, and
  413. overridden through Makefile options.</p>
  414. <p>On Windows and Mac OS X, the CPython installers now default to installing
  415. <code class="docutils literal notranslate"><span class="pre">pip</span></code> along with CPython itself (users may opt out of installing it
  416. during the installation process). Window users will need to opt in to the
  417. automatic <code class="docutils literal notranslate"><span class="pre">PATH</span></code> modifications to have <code class="docutils literal notranslate"><span class="pre">pip</span></code> available from the command
  418. line by default, otherwise it can still be accessed through the Python
  419. launcher for Windows as <code class="docutils literal notranslate"><span class="pre">py</span> <span class="pre">-m</span> <span class="pre">pip</span></code>.</p>
  420. <p>As <a class="reference external" href="https://peps.python.org/pep-0453/#recommendations-for-downstream-distributors">discussed in the PEP</a>, platform packagers may choose not to install
  421. these commands by default, as long as, when invoked, they provide clear and
  422. simple directions on how to install them on that platform (usually using
  423. the system package manager).</p>
  424. <div class="admonition note">
  425. <p class="admonition-title">Note</p>
  426. <p>To avoid conflicts between parallel Python 2 and Python 3 installations,
  427. only the versioned <code class="docutils literal notranslate"><span class="pre">pip3</span></code> and <code class="docutils literal notranslate"><span class="pre">pip3.4</span></code> commands are bootstrapped by
  428. default when <code class="docutils literal notranslate"><span class="pre">ensurepip</span></code> is invoked directly - the <code class="docutils literal notranslate"><span class="pre">--default-pip</span></code>
  429. option is needed to also request the unversioned <code class="docutils literal notranslate"><span class="pre">pip</span></code> command.
  430. <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> and the Windows installer ensure that the unqualified <code class="docutils literal notranslate"><span class="pre">pip</span></code>
  431. command is made available in those environments, and <code class="docutils literal notranslate"><span class="pre">pip</span></code> can always be
  432. invoked via the <code class="docutils literal notranslate"><span class="pre">-m</span></code> switch rather than directly to avoid ambiguity on
  433. systems with multiple Python installations.</p>
  434. </div>
  435. </section>
  436. <section id="documentation-changes">
  437. <h4>Documentation Changes<a class="headerlink" href="#documentation-changes" title="Link to this heading">¶</a></h4>
  438. <p>As part of this change, the <a class="reference internal" href="../installing/index.html#installing-index"><span class="std std-ref">Installing Python Modules</span></a> and
  439. <a class="reference internal" href="../distributing/index.html#distributing-index"><span class="std std-ref">Distributing Python Modules</span></a> sections of the documentation have been
  440. completely redesigned as short getting started and FAQ documents. Most
  441. packaging documentation has now been moved out to the Python Packaging
  442. Authority maintained <a class="reference external" href="https://packaging.python.org">Python Packaging User Guide</a> and the documentation of the individual
  443. projects.</p>
  444. <p>However, as this migration is currently still incomplete, the legacy
  445. versions of those guides remaining available as <a class="reference internal" href="../extending/building.html#install-index"><span class="std std-ref">Building C and C++ Extensions with setuptools</span></a>
  446. and <a class="reference internal" href="../extending/building.html#setuptools-index"><span class="std std-ref">Building C and C++ Extensions with setuptools</span></a>.</p>
  447. <div class="admonition seealso">
  448. <p class="admonition-title">See also</p>
  449. <dl class="simple">
  450. <dt><span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0453/"><strong>PEP 453</strong></a> – Explicit bootstrapping of pip in Python installations</dt><dd><p>PEP written by Donald Stufft and Nick Coghlan, implemented by
  451. Donald Stufft, Nick Coghlan, Martin von Löwis and Ned Deily.</p>
  452. </dd>
  453. </dl>
  454. </div>
  455. </section>
  456. </section>
  457. <section id="pep-446-newly-created-file-descriptors-are-non-inheritable">
  458. <span id="whatsnew-pep-446"></span><h3>PEP 446: Newly Created File Descriptors Are Non-Inheritable<a class="headerlink" href="#pep-446-newly-created-file-descriptors-are-non-inheritable" title="Link to this heading">¶</a></h3>
  459. <p><span class="target" id="index-21"></span><a class="pep reference external" href="https://peps.python.org/pep-0446/"><strong>PEP 446</strong></a> makes newly created file descriptors <a class="reference internal" href="../library/os.html#fd-inheritance"><span class="std std-ref">non-inheritable</span></a>. In general, this is the behavior an application will
  460. want: when launching a new process, having currently open files also
  461. open in the new process can lead to all sorts of hard to find bugs,
  462. and potentially to security issues.</p>
  463. <p>However, there are occasions when inheritance is desired. To support
  464. these cases, the following new functions and methods are available:</p>
  465. <ul class="simple">
  466. <li><p><a class="reference internal" href="../library/os.html#os.get_inheritable" title="os.get_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.get_inheritable()</span></code></a>, <a class="reference internal" href="../library/os.html#os.set_inheritable" title="os.set_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.set_inheritable()</span></code></a></p></li>
  467. <li><p><a class="reference internal" href="../library/os.html#os.get_handle_inheritable" title="os.get_handle_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.get_handle_inheritable()</span></code></a>, <a class="reference internal" href="../library/os.html#os.set_handle_inheritable" title="os.set_handle_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.set_handle_inheritable()</span></code></a></p></li>
  468. <li><p><a class="reference internal" href="../library/socket.html#socket.socket.get_inheritable" title="socket.socket.get_inheritable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.socket.get_inheritable()</span></code></a>, <a class="reference internal" href="../library/socket.html#socket.socket.set_inheritable" title="socket.socket.set_inheritable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.socket.set_inheritable()</span></code></a></p></li>
  469. </ul>
  470. <div class="admonition seealso">
  471. <p class="admonition-title">See also</p>
  472. <dl class="simple">
  473. <dt><span class="target" id="index-22"></span><a class="pep reference external" href="https://peps.python.org/pep-0446/"><strong>PEP 446</strong></a> – Make newly created file descriptors non-inheritable</dt><dd><p>PEP written and implemented by Victor Stinner.</p>
  474. </dd>
  475. </dl>
  476. </div>
  477. </section>
  478. <section id="improvements-to-codec-handling">
  479. <span id="codec-handling-improvements"></span><h3>Improvements to Codec Handling<a class="headerlink" href="#improvements-to-codec-handling" title="Link to this heading">¶</a></h3>
  480. <p>Since it was first introduced, the <a class="reference internal" href="../library/codecs.html#module-codecs" title="codecs: Encode and decode data and streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">codecs</span></code></a> module has always been
  481. intended to operate as a type-neutral dynamic encoding and decoding
  482. system. However, its close coupling with the Python text model, especially
  483. the type restricted convenience methods on the builtin <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>,
  484. <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> types, has historically obscured that
  485. fact.</p>
  486. <p>As a key step in clarifying the situation, the <a class="reference internal" href="../library/codecs.html#codecs.encode" title="codecs.encode"><code class="xref py py-meth docutils literal notranslate"><span class="pre">codecs.encode()</span></code></a> and
  487. <a class="reference internal" href="../library/codecs.html#codecs.decode" title="codecs.decode"><code class="xref py py-meth docutils literal notranslate"><span class="pre">codecs.decode()</span></code></a> convenience functions are now properly documented in
  488. Python 2.7, 3.3 and 3.4. These functions have existed in the <a class="reference internal" href="../library/codecs.html#module-codecs" title="codecs: Encode and decode data and streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">codecs</span></code></a>
  489. module (and have been covered by the regression test suite) since Python 2.4,
  490. but were previously only discoverable through runtime introspection.</p>
  491. <p>Unlike the convenience methods on <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
  492. <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>, the <a class="reference internal" href="../library/codecs.html#module-codecs" title="codecs: Encode and decode data and streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">codecs</span></code></a> convenience functions support arbitrary
  493. codecs in both Python 2 and Python 3, rather than being limited to Unicode text
  494. encodings (in Python 3) or <code class="docutils literal notranslate"><span class="pre">basestring</span></code> &lt;-&gt; <code class="docutils literal notranslate"><span class="pre">basestring</span></code> conversions (in
  495. Python 2).</p>
  496. <p>In Python 3.4, the interpreter is able to identify the known non-text
  497. encodings provided in the standard library and direct users towards these
  498. general purpose convenience functions when appropriate:</p>
  499. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="sa">b</span><span class="s2">&quot;abcdef&quot;</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;hex&quot;</span><span class="p">)</span>
  500. <span class="gt">Traceback (most recent call last):</span>
  501. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  502. <span class="gr">LookupError</span>: <span class="n">&#39;hex&#39; is not a text encoding; use codecs.decode() to handle arbitrary codecs</span>
  503. <span class="gp">&gt;&gt;&gt; </span><span class="s2">&quot;hello&quot;</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;rot13&quot;</span><span class="p">)</span>
  504. <span class="gt">Traceback (most recent call last):</span>
  505. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  506. <span class="gr">LookupError</span>: <span class="n">&#39;rot13&#39; is not a text encoding; use codecs.encode() to handle arbitrary codecs</span>
  507. <span class="gp">&gt;&gt;&gt; </span><span class="nb">open</span><span class="p">(</span><span class="s2">&quot;foo.txt&quot;</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">&quot;hex&quot;</span><span class="p">)</span>
  508. <span class="gt">Traceback (most recent call last):</span>
  509. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  510. <span class="gr">LookupError</span>: <span class="n">&#39;hex&#39; is not a text encoding; use codecs.open() to handle arbitrary codecs</span>
  511. </pre></div>
  512. </div>
  513. <p>In a related change, whenever it is feasible without breaking backwards
  514. compatibility, exceptions raised during encoding and decoding operations
  515. are wrapped in a chained exception of the same type that mentions the
  516. name of the codec responsible for producing the error:</p>
  517. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">codecs</span>
  518. <span class="gp">&gt;&gt;&gt; </span><span class="n">codecs</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="sa">b</span><span class="s2">&quot;abcdefgh&quot;</span><span class="p">,</span> <span class="s2">&quot;hex&quot;</span><span class="p">)</span>
  519. <span class="gt">Traceback (most recent call last):</span>
  520. File <span class="nb">&quot;/usr/lib/python3.4/encodings/hex_codec.py&quot;</span>, line <span class="m">20</span>, in <span class="n">hex_decode</span>
  521. <span class="w"> </span><span class="k">return</span> <span class="p">(</span><span class="n">binascii</span><span class="o">.</span><span class="n">a2b_hex</span><span class="p">(</span><span class="nb">input</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="nb">input</span><span class="p">))</span>
  522. <span class="gr">binascii.Error</span>: <span class="n">Non-hexadecimal digit found</span>
  523. <span class="gt">The above exception was the direct cause of the following exception:</span>
  524. <span class="gt">Traceback (most recent call last):</span>
  525. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  526. <span class="gr">binascii.Error</span>: <span class="n">decoding with &#39;hex&#39; codec failed (Error: Non-hexadecimal digit found)</span>
  527. <span class="gp">&gt;&gt;&gt; </span><span class="n">codecs</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;hello&quot;</span><span class="p">,</span> <span class="s2">&quot;bz2&quot;</span><span class="p">)</span>
  528. <span class="gt">Traceback (most recent call last):</span>
  529. File <span class="nb">&quot;/usr/lib/python3.4/encodings/bz2_codec.py&quot;</span>, line <span class="m">17</span>, in <span class="n">bz2_encode</span>
  530. <span class="w"> </span><span class="k">return</span> <span class="p">(</span><span class="n">bz2</span><span class="o">.</span><span class="n">compress</span><span class="p">(</span><span class="nb">input</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="nb">input</span><span class="p">))</span>
  531. File <span class="nb">&quot;/usr/lib/python3.4/bz2.py&quot;</span>, line <span class="m">498</span>, in <span class="n">compress</span>
  532. <span class="w"> </span><span class="k">return</span> <span class="n">comp</span><span class="o">.</span><span class="n">compress</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">+</span> <span class="n">comp</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
  533. <span class="gr">TypeError</span>: <span class="n">&#39;str&#39; does not support the buffer interface</span>
  534. <span class="gt">The above exception was the direct cause of the following exception:</span>
  535. <span class="gt">Traceback (most recent call last):</span>
  536. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  537. <span class="gr">TypeError</span>: <span class="n">encoding with &#39;bz2&#39; codec failed (TypeError: &#39;str&#39; does not support the buffer interface)</span>
  538. </pre></div>
  539. </div>
  540. <p>Finally, as the examples above show, these improvements have permitted
  541. the restoration of the convenience aliases for the non-Unicode codecs that
  542. were themselves restored in Python 3.2. This means that encoding binary data
  543. to and from its hexadecimal representation (for example) can now be written
  544. as:</p>
  545. <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">codecs</span> <span class="kn">import</span> <span class="n">encode</span><span class="p">,</span> <span class="n">decode</span>
  546. <span class="gp">&gt;&gt;&gt; </span><span class="n">encode</span><span class="p">(</span><span class="sa">b</span><span class="s2">&quot;hello&quot;</span><span class="p">,</span> <span class="s2">&quot;hex&quot;</span><span class="p">)</span>
  547. <span class="go">b&#39;68656c6c6f&#39;</span>
  548. <span class="gp">&gt;&gt;&gt; </span><span class="n">decode</span><span class="p">(</span><span class="sa">b</span><span class="s2">&quot;68656c6c6f&quot;</span><span class="p">,</span> <span class="s2">&quot;hex&quot;</span><span class="p">)</span>
  549. <span class="go">b&#39;hello&#39;</span>
  550. </pre></div>
  551. </div>
  552. <p>The binary and text transforms provided in the standard library are detailed
  553. in <a class="reference internal" href="../library/codecs.html#binary-transforms"><span class="std std-ref">Binary Transforms</span></a> and <a class="reference internal" href="../library/codecs.html#text-transforms"><span class="std std-ref">Text Transforms</span></a>.</p>
  554. <p>(Contributed by Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=7475">bpo-7475</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17827">bpo-17827</a>,
  555. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17828">bpo-17828</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19619">bpo-19619</a>.)</p>
  556. </section>
  557. <section id="pep-451-a-modulespec-type-for-the-import-system">
  558. <span id="whatsnew-pep-451"></span><h3>PEP 451: A ModuleSpec Type for the Import System<a class="headerlink" href="#pep-451-a-modulespec-type-for-the-import-system" title="Link to this heading">¶</a></h3>
  559. <p><span class="target" id="index-23"></span><a class="pep reference external" href="https://peps.python.org/pep-0451/"><strong>PEP 451</strong></a> provides an encapsulation of the information about a module that the
  560. import machinery will use to load it (that is, a module specification). This
  561. helps simplify both the import implementation and several import-related APIs.
  562. The change is also a stepping stone for <a class="reference external" href="https://mail.python.org/pipermail/python-dev/2013-November/130111.html">several future import-related
  563. improvements</a>.</p>
  564. <p>The public-facing changes from the PEP are entirely backward-compatible.
  565. Furthermore, they should be transparent to everyone but importer authors. Key
  566. finder and loader methods have been deprecated, but they will continue working.
  567. New importers should use the new methods described in the PEP. Existing
  568. importers should be updated to implement the new methods. See the
  569. <a class="reference internal" href="#deprecated-3-4"><span class="std std-ref">Deprecated</span></a> section for a list of methods that should be replaced and
  570. their replacements.</p>
  571. </section>
  572. <section id="other-language-changes">
  573. <h3>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading">¶</a></h3>
  574. <p>Some smaller changes made to the core Python language are:</p>
  575. <ul class="simple">
  576. <li><p>Unicode database updated to UCD version 6.3.</p></li>
  577. <li><p><a class="reference internal" href="../library/functions.html#min" title="min"><code class="xref py py-func docutils literal notranslate"><span class="pre">min()</span></code></a> and <a class="reference internal" href="../library/functions.html#max" title="max"><code class="xref py py-func docutils literal notranslate"><span class="pre">max()</span></code></a> now accept a <em>default</em> keyword-only argument that
  578. can be used to specify the value they return if the iterable they are
  579. evaluating has no elements. (Contributed by Julian Berman in
  580. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18111">bpo-18111</a>.)</p></li>
  581. <li><p>Module objects are now <a class="reference internal" href="../library/weakref.html#mod-weakref"><span class="std std-ref">weakly referenceable</span></a>.</p></li>
  582. <li><p>Module <code class="docutils literal notranslate"><span class="pre">__file__</span></code> attributes (and related values) should now always
  583. contain absolute paths by default, with the sole exception of
  584. <code class="docutils literal notranslate"><span class="pre">__main__.__file__</span></code> when a script has been executed directly using
  585. a relative path. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18416">bpo-18416</a>.)</p></li>
  586. <li><p>All the UTF-* codecs (except UTF-7) now reject surrogates during both
  587. encoding and decoding unless the <code class="docutils literal notranslate"><span class="pre">surrogatepass</span></code> error handler is used,
  588. with the exception of the UTF-16 decoder (which accepts valid surrogate pairs)
  589. and the UTF-16 encoder (which produces them while encoding non-BMP characters).
  590. (Contributed by Victor Stinner, Kang-Hao (Kenny) Lu and Serhiy Storchaka in
  591. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12892">bpo-12892</a>.)</p></li>
  592. <li><p>New German EBCDIC <a class="reference internal" href="../library/codecs.html#standard-encodings"><span class="std std-ref">codec</span></a> <code class="docutils literal notranslate"><span class="pre">cp273</span></code>. (Contributed
  593. by Michael Bierenfeld and Andrew Kuchling in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1097797">bpo-1097797</a>.)</p></li>
  594. <li><p>New Ukrainian <a class="reference internal" href="../library/codecs.html#standard-encodings"><span class="std std-ref">codec</span></a> <code class="docutils literal notranslate"><span class="pre">cp1125</span></code>. (Contributed by
  595. Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19668">bpo-19668</a>.)</p></li>
  596. <li><p><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>.join() and <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a>.join() now accept arbitrary
  597. buffer objects as arguments. (Contributed by Antoine Pitrou in
  598. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15958">bpo-15958</a>.)</p></li>
  599. <li><p>The <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> constructor now accepts any object that has an <code class="docutils literal notranslate"><span class="pre">__index__</span></code>
  600. method for its <em>base</em> argument. (Contributed by Mark Dickinson in
  601. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16772">bpo-16772</a>.)</p></li>
  602. <li><p>Frame objects now have a <a class="reference internal" href="../reference/datamodel.html#frame.clear" title="frame.clear"><code class="xref py py-func docutils literal notranslate"><span class="pre">clear()</span></code></a> method that clears all
  603. references to local variables from the frame. (Contributed by Antoine Pitrou
  604. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17934">bpo-17934</a>.)</p></li>
  605. <li><p><a class="reference internal" href="../library/stdtypes.html#memoryview" title="memoryview"><code class="xref py py-class docutils literal notranslate"><span class="pre">memoryview</span></code></a> is now registered as a <a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-class docutils literal notranslate"><span class="pre">Sequence</span></code></a>,
  606. and supports the <a class="reference internal" href="../library/functions.html#reversed" title="reversed"><code class="xref py py-func docutils literal notranslate"><span class="pre">reversed()</span></code></a> builtin. (Contributed by Nick Coghlan
  607. and Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18690">bpo-18690</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19078">bpo-19078</a>.)</p></li>
  608. <li><p>Signatures reported by <a class="reference internal" href="../library/functions.html#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a> have been modified and improved in
  609. several cases as a result of the introduction of Argument Clinic and other
  610. changes to 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> and <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> modules.</p></li>
  611. <li><p><a class="reference internal" href="../reference/datamodel.html#object.__length_hint__" title="object.__length_hint__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__length_hint__()</span></code></a> is now part of the formal language
  612. specification (see <span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0424/"><strong>PEP 424</strong></a>). (Contributed by Armin Ronacher in
  613. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16148">bpo-16148</a>.)</p></li>
  614. </ul>
  615. </section>
  616. </section>
  617. <section id="new-modules">
  618. <h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading">¶</a></h2>
  619. <section id="asyncio">
  620. <span id="whatsnew-asyncio"></span><h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading">¶</a></h3>
  621. <p>The new <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> module (defined in <span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-3156/"><strong>PEP 3156</strong></a>) provides a standard
  622. pluggable event loop model for Python, providing solid asynchronous IO
  623. support in the standard library, and making it easier for other event loop
  624. implementations to interoperate with the standard library and each other.</p>
  625. <p>For Python 3.4, this module is considered a <a class="reference internal" href="../glossary.html#term-provisional-API"><span class="xref std std-term">provisional API</span></a>.</p>
  626. <div class="admonition seealso">
  627. <p class="admonition-title">See also</p>
  628. <dl class="simple">
  629. <dt><span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-3156/"><strong>PEP 3156</strong></a> – Asynchronous IO Support Rebooted: the “asyncio” Module</dt><dd><p>PEP written and implementation led by Guido van Rossum.</p>
  630. </dd>
  631. </dl>
  632. </div>
  633. </section>
  634. <section id="ensurepip">
  635. <span id="whatsnew-ensurepip"></span><h3>ensurepip<a class="headerlink" href="#ensurepip" title="Link to this heading">¶</a></h3>
  636. <p>The new <a class="reference internal" href="../library/ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the &quot;pip&quot; installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a> module is the primary infrastructure for the
  637. <span class="target" id="index-27"></span><a class="pep reference external" href="https://peps.python.org/pep-0453/"><strong>PEP 453</strong></a> implementation. In the normal course of events end users will not
  638. need to interact with this module, but it can be used to manually bootstrap
  639. <code class="docutils literal notranslate"><span class="pre">pip</span></code> if the automated bootstrapping into an installation or virtual
  640. environment was declined.</p>
  641. <p><a class="reference internal" href="../library/ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the &quot;pip&quot; installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a> includes a bundled copy of <code class="docutils literal notranslate"><span class="pre">pip</span></code>, up-to-date as of the first
  642. release candidate of the release of CPython with which it ships (this applies
  643. to both maintenance releases and feature releases). <code class="docutils literal notranslate"><span class="pre">ensurepip</span></code> does not
  644. access the internet. If the installation has internet access, after
  645. <code class="docutils literal notranslate"><span class="pre">ensurepip</span></code> is run the bundled <code class="docutils literal notranslate"><span class="pre">pip</span></code> can be used to upgrade <code class="docutils literal notranslate"><span class="pre">pip</span></code> to a
  646. more recent release than the bundled one. (Note that such an upgraded version
  647. of <code class="docutils literal notranslate"><span class="pre">pip</span></code> is considered to be a separately installed package and will not be
  648. removed if Python is uninstalled.)</p>
  649. <p>The module is named <em>ensure</em>pip because if called when <code class="docutils literal notranslate"><span class="pre">pip</span></code> is already
  650. installed, it does nothing. It also has an <code class="docutils literal notranslate"><span class="pre">--upgrade</span></code> option that will
  651. cause it to install the bundled copy of <code class="docutils literal notranslate"><span class="pre">pip</span></code> if the existing installed
  652. version of <code class="docutils literal notranslate"><span class="pre">pip</span></code> is older than the bundled copy.</p>
  653. </section>
  654. <section id="enum">
  655. <span id="whatsnew-enum"></span><h3>enum<a class="headerlink" href="#enum" title="Link to this heading">¶</a></h3>
  656. <p>The new <a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a> module (defined in <span class="target" id="index-28"></span><a class="pep reference external" href="https://peps.python.org/pep-0435/"><strong>PEP 435</strong></a>) provides a standard
  657. implementation of enumeration types, allowing other modules (such as
  658. <a class="reference internal" href="../library/socket.html#module-socket" title="socket: Low-level networking interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socket</span></code></a>) to provide more informative error messages and better
  659. debugging support by replacing opaque integer constants with backwards
  660. compatible enumeration values.</p>
  661. <div class="admonition seealso">
  662. <p class="admonition-title">See also</p>
  663. <dl class="simple">
  664. <dt><span class="target" id="index-29"></span><a class="pep reference external" href="https://peps.python.org/pep-0435/"><strong>PEP 435</strong></a> – Adding an Enum type to the Python standard library</dt><dd><p>PEP written by Barry Warsaw, Eli Bendersky and Ethan Furman,
  665. implemented by Ethan Furman.</p>
  666. </dd>
  667. </dl>
  668. </div>
  669. </section>
  670. <section id="pathlib">
  671. <span id="whatsnew-pathlib"></span><h3>pathlib<a class="headerlink" href="#pathlib" title="Link to this heading">¶</a></h3>
  672. <p>The new <a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> module offers classes representing filesystem paths
  673. with semantics appropriate for different operating systems. Path classes are
  674. divided between <em>pure paths</em>, which provide purely computational operations
  675. without I/O, and <em>concrete paths</em>, which inherit from pure paths but also
  676. provide I/O operations.</p>
  677. <p>For Python 3.4, this module is considered a <a class="reference internal" href="../glossary.html#term-provisional-API"><span class="xref std std-term">provisional API</span></a>.</p>
  678. <div class="admonition seealso">
  679. <p class="admonition-title">See also</p>
  680. <dl class="simple">
  681. <dt><span class="target" id="index-30"></span><a class="pep reference external" href="https://peps.python.org/pep-0428/"><strong>PEP 428</strong></a> – The pathlib module – object-oriented filesystem paths</dt><dd><p>PEP written and implemented by Antoine Pitrou.</p>
  682. </dd>
  683. </dl>
  684. </div>
  685. </section>
  686. <section id="selectors">
  687. <span id="whatsnew-selectors"></span><h3>selectors<a class="headerlink" href="#selectors" title="Link to this heading">¶</a></h3>
  688. <p>The new <a class="reference internal" href="../library/selectors.html#module-selectors" title="selectors: High-level I/O multiplexing."><code class="xref py py-mod docutils literal notranslate"><span class="pre">selectors</span></code></a> module (created as part of implementing <span class="target" id="index-31"></span><a class="pep reference external" href="https://peps.python.org/pep-3156/"><strong>PEP 3156</strong></a>)
  689. allows high-level and efficient I/O multiplexing, built upon the
  690. <a class="reference internal" href="../library/select.html#module-select" title="select: Wait for I/O completion on multiple streams."><code class="xref py py-mod docutils literal notranslate"><span class="pre">select</span></code></a> module primitives.</p>
  691. </section>
  692. <section id="statistics">
  693. <span id="whatsnew-statistics"></span><h3>statistics<a class="headerlink" href="#statistics" title="Link to this heading">¶</a></h3>
  694. <p>The new <a class="reference internal" href="../library/statistics.html#module-statistics" title="statistics: Mathematical statistics functions"><code class="xref py py-mod docutils literal notranslate"><span class="pre">statistics</span></code></a> module (defined in <span class="target" id="index-32"></span><a class="pep reference external" href="https://peps.python.org/pep-0450/"><strong>PEP 450</strong></a>) offers some core
  695. statistics functionality directly in the standard library. This module
  696. supports calculation of the mean, median, mode, variance and standard
  697. deviation of a data series.</p>
  698. <div class="admonition seealso">
  699. <p class="admonition-title">See also</p>
  700. <dl class="simple">
  701. <dt><span class="target" id="index-33"></span><a class="pep reference external" href="https://peps.python.org/pep-0450/"><strong>PEP 450</strong></a> – Adding A Statistics Module To The Standard Library</dt><dd><p>PEP written and implemented by Steven D’Aprano</p>
  702. </dd>
  703. </dl>
  704. </div>
  705. </section>
  706. <section id="tracemalloc">
  707. <span id="whatsnew-tracemalloc"></span><h3>tracemalloc<a class="headerlink" href="#tracemalloc" title="Link to this heading">¶</a></h3>
  708. <p>The new <a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a> module (defined in <span class="target" id="index-34"></span><a class="pep reference external" href="https://peps.python.org/pep-0454/"><strong>PEP 454</strong></a>) is a debug tool to
  709. trace memory blocks allocated by Python. It provides the following information:</p>
  710. <ul class="simple">
  711. <li><p>Trace where an object was allocated</p></li>
  712. <li><p>Statistics on allocated memory blocks per filename and per line number:
  713. total size, number and average size of allocated memory blocks</p></li>
  714. <li><p>Compute the differences between two snapshots to detect memory leaks</p></li>
  715. </ul>
  716. <div class="admonition seealso">
  717. <p class="admonition-title">See also</p>
  718. <dl class="simple">
  719. <dt><span class="target" id="index-35"></span><a class="pep reference external" href="https://peps.python.org/pep-0454/"><strong>PEP 454</strong></a> – Add a new tracemalloc module to trace Python memory allocations</dt><dd><p>PEP written and implemented by Victor Stinner</p>
  720. </dd>
  721. </dl>
  722. </div>
  723. </section>
  724. </section>
  725. <section id="improved-modules">
  726. <h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading">¶</a></h2>
  727. <section id="abc">
  728. <h3>abc<a class="headerlink" href="#abc" title="Link to this heading">¶</a></h3>
  729. <p>New function <a class="reference internal" href="../library/abc.html#abc.get_cache_token" title="abc.get_cache_token"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.get_cache_token()</span></code></a> can be used to know when to invalidate
  730. caches that are affected by changes in the object graph. (Contributed
  731. by Łukasz Langa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16832">bpo-16832</a>.)</p>
  732. <p>New class <a class="reference internal" href="../library/abc.html#abc.ABC" title="abc.ABC"><code class="xref py py-class docutils literal notranslate"><span class="pre">ABC</span></code></a> has <a class="reference internal" href="../library/abc.html#abc.ABCMeta" title="abc.ABCMeta"><code class="xref py py-class docutils literal notranslate"><span class="pre">ABCMeta</span></code></a> as its meta class.
  733. Using <code class="docutils literal notranslate"><span class="pre">ABC</span></code> as a base class has essentially the same effect as specifying
  734. <code class="docutils literal notranslate"><span class="pre">metaclass=abc.ABCMeta</span></code>, but is simpler to type and easier to read.
  735. (Contributed by Bruno Dupuis in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16049">bpo-16049</a>.)</p>
  736. </section>
  737. <section id="aifc">
  738. <h3>aifc<a class="headerlink" href="#aifc" title="Link to this heading">¶</a></h3>
  739. <p>The <a class="reference internal" href="../library/aifc.html#aifc.aifc.getparams" title="aifc.aifc.getparams"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getparams()</span></code></a> method now returns a namedtuple rather than a
  740. plain tuple. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17818">bpo-17818</a>.)</p>
  741. <p><a class="reference internal" href="../library/aifc.html#aifc.open" title="aifc.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">aifc.open()</span></code></a> now supports the context management protocol: when used in a
  742. <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, the <a class="reference internal" href="../library/aifc.html#aifc.aifc.close" title="aifc.aifc.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> method of the returned
  743. object will be called automatically at the end of the block. (Contributed by
  744. Serhiy Storchacha in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16486">bpo-16486</a>.)</p>
  745. <p>The <a class="reference internal" href="../library/aifc.html#aifc.aifc.writeframesraw" title="aifc.aifc.writeframesraw"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframesraw()</span></code></a> and <a class="reference internal" href="../library/aifc.html#aifc.aifc.writeframes" title="aifc.aifc.writeframes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframes()</span></code></a>
  746. methods now accept any <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a>. (Contributed by Serhiy
  747. Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8311">bpo-8311</a>.)</p>
  748. </section>
  749. <section id="argparse">
  750. <h3>argparse<a class="headerlink" href="#argparse" title="Link to this heading">¶</a></h3>
  751. <p>The <a class="reference internal" href="../library/argparse.html#argparse.FileType" title="argparse.FileType"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileType</span></code></a> class now accepts <em>encoding</em> and
  752. <em>errors</em> arguments, which are passed through to <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>. (Contributed
  753. by Lucas Maystre in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11175">bpo-11175</a>.)</p>
  754. </section>
  755. <section id="audioop">
  756. <h3>audioop<a class="headerlink" href="#audioop" title="Link to this heading">¶</a></h3>
  757. <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> now supports 24-bit samples. (Contributed by Serhiy Storchaka
  758. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12866">bpo-12866</a>.)</p>
  759. <p>New <a class="reference internal" href="../library/audioop.html#audioop.byteswap" title="audioop.byteswap"><code class="xref py py-func docutils literal notranslate"><span class="pre">byteswap()</span></code></a> function converts big-endian samples to
  760. little-endian and vice versa. (Contributed by Serhiy Storchaka in
  761. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19641">bpo-19641</a>.)</p>
  762. <p>All <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> functions now accept any <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a>. Strings
  763. are not accepted: they didn’t work before, now they raise an error right away.
  764. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16685">bpo-16685</a>.)</p>
  765. </section>
  766. <section id="base64">
  767. <h3>base64<a class="headerlink" href="#base64" title="Link to this heading">¶</a></h3>
  768. <p>The encoding and decoding functions in <a class="reference internal" href="../library/base64.html#module-base64" title="base64: RFC 4648: Base16, Base32, Base64 Data Encodings; Base85 and Ascii85"><code class="xref py py-mod docutils literal notranslate"><span class="pre">base64</span></code></a> now accept any
  769. <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a> in cases where it previously required a
  770. <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> or <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> instance. (Contributed by Nick Coghlan in
  771. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17839">bpo-17839</a>.)</p>
  772. <p>New functions <a class="reference internal" href="../library/base64.html#base64.a85encode" title="base64.a85encode"><code class="xref py py-func docutils literal notranslate"><span class="pre">a85encode()</span></code></a>, <a class="reference internal" href="../library/base64.html#base64.a85decode" title="base64.a85decode"><code class="xref py py-func docutils literal notranslate"><span class="pre">a85decode()</span></code></a>,
  773. <a class="reference internal" href="../library/base64.html#base64.b85encode" title="base64.b85encode"><code class="xref py py-func docutils literal notranslate"><span class="pre">b85encode()</span></code></a>, and <a class="reference internal" href="../library/base64.html#base64.b85decode" title="base64.b85decode"><code class="xref py py-func docutils literal notranslate"><span class="pre">b85decode()</span></code></a> provide the ability to
  774. encode and decode binary data from and to <code class="docutils literal notranslate"><span class="pre">Ascii85</span></code> and the git/mercurial
  775. <code class="docutils literal notranslate"><span class="pre">Base85</span></code> formats, respectively. The <code class="docutils literal notranslate"><span class="pre">a85</span></code> functions have options that can
  776. be used to make them compatible with the variants of the <code class="docutils literal notranslate"><span class="pre">Ascii85</span></code> encoding,
  777. including the Adobe variant. (Contributed by Martin Morrison, the Mercurial
  778. project, Serhiy Storchaka, and Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17618">bpo-17618</a>.)</p>
  779. </section>
  780. <section id="collections">
  781. <h3>collections<a class="headerlink" href="#collections" title="Link to this heading">¶</a></h3>
  782. <p>The <a class="reference internal" href="../library/collections.html#collections.ChainMap.new_child" title="collections.ChainMap.new_child"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ChainMap.new_child()</span></code></a> method now accepts an <em>m</em> argument specifying
  783. the child map to add to the chain. This allows an existing mapping and/or a
  784. custom mapping type to be used for the child. (Contributed by Vinay Sajip in
  785. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16613">bpo-16613</a>.)</p>
  786. </section>
  787. <section id="colorsys">
  788. <h3>colorsys<a class="headerlink" href="#colorsys" title="Link to this heading">¶</a></h3>
  789. <p>The number of digits in the coefficients for the RGB — YIQ conversions have
  790. been expanded so that they match the FCC NTSC versions. The change in
  791. results should be less than 1% and may better match results found elsewhere.
  792. (Contributed by Brian Landers and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14323">bpo-14323</a>.)</p>
  793. </section>
  794. <section id="contextlib">
  795. <h3>contextlib<a class="headerlink" href="#contextlib" title="Link to this heading">¶</a></h3>
  796. <p>The new <a class="reference internal" href="../library/contextlib.html#contextlib.suppress" title="contextlib.suppress"><code class="xref py py-class docutils literal notranslate"><span class="pre">contextlib.suppress</span></code></a> context manager helps to clarify the
  797. intent of code that deliberately suppresses exceptions from a single
  798. statement. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15806">bpo-15806</a> and
  799. Zero Piraeus in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19266">bpo-19266</a>.)</p>
  800. <p>The new <a class="reference internal" href="../library/contextlib.html#contextlib.redirect_stdout" title="contextlib.redirect_stdout"><code class="xref py py-func docutils literal notranslate"><span class="pre">contextlib.redirect_stdout()</span></code></a> context manager makes it easier
  801. for utility scripts to handle inflexible APIs that write their output to
  802. <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a> and don’t provide any options to redirect it. Using the
  803. context manager, the <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a> output can be redirected to any
  804. other stream or, in conjunction with <a class="reference internal" href="../library/io.html#io.StringIO" title="io.StringIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.StringIO</span></code></a>, to a string.
  805. The latter can be especially useful, for example, to capture output
  806. from a function that was written to implement a command line interface.
  807. It is recommended only for utility scripts because it affects the
  808. global state of <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a>. (Contributed by Raymond Hettinger
  809. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15805">bpo-15805</a>.)</p>
  810. <p>The <a class="reference internal" href="../library/contextlib.html#module-contextlib" title="contextlib: Utilities for with-statement contexts."><code class="xref py py-mod docutils literal notranslate"><span class="pre">contextlib</span></code></a> documentation has also been updated to include a
  811. <a class="reference internal" href="../library/contextlib.html#single-use-reusable-and-reentrant-cms"><span class="std std-ref">discussion</span></a> of the
  812. differences between single use, reusable and reentrant context managers.</p>
  813. </section>
  814. <section id="dbm">
  815. <h3>dbm<a class="headerlink" href="#dbm" title="Link to this heading">¶</a></h3>
  816. <p><a class="reference internal" href="../library/dbm.html#dbm.open" title="dbm.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">dbm.open()</span></code></a> objects now support the context management protocol. When
  817. used in a <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> statement, the <code class="docutils literal notranslate"><span class="pre">close</span></code> method of the database
  818. object will be called automatically at the end of the block. (Contributed by
  819. Claudiu Popa and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19282">bpo-19282</a>.)</p>
  820. </section>
  821. <section id="dis">
  822. <h3>dis<a class="headerlink" href="#dis" title="Link to this heading">¶</a></h3>
  823. <p>Functions <a class="reference internal" href="../library/dis.html#dis.show_code" title="dis.show_code"><code class="xref py py-func docutils literal notranslate"><span class="pre">show_code()</span></code></a>, <a class="reference internal" href="../library/dis.html#dis.dis" title="dis.dis"><code class="xref py py-func docutils literal notranslate"><span class="pre">dis()</span></code></a>, <a class="reference internal" href="../library/dis.html#dis.distb" title="dis.distb"><code class="xref py py-func docutils literal notranslate"><span class="pre">distb()</span></code></a>, and
  824. <a class="reference internal" href="../library/dis.html#dis.disassemble" title="dis.disassemble"><code class="xref py py-func docutils literal notranslate"><span class="pre">disassemble()</span></code></a> now accept a keyword-only <em>file</em> argument that
  825. controls where they write their output.</p>
  826. <p>The <a class="reference internal" href="../library/dis.html#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> module is now built around an <a class="reference internal" href="../library/dis.html#dis.Instruction" title="dis.Instruction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Instruction</span></code></a> class
  827. that provides object oriented access to the details of each individual bytecode
  828. operation.</p>
  829. <p>A new method, <a class="reference internal" href="../library/dis.html#dis.get_instructions" title="dis.get_instructions"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_instructions()</span></code></a>, provides an iterator that emits
  830. the Instruction stream for a given piece of Python code. Thus it is now
  831. possible to write a program that inspects and manipulates a bytecode
  832. object in ways different from those provided by the <a class="reference internal" href="../library/dis.html#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> module
  833. itself. For example:</p>
  834. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">dis</span>
  835. <span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">instr</span> <span class="ow">in</span> <span class="n">dis</span><span class="o">.</span><span class="n">get_instructions</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
  836. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">instr</span><span class="o">.</span><span class="n">opname</span><span class="p">)</span>
  837. <span class="go">LOAD_FAST</span>
  838. <span class="go">LOAD_CONST</span>
  839. <span class="go">BINARY_ADD</span>
  840. <span class="go">RETURN_VALUE</span>
  841. </pre></div>
  842. </div>
  843. <p>The various display tools in the <a class="reference internal" href="../library/dis.html#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> module have been rewritten to use
  844. these new components.</p>
  845. <p>In addition, a new application-friendly class <a class="reference internal" href="../library/dis.html#dis.Bytecode" title="dis.Bytecode"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bytecode</span></code></a> provides
  846. an object-oriented API for inspecting bytecode in both in human-readable form
  847. and for iterating over instructions. The <a class="reference internal" href="../library/dis.html#dis.Bytecode" title="dis.Bytecode"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bytecode</span></code></a> constructor
  848. takes the same arguments that <code class="xref py py-func docutils literal notranslate"><span class="pre">get_instruction()</span></code> does (plus an
  849. optional <em>current_offset</em>), and the resulting object can be iterated to produce
  850. <a class="reference internal" href="../library/dis.html#dis.Instruction" title="dis.Instruction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Instruction</span></code></a> objects. But it also has a <a class="reference internal" href="../library/dis.html#dis.Bytecode.dis" title="dis.Bytecode.dis"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a>
  851. method, equivalent to calling <a class="reference internal" href="../library/dis.html#dis.dis" title="dis.dis"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> on the constructor argument, but
  852. returned as a multi-line string:</p>
  853. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">bytecode</span> <span class="o">=</span> <span class="n">dis</span><span class="o">.</span><span class="n">Bytecode</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">current_offset</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
  854. <span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">instr</span> <span class="ow">in</span> <span class="n">bytecode</span><span class="p">:</span>
  855. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{}</span><span class="s1"> (</span><span class="si">{}</span><span class="s1">)&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">instr</span><span class="o">.</span><span class="n">opname</span><span class="p">,</span> <span class="n">instr</span><span class="o">.</span><span class="n">opcode</span><span class="p">))</span>
  856. <span class="go">LOAD_FAST (124)</span>
  857. <span class="go">LOAD_CONST (100)</span>
  858. <span class="go">BINARY_ADD (23)</span>
  859. <span class="go">RETURN_VALUE (83)</span>
  860. <span class="gp">&gt;&gt;&gt; </span><span class="n">bytecode</span><span class="o">.</span><span class="n">dis</span><span class="p">()</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()</span>
  861. <span class="go">[&#39; 1 0 LOAD_FAST 0 (x)&#39;,</span>
  862. <span class="go"> &#39; --&gt; 3 LOAD_CONST 1 (1)&#39;,</span>
  863. <span class="go"> &#39; 6 BINARY_ADD&#39;,</span>
  864. <span class="go"> &#39; 7 RETURN_VALUE&#39;]</span>
  865. </pre></div>
  866. </div>
  867. <p><a class="reference internal" href="../library/dis.html#dis.Bytecode" title="dis.Bytecode"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bytecode</span></code></a> also has a class method,
  868. <a class="reference internal" href="../library/dis.html#dis.Bytecode.from_traceback" title="dis.Bytecode.from_traceback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">from_traceback()</span></code></a>, that provides the ability to manipulate a
  869. traceback (that is, <code class="docutils literal notranslate"><span class="pre">print(Bytecode.from_traceback(tb).dis())</span></code> is equivalent
  870. to <code class="docutils literal notranslate"><span class="pre">distb(tb)</span></code>).</p>
  871. <p>(Contributed by Nick Coghlan, Ryan Kelly and Thomas Kluyver in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11816">bpo-11816</a>
  872. and Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17916">bpo-17916</a>.)</p>
  873. <p>New function <a class="reference internal" href="../library/dis.html#dis.stack_effect" title="dis.stack_effect"><code class="xref py py-func docutils literal notranslate"><span class="pre">stack_effect()</span></code></a> computes the effect on the Python stack
  874. of a given opcode and argument, information that is not otherwise available.
  875. (Contributed by Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19722">bpo-19722</a>.)</p>
  876. </section>
  877. <section id="doctest">
  878. <h3>doctest<a class="headerlink" href="#doctest" title="Link to this heading">¶</a></h3>
  879. <p>A new <a class="reference internal" href="../library/doctest.html#doctest-options"><span class="std std-ref">option flag</span></a>, <a class="reference internal" href="../library/doctest.html#doctest.FAIL_FAST" title="doctest.FAIL_FAST"><code class="xref py py-const docutils literal notranslate"><span class="pre">FAIL_FAST</span></code></a>, halts
  880. test running as soon as the first failure is detected. (Contributed by R.
  881. David Murray and Daniel Urban in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16522">bpo-16522</a>.)</p>
  882. <p>The <a class="reference internal" href="../library/doctest.html#module-doctest" title="doctest: Test pieces of code within docstrings."><code class="xref py py-mod docutils literal notranslate"><span class="pre">doctest</span></code></a> command line interface now uses <a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a>, and has two
  883. new options, <code class="docutils literal notranslate"><span class="pre">-o</span></code> and <code class="docutils literal notranslate"><span class="pre">-f</span></code>. <code class="docutils literal notranslate"><span class="pre">-o</span></code> allows <a class="reference internal" href="../library/doctest.html#doctest-options"><span class="std std-ref">doctest options</span></a> to be specified on the command line, and <code class="docutils literal notranslate"><span class="pre">-f</span></code> is a
  884. shorthand for <code class="docutils literal notranslate"><span class="pre">-o</span> <span class="pre">FAIL_FAST</span></code> (to parallel the similar option supported by the
  885. <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> CLI). (Contributed by R. David Murray in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11390">bpo-11390</a>.)</p>
  886. <p><a class="reference internal" href="../library/doctest.html#module-doctest" title="doctest: Test pieces of code within docstrings."><code class="xref py py-mod docutils literal notranslate"><span class="pre">doctest</span></code></a> will now find doctests in extension module <code class="docutils literal notranslate"><span class="pre">__doc__</span></code> strings.
  887. (Contributed by Zachary Ware in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=3158">bpo-3158</a>.)</p>
  888. </section>
  889. <section id="email">
  890. <h3>email<a class="headerlink" href="#email" title="Link to this heading">¶</a></h3>
  891. <p><a class="reference internal" href="../library/email.compat32-message.html#email.message.Message.as_string" title="email.message.Message.as_string"><code class="xref py py-meth docutils literal notranslate"><span class="pre">as_string()</span></code></a> now accepts a <em>policy</em> argument to
  892. override the default policy of the message when generating a string
  893. representation of it. This means that <code class="docutils literal notranslate"><span class="pre">as_string</span></code> can now be used in more
  894. circumstances, instead of having to create and use a <a class="reference internal" href="../library/email.generator.html#module-email.generator" title="email.generator: Generate flat text email messages from a message structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">generator</span></code></a> in
  895. order to pass formatting parameters to its <code class="docutils literal notranslate"><span class="pre">flatten</span></code> method. (Contributed by
  896. R. David Murray in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18600">bpo-18600</a>.)</p>
  897. <p>New method <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message.as_bytes" title="email.message.Message.as_bytes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">as_bytes()</span></code></a> added to produce a bytes
  898. representation of the message in a fashion similar to how <code class="docutils literal notranslate"><span class="pre">as_string</span></code>
  899. produces a string representation. It does not accept the <em>maxheaderlen</em>
  900. argument, but does accept the <em>unixfrom</em> and <em>policy</em> arguments. The
  901. <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message.__bytes__" title="email.message.Message.__bytes__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__bytes__()</span></code></a> method
  902. calls it, meaning that <code class="docutils literal notranslate"><span class="pre">bytes(mymsg)</span></code> will now produce the intuitive
  903. result: a bytes object containing the fully formatted message. (Contributed
  904. by R. David Murray in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18600">bpo-18600</a>.)</p>
  905. <p>The <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message.set_param" title="email.message.Message.set_param"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Message.set_param()</span></code></a> message now accepts a <em>replace</em> keyword argument.
  906. When specified, the associated header will be updated without changing
  907. its location in the list of headers. For backward compatibility, the default
  908. is <code class="docutils literal notranslate"><span class="pre">False</span></code>. (Contributed by R. David Murray in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18891">bpo-18891</a>.)</p>
  909. <p id="whatsnew-email-contentmanager">A pair of new subclasses of <a class="reference internal" href="../library/email.compat32-message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> have been added
  910. (<a class="reference internal" href="../library/email.message.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailMessage</span></code></a> and <a class="reference internal" href="../library/email.message.html#email.message.MIMEPart" title="email.message.MIMEPart"><code class="xref py py-class docutils literal notranslate"><span class="pre">MIMEPart</span></code></a>), along with a new sub-module,
  911. <a class="reference internal" href="../library/email.contentmanager.html#module-email.contentmanager" title="email.contentmanager: Storing and Retrieving Content from MIME Parts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">contentmanager</span></code></a> and a new <a class="reference internal" href="../library/email.policy.html#module-email.policy" title="email.policy: Controlling the parsing and generating of messages"><code class="xref py py-mod docutils literal notranslate"><span class="pre">policy</span></code></a> attribute
  912. <a class="reference internal" href="../library/email.policy.html#email.policy.EmailPolicy.content_manager" title="email.policy.EmailPolicy.content_manager"><code class="xref py py-attr docutils literal notranslate"><span class="pre">content_manager</span></code></a>. All documentation is
  913. currently in the new module, which is being added as part of email’s new
  914. <a class="reference internal" href="../glossary.html#term-provisional-API"><span class="xref std std-term">provisional API</span></a>. These classes provide a number of new methods that
  915. make extracting content from and inserting content into email messages much
  916. easier. For details, see the <a class="reference internal" href="../library/email.contentmanager.html#module-email.contentmanager" title="email.contentmanager: Storing and Retrieving Content from MIME Parts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">contentmanager</span></code></a> documentation and
  917. the <a class="reference internal" href="../library/email.examples.html#email-examples"><span class="std std-ref">email: Examples</span></a>. These API additions complete the
  918. bulk of the work that was planned as part of the email6 project. The currently
  919. provisional API is scheduled to become final in Python 3.5 (possibly with a few
  920. minor additions in the area of error handling). (Contributed by R. David
  921. Murray in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18891">bpo-18891</a>.)</p>
  922. </section>
  923. <section id="filecmp">
  924. <h3>filecmp<a class="headerlink" href="#filecmp" title="Link to this heading">¶</a></h3>
  925. <p>A new <a class="reference internal" href="../library/filecmp.html#filecmp.clear_cache" title="filecmp.clear_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">clear_cache()</span></code></a> function provides the ability to clear the
  926. <a class="reference internal" href="../library/filecmp.html#module-filecmp" title="filecmp: Compare files efficiently."><code class="xref py py-mod docutils literal notranslate"><span class="pre">filecmp</span></code></a> comparison cache, which uses <a class="reference internal" href="../library/os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat()</span></code></a> information to
  927. determine if the file has changed since the last compare. This can be used,
  928. for example, if the file might have been changed and re-checked in less time
  929. than the resolution of a particular filesystem’s file modification time field.
  930. (Contributed by Mark Levitt in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18149">bpo-18149</a>.)</p>
  931. <p>New module attribute <a class="reference internal" href="../library/filecmp.html#filecmp.DEFAULT_IGNORES" title="filecmp.DEFAULT_IGNORES"><code class="xref py py-const docutils literal notranslate"><span class="pre">DEFAULT_IGNORES</span></code></a> provides the list of
  932. directories that are used as the default value for the <em>ignore</em> parameter of
  933. the <a class="reference internal" href="../library/filecmp.html#filecmp.dircmp" title="filecmp.dircmp"><code class="xref py py-func docutils literal notranslate"><span class="pre">dircmp()</span></code></a> function. (Contributed by Eli Bendersky in
  934. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15442">bpo-15442</a>.)</p>
  935. </section>
  936. <section id="functools">
  937. <h3>functools<a class="headerlink" href="#functools" title="Link to this heading">¶</a></h3>
  938. <p>The new <a class="reference internal" href="../library/functools.html#functools.partialmethod" title="functools.partialmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">partialmethod()</span></code></a> descriptor brings partial argument
  939. application to descriptors, just as <a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal notranslate"><span class="pre">partial()</span></code></a> provides
  940. for normal callables. The new descriptor also makes it easier to get
  941. arbitrary callables (including <a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal notranslate"><span class="pre">partial()</span></code></a> instances)
  942. to behave like normal instance methods when included in a class definition.
  943. (Contributed by Alon Horev and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4331">bpo-4331</a>.)</p>
  944. <p id="whatsnew-singledispatch">The new <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">singledispatch()</span></code></a> decorator brings support for
  945. single-dispatch generic functions to the Python standard library. Where
  946. object oriented programming focuses on grouping multiple operations on a
  947. common set of data into a class, a generic function focuses on grouping
  948. multiple implementations of an operation that allows it to work with
  949. <em>different</em> kinds of data.</p>
  950. <div class="admonition seealso">
  951. <p class="admonition-title">See also</p>
  952. <dl class="simple">
  953. <dt><span class="target" id="index-36"></span><a class="pep reference external" href="https://peps.python.org/pep-0443/"><strong>PEP 443</strong></a> – Single-dispatch generic functions</dt><dd><p>PEP written and implemented by Łukasz Langa.</p>
  954. </dd>
  955. </dl>
  956. </div>
  957. <p><a class="reference internal" href="../library/functools.html#functools.total_ordering" title="functools.total_ordering"><code class="xref py py-func docutils literal notranslate"><span class="pre">total_ordering()</span></code></a> now supports a return value of
  958. <a class="reference internal" href="../library/constants.html#NotImplemented" title="NotImplemented"><code class="xref py py-data docutils literal notranslate"><span class="pre">NotImplemented</span></code></a> from the underlying comparison function. (Contributed
  959. by Katie Miller in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10042">bpo-10042</a>.)</p>
  960. <p>A pure-python version of the <a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal notranslate"><span class="pre">partial()</span></code></a> function is now in the
  961. stdlib; in CPython it is overridden by the C accelerated version, but it is
  962. available for other implementations to use. (Contributed by Brian Thorne in
  963. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12428">bpo-12428</a>.)</p>
  964. </section>
  965. <section id="gc">
  966. <h3>gc<a class="headerlink" href="#gc" title="Link to this heading">¶</a></h3>
  967. <p>New function <a class="reference internal" href="../library/gc.html#gc.get_stats" title="gc.get_stats"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_stats()</span></code></a> returns a list of three per-generation
  968. dictionaries containing the collections statistics since interpreter startup.
  969. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16351">bpo-16351</a>.)</p>
  970. </section>
  971. <section id="glob">
  972. <h3>glob<a class="headerlink" href="#glob" title="Link to this heading">¶</a></h3>
  973. <p>A new function <a class="reference internal" href="../library/glob.html#glob.escape" title="glob.escape"><code class="xref py py-func docutils literal notranslate"><span class="pre">escape()</span></code></a> provides a way to escape special characters
  974. in a filename so that they do not become part of the globbing expansion but are
  975. instead matched literally. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8402">bpo-8402</a>.)</p>
  976. </section>
  977. <section id="hashlib">
  978. <h3>hashlib<a class="headerlink" href="#hashlib" title="Link to this heading">¶</a></h3>
  979. <p>A new <a class="reference internal" href="../library/hashlib.html#hashlib.pbkdf2_hmac" title="hashlib.pbkdf2_hmac"><code class="xref py py-func docutils literal notranslate"><span class="pre">hashlib.pbkdf2_hmac()</span></code></a> function provides
  980. the <a class="reference external" href="https://en.wikipedia.org/wiki/PBKDF2">PKCS#5 password-based key derivation function 2</a>. (Contributed by Christian
  981. Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18582">bpo-18582</a>.)</p>
  982. <p>The <a class="reference internal" href="../library/hashlib.html#hashlib.hash.name" title="hashlib.hash.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a> attribute of <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> hash objects is now
  983. a formally supported interface. It has always existed in CPython’s
  984. <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> (although it did not return lower case names for all supported
  985. hashes), but it was not a public interface and so some other Python
  986. implementations have not previously supported it. (Contributed by Jason R.
  987. Coombs in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18532">bpo-18532</a>.)</p>
  988. </section>
  989. <section id="hmac">
  990. <h3>hmac<a class="headerlink" href="#hmac" title="Link to this heading">¶</a></h3>
  991. <p><a class="reference internal" href="../library/hmac.html#module-hmac" title="hmac: Keyed-Hashing for Message Authentication (HMAC) implementation"><code class="xref py py-mod docutils literal notranslate"><span class="pre">hmac</span></code></a> now accepts <code class="docutils literal notranslate"><span class="pre">bytearray</span></code> as well as <code class="docutils literal notranslate"><span class="pre">bytes</span></code> for the <em>key</em>
  992. argument to the <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">new()</span></code></a> function, and the <em>msg</em> parameter to both the
  993. <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">new()</span></code></a> function and the <a class="reference internal" href="../library/hmac.html#hmac.HMAC.update" title="hmac.HMAC.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a> method now
  994. accepts any type supported by 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. (Contributed
  995. by Jonas Borgström in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18240">bpo-18240</a>.)</p>
  996. <p>The <em>digestmod</em> argument to the <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">hmac.new()</span></code></a> function may now be any hash
  997. digest name recognized by <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>. In addition, the current behavior in
  998. which the value of <em>digestmod</em> defaults to <code class="docutils literal notranslate"><span class="pre">MD5</span></code> is deprecated: in a
  999. future version of Python there will be no default value. (Contributed by
  1000. Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17276">bpo-17276</a>.)</p>
  1001. <p>With the addition of <a class="reference internal" href="../library/hmac.html#hmac.HMAC.block_size" title="hmac.HMAC.block_size"><code class="xref py py-attr docutils literal notranslate"><span class="pre">block_size</span></code></a> and <a class="reference internal" href="../library/hmac.html#hmac.HMAC.name" title="hmac.HMAC.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">name</span></code></a>
  1002. attributes (and the formal documentation of the <a class="reference internal" href="../library/hmac.html#hmac.HMAC.digest_size" title="hmac.HMAC.digest_size"><code class="xref py py-attr docutils literal notranslate"><span class="pre">digest_size</span></code></a>
  1003. attribute), the <a class="reference internal" href="../library/hmac.html#module-hmac" title="hmac: Keyed-Hashing for Message Authentication (HMAC) implementation"><code class="xref py py-mod docutils literal notranslate"><span class="pre">hmac</span></code></a> module now conforms fully to the <span class="target" id="index-37"></span><a class="pep reference external" href="https://peps.python.org/pep-0247/"><strong>PEP 247</strong></a> API.
  1004. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18775">bpo-18775</a>.)</p>
  1005. </section>
  1006. <section id="html">
  1007. <h3>html<a class="headerlink" href="#html" title="Link to this heading">¶</a></h3>
  1008. <p>New function <a class="reference internal" href="../library/html.html#html.unescape" title="html.unescape"><code class="xref py py-func docutils literal notranslate"><span class="pre">unescape()</span></code></a> function converts HTML5 character references to
  1009. the corresponding Unicode characters. (Contributed by Ezio Melotti in
  1010. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=2927">bpo-2927</a>.)</p>
  1011. <p><a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> accepts a new keyword argument
  1012. <em>convert_charrefs</em> that, when <code class="docutils literal notranslate"><span class="pre">True</span></code>, automatically converts all character
  1013. references. For backward-compatibility, its value defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>, but
  1014. it will change to <code class="docutils literal notranslate"><span class="pre">True</span></code> in a future version of Python, so you are invited to
  1015. set it explicitly and update your code to use this new feature. (Contributed
  1016. by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13633">bpo-13633</a>.)</p>
  1017. <p>The <em>strict</em> argument of <a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> is now deprecated.
  1018. (Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15114">bpo-15114</a>.)</p>
  1019. </section>
  1020. <section id="http">
  1021. <h3>http<a class="headerlink" href="#http" title="Link to this heading">¶</a></h3>
  1022. <p><a class="reference internal" href="../library/http.server.html#http.server.BaseHTTPRequestHandler.send_error" title="http.server.BaseHTTPRequestHandler.send_error"><code class="xref py py-meth docutils literal notranslate"><span class="pre">send_error()</span></code></a> now accepts an
  1023. optional additional <em>explain</em> parameter which can be used to provide an
  1024. extended error description, overriding the hardcoded default if there is one.
  1025. This extended error description will be formatted using the
  1026. <code class="xref py py-attr docutils literal notranslate"><span class="pre">error_message_format</span></code> attribute and sent as the body
  1027. of the error response. (Contributed by Karl Cow in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12921">bpo-12921</a>.)</p>
  1028. <p>The <a class="reference internal" href="../library/http.server.html#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a> <a class="reference internal" href="../library/http.server.html#http-server-cli"><span class="std std-ref">command line interface</span></a> now has
  1029. a <code class="docutils literal notranslate"><span class="pre">-b/--bind</span></code> option that causes the server to listen on a specific address.
  1030. (Contributed by Malte Swart in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17764">bpo-17764</a>.)</p>
  1031. </section>
  1032. <section id="idlelib-and-idle">
  1033. <h3>idlelib and IDLE<a class="headerlink" href="#idlelib-and-idle" title="Link to this heading">¶</a></h3>
  1034. <p>Since idlelib implements the IDLE shell and editor and is not intended for
  1035. import by other programs, it gets improvements with every release. See
  1036. <code class="file docutils literal notranslate"><span class="pre">Lib/idlelib/NEWS.txt</span></code> for a cumulative list of changes since 3.3.0,
  1037. as well as changes made in future 3.4.x releases. This file is also available
  1038. from the IDLE <span class="menuselection">Help ‣ About IDLE</span> dialog.</p>
  1039. </section>
  1040. <section id="importlib">
  1041. <h3>importlib<a class="headerlink" href="#importlib" title="Link to this heading">¶</a></h3>
  1042. <p>The <a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader" title="importlib.abc.InspectLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">InspectLoader</span></code></a> ABC defines a new method,
  1043. <a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader.source_to_code" title="importlib.abc.InspectLoader.source_to_code"><code class="xref py py-meth docutils literal notranslate"><span class="pre">source_to_code()</span></code></a> that accepts source
  1044. data and a path and returns a code object. The default implementation
  1045. is equivalent to <code class="docutils literal notranslate"><span class="pre">compile(data,</span> <span class="pre">path,</span> <span class="pre">'exec',</span> <span class="pre">dont_inherit=True)</span></code>.
  1046. (Contributed by Eric Snow and Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15627">bpo-15627</a>.)</p>
  1047. <p><a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader" title="importlib.abc.InspectLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">InspectLoader</span></code></a> also now has a default implementation
  1048. for the <a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader.get_code" title="importlib.abc.InspectLoader.get_code"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_code()</span></code></a> method. However,
  1049. it will normally be desirable to override the default implementation
  1050. for performance reasons. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18072">bpo-18072</a>.)</p>
  1051. <p>The <a class="reference internal" href="../library/importlib.html#importlib.reload" title="importlib.reload"><code class="xref py py-func docutils literal notranslate"><span class="pre">reload()</span></code></a> function has been moved from <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> to
  1052. <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> as part of the <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> module deprecation. (Contributed by
  1053. Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18193">bpo-18193</a>.)</p>
  1054. <p><a class="reference internal" href="../library/importlib.html#module-importlib.util" title="importlib.util: Utility code for importers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.util</span></code></a> now has a <a class="reference internal" href="../library/importlib.html#importlib.util.MAGIC_NUMBER" title="importlib.util.MAGIC_NUMBER"><code class="xref py py-data docutils literal notranslate"><span class="pre">MAGIC_NUMBER</span></code></a> attribute
  1055. providing access to the bytecode version number. This replaces the
  1056. <code class="xref py py-func docutils literal notranslate"><span class="pre">get_magic()</span></code> function in the deprecated <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> module.
  1057. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18192">bpo-18192</a>.)</p>
  1058. <p>New <a class="reference internal" href="../library/importlib.html#module-importlib.util" title="importlib.util: Utility code for importers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.util</span></code></a> functions <a class="reference internal" href="../library/importlib.html#importlib.util.cache_from_source" title="importlib.util.cache_from_source"><code class="xref py py-func docutils literal notranslate"><span class="pre">cache_from_source()</span></code></a>
  1059. and <a class="reference internal" href="../library/importlib.html#importlib.util.source_from_cache" title="importlib.util.source_from_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">source_from_cache()</span></code></a> replace the same-named functions
  1060. in the deprecated <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> module. (Contributed by Brett Cannon in
  1061. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18194">bpo-18194</a>.)</p>
  1062. <p>The <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> bootstrap <a class="reference internal" href="../library/importlib.html#importlib.machinery.NamespaceLoader" title="importlib.machinery.NamespaceLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">NamespaceLoader</span></code></a> now conforms to
  1063. the <a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader" title="importlib.abc.InspectLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">InspectLoader</span></code></a> ABC, which means that <code class="docutils literal notranslate"><span class="pre">runpy</span></code> and
  1064. <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span></code> can now be used with namespace packages. (Contributed
  1065. by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18058">bpo-18058</a>.)</p>
  1066. <p><a class="reference internal" href="../library/importlib.html#module-importlib.util" title="importlib.util: Utility code for importers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.util</span></code></a> has a new function <a class="reference internal" href="../library/importlib.html#importlib.util.decode_source" title="importlib.util.decode_source"><code class="xref py py-func docutils literal notranslate"><span class="pre">decode_source()</span></code></a>
  1067. that decodes source from bytes using universal newline processing. This is
  1068. useful for implementing <a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader.get_source" title="importlib.abc.InspectLoader.get_source"><code class="xref py py-meth docutils literal notranslate"><span class="pre">InspectLoader.get_source()</span></code></a> methods.</p>
  1069. <p><a class="reference internal" href="../library/importlib.html#importlib.machinery.ExtensionFileLoader" title="importlib.machinery.ExtensionFileLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.ExtensionFileLoader</span></code></a> now has a
  1070. <a class="reference internal" href="../library/importlib.html#importlib.machinery.ExtensionFileLoader.get_filename" title="importlib.machinery.ExtensionFileLoader.get_filename"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_filename()</span></code></a> method. This was
  1071. inadvertently omitted in the original implementation. (Contributed by Eric
  1072. Snow in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19152">bpo-19152</a>.)</p>
  1073. </section>
  1074. <section id="inspect">
  1075. <h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading">¶</a></h3>
  1076. <p>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 now offers a basic <a class="reference internal" href="../library/inspect.html#inspect-module-cli"><span class="std std-ref">command line interface</span></a> to quickly display source code and other
  1077. information for modules, classes and functions. (Contributed by Claudiu Popa
  1078. and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18626">bpo-18626</a>.)</p>
  1079. <p><a class="reference internal" href="../library/inspect.html#inspect.unwrap" title="inspect.unwrap"><code class="xref py py-func docutils literal notranslate"><span class="pre">unwrap()</span></code></a> makes it easy to unravel wrapper function chains
  1080. created by <a class="reference internal" href="../library/functools.html#functools.wraps" title="functools.wraps"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.wraps()</span></code></a> (and any other API that sets the
  1081. <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute on a wrapper function). (Contributed by
  1082. Daniel Urban, Aaron Iles and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13266">bpo-13266</a>.)</p>
  1083. <p>As part of the implementation of the new <a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a> module, the
  1084. <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 now has substantially better support for custom
  1085. <code class="docutils literal notranslate"><span class="pre">__dir__</span></code> methods and dynamic class attributes provided through
  1086. metaclasses. (Contributed by Ethan Furman in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18929">bpo-18929</a> and
  1087. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19030">bpo-19030</a>.)</p>
  1088. <p><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">getfullargspec()</span></code></a> and <code class="xref py py-func docutils literal notranslate"><span class="pre">getargspec()</span></code>
  1089. now 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">signature()</span></code></a> API. This allows them to
  1090. support a much broader range of callables, including those with
  1091. <code class="docutils literal notranslate"><span class="pre">__signature__</span></code> attributes, those with metadata provided by argument
  1092. clinic, <a class="reference internal" href="../library/functools.html#functools.partial" title="functools.partial"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.partial()</span></code></a> objects and more. Note that, unlike
  1093. <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">signature()</span></code></a>, these functions still ignore <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code>
  1094. attributes, and report the already bound first argument for bound methods,
  1095. so it is still necessary to update your code to use
  1096. <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">signature()</span></code></a> directly if those features are desired.
  1097. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17481">bpo-17481</a>.)</p>
  1098. <p><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">signature()</span></code></a> now supports duck types of CPython functions,
  1099. which adds support for functions compiled with Cython. (Contributed
  1100. by Stefan Behnel and Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17159">bpo-17159</a>.)</p>
  1101. </section>
  1102. <section id="ipaddress">
  1103. <h3>ipaddress<a class="headerlink" href="#ipaddress" title="Link to this heading">¶</a></h3>
  1104. <p><a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ipaddress</span></code></a> was added to the standard library in Python 3.3 as a
  1105. <a class="reference internal" href="../glossary.html#term-provisional-API"><span class="xref std std-term">provisional API</span></a>. With the release of Python 3.4, this qualification
  1106. has been removed: <a class="reference internal" href="../library/ipaddress.html#module-ipaddress" title="ipaddress: IPv4/IPv6 manipulation library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ipaddress</span></code></a> is now considered a stable API, covered
  1107. by the normal standard library requirements to maintain backwards
  1108. compatibility.</p>
  1109. <p>A new <a class="reference internal" href="../library/ipaddress.html#ipaddress.IPv4Address.is_global" title="ipaddress.IPv4Address.is_global"><code class="xref py py-attr docutils literal notranslate"><span class="pre">is_global</span></code></a> property is <code class="docutils literal notranslate"><span class="pre">True</span></code> if
  1110. an address is globally routeable. (Contributed by Peter Moody in
  1111. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17400">bpo-17400</a>.)</p>
  1112. </section>
  1113. <section id="logging">
  1114. <h3>logging<a class="headerlink" href="#logging" title="Link to this heading">¶</a></h3>
  1115. <p>The <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.TimedRotatingFileHandler" title="logging.handlers.TimedRotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">TimedRotatingFileHandler</span></code></a> has a new <em>atTime</em>
  1116. parameter that can be used to specify the time of day when rollover should
  1117. happen. (Contributed by Ronald Oussoren in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9556">bpo-9556</a>.)</p>
  1118. <p><a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SocketHandler" title="logging.handlers.SocketHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SocketHandler</span></code></a> and
  1119. <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.DatagramHandler" title="logging.handlers.DatagramHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">DatagramHandler</span></code></a> now support Unix domain sockets (by
  1120. setting <em>port</em> to <code class="docutils literal notranslate"><span class="pre">None</span></code>). (Contributed by Vinay Sajip in commit
  1121. ce46195b56a9.)</p>
  1122. <p><a class="reference internal" href="../library/logging.config.html#logging.config.fileConfig" title="logging.config.fileConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">fileConfig()</span></code></a> now accepts a
  1123. <a class="reference internal" href="../library/configparser.html#configparser.RawConfigParser" title="configparser.RawConfigParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">configparser.RawConfigParser</span></code></a> subclass instance for the <em>fname</em>
  1124. parameter. This facilitates using a configuration file when logging
  1125. configuration is just a part of the overall application configuration, or where
  1126. the application modifies the configuration before passing it to
  1127. <a class="reference internal" href="../library/logging.config.html#logging.config.fileConfig" title="logging.config.fileConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">fileConfig()</span></code></a>. (Contributed by Vinay Sajip in
  1128. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16110">bpo-16110</a>.)</p>
  1129. <p>Logging configuration data received from a socket via the
  1130. <a class="reference internal" href="../library/logging.config.html#logging.config.listen" title="logging.config.listen"><code class="xref py py-func docutils literal notranslate"><span class="pre">logging.config.listen()</span></code></a> function can now be validated before being
  1131. processed by supplying a verification function as the argument to the new
  1132. <em>verify</em> keyword argument. (Contributed by Vinay Sajip in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15452">bpo-15452</a>.)</p>
  1133. </section>
  1134. <section id="marshal">
  1135. <span id="whatsnew-marshal-3"></span><h3>marshal<a class="headerlink" href="#marshal" title="Link to this heading">¶</a></h3>
  1136. <p>The default <a class="reference internal" href="../library/marshal.html#module-marshal" title="marshal: Convert Python objects to streams of bytes and back (with different constraints)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">marshal</span></code></a> version has been bumped to 3. The code implementing
  1137. the new version restores the Python2 behavior of recording only one copy of
  1138. interned strings and preserving the interning on deserialization, and extends
  1139. this “one copy” ability to any object type (including handling recursive
  1140. references). This reduces both the size of <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files and the amount of
  1141. memory a module occupies in memory when it is loaded from a <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> (or
  1142. <code class="docutils literal notranslate"><span class="pre">.pyo</span></code>) file. (Contributed by Kristján Valur Jónsson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16475">bpo-16475</a>,
  1143. with additional speedups by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19219">bpo-19219</a>.)</p>
  1144. </section>
  1145. <section id="mmap">
  1146. <h3>mmap<a class="headerlink" href="#mmap" title="Link to this heading">¶</a></h3>
  1147. <p>mmap objects are now <a class="reference internal" href="../library/weakref.html#mod-weakref"><span class="std std-ref">weakly referenceable</span></a>.
  1148. (Contributed by Valerie Lambert in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4885">bpo-4885</a>.)</p>
  1149. </section>
  1150. <section id="multiprocessing">
  1151. <h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Link to this heading">¶</a></h3>
  1152. <p id="whatsnew-multiprocessing-no-fork">On Unix two new <a class="reference internal" href="../library/multiprocessing.html#multiprocessing-start-methods"><span class="std std-ref">start methods</span></a>,
  1153. <code class="docutils literal notranslate"><span class="pre">spawn</span></code> and <code class="docutils literal notranslate"><span class="pre">forkserver</span></code>, have been added for starting processes using
  1154. <a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a>. These make the mixing of processes with threads more
  1155. robust, and the <code class="docutils literal notranslate"><span class="pre">spawn</span></code> method matches the semantics that multiprocessing has
  1156. always used on Windows. New function
  1157. <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.get_all_start_methods" title="multiprocessing.get_all_start_methods"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_all_start_methods()</span></code></a> reports all start methods
  1158. available on the platform, <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.get_start_method" title="multiprocessing.get_start_method"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_start_method()</span></code></a> reports
  1159. the current start method, and <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.set_start_method" title="multiprocessing.set_start_method"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_start_method()</span></code></a> sets
  1160. the start method. (Contributed by Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8713">bpo-8713</a>.)</p>
  1161. <p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> also now has the concept of a <code class="docutils literal notranslate"><span class="pre">context</span></code>, which
  1162. determines how child processes are created. New function
  1163. <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.get_context" title="multiprocessing.get_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_context()</span></code></a> returns a context that uses a specified
  1164. start method. It has the same API as the <a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> module itself,
  1165. so you can use it to create <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.pool.Pool" title="multiprocessing.pool.Pool"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pool</span></code></a>s and other
  1166. objects that will operate within that context. This allows a framework and an
  1167. application or different parts of the same application to use multiprocessing
  1168. without interfering with each other. (Contributed by Richard Oudkerk in
  1169. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18999">bpo-18999</a>.)</p>
  1170. <p>Except when using the old <em>fork</em> start method, child processes no longer
  1171. inherit unneeded handles/file descriptors from their parents (part of
  1172. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8713">bpo-8713</a>).</p>
  1173. <p><a class="reference internal" href="../library/multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> now relies on <a class="reference internal" href="../library/runpy.html#module-runpy" title="runpy: Locate and run Python modules without importing them first."><code class="xref py py-mod docutils literal notranslate"><span class="pre">runpy</span></code></a> (which implements the
  1174. <code class="docutils literal notranslate"><span class="pre">-m</span></code> switch) to initialise <code class="docutils literal notranslate"><span class="pre">__main__</span></code> appropriately in child processes
  1175. when using the <code class="docutils literal notranslate"><span class="pre">spawn</span></code> or <code class="docutils literal notranslate"><span class="pre">forkserver</span></code> start methods. This resolves some
  1176. edge cases where combining multiprocessing, the <code class="docutils literal notranslate"><span class="pre">-m</span></code> command line switch,
  1177. and explicit relative imports could cause obscure failures in child
  1178. processes. (Contributed by Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19946">bpo-19946</a>.)</p>
  1179. </section>
  1180. <section id="operator">
  1181. <h3>operator<a class="headerlink" href="#operator" title="Link to this heading">¶</a></h3>
  1182. <p>New function <a class="reference internal" href="../library/operator.html#operator.length_hint" title="operator.length_hint"><code class="xref py py-func docutils literal notranslate"><span class="pre">length_hint()</span></code></a> provides an implementation of the
  1183. specification for how the <a class="reference internal" href="../reference/datamodel.html#object.__length_hint__" title="object.__length_hint__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__length_hint__()</span></code></a> special method should
  1184. be used, as part of the <span class="target" id="index-38"></span><a class="pep reference external" href="https://peps.python.org/pep-0424/"><strong>PEP 424</strong></a> formal specification of this language
  1185. feature. (Contributed by Armin Ronacher in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16148">bpo-16148</a>.)</p>
  1186. <p>There is now a pure-python version of the <a class="reference internal" href="../library/operator.html#module-operator" title="operator: Functions corresponding to the standard operators."><code class="xref py py-mod docutils literal notranslate"><span class="pre">operator</span></code></a> module available for
  1187. reference and for use by alternate implementations of Python. (Contributed by
  1188. Zachary Ware in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16694">bpo-16694</a>.)</p>
  1189. </section>
  1190. <section id="os">
  1191. <h3>os<a class="headerlink" href="#os" title="Link to this heading">¶</a></h3>
  1192. <p>There are new functions to get and set the <a class="reference internal" href="../library/os.html#fd-inheritance"><span class="std std-ref">inheritable flag</span></a> of a file descriptor (<a class="reference internal" href="../library/os.html#os.get_inheritable" title="os.get_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.get_inheritable()</span></code></a>,
  1193. <a class="reference internal" href="../library/os.html#os.set_inheritable" title="os.set_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.set_inheritable()</span></code></a>) or a Windows handle
  1194. (<a class="reference internal" href="../library/os.html#os.get_handle_inheritable" title="os.get_handle_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.get_handle_inheritable()</span></code></a>, <a class="reference internal" href="../library/os.html#os.set_handle_inheritable" title="os.set_handle_inheritable"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.set_handle_inheritable()</span></code></a>).</p>
  1195. <p>New function <a class="reference internal" href="../library/os.html#os.cpu_count" title="os.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">cpu_count()</span></code></a> reports the number of CPUs available on the
  1196. platform on which Python is running (or <code class="docutils literal notranslate"><span class="pre">None</span></code> if the count can’t be
  1197. determined). The <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.cpu_count" title="multiprocessing.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">multiprocessing.cpu_count()</span></code></a> function is now implemented
  1198. in terms of this function). (Contributed by Trent Nelson, Yogesh Chaudhari,
  1199. Victor Stinner, and Charles-François Natali in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17914">bpo-17914</a>.)</p>
  1200. <p><a class="reference internal" href="../library/os.path.html#os.path.samestat" title="os.path.samestat"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.samestat()</span></code></a> is now available on the Windows platform (and the
  1201. <a class="reference internal" href="../library/os.path.html#os.path.samefile" title="os.path.samefile"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.samefile()</span></code></a> implementation is now shared between Unix and
  1202. Windows). (Contributed by Brian Curtin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11939">bpo-11939</a>.)</p>
  1203. <p><a class="reference internal" href="../library/os.path.html#os.path.ismount" title="os.path.ismount"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.path.ismount()</span></code></a> now recognizes volumes mounted below a drive
  1204. root on Windows. (Contributed by Tim Golden in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9035">bpo-9035</a>.)</p>
  1205. <p><a class="reference internal" href="../library/os.html#os.open" title="os.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.open()</span></code></a> supports two new flags on platforms that provide them,
  1206. <a class="reference internal" href="../library/os.html#os.O_PATH" title="os.O_PATH"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_PATH</span></code></a> (un-opened file descriptor), and <a class="reference internal" href="../library/os.html#os.O_TMPFILE" title="os.O_TMPFILE"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_TMPFILE</span></code></a>
  1207. (unnamed temporary file; as of 3.4.0 release available only on Linux systems
  1208. with a kernel version of 3.11 or newer that have uapi headers). (Contributed
  1209. by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18673">bpo-18673</a> and Benjamin Peterson, respectively.)</p>
  1210. </section>
  1211. <section id="pdb">
  1212. <h3>pdb<a class="headerlink" href="#pdb" title="Link to this heading">¶</a></h3>
  1213. <p><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> has been enhanced to handle generators, <a class="reference internal" href="../reference/simple_stmts.html#yield"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">yield</span></code></a>, and
  1214. <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> in a more useful fashion. This is especially helpful when
  1215. debugging <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> based programs. (Contributed by Andrew Svetlov and
  1216. Xavier de Gaye in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16596">bpo-16596</a>.)</p>
  1217. <p>The <code class="docutils literal notranslate"><span class="pre">print</span></code> command has been removed from <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>, restoring access to the
  1218. Python <a class="reference internal" href="../library/functions.html#print" title="print"><code class="xref py py-func docutils literal notranslate"><span class="pre">print()</span></code></a> function from the pdb command line. Python2’s <code class="docutils literal notranslate"><span class="pre">pdb</span></code> did
  1219. not have a <code class="docutils literal notranslate"><span class="pre">print</span></code> command; instead, entering <code class="docutils literal notranslate"><span class="pre">print</span></code> executed the
  1220. <code class="docutils literal notranslate"><span class="pre">print</span></code> statement. In Python3 <code class="docutils literal notranslate"><span class="pre">print</span></code> was mistakenly made an alias for the
  1221. pdb <a class="reference internal" href="../library/pdb.html#pdbcommand-p"><code class="xref std std-pdbcmd docutils literal notranslate"><span class="pre">p</span></code></a> command. <code class="docutils literal notranslate"><span class="pre">p</span></code>, however, prints the <code class="docutils literal notranslate"><span class="pre">repr</span></code> of its argument,
  1222. not the <code class="docutils literal notranslate"><span class="pre">str</span></code> like the Python2 <code class="docutils literal notranslate"><span class="pre">print</span></code> command did. Worse, the Python3
  1223. <code class="docutils literal notranslate"><span class="pre">pdb</span> <span class="pre">print</span></code> command shadowed the Python3 <code class="docutils literal notranslate"><span class="pre">print</span></code> function, making it
  1224. inaccessible at the <code class="docutils literal notranslate"><span class="pre">pdb</span></code> prompt. (Contributed by Connor Osborn in
  1225. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18764">bpo-18764</a>.)</p>
  1226. </section>
  1227. <section id="pickle">
  1228. <span id="whatsnew-protocol-4"></span><h3>pickle<a class="headerlink" href="#pickle" title="Link to this heading">¶</a></h3>
  1229. <p><a class="reference internal" href="../library/pickle.html#module-pickle" title="pickle: Convert Python objects to streams of bytes and back."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickle</span></code></a> now supports (but does not use by default) a new pickle protocol,
  1230. protocol 4. This new protocol addresses a number of issues that were present
  1231. in previous protocols, such as the serialization of nested classes, very large
  1232. strings and containers, and classes whose <code class="xref py py-meth docutils literal notranslate"><span class="pre">__new__()</span></code> method takes
  1233. keyword-only arguments. It also provides some efficiency improvements.</p>
  1234. <div class="admonition seealso">
  1235. <p class="admonition-title">See also</p>
  1236. <dl class="simple">
  1237. <dt><span class="target" id="index-39"></span><a class="pep reference external" href="https://peps.python.org/pep-3154/"><strong>PEP 3154</strong></a> – Pickle protocol 4</dt><dd><p>PEP written by Antoine Pitrou and implemented by Alexandre Vassalotti.</p>
  1238. </dd>
  1239. </dl>
  1240. </div>
  1241. </section>
  1242. <section id="plistlib">
  1243. <h3>plistlib<a class="headerlink" href="#plistlib" title="Link to this heading">¶</a></h3>
  1244. <p><a class="reference internal" href="../library/plistlib.html#module-plistlib" title="plistlib: Generate and parse Apple plist files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code></a> now has an API that is similar to the standard pattern for
  1245. stdlib serialization protocols, with new <a class="reference internal" href="../library/plistlib.html#plistlib.load" title="plistlib.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">load()</span></code></a>,
  1246. <a class="reference internal" href="../library/plistlib.html#plistlib.dump" title="plistlib.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump()</span></code></a>, <a class="reference internal" href="../library/plistlib.html#plistlib.loads" title="plistlib.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">loads()</span></code></a>, and <a class="reference internal" href="../library/plistlib.html#plistlib.dumps" title="plistlib.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">dumps()</span></code></a>
  1247. functions. (The older API is now deprecated.) In addition to the already
  1248. supported XML plist format (<a class="reference internal" href="../library/plistlib.html#plistlib.FMT_XML" title="plistlib.FMT_XML"><code class="xref py py-const docutils literal notranslate"><span class="pre">FMT_XML</span></code></a>), it also now supports
  1249. the binary plist format (<a class="reference internal" href="../library/plistlib.html#plistlib.FMT_BINARY" title="plistlib.FMT_BINARY"><code class="xref py py-const docutils literal notranslate"><span class="pre">FMT_BINARY</span></code></a>). (Contributed by Ronald
  1250. Oussoren and others in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14455">bpo-14455</a>.)</p>
  1251. </section>
  1252. <section id="poplib">
  1253. <h3>poplib<a class="headerlink" href="#poplib" title="Link to this heading">¶</a></h3>
  1254. <p>Two new methods have been added to <a class="reference internal" href="../library/poplib.html#module-poplib" title="poplib: POP3 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code></a>: <a class="reference internal" href="../library/poplib.html#poplib.POP3.capa" title="poplib.POP3.capa"><code class="xref py py-meth docutils literal notranslate"><span class="pre">capa()</span></code></a>,
  1255. which returns the list of capabilities advertised by the POP server, and
  1256. <a class="reference internal" href="../library/poplib.html#poplib.POP3.stls" title="poplib.POP3.stls"><code class="xref py py-meth docutils literal notranslate"><span class="pre">stls()</span></code></a>, which switches a clear-text POP3 session into an
  1257. encrypted POP3 session if the POP server supports it. (Contributed by Lorenzo
  1258. Catucci in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4473">bpo-4473</a>.)</p>
  1259. </section>
  1260. <section id="pprint">
  1261. <h3>pprint<a class="headerlink" href="#pprint" title="Link to this heading">¶</a></h3>
  1262. <p>The <a class="reference internal" href="../library/pprint.html#module-pprint" title="pprint: Data pretty printer."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pprint</span></code></a> module’s <a class="reference internal" href="../library/pprint.html#pprint.PrettyPrinter" title="pprint.PrettyPrinter"><code class="xref py py-class docutils literal notranslate"><span class="pre">PrettyPrinter</span></code></a> class and its
  1263. <a class="reference internal" href="../library/pprint.html#pprint.pformat" title="pprint.pformat"><code class="xref py py-func docutils literal notranslate"><span class="pre">pformat()</span></code></a>, and <a class="reference internal" href="../library/pprint.html#pprint.pprint" title="pprint.pprint"><code class="xref py py-func docutils literal notranslate"><span class="pre">pprint()</span></code></a> functions have a new
  1264. option, <em>compact</em>, that controls how the output is formatted. Currently
  1265. setting <em>compact</em> to <code class="docutils literal notranslate"><span class="pre">True</span></code> means that sequences will be printed with as many
  1266. sequence elements as will fit within <em>width</em> on each (indented) line.
  1267. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19132">bpo-19132</a>.)</p>
  1268. <p>Long strings are now wrapped using Python’s normal line continuation
  1269. syntax. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17150">bpo-17150</a>.)</p>
  1270. </section>
  1271. <section id="pty">
  1272. <h3>pty<a class="headerlink" href="#pty" title="Link to this heading">¶</a></h3>
  1273. <p><a class="reference internal" href="../library/pty.html#pty.spawn" title="pty.spawn"><code class="xref py py-func docutils literal notranslate"><span class="pre">pty.spawn()</span></code></a> now returns the status value from <a class="reference internal" href="../library/os.html#os.waitpid" title="os.waitpid"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.waitpid()</span></code></a> on
  1274. the child process, instead of <code class="docutils literal notranslate"><span class="pre">None</span></code>. (Contributed by Gregory P. Smith.)</p>
  1275. </section>
  1276. <section id="pydoc">
  1277. <h3>pydoc<a class="headerlink" href="#pydoc" title="Link to this heading">¶</a></h3>
  1278. <p>The <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> module is now based directly on 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>
  1279. introspection API, allowing it to provide signature information for a wider
  1280. variety of callable objects. This change also means that <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code>
  1281. attributes are now taken into account when displaying help information.
  1282. (Contributed by Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19674">bpo-19674</a>.)</p>
  1283. <p>The <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> module no longer displays the <code class="docutils literal notranslate"><span class="pre">self</span></code> parameter for
  1284. already bound methods. Instead, it aims to always display the exact current
  1285. signature of the supplied callable. (Contributed by Larry Hastings in
  1286. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20710">bpo-20710</a>.)</p>
  1287. <p>In addition to the changes that have been made to <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> directly,
  1288. its handling of custom <code class="docutils literal notranslate"><span class="pre">__dir__</span></code> methods and various descriptor
  1289. behaviours has also been improved substantially by the underlying changes in
  1290. 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>
  1291. <p>As the <a class="reference internal" href="../library/functions.html#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a> builtin is based on <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a>, the above changes also
  1292. affect the behaviour of <a class="reference internal" href="../library/functions.html#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a>.</p>
  1293. </section>
  1294. <section id="re">
  1295. <h3>re<a class="headerlink" href="#re" title="Link to this heading">¶</a></h3>
  1296. <p>New <a class="reference internal" href="../library/re.html#re.fullmatch" title="re.fullmatch"><code class="xref py py-func docutils literal notranslate"><span class="pre">fullmatch()</span></code></a> function and <code class="xref py py-meth docutils literal notranslate"><span class="pre">regex.fullmatch()</span></code> method anchor
  1297. the pattern at both ends of the string to match. This provides a way to be
  1298. explicit about the goal of the match, which avoids a class of subtle bugs where
  1299. <code class="docutils literal notranslate"><span class="pre">$</span></code> characters get lost during code changes or the addition of alternatives
  1300. to an existing regular expression. (Contributed by Matthew Barnett in
  1301. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16203">bpo-16203</a>.)</p>
  1302. <p>The repr of <a class="reference internal" href="../library/re.html#re-objects"><span class="std std-ref">regex objects</span></a> now includes the pattern
  1303. and the flags; the repr of <a class="reference internal" href="../library/re.html#match-objects"><span class="std std-ref">match objects</span></a> now
  1304. includes the start, end, and the part of the string that matched. (Contributed
  1305. by Hugo Lopes Tavares and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13592">bpo-13592</a> and
  1306. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17087">bpo-17087</a>.)</p>
  1307. </section>
  1308. <section id="resource">
  1309. <h3>resource<a class="headerlink" href="#resource" title="Link to this heading">¶</a></h3>
  1310. <p>New <a class="reference internal" href="../library/resource.html#resource.prlimit" title="resource.prlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">prlimit()</span></code></a> function, available on Linux platforms with a
  1311. kernel version of 2.6.36 or later and glibc of 2.13 or later, provides the
  1312. ability to query or set the resource limits for processes other than the one
  1313. making the call. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16595">bpo-16595</a>.)</p>
  1314. <p>On Linux kernel version 2.6.36 or later, there are also some new
  1315. Linux specific constants: <a class="reference internal" href="../library/resource.html#resource.RLIMIT_MSGQUEUE" title="resource.RLIMIT_MSGQUEUE"><code class="xref py py-const docutils literal notranslate"><span class="pre">RLIMIT_MSGQUEUE</span></code></a>,
  1316. <a class="reference internal" href="../library/resource.html#resource.RLIMIT_NICE" title="resource.RLIMIT_NICE"><code class="xref py py-const docutils literal notranslate"><span class="pre">RLIMIT_NICE</span></code></a>, <a class="reference internal" href="../library/resource.html#resource.RLIMIT_RTPRIO" title="resource.RLIMIT_RTPRIO"><code class="xref py py-const docutils literal notranslate"><span class="pre">RLIMIT_RTPRIO</span></code></a>,
  1317. <a class="reference internal" href="../library/resource.html#resource.RLIMIT_RTTIME" title="resource.RLIMIT_RTTIME"><code class="xref py py-const docutils literal notranslate"><span class="pre">RLIMIT_RTTIME</span></code></a>, and <a class="reference internal" href="../library/resource.html#resource.RLIMIT_SIGPENDING" title="resource.RLIMIT_SIGPENDING"><code class="xref py py-const docutils literal notranslate"><span class="pre">RLIMIT_SIGPENDING</span></code></a>.
  1318. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19324">bpo-19324</a>.)</p>
  1319. <p>On FreeBSD version 9 and later, there some new FreeBSD specific constants:
  1320. <a class="reference internal" href="../library/resource.html#resource.RLIMIT_SBSIZE" title="resource.RLIMIT_SBSIZE"><code class="xref py py-const docutils literal notranslate"><span class="pre">RLIMIT_SBSIZE</span></code></a>, <a class="reference internal" href="../library/resource.html#resource.RLIMIT_SWAP" title="resource.RLIMIT_SWAP"><code class="xref py py-const docutils literal notranslate"><span class="pre">RLIMIT_SWAP</span></code></a>, and
  1321. <a class="reference internal" href="../library/resource.html#resource.RLIMIT_NPTS" title="resource.RLIMIT_NPTS"><code class="xref py py-const docutils literal notranslate"><span class="pre">RLIMIT_NPTS</span></code></a>. (Contributed by Claudiu Popa in
  1322. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19343">bpo-19343</a>.)</p>
  1323. </section>
  1324. <section id="select">
  1325. <h3>select<a class="headerlink" href="#select" title="Link to this heading">¶</a></h3>
  1326. <p><a class="reference internal" href="../library/select.html#select.epoll" title="select.epoll"><code class="xref py py-class docutils literal notranslate"><span class="pre">epoll</span></code></a> objects now support the context management protocol.
  1327. When used in a <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> statement, the <a class="reference internal" href="../library/select.html#select.epoll.close" title="select.epoll.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a>
  1328. method will be called automatically at the end of the block. (Contributed
  1329. by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16488">bpo-16488</a>.)</p>
  1330. <p><a class="reference internal" href="../library/select.html#select.devpoll" title="select.devpoll"><code class="xref py py-class docutils literal notranslate"><span class="pre">devpoll</span></code></a> objects now have <a class="reference internal" href="../library/select.html#select.devpoll.fileno" title="select.devpoll.fileno"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fileno()</span></code></a> and
  1331. <a class="reference internal" href="../library/select.html#select.devpoll.close" title="select.devpoll.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> methods, as well as a new attribute
  1332. <a class="reference internal" href="../library/select.html#select.devpoll.closed" title="select.devpoll.closed"><code class="xref py py-attr docutils literal notranslate"><span class="pre">closed</span></code></a>. (Contributed by Victor Stinner in
  1333. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18794">bpo-18794</a>.)</p>
  1334. </section>
  1335. <section id="shelve">
  1336. <h3>shelve<a class="headerlink" href="#shelve" title="Link to this heading">¶</a></h3>
  1337. <p><a class="reference internal" href="../library/shelve.html#shelve.Shelf" title="shelve.Shelf"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shelf</span></code></a> instances may now be used in <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,
  1338. and will be automatically closed at the end of the <code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code> block.
  1339. (Contributed by Filip Gruszczyński in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13896">bpo-13896</a>.)</p>
  1340. </section>
  1341. <section id="shutil">
  1342. <h3>shutil<a class="headerlink" href="#shutil" title="Link to this heading">¶</a></h3>
  1343. <p><a class="reference internal" href="../library/shutil.html#shutil.copyfile" title="shutil.copyfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">copyfile()</span></code></a> now raises a specific <a class="reference internal" href="../library/shutil.html#shutil.Error" title="shutil.Error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Error</span></code></a> subclass,
  1344. <a class="reference internal" href="../library/shutil.html#shutil.SameFileError" title="shutil.SameFileError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SameFileError</span></code></a>, when the source and destination are the same
  1345. file, which allows an application to take appropriate action on this specific
  1346. error. (Contributed by Atsuo Ishimoto and Hynek Schlawack in
  1347. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1492704">bpo-1492704</a>.)</p>
  1348. </section>
  1349. <section id="smtpd">
  1350. <h3>smtpd<a class="headerlink" href="#smtpd" title="Link to this heading">¶</a></h3>
  1351. <p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPServer</span></code> and <code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPChannel</span></code> classes now
  1352. accept a <em>map</em> keyword argument which, if specified, is passed in to
  1353. <code class="xref py py-class docutils literal notranslate"><span class="pre">asynchat.async_chat</span></code> as its <em>map</em> argument. This allows an application
  1354. to avoid affecting the global socket map. (Contributed by Vinay Sajip in
  1355. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11959">bpo-11959</a>.)</p>
  1356. </section>
  1357. <section id="smtplib">
  1358. <h3>smtplib<a class="headerlink" href="#smtplib" title="Link to this heading">¶</a></h3>
  1359. <p><a class="reference internal" href="../library/smtplib.html#smtplib.SMTPException" title="smtplib.SMTPException"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SMTPException</span></code></a> is now a subclass of <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>, which allows
  1360. both socket level errors and SMTP protocol level errors to be caught in one
  1361. try/except statement by code that only cares whether or not an error occurred.
  1362. (Contributed by Ned Jackson Lovely in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=2118">bpo-2118</a>.)</p>
  1363. </section>
  1364. <section id="socket">
  1365. <h3>socket<a class="headerlink" href="#socket" title="Link to this heading">¶</a></h3>
  1366. <p>The socket module now supports the <a class="reference internal" href="../library/socket.html#socket.CAN_BCM" title="socket.CAN_BCM"><code class="xref py py-const docutils literal notranslate"><span class="pre">CAN_BCM</span></code></a> protocol on
  1367. platforms that support it. (Contributed by Brian Thorne in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15359">bpo-15359</a>.)</p>
  1368. <p>Socket objects have new methods to get or set their <a class="reference internal" href="../library/os.html#fd-inheritance"><span class="std std-ref">inheritable flag</span></a>, <a class="reference internal" href="../library/socket.html#socket.socket.get_inheritable" title="socket.socket.get_inheritable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_inheritable()</span></code></a> and
  1369. <a class="reference internal" href="../library/socket.html#socket.socket.set_inheritable" title="socket.socket.set_inheritable"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_inheritable()</span></code></a>.</p>
  1370. <p>The <code class="docutils literal notranslate"><span class="pre">socket.AF_*</span></code> and <code class="docutils literal notranslate"><span class="pre">socket.SOCK_*</span></code> constants are now enumeration values
  1371. using the new <a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a> module. This allows meaningful names to be printed
  1372. during debugging, instead of integer “magic numbers”.</p>
  1373. <p>The <a class="reference internal" href="../library/socket.html#socket.AF_LINK" title="socket.AF_LINK"><code class="xref py py-const docutils literal notranslate"><span class="pre">AF_LINK</span></code></a> constant is now available on BSD and OSX.</p>
  1374. <p><a class="reference internal" href="../library/socket.html#socket.inet_pton" title="socket.inet_pton"><code class="xref py py-func docutils literal notranslate"><span class="pre">inet_pton()</span></code></a> and <a class="reference internal" href="../library/socket.html#socket.inet_ntop" title="socket.inet_ntop"><code class="xref py py-func docutils literal notranslate"><span class="pre">inet_ntop()</span></code></a> are now supported
  1375. on Windows. (Contributed by Atsuo Ishimoto in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=7171">bpo-7171</a>.)</p>
  1376. </section>
  1377. <section id="sqlite3">
  1378. <h3>sqlite3<a class="headerlink" href="#sqlite3" title="Link to this heading">¶</a></h3>
  1379. <p>A new boolean parameter to the <a class="reference internal" href="../library/sqlite3.html#sqlite3.connect" title="sqlite3.connect"><code class="xref py py-func docutils literal notranslate"><span class="pre">connect()</span></code></a> function, <em>uri</em>, can be
  1380. used to indicate that the <em>database</em> parameter is a <code class="docutils literal notranslate"><span class="pre">uri</span></code> (see the <a class="reference external" href="https://www.sqlite.org/uri.html">SQLite
  1381. URI documentation</a>). (Contributed by poq in
  1382. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13773">bpo-13773</a>.)</p>
  1383. </section>
  1384. <section id="ssl">
  1385. <h3>ssl<a class="headerlink" href="#ssl" title="Link to this heading">¶</a></h3>
  1386. <p id="whatsnew-tls-11-12"><a class="reference internal" href="../library/ssl.html#ssl.PROTOCOL_TLSv1_1" title="ssl.PROTOCOL_TLSv1_1"><code class="xref py py-data docutils literal notranslate"><span class="pre">PROTOCOL_TLSv1_1</span></code></a> and <a class="reference internal" href="../library/ssl.html#ssl.PROTOCOL_TLSv1_2" title="ssl.PROTOCOL_TLSv1_2"><code class="xref py py-data docutils literal notranslate"><span class="pre">PROTOCOL_TLSv1_2</span></code></a> (TLSv1.1 and
  1387. TLSv1.2 support) have been added; support for these protocols is only available if
  1388. Python is linked with OpenSSL 1.0.1 or later. (Contributed by Michele Orrù and
  1389. Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16692">bpo-16692</a>.)</p>
  1390. <p id="whatsnew34-sslcontext">New function <a class="reference internal" href="../library/ssl.html#ssl.create_default_context" title="ssl.create_default_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">create_default_context()</span></code></a> provides a standard way to
  1391. obtain an <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLContext</span></code></a> whose settings are intended to be a
  1392. reasonable balance between compatibility and security. These settings are
  1393. more stringent than the defaults provided by the <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLContext</span></code></a>
  1394. constructor, and may be adjusted in the future, without prior deprecation, if
  1395. best-practice security requirements change. The new recommended best
  1396. practice for using stdlib libraries that support SSL is to use
  1397. <a class="reference internal" href="../library/ssl.html#ssl.create_default_context" title="ssl.create_default_context"><code class="xref py py-func docutils literal notranslate"><span class="pre">create_default_context()</span></code></a> to obtain an <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLContext</span></code></a>
  1398. object, modify it if needed, and then pass it as the <em>context</em> argument
  1399. of the appropriate stdlib API. (Contributed by Christian Heimes
  1400. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19689">bpo-19689</a>.)</p>
  1401. <p><a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLContext</span></code></a> method <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.load_verify_locations" title="ssl.SSLContext.load_verify_locations"><code class="xref py py-meth docutils literal notranslate"><span class="pre">load_verify_locations()</span></code></a>
  1402. accepts a new optional argument <em>cadata</em>, which can be used to provide PEM or
  1403. DER encoded certificates directly via strings or bytes, respectively.
  1404. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18138">bpo-18138</a>.)</p>
  1405. <p>New function <a class="reference internal" href="../library/ssl.html#ssl.get_default_verify_paths" title="ssl.get_default_verify_paths"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_default_verify_paths()</span></code></a> returns
  1406. a named tuple of the paths and environment variables that the
  1407. <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_default_verify_paths" title="ssl.SSLContext.set_default_verify_paths"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_default_verify_paths()</span></code></a> method uses to set
  1408. OpenSSL’s default <code class="docutils literal notranslate"><span class="pre">cafile</span></code> and <code class="docutils literal notranslate"><span class="pre">capath</span></code>. This can be an aid in
  1409. debugging default verification issues. (Contributed by Christian Heimes
  1410. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18143">bpo-18143</a>.)</p>
  1411. <p><a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLContext</span></code></a> has a new method,
  1412. <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.cert_store_stats" title="ssl.SSLContext.cert_store_stats"><code class="xref py py-meth docutils literal notranslate"><span class="pre">cert_store_stats()</span></code></a>, that reports the number of loaded
  1413. <code class="docutils literal notranslate"><span class="pre">X.509</span></code> certs, <code class="docutils literal notranslate"><span class="pre">X.509</span> <span class="pre">CA</span></code> certs, and certificate revocation lists
  1414. (<code class="docutils literal notranslate"><span class="pre">crl</span></code>s), as well as a <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.get_ca_certs" title="ssl.SSLContext.get_ca_certs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_ca_certs()</span></code></a> method that
  1415. returns a list of the loaded <code class="docutils literal notranslate"><span class="pre">CA</span></code> certificates. (Contributed by Christian
  1416. Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18147">bpo-18147</a>.)</p>
  1417. <p>If OpenSSL 0.9.8 or later is available, <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLContext</span></code></a> has a new
  1418. attribute <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.verify_flags" title="ssl.SSLContext.verify_flags"><code class="xref py py-attr docutils literal notranslate"><span class="pre">verify_flags</span></code></a> that can be used to control the
  1419. certificate verification process by setting it to some combination of the new
  1420. constants <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_DEFAULT" title="ssl.VERIFY_DEFAULT"><code class="xref py py-const docutils literal notranslate"><span class="pre">VERIFY_DEFAULT</span></code></a>, <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_CRL_CHECK_LEAF" title="ssl.VERIFY_CRL_CHECK_LEAF"><code class="xref py py-const docutils literal notranslate"><span class="pre">VERIFY_CRL_CHECK_LEAF</span></code></a>,
  1421. <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_CRL_CHECK_CHAIN" title="ssl.VERIFY_CRL_CHECK_CHAIN"><code class="xref py py-const docutils literal notranslate"><span class="pre">VERIFY_CRL_CHECK_CHAIN</span></code></a>, or <a class="reference internal" href="../library/ssl.html#ssl.VERIFY_X509_STRICT" title="ssl.VERIFY_X509_STRICT"><code class="xref py py-const docutils literal notranslate"><span class="pre">VERIFY_X509_STRICT</span></code></a>.
  1422. OpenSSL does not do any CRL verification by default. (Contributed by
  1423. Christien Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8813">bpo-8813</a>.)</p>
  1424. <p>New <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLContext</span></code></a> method <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.load_default_certs" title="ssl.SSLContext.load_default_certs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">load_default_certs()</span></code></a>
  1425. loads a set of default “certificate authority” (CA) certificates from default
  1426. locations, which vary according to the platform. It can be used to load both
  1427. TLS web server authentication certificates
  1428. (<code class="docutils literal notranslate"><span class="pre">purpose=</span></code><a class="reference internal" href="../library/ssl.html#ssl.Purpose.SERVER_AUTH" title="ssl.Purpose.SERVER_AUTH"><code class="xref py py-data docutils literal notranslate"><span class="pre">SERVER_AUTH</span></code></a>) for a client to use to verify a
  1429. server, and certificates for a server to use in verifying client certificates
  1430. (<code class="docutils literal notranslate"><span class="pre">purpose=</span></code><a class="reference internal" href="../library/ssl.html#ssl.Purpose.CLIENT_AUTH" title="ssl.Purpose.CLIENT_AUTH"><code class="xref py py-data docutils literal notranslate"><span class="pre">CLIENT_AUTH</span></code></a>). (Contributed by Christian
  1431. Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19292">bpo-19292</a>.)</p>
  1432. <p id="whatsnew34-win-cert-store">Two new windows-only functions, <a class="reference internal" href="../library/ssl.html#ssl.enum_certificates" title="ssl.enum_certificates"><code class="xref py py-func docutils literal notranslate"><span class="pre">enum_certificates()</span></code></a> and
  1433. <a class="reference internal" href="../library/ssl.html#ssl.enum_crls" title="ssl.enum_crls"><code class="xref py py-func docutils literal notranslate"><span class="pre">enum_crls()</span></code></a> provide the ability to retrieve certificates,
  1434. certificate information, and CRLs from the Windows cert store. (Contributed
  1435. by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17134">bpo-17134</a>.)</p>
  1436. <p id="whatsnew34-sni">Support for server-side SNI (Server Name Indication) using the new
  1437. <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_servername_callback" title="ssl.SSLContext.set_servername_callback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLContext.set_servername_callback()</span></code></a> method.
  1438. (Contributed by Daniel Black in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8109">bpo-8109</a>.)</p>
  1439. <p>The dictionary returned by <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.getpeercert" title="ssl.SSLSocket.getpeercert"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SSLSocket.getpeercert()</span></code></a> contains additional
  1440. <code class="docutils literal notranslate"><span class="pre">X509v3</span></code> extension items: <code class="docutils literal notranslate"><span class="pre">crlDistributionPoints</span></code>, <code class="docutils literal notranslate"><span class="pre">calIssuers</span></code>, and
  1441. <code class="docutils literal notranslate"><span class="pre">OCSP</span></code> URIs. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18379">bpo-18379</a>.)</p>
  1442. </section>
  1443. <section id="stat">
  1444. <h3>stat<a class="headerlink" href="#stat" title="Link to this heading">¶</a></h3>
  1445. <p>The <a class="reference internal" href="../library/stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> module is now backed by a C implementation in <code class="xref py py-mod docutils literal notranslate"><span class="pre">_stat</span></code>. A C
  1446. implementation is required as most of the values aren’t standardized and
  1447. are platform-dependent. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11016">bpo-11016</a>.)</p>
  1448. <p>The module supports new <a class="reference internal" href="../library/stat.html#stat.ST_MODE" title="stat.ST_MODE"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ST_MODE</span></code></a> flags, <a class="reference internal" href="../library/stat.html#stat.S_IFDOOR" title="stat.S_IFDOOR"><code class="xref py py-mod docutils literal notranslate"><span class="pre">S_IFDOOR</span></code></a>,
  1449. <a class="reference internal" href="../library/stat.html#stat.S_IFPORT" title="stat.S_IFPORT"><code class="xref py py-const docutils literal notranslate"><span class="pre">S_IFPORT</span></code></a>, and <a class="reference internal" href="../library/stat.html#stat.S_IFWHT" title="stat.S_IFWHT"><code class="xref py py-const docutils literal notranslate"><span class="pre">S_IFWHT</span></code></a>. (Contributed by
  1450. Christian Hiemes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11016">bpo-11016</a>.)</p>
  1451. </section>
  1452. <section id="struct">
  1453. <h3>struct<a class="headerlink" href="#struct" title="Link to this heading">¶</a></h3>
  1454. <p>New function <a class="reference internal" href="../library/struct.html#struct.iter_unpack" title="struct.iter_unpack"><code class="xref py py-mod docutils literal notranslate"><span class="pre">iter_unpack</span></code></a> and a new
  1455. <a class="reference internal" href="../library/struct.html#struct.Struct.iter_unpack" title="struct.Struct.iter_unpack"><code class="xref py py-meth docutils literal notranslate"><span class="pre">struct.Struct.iter_unpack()</span></code></a> method on compiled formats provide streamed
  1456. unpacking of a buffer containing repeated instances of a given format of data.
  1457. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17804">bpo-17804</a>.)</p>
  1458. </section>
  1459. <section id="subprocess">
  1460. <h3>subprocess<a class="headerlink" href="#subprocess" title="Link to this heading">¶</a></h3>
  1461. <p><a class="reference internal" href="../library/subprocess.html#subprocess.check_output" title="subprocess.check_output"><code class="xref py py-func docutils literal notranslate"><span class="pre">check_output()</span></code></a> now accepts an <em>input</em> argument that can
  1462. be used to provide the contents of <code class="docutils literal notranslate"><span class="pre">stdin</span></code> for the command that is run.
  1463. (Contributed by Zack Weinberg in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16624">bpo-16624</a>.)</p>
  1464. <p><code class="xref py py-func docutils literal notranslate"><span class="pre">getstatus()</span></code> and <a class="reference internal" href="../library/subprocess.html#subprocess.getstatusoutput" title="subprocess.getstatusoutput"><code class="xref py py-func docutils literal notranslate"><span class="pre">getstatusoutput()</span></code></a> now
  1465. work on Windows. This change was actually inadvertently made in 3.3.4.
  1466. (Contributed by Tim Golden in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10197">bpo-10197</a>.)</p>
  1467. </section>
  1468. <section id="sunau">
  1469. <h3>sunau<a class="headerlink" href="#sunau" title="Link to this heading">¶</a></h3>
  1470. <p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">getparams()</span></code> method now returns a namedtuple rather than a
  1471. plain tuple. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18901">bpo-18901</a>.)</p>
  1472. <p><a class="reference internal" href="../library/sunau.html#sunau.open" title="sunau.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sunau.open()</span></code></a> now supports the context management protocol: when used in a
  1473. <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, the <code class="docutils literal notranslate"><span class="pre">close</span></code> method of the returned object will be
  1474. called automatically at the end of the block. (Contributed by Serhiy Storchaka
  1475. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18878">bpo-18878</a>.)</p>
  1476. <p><a class="reference internal" href="../library/sunau.html#sunau.AU_write.setsampwidth" title="sunau.AU_write.setsampwidth"><code class="xref py py-meth docutils literal notranslate"><span class="pre">AU_write.setsampwidth()</span></code></a> now supports 24 bit samples, thus adding
  1477. support for writing 24 sample using the module. (Contributed by
  1478. Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19261">bpo-19261</a>.)</p>
  1479. <p>The <a class="reference internal" href="../library/sunau.html#sunau.AU_write.writeframesraw" title="sunau.AU_write.writeframesraw"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframesraw()</span></code></a> and
  1480. <a class="reference internal" href="../library/sunau.html#sunau.AU_write.writeframes" title="sunau.AU_write.writeframes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframes()</span></code></a> methods now accept any <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like
  1481. object</span></a>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8311">bpo-8311</a>.)</p>
  1482. </section>
  1483. <section id="sys">
  1484. <h3>sys<a class="headerlink" href="#sys" title="Link to this heading">¶</a></h3>
  1485. <p>New function <a class="reference internal" href="../library/sys.html#sys.getallocatedblocks" title="sys.getallocatedblocks"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getallocatedblocks()</span></code></a> returns the current number of
  1486. blocks allocated by the interpreter. (In CPython with the default
  1487. <code class="docutils literal notranslate"><span class="pre">--with-pymalloc</span></code> setting, this is allocations made through the
  1488. <a class="reference internal" href="../c-api/memory.html#c.PyObject_Malloc" title="PyObject_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Malloc()</span></code></a> API.) This can be useful for tracking memory leaks,
  1489. especially if automated via a test suite. (Contributed by Antoine Pitrou
  1490. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13390">bpo-13390</a>.)</p>
  1491. <p>When the Python interpreter starts in <a class="reference internal" href="../tutorial/interpreter.html#tut-interactive"><span class="std std-ref">interactive mode</span></a>, it checks for an <a class="reference internal" href="../library/sys.html#sys.__interactivehook__" title="sys.__interactivehook__"><code class="xref py py-data docutils literal notranslate"><span class="pre">__interactivehook__</span></code></a> attribute
  1492. on the <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> module. If the attribute exists, its value is called with no
  1493. arguments just before interactive mode is started. The check is made after the
  1494. <span class="target" id="index-40"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a> file is read, so it can be set there. The <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a>
  1495. module <a class="reference internal" href="../library/site.html#rlcompleter-config"><span class="std std-ref">sets it</span></a> to a function that enables tab
  1496. completion and history saving (in <code class="file docutils literal notranslate"><span class="pre">~/.python-history</span></code>) if the platform
  1497. supports <a class="reference internal" href="../library/readline.html#module-readline" title="readline: GNU readline support for Python. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code></a>. If you do not want this (new) behavior, you can
  1498. override it in <span class="target" id="index-41"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSTARTUP"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSTARTUP</span></code></a>, <a class="reference internal" href="../library/site.html#module-sitecustomize" title="sitecustomize"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sitecustomize</span></code></a>, or
  1499. <a class="reference internal" href="../library/site.html#module-usercustomize" title="usercustomize"><code class="xref py py-mod docutils literal notranslate"><span class="pre">usercustomize</span></code></a> by deleting this attribute from <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> (or setting it
  1500. to some other callable). (Contributed by Éric Araujo and Antoine Pitrou in
  1501. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5845">bpo-5845</a>.)</p>
  1502. </section>
  1503. <section id="tarfile">
  1504. <h3>tarfile<a class="headerlink" href="#tarfile" title="Link to this heading">¶</a></h3>
  1505. <p>The <a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a> module now supports a simple <a class="reference internal" href="../library/tarfile.html#tarfile-commandline"><span class="std std-ref">Command-Line Interface</span></a> when
  1506. called as a script directly or via <code class="docutils literal notranslate"><span class="pre">-m</span></code>. This can be used to create and
  1507. extract tarfile archives. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13477">bpo-13477</a>.)</p>
  1508. </section>
  1509. <section id="textwrap">
  1510. <h3>textwrap<a class="headerlink" href="#textwrap" title="Link to this heading">¶</a></h3>
  1511. <p>The <a class="reference internal" href="../library/textwrap.html#textwrap.TextWrapper" title="textwrap.TextWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">TextWrapper</span></code></a> class has two new attributes/constructor
  1512. arguments: <a class="reference internal" href="../library/textwrap.html#textwrap.TextWrapper.max_lines" title="textwrap.TextWrapper.max_lines"><code class="xref py py-attr docutils literal notranslate"><span class="pre">max_lines</span></code></a>, which limits the number of
  1513. lines in the output, and <a class="reference internal" href="../library/textwrap.html#textwrap.TextWrapper.placeholder" title="textwrap.TextWrapper.placeholder"><code class="xref py py-attr docutils literal notranslate"><span class="pre">placeholder</span></code></a>, which is a
  1514. string that will appear at the end of the output if it has been truncated
  1515. because of <em>max_lines</em>. Building on these capabilities, a new convenience
  1516. function <a class="reference internal" href="../library/textwrap.html#textwrap.shorten" title="textwrap.shorten"><code class="xref py py-func docutils literal notranslate"><span class="pre">shorten()</span></code></a> collapses all of the whitespace in the input
  1517. to single spaces and produces a single line of a given <em>width</em> that ends with
  1518. the <em>placeholder</em> (by default, <code class="docutils literal notranslate"><span class="pre">[...]</span></code>). (Contributed by Antoine Pitrou and
  1519. Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18585">bpo-18585</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18725">bpo-18725</a>.)</p>
  1520. </section>
  1521. <section id="threading">
  1522. <h3>threading<a class="headerlink" href="#threading" title="Link to this heading">¶</a></h3>
  1523. <p>The <a class="reference internal" href="../library/threading.html#threading.Thread" title="threading.Thread"><code class="xref py py-class docutils literal notranslate"><span class="pre">Thread</span></code></a> object representing the main thread can be
  1524. obtained from the new <a class="reference internal" href="../library/threading.html#threading.main_thread" title="threading.main_thread"><code class="xref py py-func docutils literal notranslate"><span class="pre">main_thread()</span></code></a> function. In normal
  1525. conditions this will be the thread from which the Python interpreter was
  1526. started. (Contributed by Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18882">bpo-18882</a>.)</p>
  1527. </section>
  1528. <section id="traceback">
  1529. <h3>traceback<a class="headerlink" href="#traceback" title="Link to this heading">¶</a></h3>
  1530. <p>A new <a class="reference internal" href="../library/traceback.html#traceback.clear_frames" title="traceback.clear_frames"><code class="xref py py-func docutils literal notranslate"><span class="pre">traceback.clear_frames()</span></code></a> function takes a traceback object
  1531. and clears the local variables in all of the frames it references,
  1532. reducing the amount of memory consumed. (Contributed by Andrew Kuchling in
  1533. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1565525">bpo-1565525</a>.)</p>
  1534. </section>
  1535. <section id="types">
  1536. <h3>types<a class="headerlink" href="#types" title="Link to this heading">¶</a></h3>
  1537. <p>A new <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">DynamicClassAttribute()</span></code></a> descriptor provides a way to define
  1538. an attribute that acts normally when looked up through an instance object, but
  1539. which is routed to the <em>class</em> <code class="docutils literal notranslate"><span class="pre">__getattr__</span></code> when looked up through the
  1540. class. This allows one to have properties active on a class, and have virtual
  1541. attributes on the class with the same name (see <code class="xref py py-mod docutils literal notranslate"><span class="pre">Enum</span></code> for an example).
  1542. (Contributed by Ethan Furman in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19030">bpo-19030</a>.)</p>
  1543. </section>
  1544. <section id="urllib">
  1545. <h3>urllib<a class="headerlink" href="#urllib" title="Link to this heading">¶</a></h3>
  1546. <p><a class="reference internal" href="../library/urllib.request.html#module-urllib.request" title="urllib.request: Extensible library for opening URLs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request</span></code></a> now supports <code class="docutils literal notranslate"><span class="pre">data:</span></code> URLs via the
  1547. <a class="reference internal" href="../library/urllib.request.html#urllib.request.DataHandler" title="urllib.request.DataHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">DataHandler</span></code></a> class. (Contributed by Mathias Panzenböck
  1548. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16423">bpo-16423</a>.)</p>
  1549. <p>The http method that will be used by a <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> class
  1550. can now be specified by setting a <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request.method" title="urllib.request.Request.method"><code class="xref py py-class docutils literal notranslate"><span class="pre">method</span></code></a>
  1551. class attribute on the subclass. (Contributed by Jason R Coombs in
  1552. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18978">bpo-18978</a>.)</p>
  1553. <p><a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> objects are now reusable: if the
  1554. <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request.full_url" title="urllib.request.Request.full_url"><code class="xref py py-attr docutils literal notranslate"><span class="pre">full_url</span></code></a> or <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request.data" title="urllib.request.Request.data"><code class="xref py py-attr docutils literal notranslate"><span class="pre">data</span></code></a>
  1555. attributes are modified, all relevant internal properties are updated. This
  1556. means, for example, that it is now possible to use the same
  1557. <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a> object in more than one
  1558. <a class="reference internal" href="../library/urllib.request.html#urllib.request.OpenerDirector.open" title="urllib.request.OpenerDirector.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">OpenerDirector.open()</span></code></a> call with different <em>data</em> arguments, or to
  1559. modify a <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a>‘s <code class="docutils literal notranslate"><span class="pre">url</span></code> rather than recomputing it
  1560. from scratch. There is also a new
  1561. <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request.remove_header" title="urllib.request.Request.remove_header"><code class="xref py py-meth docutils literal notranslate"><span class="pre">remove_header()</span></code></a> method that can be used to remove
  1562. headers from a <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-class docutils literal notranslate"><span class="pre">Request</span></code></a>. (Contributed by Alexey
  1563. Kachayev in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16464">bpo-16464</a>, Daniel Wozniak in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17485">bpo-17485</a>, and Damien Brecht
  1564. and Senthil Kumaran in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17272">bpo-17272</a>.)</p>
  1565. <p><a class="reference internal" href="../library/urllib.error.html#urllib.error.HTTPError" title="urllib.error.HTTPError"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPError</span></code></a> objects now have a
  1566. <a class="reference internal" href="../library/urllib.error.html#urllib.error.HTTPError.headers" title="urllib.error.HTTPError.headers"><code class="xref py py-attr docutils literal notranslate"><span class="pre">headers</span></code></a> attribute that provides access to the
  1567. HTTP response headers associated with the error. (Contributed by
  1568. Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15701">bpo-15701</a>.)</p>
  1569. </section>
  1570. <section id="unittest">
  1571. <h3>unittest<a class="headerlink" href="#unittest" title="Link to this heading">¶</a></h3>
  1572. <p>The <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> class has a new method,
  1573. <a class="reference internal" href="../library/unittest.html#unittest.TestCase.subTest" title="unittest.TestCase.subTest"><code class="xref py py-meth docutils literal notranslate"><span class="pre">subTest()</span></code></a>, that produces a context manager whose
  1574. <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 becomes a “sub-test”. This context manager allows a test
  1575. method to dynamically generate subtests by, say, calling the <code class="docutils literal notranslate"><span class="pre">subTest</span></code>
  1576. context manager inside a loop. A single test method can thereby produce an
  1577. indefinite number of separately identified and separately counted tests, all of
  1578. which will run even if one or more of them fail. For example:</p>
  1579. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">NumbersTest</span><span class="p">(</span><span class="n">unittest</span><span class="o">.</span><span class="n">TestCase</span><span class="p">):</span>
  1580. <span class="k">def</span> <span class="nf">test_even</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  1581. <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">6</span><span class="p">):</span>
  1582. <span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">subTest</span><span class="p">(</span><span class="n">i</span><span class="o">=</span><span class="n">i</span><span class="p">):</span>
  1583. <span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="n">i</span> <span class="o">%</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
  1584. </pre></div>
  1585. </div>
  1586. <p>will result in six subtests, each identified in the unittest verbose output
  1587. with a label consisting of the variable name <code class="docutils literal notranslate"><span class="pre">i</span></code> and a particular value for
  1588. that variable (<code class="docutils literal notranslate"><span class="pre">i=0</span></code>, <code class="docutils literal notranslate"><span class="pre">i=1</span></code>, etc). See <a class="reference internal" href="../library/unittest.html#subtests"><span class="std std-ref">Distinguishing test iterations using subtests</span></a> for the full
  1589. version of this example. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16997">bpo-16997</a>.)</p>
  1590. <p><a class="reference internal" href="../library/unittest.html#unittest.main" title="unittest.main"><code class="xref py py-func docutils literal notranslate"><span class="pre">unittest.main()</span></code></a> now accepts an iterable of test names for
  1591. <em>defaultTest</em>, where previously it only accepted a single test name as a
  1592. string. (Contributed by Jyrki Pulliainen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15132">bpo-15132</a>.)</p>
  1593. <p>If <a class="reference internal" href="../library/unittest.html#unittest.SkipTest" title="unittest.SkipTest"><code class="xref py py-class docutils literal notranslate"><span class="pre">SkipTest</span></code></a> is raised during test discovery (that is, at the
  1594. module level in the test file), it is now reported as a skip instead of an
  1595. error. (Contributed by Zach Ware in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16935">bpo-16935</a>.)</p>
  1596. <p><a class="reference internal" href="../library/unittest.html#unittest.TestLoader.discover" title="unittest.TestLoader.discover"><code class="xref py py-meth docutils literal notranslate"><span class="pre">discover()</span></code></a> now sorts the discovered files to provide
  1597. consistent test ordering. (Contributed by Martin Melin and Jeff Ramnani in
  1598. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16709">bpo-16709</a>.)</p>
  1599. <p><a class="reference internal" href="../library/unittest.html#unittest.TestSuite" title="unittest.TestSuite"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestSuite</span></code></a> now drops references to tests as soon as the test
  1600. has been run, if the test is successful. On Python interpreters that do
  1601. garbage collection, this allows the tests to be garbage collected if nothing
  1602. else is holding a reference to the test. It is possible to override this
  1603. behavior by creating a <a class="reference internal" href="../library/unittest.html#unittest.TestSuite" title="unittest.TestSuite"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestSuite</span></code></a> subclass that defines a
  1604. custom <code class="docutils literal notranslate"><span class="pre">_removeTestAtIndex</span></code> method. (Contributed by Tom Wardill, Matt
  1605. McClure, and Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11798">bpo-11798</a>.)</p>
  1606. <p>A new test assertion context-manager, <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertLogs" title="unittest.TestCase.assertLogs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertLogs()</span></code></a>,
  1607. will ensure that a given block of code emits a log message using the
  1608. <a class="reference internal" href="../library/logging.html#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> module. By default the message can come from any logger and
  1609. have a priority of <code class="docutils literal notranslate"><span class="pre">INFO</span></code> or higher, but both the logger name and an
  1610. alternative minimum logging level may be specified. The object returned by the
  1611. context manager can be queried for the <a class="reference internal" href="../library/logging.html#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a>s and/or
  1612. formatted messages that were logged. (Contributed by Antoine Pitrou in
  1613. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18937">bpo-18937</a>.)</p>
  1614. <p>Test discovery now works with namespace packages (Contributed by Claudiu Popa
  1615. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17457">bpo-17457</a>.)</p>
  1616. <p><a class="reference internal" href="../library/unittest.mock.html#module-unittest.mock" title="unittest.mock: Mock object library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest.mock</span></code></a> objects now inspect their specification signatures when
  1617. matching calls, which means an argument can now be matched by either position
  1618. or name, instead of only by position. (Contributed by Antoine Pitrou in
  1619. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17015">bpo-17015</a>.)</p>
  1620. <p><code class="xref py py-func docutils literal notranslate"><span class="pre">mock_open()</span></code> objects now have <code class="docutils literal notranslate"><span class="pre">readline</span></code> and <code class="docutils literal notranslate"><span class="pre">readlines</span></code>
  1621. methods. (Contributed by Toshio Kuratomi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17467">bpo-17467</a>.)</p>
  1622. </section>
  1623. <section id="venv">
  1624. <h3>venv<a class="headerlink" href="#venv" title="Link to this heading">¶</a></h3>
  1625. <p><a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a> now includes activation scripts for the <code class="docutils literal notranslate"><span class="pre">csh</span></code> and <code class="docutils literal notranslate"><span class="pre">fish</span></code>
  1626. shells. (Contributed by Andrew Svetlov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15417">bpo-15417</a>.)</p>
  1627. <p><a class="reference internal" href="../library/venv.html#venv.EnvBuilder" title="venv.EnvBuilder"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvBuilder</span></code></a> and the <a class="reference internal" href="../library/venv.html#venv.create" title="venv.create"><code class="xref py py-func docutils literal notranslate"><span class="pre">create()</span></code></a> convenience function
  1628. take a new keyword argument <em>with_pip</em>, which defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>, that
  1629. controls whether or not <a class="reference internal" href="../library/venv.html#venv.EnvBuilder" title="venv.EnvBuilder"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvBuilder</span></code></a> ensures that <code class="docutils literal notranslate"><span class="pre">pip</span></code> is
  1630. installed in the virtual environment. (Contributed by Nick Coghlan in
  1631. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19552">bpo-19552</a> as part of the <span class="target" id="index-42"></span><a class="pep reference external" href="https://peps.python.org/pep-0453/"><strong>PEP 453</strong></a> implementation.)</p>
  1632. </section>
  1633. <section id="wave">
  1634. <h3>wave<a class="headerlink" href="#wave" title="Link to this heading">¶</a></h3>
  1635. <p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">getparams()</span></code> method now returns a namedtuple rather than a
  1636. plain tuple. (Contributed by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17487">bpo-17487</a>.)</p>
  1637. <p><a class="reference internal" href="../library/wave.html#wave.open" title="wave.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">wave.open()</span></code></a> now supports the context management protocol. (Contributed
  1638. by Claudiu Popa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17616">bpo-17616</a>.)</p>
  1639. <p><a class="reference internal" href="../library/wave.html#module-wave" title="wave: Provide an interface to the WAV sound format."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wave</span></code></a> can now <a class="reference internal" href="../library/wave.html#wave-write-objects"><span class="std std-ref">write output to unseekable files</span></a>. (Contributed by David Jones, Guilherme Polo, and Serhiy
  1640. Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5202">bpo-5202</a>.)</p>
  1641. <p>The <a class="reference internal" href="../library/wave.html#wave.Wave_write.writeframesraw" title="wave.Wave_write.writeframesraw"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframesraw()</span></code></a> and
  1642. <a class="reference internal" href="../library/wave.html#wave.Wave_write.writeframes" title="wave.Wave_write.writeframes"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writeframes()</span></code></a> methods now accept any <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like
  1643. object</span></a>. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8311">bpo-8311</a>.)</p>
  1644. </section>
  1645. <section id="weakref">
  1646. <h3>weakref<a class="headerlink" href="#weakref" title="Link to this heading">¶</a></h3>
  1647. <p>New <a class="reference internal" href="../library/weakref.html#weakref.WeakMethod" title="weakref.WeakMethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">WeakMethod</span></code></a> class simulates weak references to bound
  1648. methods. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14631">bpo-14631</a>.)</p>
  1649. <p>New <a class="reference internal" href="../library/weakref.html#weakref.finalize" title="weakref.finalize"><code class="xref py py-class docutils literal notranslate"><span class="pre">finalize</span></code></a> class makes it possible to register a callback
  1650. to be invoked when an object is garbage collected, without needing to
  1651. carefully manage the lifecycle of the weak reference itself. (Contributed by
  1652. Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15528">bpo-15528</a>.)</p>
  1653. <p>The callback, if any, associated with a <a class="reference internal" href="../library/weakref.html#weakref.ref" title="weakref.ref"><code class="xref py py-class docutils literal notranslate"><span class="pre">ref</span></code></a> is now
  1654. exposed via the <a class="reference internal" href="../library/weakref.html#weakref.ref.__callback__" title="weakref.ref.__callback__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__callback__</span></code></a> attribute. (Contributed
  1655. by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17643">bpo-17643</a>.)</p>
  1656. </section>
  1657. <section id="xml-etree">
  1658. <h3>xml.etree<a class="headerlink" href="#xml-etree" title="Link to this heading">¶</a></h3>
  1659. <p>A new parser, <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLPullParser" title="xml.etree.ElementTree.XMLPullParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">XMLPullParser</span></code></a>, allows a
  1660. non-blocking applications to parse XML documents. An example can be
  1661. seen at <a class="reference internal" href="../library/xml.etree.elementtree.html#elementtree-pull-parsing"><span class="std std-ref">Pull API for non-blocking parsing</span></a>. (Contributed by Antoine
  1662. Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17741">bpo-17741</a>.)</p>
  1663. <p>The <a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code></a> <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.tostring" title="xml.etree.ElementTree.tostring"><code class="xref py py-func docutils literal notranslate"><span class="pre">tostring()</span></code></a> and
  1664. <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.tostringlist" title="xml.etree.ElementTree.tostringlist"><code class="xref py py-func docutils literal notranslate"><span class="pre">tostringlist()</span></code></a> functions, and the
  1665. <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree" title="xml.etree.ElementTree.ElementTree"><code class="xref py py-class docutils literal notranslate"><span class="pre">ElementTree</span></code></a>
  1666. <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree.write" title="xml.etree.ElementTree.ElementTree.write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code></a> method, now have a
  1667. <em>short_empty_elements</em> <a class="reference internal" href="../glossary.html#keyword-only-parameter"><span class="std std-ref">keyword-only parameter</span></a>
  1668. providing control over whether elements with no content are written in
  1669. abbreviated (<code class="docutils literal notranslate"><span class="pre">&lt;tag</span> <span class="pre">/&gt;</span></code>) or expanded (<code class="docutils literal notranslate"><span class="pre">&lt;tag&gt;&lt;/tag&gt;</span></code>) form. (Contributed by
  1670. Ariel Poliak and Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14377">bpo-14377</a>.)</p>
  1671. </section>
  1672. <section id="zipfile">
  1673. <h3>zipfile<a class="headerlink" href="#zipfile" title="Link to this heading">¶</a></h3>
  1674. <p>The <a class="reference internal" href="../library/zipfile.html#zipfile.PyZipFile.writepy" title="zipfile.PyZipFile.writepy"><code class="xref py py-meth docutils literal notranslate"><span class="pre">writepy()</span></code></a> method of the
  1675. <a class="reference internal" href="../library/zipfile.html#zipfile.PyZipFile" title="zipfile.PyZipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">PyZipFile</span></code></a> class has a new <em>filterfunc</em> option that can be
  1676. used to control which directories and files are added to the archive. For
  1677. example, this could be used to exclude test files from the archive.
  1678. (Contributed by Christian Tismer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19274">bpo-19274</a>.)</p>
  1679. <p>The <em>allowZip64</em> parameter to <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> and
  1680. <code class="xref py py-class docutils literal notranslate"><span class="pre">PyZipfile</span></code> is now <code class="docutils literal notranslate"><span class="pre">True</span></code> by default. (Contributed by
  1681. William Mallard in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17201">bpo-17201</a>.)</p>
  1682. </section>
  1683. </section>
  1684. <section id="cpython-implementation-changes">
  1685. <h2>CPython Implementation Changes<a class="headerlink" href="#cpython-implementation-changes" title="Link to this heading">¶</a></h2>
  1686. <section id="pep-445-customization-of-cpython-memory-allocators">
  1687. <span id="whatsnew-pep-445"></span><h3>PEP 445: Customization of CPython Memory Allocators<a class="headerlink" href="#pep-445-customization-of-cpython-memory-allocators" title="Link to this heading">¶</a></h3>
  1688. <p><span class="target" id="index-43"></span><a class="pep reference external" href="https://peps.python.org/pep-0445/"><strong>PEP 445</strong></a> adds new C level interfaces to customize memory allocation in
  1689. the CPython interpreter.</p>
  1690. <div class="admonition seealso">
  1691. <p class="admonition-title">See also</p>
  1692. <dl class="simple">
  1693. <dt><span class="target" id="index-44"></span><a class="pep reference external" href="https://peps.python.org/pep-0445/"><strong>PEP 445</strong></a> – Add new APIs to customize Python memory allocators</dt><dd><p>PEP written and implemented by Victor Stinner.</p>
  1694. </dd>
  1695. </dl>
  1696. </div>
  1697. </section>
  1698. <section id="pep-442-safe-object-finalization">
  1699. <span id="whatsnew-pep-442"></span><h3>PEP 442: Safe Object Finalization<a class="headerlink" href="#pep-442-safe-object-finalization" title="Link to this heading">¶</a></h3>
  1700. <p><span class="target" id="index-45"></span><a class="pep reference external" href="https://peps.python.org/pep-0442/"><strong>PEP 442</strong></a> removes the current limitations and quirks of object finalization
  1701. in CPython. With it, objects with <code class="xref py py-meth docutils literal notranslate"><span class="pre">__del__()</span></code> methods, as well as
  1702. generators with <a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">finally</span></code></a> clauses, can be finalized when they are
  1703. part of a reference cycle.</p>
  1704. <p>As part of this change, module globals are no longer forcibly set to
  1705. <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> during interpreter shutdown in most cases, instead relying
  1706. on the normal operation of the cyclic garbage collector. This avoids a
  1707. whole class of interpreter-shutdown-time errors, usually involving
  1708. <code class="docutils literal notranslate"><span class="pre">__del__</span></code> methods, that have plagued Python since the cyclic GC
  1709. was first introduced.</p>
  1710. <div class="admonition seealso">
  1711. <p class="admonition-title">See also</p>
  1712. <dl class="simple">
  1713. <dt><span class="target" id="index-46"></span><a class="pep reference external" href="https://peps.python.org/pep-0442/"><strong>PEP 442</strong></a> – Safe object finalization</dt><dd><p>PEP written and implemented by Antoine Pitrou.</p>
  1714. </dd>
  1715. </dl>
  1716. </div>
  1717. </section>
  1718. <section id="pep-456-secure-and-interchangeable-hash-algorithm">
  1719. <span id="whatsnew-pep-456"></span><h3>PEP 456: Secure and Interchangeable Hash Algorithm<a class="headerlink" href="#pep-456-secure-and-interchangeable-hash-algorithm" title="Link to this heading">¶</a></h3>
  1720. <p><span class="target" id="index-47"></span><a class="pep reference external" href="https://peps.python.org/pep-0456/"><strong>PEP 456</strong></a> follows up on earlier security fix work done on Python’s hash
  1721. algorithm to address certain DOS attacks to which public facing APIs backed by
  1722. dictionary lookups may be subject. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14621">bpo-14621</a> for the start of the
  1723. current round of improvements.) The PEP unifies CPython’s hash code to make it
  1724. easier for a packager to substitute a different hash algorithm, and switches
  1725. Python’s default implementation to a SipHash implementation on platforms that
  1726. have a 64 bit data type. Any performance differences in comparison with the
  1727. older FNV algorithm are trivial.</p>
  1728. <p>The PEP adds additional fields to the <a class="reference internal" href="../library/sys.html#sys.hash_info" title="sys.hash_info"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.hash_info</span></code></a> named tuple to
  1729. describe the hash algorithm in use by the currently executing binary. Otherwise,
  1730. the PEP does not alter any existing CPython APIs.</p>
  1731. </section>
  1732. <section id="pep-436-argument-clinic">
  1733. <span id="whatsnew-pep-436"></span><h3>PEP 436: Argument Clinic<a class="headerlink" href="#pep-436-argument-clinic" title="Link to this heading">¶</a></h3>
  1734. <p>“Argument Clinic” (<span class="target" id="index-48"></span><a class="pep reference external" href="https://peps.python.org/pep-0436/"><strong>PEP 436</strong></a>) is now part of the CPython build process
  1735. and can be used to simplify the process of defining and maintaining
  1736. accurate signatures for builtins and standard library extension modules
  1737. implemented in C.</p>
  1738. <p>Some standard library extension modules have been converted to use Argument
  1739. Clinic in Python 3.4, and <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> and <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> have been updated
  1740. accordingly.</p>
  1741. <p>It is expected that signature metadata for programmatic introspection will
  1742. be added to additional callables implemented in C as part of Python 3.4
  1743. maintenance releases.</p>
  1744. <div class="admonition note">
  1745. <p class="admonition-title">Note</p>
  1746. <p>The Argument Clinic PEP is not fully up to date with the state of the
  1747. implementation. This has been deemed acceptable by the release manager
  1748. and core development team in this case, as Argument Clinic will not
  1749. be made available as a public API for third party use in Python 3.4.</p>
  1750. </div>
  1751. <div class="admonition seealso">
  1752. <p class="admonition-title">See also</p>
  1753. <dl class="simple">
  1754. <dt><span class="target" id="index-49"></span><a class="pep reference external" href="https://peps.python.org/pep-0436/"><strong>PEP 436</strong></a> – The Argument Clinic DSL</dt><dd><p>PEP written and implemented by Larry Hastings.</p>
  1755. </dd>
  1756. </dl>
  1757. </div>
  1758. </section>
  1759. <section id="other-build-and-c-api-changes">
  1760. <h3>Other Build and C API Changes<a class="headerlink" href="#other-build-and-c-api-changes" title="Link to this heading">¶</a></h3>
  1761. <ul class="simple">
  1762. <li><p>The new <a class="reference internal" href="../c-api/type.html#c.PyType_GetSlot" title="PyType_GetSlot"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyType_GetSlot()</span></code></a> function has been added to the stable ABI,
  1763. allowing retrieval of function pointers from named type slots when using
  1764. the limited API. (Contributed by Martin von Löwis in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17162">bpo-17162</a>.)</p></li>
  1765. <li><p>The new <a class="reference internal" href="../c-api/init.html#c.Py_SetStandardStreamEncoding" title="Py_SetStandardStreamEncoding"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetStandardStreamEncoding()</span></code></a> pre-initialization API
  1766. allows applications embedding the CPython interpreter to reliably force
  1767. a particular encoding and error handler for the standard streams.
  1768. (Contributed by Bastien Montagne and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16129">bpo-16129</a>.)</p></li>
  1769. <li><p>Most Python C APIs that don’t mutate string arguments are now correctly
  1770. marked as accepting <code class="docutils literal notranslate"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></code> rather than <code class="docutils literal notranslate"><span class="pre">char</span> <span class="pre">*</span></code>. (Contributed
  1771. by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1772673">bpo-1772673</a>.)</p></li>
  1772. <li><p>A new shell version of <code class="docutils literal notranslate"><span class="pre">python-config</span></code> can be used even when a python
  1773. interpreter is not available (for example, in cross compilation scenarios).</p></li>
  1774. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a> now supports width and precision
  1775. specifications for <code class="docutils literal notranslate"><span class="pre">%s</span></code>, <code class="docutils literal notranslate"><span class="pre">%A</span></code>, <code class="docutils literal notranslate"><span class="pre">%U</span></code>, <code class="docutils literal notranslate"><span class="pre">%V</span></code>, <code class="docutils literal notranslate"><span class="pre">%S</span></code>, and <code class="docutils literal notranslate"><span class="pre">%R</span></code>.
  1776. (Contributed by Ysj Ray and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=7330">bpo-7330</a>.)</p></li>
  1777. <li><p>New function <a class="reference internal" href="../c-api/tuple.html#c.PyStructSequence_InitType2" title="PyStructSequence_InitType2"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStructSequence_InitType2()</span></code></a> supplements the
  1778. existing <a class="reference internal" href="../c-api/tuple.html#c.PyStructSequence_InitType" title="PyStructSequence_InitType"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStructSequence_InitType()</span></code></a> function. The difference
  1779. is that it returns <code class="docutils literal notranslate"><span class="pre">0</span></code> on success and <code class="docutils literal notranslate"><span class="pre">-1</span></code> on failure.</p></li>
  1780. <li><p>The CPython source can now be compiled using the address sanity checking
  1781. features of recent versions of GCC and clang: the false alarms in the small
  1782. object allocator have been silenced. (Contributed by Dhiru Kholia in
  1783. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18596">bpo-18596</a>.)</p></li>
  1784. <li><p>The Windows build now uses <a class="reference external" href="https://en.wikipedia.org/wiki/Address_space_layout_randomization">Address Space Layout Randomization</a> and <a class="reference external" href="https://en.wikipedia.org/wiki/Data_Execution_Prevention">Data Execution Prevention</a>. (Contributed by
  1785. Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16632">bpo-16632</a>.)</p></li>
  1786. <li><p>New function <a class="reference internal" href="../c-api/object.html#c.PyObject_LengthHint" title="PyObject_LengthHint"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_LengthHint()</span></code></a> is the C API equivalent
  1787. of <a class="reference internal" href="../library/operator.html#operator.length_hint" title="operator.length_hint"><code class="xref py py-func docutils literal notranslate"><span class="pre">operator.length_hint()</span></code></a>. (Contributed by Armin Ronacher in
  1788. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16148">bpo-16148</a>.)</p></li>
  1789. </ul>
  1790. </section>
  1791. <section id="other-improvements">
  1792. <span id="other-improvements-3-4"></span><h3>Other Improvements<a class="headerlink" href="#other-improvements" title="Link to this heading">¶</a></h3>
  1793. <ul class="simple" id="whatsnew-isolated-mode">
  1794. <li><p>The <a class="reference internal" href="../using/cmdline.html#using-on-cmdline"><span class="std std-ref">python</span></a> command has a new <a class="reference internal" href="../using/cmdline.html#using-on-misc-options"><span class="std std-ref">option</span></a>, <code class="docutils literal notranslate"><span class="pre">-I</span></code>, which causes it to run in “isolated mode”,
  1795. which means that <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> contains neither the script’s directory nor
  1796. the user’s <code class="docutils literal notranslate"><span class="pre">site-packages</span></code> directory, and all <code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHON*</span></code> environment
  1797. variables are ignored (it implies both <code class="docutils literal notranslate"><span class="pre">-s</span></code> and <code class="docutils literal notranslate"><span class="pre">-E</span></code>). Other
  1798. restrictions may also be applied in the future, with the goal being to
  1799. isolate the execution of a script from the user’s environment. This is
  1800. appropriate, for example, when Python is used to run a system script. On
  1801. most POSIX systems it can and should be used in the <code class="docutils literal notranslate"><span class="pre">#!</span></code> line of system
  1802. scripts. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16499">bpo-16499</a>.)</p></li>
  1803. <li><p>Tab-completion is now enabled by default in the interactive interpreter
  1804. on systems that support <a class="reference internal" href="../library/readline.html#module-readline" title="readline: GNU readline support for Python. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code></a>. History is also enabled by default,
  1805. and is written to (and read from) the file <code class="file docutils literal notranslate"><span class="pre">~/.python-history</span></code>.
  1806. (Contributed by Antoine Pitrou and Éric Araujo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5845">bpo-5845</a>.)</p></li>
  1807. <li><p>Invoking the Python interpreter with <code class="docutils literal notranslate"><span class="pre">--version</span></code> now outputs the version to
  1808. standard output instead of standard error (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18338">bpo-18338</a>). Similar changes
  1809. were made to <a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18920">bpo-18920</a>) and other modules that have
  1810. script-like invocation capabilities (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18922">bpo-18922</a>).</p></li>
  1811. <li><p>The CPython Windows installer now adds <code class="docutils literal notranslate"><span class="pre">.py</span></code> to the <span class="target" id="index-50"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATHEXT</span></code>
  1812. variable when extensions are registered, allowing users to run a python
  1813. script at the windows command prompt by just typing its name without the
  1814. <code class="docutils literal notranslate"><span class="pre">.py</span></code> extension. (Contributed by Paul Moore in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18569">bpo-18569</a>.)</p></li>
  1815. <li><p>A new <code class="docutils literal notranslate"><span class="pre">make</span></code> target <a class="reference external" href="https://devguide.python.org/coverage/#measuring-coverage-of-c-code-with-gcov-and-lcov">coverage-report</a>
  1816. will build python, run the test suite, and generate an HTML coverage report
  1817. for the C codebase using <code class="docutils literal notranslate"><span class="pre">gcov</span></code> and <a class="reference external" href="https://ltp.sourceforge.net/coverage/lcov.php">lcov</a>.</p></li>
  1818. <li><p>The <code class="docutils literal notranslate"><span class="pre">-R</span></code> option to the <a class="reference internal" href="../library/test.html#regrtest"><span class="std std-ref">python regression test suite</span></a> now
  1819. also checks for memory allocation leaks, using
  1820. <a class="reference internal" href="../library/sys.html#sys.getallocatedblocks" title="sys.getallocatedblocks"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getallocatedblocks()</span></code></a>. (Contributed by Antoine Pitrou in
  1821. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13390">bpo-13390</a>.)</p></li>
  1822. <li><p><code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span></code> now works with namespace packages.</p></li>
  1823. <li><p>The <a class="reference internal" href="../library/stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> module is now implemented in C, which means it gets the
  1824. values for its constants from the C header files, instead of having the
  1825. values hard-coded in the python module as was previously the case.</p></li>
  1826. <li><p>Loading multiple python modules from a single OS module (<code class="docutils literal notranslate"><span class="pre">.so</span></code>, <code class="docutils literal notranslate"><span class="pre">.dll</span></code>)
  1827. now works correctly (previously it silently returned the first python
  1828. module in the file). (Contributed by Václav Šmilauer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16421">bpo-16421</a>.)</p></li>
  1829. <li><p>A new opcode, <code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_CLASSDEREF</span></code>, has been added to fix a bug in the
  1830. loading of free variables in class bodies that could be triggered by certain
  1831. uses of <a class="reference internal" href="../reference/datamodel.html#prepare"><span class="std std-ref">__prepare__</span></a>. (Contributed by Benjamin Peterson in
  1832. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17853">bpo-17853</a>.)</p></li>
  1833. <li><p>A number of MemoryError-related crashes were identified and fixed by Victor
  1834. Stinner using his <span class="target" id="index-51"></span><a class="pep reference external" href="https://peps.python.org/pep-0445/"><strong>PEP 445</strong></a>-based <code class="docutils literal notranslate"><span class="pre">pyfailmalloc</span></code> tool (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18408">bpo-18408</a>,
  1835. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18520">bpo-18520</a>).</p></li>
  1836. <li><p>The <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> command now accepts a <code class="docutils literal notranslate"><span class="pre">--copies</span></code> option
  1837. to use copies rather than symlinks even on systems where symlinks are the
  1838. default. (Contributed by Vinay Sajip in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18807">bpo-18807</a>.)</p></li>
  1839. <li><p>The <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> command also accepts a <code class="docutils literal notranslate"><span class="pre">--without-pip</span></code>
  1840. option to suppress the otherwise-automatic bootstrapping of pip into
  1841. the virtual environment. (Contributed by Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19552">bpo-19552</a>
  1842. as part of the <span class="target" id="index-52"></span><a class="pep reference external" href="https://peps.python.org/pep-0453/"><strong>PEP 453</strong></a> implementation.)</p></li>
  1843. <li><p>The encoding name is now optional in the value set for the
  1844. <span class="target" id="index-53"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONIOENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONIOENCODING</span></code></a> environment variable. This makes it possible to
  1845. set just the error handler, without changing the default encoding.
  1846. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18818">bpo-18818</a>.)</p></li>
  1847. <li><p>The <a class="reference internal" href="../library/bz2.html#module-bz2" title="bz2: Interfaces for bzip2 compression and decompression."><code class="xref py py-mod docutils literal notranslate"><span class="pre">bz2</span></code></a>, <a class="reference internal" href="../library/lzma.html#module-lzma" title="lzma: A Python wrapper for the liblzma compression library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">lzma</span></code></a>, and <a class="reference internal" href="../library/gzip.html#module-gzip" title="gzip: Interfaces for gzip compression and decompression using file objects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">gzip</span></code></a> module <code class="docutils literal notranslate"><span class="pre">open</span></code> functions now
  1848. support <code class="docutils literal notranslate"><span class="pre">x</span></code> (exclusive creation) mode. (Contributed by Tim Heaney and
  1849. Vajrasky Kok in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19201">bpo-19201</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19222">bpo-19222</a>, and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19223">bpo-19223</a>.)</p></li>
  1850. </ul>
  1851. </section>
  1852. <section id="significant-optimizations">
  1853. <h3>Significant Optimizations<a class="headerlink" href="#significant-optimizations" title="Link to this heading">¶</a></h3>
  1854. <ul class="simple">
  1855. <li><p>The UTF-32 decoder is now 3x to 4x faster. (Contributed by Serhiy Storchaka
  1856. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14625">bpo-14625</a>.)</p></li>
  1857. <li><p>The cost of hash collisions for sets is now reduced. Each hash table
  1858. probe now checks a series of consecutive, adjacent key/hash pairs before
  1859. continuing to make random probes through the hash table. This exploits
  1860. cache locality to make collision resolution less expensive.
  1861. The collision resolution scheme can be described as a hybrid of linear
  1862. probing and open addressing. The number of additional linear probes
  1863. defaults to nine. This can be changed at compile-time by defining
  1864. LINEAR_PROBES to be any value. Set LINEAR_PROBES=0 to turn-off
  1865. linear probing entirely. (Contributed by Raymond Hettinger in
  1866. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18771">bpo-18771</a>.)</p></li>
  1867. <li><p>The interpreter starts about 30% faster. A couple of measures lead to the
  1868. speedup. The interpreter loads fewer modules on startup, e.g. 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>,
  1869. <a class="reference internal" href="../library/collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a> and <a class="reference internal" href="../library/locale.html#module-locale" title="locale: Internationalization services."><code class="xref py py-mod docutils literal notranslate"><span class="pre">locale</span></code></a> modules and their dependencies are no
  1870. longer imported by default. The marshal module has been improved to load
  1871. compiled Python code faster. (Contributed by Antoine Pitrou, Christian
  1872. Heimes and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19219">bpo-19219</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19218">bpo-19218</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19209">bpo-19209</a>,
  1873. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19205">bpo-19205</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9548">bpo-9548</a>.)</p></li>
  1874. <li><p><a class="reference internal" href="../library/bz2.html#bz2.BZ2File" title="bz2.BZ2File"><code class="xref py py-class docutils literal notranslate"><span class="pre">bz2.BZ2File</span></code></a> is now as fast or faster than the Python2 version for
  1875. most cases. <a class="reference internal" href="../library/lzma.html#lzma.LZMAFile" title="lzma.LZMAFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">lzma.LZMAFile</span></code></a> has also been optimized. (Contributed by
  1876. Serhiy Storchaka and Nadeem Vawda in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16034">bpo-16034</a>.)</p></li>
  1877. <li><p><a class="reference internal" href="../library/random.html#random.getrandbits" title="random.getrandbits"><code class="xref py py-func docutils literal notranslate"><span class="pre">random.getrandbits()</span></code></a> is 20%-40% faster for small integers (the most
  1878. common use case). (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16674">bpo-16674</a>.)</p></li>
  1879. <li><p>By taking advantage of the new storage format for strings, pickling of
  1880. strings is now significantly faster. (Contributed by Victor Stinner and
  1881. Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15596">bpo-15596</a>.)</p></li>
  1882. <li><p>A performance issue in <code class="xref py py-meth docutils literal notranslate"><span class="pre">io.FileIO.readall()</span></code> has been solved. This
  1883. particularly affects Windows, and significantly speeds up the case of piping
  1884. significant amounts of data through <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a>. (Contributed
  1885. by Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15758">bpo-15758</a>.)</p></li>
  1886. <li><p><a class="reference internal" href="../library/html.html#html.escape" title="html.escape"><code class="xref py py-func docutils literal notranslate"><span class="pre">html.escape()</span></code></a> is now 10x faster. (Contributed by Matt Bryant in
  1887. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18020">bpo-18020</a>.)</p></li>
  1888. <li><p>On Windows, the native <code class="docutils literal notranslate"><span class="pre">VirtualAlloc</span></code> is now used instead of the CRT
  1889. <code class="docutils literal notranslate"><span class="pre">malloc</span></code> in <code class="docutils literal notranslate"><span class="pre">obmalloc</span></code>. Artificial benchmarks show about a 3% memory
  1890. savings.</p></li>
  1891. <li><p><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 a lazily opened persistent file descriptor
  1892. so as to avoid using many file descriptors when run in parallel from
  1893. multiple threads. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18756">bpo-18756</a>.)</p></li>
  1894. </ul>
  1895. </section>
  1896. </section>
  1897. <section id="deprecated">
  1898. <span id="deprecated-3-4"></span><h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading">¶</a></h2>
  1899. <p>This section covers various APIs and other features that have been deprecated
  1900. in Python 3.4, and will be removed in Python 3.5 or later. In most (but not
  1901. all) cases, using the deprecated APIs will 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>
  1902. when the interpreter is run with deprecation warnings enabled (for example, by
  1903. using <code class="docutils literal notranslate"><span class="pre">-Wd</span></code>).</p>
  1904. <section id="deprecations-in-the-python-api">
  1905. <h3>Deprecations in the Python API<a class="headerlink" href="#deprecations-in-the-python-api" title="Link to this heading">¶</a></h3>
  1906. <ul class="simple">
  1907. <li><p>As mentioned in <a class="reference internal" href="#whatsnew-pep-451"><span class="std std-ref">PEP 451: A ModuleSpec Type for the Import System</span></a>, a number of <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a>
  1908. methods and functions are deprecated: <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.find_loader()</span></code> is
  1909. replaced by <a class="reference internal" href="../library/importlib.html#importlib.util.find_spec" title="importlib.util.find_spec"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.find_spec()</span></code></a>;
  1910. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.PathFinder.find_module()</span></code> is replaced by
  1911. <a class="reference internal" href="../library/importlib.html#importlib.machinery.PathFinder.find_spec" title="importlib.machinery.PathFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.PathFinder.find_spec()</span></code></a>;
  1912. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder.find_module()</span></code> is replaced by
  1913. <a class="reference internal" href="../library/importlib.html#importlib.abc.MetaPathFinder.find_spec" title="importlib.abc.MetaPathFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder.find_spec()</span></code></a>;
  1914. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_loader()</span></code> and
  1915. <code class="xref py py-meth docutils literal notranslate"><span class="pre">find_module()</span></code> are replaced by
  1916. <a class="reference internal" href="../library/importlib.html#importlib.abc.PathEntryFinder.find_spec" title="importlib.abc.PathEntryFinder.find_spec"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder.find_spec()</span></code></a>; all of the <code class="samp docutils literal notranslate"><em><span class="pre">xxx</span></em><span class="pre">Loader</span></code> ABC
  1917. <code class="docutils literal notranslate"><span class="pre">load_module</span></code> methods (<code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.load_module()</span></code>,
  1918. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.InspectLoader.load_module()</span></code>,
  1919. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.FileLoader.load_module()</span></code>,
  1920. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.SourceLoader.load_module()</span></code>) should no longer be
  1921. implemented, instead loaders should implement an
  1922. <code class="docutils literal notranslate"><span class="pre">exec_module</span></code> method
  1923. (<a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.exec_module" title="importlib.abc.Loader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.exec_module()</span></code></a>,
  1924. <a class="reference internal" href="../library/importlib.html#importlib.abc.InspectLoader.exec_module" title="importlib.abc.InspectLoader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.InspectLoader.exec_module()</span></code></a>
  1925. <a class="reference internal" href="../library/importlib.html#importlib.abc.SourceLoader.exec_module" title="importlib.abc.SourceLoader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.SourceLoader.exec_module()</span></code></a>) and let the import system
  1926. take care of the rest; and
  1927. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.module_repr()</span></code>,
  1928. <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.util.module_for_loader()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.util.set_loader()</span></code>,
  1929. and <code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.util.set_package()</span></code> are no longer needed because their
  1930. functions are now handled automatically by the import system.</p></li>
  1931. <li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> module is pending deprecation. To keep compatibility with
  1932. Python 2/3 code bases, the module’s removal is currently not scheduled.</p></li>
  1933. <li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">formatter</span></code> module is pending deprecation and is slated for removal
  1934. in Python 3.6.</p></li>
  1935. <li><p><code class="docutils literal notranslate"><span class="pre">MD5</span></code> as the default <em>digestmod</em> for the <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">hmac.new()</span></code></a> function is
  1936. deprecated. Python 3.6 will require an explicit digest name or constructor as
  1937. <em>digestmod</em> argument.</p></li>
  1938. <li><p>The internal <code class="docutils literal notranslate"><span class="pre">Netrc</span></code> class in the <a class="reference internal" href="../library/ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a> module has been documented
  1939. as deprecated in its docstring for quite some time. It now emits a
  1940. <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 completely in Python 3.5.</p></li>
  1941. <li><p>The undocumented <em>endtime</em> argument to <a class="reference internal" href="../library/subprocess.html#subprocess.Popen.wait" title="subprocess.Popen.wait"><code class="xref py py-meth docutils literal notranslate"><span class="pre">subprocess.Popen.wait()</span></code></a> should
  1942. not have been exposed and is hopefully not in use; it is deprecated and
  1943. will mostly likely be removed in Python 3.5.</p></li>
  1944. <li><p>The <em>strict</em> argument of <a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> is deprecated.</p></li>
  1945. <li><p>The <a class="reference internal" href="../library/plistlib.html#module-plistlib" title="plistlib: Generate and parse Apple plist files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code></a> <code class="xref py py-func docutils literal notranslate"><span class="pre">readPlist()</span></code>,
  1946. <code class="xref py py-func docutils literal notranslate"><span class="pre">writePlist()</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">readPlistFromBytes()</span></code>, and
  1947. <code class="xref py py-func docutils literal notranslate"><span class="pre">writePlistToBytes()</span></code> functions are deprecated in favor of the
  1948. corresponding new functions <a class="reference internal" href="../library/plistlib.html#plistlib.load" title="plistlib.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">load()</span></code></a>, <a class="reference internal" href="../library/plistlib.html#plistlib.dump" title="plistlib.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump()</span></code></a>,
  1949. <a class="reference internal" href="../library/plistlib.html#plistlib.loads" title="plistlib.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">loads()</span></code></a>, and <a class="reference internal" href="../library/plistlib.html#plistlib.dumps" title="plistlib.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">dumps()</span></code></a>. <code class="xref py py-func docutils literal notranslate"><span class="pre">Data()</span></code>
  1950. is deprecated in favor of just using the <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> constructor.</p></li>
  1951. <li><p>The <a class="reference internal" href="../library/sysconfig.html#module-sysconfig" title="sysconfig: Python's configuration information"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sysconfig</span></code></a> key <code class="docutils literal notranslate"><span class="pre">SO</span></code> is deprecated, it has been replaced by
  1952. <code class="docutils literal notranslate"><span class="pre">EXT_SUFFIX</span></code>.</p></li>
  1953. <li><p>The <code class="docutils literal notranslate"><span class="pre">U</span></code> mode accepted by various <code class="docutils literal notranslate"><span class="pre">open</span></code> functions is deprecated.
  1954. In Python3 it does not do anything useful, and should be replaced by
  1955. appropriate uses of <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.TextIOWrapper</span></code></a> (if needed) and its <em>newline</em>
  1956. argument.</p></li>
  1957. <li><p>The <em>parser</em> argument of <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.iterparse" title="xml.etree.ElementTree.iterparse"><code class="xref py py-func docutils literal notranslate"><span class="pre">xml.etree.ElementTree.iterparse()</span></code></a> has
  1958. been deprecated, as has the <em>html</em> argument of
  1959. <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.XMLParser" title="xml.etree.ElementTree.XMLParser"><code class="xref py py-func docutils literal notranslate"><span class="pre">XMLParser()</span></code></a>. To prepare for the removal of the
  1960. latter, all arguments to <code class="docutils literal notranslate"><span class="pre">XMLParser</span></code> should be passed by keyword.</p></li>
  1961. </ul>
  1962. </section>
  1963. <section id="deprecated-features">
  1964. <h3>Deprecated Features<a class="headerlink" href="#deprecated-features" title="Link to this heading">¶</a></h3>
  1965. <ul class="simple">
  1966. <li><p>Running <a class="reference internal" href="../library/idle.html#idle"><span class="std std-ref">IDLE</span></a> with the <code class="docutils literal notranslate"><span class="pre">-n</span></code> flag (no subprocess) is deprecated.
  1967. However, the feature will not be removed until <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18823">bpo-18823</a> is resolved.</p></li>
  1968. <li><p>The site module adding a “site-python” directory to sys.path, if it
  1969. exists, is deprecated (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19375">bpo-19375</a>).</p></li>
  1970. </ul>
  1971. </section>
  1972. </section>
  1973. <section id="removed">
  1974. <h2>Removed<a class="headerlink" href="#removed" title="Link to this heading">¶</a></h2>
  1975. <section id="operating-systems-no-longer-supported">
  1976. <h3>Operating Systems No Longer Supported<a class="headerlink" href="#operating-systems-no-longer-supported" title="Link to this heading">¶</a></h3>
  1977. <p>Support for the following operating systems has been removed from the source
  1978. and build tools:</p>
  1979. <ul class="simple">
  1980. <li><p>OS/2 (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16135">bpo-16135</a>).</p></li>
  1981. <li><p>Windows 2000 (changeset e52df05b496a).</p></li>
  1982. <li><p>Windows systems where <code class="docutils literal notranslate"><span class="pre">COMSPEC</span></code> points to <code class="docutils literal notranslate"><span class="pre">command.com</span></code> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14470">bpo-14470</a>).</p></li>
  1983. <li><p>VMS (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16136">bpo-16136</a>).</p></li>
  1984. </ul>
  1985. </section>
  1986. <section id="api-and-feature-removals">
  1987. <h3>API and Feature Removals<a class="headerlink" href="#api-and-feature-removals" title="Link to this heading">¶</a></h3>
  1988. <p>The following obsolete and previously deprecated APIs and features have been
  1989. removed:</p>
  1990. <ul class="simple">
  1991. <li><p>The unmaintained <code class="docutils literal notranslate"><span class="pre">Misc/TextMate</span></code> and <code class="docutils literal notranslate"><span class="pre">Misc/vim</span></code> directories have been
  1992. removed (see the <a class="reference external" href="https://devguide.python.org">devguide</a>
  1993. for suggestions on what to use instead).</p></li>
  1994. <li><p>The <code class="docutils literal notranslate"><span class="pre">SO</span></code> makefile macro is removed (it was replaced by the
  1995. <code class="docutils literal notranslate"><span class="pre">SHLIB_SUFFIX</span></code> and <code class="docutils literal notranslate"><span class="pre">EXT_SUFFIX</span></code> macros) (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16754">bpo-16754</a>).</p></li>
  1996. <li><p>The <code class="docutils literal notranslate"><span class="pre">PyThreadState.tick_counter</span></code> field has been removed; its value has
  1997. been meaningless since Python 3.2, when the “new GIL” was introduced
  1998. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19199">bpo-19199</a>).</p></li>
  1999. <li><p><code class="docutils literal notranslate"><span class="pre">PyLoader</span></code> and <code class="docutils literal notranslate"><span class="pre">PyPycLoader</span></code> have been removed from <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a>.
  2000. (Contributed by Taras Lyapun in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15641">bpo-15641</a>.)</p></li>
  2001. <li><p>The <em>strict</em> argument to <a class="reference internal" href="../library/http.client.html#http.client.HTTPConnection" title="http.client.HTTPConnection"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPConnection</span></code></a> and
  2002. <a class="reference internal" href="../library/http.client.html#http.client.HTTPSConnection" title="http.client.HTTPSConnection"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPSConnection</span></code></a> has been removed. HTTP 0.9-style
  2003. “Simple Responses” are no longer supported.</p></li>
  2004. <li><p>The deprecated <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request" title="urllib.request.Request"><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request.Request</span></code></a> getter and setter methods
  2005. <code class="docutils literal notranslate"><span class="pre">add_data</span></code>, <code class="docutils literal notranslate"><span class="pre">has_data</span></code>, <code class="docutils literal notranslate"><span class="pre">get_data</span></code>, <code class="docutils literal notranslate"><span class="pre">get_type</span></code>, <code class="docutils literal notranslate"><span class="pre">get_host</span></code>,
  2006. <code class="docutils literal notranslate"><span class="pre">get_selector</span></code>, <code class="docutils literal notranslate"><span class="pre">set_proxy</span></code>, <code class="docutils literal notranslate"><span class="pre">get_origin_req_host</span></code>, and
  2007. <code class="docutils literal notranslate"><span class="pre">is_unverifiable</span></code> have been removed (use direct attribute access instead).</p></li>
  2008. <li><p>Support for loading the deprecated <code class="docutils literal notranslate"><span class="pre">TYPE_INT64</span></code> has been removed from
  2009. <a class="reference internal" href="../library/marshal.html#module-marshal" title="marshal: Convert Python objects to streams of bytes and back (with different constraints)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">marshal</span></code></a>. (Contributed by Dan Riti in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15480">bpo-15480</a>.)</p></li>
  2010. <li><p><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>: positional-only parameters are now required
  2011. to have a valid name.</p></li>
  2012. <li><p><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">object.__format__()</span></code></a> no longer accepts non-empty format strings, it now
  2013. raises 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> instead. Using a non-empty string has been
  2014. deprecated since Python 3.2. This change has been made to prevent a
  2015. situation where previously working (but incorrect) code would start failing
  2016. if an object gained a __format__ method, which means that your code may now
  2017. raise a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> if you are using an <code class="docutils literal notranslate"><span class="pre">'s'</span></code> format code with objects
  2018. that do not have a __format__ method that handles it. See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=7994">bpo-7994</a> for
  2019. background.</p></li>
  2020. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">difflib.SequenceMatcher.isbjunk()</span></code> and
  2021. <code class="xref py py-meth docutils literal notranslate"><span class="pre">difflib.SequenceMatcher.isbpopular()</span></code> were deprecated in 3.2, and have
  2022. now been removed: use <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">in</span> <span class="pre">sm.bjunk</span></code> and
  2023. <code class="docutils literal notranslate"><span class="pre">x</span> <span class="pre">in</span> <span class="pre">sm.bpopular</span></code>, where <em>sm</em> is a <a class="reference internal" href="../library/difflib.html#difflib.SequenceMatcher" title="difflib.SequenceMatcher"><code class="xref py py-class docutils literal notranslate"><span class="pre">SequenceMatcher</span></code></a> object
  2024. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13248">bpo-13248</a>).</p></li>
  2025. </ul>
  2026. </section>
  2027. <section id="code-cleanups">
  2028. <h3>Code Cleanups<a class="headerlink" href="#code-cleanups" title="Link to this heading">¶</a></h3>
  2029. <ul class="simple">
  2030. <li><p>The unused and undocumented internal <code class="docutils literal notranslate"><span class="pre">Scanner</span></code> class has been removed from
  2031. the <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> module.</p></li>
  2032. <li><p>The private and effectively unused <code class="docutils literal notranslate"><span class="pre">_gestalt</span></code> module has been removed,
  2033. along with the private <a class="reference internal" href="../library/platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><code class="xref py py-mod docutils literal notranslate"><span class="pre">platform</span></code></a> functions <code class="docutils literal notranslate"><span class="pre">_mac_ver_lookup</span></code>,
  2034. <code class="docutils literal notranslate"><span class="pre">_mac_ver_gstalt</span></code>, and <code class="docutils literal notranslate"><span class="pre">_bcd2str</span></code>, which would only have ever been called
  2035. on badly broken OSX systems (see <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18393">bpo-18393</a>).</p></li>
  2036. <li><p>The hardcoded copies of certain <a class="reference internal" href="../library/stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><code class="xref py py-mod docutils literal notranslate"><span class="pre">stat</span></code></a> constants that were included in
  2037. the <a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a> module namespace have been removed.</p></li>
  2038. </ul>
  2039. </section>
  2040. </section>
  2041. <section id="porting-to-python-3-4">
  2042. <h2>Porting to Python 3.4<a class="headerlink" href="#porting-to-python-3-4" title="Link to this heading">¶</a></h2>
  2043. <p>This section lists previously described changes and other bugfixes
  2044. that may require changes to your code.</p>
  2045. <section id="changes-in-python-command-behavior">
  2046. <h3>Changes in ‘python’ Command Behavior<a class="headerlink" href="#changes-in-python-command-behavior" title="Link to this heading">¶</a></h3>
  2047. <ul class="simple">
  2048. <li><p>In a posix shell, setting the <span class="target" id="index-54"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> environment variable to
  2049. an empty value is equivalent to not setting it at all. However, setting
  2050. <span class="target" id="index-55"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a> to an empty value was <em>not</em> equivalent to not setting it
  2051. at all: setting <span class="target" id="index-56"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a> to an empty value was equivalent to
  2052. setting it to <code class="docutils literal notranslate"><span class="pre">.</span></code>, which leads to confusion when reasoning by analogy to
  2053. how <span class="target" id="index-57"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code> works. The behavior now conforms to the posix convention
  2054. for <span class="target" id="index-58"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code>.</p></li>
  2055. <li><p>The [X refs, Y blocks] output of a debug (<code class="docutils literal notranslate"><span class="pre">--with-pydebug</span></code>) build of the
  2056. CPython interpreter is now off by default. It can be re-enabled using the
  2057. <code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">showrefcount</span></code> option. (Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17323">bpo-17323</a>.)</p></li>
  2058. <li><p>The python command and most stdlib scripts (as well as <a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a>) now
  2059. output <code class="docutils literal notranslate"><span class="pre">--version</span></code> information to <code class="docutils literal notranslate"><span class="pre">stdout</span></code> instead of <code class="docutils literal notranslate"><span class="pre">stderr</span></code> (for
  2060. issue list see <a class="reference internal" href="#other-improvements-3-4"><span class="std std-ref">Other Improvements</span></a> above).</p></li>
  2061. </ul>
  2062. </section>
  2063. <section id="changes-in-the-python-api">
  2064. <h3>Changes in the Python API<a class="headerlink" href="#changes-in-the-python-api" title="Link to this heading">¶</a></h3>
  2065. <ul class="simple">
  2066. <li><p>The ABCs defined in <a class="reference internal" href="../library/importlib.html#module-importlib.abc" title="importlib.abc: Abstract base classes related to import"><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib.abc</span></code></a> now either raise the appropriate
  2067. exception or return a default value instead of raising
  2068. <a class="reference internal" href="../library/exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> blindly. This will only affect code calling
  2069. <a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a> and falling through all the way to the ABCs. For compatibility,
  2070. catch both <a class="reference internal" href="../library/exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> or the appropriate exception as needed.</p></li>
  2071. <li><p>The module type now initializes the <a class="reference internal" href="../reference/import.html#package__" title="__package__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__package__</span></code></a> and <a class="reference internal" href="../reference/import.html#loader__" title="__loader__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__loader__</span></code></a>
  2072. attributes to <code class="docutils literal notranslate"><span class="pre">None</span></code> by default. To determine if these attributes were set
  2073. in a backwards-compatible fashion, use e.g.
  2074. <code class="docutils literal notranslate"><span class="pre">getattr(module,</span> <span class="pre">'__loader__',</span> <span class="pre">None)</span> <span class="pre">is</span> <span class="pre">not</span> <span class="pre">None</span></code>. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17115">bpo-17115</a>.)</p></li>
  2075. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.util.module_for_loader()</span></code> now sets <code class="docutils literal notranslate"><span class="pre">__loader__</span></code> and
  2076. <code class="docutils literal notranslate"><span class="pre">__package__</span></code> unconditionally to properly support reloading. If this is not
  2077. desired then you will need to set these attributes manually. You can use
  2078. <code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.module_to_load()</span></code> for module management.</p></li>
  2079. <li><p>Import now resets relevant attributes (e.g. <code class="docutils literal notranslate"><span class="pre">__name__</span></code>, <code class="docutils literal notranslate"><span class="pre">__loader__</span></code>,
  2080. <code class="docutils literal notranslate"><span class="pre">__package__</span></code>, <code class="docutils literal notranslate"><span class="pre">__file__</span></code>, <code class="docutils literal notranslate"><span class="pre">__cached__</span></code>) unconditionally when reloading.
  2081. Note that this restores a pre-3.3 behavior in that it means a module is
  2082. re-found when re-loaded (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19413">bpo-19413</a>).</p></li>
  2083. <li><p>Frozen packages no longer set <code class="docutils literal notranslate"><span class="pre">__path__</span></code> to a list containing the package
  2084. name, they now set it to an empty list. The previous behavior could cause
  2085. the import system to do the wrong thing on submodule imports if there was
  2086. also a directory with the same name as the frozen package. The correct way
  2087. to determine if a module is a package or not is to use <code class="docutils literal notranslate"><span class="pre">hasattr(module,</span>
  2088. <span class="pre">'__path__')</span></code> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18065">bpo-18065</a>).</p></li>
  2089. <li><p>Frozen modules no longer define a <code class="docutils literal notranslate"><span class="pre">__file__</span></code> attribute. It’s semantically
  2090. incorrect for frozen modules to set the attribute as they are not loaded from
  2091. any explicit location. If you must know that a module comes from frozen code
  2092. then you can see if the module’s <code class="docutils literal notranslate"><span class="pre">__spec__.location</span></code> is set to <code class="docutils literal notranslate"><span class="pre">'frozen'</span></code>,
  2093. check if the loader is a subclass of
  2094. <a class="reference internal" href="../library/importlib.html#importlib.machinery.FrozenImporter" title="importlib.machinery.FrozenImporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.FrozenImporter</span></code></a>,
  2095. or if Python 2 compatibility is necessary you can use <code class="xref py py-func docutils literal notranslate"><span class="pre">imp.is_frozen()</span></code>.</p></li>
  2096. <li><p><a class="reference internal" href="../library/py_compile.html#py_compile.compile" title="py_compile.compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">py_compile.compile()</span></code></a> now raises <a class="reference internal" href="../library/exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> if the file path
  2097. it would write to is a symlink or a non-regular file. This is to act as a
  2098. warning that import will overwrite those files with a regular file regardless
  2099. of what type of file path they were originally.</p></li>
  2100. <li><p><a class="reference internal" href="../library/importlib.html#importlib.abc.SourceLoader.get_source" title="importlib.abc.SourceLoader.get_source"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.SourceLoader.get_source()</span></code></a> no longer raises
  2101. <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> when the source code being loaded triggers a
  2102. <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> or <a class="reference internal" href="../library/exceptions.html#UnicodeDecodeError" title="UnicodeDecodeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">UnicodeDecodeError</span></code></a>. As <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> is
  2103. meant to be raised only when source code cannot be found but it should, it was
  2104. felt to be over-reaching/overloading of that meaning when the source code is
  2105. found but improperly structured. If you were catching ImportError before and
  2106. wish to continue to ignore syntax or decoding issues, catch all three
  2107. exceptions now.</p></li>
  2108. <li><p><a class="reference internal" href="../library/functools.html#functools.update_wrapper" title="functools.update_wrapper"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.update_wrapper()</span></code></a> and <a class="reference internal" href="../library/functools.html#functools.wraps" title="functools.wraps"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.wraps()</span></code></a> now correctly
  2109. set the <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute to the function being wrapped, even if
  2110. that function also had its <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute set. This means
  2111. <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attributes now correctly link a stack of decorated
  2112. functions rather than every <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute in the chain
  2113. referring to the innermost function. Introspection libraries that
  2114. assumed the previous behaviour was intentional can use
  2115. <a class="reference internal" href="../library/inspect.html#inspect.unwrap" title="inspect.unwrap"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.unwrap()</span></code></a> to access the first function in the chain that has
  2116. no <code class="docutils literal notranslate"><span class="pre">__wrapped__</span></code> attribute.</p></li>
  2117. <li><p><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> has been reimplemented on top of
  2118. <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.signature()</span></code></a> and hence handles a much wider variety of callable
  2119. objects than it did in the past. It is expected that additional builtin and
  2120. extension module callables will gain signature metadata over the course of
  2121. the Python 3.4 series. Code that assumes that
  2122. <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> will fail on non-Python callables may need
  2123. to be adjusted accordingly.</p></li>
  2124. <li><p><a class="reference internal" href="../library/importlib.html#importlib.machinery.PathFinder" title="importlib.machinery.PathFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.PathFinder</span></code></a> now passes on the current working
  2125. directory to objects in <a class="reference internal" href="../library/sys.html#sys.path_hooks" title="sys.path_hooks"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_hooks</span></code></a> for the empty string. This
  2126. results in <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> never containing <code class="docutils literal notranslate"><span class="pre">''</span></code>, thus
  2127. iterating through <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> based 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>
  2128. will not find all keys. A module’s <code class="docutils literal notranslate"><span class="pre">__file__</span></code> when imported in the current
  2129. working directory will also now have an absolute path, including when using
  2130. <code class="docutils literal notranslate"><span class="pre">-m</span></code> with the interpreter (except for <code class="docutils literal notranslate"><span class="pre">__main__.__file__</span></code> when a script
  2131. has been executed directly using a relative path) (Contributed by Brett
  2132. Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18416">bpo-18416</a>). is specified on the command-line)
  2133. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18416">bpo-18416</a>).</p></li>
  2134. <li><p>The removal of the <em>strict</em> argument to <a class="reference internal" href="../library/http.client.html#http.client.HTTPConnection" title="http.client.HTTPConnection"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPConnection</span></code></a>
  2135. and <a class="reference internal" href="../library/http.client.html#http.client.HTTPSConnection" title="http.client.HTTPSConnection"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPSConnection</span></code></a> changes the meaning of the
  2136. remaining arguments if you are specifying them positionally rather than by
  2137. keyword. If you’ve been paying attention to deprecation warnings your code
  2138. should already be specifying any additional arguments via keywords.</p></li>
  2139. <li><p>Strings between <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">__future__</span> <span class="pre">import</span> <span class="pre">...</span></code> statements now <em>always</em> raise
  2140. 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>. Previously if there was no leading docstring, an
  2141. interstitial string would sometimes be ignored. This brings CPython into
  2142. compliance with the language spec; Jython and PyPy already were.
  2143. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17434">bpo-17434</a>).</p></li>
  2144. <li><p><a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.getpeercert" title="ssl.SSLSocket.getpeercert"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLSocket.getpeercert()</span></code></a> and <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.do_handshake" title="ssl.SSLSocket.do_handshake"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLSocket.do_handshake()</span></code></a>
  2145. now raise an <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> with <code class="docutils literal notranslate"><span class="pre">ENOTCONN</span></code> when the <code class="docutils literal notranslate"><span class="pre">SSLSocket</span></code> is not
  2146. connected, instead of the previous behavior of raising an
  2147. <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 addition, <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.getpeercert" title="ssl.SSLSocket.getpeercert"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getpeercert()</span></code></a>
  2148. will raise 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 handshake has not yet been done.</p></li>
  2149. <li><p><a class="reference internal" href="../library/base64.html#base64.b32decode" title="base64.b32decode"><code class="xref py py-func docutils literal notranslate"><span class="pre">base64.b32decode()</span></code></a> now raises a <a class="reference internal" href="../library/binascii.html#binascii.Error" title="binascii.Error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">binascii.Error</span></code></a> when the
  2150. input string contains non-b32-alphabet characters, instead of a
  2151. <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a>. This particular <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> was missed when the other
  2152. <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>s were converted. (Contributed by Serhiy Storchaka in
  2153. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18011">bpo-18011</a>.) Note: this change was also inadvertently applied in Python
  2154. 3.3.3.</p></li>
  2155. <li><p>The <code class="xref py py-attr docutils literal notranslate"><span class="pre">file</span></code> attribute is now automatically closed when
  2156. the creating <code class="xref py py-class docutils literal notranslate"><span class="pre">cgi.FieldStorage</span></code> instance is garbage collected. If you
  2157. were pulling the file object out separately from the <code class="xref py py-class docutils literal notranslate"><span class="pre">cgi.FieldStorage</span></code>
  2158. instance and not keeping the instance alive, then you should either store the
  2159. entire <code class="xref py py-class docutils literal notranslate"><span class="pre">cgi.FieldStorage</span></code> instance or read the contents of the file
  2160. before the <code class="xref py py-class docutils literal notranslate"><span class="pre">cgi.FieldStorage</span></code> instance is garbage collected.</p></li>
  2161. <li><p>Calling <code class="docutils literal notranslate"><span class="pre">read</span></code> or <code class="docutils literal notranslate"><span class="pre">write</span></code> on a closed SSL socket now raises an
  2162. informative <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> rather than the previous more mysterious
  2163. <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> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9177">bpo-9177</a>).</p></li>
  2164. <li><p><a class="reference internal" href="../reference/datamodel.html#slice.indices" title="slice.indices"><code class="xref py py-meth docutils literal notranslate"><span class="pre">slice.indices()</span></code></a> no longer produces an <a class="reference internal" href="../library/exceptions.html#OverflowError" title="OverflowError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OverflowError</span></code></a> for huge
  2165. values. As a consequence of this fix, <a class="reference internal" href="../reference/datamodel.html#slice.indices" title="slice.indices"><code class="xref py py-meth docutils literal notranslate"><span class="pre">slice.indices()</span></code></a> now raises a
  2166. <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 given a negative length; previously it returned nonsense
  2167. values (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14794">bpo-14794</a>).</p></li>
  2168. <li><p>The <a class="reference internal" href="../library/functions.html#complex" title="complex"><code class="xref py py-class docutils literal notranslate"><span class="pre">complex</span></code></a> constructor, unlike the <a class="reference internal" href="../library/cmath.html#module-cmath" title="cmath: Mathematical functions for complex numbers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">cmath</span></code></a> functions, was
  2169. incorrectly accepting <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> values if an object’s <code class="docutils literal notranslate"><span class="pre">__complex__</span></code>
  2170. special method returned one. This now raises 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>.
  2171. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16290">bpo-16290</a>.)</p></li>
  2172. <li><p>The <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> constructor in 3.2 and 3.3 erroneously accepts <a class="reference internal" href="../library/functions.html#float" title="float"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>
  2173. values for the <em>base</em> parameter. It is unlikely anyone was doing this, but
  2174. if so, it will now raise a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16772">bpo-16772</a>).</p></li>
  2175. <li><p>Defaults for keyword-only arguments are now evaluated <em>after</em> defaults for
  2176. regular keyword arguments, instead of before. Hopefully no one wrote any
  2177. code that depends on the previous buggy behavior (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16967">bpo-16967</a>).</p></li>
  2178. <li><p>Stale thread states are now cleared after <a class="reference internal" href="../library/os.html#os.fork" title="os.fork"><code class="xref py py-func docutils literal notranslate"><span class="pre">fork()</span></code></a>. This may cause
  2179. some system resources to be released that previously were incorrectly kept
  2180. perpetually alive (for example, database connections kept in thread-local
  2181. storage). (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17094">bpo-17094</a>.)</p></li>
  2182. <li><p>Parameter names in <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code> dicts are now mangled properly,
  2183. similarly to <a class="reference internal" href="../reference/datamodel.html#function.__kwdefaults__" title="function.__kwdefaults__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__kwdefaults__</span></code></a>.
  2184. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20625">bpo-20625</a>.)</p></li>
  2185. <li><p><a class="reference internal" href="../library/hashlib.html#hashlib.hash.name" title="hashlib.hash.name"><code class="xref py py-attr docutils literal notranslate"><span class="pre">hashlib.hash.name</span></code></a> now always returns the identifier in lower case.
  2186. Previously some builtin hashes had uppercase names, but now that it is a
  2187. formal public interface the naming has been made consistent (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18532">bpo-18532</a>).</p></li>
  2188. <li><p>Because <a class="reference internal" href="../library/unittest.html#unittest.TestSuite" title="unittest.TestSuite"><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest.TestSuite</span></code></a> now drops references to tests after they
  2189. are run, test harnesses that re-use a <a class="reference internal" href="../library/unittest.html#unittest.TestSuite" title="unittest.TestSuite"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestSuite</span></code></a> to re-run
  2190. a set of tests may fail. Test suites should not be re-used in this fashion
  2191. since it means state is retained between test runs, breaking the test
  2192. isolation that <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> is designed to provide. However, if the lack
  2193. of isolation is considered acceptable, the old behavior can be restored by
  2194. creating a <a class="reference internal" href="../library/unittest.html#unittest.TestSuite" title="unittest.TestSuite"><code class="xref py py-mod docutils literal notranslate"><span class="pre">TestSuite</span></code></a> subclass that defines a
  2195. <code class="docutils literal notranslate"><span class="pre">_removeTestAtIndex</span></code> method that does nothing (see
  2196. <a class="reference internal" href="../library/unittest.html#unittest.TestSuite.__iter__" title="unittest.TestSuite.__iter__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">TestSuite.__iter__()</span></code></a>) (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11798">bpo-11798</a>).</p></li>
  2197. <li><p><a class="reference internal" href="../library/unittest.html#module-unittest" title="unittest: Unit testing framework for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unittest</span></code></a> now uses <a class="reference internal" href="../library/argparse.html#module-argparse" title="argparse: Command-line option and argument parsing library."><code class="xref py py-mod docutils literal notranslate"><span class="pre">argparse</span></code></a> for command line parsing. There are
  2198. certain invalid command forms that used to work that are no longer allowed;
  2199. in theory this should not cause backward compatibility issues since the
  2200. disallowed command forms didn’t make any sense and are unlikely to be in use.</p></li>
  2201. <li><p>The <a class="reference internal" href="../library/re.html#re.split" title="re.split"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.split()</span></code></a>, <a class="reference internal" href="../library/re.html#re.findall" title="re.findall"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.findall()</span></code></a>, and <a class="reference internal" href="../library/re.html#re.sub" title="re.sub"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.sub()</span></code></a> functions, and
  2202. the <code class="xref py py-meth docutils literal notranslate"><span class="pre">group()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">groups()</span></code> methods of
  2203. <code class="docutils literal notranslate"><span class="pre">match</span></code> objects now always return a <em>bytes</em> object when the string
  2204. to be matched is a <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like object</span></a>. Previously the return type
  2205. matched the input type, so if your code was depending on the return value
  2206. being, say, a <code class="docutils literal notranslate"><span class="pre">bytearray</span></code>, you will need to change your code.</p></li>
  2207. <li><p><a class="reference internal" href="../library/audioop.html#module-audioop" title="audioop: Manipulate raw audio data. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">audioop</span></code></a> functions now raise an error immediately if passed string
  2208. input, instead of failing randomly later on (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16685">bpo-16685</a>).</p></li>
  2209. <li><p>The new <em>convert_charrefs</em> argument to <a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a>
  2210. currently defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code> for backward compatibility, but will
  2211. eventually be changed to default to <code class="docutils literal notranslate"><span class="pre">True</span></code>. It is recommended that you add
  2212. this keyword, with the appropriate value, to any
  2213. <a class="reference internal" href="../library/html.parser.html#html.parser.HTMLParser" title="html.parser.HTMLParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTMLParser</span></code></a> calls in your code (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13633">bpo-13633</a>).</p></li>
  2214. <li><p>Since the <em>digestmod</em> argument to the <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">hmac.new()</span></code></a> function will in the
  2215. future have no default, all calls to <a class="reference internal" href="../library/hmac.html#hmac.new" title="hmac.new"><code class="xref py py-func docutils literal notranslate"><span class="pre">hmac.new()</span></code></a> should be changed to
  2216. explicitly specify a <em>digestmod</em> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17276">bpo-17276</a>).</p></li>
  2217. <li><p>Calling <a class="reference internal" href="../library/sysconfig.html#sysconfig.get_config_var" title="sysconfig.get_config_var"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconfig.get_config_var()</span></code></a> with the <code class="docutils literal notranslate"><span class="pre">SO</span></code> key, or looking
  2218. <code class="docutils literal notranslate"><span class="pre">SO</span></code> up in the results of a call to <a class="reference internal" href="../library/sysconfig.html#sysconfig.get_config_vars" title="sysconfig.get_config_vars"><code class="xref py py-func docutils literal notranslate"><span class="pre">sysconfig.get_config_vars()</span></code></a>
  2219. is deprecated. This key should be replaced by <code class="docutils literal notranslate"><span class="pre">EXT_SUFFIX</span></code> or
  2220. <code class="docutils literal notranslate"><span class="pre">SHLIB_SUFFIX</span></code>, depending on the context (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19555">bpo-19555</a>).</p></li>
  2221. <li><p>Any calls to <code class="docutils literal notranslate"><span class="pre">open</span></code> functions that specify <code class="docutils literal notranslate"><span class="pre">U</span></code> should be modified.
  2222. <code class="docutils literal notranslate"><span class="pre">U</span></code> is ineffective in Python3 and will eventually raise an error if used.
  2223. Depending on the function, the equivalent of its old Python2 behavior can be
  2224. achieved using either a <em>newline</em> argument, or if necessary by wrapping the
  2225. stream in <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-mod docutils literal notranslate"><span class="pre">TextIOWrapper</span></code></a> to use its <em>newline</em> argument
  2226. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15204">bpo-15204</a>).</p></li>
  2227. <li><p>If you use <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> in a script and desire that pip
  2228. <em>not</em> be installed, you must add <code class="docutils literal notranslate"><span class="pre">--without-pip</span></code> to your command
  2229. invocation.</p></li>
  2230. <li><p>The default behavior of <a class="reference internal" href="../library/json.html#json.dump" title="json.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.dump()</span></code></a> and <a class="reference internal" href="../library/json.html#json.dumps" title="json.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.dumps()</span></code></a> when
  2231. an indent is specified has changed: it no longer produces trailing
  2232. spaces after the item separating commas at the ends of lines. This
  2233. will matter only if you have tests that are doing white-space-sensitive
  2234. comparisons of such output (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16333">bpo-16333</a>).</p></li>
  2235. <li><p><a class="reference internal" href="../library/doctest.html#module-doctest" title="doctest: Test pieces of code within docstrings."><code class="xref py py-mod docutils literal notranslate"><span class="pre">doctest</span></code></a> now looks for doctests in extension module <code class="docutils literal notranslate"><span class="pre">__doc__</span></code>
  2236. strings, so if your doctest test discovery includes extension modules that
  2237. have things that look like doctests in them you may see test failures you’ve
  2238. never seen before when running your tests (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=3158">bpo-3158</a>).</p></li>
  2239. <li><p>The <a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a> module has been slightly refactored as
  2240. part of the Python startup improvements. As a consequence of this, it is no
  2241. longer the case that importing <a class="reference internal" href="../library/collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a> automatically imports
  2242. <a class="reference internal" href="../library/collections.abc.html#module-collections.abc" title="collections.abc: Abstract base classes for containers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections.abc</span></code></a>. If your program depended on the (undocumented)
  2243. implicit import, you will need to add an explicit <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">collections.abc</span></code>
  2244. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20784">bpo-20784</a>).</p></li>
  2245. </ul>
  2246. </section>
  2247. <section id="changes-in-the-c-api">
  2248. <h3>Changes in the C API<a class="headerlink" href="#changes-in-the-c-api" title="Link to this heading">¶</a></h3>
  2249. <ul class="simple">
  2250. <li><p><a class="reference internal" href="../c-api/veryhigh.html#c.PyEval_EvalFrameEx" title="PyEval_EvalFrameEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyEval_EvalFrameEx()</span></code></a>, <a class="reference internal" href="../c-api/object.html#c.PyObject_Repr" title="PyObject_Repr"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Repr()</span></code></a>, and
  2251. <a class="reference internal" href="../c-api/object.html#c.PyObject_Str" title="PyObject_Str"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Str()</span></code></a>, along with some other internal C APIs, now include
  2252. a debugging assertion that ensures they are not used in situations where
  2253. they may silently discard a currently active exception. In cases where
  2254. discarding the active exception is expected and desired (for example,
  2255. because it has already been saved locally with <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Fetch" title="PyErr_Fetch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Fetch()</span></code></a> or
  2256. is being deliberately replaced with a different exception), an explicit
  2257. <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_Clear" title="PyErr_Clear"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_Clear()</span></code></a> call will be needed to avoid triggering the
  2258. assertion when invoking these operations (directly or indirectly) and
  2259. running against a version of Python that is compiled with assertions
  2260. enabled.</p></li>
  2261. <li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetImportError" title="PyErr_SetImportError"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetImportError()</span></code></a> now sets <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> when its <strong>msg</strong>
  2262. argument is not set. Previously only <code class="docutils literal notranslate"><span class="pre">NULL</span></code> was returned with no exception
  2263. set.</p></li>
  2264. <li><p>The result of the <a class="reference internal" href="../c-api/veryhigh.html#c.PyOS_ReadlineFunctionPointer" title="PyOS_ReadlineFunctionPointer"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyOS_ReadlineFunctionPointer</span></code></a> callback must
  2265. now be a string allocated by <a class="reference internal" href="../c-api/memory.html#c.PyMem_RawMalloc" title="PyMem_RawMalloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawMalloc()</span></code></a> or
  2266. <a class="reference internal" href="../c-api/memory.html#c.PyMem_RawRealloc" title="PyMem_RawRealloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawRealloc()</span></code></a>, or <code class="docutils literal notranslate"><span class="pre">NULL</span></code> if an error occurred, instead of a
  2267. string allocated by <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a> or <a class="reference internal" href="../c-api/memory.html#c.PyMem_Realloc" title="PyMem_Realloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Realloc()</span></code></a>
  2268. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16742">bpo-16742</a>)</p></li>
  2269. <li><p><a class="reference internal" href="../c-api/init.html#c.PyThread_set_key_value" title="PyThread_set_key_value"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyThread_set_key_value()</span></code></a> now always set the value. In Python
  2270. 3.3, the function did nothing if the key already exists (if the current
  2271. value is a non-<code class="docutils literal notranslate"><span class="pre">NULL</span></code> pointer).</p></li>
  2272. <li><p>The <code class="docutils literal notranslate"><span class="pre">f_tstate</span></code> (thread state) field of 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>
  2273. structure has been removed to fix a bug: see <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14432">bpo-14432</a> for the
  2274. rationale.</p></li>
  2275. </ul>
  2276. </section>
  2277. </section>
  2278. <section id="changed-in-3-4-3">
  2279. <h2>Changed in 3.4.3<a class="headerlink" href="#changed-in-3-4-3" title="Link to this heading">¶</a></h2>
  2280. <section id="pep-476-enabling-certificate-verification-by-default-for-stdlib-http-clients">
  2281. <span id="pep-476"></span><h3>PEP 476: Enabling certificate verification by default for stdlib http clients<a class="headerlink" href="#pep-476-enabling-certificate-verification-by-default-for-stdlib-http-clients" title="Link to this heading">¶</a></h3>
  2282. <p><a class="reference internal" href="../library/http.client.html#module-http.client" title="http.client: HTTP and HTTPS protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.client</span></code></a> and modules which use it, such as <a class="reference internal" href="../library/urllib.request.html#module-urllib.request" title="urllib.request: Extensible library for opening URLs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request</span></code></a> and
  2283. <a class="reference internal" href="../library/xmlrpc.client.html#module-xmlrpc.client" title="xmlrpc.client: XML-RPC client access."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpc.client</span></code></a>, will now verify that the server presents a certificate
  2284. which is signed by a CA in the platform trust store and whose hostname matches
  2285. the hostname being requested by default, significantly improving security for
  2286. many applications.</p>
  2287. <p>For applications which require the old previous behavior, they can pass an
  2288. alternate context:</p>
  2289. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">urllib.request</span>
  2290. <span class="kn">import</span> <span class="nn">ssl</span>
  2291. <span class="c1"># This disables all verification</span>
  2292. <span class="n">context</span> <span class="o">=</span> <span class="n">ssl</span><span class="o">.</span><span class="n">_create_unverified_context</span><span class="p">()</span>
  2293. <span class="c1"># This allows using a specific certificate for the host, which doesn&#39;t need</span>
  2294. <span class="c1"># to be in the trust store</span>
  2295. <span class="n">context</span> <span class="o">=</span> <span class="n">ssl</span><span class="o">.</span><span class="n">create_default_context</span><span class="p">(</span><span class="n">cafile</span><span class="o">=</span><span class="s2">&quot;/path/to/file.crt&quot;</span><span class="p">)</span>
  2296. <span class="n">urllib</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s2">&quot;https://invalid-cert&quot;</span><span class="p">,</span> <span class="n">context</span><span class="o">=</span><span class="n">context</span><span class="p">)</span>
  2297. </pre></div>
  2298. </div>
  2299. </section>
  2300. </section>
  2301. </section>
  2302. <div class="clearer"></div>
  2303. </div>
  2304. </div>
  2305. </div>
  2306. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  2307. <div class="sphinxsidebarwrapper">
  2308. <div>
  2309. <h3><a href="../contents.html">Table of Contents</a></h3>
  2310. <ul>
  2311. <li><a class="reference internal" href="#">What’s New In Python 3.4</a><ul>
  2312. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release Highlights</a></li>
  2313. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  2314. <li><a class="reference internal" href="#pep-453-explicit-bootstrapping-of-pip-in-python-installations">PEP 453: Explicit Bootstrapping of PIP in Python Installations</a><ul>
  2315. <li><a class="reference internal" href="#bootstrapping-pip-by-default">Bootstrapping pip By Default</a></li>
  2316. <li><a class="reference internal" href="#documentation-changes">Documentation Changes</a></li>
  2317. </ul>
  2318. </li>
  2319. <li><a class="reference internal" href="#pep-446-newly-created-file-descriptors-are-non-inheritable">PEP 446: Newly Created File Descriptors Are Non-Inheritable</a></li>
  2320. <li><a class="reference internal" href="#improvements-to-codec-handling">Improvements to Codec Handling</a></li>
  2321. <li><a class="reference internal" href="#pep-451-a-modulespec-type-for-the-import-system">PEP 451: A ModuleSpec Type for the Import System</a></li>
  2322. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  2323. </ul>
  2324. </li>
  2325. <li><a class="reference internal" href="#new-modules">New Modules</a><ul>
  2326. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  2327. <li><a class="reference internal" href="#ensurepip">ensurepip</a></li>
  2328. <li><a class="reference internal" href="#enum">enum</a></li>
  2329. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  2330. <li><a class="reference internal" href="#selectors">selectors</a></li>
  2331. <li><a class="reference internal" href="#statistics">statistics</a></li>
  2332. <li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
  2333. </ul>
  2334. </li>
  2335. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  2336. <li><a class="reference internal" href="#abc">abc</a></li>
  2337. <li><a class="reference internal" href="#aifc">aifc</a></li>
  2338. <li><a class="reference internal" href="#argparse">argparse</a></li>
  2339. <li><a class="reference internal" href="#audioop">audioop</a></li>
  2340. <li><a class="reference internal" href="#base64">base64</a></li>
  2341. <li><a class="reference internal" href="#collections">collections</a></li>
  2342. <li><a class="reference internal" href="#colorsys">colorsys</a></li>
  2343. <li><a class="reference internal" href="#contextlib">contextlib</a></li>
  2344. <li><a class="reference internal" href="#dbm">dbm</a></li>
  2345. <li><a class="reference internal" href="#dis">dis</a></li>
  2346. <li><a class="reference internal" href="#doctest">doctest</a></li>
  2347. <li><a class="reference internal" href="#email">email</a></li>
  2348. <li><a class="reference internal" href="#filecmp">filecmp</a></li>
  2349. <li><a class="reference internal" href="#functools">functools</a></li>
  2350. <li><a class="reference internal" href="#gc">gc</a></li>
  2351. <li><a class="reference internal" href="#glob">glob</a></li>
  2352. <li><a class="reference internal" href="#hashlib">hashlib</a></li>
  2353. <li><a class="reference internal" href="#hmac">hmac</a></li>
  2354. <li><a class="reference internal" href="#html">html</a></li>
  2355. <li><a class="reference internal" href="#http">http</a></li>
  2356. <li><a class="reference internal" href="#idlelib-and-idle">idlelib and IDLE</a></li>
  2357. <li><a class="reference internal" href="#importlib">importlib</a></li>
  2358. <li><a class="reference internal" href="#inspect">inspect</a></li>
  2359. <li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
  2360. <li><a class="reference internal" href="#logging">logging</a></li>
  2361. <li><a class="reference internal" href="#marshal">marshal</a></li>
  2362. <li><a class="reference internal" href="#mmap">mmap</a></li>
  2363. <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
  2364. <li><a class="reference internal" href="#operator">operator</a></li>
  2365. <li><a class="reference internal" href="#os">os</a></li>
  2366. <li><a class="reference internal" href="#pdb">pdb</a></li>
  2367. <li><a class="reference internal" href="#pickle">pickle</a></li>
  2368. <li><a class="reference internal" href="#plistlib">plistlib</a></li>
  2369. <li><a class="reference internal" href="#poplib">poplib</a></li>
  2370. <li><a class="reference internal" href="#pprint">pprint</a></li>
  2371. <li><a class="reference internal" href="#pty">pty</a></li>
  2372. <li><a class="reference internal" href="#pydoc">pydoc</a></li>
  2373. <li><a class="reference internal" href="#re">re</a></li>
  2374. <li><a class="reference internal" href="#resource">resource</a></li>
  2375. <li><a class="reference internal" href="#select">select</a></li>
  2376. <li><a class="reference internal" href="#shelve">shelve</a></li>
  2377. <li><a class="reference internal" href="#shutil">shutil</a></li>
  2378. <li><a class="reference internal" href="#smtpd">smtpd</a></li>
  2379. <li><a class="reference internal" href="#smtplib">smtplib</a></li>
  2380. <li><a class="reference internal" href="#socket">socket</a></li>
  2381. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  2382. <li><a class="reference internal" href="#ssl">ssl</a></li>
  2383. <li><a class="reference internal" href="#stat">stat</a></li>
  2384. <li><a class="reference internal" href="#struct">struct</a></li>
  2385. <li><a class="reference internal" href="#subprocess">subprocess</a></li>
  2386. <li><a class="reference internal" href="#sunau">sunau</a></li>
  2387. <li><a class="reference internal" href="#sys">sys</a></li>
  2388. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  2389. <li><a class="reference internal" href="#textwrap">textwrap</a></li>
  2390. <li><a class="reference internal" href="#threading">threading</a></li>
  2391. <li><a class="reference internal" href="#traceback">traceback</a></li>
  2392. <li><a class="reference internal" href="#types">types</a></li>
  2393. <li><a class="reference internal" href="#urllib">urllib</a></li>
  2394. <li><a class="reference internal" href="#unittest">unittest</a></li>
  2395. <li><a class="reference internal" href="#venv">venv</a></li>
  2396. <li><a class="reference internal" href="#wave">wave</a></li>
  2397. <li><a class="reference internal" href="#weakref">weakref</a></li>
  2398. <li><a class="reference internal" href="#xml-etree">xml.etree</a></li>
  2399. <li><a class="reference internal" href="#zipfile">zipfile</a></li>
  2400. </ul>
  2401. </li>
  2402. <li><a class="reference internal" href="#cpython-implementation-changes">CPython Implementation Changes</a><ul>
  2403. <li><a class="reference internal" href="#pep-445-customization-of-cpython-memory-allocators">PEP 445: Customization of CPython Memory Allocators</a></li>
  2404. <li><a class="reference internal" href="#pep-442-safe-object-finalization">PEP 442: Safe Object Finalization</a></li>
  2405. <li><a class="reference internal" href="#pep-456-secure-and-interchangeable-hash-algorithm">PEP 456: Secure and Interchangeable Hash Algorithm</a></li>
  2406. <li><a class="reference internal" href="#pep-436-argument-clinic">PEP 436: Argument Clinic</a></li>
  2407. <li><a class="reference internal" href="#other-build-and-c-api-changes">Other Build and C API Changes</a></li>
  2408. <li><a class="reference internal" href="#other-improvements">Other Improvements</a></li>
  2409. <li><a class="reference internal" href="#significant-optimizations">Significant Optimizations</a></li>
  2410. </ul>
  2411. </li>
  2412. <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
  2413. <li><a class="reference internal" href="#deprecations-in-the-python-api">Deprecations in the Python API</a></li>
  2414. <li><a class="reference internal" href="#deprecated-features">Deprecated Features</a></li>
  2415. </ul>
  2416. </li>
  2417. <li><a class="reference internal" href="#removed">Removed</a><ul>
  2418. <li><a class="reference internal" href="#operating-systems-no-longer-supported">Operating Systems No Longer Supported</a></li>
  2419. <li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
  2420. <li><a class="reference internal" href="#code-cleanups">Code Cleanups</a></li>
  2421. </ul>
  2422. </li>
  2423. <li><a class="reference internal" href="#porting-to-python-3-4">Porting to Python 3.4</a><ul>
  2424. <li><a class="reference internal" href="#changes-in-python-command-behavior">Changes in ‘python’ Command Behavior</a></li>
  2425. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  2426. <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
  2427. </ul>
  2428. </li>
  2429. <li><a class="reference internal" href="#changed-in-3-4-3">Changed in 3.4.3</a><ul>
  2430. <li><a class="reference internal" href="#pep-476-enabling-certificate-verification-by-default-for-stdlib-http-clients">PEP 476: Enabling certificate verification by default for stdlib http clients</a></li>
  2431. </ul>
  2432. </li>
  2433. </ul>
  2434. </li>
  2435. </ul>
  2436. </div>
  2437. <div>
  2438. <h4>Previous topic</h4>
  2439. <p class="topless"><a href="3.5.html"
  2440. title="previous chapter">What’s New In Python 3.5</a></p>
  2441. </div>
  2442. <div>
  2443. <h4>Next topic</h4>
  2444. <p class="topless"><a href="3.3.html"
  2445. title="next chapter">What’s New In Python 3.3</a></p>
  2446. </div>
  2447. <div role="note" aria-label="source link">
  2448. <h3>This Page</h3>
  2449. <ul class="this-page-menu">
  2450. <li><a href="../bugs.html">Report a Bug</a></li>
  2451. <li>
  2452. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.4.rst"
  2453. rel="nofollow">Show Source
  2454. </a>
  2455. </li>
  2456. </ul>
  2457. </div>
  2458. </div>
  2459. <div id="sidebarbutton" title="Collapse sidebar">
  2460. <span>«</span>
  2461. </div>
  2462. </div>
  2463. <div class="clearer"></div>
  2464. </div>
  2465. <div class="related" role="navigation" aria-label="related navigation">
  2466. <h3>Navigation</h3>
  2467. <ul>
  2468. <li class="right" style="margin-right: 10px">
  2469. <a href="../genindex.html" title="General Index"
  2470. >index</a></li>
  2471. <li class="right" >
  2472. <a href="../py-modindex.html" title="Python Module Index"
  2473. >modules</a> |</li>
  2474. <li class="right" >
  2475. <a href="3.3.html" title="What’s New In Python 3.3"
  2476. >next</a> |</li>
  2477. <li class="right" >
  2478. <a href="3.5.html" title="What’s New In Python 3.5"
  2479. >previous</a> |</li>
  2480. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  2481. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  2482. <li class="switchers">
  2483. <div class="language_switcher_placeholder"></div>
  2484. <div class="version_switcher_placeholder"></div>
  2485. </li>
  2486. <li>
  2487. </li>
  2488. <li id="cpython-language-and-version">
  2489. <a href="../index.html">3.12.3 Documentation</a> &#187;
  2490. </li>
  2491. <li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> &#187;</li>
  2492. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.4</a></li>
  2493. <li class="right">
  2494. <div class="inline-search" role="search">
  2495. <form class="inline-search" action="../search.html" method="get">
  2496. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  2497. <input type="submit" value="Go" />
  2498. </form>
  2499. </div>
  2500. |
  2501. </li>
  2502. <li class="right">
  2503. <label class="theme-selector-label">
  2504. Theme
  2505. <select class="theme-selector" oninput="activateTheme(this.value)">
  2506. <option value="auto" selected>Auto</option>
  2507. <option value="light">Light</option>
  2508. <option value="dark">Dark</option>
  2509. </select>
  2510. </label> |</li>
  2511. </ul>
  2512. </div>
  2513. <div class="footer">
  2514. &copy;
  2515. <a href="../copyright.html">
  2516. Copyright
  2517. </a>
  2518. 2001-2024, Python Software Foundation.
  2519. <br />
  2520. This page is licensed under the Python Software Foundation License Version 2.
  2521. <br />
  2522. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  2523. <br />
  2524. See <a href="/license.html">History and License</a> for more information.<br />
  2525. <br />
  2526. The Python Software Foundation is a non-profit corporation.
  2527. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  2528. <br />
  2529. <br />
  2530. Last updated on Apr 09, 2024 (13:47 UTC).
  2531. <a href="/bugs.html">Found a bug</a>?
  2532. <br />
  2533. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  2534. </div>
  2535. </body>
  2536. </html>
上海开阖软件有限公司 沪ICP备12045867号-1