gooderp18绿色标准版
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

2761 lines
320KB

  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.3" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/whatsnew/3.3.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="This article explains the new features in Python 3.3, compared to 3.2. Python 3.3 was released on September 29, 2012. For full details, see the changelog. Summary – Release highlights: New syntax f..." />
  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="This article explains the new features in Python 3.3, compared to 3.2. Python 3.3 was released on September 29, 2012. For full details, see the changelog. Summary – Release highlights: New syntax f..." />
  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.3 &#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.2" href="3.2.html" />
  33. <link rel="prev" title="What’s New In Python 3.4" href="3.4.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/whatsnew/3.3.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.3</a><ul>
  86. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  87. <li><a class="reference internal" href="#pep-405-virtual-environments">PEP 405: Virtual Environments</a></li>
  88. <li><a class="reference internal" href="#pep-420-implicit-namespace-packages">PEP 420: Implicit Namespace Packages</a></li>
  89. <li><a class="reference internal" href="#pep-3118-new-memoryview-implementation-and-buffer-protocol-documentation">PEP 3118: New memoryview implementation and buffer protocol documentation</a><ul>
  90. <li><a class="reference internal" href="#features">Features</a></li>
  91. <li><a class="reference internal" href="#api-changes">API changes</a></li>
  92. </ul>
  93. </li>
  94. <li><a class="reference internal" href="#pep-393-flexible-string-representation">PEP 393: Flexible String Representation</a><ul>
  95. <li><a class="reference internal" href="#functionality">Functionality</a></li>
  96. <li><a class="reference internal" href="#performance-and-resource-usage">Performance and resource usage</a></li>
  97. </ul>
  98. </li>
  99. <li><a class="reference internal" href="#pep-397-python-launcher-for-windows">PEP 397: Python Launcher for Windows</a></li>
  100. <li><a class="reference internal" href="#pep-3151-reworking-the-os-and-io-exception-hierarchy">PEP 3151: Reworking the OS and IO exception hierarchy</a></li>
  101. <li><a class="reference internal" href="#pep-380-syntax-for-delegating-to-a-subgenerator">PEP 380: Syntax for Delegating to a Subgenerator</a></li>
  102. <li><a class="reference internal" href="#pep-409-suppressing-exception-context">PEP 409: Suppressing exception context</a></li>
  103. <li><a class="reference internal" href="#pep-414-explicit-unicode-literals">PEP 414: Explicit Unicode literals</a></li>
  104. <li><a class="reference internal" href="#pep-3155-qualified-name-for-classes-and-functions">PEP 3155: Qualified name for classes and functions</a></li>
  105. <li><a class="reference internal" href="#pep-412-key-sharing-dictionary">PEP 412: Key-Sharing Dictionary</a></li>
  106. <li><a class="reference internal" href="#pep-362-function-signature-object">PEP 362: Function Signature Object</a></li>
  107. <li><a class="reference internal" href="#pep-421-adding-sys-implementation">PEP 421: Adding sys.implementation</a><ul>
  108. <li><a class="reference internal" href="#simplenamespace">SimpleNamespace</a></li>
  109. </ul>
  110. </li>
  111. <li><a class="reference internal" href="#using-importlib-as-the-implementation-of-import">Using importlib as the Implementation of Import</a><ul>
  112. <li><a class="reference internal" href="#new-apis">New APIs</a></li>
  113. <li><a class="reference internal" href="#visible-changes">Visible Changes</a></li>
  114. </ul>
  115. </li>
  116. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  117. <li><a class="reference internal" href="#a-finer-grained-import-lock">A Finer-Grained Import Lock</a></li>
  118. <li><a class="reference internal" href="#builtin-functions-and-types">Builtin functions and types</a></li>
  119. <li><a class="reference internal" href="#new-modules">New Modules</a><ul>
  120. <li><a class="reference internal" href="#faulthandler">faulthandler</a></li>
  121. <li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
  122. <li><a class="reference internal" href="#lzma">lzma</a></li>
  123. </ul>
  124. </li>
  125. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  126. <li><a class="reference internal" href="#abc">abc</a></li>
  127. <li><a class="reference internal" href="#array">array</a></li>
  128. <li><a class="reference internal" href="#base64">base64</a></li>
  129. <li><a class="reference internal" href="#binascii">binascii</a></li>
  130. <li><a class="reference internal" href="#bz2">bz2</a></li>
  131. <li><a class="reference internal" href="#codecs">codecs</a></li>
  132. <li><a class="reference internal" href="#collections">collections</a></li>
  133. <li><a class="reference internal" href="#contextlib">contextlib</a></li>
  134. <li><a class="reference internal" href="#crypt">crypt</a></li>
  135. <li><a class="reference internal" href="#curses">curses</a></li>
  136. <li><a class="reference internal" href="#datetime">datetime</a></li>
  137. <li><a class="reference internal" href="#decimal">decimal</a><ul>
  138. <li><a class="reference internal" href="#id1">Features</a></li>
  139. <li><a class="reference internal" href="#id2">API changes</a></li>
  140. </ul>
  141. </li>
  142. <li><a class="reference internal" href="#email">email</a><ul>
  143. <li><a class="reference internal" href="#policy-framework">Policy Framework</a></li>
  144. <li><a class="reference internal" href="#provisional-policy-with-new-header-api">Provisional Policy with New Header API</a></li>
  145. <li><a class="reference internal" href="#other-api-changes">Other API Changes</a></li>
  146. </ul>
  147. </li>
  148. <li><a class="reference internal" href="#ftplib">ftplib</a></li>
  149. <li><a class="reference internal" href="#functools">functools</a></li>
  150. <li><a class="reference internal" href="#gc">gc</a></li>
  151. <li><a class="reference internal" href="#hmac">hmac</a></li>
  152. <li><a class="reference internal" href="#http">http</a></li>
  153. <li><a class="reference internal" href="#html">html</a></li>
  154. <li><a class="reference internal" href="#imaplib">imaplib</a></li>
  155. <li><a class="reference internal" href="#inspect">inspect</a></li>
  156. <li><a class="reference internal" href="#io">io</a></li>
  157. <li><a class="reference internal" href="#itertools">itertools</a></li>
  158. <li><a class="reference internal" href="#logging">logging</a></li>
  159. <li><a class="reference internal" href="#math">math</a></li>
  160. <li><a class="reference internal" href="#mmap">mmap</a></li>
  161. <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
  162. <li><a class="reference internal" href="#nntplib">nntplib</a></li>
  163. <li><a class="reference internal" href="#os">os</a></li>
  164. <li><a class="reference internal" href="#pdb">pdb</a></li>
  165. <li><a class="reference internal" href="#pickle">pickle</a></li>
  166. <li><a class="reference internal" href="#pydoc">pydoc</a></li>
  167. <li><a class="reference internal" href="#re">re</a></li>
  168. <li><a class="reference internal" href="#sched">sched</a></li>
  169. <li><a class="reference internal" href="#select">select</a></li>
  170. <li><a class="reference internal" href="#shlex">shlex</a></li>
  171. <li><a class="reference internal" href="#shutil">shutil</a></li>
  172. <li><a class="reference internal" href="#signal">signal</a></li>
  173. <li><a class="reference internal" href="#smtpd">smtpd</a></li>
  174. <li><a class="reference internal" href="#smtplib">smtplib</a></li>
  175. <li><a class="reference internal" href="#socket">socket</a></li>
  176. <li><a class="reference internal" href="#socketserver">socketserver</a></li>
  177. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  178. <li><a class="reference internal" href="#ssl">ssl</a></li>
  179. <li><a class="reference internal" href="#stat">stat</a></li>
  180. <li><a class="reference internal" href="#struct">struct</a></li>
  181. <li><a class="reference internal" href="#subprocess">subprocess</a></li>
  182. <li><a class="reference internal" href="#sys">sys</a></li>
  183. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  184. <li><a class="reference internal" href="#tempfile">tempfile</a></li>
  185. <li><a class="reference internal" href="#textwrap">textwrap</a></li>
  186. <li><a class="reference internal" href="#threading">threading</a></li>
  187. <li><a class="reference internal" href="#time">time</a></li>
  188. <li><a class="reference internal" href="#types">types</a></li>
  189. <li><a class="reference internal" href="#unittest">unittest</a></li>
  190. <li><a class="reference internal" href="#urllib">urllib</a></li>
  191. <li><a class="reference internal" href="#webbrowser">webbrowser</a></li>
  192. <li><a class="reference internal" href="#xml-etree-elementtree">xml.etree.ElementTree</a></li>
  193. <li><a class="reference internal" href="#zlib">zlib</a></li>
  194. </ul>
  195. </li>
  196. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  197. <li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
  198. <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
  199. <li><a class="reference internal" href="#unsupported-operating-systems">Unsupported Operating Systems</a></li>
  200. <li><a class="reference internal" href="#deprecated-python-modules-functions-and-methods">Deprecated Python modules, functions and methods</a></li>
  201. <li><a class="reference internal" href="#deprecated-functions-and-types-of-the-c-api">Deprecated functions and types of the C API</a></li>
  202. <li><a class="reference internal" href="#deprecated-features">Deprecated features</a></li>
  203. </ul>
  204. </li>
  205. <li><a class="reference internal" href="#porting-to-python-3-3">Porting to Python 3.3</a><ul>
  206. <li><a class="reference internal" href="#porting-python-code">Porting Python code</a></li>
  207. <li><a class="reference internal" href="#porting-c-code">Porting C code</a></li>
  208. <li><a class="reference internal" href="#building-c-extensions">Building C extensions</a></li>
  209. <li><a class="reference internal" href="#command-line-switch-changes">Command Line Switch Changes</a></li>
  210. </ul>
  211. </li>
  212. </ul>
  213. </li>
  214. </ul>
  215. </div>
  216. <div>
  217. <h4>Previous topic</h4>
  218. <p class="topless"><a href="3.4.html"
  219. title="previous chapter">What’s New In Python 3.4</a></p>
  220. </div>
  221. <div>
  222. <h4>Next topic</h4>
  223. <p class="topless"><a href="3.2.html"
  224. title="next chapter">What’s New In Python 3.2</a></p>
  225. </div>
  226. <div role="note" aria-label="source link">
  227. <h3>This Page</h3>
  228. <ul class="this-page-menu">
  229. <li><a href="../bugs.html">Report a Bug</a></li>
  230. <li>
  231. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.3.rst"
  232. rel="nofollow">Show Source
  233. </a>
  234. </li>
  235. </ul>
  236. </div>
  237. </nav>
  238. </div>
  239. </div>
  240. <div class="related" role="navigation" aria-label="related navigation">
  241. <h3>Navigation</h3>
  242. <ul>
  243. <li class="right" style="margin-right: 10px">
  244. <a href="../genindex.html" title="General Index"
  245. accesskey="I">index</a></li>
  246. <li class="right" >
  247. <a href="../py-modindex.html" title="Python Module Index"
  248. >modules</a> |</li>
  249. <li class="right" >
  250. <a href="3.2.html" title="What’s New In Python 3.2"
  251. accesskey="N">next</a> |</li>
  252. <li class="right" >
  253. <a href="3.4.html" title="What’s New In Python 3.4"
  254. accesskey="P">previous</a> |</li>
  255. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  256. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  257. <li class="switchers">
  258. <div class="language_switcher_placeholder"></div>
  259. <div class="version_switcher_placeholder"></div>
  260. </li>
  261. <li>
  262. </li>
  263. <li id="cpython-language-and-version">
  264. <a href="../index.html">3.12.3 Documentation</a> &#187;
  265. </li>
  266. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> &#187;</li>
  267. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.3</a></li>
  268. <li class="right">
  269. <div class="inline-search" role="search">
  270. <form class="inline-search" action="../search.html" method="get">
  271. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  272. <input type="submit" value="Go" />
  273. </form>
  274. </div>
  275. |
  276. </li>
  277. <li class="right">
  278. <label class="theme-selector-label">
  279. Theme
  280. <select class="theme-selector" oninput="activateTheme(this.value)">
  281. <option value="auto" selected>Auto</option>
  282. <option value="light">Light</option>
  283. <option value="dark">Dark</option>
  284. </select>
  285. </label> |</li>
  286. </ul>
  287. </div>
  288. <div class="document">
  289. <div class="documentwrapper">
  290. <div class="bodywrapper">
  291. <div class="body" role="main">
  292. <section id="what-s-new-in-python-3-3">
  293. <h1>What’s New In Python 3.3<a class="headerlink" href="#what-s-new-in-python-3-3" title="Link to this heading">¶</a></h1>
  294. <p>This article explains the new features in Python 3.3, compared to 3.2.
  295. Python 3.3 was released on September 29, 2012. For full details,
  296. see the <a class="reference external" href="https://docs.python.org/3.3/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-0398/"><strong>PEP 398</strong></a> - Python 3.3 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>New <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> expression for <a class="reference internal" href="#pep-380"><span class="std std-ref">generator delegation</span></a>.</p></li>
  306. <li><p>The <code class="docutils literal notranslate"><span class="pre">u'unicode'</span></code> syntax is accepted again for <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> objects.</p></li>
  307. </ul>
  308. <p>New library modules:</p>
  309. <ul class="simple">
  310. <li><p><a class="reference internal" href="../library/faulthandler.html#module-faulthandler" title="faulthandler: Dump the Python traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code></a> (helps debugging low-level crashes)</p></li>
  311. <li><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> (high-level objects representing IP addresses and masks)</p></li>
  312. <li><p><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> (compress data using the XZ / LZMA algorithm)</p></li>
  313. <li><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> (replace parts of your system under test with mock objects)</p></li>
  314. <li><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> (Python <a class="reference internal" href="#pep-405"><span class="std std-ref">virtual environments</span></a>, as in the
  315. popular <code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> package)</p></li>
  316. </ul>
  317. <p>New built-in features:</p>
  318. <ul class="simple">
  319. <li><p>Reworked <a class="reference internal" href="#pep-3151"><span class="std std-ref">I/O exception hierarchy</span></a>.</p></li>
  320. </ul>
  321. <p>Implementation improvements:</p>
  322. <ul class="simple">
  323. <li><p>Rewritten <a class="reference internal" href="#importlib"><span class="std std-ref">import machinery</span></a> based on <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>.</p></li>
  324. <li><p>More compact <a class="reference internal" href="#pep-393"><span class="std std-ref">unicode strings</span></a>.</p></li>
  325. <li><p>More compact <a class="reference internal" href="#pep-412"><span class="std std-ref">attribute dictionaries</span></a>.</p></li>
  326. </ul>
  327. <p>Significantly Improved Library Modules:</p>
  328. <ul class="simple">
  329. <li><p>C Accelerator for the <a class="reference internal" href="#new-decimal"><span class="std std-ref">decimal</span></a> module.</p></li>
  330. <li><p>Better unicode handling in the <a class="reference internal" href="#new-email"><span class="std std-ref">email</span></a> module
  331. (<a class="reference internal" href="../glossary.html#term-provisional-package"><span class="xref std std-term">provisional</span></a>).</p></li>
  332. </ul>
  333. <p>Security improvements:</p>
  334. <ul class="simple">
  335. <li><p>Hash randomization is switched on by default.</p></li>
  336. </ul>
  337. <p>Please read on for a comprehensive list of user-facing changes.</p>
  338. </section>
  339. <section id="pep-405-virtual-environments">
  340. <span id="pep-405"></span><h2>PEP 405: Virtual Environments<a class="headerlink" href="#pep-405-virtual-environments" title="Link to this heading">¶</a></h2>
  341. <p>Virtual environments help create separate Python setups while sharing a
  342. system-wide base install, for ease of maintenance. Virtual environments
  343. have their own set of private site packages (i.e. locally installed
  344. libraries), and are optionally segregated from the system-wide site
  345. packages. Their concept and implementation are inspired by the popular
  346. <code class="docutils literal notranslate"><span class="pre">virtualenv</span></code> third-party package, but benefit from tighter integration
  347. with the interpreter core.</p>
  348. <p>This PEP adds 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 for programmatic access, and the
  349. <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> script for command-line access and
  350. administration. The Python interpreter checks for a <code class="docutils literal notranslate"><span class="pre">pyvenv.cfg</span></code>,
  351. file whose existence signals the base of a virtual environment’s directory
  352. tree.</p>
  353. <div class="admonition seealso">
  354. <p class="admonition-title">See also</p>
  355. <dl class="simple">
  356. <dt><span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0405/"><strong>PEP 405</strong></a> - Python Virtual Environments</dt><dd><p>PEP written by Carl Meyer; implementation by Carl Meyer and Vinay Sajip</p>
  357. </dd>
  358. </dl>
  359. </div>
  360. </section>
  361. <section id="pep-420-implicit-namespace-packages">
  362. <h2>PEP 420: Implicit Namespace Packages<a class="headerlink" href="#pep-420-implicit-namespace-packages" title="Link to this heading">¶</a></h2>
  363. <p>Native support for package directories that don’t require <code class="docutils literal notranslate"><span class="pre">__init__.py</span></code>
  364. marker files and can automatically span multiple path segments (inspired by
  365. various third party approaches to namespace packages, as described in
  366. <span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0420/"><strong>PEP 420</strong></a>)</p>
  367. <div class="admonition seealso">
  368. <p class="admonition-title">See also</p>
  369. <dl class="simple">
  370. <dt><span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0420/"><strong>PEP 420</strong></a> - Implicit Namespace Packages</dt><dd><p>PEP written by Eric V. Smith; implementation by Eric V. Smith
  371. and Barry Warsaw</p>
  372. </dd>
  373. </dl>
  374. </div>
  375. </section>
  376. <section id="pep-3118-new-memoryview-implementation-and-buffer-protocol-documentation">
  377. <span id="pep-3118-update"></span><h2>PEP 3118: New memoryview implementation and buffer protocol documentation<a class="headerlink" href="#pep-3118-new-memoryview-implementation-and-buffer-protocol-documentation" title="Link to this heading">¶</a></h2>
  378. <p>The implementation of <span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-3118/"><strong>PEP 3118</strong></a> has been significantly improved.</p>
  379. <p>The new memoryview implementation comprehensively fixes all ownership and
  380. lifetime issues of dynamically allocated fields in the Py_buffer struct
  381. that led to multiple crash reports. Additionally, several functions that
  382. crashed or returned incorrect results for non-contiguous or multi-dimensional
  383. input have been fixed.</p>
  384. <p>The memoryview object now has a PEP-3118 compliant getbufferproc()
  385. that checks the consumer’s request type. Many new features have been
  386. added, most of them work in full generality for non-contiguous arrays
  387. and arrays with suboffsets.</p>
  388. <p>The documentation has been updated, clearly spelling out responsibilities
  389. for both exporters and consumers. Buffer request flags are grouped into
  390. basic and compound flags. The memory layout of non-contiguous and
  391. multi-dimensional NumPy-style arrays is explained.</p>
  392. <section id="features">
  393. <h3>Features<a class="headerlink" href="#features" title="Link to this heading">¶</a></h3>
  394. <ul class="simple">
  395. <li><p>All native single character format specifiers in struct module syntax
  396. (optionally prefixed with ‘&#64;’) are now supported.</p></li>
  397. <li><p>With some restrictions, the cast() method allows changing of format and
  398. shape of C-contiguous arrays.</p></li>
  399. <li><p>Multi-dimensional list representations are supported for any array type.</p></li>
  400. <li><p>Multi-dimensional comparisons are supported for any array type.</p></li>
  401. <li><p>One-dimensional memoryviews of hashable (read-only) types with formats B,
  402. b or c are now hashable. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13411">bpo-13411</a>.)</p></li>
  403. <li><p>Arbitrary slicing of any 1-D arrays type is supported. For example, it
  404. is now possible to reverse a memoryview in <em>O</em>(1) by using a negative step.</p></li>
  405. </ul>
  406. </section>
  407. <section id="api-changes">
  408. <h3>API changes<a class="headerlink" href="#api-changes" title="Link to this heading">¶</a></h3>
  409. <ul class="simple">
  410. <li><p>The maximum number of dimensions is officially limited to 64.</p></li>
  411. <li><p>The representation of empty shape, strides and suboffsets is now
  412. an empty tuple instead of <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></li>
  413. <li><p>Accessing a memoryview element with format ‘B’ (unsigned bytes)
  414. now returns an integer (in accordance with the struct module syntax).
  415. For returning a bytes object the view must be cast to ‘c’ first.</p></li>
  416. <li><p>memoryview comparisons now use the logical structure of the operands
  417. and compare all array elements by value. All format strings in struct
  418. module syntax are supported. Views with unrecognised format strings
  419. are still permitted, but will always compare as unequal, regardless
  420. of view contents.</p></li>
  421. <li><p>For further changes see <a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a> and <a class="reference internal" href="#porting-c-code">Porting C code</a>.</p></li>
  422. </ul>
  423. <p>(Contributed by Stefan Krah in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10181">bpo-10181</a>.)</p>
  424. <div class="admonition seealso">
  425. <p class="admonition-title">See also</p>
  426. <p><span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-3118/"><strong>PEP 3118</strong></a> - Revising the Buffer Protocol</p>
  427. </div>
  428. </section>
  429. </section>
  430. <section id="pep-393-flexible-string-representation">
  431. <span id="pep-393"></span><h2>PEP 393: Flexible String Representation<a class="headerlink" href="#pep-393-flexible-string-representation" title="Link to this heading">¶</a></h2>
  432. <p>The Unicode string type is changed to support multiple internal
  433. representations, depending on the character with the largest Unicode ordinal
  434. (1, 2, or 4 bytes) in the represented string. This allows a space-efficient
  435. representation in common cases, but gives access to full UCS-4 on all
  436. systems. For compatibility with existing APIs, several representations may
  437. exist in parallel; over time, this compatibility should be phased out.</p>
  438. <p>On the Python side, there should be no downside to this change.</p>
  439. <p>On the C API side, <span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a> is fully backward compatible. The legacy API
  440. should remain available at least five years. Applications using the legacy
  441. API will not fully benefit of the memory reduction, or - worse - may use
  442. a bit more memory, because Python may have to maintain two versions of each
  443. string (in the legacy format and in the new efficient storage).</p>
  444. <section id="functionality">
  445. <h3>Functionality<a class="headerlink" href="#functionality" title="Link to this heading">¶</a></h3>
  446. <p>Changes introduced by <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a> are the following:</p>
  447. <ul class="simple">
  448. <li><p>Python now always supports the full range of Unicode code points, including
  449. non-BMP ones (i.e. from <code class="docutils literal notranslate"><span class="pre">U+0000</span></code> to <code class="docutils literal notranslate"><span class="pre">U+10FFFF</span></code>). The distinction between
  450. narrow and wide builds no longer exists and Python now behaves like a wide
  451. build, even under Windows.</p></li>
  452. <li><p>With the death of narrow builds, the problems specific to narrow builds have
  453. also been fixed, for example:</p>
  454. <ul>
  455. <li><p><a class="reference internal" href="../library/functions.html#len" title="len"><code class="xref py py-func docutils literal notranslate"><span class="pre">len()</span></code></a> now always returns 1 for non-BMP characters,
  456. so <code class="docutils literal notranslate"><span class="pre">len('\U0010FFFF')</span> <span class="pre">==</span> <span class="pre">1</span></code>;</p></li>
  457. <li><p>surrogate pairs are not recombined in string literals,
  458. so <code class="docutils literal notranslate"><span class="pre">'\uDBFF\uDFFF'</span> <span class="pre">!=</span> <span class="pre">'\U0010FFFF'</span></code>;</p></li>
  459. <li><p>indexing or slicing non-BMP characters returns the expected value,
  460. so <code class="docutils literal notranslate"><span class="pre">'\U0010FFFF'[0]</span></code> now returns <code class="docutils literal notranslate"><span class="pre">'\U0010FFFF'</span></code> and not <code class="docutils literal notranslate"><span class="pre">'\uDBFF'</span></code>;</p></li>
  461. <li><p>all other functions in the standard library now correctly handle
  462. non-BMP code points.</p></li>
  463. </ul>
  464. </li>
  465. <li><p>The value of <a class="reference internal" href="../library/sys.html#sys.maxunicode" title="sys.maxunicode"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.maxunicode</span></code></a> is now always <code class="docutils literal notranslate"><span class="pre">1114111</span></code> (<code class="docutils literal notranslate"><span class="pre">0x10FFFF</span></code>
  466. in hexadecimal). The <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetMax()</span></code> function still returns
  467. either <code class="docutils literal notranslate"><span class="pre">0xFFFF</span></code> or <code class="docutils literal notranslate"><span class="pre">0x10FFFF</span></code> for backward compatibility, and it should
  468. not be used with the new Unicode API (see <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13054">bpo-13054</a>).</p></li>
  469. <li><p>The <code class="file docutils literal notranslate"><span class="pre">./configure</span></code> flag <code class="docutils literal notranslate"><span class="pre">--with-wide-unicode</span></code> has been removed.</p></li>
  470. </ul>
  471. </section>
  472. <section id="performance-and-resource-usage">
  473. <h3>Performance and resource usage<a class="headerlink" href="#performance-and-resource-usage" title="Link to this heading">¶</a></h3>
  474. <p>The storage of Unicode strings now depends on the highest code point in the string:</p>
  475. <ul class="simple">
  476. <li><p>pure ASCII and Latin1 strings (<code class="docutils literal notranslate"><span class="pre">U+0000-U+00FF</span></code>) use 1 byte per code point;</p></li>
  477. <li><p>BMP strings (<code class="docutils literal notranslate"><span class="pre">U+0000-U+FFFF</span></code>) use 2 bytes per code point;</p></li>
  478. <li><p>non-BMP strings (<code class="docutils literal notranslate"><span class="pre">U+10000-U+10FFFF</span></code>) use 4 bytes per code point.</p></li>
  479. </ul>
  480. <p>The net effect is that for most applications, memory usage of string
  481. storage should decrease significantly - especially compared to former
  482. wide unicode builds - as, in many cases, strings will be pure ASCII
  483. even in international contexts (because many strings store non-human
  484. language data, such as XML fragments, HTTP headers, JSON-encoded data,
  485. etc.). We also hope that it will, for the same reasons, increase CPU
  486. cache efficiency on non-trivial applications. The memory usage of
  487. Python 3.3 is two to three times smaller than Python 3.2, and a little
  488. bit better than Python 2.7, on a Django benchmark (see the PEP for
  489. details).</p>
  490. <div class="admonition seealso">
  491. <p class="admonition-title">See also</p>
  492. <dl class="simple">
  493. <dt><span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a> - Flexible String Representation</dt><dd><p>PEP written by Martin von Löwis; implementation by Torsten Becker
  494. and Martin von Löwis.</p>
  495. </dd>
  496. </dl>
  497. </div>
  498. </section>
  499. </section>
  500. <section id="pep-397-python-launcher-for-windows">
  501. <span id="pep-397"></span><h2>PEP 397: Python Launcher for Windows<a class="headerlink" href="#pep-397-python-launcher-for-windows" title="Link to this heading">¶</a></h2>
  502. <p>The Python 3.3 Windows installer now includes a <code class="docutils literal notranslate"><span class="pre">py</span></code> launcher application
  503. that can be used to launch Python applications in a version independent
  504. fashion.</p>
  505. <p>This launcher is invoked implicitly when double-clicking <code class="docutils literal notranslate"><span class="pre">*.py</span></code> files.
  506. If only a single Python version is installed on the system, that version
  507. will be used to run the file. If multiple versions are installed, the most
  508. recent version is used by default, but this can be overridden by including
  509. a Unix-style “shebang line” in the Python script.</p>
  510. <p>The launcher can also be used explicitly from the command line as the <code class="docutils literal notranslate"><span class="pre">py</span></code>
  511. application. Running <code class="docutils literal notranslate"><span class="pre">py</span></code> follows the same version selection rules as
  512. implicitly launching scripts, but a more specific version can be selected
  513. by passing appropriate arguments (such as <code class="docutils literal notranslate"><span class="pre">-3</span></code> to request Python 3 when
  514. Python 2 is also installed, or <code class="docutils literal notranslate"><span class="pre">-2.6</span></code> to specifically request an earlier
  515. Python version when a more recent version is installed).</p>
  516. <p>In addition to the launcher, the Windows installer now includes an
  517. option to add the newly installed Python to the system PATH. (Contributed
  518. by Brian Curtin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=3561">bpo-3561</a>.)</p>
  519. <div class="admonition seealso">
  520. <p class="admonition-title">See also</p>
  521. <dl class="simple">
  522. <dt><span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0397/"><strong>PEP 397</strong></a> - Python Launcher for Windows</dt><dd><p>PEP written by Mark Hammond and Martin v. Löwis; implementation by
  523. Vinay Sajip.</p>
  524. </dd>
  525. </dl>
  526. <p>Launcher documentation: <a class="reference internal" href="../using/windows.html#launcher"><span class="std std-ref">Python Launcher for Windows</span></a></p>
  527. <p>Installer PATH modification: <a class="reference internal" href="../using/windows.html#windows-path-mod"><span class="std std-ref">Finding the Python executable</span></a></p>
  528. </div>
  529. </section>
  530. <section id="pep-3151-reworking-the-os-and-io-exception-hierarchy">
  531. <span id="pep-3151"></span><h2>PEP 3151: Reworking the OS and IO exception hierarchy<a class="headerlink" href="#pep-3151-reworking-the-os-and-io-exception-hierarchy" title="Link to this heading">¶</a></h2>
  532. <p>The hierarchy of exceptions raised by operating system errors is now both
  533. simplified and finer-grained.</p>
  534. <p>You don’t have to worry anymore about choosing the appropriate exception
  535. type between <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>, <a class="reference internal" href="../library/exceptions.html#IOError" title="IOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IOError</span></code></a>, <a class="reference internal" href="../library/exceptions.html#EnvironmentError" title="EnvironmentError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">EnvironmentError</span></code></a>,
  536. <a class="reference internal" href="../library/exceptions.html#WindowsError" title="WindowsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">WindowsError</span></code></a>, <code class="xref py py-exc docutils literal notranslate"><span class="pre">mmap.error</span></code>, <a class="reference internal" href="../library/socket.html#socket.error" title="socket.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">socket.error</span></code></a> or
  537. <a class="reference internal" href="../library/select.html#select.error" title="select.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">select.error</span></code></a>. All these exception types are now only one:
  538. <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>. The other names are kept as aliases for compatibility
  539. reasons.</p>
  540. <p>Also, it is now easier to catch a specific error condition. Instead of
  541. inspecting the <code class="docutils literal notranslate"><span class="pre">errno</span></code> attribute (or <code class="docutils literal notranslate"><span class="pre">args[0]</span></code>) for a particular
  542. constant from the <a class="reference internal" href="../library/errno.html#module-errno" title="errno: Standard errno system symbols."><code class="xref py py-mod docutils literal notranslate"><span class="pre">errno</span></code></a> module, you can catch the adequate
  543. <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> subclass. The available subclasses are the following:</p>
  544. <ul class="simple">
  545. <li><p><a class="reference internal" href="../library/exceptions.html#BlockingIOError" title="BlockingIOError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BlockingIOError</span></code></a></p></li>
  546. <li><p><a class="reference internal" href="../library/exceptions.html#ChildProcessError" title="ChildProcessError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ChildProcessError</span></code></a></p></li>
  547. <li><p><a class="reference internal" href="../library/exceptions.html#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a></p></li>
  548. <li><p><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></p></li>
  549. <li><p><a class="reference internal" href="../library/exceptions.html#FileNotFoundError" title="FileNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileNotFoundError</span></code></a></p></li>
  550. <li><p><a class="reference internal" href="../library/exceptions.html#InterruptedError" title="InterruptedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InterruptedError</span></code></a></p></li>
  551. <li><p><a class="reference internal" href="../library/exceptions.html#IsADirectoryError" title="IsADirectoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IsADirectoryError</span></code></a></p></li>
  552. <li><p><a class="reference internal" href="../library/exceptions.html#NotADirectoryError" title="NotADirectoryError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotADirectoryError</span></code></a></p></li>
  553. <li><p><a class="reference internal" href="../library/exceptions.html#PermissionError" title="PermissionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PermissionError</span></code></a></p></li>
  554. <li><p><a class="reference internal" href="../library/exceptions.html#ProcessLookupError" title="ProcessLookupError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ProcessLookupError</span></code></a></p></li>
  555. <li><p><a class="reference internal" href="../library/exceptions.html#TimeoutError" title="TimeoutError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TimeoutError</span></code></a></p></li>
  556. </ul>
  557. <p>And the <a class="reference internal" href="../library/exceptions.html#ConnectionError" title="ConnectionError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionError</span></code></a> itself has finer-grained subclasses:</p>
  558. <ul class="simple">
  559. <li><p><a class="reference internal" href="../library/exceptions.html#BrokenPipeError" title="BrokenPipeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BrokenPipeError</span></code></a></p></li>
  560. <li><p><a class="reference internal" href="../library/exceptions.html#ConnectionAbortedError" title="ConnectionAbortedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionAbortedError</span></code></a></p></li>
  561. <li><p><a class="reference internal" href="../library/exceptions.html#ConnectionRefusedError" title="ConnectionRefusedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionRefusedError</span></code></a></p></li>
  562. <li><p><a class="reference internal" href="../library/exceptions.html#ConnectionResetError" title="ConnectionResetError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ConnectionResetError</span></code></a></p></li>
  563. </ul>
  564. <p>Thanks to the new exceptions, common usages of the <a class="reference internal" href="../library/errno.html#module-errno" title="errno: Standard errno system symbols."><code class="xref py py-mod docutils literal notranslate"><span class="pre">errno</span></code></a> can now be
  565. avoided. For example, the following code written for Python 3.2:</p>
  566. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">errno</span> <span class="kn">import</span> <span class="n">ENOENT</span><span class="p">,</span> <span class="n">EACCES</span><span class="p">,</span> <span class="n">EPERM</span>
  567. <span class="k">try</span><span class="p">:</span>
  568. <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&quot;document.txt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
  569. <span class="n">content</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
  570. <span class="k">except</span> <span class="ne">IOError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span>
  571. <span class="k">if</span> <span class="n">err</span><span class="o">.</span><span class="n">errno</span> <span class="o">==</span> <span class="n">ENOENT</span><span class="p">:</span>
  572. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;document.txt file is missing&quot;</span><span class="p">)</span>
  573. <span class="k">elif</span> <span class="n">err</span><span class="o">.</span><span class="n">errno</span> <span class="ow">in</span> <span class="p">(</span><span class="n">EACCES</span><span class="p">,</span> <span class="n">EPERM</span><span class="p">):</span>
  574. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;You are not allowed to read document.txt&quot;</span><span class="p">)</span>
  575. <span class="k">else</span><span class="p">:</span>
  576. <span class="k">raise</span>
  577. </pre></div>
  578. </div>
  579. <p>can now be written without the <a class="reference internal" href="../library/errno.html#module-errno" title="errno: Standard errno system symbols."><code class="xref py py-mod docutils literal notranslate"><span class="pre">errno</span></code></a> import and without manual
  580. inspection of exception attributes:</p>
  581. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">try</span><span class="p">:</span>
  582. <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&quot;document.txt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
  583. <span class="n">content</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
  584. <span class="k">except</span> <span class="ne">FileNotFoundError</span><span class="p">:</span>
  585. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;document.txt file is missing&quot;</span><span class="p">)</span>
  586. <span class="k">except</span> <span class="ne">PermissionError</span><span class="p">:</span>
  587. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;You are not allowed to read document.txt&quot;</span><span class="p">)</span>
  588. </pre></div>
  589. </div>
  590. <div class="admonition seealso">
  591. <p class="admonition-title">See also</p>
  592. <dl class="simple">
  593. <dt><span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-3151/"><strong>PEP 3151</strong></a> - Reworking the OS and IO Exception Hierarchy</dt><dd><p>PEP written and implemented by Antoine Pitrou</p>
  594. </dd>
  595. </dl>
  596. </div>
  597. </section>
  598. <section id="pep-380-syntax-for-delegating-to-a-subgenerator">
  599. <span id="pep-380"></span><span id="index-11"></span><h2>PEP 380: Syntax for Delegating to a Subgenerator<a class="headerlink" href="#pep-380-syntax-for-delegating-to-a-subgenerator" title="Link to this heading">¶</a></h2>
  600. <p>PEP 380 adds the <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> expression, allowing a <a class="reference internal" href="../glossary.html#term-generator"><span class="xref std std-term">generator</span></a> to
  601. delegate
  602. part of its operations to another generator. This allows a section of code
  603. containing <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> to be factored out and placed in another generator.
  604. Additionally, the subgenerator is allowed to return with a value, and the
  605. value is made available to the delegating generator.</p>
  606. <p>While designed primarily for use in delegating to a subgenerator, the <code class="docutils literal notranslate"><span class="pre">yield</span>
  607. <span class="pre">from</span></code> expression actually allows delegation to arbitrary subiterators.</p>
  608. <p>For simple iterators, <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span> <span class="pre">iterable</span></code> is essentially just a shortened
  609. form of <code class="docutils literal notranslate"><span class="pre">for</span> <span class="pre">item</span> <span class="pre">in</span> <span class="pre">iterable:</span> <span class="pre">yield</span> <span class="pre">item</span></code>:</p>
  610. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">g</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
  611. <span class="gp">... </span> <span class="k">yield from</span> <span class="nb">range</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
  612. <span class="gp">... </span> <span class="k">yield from</span> <span class="nb">range</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
  613. <span class="gp">...</span>
  614. <span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">g</span><span class="p">(</span><span class="mi">5</span><span class="p">))</span>
  615. <span class="go">[5, 4, 3, 2, 1, 0, 1, 2, 3, 4]</span>
  616. </pre></div>
  617. </div>
  618. <p>However, unlike an ordinary loop, <code class="docutils literal notranslate"><span class="pre">yield</span> <span class="pre">from</span></code> allows subgenerators to
  619. receive sent and thrown values directly from the calling scope, and
  620. return a final value to the outer generator:</p>
  621. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">accumulate</span><span class="p">():</span>
  622. <span class="gp">... </span> <span class="n">tally</span> <span class="o">=</span> <span class="mi">0</span>
  623. <span class="gp">... </span> <span class="k">while</span> <span class="mi">1</span><span class="p">:</span>
  624. <span class="gp">... </span> <span class="nb">next</span> <span class="o">=</span> <span class="k">yield</span>
  625. <span class="gp">... </span> <span class="k">if</span> <span class="nb">next</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
  626. <span class="gp">... </span> <span class="k">return</span> <span class="n">tally</span>
  627. <span class="gp">... </span> <span class="n">tally</span> <span class="o">+=</span> <span class="nb">next</span>
  628. <span class="gp">...</span>
  629. <span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">gather_tallies</span><span class="p">(</span><span class="n">tallies</span><span class="p">):</span>
  630. <span class="gp">... </span> <span class="k">while</span> <span class="mi">1</span><span class="p">:</span>
  631. <span class="gp">... </span> <span class="n">tally</span> <span class="o">=</span> <span class="k">yield from</span> <span class="n">accumulate</span><span class="p">()</span>
  632. <span class="gp">... </span> <span class="n">tallies</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tally</span><span class="p">)</span>
  633. <span class="gp">...</span>
  634. <span class="gp">&gt;&gt;&gt; </span><span class="n">tallies</span> <span class="o">=</span> <span class="p">[]</span>
  635. <span class="gp">&gt;&gt;&gt; </span><span class="n">acc</span> <span class="o">=</span> <span class="n">gather_tallies</span><span class="p">(</span><span class="n">tallies</span><span class="p">)</span>
  636. <span class="gp">&gt;&gt;&gt; </span><span class="nb">next</span><span class="p">(</span><span class="n">acc</span><span class="p">)</span> <span class="c1"># Ensure the accumulator is ready to accept values</span>
  637. <span class="gp">&gt;&gt;&gt; </span><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">4</span><span class="p">):</span>
  638. <span class="gp">... </span> <span class="n">acc</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
  639. <span class="gp">...</span>
  640. <span class="gp">&gt;&gt;&gt; </span><span class="n">acc</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span> <span class="c1"># Finish the first tally</span>
  641. <span class="gp">&gt;&gt;&gt; </span><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">5</span><span class="p">):</span>
  642. <span class="gp">... </span> <span class="n">acc</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
  643. <span class="gp">...</span>
  644. <span class="gp">&gt;&gt;&gt; </span><span class="n">acc</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span> <span class="c1"># Finish the second tally</span>
  645. <span class="gp">&gt;&gt;&gt; </span><span class="n">tallies</span>
  646. <span class="go">[6, 10]</span>
  647. </pre></div>
  648. </div>
  649. <p>The main principle driving this change is to allow even generators that are
  650. designed to be used with the <code class="docutils literal notranslate"><span class="pre">send</span></code> and <code class="docutils literal notranslate"><span class="pre">throw</span></code> methods to be split into
  651. multiple subgenerators as easily as a single large function can be split into
  652. multiple subfunctions.</p>
  653. <div class="admonition seealso">
  654. <p class="admonition-title">See also</p>
  655. <dl class="simple">
  656. <dt><span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0380/"><strong>PEP 380</strong></a> - Syntax for Delegating to a Subgenerator</dt><dd><p>PEP written by Greg Ewing; implementation by Greg Ewing, integrated into
  657. 3.3 by Renaud Blanch, Ryan Kelly and Nick Coghlan; documentation by
  658. Zbigniew Jędrzejewski-Szmek and Nick Coghlan</p>
  659. </dd>
  660. </dl>
  661. </div>
  662. </section>
  663. <section id="pep-409-suppressing-exception-context">
  664. <h2>PEP 409: Suppressing exception context<a class="headerlink" href="#pep-409-suppressing-exception-context" title="Link to this heading">¶</a></h2>
  665. <p>PEP 409 introduces new syntax that allows the display of the chained
  666. exception context to be disabled. This allows cleaner error messages in
  667. applications that convert between exception types:</p>
  668. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">D</span><span class="p">:</span>
  669. <span class="gp">... </span> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">extra</span><span class="p">):</span>
  670. <span class="gp">... </span> <span class="bp">self</span><span class="o">.</span><span class="n">_extra_attributes</span> <span class="o">=</span> <span class="n">extra</span>
  671. <span class="gp">... </span> <span class="k">def</span> <span class="fm">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attr</span><span class="p">):</span>
  672. <span class="gp">... </span> <span class="k">try</span><span class="p">:</span>
  673. <span class="gp">... </span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_extra_attributes</span><span class="p">[</span><span class="n">attr</span><span class="p">]</span>
  674. <span class="gp">... </span> <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
  675. <span class="gp">... </span> <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="n">attr</span><span class="p">)</span> <span class="kn">from</span> <span class="kc">None</span>
  676. <span class="gp">...</span>
  677. <span class="gp">&gt;&gt;&gt; </span><span class="n">D</span><span class="p">({})</span><span class="o">.</span><span class="n">x</span>
  678. <span class="gt">Traceback (most recent call last):</span>
  679. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  680. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">8</span>, in <span class="n">__getattr__</span>
  681. <span class="gr">AttributeError</span>: <span class="n">x</span>
  682. </pre></div>
  683. </div>
  684. <p>Without the <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">None</span></code> suffix to suppress the cause, the original
  685. exception would be displayed by default:</p>
  686. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">C</span><span class="p">:</span>
  687. <span class="gp">... </span> <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">extra</span><span class="p">):</span>
  688. <span class="gp">... </span> <span class="bp">self</span><span class="o">.</span><span class="n">_extra_attributes</span> <span class="o">=</span> <span class="n">extra</span>
  689. <span class="gp">... </span> <span class="k">def</span> <span class="fm">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attr</span><span class="p">):</span>
  690. <span class="gp">... </span> <span class="k">try</span><span class="p">:</span>
  691. <span class="gp">... </span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_extra_attributes</span><span class="p">[</span><span class="n">attr</span><span class="p">]</span>
  692. <span class="gp">... </span> <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
  693. <span class="gp">... </span> <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="n">attr</span><span class="p">)</span>
  694. <span class="gp">...</span>
  695. <span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="p">({})</span><span class="o">.</span><span class="n">x</span>
  696. <span class="gt">Traceback (most recent call last):</span>
  697. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">6</span>, in <span class="n">__getattr__</span>
  698. <span class="gr">KeyError</span>: <span class="n">&#39;x&#39;</span>
  699. <span class="gt">During handling of the above exception, another exception occurred:</span>
  700. <span class="gt">Traceback (most recent call last):</span>
  701. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  702. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">8</span>, in <span class="n">__getattr__</span>
  703. <span class="gr">AttributeError</span>: <span class="n">x</span>
  704. </pre></div>
  705. </div>
  706. <p>No debugging capability is lost, as the original exception context remains
  707. available if needed (for example, if an intervening library has incorrectly
  708. suppressed valuable underlying details):</p>
  709. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">try</span><span class="p">:</span>
  710. <span class="gp">... </span> <span class="n">D</span><span class="p">({})</span><span class="o">.</span><span class="n">x</span>
  711. <span class="gp">... </span><span class="k">except</span> <span class="ne">AttributeError</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span>
  712. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="nb">repr</span><span class="p">(</span><span class="n">exc</span><span class="o">.</span><span class="n">__context__</span><span class="p">))</span>
  713. <span class="gp">...</span>
  714. <span class="go">KeyError(&#39;x&#39;,)</span>
  715. </pre></div>
  716. </div>
  717. <div class="admonition seealso">
  718. <p class="admonition-title">See also</p>
  719. <dl class="simple">
  720. <dt><span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0409/"><strong>PEP 409</strong></a> - Suppressing exception context</dt><dd><p>PEP written by Ethan Furman; implemented by Ethan Furman and Nick
  721. Coghlan.</p>
  722. </dd>
  723. </dl>
  724. </div>
  725. </section>
  726. <section id="pep-414-explicit-unicode-literals">
  727. <h2>PEP 414: Explicit Unicode literals<a class="headerlink" href="#pep-414-explicit-unicode-literals" title="Link to this heading">¶</a></h2>
  728. <p>To ease the transition from Python 2 for Unicode aware Python applications
  729. that make heavy use of Unicode literals, Python 3.3 once again supports the
  730. “<code class="docutils literal notranslate"><span class="pre">u</span></code>” prefix for string literals. This prefix has no semantic significance
  731. in Python 3, it is provided solely to reduce the number of purely mechanical
  732. changes in migrating to Python 3, making it easier for developers to focus on
  733. the more significant semantic changes (such as the stricter default
  734. separation of binary and text data).</p>
  735. <div class="admonition seealso">
  736. <p class="admonition-title">See also</p>
  737. <dl class="simple">
  738. <dt><span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0414/"><strong>PEP 414</strong></a> - Explicit Unicode literals</dt><dd><p>PEP written by Armin Ronacher.</p>
  739. </dd>
  740. </dl>
  741. </div>
  742. </section>
  743. <section id="pep-3155-qualified-name-for-classes-and-functions">
  744. <h2>PEP 3155: Qualified name for classes and functions<a class="headerlink" href="#pep-3155-qualified-name-for-classes-and-functions" title="Link to this heading">¶</a></h2>
  745. <p>Functions and class objects have a new <code class="docutils literal notranslate"><span class="pre">__qualname__</span></code> attribute representing
  746. the “path” from the module top-level to their definition. For global functions
  747. and classes, this is the same as <code class="docutils literal notranslate"><span class="pre">__name__</span></code>. For other functions and classes,
  748. it provides better information about where they were actually defined, and
  749. how they might be accessible from the global scope.</p>
  750. <p>Example with (non-bound) methods:</p>
  751. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">C</span><span class="p">:</span>
  752. <span class="gp">... </span> <span class="k">def</span> <span class="nf">meth</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  753. <span class="gp">... </span> <span class="k">pass</span>
  754. <span class="gp">...</span>
  755. <span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">meth</span><span class="o">.</span><span class="vm">__name__</span>
  756. <span class="go">&#39;meth&#39;</span>
  757. <span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">meth</span><span class="o">.</span><span class="vm">__qualname__</span>
  758. <span class="go">&#39;C.meth&#39;</span>
  759. </pre></div>
  760. </div>
  761. <p>Example with nested classes:</p>
  762. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">C</span><span class="p">:</span>
  763. <span class="gp">... </span> <span class="k">class</span> <span class="nc">D</span><span class="p">:</span>
  764. <span class="gp">... </span> <span class="k">def</span> <span class="nf">meth</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  765. <span class="gp">... </span> <span class="k">pass</span>
  766. <span class="gp">...</span>
  767. <span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="o">.</span><span class="vm">__name__</span>
  768. <span class="go">&#39;D&#39;</span>
  769. <span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="o">.</span><span class="vm">__qualname__</span>
  770. <span class="go">&#39;C.D&#39;</span>
  771. <span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="o">.</span><span class="n">meth</span><span class="o">.</span><span class="vm">__name__</span>
  772. <span class="go">&#39;meth&#39;</span>
  773. <span class="gp">&gt;&gt;&gt; </span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="o">.</span><span class="n">meth</span><span class="o">.</span><span class="vm">__qualname__</span>
  774. <span class="go">&#39;C.D.meth&#39;</span>
  775. </pre></div>
  776. </div>
  777. <p>Example with nested functions:</p>
  778. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">outer</span><span class="p">():</span>
  779. <span class="gp">... </span> <span class="k">def</span> <span class="nf">inner</span><span class="p">():</span>
  780. <span class="gp">... </span> <span class="k">pass</span>
  781. <span class="gp">... </span> <span class="k">return</span> <span class="n">inner</span>
  782. <span class="gp">...</span>
  783. <span class="gp">&gt;&gt;&gt; </span><span class="n">outer</span><span class="p">()</span><span class="o">.</span><span class="vm">__name__</span>
  784. <span class="go">&#39;inner&#39;</span>
  785. <span class="gp">&gt;&gt;&gt; </span><span class="n">outer</span><span class="p">()</span><span class="o">.</span><span class="vm">__qualname__</span>
  786. <span class="go">&#39;outer.&lt;locals&gt;.inner&#39;</span>
  787. </pre></div>
  788. </div>
  789. <p>The string representation of those objects is also changed to include the
  790. new, more precise information:</p>
  791. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">str</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="p">)</span>
  792. <span class="go">&quot;&lt;class &#39;__main__.C.D&#39;&gt;&quot;</span>
  793. <span class="gp">&gt;&gt;&gt; </span><span class="nb">str</span><span class="p">(</span><span class="n">C</span><span class="o">.</span><span class="n">D</span><span class="o">.</span><span class="n">meth</span><span class="p">)</span>
  794. <span class="go">&#39;&lt;function C.D.meth at 0x7f46b9fe31e0&gt;&#39;</span>
  795. </pre></div>
  796. </div>
  797. <div class="admonition seealso">
  798. <p class="admonition-title">See also</p>
  799. <dl class="simple">
  800. <dt><span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-3155/"><strong>PEP 3155</strong></a> - Qualified name for classes and functions</dt><dd><p>PEP written and implemented by Antoine Pitrou.</p>
  801. </dd>
  802. </dl>
  803. </div>
  804. </section>
  805. <section id="pep-412-key-sharing-dictionary">
  806. <span id="pep-412"></span><h2>PEP 412: Key-Sharing Dictionary<a class="headerlink" href="#pep-412-key-sharing-dictionary" title="Link to this heading">¶</a></h2>
  807. <p>Dictionaries used for the storage of objects’ attributes are now able to
  808. share part of their internal storage between each other (namely, the part
  809. which stores the keys and their respective hashes). This reduces the memory
  810. consumption of programs creating many instances of non-builtin types.</p>
  811. <div class="admonition seealso">
  812. <p class="admonition-title">See also</p>
  813. <dl class="simple">
  814. <dt><span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0412/"><strong>PEP 412</strong></a> - Key-Sharing Dictionary</dt><dd><p>PEP written and implemented by Mark Shannon.</p>
  815. </dd>
  816. </dl>
  817. </div>
  818. </section>
  819. <section id="pep-362-function-signature-object">
  820. <h2>PEP 362: Function Signature Object<a class="headerlink" href="#pep-362-function-signature-object" title="Link to this heading">¶</a></h2>
  821. <p>A new function <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> makes introspection of python
  822. callables easy and straightforward. A broad range of callables is supported:
  823. python functions, decorated or not, classes, and <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>
  824. objects. New classes <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>, <a class="reference internal" href="../library/inspect.html#inspect.Parameter" title="inspect.Parameter"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.Parameter</span></code></a>
  825. and <a class="reference internal" href="../library/inspect.html#inspect.BoundArguments" title="inspect.BoundArguments"><code class="xref py py-class docutils literal notranslate"><span class="pre">inspect.BoundArguments</span></code></a> hold information about the call signatures,
  826. such as, annotations, default values, parameters kinds, and bound arguments,
  827. which considerably simplifies writing decorators and any code that validates
  828. or amends calling signatures or arguments.</p>
  829. <div class="admonition seealso">
  830. <p class="admonition-title">See also</p>
  831. <dl class="simple">
  832. <dt><span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0362/"><strong>PEP 362</strong></a>: - Function Signature Object</dt><dd><p>PEP written by Brett Cannon, Yury Selivanov, Larry Hastings, Jiwon Seo;
  833. implemented by Yury Selivanov.</p>
  834. </dd>
  835. </dl>
  836. </div>
  837. </section>
  838. <section id="pep-421-adding-sys-implementation">
  839. <h2>PEP 421: Adding sys.implementation<a class="headerlink" href="#pep-421-adding-sys-implementation" title="Link to this heading">¶</a></h2>
  840. <p>A new attribute 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 exposes details specific to the
  841. implementation of the currently running interpreter. The initial set of
  842. attributes on <a class="reference internal" href="../library/sys.html#sys.implementation" title="sys.implementation"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.implementation</span></code></a> are <code class="docutils literal notranslate"><span class="pre">name</span></code>, <code class="docutils literal notranslate"><span class="pre">version</span></code>,
  843. <code class="docutils literal notranslate"><span class="pre">hexversion</span></code>, and <code class="docutils literal notranslate"><span class="pre">cache_tag</span></code>.</p>
  844. <p>The intention of <code class="docutils literal notranslate"><span class="pre">sys.implementation</span></code> is to consolidate into one namespace
  845. the implementation-specific data used by the standard library. This allows
  846. different Python implementations to share a single standard library code base
  847. much more easily. In its initial state, <code class="docutils literal notranslate"><span class="pre">sys.implementation</span></code> holds only a
  848. small portion of the implementation-specific data. Over time that ratio will
  849. shift in order to make the standard library more portable.</p>
  850. <p>One example of improved standard library portability is <code class="docutils literal notranslate"><span class="pre">cache_tag</span></code>. As of
  851. Python 3.3, <code class="docutils literal notranslate"><span class="pre">sys.implementation.cache_tag</span></code> is used by <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> to
  852. support <span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-3147/"><strong>PEP 3147</strong></a> compliance. Any Python implementation that uses
  853. <code class="docutils literal notranslate"><span class="pre">importlib</span></code> for its built-in import system may use <code class="docutils literal notranslate"><span class="pre">cache_tag</span></code> to control
  854. the caching behavior for modules.</p>
  855. <section id="simplenamespace">
  856. <h3>SimpleNamespace<a class="headerlink" href="#simplenamespace" title="Link to this heading">¶</a></h3>
  857. <p>The implementation of <code class="docutils literal notranslate"><span class="pre">sys.implementation</span></code> also introduces a new type to
  858. Python: <a class="reference internal" href="../library/types.html#types.SimpleNamespace" title="types.SimpleNamespace"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.SimpleNamespace</span></code></a>. In contrast to a mapping-based
  859. namespace, like <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-class docutils literal notranslate"><span class="pre">dict</span></code></a>, <code class="docutils literal notranslate"><span class="pre">SimpleNamespace</span></code> is attribute-based, like
  860. <a class="reference internal" href="../library/functions.html#object" title="object"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a>. However, unlike <code class="docutils literal notranslate"><span class="pre">object</span></code>, <code class="docutils literal notranslate"><span class="pre">SimpleNamespace</span></code> instances
  861. are writable. This means that you can add, remove, and modify the namespace
  862. through normal attribute access.</p>
  863. <div class="admonition seealso">
  864. <p class="admonition-title">See also</p>
  865. <dl class="simple">
  866. <dt><span class="target" id="index-19"></span><a class="pep reference external" href="https://peps.python.org/pep-0421/"><strong>PEP 421</strong></a> - Adding sys.implementation</dt><dd><p>PEP written and implemented by Eric Snow.</p>
  867. </dd>
  868. </dl>
  869. </div>
  870. </section>
  871. </section>
  872. <section id="using-importlib-as-the-implementation-of-import">
  873. <span id="importlib"></span><h2>Using importlib as the Implementation of Import<a class="headerlink" href="#using-importlib-as-the-implementation-of-import" title="Link to this heading">¶</a></h2>
  874. <p><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=2377">bpo-2377</a> - Replace __import__ w/ importlib.__import__
  875. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13959">bpo-13959</a> - Re-implement parts of <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> in pure Python
  876. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14605">bpo-14605</a> - Make import machinery explicit
  877. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14646">bpo-14646</a> - Require loaders set __loader__ and __package__</p>
  878. <p>The <a class="reference internal" href="../library/functions.html#import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> function is now powered by <a class="reference internal" href="../library/importlib.html#importlib.__import__" title="importlib.__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.__import__()</span></code></a>.
  879. This work leads to the completion of “phase 2” of <span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0302/"><strong>PEP 302</strong></a>. There are
  880. multiple benefits to this change. First, it has allowed for more of the
  881. machinery powering import to be exposed instead of being implicit and hidden
  882. within the C code. It also provides a single implementation for all Python VMs
  883. supporting Python 3.3 to use, helping to end any VM-specific deviations in
  884. import semantics. And finally it eases the maintenance of import, allowing for
  885. future growth to occur.</p>
  886. <p>For the common user, there should be no visible change in semantics. For
  887. those whose code currently manipulates import or calls import
  888. programmatically, the code changes that might possibly be required are covered
  889. in the <a class="reference internal" href="#porting-python-code">Porting Python code</a> section of this document.</p>
  890. <section id="new-apis">
  891. <h3>New APIs<a class="headerlink" href="#new-apis" title="Link to this heading">¶</a></h3>
  892. <p>One of the large benefits of this work is the exposure of what goes into
  893. making the import statement work. That means the various importers that were
  894. once implicit are now fully exposed as part of 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> package.</p>
  895. <p>The abstract base classes 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> have been expanded
  896. to properly delineate between <a class="reference internal" href="../glossary.html#term-meta-path-finder"><span class="xref std std-term">meta path finders</span></a>
  897. and <a class="reference internal" href="../glossary.html#term-path-entry-finder"><span class="xref std std-term">path entry finders</span></a> by introducing
  898. <a class="reference internal" href="../library/importlib.html#importlib.abc.MetaPathFinder" title="importlib.abc.MetaPathFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.MetaPathFinder</span></code></a> and
  899. <a class="reference internal" href="../library/importlib.html#importlib.abc.PathEntryFinder" title="importlib.abc.PathEntryFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.PathEntryFinder</span></code></a>, respectively. The old ABC of
  900. <code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.Finder</span></code> is now only provided for backwards-compatibility
  901. and does not enforce any method requirements.</p>
  902. <p>In terms of finders, <a class="reference internal" href="../library/importlib.html#importlib.machinery.FileFinder" title="importlib.machinery.FileFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.FileFinder</span></code></a> exposes the
  903. mechanism used to search for source and bytecode files of a module. Previously
  904. this class was an implicit member of <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>.</p>
  905. <p>For loaders, the new abstract base class <a class="reference internal" href="../library/importlib.html#importlib.abc.FileLoader" title="importlib.abc.FileLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.FileLoader</span></code></a> helps
  906. write a loader that uses the file system as the storage mechanism for a module’s
  907. code. The loader for source files
  908. (<a class="reference internal" href="../library/importlib.html#importlib.machinery.SourceFileLoader" title="importlib.machinery.SourceFileLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.SourceFileLoader</span></code></a>), sourceless bytecode files
  909. (<a class="reference internal" href="../library/importlib.html#importlib.machinery.SourcelessFileLoader" title="importlib.machinery.SourcelessFileLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.SourcelessFileLoader</span></code></a>), and extension modules
  910. (<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>) are now available for
  911. direct use.</p>
  912. <p><a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> now has <code class="docutils literal notranslate"><span class="pre">name</span></code> and <code class="docutils literal notranslate"><span class="pre">path</span></code> attributes which are set when
  913. there is relevant data to provide. The message for failed imports will also
  914. provide the full name of the module now instead of just the tail end of the
  915. module’s name.</p>
  916. <p>The <a class="reference internal" href="../library/importlib.html#importlib.invalidate_caches" title="importlib.invalidate_caches"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.invalidate_caches()</span></code></a> function will now call the method with
  917. the same name on all finders cached 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> to help
  918. clean up any stored state as necessary.</p>
  919. </section>
  920. <section id="visible-changes">
  921. <h3>Visible Changes<a class="headerlink" href="#visible-changes" title="Link to this heading">¶</a></h3>
  922. <p>For potential required changes to code, see the <a class="reference internal" href="#porting-python-code">Porting Python code</a>
  923. section.</p>
  924. <p>Beyond the expanse of what <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> now exposes, there are other
  925. visible changes to import. The biggest is that <a class="reference internal" href="../library/sys.html#sys.meta_path" title="sys.meta_path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.meta_path</span></code></a> and
  926. <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> now store all of the meta path finders and path entry
  927. hooks used by import. Previously the finders were implicit and hidden within
  928. the C code of import instead of being directly exposed. This means that one can
  929. now easily remove or change the order of the various finders to fit one’s needs.</p>
  930. <p>Another change is that all modules have a <code class="docutils literal notranslate"><span class="pre">__loader__</span></code> attribute, storing the
  931. loader used to create the module. <span class="target" id="index-21"></span><a class="pep reference external" href="https://peps.python.org/pep-0302/"><strong>PEP 302</strong></a> has been updated to make this
  932. attribute mandatory for loaders to implement, so in the future once 3rd-party
  933. loaders have been updated people will be able to rely on the existence of the
  934. attribute. Until such time, though, import is setting the module post-load.</p>
  935. <p>Loaders are also now expected to set the <code class="docutils literal notranslate"><span class="pre">__package__</span></code> attribute from
  936. <span class="target" id="index-22"></span><a class="pep reference external" href="https://peps.python.org/pep-0366/"><strong>PEP 366</strong></a>. Once again, import itself is already setting this on all loaders
  937. 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> and import itself is setting the attribute post-load.</p>
  938. <p><code class="docutils literal notranslate"><span class="pre">None</span></code> is now inserted into <a class="reference internal" href="../library/sys.html#sys.path_importer_cache" title="sys.path_importer_cache"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path_importer_cache</span></code></a> when no finder
  939. can be found on <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>. Since <code class="xref py py-class docutils literal notranslate"><span class="pre">imp.NullImporter</span></code> is not
  940. directly exposed on <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> it could no longer be relied upon to
  941. always be available to use as a value representing no finder found.</p>
  942. <p>All other changes relate to semantic changes which should be taken into
  943. consideration when updating code for Python 3.3, and thus should be read about
  944. in the <a class="reference internal" href="#porting-python-code">Porting Python code</a> section of this document.</p>
  945. <p>(Implementation by Brett Cannon)</p>
  946. </section>
  947. </section>
  948. <section id="other-language-changes">
  949. <h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading">¶</a></h2>
  950. <p>Some smaller changes made to the core Python language are:</p>
  951. <ul>
  952. <li><p>Added support for Unicode name aliases and named sequences.
  953. Both <a class="reference internal" href="../library/unicodedata.html#unicodedata.lookup" title="unicodedata.lookup"><code class="xref py py-func docutils literal notranslate"><span class="pre">unicodedata.lookup()</span></code></a> and <code class="docutils literal notranslate"><span class="pre">'\N{...}'</span></code> now resolve name aliases,
  954. and <a class="reference internal" href="../library/unicodedata.html#unicodedata.lookup" title="unicodedata.lookup"><code class="xref py py-func docutils literal notranslate"><span class="pre">unicodedata.lookup()</span></code></a> resolves named sequences too.</p>
  955. <p>(Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12753">bpo-12753</a>.)</p>
  956. </li>
  957. <li><p>Unicode database updated to UCD version 6.1.0</p></li>
  958. <li><p>Equality comparisons on <a class="reference internal" href="../library/stdtypes.html#range" title="range"><code class="xref py py-func docutils literal notranslate"><span class="pre">range()</span></code></a> objects now return a result reflecting
  959. the equality of the underlying sequences generated by those range objects.
  960. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13201">bpo-13201</a>)</p></li>
  961. <li><p>The <code class="docutils literal notranslate"><span class="pre">count()</span></code>, <code class="docutils literal notranslate"><span class="pre">find()</span></code>, <code class="docutils literal notranslate"><span class="pre">rfind()</span></code>, <code class="docutils literal notranslate"><span class="pre">index()</span></code> and <code class="docutils literal notranslate"><span class="pre">rindex()</span></code>
  962. methods of <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> objects now accept an
  963. integer between 0 and 255 as their first argument.</p>
  964. <p>(Contributed by Petri Lehtinen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12170">bpo-12170</a>.)</p>
  965. </li>
  966. <li><p>The <code class="docutils literal notranslate"><span class="pre">rjust()</span></code>, <code class="docutils literal notranslate"><span class="pre">ljust()</span></code>, and <code class="docutils literal notranslate"><span class="pre">center()</span></code> methods of <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>
  967. 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> now accept a <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> for the <code class="docutils literal notranslate"><span class="pre">fill</span></code>
  968. argument. (Contributed by Petri Lehtinen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12380">bpo-12380</a>.)</p></li>
  969. <li><p>New methods have been added to <a class="reference internal" href="../library/stdtypes.html#list" title="list"><code class="xref py py-class docutils literal notranslate"><span class="pre">list</span></code></a> 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>:
  970. <code class="docutils literal notranslate"><span class="pre">copy()</span></code> and <code class="docutils literal notranslate"><span class="pre">clear()</span></code> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10516">bpo-10516</a>). Consequently,
  971. <a class="reference internal" href="../library/collections.abc.html#collections.abc.MutableSequence" title="collections.abc.MutableSequence"><code class="xref py py-class docutils literal notranslate"><span class="pre">MutableSequence</span></code></a> now also defines a
  972. <code class="xref py py-meth docutils literal notranslate"><span class="pre">clear()</span></code> method (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11388">bpo-11388</a>).</p></li>
  973. <li><p>Raw bytes literals can now be written <code class="docutils literal notranslate"><span class="pre">rb&quot;...&quot;</span></code> as well as <code class="docutils literal notranslate"><span class="pre">br&quot;...&quot;</span></code>.</p>
  974. <p>(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13748">bpo-13748</a>.)</p>
  975. </li>
  976. <li><p><a class="reference internal" href="../library/stdtypes.html#dict.setdefault" title="dict.setdefault"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dict.setdefault()</span></code></a> now does only one lookup for the given key, making
  977. it atomic when used with built-in types.</p>
  978. <p>(Contributed by Filip Gruszczyński in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13521">bpo-13521</a>.)</p>
  979. </li>
  980. <li><p>The error messages produced when a function call does not match the function
  981. signature have been significantly improved.</p>
  982. <p>(Contributed by Benjamin Peterson.)</p>
  983. </li>
  984. </ul>
  985. </section>
  986. <section id="a-finer-grained-import-lock">
  987. <h2>A Finer-Grained Import Lock<a class="headerlink" href="#a-finer-grained-import-lock" title="Link to this heading">¶</a></h2>
  988. <p>Previous versions of CPython have always relied on a global import lock.
  989. This led to unexpected annoyances, such as deadlocks when importing a module
  990. would trigger code execution in a different thread as a side-effect.
  991. Clumsy workarounds were sometimes employed, such as the
  992. <a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModuleNoBlock" title="PyImport_ImportModuleNoBlock"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModuleNoBlock()</span></code></a> C API function.</p>
  993. <p>In Python 3.3, importing a module takes a per-module lock. This correctly
  994. serializes importation of a given module from multiple threads (preventing
  995. the exposure of incompletely initialized modules), while eliminating the
  996. aforementioned annoyances.</p>
  997. <p>(Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9260">bpo-9260</a>.)</p>
  998. </section>
  999. <section id="builtin-functions-and-types">
  1000. <h2>Builtin functions and types<a class="headerlink" href="#builtin-functions-and-types" title="Link to this heading">¶</a></h2>
  1001. <ul class="simple">
  1002. <li><p><a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> gets a new <em>opener</em> parameter: the underlying file descriptor
  1003. for the file object is then obtained by calling <em>opener</em> with (<em>file</em>,
  1004. <em>flags</em>). It can be used to use custom flags like <a class="reference internal" href="../library/os.html#os.O_CLOEXEC" title="os.O_CLOEXEC"><code class="xref py py-const docutils literal notranslate"><span class="pre">os.O_CLOEXEC</span></code></a> for
  1005. example. The <code class="docutils literal notranslate"><span class="pre">'x'</span></code> mode was added: open for exclusive creation, failing if
  1006. the file already exists.</p></li>
  1007. <li><p><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>: added the <em>flush</em> keyword argument. If the <em>flush</em> keyword
  1008. argument is true, the stream is forcibly flushed.</p></li>
  1009. <li><p><a class="reference internal" href="../library/functions.html#hash" title="hash"><code class="xref py py-func docutils literal notranslate"><span class="pre">hash()</span></code></a>: hash randomization is enabled by default, see
  1010. <a class="reference internal" href="../reference/datamodel.html#object.__hash__" title="object.__hash__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__hash__()</span></code></a> and <span class="target" id="index-23"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHASHSEED"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHASHSEED</span></code></a>.</p></li>
  1011. <li><p>The <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> type gets a new <a class="reference internal" href="../library/stdtypes.html#str.casefold" title="str.casefold"><code class="xref py py-meth docutils literal notranslate"><span class="pre">casefold()</span></code></a> method: return a
  1012. casefolded copy of the string, casefolded strings may be used for caseless
  1013. matching. For example, <code class="docutils literal notranslate"><span class="pre">'ß'.casefold()</span></code> returns <code class="docutils literal notranslate"><span class="pre">'ss'</span></code>.</p></li>
  1014. <li><p>The sequence documentation has been substantially rewritten to better
  1015. explain the binary/text sequence distinction and to provide specific
  1016. documentation sections for the individual builtin sequence types
  1017. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4966">bpo-4966</a>).</p></li>
  1018. </ul>
  1019. </section>
  1020. <section id="new-modules">
  1021. <h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading">¶</a></h2>
  1022. <section id="faulthandler">
  1023. <h3>faulthandler<a class="headerlink" href="#faulthandler" title="Link to this heading">¶</a></h3>
  1024. <p>This new debug module <a class="reference internal" href="../library/faulthandler.html#module-faulthandler" title="faulthandler: Dump the Python traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code></a> contains functions to dump Python tracebacks explicitly,
  1025. on a fault (a crash like a segmentation fault), after a timeout, or on a user
  1026. signal. Call <a class="reference internal" href="../library/faulthandler.html#faulthandler.enable" title="faulthandler.enable"><code class="xref py py-func docutils literal notranslate"><span class="pre">faulthandler.enable()</span></code></a> to install fault handlers for the
  1027. <code class="xref py py-const docutils literal notranslate"><span class="pre">SIGSEGV</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">SIGFPE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">SIGABRT</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">SIGBUS</span></code>, and
  1028. <code class="xref py py-const docutils literal notranslate"><span class="pre">SIGILL</span></code> signals. You can also enable them at startup by setting the
  1029. <span class="target" id="index-24"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONFAULTHANDLER"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONFAULTHANDLER</span></code></a> environment variable or by using <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a>
  1030. <code class="docutils literal notranslate"><span class="pre">faulthandler</span></code> command line option.</p>
  1031. <p>Example of a segmentation fault on Linux:</p>
  1032. <div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>python<span class="w"> </span>-q<span class="w"> </span>-X<span class="w"> </span>faulthandler
  1033. <span class="go">&gt;&gt;&gt; import ctypes</span>
  1034. <span class="go">&gt;&gt;&gt; ctypes.string_at(0)</span>
  1035. <span class="go">Fatal Python error: Segmentation fault</span>
  1036. <span class="go">Current thread 0x00007fb899f39700:</span>
  1037. <span class="go"> File &quot;/home/python/cpython/Lib/ctypes/__init__.py&quot;, line 486 in string_at</span>
  1038. <span class="go"> File &quot;&lt;stdin&gt;&quot;, line 1 in &lt;module&gt;</span>
  1039. <span class="go">Segmentation fault</span>
  1040. </pre></div>
  1041. </div>
  1042. </section>
  1043. <section id="ipaddress">
  1044. <h3>ipaddress<a class="headerlink" href="#ipaddress" title="Link to this heading">¶</a></h3>
  1045. <p>The new <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 provides tools for creating and manipulating
  1046. objects representing IPv4 and IPv6 addresses, networks and interfaces (i.e.
  1047. an IP address associated with a specific IP subnet).</p>
  1048. <p>(Contributed by Google and Peter Moody in <span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-3144/"><strong>PEP 3144</strong></a>.)</p>
  1049. </section>
  1050. <section id="lzma">
  1051. <h3>lzma<a class="headerlink" href="#lzma" title="Link to this heading">¶</a></h3>
  1052. <p>The newly added <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> module provides data compression and decompression
  1053. using the LZMA algorithm, including support for the <code class="docutils literal notranslate"><span class="pre">.xz</span></code> and <code class="docutils literal notranslate"><span class="pre">.lzma</span></code>
  1054. file formats.</p>
  1055. <p>(Contributed by Nadeem Vawda and Per Øyvind Karlsen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6715">bpo-6715</a>.)</p>
  1056. </section>
  1057. </section>
  1058. <section id="improved-modules">
  1059. <h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading">¶</a></h2>
  1060. <section id="abc">
  1061. <h3>abc<a class="headerlink" href="#abc" title="Link to this heading">¶</a></h3>
  1062. <p>Improved support for abstract base classes containing descriptors composed with
  1063. abstract methods. The recommended approach to declaring abstract descriptors is
  1064. now to provide <code class="xref py py-attr docutils literal notranslate"><span class="pre">__isabstractmethod__</span></code> as a dynamically updated
  1065. property. The built-in descriptors have been updated accordingly.</p>
  1066. <ul class="simple">
  1067. <li><p><a class="reference internal" href="../library/abc.html#abc.abstractproperty" title="abc.abstractproperty"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.abstractproperty</span></code></a> has been deprecated, use <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-class docutils literal notranslate"><span class="pre">property</span></code></a>
  1068. with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.abstractmethod()</span></code></a> instead.</p></li>
  1069. <li><p><a class="reference internal" href="../library/abc.html#abc.abstractclassmethod" title="abc.abstractclassmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.abstractclassmethod</span></code></a> has been deprecated, use
  1070. <a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">classmethod</span></code></a> with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.abstractmethod()</span></code></a> instead.</p></li>
  1071. <li><p><a class="reference internal" href="../library/abc.html#abc.abstractstaticmethod" title="abc.abstractstaticmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.abstractstaticmethod</span></code></a> has been deprecated, use
  1072. <a class="reference internal" href="../library/functions.html#staticmethod" title="staticmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">staticmethod</span></code></a> with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.abstractmethod()</span></code></a> instead.</p></li>
  1073. </ul>
  1074. <p>(Contributed by Darren Dale in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11610">bpo-11610</a>.)</p>
  1075. <p><a class="reference internal" href="../library/abc.html#abc.ABCMeta.register" title="abc.ABCMeta.register"><code class="xref py py-meth docutils literal notranslate"><span class="pre">abc.ABCMeta.register()</span></code></a> now returns the registered subclass, which means
  1076. it can now be used as a class decorator (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10868">bpo-10868</a>).</p>
  1077. </section>
  1078. <section id="array">
  1079. <h3>array<a class="headerlink" href="#array" title="Link to this heading">¶</a></h3>
  1080. <p>The <a class="reference internal" href="../library/array.html#module-array" title="array: Space efficient arrays of uniformly typed numeric values."><code class="xref py py-mod docutils literal notranslate"><span class="pre">array</span></code></a> module supports the <span class="c-expr sig sig-inline c"><span class="kt">long</span><span class="w"> </span><span class="kt">long</span></span> type using <code class="docutils literal notranslate"><span class="pre">q</span></code> and
  1081. <code class="docutils literal notranslate"><span class="pre">Q</span></code> type codes.</p>
  1082. <p>(Contributed by Oren Tirosh and Hirokazu Yamamoto in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1172711">bpo-1172711</a>.)</p>
  1083. </section>
  1084. <section id="base64">
  1085. <h3>base64<a class="headerlink" href="#base64" title="Link to this heading">¶</a></h3>
  1086. <p>ASCII-only Unicode strings are now accepted by the decoding functions of the
  1087. <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> modern interface. For example, <code class="docutils literal notranslate"><span class="pre">base64.b64decode('YWJj')</span></code>
  1088. returns <code class="docutils literal notranslate"><span class="pre">b'abc'</span></code>. (Contributed by Catalin Iacob in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13641">bpo-13641</a>.)</p>
  1089. </section>
  1090. <section id="binascii">
  1091. <h3>binascii<a class="headerlink" href="#binascii" title="Link to this heading">¶</a></h3>
  1092. <p>In addition to the binary objects they normally accept, the <code class="docutils literal notranslate"><span class="pre">a2b_</span></code> functions
  1093. now all also accept ASCII-only strings as input. (Contributed by Antoine
  1094. Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13637">bpo-13637</a>.)</p>
  1095. </section>
  1096. <section id="bz2">
  1097. <h3>bz2<a class="headerlink" href="#bz2" title="Link to this heading">¶</a></h3>
  1098. <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> module has been rewritten from scratch. In the process, several
  1099. new features have been added:</p>
  1100. <ul>
  1101. <li><p>New <a class="reference internal" href="../library/bz2.html#bz2.open" title="bz2.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">bz2.open()</span></code></a> function: open a bzip2-compressed file in binary or
  1102. text mode.</p></li>
  1103. <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> can now read from and write to arbitrary file-like
  1104. objects, by means of its constructor’s <em>fileobj</em> argument.</p>
  1105. <p>(Contributed by Nadeem Vawda in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5863">bpo-5863</a>.)</p>
  1106. </li>
  1107. <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> and <a class="reference internal" href="../library/bz2.html#bz2.decompress" title="bz2.decompress"><code class="xref py py-func docutils literal notranslate"><span class="pre">bz2.decompress()</span></code></a> can now decompress
  1108. multi-stream inputs (such as those produced by the <strong class="program">pbzip2</strong> tool).
  1109. <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> can now also be used to create this type of file, using
  1110. the <code class="docutils literal notranslate"><span class="pre">'a'</span></code> (append) mode.</p>
  1111. <p>(Contributed by Nir Aides in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1625">bpo-1625</a>.)</p>
  1112. </li>
  1113. <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> now implements all of the <a class="reference internal" href="../library/io.html#io.BufferedIOBase" title="io.BufferedIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.BufferedIOBase</span></code></a> API,
  1114. except for the <code class="xref py py-meth docutils literal notranslate"><span class="pre">detach()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">truncate()</span></code> methods.</p></li>
  1115. </ul>
  1116. </section>
  1117. <section id="codecs">
  1118. <h3>codecs<a class="headerlink" href="#codecs" title="Link to this heading">¶</a></h3>
  1119. <p>The <a class="reference internal" href="../library/codecs.html#module-encodings.mbcs" title="encodings.mbcs: Windows ANSI codepage"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mbcs</span></code></a> codec has been rewritten to handle correctly
  1120. <code class="docutils literal notranslate"><span class="pre">replace</span></code> and <code class="docutils literal notranslate"><span class="pre">ignore</span></code> error handlers on all Windows versions. The
  1121. <a class="reference internal" href="../library/codecs.html#module-encodings.mbcs" title="encodings.mbcs: Windows ANSI codepage"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mbcs</span></code></a> codec now supports all error handlers, instead of only
  1122. <code class="docutils literal notranslate"><span class="pre">replace</span></code> to encode and <code class="docutils literal notranslate"><span class="pre">ignore</span></code> to decode.</p>
  1123. <p>A new Windows-only codec has been added: <code class="docutils literal notranslate"><span class="pre">cp65001</span></code> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13216">bpo-13216</a>). It is the
  1124. Windows code page 65001 (Windows UTF-8, <code class="docutils literal notranslate"><span class="pre">CP_UTF8</span></code>). For example, it is used
  1125. by <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code> if the console output code page is set to cp65001 (e.g., using
  1126. <code class="docutils literal notranslate"><span class="pre">chcp</span> <span class="pre">65001</span></code> command).</p>
  1127. <p>Multibyte CJK decoders now resynchronize faster. They only ignore the first
  1128. byte of an invalid byte sequence. For example, <code class="docutils literal notranslate"><span class="pre">b'\xff\n'.decode('gb2312',</span>
  1129. <span class="pre">'replace')</span></code> now returns a <code class="docutils literal notranslate"><span class="pre">\n</span></code> after the replacement character.</p>
  1130. <p>(<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12016">bpo-12016</a>)</p>
  1131. <p>Incremental CJK codec encoders are no longer reset at each call to their
  1132. encode() methods. For example:</p>
  1133. <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>
  1134. <span class="gp">&gt;&gt;&gt; </span><span class="n">encoder</span> <span class="o">=</span> <span class="n">codecs</span><span class="o">.</span><span class="n">getincrementalencoder</span><span class="p">(</span><span class="s1">&#39;hz&#39;</span><span class="p">)(</span><span class="s1">&#39;strict&#39;</span><span class="p">)</span>
  1135. <span class="gp">&gt;&gt;&gt; </span><span class="sa">b</span><span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">encoder</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="s1">&#39;</span><span class="se">\u52ff\u65bd\u65bc\u4eba\u3002</span><span class="s1"> Bye.&#39;</span><span class="p">)</span>
  1136. <span class="go">b&#39;~{NpJ)l6HK!#~} Bye.&#39;</span>
  1137. </pre></div>
  1138. </div>
  1139. <p>This example gives <code class="docutils literal notranslate"><span class="pre">b'~{Np~}~{J)~}~{l6~}~{HK~}~{!#~}</span> <span class="pre">Bye.'</span></code> with older Python
  1140. versions.</p>
  1141. <p>(<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12100">bpo-12100</a>)</p>
  1142. <p>The <code class="docutils literal notranslate"><span class="pre">unicode_internal</span></code> codec has been deprecated.</p>
  1143. </section>
  1144. <section id="collections">
  1145. <h3>collections<a class="headerlink" href="#collections" title="Link to this heading">¶</a></h3>
  1146. <p>Addition of a new <a class="reference internal" href="../library/collections.html#collections.ChainMap" title="collections.ChainMap"><code class="xref py py-class docutils literal notranslate"><span class="pre">ChainMap</span></code></a> class to allow treating a
  1147. number of mappings as a single unit. (Written by Raymond Hettinger for
  1148. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11089">bpo-11089</a>, made public in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11297">bpo-11297</a>.)</p>
  1149. <p>The abstract base classes have been moved in a new <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>
  1150. module, to better differentiate between the abstract and the concrete
  1151. collections classes. Aliases for ABCs are still present in the
  1152. <a class="reference internal" href="../library/collections.html#module-collections" title="collections: Container datatypes"><code class="xref py py-mod docutils literal notranslate"><span class="pre">collections</span></code></a> module to preserve existing imports. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11085">bpo-11085</a>)</p>
  1153. <p>The <a class="reference internal" href="../library/collections.html#collections.Counter" title="collections.Counter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Counter</span></code></a> class now supports the unary <code class="docutils literal notranslate"><span class="pre">+</span></code> and <code class="docutils literal notranslate"><span class="pre">-</span></code>
  1154. operators, as well as the in-place operators <code class="docutils literal notranslate"><span class="pre">+=</span></code>, <code class="docutils literal notranslate"><span class="pre">-=</span></code>, <code class="docutils literal notranslate"><span class="pre">|=</span></code>, and
  1155. <code class="docutils literal notranslate"><span class="pre">&amp;=</span></code>. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13121">bpo-13121</a>.)</p>
  1156. </section>
  1157. <section id="contextlib">
  1158. <h3>contextlib<a class="headerlink" href="#contextlib" title="Link to this heading">¶</a></h3>
  1159. <p><a class="reference internal" href="../library/contextlib.html#contextlib.ExitStack" title="contextlib.ExitStack"><code class="xref py py-class docutils literal notranslate"><span class="pre">ExitStack</span></code></a> now provides a solid foundation for
  1160. programmatic manipulation of context managers and similar cleanup
  1161. functionality. Unlike the previous <code class="docutils literal notranslate"><span class="pre">contextlib.nested</span></code> API (which was
  1162. deprecated and removed), the new API is designed to work correctly
  1163. regardless of whether context managers acquire their resources in
  1164. their <code class="docutils literal notranslate"><span class="pre">__init__</span></code> method (for example, file objects) or in their
  1165. <code class="docutils literal notranslate"><span class="pre">__enter__</span></code> method (for example, synchronisation objects from the
  1166. <a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a> module).</p>
  1167. <p>(<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13585">bpo-13585</a>)</p>
  1168. </section>
  1169. <section id="crypt">
  1170. <h3>crypt<a class="headerlink" href="#crypt" title="Link to this heading">¶</a></h3>
  1171. <p>Addition of salt and modular crypt format (hashing method) and the <a class="reference internal" href="../library/crypt.html#crypt.mksalt" title="crypt.mksalt"><code class="xref py py-func docutils literal notranslate"><span class="pre">mksalt()</span></code></a>
  1172. function to the <a class="reference internal" href="../library/crypt.html#module-crypt" title="crypt: The crypt() function used to check Unix passwords. (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">crypt</span></code></a> module.</p>
  1173. <p>(<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10924">bpo-10924</a>)</p>
  1174. </section>
  1175. <section id="curses">
  1176. <h3>curses<a class="headerlink" href="#curses" title="Link to this heading">¶</a></h3>
  1177. <ul class="simple">
  1178. <li><p>If the <a class="reference internal" href="../library/curses.html#module-curses" title="curses: An interface to the curses library, providing portable terminal handling. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses</span></code></a> module is linked to the ncursesw library, use Unicode
  1179. functions when Unicode strings or characters are passed (e.g.
  1180. <code class="xref c c-func docutils literal notranslate"><span class="pre">waddwstr()</span></code>), and bytes functions otherwise (e.g. <code class="xref c c-func docutils literal notranslate"><span class="pre">waddstr()</span></code>).</p></li>
  1181. <li><p>Use the locale encoding instead of <code class="docutils literal notranslate"><span class="pre">utf-8</span></code> to encode Unicode strings.</p></li>
  1182. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">curses.window</span></code> has a new <a class="reference internal" href="../library/curses.html#curses.window.encoding" title="curses.window.encoding"><code class="xref py py-attr docutils literal notranslate"><span class="pre">curses.window.encoding</span></code></a> attribute.</p></li>
  1183. <li><p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">curses.window</span></code> class has a new <a class="reference internal" href="../library/curses.html#curses.window.get_wch" title="curses.window.get_wch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_wch()</span></code></a>
  1184. method to get a wide character</p></li>
  1185. <li><p>The <a class="reference internal" href="../library/curses.html#module-curses" title="curses: An interface to the curses library, providing portable terminal handling. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">curses</span></code></a> module has a new <a class="reference internal" href="../library/curses.html#curses.unget_wch" title="curses.unget_wch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unget_wch()</span></code></a> function to
  1186. push a wide character so the next <a class="reference internal" href="../library/curses.html#curses.window.get_wch" title="curses.window.get_wch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_wch()</span></code></a> will return
  1187. it</p></li>
  1188. </ul>
  1189. <p>(Contributed by Iñigo Serna in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6755">bpo-6755</a>.)</p>
  1190. </section>
  1191. <section id="datetime">
  1192. <h3>datetime<a class="headerlink" href="#datetime" title="Link to this heading">¶</a></h3>
  1193. <ul class="simple">
  1194. <li><p>Equality comparisons between naive and aware <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a>
  1195. instances now return <a class="reference internal" href="../library/constants.html#False" title="False"><code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code></a> instead of raising <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>
  1196. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15006">bpo-15006</a>).</p></li>
  1197. <li><p>New <a class="reference internal" href="../library/datetime.html#datetime.datetime.timestamp" title="datetime.datetime.timestamp"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.timestamp()</span></code></a> method: Return POSIX timestamp
  1198. corresponding to the <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> instance.</p></li>
  1199. <li><p>The <a class="reference internal" href="../library/datetime.html#datetime.datetime.strftime" title="datetime.datetime.strftime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.strftime()</span></code></a> method supports formatting years
  1200. older than 1000.</p></li>
  1201. <li><p>The <a class="reference internal" href="../library/datetime.html#datetime.datetime.astimezone" title="datetime.datetime.astimezone"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.datetime.astimezone()</span></code></a> method can now be
  1202. called without arguments to convert datetime instance to the system
  1203. timezone.</p></li>
  1204. </ul>
  1205. </section>
  1206. <section id="decimal">
  1207. <span id="new-decimal"></span><h3>decimal<a class="headerlink" href="#decimal" title="Link to this heading">¶</a></h3>
  1208. <dl class="simple">
  1209. <dt><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=7652">bpo-7652</a> - integrate fast native decimal arithmetic.</dt><dd><p>C-module and libmpdec written by Stefan Krah.</p>
  1210. </dd>
  1211. </dl>
  1212. <p>The new C version of the decimal module integrates the high speed libmpdec
  1213. library for arbitrary precision correctly rounded decimal floating point
  1214. arithmetic. libmpdec conforms to IBM’s General Decimal Arithmetic Specification.</p>
  1215. <p>Performance gains range from 10x for database applications to 100x for
  1216. numerically intensive applications. These numbers are expected gains
  1217. for standard precisions used in decimal floating point arithmetic. Since
  1218. the precision is user configurable, the exact figures may vary. For example,
  1219. in integer bignum arithmetic the differences can be significantly higher.</p>
  1220. <p>The following table is meant as an illustration. Benchmarks are available
  1221. at <a class="reference external" href="https://www.bytereef.org/mpdecimal/quickstart.html">https://www.bytereef.org/mpdecimal/quickstart.html</a>.</p>
  1222. <blockquote>
  1223. <div><table class="docutils align-default">
  1224. <thead>
  1225. <tr class="row-odd"><th class="head"></th>
  1226. <th class="head"><p>decimal.py</p></th>
  1227. <th class="head"><p>_decimal</p></th>
  1228. <th class="head"><p>speedup</p></th>
  1229. </tr>
  1230. </thead>
  1231. <tbody>
  1232. <tr class="row-even"><td><p>pi</p></td>
  1233. <td><p>42.02s</p></td>
  1234. <td><p>0.345s</p></td>
  1235. <td><p>120x</p></td>
  1236. </tr>
  1237. <tr class="row-odd"><td><p>telco</p></td>
  1238. <td><p>172.19s</p></td>
  1239. <td><p>5.68s</p></td>
  1240. <td><p>30x</p></td>
  1241. </tr>
  1242. <tr class="row-even"><td><p>psycopg</p></td>
  1243. <td><p>3.57s</p></td>
  1244. <td><p>0.29s</p></td>
  1245. <td><p>12x</p></td>
  1246. </tr>
  1247. </tbody>
  1248. </table>
  1249. </div></blockquote>
  1250. <section id="id1">
  1251. <h4>Features<a class="headerlink" href="#id1" title="Link to this heading">¶</a></h4>
  1252. <ul class="simple">
  1253. <li><p>The <a class="reference internal" href="../library/decimal.html#decimal.FloatOperation" title="decimal.FloatOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FloatOperation</span></code></a> signal optionally enables stricter
  1254. semantics for mixing floats and Decimals.</p></li>
  1255. <li><p>If Python is compiled without threads, the C version automatically
  1256. disables the expensive thread local context machinery. In this case,
  1257. the variable <a class="reference internal" href="../library/decimal.html#decimal.HAVE_THREADS" title="decimal.HAVE_THREADS"><code class="xref py py-const docutils literal notranslate"><span class="pre">HAVE_THREADS</span></code></a> is set to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p></li>
  1258. </ul>
  1259. </section>
  1260. <section id="id2">
  1261. <h4>API changes<a class="headerlink" href="#id2" title="Link to this heading">¶</a></h4>
  1262. <ul>
  1263. <li><p>The C module has the following context limits, depending on the machine
  1264. architecture:</p>
  1265. <blockquote>
  1266. <div><table class="docutils align-default">
  1267. <thead>
  1268. <tr class="row-odd"><th class="head"></th>
  1269. <th class="head"><p>32-bit</p></th>
  1270. <th class="head"><p>64-bit</p></th>
  1271. </tr>
  1272. </thead>
  1273. <tbody>
  1274. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">MAX_PREC</span></code></p></td>
  1275. <td><p><code class="docutils literal notranslate"><span class="pre">425000000</span></code></p></td>
  1276. <td><p><code class="docutils literal notranslate"><span class="pre">999999999999999999</span></code></p></td>
  1277. </tr>
  1278. <tr class="row-odd"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">MAX_EMAX</span></code></p></td>
  1279. <td><p><code class="docutils literal notranslate"><span class="pre">425000000</span></code></p></td>
  1280. <td><p><code class="docutils literal notranslate"><span class="pre">999999999999999999</span></code></p></td>
  1281. </tr>
  1282. <tr class="row-even"><td><p><code class="xref py py-const docutils literal notranslate"><span class="pre">MIN_EMIN</span></code></p></td>
  1283. <td><p><code class="docutils literal notranslate"><span class="pre">-425000000</span></code></p></td>
  1284. <td><p><code class="docutils literal notranslate"><span class="pre">-999999999999999999</span></code></p></td>
  1285. </tr>
  1286. </tbody>
  1287. </table>
  1288. </div></blockquote>
  1289. </li>
  1290. <li><p>In the context templates (<a class="reference internal" href="../library/decimal.html#decimal.DefaultContext" title="decimal.DefaultContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">DefaultContext</span></code></a>,
  1291. <a class="reference internal" href="../library/decimal.html#decimal.BasicContext" title="decimal.BasicContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">BasicContext</span></code></a> and <a class="reference internal" href="../library/decimal.html#decimal.ExtendedContext" title="decimal.ExtendedContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ExtendedContext</span></code></a>)
  1292. the magnitude of <code class="xref py py-attr docutils literal notranslate"><span class="pre">Emax</span></code> and
  1293. <code class="xref py py-attr docutils literal notranslate"><span class="pre">Emin</span></code> has changed to <code class="docutils literal notranslate"><span class="pre">999999</span></code>.</p></li>
  1294. <li><p>The <a class="reference internal" href="../library/decimal.html#decimal.Decimal" title="decimal.Decimal"><code class="xref py py-class docutils literal notranslate"><span class="pre">Decimal</span></code></a> constructor in decimal.py does not observe
  1295. the context limits and converts values with arbitrary exponents or precision
  1296. exactly. Since the C version has internal limits, the following scheme is
  1297. used: If possible, values are converted exactly, otherwise
  1298. <a class="reference internal" href="../library/decimal.html#decimal.InvalidOperation" title="decimal.InvalidOperation"><code class="xref py py-exc docutils literal notranslate"><span class="pre">InvalidOperation</span></code></a> is raised and the result is NaN. In the
  1299. latter case it is always possible to use <a class="reference internal" href="../library/decimal.html#decimal.Context.create_decimal" title="decimal.Context.create_decimal"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_decimal()</span></code></a>
  1300. in order to obtain a rounded or inexact value.</p></li>
  1301. <li><p>The power function in decimal.py is always correctly rounded. In the
  1302. C version, it is defined in terms of the correctly rounded
  1303. <a class="reference internal" href="../library/decimal.html#decimal.Decimal.exp" title="decimal.Decimal.exp"><code class="xref py py-meth docutils literal notranslate"><span class="pre">exp()</span></code></a> and <a class="reference internal" href="../library/decimal.html#decimal.Decimal.ln" title="decimal.Decimal.ln"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ln()</span></code></a> functions,
  1304. but the final result is only “almost always correctly rounded”.</p></li>
  1305. <li><p>In the C version, the context dictionary containing the signals is a
  1306. <a class="reference internal" href="../library/collections.abc.html#collections.abc.MutableMapping" title="collections.abc.MutableMapping"><code class="xref py py-class docutils literal notranslate"><span class="pre">MutableMapping</span></code></a>. For speed reasons,
  1307. <code class="xref py py-attr docutils literal notranslate"><span class="pre">flags</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">traps</span></code> always
  1308. refer to the same <a class="reference internal" href="../library/collections.abc.html#collections.abc.MutableMapping" title="collections.abc.MutableMapping"><code class="xref py py-class docutils literal notranslate"><span class="pre">MutableMapping</span></code></a> that the context
  1309. was initialized with. If a new signal dictionary is assigned,
  1310. <code class="xref py py-attr docutils literal notranslate"><span class="pre">flags</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">traps</span></code>
  1311. are updated with the new values, but they do not reference the RHS
  1312. dictionary.</p></li>
  1313. <li><p>Pickling a <a class="reference internal" href="../library/decimal.html#decimal.Context" title="decimal.Context"><code class="xref py py-class docutils literal notranslate"><span class="pre">Context</span></code></a> produces a different output in order
  1314. to have a common interchange format for the Python and C versions.</p></li>
  1315. <li><p>The order of arguments in the <a class="reference internal" href="../library/decimal.html#decimal.Context" title="decimal.Context"><code class="xref py py-class docutils literal notranslate"><span class="pre">Context</span></code></a> constructor has been
  1316. changed to match the order displayed by <a class="reference internal" href="../library/functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a>.</p></li>
  1317. <li><p>The <code class="docutils literal notranslate"><span class="pre">watchexp</span></code> parameter in the <a class="reference internal" href="../library/decimal.html#decimal.Decimal.quantize" title="decimal.Decimal.quantize"><code class="xref py py-meth docutils literal notranslate"><span class="pre">quantize()</span></code></a> method
  1318. is deprecated.</p></li>
  1319. </ul>
  1320. </section>
  1321. </section>
  1322. <section id="email">
  1323. <span id="new-email"></span><h3>email<a class="headerlink" href="#email" title="Link to this heading">¶</a></h3>
  1324. <section id="policy-framework">
  1325. <h4>Policy Framework<a class="headerlink" href="#policy-framework" title="Link to this heading">¶</a></h4>
  1326. <p>The email package now has a <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> framework. A
  1327. <a class="reference internal" href="../library/email.policy.html#email.policy.Policy" title="email.policy.Policy"><code class="xref py py-class docutils literal notranslate"><span class="pre">Policy</span></code></a> is an object with several methods and properties
  1328. that control how the email package behaves. The primary policy for Python 3.3
  1329. is the <a class="reference internal" href="../library/email.policy.html#email.policy.Compat32" title="email.policy.Compat32"><code class="xref py py-class docutils literal notranslate"><span class="pre">Compat32</span></code></a> policy, which provides backward
  1330. compatibility with the email package in Python 3.2. A <code class="docutils literal notranslate"><span class="pre">policy</span></code> can be
  1331. specified when an email message is parsed by a <a class="reference internal" href="../library/email.parser.html#module-email.parser" title="email.parser: Parse flat text email messages to produce a message object structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code></a>, or when a
  1332. <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> object is created, or when an email is
  1333. serialized using 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>. Unless overridden, a policy passed
  1334. to a <code class="docutils literal notranslate"><span class="pre">parser</span></code> is inherited by all the <code class="docutils literal notranslate"><span class="pre">Message</span></code> object and sub-objects
  1335. created by the <code class="docutils literal notranslate"><span class="pre">parser</span></code>. By default a <code class="docutils literal notranslate"><span class="pre">generator</span></code> will use the policy of
  1336. the <code class="docutils literal notranslate"><span class="pre">Message</span></code> object it is serializing. The default policy is
  1337. <a class="reference internal" href="../library/email.policy.html#email.policy.compat32" title="email.policy.compat32"><code class="xref py py-data docutils literal notranslate"><span class="pre">compat32</span></code></a>.</p>
  1338. <p>The minimum set of controls implemented by all <code class="docutils literal notranslate"><span class="pre">policy</span></code> objects are:</p>
  1339. <table class="docutils align-default">
  1340. <tbody>
  1341. <tr class="row-odd"><td><p>max_line_length</p></td>
  1342. <td><p>The maximum length, excluding the linesep character(s),
  1343. individual lines may have when a <code class="docutils literal notranslate"><span class="pre">Message</span></code> is
  1344. serialized. Defaults to 78.</p></td>
  1345. </tr>
  1346. <tr class="row-even"><td><p>linesep</p></td>
  1347. <td><p>The character used to separate individual lines when a
  1348. <code class="docutils literal notranslate"><span class="pre">Message</span></code> is serialized. Defaults to <code class="docutils literal notranslate"><span class="pre">\n</span></code>.</p></td>
  1349. </tr>
  1350. <tr class="row-odd"><td><p>cte_type</p></td>
  1351. <td><p><code class="docutils literal notranslate"><span class="pre">7bit</span></code> or <code class="docutils literal notranslate"><span class="pre">8bit</span></code>. <code class="docutils literal notranslate"><span class="pre">8bit</span></code> applies only to a
  1352. <code class="docutils literal notranslate"><span class="pre">Bytes</span></code> <code class="docutils literal notranslate"><span class="pre">generator</span></code>, and means that non-ASCII may
  1353. be used where allowed by the protocol (or where it
  1354. exists in the original input).</p></td>
  1355. </tr>
  1356. <tr class="row-even"><td><p>raise_on_defect</p></td>
  1357. <td><p>Causes a <code class="docutils literal notranslate"><span class="pre">parser</span></code> to raise error when defects are
  1358. encountered instead of adding them to the <code class="docutils literal notranslate"><span class="pre">Message</span></code>
  1359. object’s <code class="docutils literal notranslate"><span class="pre">defects</span></code> list.</p></td>
  1360. </tr>
  1361. </tbody>
  1362. </table>
  1363. <p>A new policy instance, with new settings, is created using the
  1364. <a class="reference internal" href="../library/email.policy.html#email.policy.Policy.clone" title="email.policy.Policy.clone"><code class="xref py py-meth docutils literal notranslate"><span class="pre">clone()</span></code></a> method of policy objects. <code class="docutils literal notranslate"><span class="pre">clone</span></code> takes
  1365. any of the above controls as keyword arguments. Any control not specified in
  1366. the call retains its default value. Thus you can create a policy that uses
  1367. <code class="docutils literal notranslate"><span class="pre">\r\n</span></code> linesep characters like this:</p>
  1368. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">mypolicy</span> <span class="o">=</span> <span class="n">compat32</span><span class="o">.</span><span class="n">clone</span><span class="p">(</span><span class="n">linesep</span><span class="o">=</span><span class="s1">&#39;</span><span class="se">\r\n</span><span class="s1">&#39;</span><span class="p">)</span>
  1369. </pre></div>
  1370. </div>
  1371. <p>Policies can be used to make the generation of messages in the format needed by
  1372. your application simpler. Instead of having to remember to specify
  1373. <code class="docutils literal notranslate"><span class="pre">linesep='\r\n'</span></code> in all the places you call a <code class="docutils literal notranslate"><span class="pre">generator</span></code>, you can specify
  1374. it once, when you set the policy used by the <code class="docutils literal notranslate"><span class="pre">parser</span></code> or the <code class="docutils literal notranslate"><span class="pre">Message</span></code>,
  1375. whichever your program uses to create <code class="docutils literal notranslate"><span class="pre">Message</span></code> objects. On the other hand,
  1376. if you need to generate messages in multiple forms, you can still specify the
  1377. parameters in the appropriate <code class="docutils literal notranslate"><span class="pre">generator</span></code> call. Or you can have custom
  1378. policy instances for your different cases, and pass those in when you create
  1379. the <code class="docutils literal notranslate"><span class="pre">generator</span></code>.</p>
  1380. </section>
  1381. <section id="provisional-policy-with-new-header-api">
  1382. <h4>Provisional Policy with New Header API<a class="headerlink" href="#provisional-policy-with-new-header-api" title="Link to this heading">¶</a></h4>
  1383. <p>While the policy framework is worthwhile all by itself, the main motivation for
  1384. introducing it is to allow the creation of new policies that implement new
  1385. features for the email package in a way that maintains backward compatibility
  1386. for those who do not use the new policies. Because the new policies introduce a
  1387. new API, we are releasing them in Python 3.3 as a <a class="reference internal" href="../glossary.html#term-provisional-package"><span class="xref std std-term">provisional policy</span></a>. Backwards incompatible changes (up to and including
  1388. removal of the code) may occur if deemed necessary by the core developers.</p>
  1389. <p>The new policies are instances of <a class="reference internal" href="../library/email.policy.html#email.policy.EmailPolicy" title="email.policy.EmailPolicy"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailPolicy</span></code></a>,
  1390. and add the following additional controls:</p>
  1391. <table class="docutils align-default">
  1392. <tbody>
  1393. <tr class="row-odd"><td><p>refold_source</p></td>
  1394. <td><p>Controls whether or not headers parsed by a
  1395. <a class="reference internal" href="../library/email.parser.html#module-email.parser" title="email.parser: Parse flat text email messages to produce a message object structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code></a> are refolded by the
  1396. <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>. It can be <code class="docutils literal notranslate"><span class="pre">none</span></code>, <code class="docutils literal notranslate"><span class="pre">long</span></code>,
  1397. or <code class="docutils literal notranslate"><span class="pre">all</span></code>. The default is <code class="docutils literal notranslate"><span class="pre">long</span></code>, which means that
  1398. source headers with a line longer than
  1399. <code class="docutils literal notranslate"><span class="pre">max_line_length</span></code> get refolded. <code class="docutils literal notranslate"><span class="pre">none</span></code> means no
  1400. line get refolded, and <code class="docutils literal notranslate"><span class="pre">all</span></code> means that all lines
  1401. get refolded.</p></td>
  1402. </tr>
  1403. <tr class="row-even"><td><p>header_factory</p></td>
  1404. <td><p>A callable that take a <code class="docutils literal notranslate"><span class="pre">name</span></code> and <code class="docutils literal notranslate"><span class="pre">value</span></code> and
  1405. produces a custom header object.</p></td>
  1406. </tr>
  1407. </tbody>
  1408. </table>
  1409. <p>The <code class="docutils literal notranslate"><span class="pre">header_factory</span></code> is the key to the new features provided by the new
  1410. policies. When one of the new policies is used, any header retrieved from
  1411. a <code class="docutils literal notranslate"><span class="pre">Message</span></code> object is an object produced by the <code class="docutils literal notranslate"><span class="pre">header_factory</span></code>, and any
  1412. time you set a header on a <code class="docutils literal notranslate"><span class="pre">Message</span></code> it becomes an object produced by
  1413. <code class="docutils literal notranslate"><span class="pre">header_factory</span></code>. All such header objects have a <code class="docutils literal notranslate"><span class="pre">name</span></code> attribute equal
  1414. to the header name. Address and Date headers have additional attributes
  1415. that give you access to the parsed data of the header. This means you can now
  1416. do things like this:</p>
  1417. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">m</span> <span class="o">=</span> <span class="n">Message</span><span class="p">(</span><span class="n">policy</span><span class="o">=</span><span class="n">SMTP</span><span class="p">)</span>
  1418. <span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s1">&#39;To&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;Éric &lt;foo@example.com&gt;&#39;</span>
  1419. <span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s1">&#39;to&#39;</span><span class="p">]</span>
  1420. <span class="go">&#39;Éric &lt;foo@example.com&gt;&#39;</span>
  1421. <span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s1">&#39;to&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">addresses</span>
  1422. <span class="go">(Address(display_name=&#39;Éric&#39;, username=&#39;foo&#39;, domain=&#39;example.com&#39;),)</span>
  1423. <span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s1">&#39;to&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">addresses</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">username</span>
  1424. <span class="go">&#39;foo&#39;</span>
  1425. <span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s1">&#39;to&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">addresses</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">display_name</span>
  1426. <span class="go">&#39;Éric&#39;</span>
  1427. <span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s1">&#39;Date&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">email</span><span class="o">.</span><span class="n">utils</span><span class="o">.</span><span class="n">localtime</span><span class="p">()</span>
  1428. <span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s1">&#39;Date&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">datetime</span>
  1429. <span class="go">datetime.datetime(2012, 5, 25, 21, 39, 24, 465484, tzinfo=datetime.timezone(datetime.timedelta(-1, 72000), &#39;EDT&#39;))</span>
  1430. <span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s1">&#39;Date&#39;</span><span class="p">]</span>
  1431. <span class="go">&#39;Fri, 25 May 2012 21:44:27 -0400&#39;</span>
  1432. <span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
  1433. <span class="go">To: =?utf-8?q?=C3=89ric?= &lt;foo@example.com&gt;</span>
  1434. <span class="go">Date: Fri, 25 May 2012 21:44:27 -0400</span>
  1435. </pre></div>
  1436. </div>
  1437. <p>You will note that the unicode display name is automatically encoded as
  1438. <code class="docutils literal notranslate"><span class="pre">utf-8</span></code> when the message is serialized, but that when the header is accessed
  1439. directly, you get the unicode version. This eliminates any need to deal with
  1440. the <a class="reference internal" href="../library/email.header.html#module-email.header" title="email.header: Representing non-ASCII headers"><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.header</span></code></a> <a class="reference internal" href="../library/email.header.html#email.header.decode_header" title="email.header.decode_header"><code class="xref py py-meth docutils literal notranslate"><span class="pre">decode_header()</span></code></a> or
  1441. <a class="reference internal" href="../library/email.header.html#email.header.make_header" title="email.header.make_header"><code class="xref py py-meth docutils literal notranslate"><span class="pre">make_header()</span></code></a> functions.</p>
  1442. <p>You can also create addresses from parts:</p>
  1443. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">m</span><span class="p">[</span><span class="s1">&#39;cc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">Group</span><span class="p">(</span><span class="s1">&#39;pals&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">Address</span><span class="p">(</span><span class="s1">&#39;Bob&#39;</span><span class="p">,</span> <span class="s1">&#39;bob&#39;</span><span class="p">,</span> <span class="s1">&#39;example.com&#39;</span><span class="p">),</span>
  1444. <span class="gp">... </span> <span class="n">Address</span><span class="p">(</span><span class="s1">&#39;Sally&#39;</span><span class="p">,</span> <span class="s1">&#39;sally&#39;</span><span class="p">,</span> <span class="s1">&#39;example.com&#39;</span><span class="p">)]),</span>
  1445. <span class="gp">... </span> <span class="n">Address</span><span class="p">(</span><span class="s1">&#39;Bonzo&#39;</span><span class="p">,</span> <span class="n">addr_spec</span><span class="o">=</span><span class="s1">&#39;bonz@laugh.com&#39;</span><span class="p">)]</span>
  1446. <span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
  1447. <span class="go">To: =?utf-8?q?=C3=89ric?= &lt;foo@example.com&gt;</span>
  1448. <span class="go">Date: Fri, 25 May 2012 21:44:27 -0400</span>
  1449. <span class="go">cc: pals: Bob &lt;bob@example.com&gt;, Sally &lt;sally@example.com&gt;;, Bonzo &lt;bonz@laugh.com&gt;</span>
  1450. </pre></div>
  1451. </div>
  1452. <p>Decoding to unicode is done automatically:</p>
  1453. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">m2</span> <span class="o">=</span> <span class="n">message_from_string</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">m</span><span class="p">))</span>
  1454. <span class="gp">&gt;&gt;&gt; </span><span class="n">m2</span><span class="p">[</span><span class="s1">&#39;to&#39;</span><span class="p">]</span>
  1455. <span class="go">&#39;Éric &lt;foo@example.com&gt;&#39;</span>
  1456. </pre></div>
  1457. </div>
  1458. <p>When you parse a message, you can use the <code class="docutils literal notranslate"><span class="pre">addresses</span></code> and <code class="docutils literal notranslate"><span class="pre">groups</span></code>
  1459. attributes of the header objects to access the groups and individual
  1460. addresses:</p>
  1461. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">m2</span><span class="p">[</span><span class="s1">&#39;cc&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">addresses</span>
  1462. <span class="go">(Address(display_name=&#39;Bob&#39;, username=&#39;bob&#39;, domain=&#39;example.com&#39;), Address(display_name=&#39;Sally&#39;, username=&#39;sally&#39;, domain=&#39;example.com&#39;), Address(display_name=&#39;Bonzo&#39;, username=&#39;bonz&#39;, domain=&#39;laugh.com&#39;))</span>
  1463. <span class="gp">&gt;&gt;&gt; </span><span class="n">m2</span><span class="p">[</span><span class="s1">&#39;cc&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">groups</span>
  1464. <span class="go">(Group(display_name=&#39;pals&#39;, addresses=(Address(display_name=&#39;Bob&#39;, username=&#39;bob&#39;, domain=&#39;example.com&#39;), Address(display_name=&#39;Sally&#39;, username=&#39;sally&#39;, domain=&#39;example.com&#39;)), Group(display_name=None, addresses=(Address(display_name=&#39;Bonzo&#39;, username=&#39;bonz&#39;, domain=&#39;laugh.com&#39;),))</span>
  1465. </pre></div>
  1466. </div>
  1467. <p>In summary, if you use one of the new policies, header manipulation works the
  1468. way it ought to: your application works with unicode strings, and the email
  1469. package transparently encodes and decodes the unicode to and from the RFC
  1470. standard Content Transfer Encodings.</p>
  1471. </section>
  1472. <section id="other-api-changes">
  1473. <h4>Other API Changes<a class="headerlink" href="#other-api-changes" title="Link to this heading">¶</a></h4>
  1474. <p>New <a class="reference internal" href="../library/email.parser.html#email.parser.BytesHeaderParser" title="email.parser.BytesHeaderParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">BytesHeaderParser</span></code></a>, added to the <a class="reference internal" href="../library/email.parser.html#module-email.parser" title="email.parser: Parse flat text email messages to produce a message object structure."><code class="xref py py-mod docutils literal notranslate"><span class="pre">parser</span></code></a>
  1475. module to complement <a class="reference internal" href="../library/email.parser.html#email.parser.HeaderParser" title="email.parser.HeaderParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">HeaderParser</span></code></a> and complete the Bytes
  1476. API.</p>
  1477. <p>New utility functions:</p>
  1478. <ul class="simple">
  1479. <li><p><a class="reference internal" href="../library/email.utils.html#email.utils.format_datetime" title="email.utils.format_datetime"><code class="xref py py-func docutils literal notranslate"><span class="pre">format_datetime()</span></code></a>: given a <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a>,
  1480. produce a string formatted for use in an email header.</p></li>
  1481. <li><p><a class="reference internal" href="../library/email.utils.html#email.utils.parsedate_to_datetime" title="email.utils.parsedate_to_datetime"><code class="xref py py-func docutils literal notranslate"><span class="pre">parsedate_to_datetime()</span></code></a>: given a date string from
  1482. an email header, convert it into an aware <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a>,
  1483. or a naive <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> if the offset is <code class="docutils literal notranslate"><span class="pre">-0000</span></code>.</p></li>
  1484. <li><p><a class="reference internal" href="../library/email.utils.html#email.utils.localtime" title="email.utils.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">localtime()</span></code></a>: With no argument, returns the
  1485. current local time as an aware <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> using the local
  1486. <a class="reference internal" href="../library/datetime.html#datetime.timezone" title="datetime.timezone"><code class="xref py py-class docutils literal notranslate"><span class="pre">timezone</span></code></a>. Given an aware <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a>,
  1487. converts it into an aware <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> using the
  1488. local <a class="reference internal" href="../library/datetime.html#datetime.timezone" title="datetime.timezone"><code class="xref py py-class docutils literal notranslate"><span class="pre">timezone</span></code></a>.</p></li>
  1489. </ul>
  1490. </section>
  1491. </section>
  1492. <section id="ftplib">
  1493. <h3>ftplib<a class="headerlink" href="#ftplib" title="Link to this heading">¶</a></h3>
  1494. <ul class="simple">
  1495. <li><p><a class="reference internal" href="../library/ftplib.html#ftplib.FTP" title="ftplib.FTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">ftplib.FTP</span></code></a> now accepts a <code class="docutils literal notranslate"><span class="pre">source_address</span></code> keyword argument to
  1496. specify the <code class="docutils literal notranslate"><span class="pre">(host,</span> <span class="pre">port)</span></code> to use as the source address in the bind call
  1497. when creating the outgoing socket. (Contributed by Giampaolo Rodolà
  1498. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8594">bpo-8594</a>.)</p></li>
  1499. <li><p>The <a class="reference internal" href="../library/ftplib.html#ftplib.FTP_TLS" title="ftplib.FTP_TLS"><code class="xref py py-class docutils literal notranslate"><span class="pre">FTP_TLS</span></code></a> class now provides a new
  1500. <a class="reference internal" href="../library/ftplib.html#ftplib.FTP_TLS.ccc" title="ftplib.FTP_TLS.ccc"><code class="xref py py-func docutils literal notranslate"><span class="pre">ccc()</span></code></a> function to revert control channel back to
  1501. plaintext. This can be useful to take advantage of firewalls that know how
  1502. to handle NAT with non-secure FTP without opening fixed ports. (Contributed
  1503. by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12139">bpo-12139</a>.)</p></li>
  1504. <li><p>Added <a class="reference internal" href="../library/ftplib.html#ftplib.FTP.mlsd" title="ftplib.FTP.mlsd"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ftplib.FTP.mlsd()</span></code></a> method which provides a parsable directory
  1505. listing format and deprecates <a class="reference internal" href="../library/ftplib.html#ftplib.FTP.nlst" title="ftplib.FTP.nlst"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ftplib.FTP.nlst()</span></code></a> and
  1506. <a class="reference internal" href="../library/ftplib.html#ftplib.FTP.dir" title="ftplib.FTP.dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ftplib.FTP.dir()</span></code></a>. (Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11072">bpo-11072</a>.)</p></li>
  1507. </ul>
  1508. </section>
  1509. <section id="functools">
  1510. <h3>functools<a class="headerlink" href="#functools" title="Link to this heading">¶</a></h3>
  1511. <p>The <a class="reference internal" href="../library/functools.html#functools.lru_cache" title="functools.lru_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.lru_cache()</span></code></a> decorator now accepts a <code class="docutils literal notranslate"><span class="pre">typed</span></code> keyword
  1512. argument (that defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code> to ensure that it caches values of
  1513. different types that compare equal in separate cache slots. (Contributed
  1514. by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13227">bpo-13227</a>.)</p>
  1515. </section>
  1516. <section id="gc">
  1517. <h3>gc<a class="headerlink" href="#gc" title="Link to this heading">¶</a></h3>
  1518. <p>It is now possible to register callbacks invoked by the garbage collector
  1519. before and after collection using the new <a class="reference internal" href="../library/gc.html#gc.callbacks" title="gc.callbacks"><code class="xref py py-data docutils literal notranslate"><span class="pre">callbacks</span></code></a> list.</p>
  1520. </section>
  1521. <section id="hmac">
  1522. <h3>hmac<a class="headerlink" href="#hmac" title="Link to this heading">¶</a></h3>
  1523. <p>A new <a class="reference internal" href="../library/hmac.html#hmac.compare_digest" title="hmac.compare_digest"><code class="xref py py-func docutils literal notranslate"><span class="pre">compare_digest()</span></code></a> function has been added to prevent side
  1524. channel attacks on digests through timing analysis. (Contributed by Nick
  1525. Coghlan and Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15061">bpo-15061</a>.)</p>
  1526. </section>
  1527. <section id="http">
  1528. <h3>http<a class="headerlink" href="#http" title="Link to this heading">¶</a></h3>
  1529. <p><a class="reference internal" href="../library/http.server.html#http.server.BaseHTTPRequestHandler" title="http.server.BaseHTTPRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.server.BaseHTTPRequestHandler</span></code></a> now buffers the headers and writes
  1530. them all at once when <a class="reference internal" href="../library/http.server.html#http.server.BaseHTTPRequestHandler.end_headers" title="http.server.BaseHTTPRequestHandler.end_headers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">end_headers()</span></code></a> is
  1531. called. A new method <a class="reference internal" href="../library/http.server.html#http.server.BaseHTTPRequestHandler.flush_headers" title="http.server.BaseHTTPRequestHandler.flush_headers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flush_headers()</span></code></a>
  1532. can be used to directly manage when the accumulated headers are sent.
  1533. (Contributed by Andrew Schaaf in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=3709">bpo-3709</a>.)</p>
  1534. <p><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-class docutils literal notranslate"><span class="pre">http.server</span></code></a> now produces valid <code class="docutils literal notranslate"><span class="pre">HTML</span> <span class="pre">4.01</span> <span class="pre">strict</span></code> output.
  1535. (Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13295">bpo-13295</a>.)</p>
  1536. <p><a class="reference internal" href="../library/http.client.html#http.client.HTTPResponse" title="http.client.HTTPResponse"><code class="xref py py-class docutils literal notranslate"><span class="pre">http.client.HTTPResponse</span></code></a> now has a
  1537. <a class="reference internal" href="../library/http.client.html#http.client.HTTPResponse.readinto" title="http.client.HTTPResponse.readinto"><code class="xref py py-meth docutils literal notranslate"><span class="pre">readinto()</span></code></a> method, which means it can be used
  1538. as an <a class="reference internal" href="../library/io.html#io.RawIOBase" title="io.RawIOBase"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.RawIOBase</span></code></a> class. (Contributed by John Kuhn in
  1539. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13464">bpo-13464</a>.)</p>
  1540. </section>
  1541. <section id="html">
  1542. <h3>html<a class="headerlink" href="#html" title="Link to this heading">¶</a></h3>
  1543. <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">html.parser.HTMLParser</span></code></a> is now able to parse broken markup without
  1544. raising errors, therefore the <em>strict</em> argument of the constructor and the
  1545. <code class="xref py py-exc docutils literal notranslate"><span class="pre">HTMLParseError</span></code> exception are now deprecated.
  1546. The ability to parse broken markup is the result of a number of bug fixes that
  1547. are also available on the latest bug fix releases of Python 2.7/3.2.
  1548. (Contributed by Ezio Melotti in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15114">bpo-15114</a>, and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14538">bpo-14538</a>,
  1549. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13993">bpo-13993</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13960">bpo-13960</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13358">bpo-13358</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1745761">bpo-1745761</a>,
  1550. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=755670">bpo-755670</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13357">bpo-13357</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12629">bpo-12629</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1200313">bpo-1200313</a>,
  1551. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=670664">bpo-670664</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13273">bpo-13273</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12888">bpo-12888</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=7311">bpo-7311</a>.)</p>
  1552. <p>A new <a class="reference internal" href="../library/html.entities.html#html.entities.html5" title="html.entities.html5"><code class="xref py py-data docutils literal notranslate"><span class="pre">html5</span></code></a> dictionary that maps HTML5 named character
  1553. references to the equivalent Unicode character(s) (e.g. <code class="docutils literal notranslate"><span class="pre">html5['gt;']</span> <span class="pre">==</span>
  1554. <span class="pre">'&gt;'</span></code>) has been added to the <a class="reference internal" href="../library/html.entities.html#module-html.entities" title="html.entities: Definitions of HTML general entities."><code class="xref py py-mod docutils literal notranslate"><span class="pre">html.entities</span></code></a> module. The dictionary is
  1555. now also used by <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>. (Contributed by Ezio
  1556. Melotti in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11113">bpo-11113</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15156">bpo-15156</a>.)</p>
  1557. </section>
  1558. <section id="imaplib">
  1559. <h3>imaplib<a class="headerlink" href="#imaplib" title="Link to this heading">¶</a></h3>
  1560. <p>The <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4_SSL" title="imaplib.IMAP4_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4_SSL</span></code></a> constructor now accepts an SSLContext
  1561. parameter to control parameters of the secure channel.</p>
  1562. <p>(Contributed by Sijin Joseph in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8808">bpo-8808</a>.)</p>
  1563. </section>
  1564. <section id="inspect">
  1565. <h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading">¶</a></h3>
  1566. <p>A new <a class="reference internal" href="../library/inspect.html#inspect.getclosurevars" title="inspect.getclosurevars"><code class="xref py py-func docutils literal notranslate"><span class="pre">getclosurevars()</span></code></a> function has been added. This function
  1567. reports the current binding of all names referenced from the function body and
  1568. where those names were resolved, making it easier to verify correct internal
  1569. state when testing code that relies on stateful closures.</p>
  1570. <p>(Contributed by Meador Inge and Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13062">bpo-13062</a>.)</p>
  1571. <p>A new <a class="reference internal" href="../library/inspect.html#inspect.getgeneratorlocals" title="inspect.getgeneratorlocals"><code class="xref py py-func docutils literal notranslate"><span class="pre">getgeneratorlocals()</span></code></a> function has been added. This
  1572. function reports the current binding of local variables in the generator’s
  1573. stack frame, making it easier to verify correct internal state when testing
  1574. generators.</p>
  1575. <p>(Contributed by Meador Inge in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15153">bpo-15153</a>.)</p>
  1576. </section>
  1577. <section id="io">
  1578. <h3>io<a class="headerlink" href="#io" title="Link to this heading">¶</a></h3>
  1579. <p>The <a class="reference internal" href="../library/io.html#io.open" title="io.open"><code class="xref py py-func docutils literal notranslate"><span class="pre">open()</span></code></a> function has a new <code class="docutils literal notranslate"><span class="pre">'x'</span></code> mode that can be used to
  1580. exclusively create a new file, and raise a <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
  1581. already exists. It is based on the C11 ‘x’ mode to fopen().</p>
  1582. <p>(Contributed by David Townshend in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12760">bpo-12760</a>.)</p>
  1583. <p>The constructor of the <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">TextIOWrapper</span></code></a> class has a new
  1584. <em>write_through</em> optional argument. If <em>write_through</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, calls to
  1585. <code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code> are guaranteed not to be buffered: any data
  1586. written on the <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">TextIOWrapper</span></code></a> object is immediately handled to its
  1587. underlying binary buffer.</p>
  1588. </section>
  1589. <section id="itertools">
  1590. <h3>itertools<a class="headerlink" href="#itertools" title="Link to this heading">¶</a></h3>
  1591. <p><a class="reference internal" href="../library/itertools.html#itertools.accumulate" title="itertools.accumulate"><code class="xref py py-func docutils literal notranslate"><span class="pre">accumulate()</span></code></a> now takes an optional <code class="docutils literal notranslate"><span class="pre">func</span></code> argument for
  1592. providing a user-supplied binary function.</p>
  1593. </section>
  1594. <section id="logging">
  1595. <h3>logging<a class="headerlink" href="#logging" title="Link to this heading">¶</a></h3>
  1596. <p>The <a class="reference internal" href="../library/logging.html#logging.basicConfig" title="logging.basicConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">basicConfig()</span></code></a> function now supports an optional <code class="docutils literal notranslate"><span class="pre">handlers</span></code>
  1597. argument taking an iterable of handlers to be added to the root logger.</p>
  1598. <p>A class level attribute <code class="xref py py-attr docutils literal notranslate"><span class="pre">append_nul</span></code> has
  1599. been added to <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.SysLogHandler" title="logging.handlers.SysLogHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SysLogHandler</span></code></a> to allow control of the
  1600. appending of the <code class="docutils literal notranslate"><span class="pre">NUL</span></code> (<code class="docutils literal notranslate"><span class="pre">\000</span></code>) byte to syslog records, since for some
  1601. daemons it is required while for others it is passed through to the log.</p>
  1602. </section>
  1603. <section id="math">
  1604. <h3>math<a class="headerlink" href="#math" title="Link to this heading">¶</a></h3>
  1605. <p>The <a class="reference internal" href="../library/math.html#module-math" title="math: Mathematical functions (sin() etc.)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">math</span></code></a> module has a new function, <a class="reference internal" href="../library/math.html#math.log2" title="math.log2"><code class="xref py py-func docutils literal notranslate"><span class="pre">log2()</span></code></a>, which returns
  1606. the base-2 logarithm of <em>x</em>.</p>
  1607. <p>(Written by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11888">bpo-11888</a>.)</p>
  1608. </section>
  1609. <section id="mmap">
  1610. <h3>mmap<a class="headerlink" href="#mmap" title="Link to this heading">¶</a></h3>
  1611. <p>The <a class="reference internal" href="../library/mmap.html#mmap.mmap.read" title="mmap.mmap.read"><code class="xref py py-meth docutils literal notranslate"><span class="pre">read()</span></code></a> method is now more compatible with other file-like
  1612. objects: if the argument is omitted or specified as <code class="docutils literal notranslate"><span class="pre">None</span></code>, it returns the
  1613. bytes from the current file position to the end of the mapping. (Contributed
  1614. by Petri Lehtinen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12021">bpo-12021</a>.)</p>
  1615. </section>
  1616. <section id="multiprocessing">
  1617. <h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Link to this heading">¶</a></h3>
  1618. <p>The new <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.connection.wait" title="multiprocessing.connection.wait"><code class="xref py py-func docutils literal notranslate"><span class="pre">multiprocessing.connection.wait()</span></code></a> function allows polling
  1619. multiple objects (such as connections, sockets and pipes) with a timeout.
  1620. (Contributed by Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12328">bpo-12328</a>.)</p>
  1621. <p><code class="xref py py-class docutils literal notranslate"><span class="pre">multiprocessing.Connection</span></code> objects can now be transferred over
  1622. multiprocessing connections.
  1623. (Contributed by Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4892">bpo-4892</a>.)</p>
  1624. <p><a class="reference internal" href="../library/multiprocessing.html#multiprocessing.Process" title="multiprocessing.Process"><code class="xref py py-class docutils literal notranslate"><span class="pre">multiprocessing.Process</span></code></a> now accepts a <code class="docutils literal notranslate"><span class="pre">daemon</span></code> keyword argument
  1625. to override the default behavior of inheriting the <code class="docutils literal notranslate"><span class="pre">daemon</span></code> flag from
  1626. the parent process (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6064">bpo-6064</a>).</p>
  1627. <p>New attribute <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.Process.sentinel" title="multiprocessing.Process.sentinel"><code class="xref py py-data docutils literal notranslate"><span class="pre">multiprocessing.Process.sentinel</span></code></a> allows a
  1628. program to wait on multiple <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.Process" title="multiprocessing.Process"><code class="xref py py-class docutils literal notranslate"><span class="pre">Process</span></code></a> objects at one
  1629. time using the appropriate OS primitives (for example, <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> on
  1630. posix systems).</p>
  1631. <p>New methods <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.pool.Pool.starmap" title="multiprocessing.pool.Pool.starmap"><code class="xref py py-meth docutils literal notranslate"><span class="pre">multiprocessing.pool.Pool.starmap()</span></code></a> and
  1632. <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.pool.Pool.starmap_async" title="multiprocessing.pool.Pool.starmap_async"><code class="xref py py-meth docutils literal notranslate"><span class="pre">starmap_async()</span></code></a> provide
  1633. <a class="reference internal" href="../library/itertools.html#itertools.starmap" title="itertools.starmap"><code class="xref py py-func docutils literal notranslate"><span class="pre">itertools.starmap()</span></code></a> equivalents to the existing
  1634. <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.pool.Pool.map" title="multiprocessing.pool.Pool.map"><code class="xref py py-meth docutils literal notranslate"><span class="pre">multiprocessing.pool.Pool.map()</span></code></a> and
  1635. <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.pool.Pool.map_async" title="multiprocessing.pool.Pool.map_async"><code class="xref py py-meth docutils literal notranslate"><span class="pre">map_async()</span></code></a> functions. (Contributed by Hynek
  1636. Schlawack in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12708">bpo-12708</a>.)</p>
  1637. </section>
  1638. <section id="nntplib">
  1639. <h3>nntplib<a class="headerlink" href="#nntplib" title="Link to this heading">¶</a></h3>
  1640. <p>The <a class="reference internal" href="../library/nntplib.html#nntplib.NNTP" title="nntplib.NNTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">nntplib.NNTP</span></code></a> class now supports the context management protocol to
  1641. unconditionally consume <a class="reference internal" href="../library/socket.html#socket.error" title="socket.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">socket.error</span></code></a> exceptions and to close the NNTP
  1642. connection when done:</p>
  1643. <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">nntplib</span> <span class="kn">import</span> <span class="n">NNTP</span>
  1644. <span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="n">NNTP</span><span class="p">(</span><span class="s1">&#39;news.gmane.org&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">n</span><span class="p">:</span>
  1645. <span class="gp">... </span> <span class="n">n</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="s1">&#39;gmane.comp.python.committers&#39;</span><span class="p">)</span>
  1646. <span class="gp">...</span>
  1647. <span class="go">(&#39;211 1755 1 1755 gmane.comp.python.committers&#39;, 1755, 1, 1755, &#39;gmane.comp.python.committers&#39;)</span>
  1648. <span class="gp">&gt;&gt;&gt;</span>
  1649. </pre></div>
  1650. </div>
  1651. <p>(Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9795">bpo-9795</a>.)</p>
  1652. </section>
  1653. <section id="os">
  1654. <h3>os<a class="headerlink" href="#os" title="Link to this heading">¶</a></h3>
  1655. <ul>
  1656. <li><p>The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module has a new <a class="reference internal" href="../library/os.html#os.pipe2" title="os.pipe2"><code class="xref py py-func docutils literal notranslate"><span class="pre">pipe2()</span></code></a> function that makes it
  1657. possible to create a pipe with <a class="reference internal" href="../library/os.html#os.O_CLOEXEC" title="os.O_CLOEXEC"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_CLOEXEC</span></code></a> or
  1658. <a class="reference internal" href="../library/os.html#os.O_NONBLOCK" title="os.O_NONBLOCK"><code class="xref py py-const docutils literal notranslate"><span class="pre">O_NONBLOCK</span></code></a> flags set atomically. This is especially useful to
  1659. avoid race conditions in multi-threaded programs.</p></li>
  1660. <li><p>The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module has a new <a class="reference internal" href="../library/os.html#os.sendfile" title="os.sendfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">sendfile()</span></code></a> function which provides
  1661. an efficient “zero-copy” way for copying data from one file (or socket)
  1662. descriptor to another. The phrase “zero-copy” refers to the fact that all of
  1663. the copying of data between the two descriptors is done entirely by the
  1664. kernel, with no copying of data into userspace buffers. <a class="reference internal" href="../library/os.html#os.sendfile" title="os.sendfile"><code class="xref py py-func docutils literal notranslate"><span class="pre">sendfile()</span></code></a>
  1665. can be used to efficiently copy data from a file on disk to a network socket,
  1666. e.g. for downloading a file.</p>
  1667. <p>(Patch submitted by Ross Lagerwall and Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10882">bpo-10882</a>.)</p>
  1668. </li>
  1669. <li><p>To avoid race conditions like symlink attacks and issues with temporary
  1670. files and directories, it is more reliable (and also faster) to manipulate
  1671. file descriptors instead of file names. Python 3.3 enhances existing functions
  1672. and introduces new functions to work on file descriptors (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4761">bpo-4761</a>,
  1673. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10755">bpo-10755</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14626">bpo-14626</a>).</p>
  1674. <ul class="simple">
  1675. <li><p>The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module has a new <a class="reference internal" href="../library/os.html#os.fwalk" title="os.fwalk"><code class="xref py py-func docutils literal notranslate"><span class="pre">fwalk()</span></code></a> function similar to
  1676. <a class="reference internal" href="../library/os.html#os.walk" title="os.walk"><code class="xref py py-func docutils literal notranslate"><span class="pre">walk()</span></code></a> except that it also yields file descriptors referring to the
  1677. directories visited. This is especially useful to avoid symlink races.</p></li>
  1678. <li><p>The following functions get new optional <em>dir_fd</em> (<a class="reference internal" href="../library/os.html#dir-fd"><span class="std std-ref">paths relative to
  1679. directory descriptors</span></a>) and/or <em>follow_symlinks</em> (<a class="reference internal" href="../library/os.html#follow-symlinks"><span class="std std-ref">not
  1680. following symlinks</span></a>):
  1681. <a class="reference internal" href="../library/os.html#os.access" title="os.access"><code class="xref py py-func docutils literal notranslate"><span class="pre">access()</span></code></a>, <a class="reference internal" href="../library/os.html#os.chflags" title="os.chflags"><code class="xref py py-func docutils literal notranslate"><span class="pre">chflags()</span></code></a>, <a class="reference internal" href="../library/os.html#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">chmod()</span></code></a>, <a class="reference internal" href="../library/os.html#os.chown" title="os.chown"><code class="xref py py-func docutils literal notranslate"><span class="pre">chown()</span></code></a>,
  1682. <a class="reference internal" href="../library/os.html#os.link" title="os.link"><code class="xref py py-func docutils literal notranslate"><span class="pre">link()</span></code></a>, <a class="reference internal" href="../library/os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">lstat()</span></code></a>, <a class="reference internal" href="../library/os.html#os.mkdir" title="os.mkdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">mkdir()</span></code></a>, <a class="reference internal" href="../library/os.html#os.mkfifo" title="os.mkfifo"><code class="xref py py-func docutils literal notranslate"><span class="pre">mkfifo()</span></code></a>,
  1683. <a class="reference internal" href="../library/os.html#os.mknod" title="os.mknod"><code class="xref py py-func docutils literal notranslate"><span class="pre">mknod()</span></code></a>, <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">open()</span></code></a>, <a class="reference internal" href="../library/os.html#os.readlink" title="os.readlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">readlink()</span></code></a>, <a class="reference internal" href="../library/os.html#os.remove" title="os.remove"><code class="xref py py-func docutils literal notranslate"><span class="pre">remove()</span></code></a>,
  1684. <a class="reference internal" href="../library/os.html#os.rename" title="os.rename"><code class="xref py py-func docutils literal notranslate"><span class="pre">rename()</span></code></a>, <a class="reference internal" href="../library/os.html#os.replace" title="os.replace"><code class="xref py py-func docutils literal notranslate"><span class="pre">replace()</span></code></a>, <a class="reference internal" href="../library/os.html#os.rmdir" title="os.rmdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">rmdir()</span></code></a>, <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">stat()</span></code></a>,
  1685. <a class="reference internal" href="../library/os.html#os.symlink" title="os.symlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">symlink()</span></code></a>, <a class="reference internal" href="../library/os.html#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">unlink()</span></code></a>, <a class="reference internal" href="../library/os.html#os.utime" title="os.utime"><code class="xref py py-func docutils literal notranslate"><span class="pre">utime()</span></code></a>. Platform
  1686. support for using these parameters can be checked via the sets
  1687. <a class="reference internal" href="../library/os.html#os.supports_dir_fd" title="os.supports_dir_fd"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.supports_dir_fd</span></code></a> and <code class="xref py py-data docutils literal notranslate"><span class="pre">os.supports_follows_symlinks</span></code>.</p></li>
  1688. <li><p>The following functions now support a file descriptor for their path argument:
  1689. <a class="reference internal" href="../library/os.html#os.chdir" title="os.chdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">chdir()</span></code></a>, <a class="reference internal" href="../library/os.html#os.chmod" title="os.chmod"><code class="xref py py-func docutils literal notranslate"><span class="pre">chmod()</span></code></a>, <a class="reference internal" href="../library/os.html#os.chown" title="os.chown"><code class="xref py py-func docutils literal notranslate"><span class="pre">chown()</span></code></a>,
  1690. <a class="reference internal" href="../library/os.html#os.execve" title="os.execve"><code class="xref py py-func docutils literal notranslate"><span class="pre">execve()</span></code></a>, <a class="reference internal" href="../library/os.html#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">listdir()</span></code></a>, <a class="reference internal" href="../library/os.html#os.pathconf" title="os.pathconf"><code class="xref py py-func docutils literal notranslate"><span class="pre">pathconf()</span></code></a>, <a class="reference internal" href="../library/os.path.html#os.path.exists" title="os.path.exists"><code class="xref py py-func docutils literal notranslate"><span class="pre">exists()</span></code></a>,
  1691. <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">stat()</span></code></a>, <a class="reference internal" href="../library/os.html#os.statvfs" title="os.statvfs"><code class="xref py py-func docutils literal notranslate"><span class="pre">statvfs()</span></code></a>, <a class="reference internal" href="../library/os.html#os.utime" title="os.utime"><code class="xref py py-func docutils literal notranslate"><span class="pre">utime()</span></code></a>. Platform support
  1692. for this can be checked via the <a class="reference internal" href="../library/os.html#os.supports_fd" title="os.supports_fd"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.supports_fd</span></code></a> set.</p></li>
  1693. </ul>
  1694. </li>
  1695. <li><p><a class="reference internal" href="../library/os.html#os.access" title="os.access"><code class="xref py py-func docutils literal notranslate"><span class="pre">access()</span></code></a> accepts an <code class="docutils literal notranslate"><span class="pre">effective_ids</span></code> keyword argument to turn on
  1696. using the effective uid/gid rather than the real uid/gid in the access check.
  1697. Platform support for this can be checked via the
  1698. <a class="reference internal" href="../library/os.html#os.supports_effective_ids" title="os.supports_effective_ids"><code class="xref py py-data docutils literal notranslate"><span class="pre">supports_effective_ids</span></code></a> set.</p></li>
  1699. <li><p>The <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> module has two new functions: <a class="reference internal" href="../library/os.html#os.getpriority" title="os.getpriority"><code class="xref py py-func docutils literal notranslate"><span class="pre">getpriority()</span></code></a> and
  1700. <a class="reference internal" href="../library/os.html#os.setpriority" title="os.setpriority"><code class="xref py py-func docutils literal notranslate"><span class="pre">setpriority()</span></code></a>. They can be used to get or set process
  1701. niceness/priority in a fashion similar to <a class="reference internal" href="../library/os.html#os.nice" title="os.nice"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.nice()</span></code></a> but extended to all
  1702. processes instead of just the current one.</p>
  1703. <p>(Patch submitted by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10784">bpo-10784</a>.)</p>
  1704. </li>
  1705. <li><p>The new <a class="reference internal" href="../library/os.html#os.replace" title="os.replace"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.replace()</span></code></a> function allows cross-platform renaming of a
  1706. file with overwriting the destination. With <a class="reference internal" href="../library/os.html#os.rename" title="os.rename"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.rename()</span></code></a>, an existing
  1707. destination file is overwritten under POSIX, but raises an error under
  1708. Windows.
  1709. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8828">bpo-8828</a>.)</p></li>
  1710. <li><p>The stat family of functions (<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">stat()</span></code></a>, <a class="reference internal" href="../library/os.html#os.fstat" title="os.fstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstat()</span></code></a>,
  1711. and <a class="reference internal" href="../library/os.html#os.lstat" title="os.lstat"><code class="xref py py-func docutils literal notranslate"><span class="pre">lstat()</span></code></a>) now support reading a file’s timestamps
  1712. with nanosecond precision. Symmetrically, <a class="reference internal" href="../library/os.html#os.utime" title="os.utime"><code class="xref py py-func docutils literal notranslate"><span class="pre">utime()</span></code></a>
  1713. can now write file timestamps with nanosecond precision. (Contributed by
  1714. Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14127">bpo-14127</a>.)</p></li>
  1715. <li><p>The new <a class="reference internal" href="../library/os.html#os.get_terminal_size" title="os.get_terminal_size"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.get_terminal_size()</span></code></a> function queries the size of the
  1716. terminal attached to a file descriptor. See also
  1717. <a class="reference internal" href="../library/shutil.html#shutil.get_terminal_size" title="shutil.get_terminal_size"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.get_terminal_size()</span></code></a>.
  1718. (Contributed by Zbigniew Jędrzejewski-Szmek in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13609">bpo-13609</a>.)</p></li>
  1719. </ul>
  1720. <ul class="simple">
  1721. <li><p>New functions to support Linux extended attributes (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12720">bpo-12720</a>):
  1722. <a class="reference internal" href="../library/os.html#os.getxattr" title="os.getxattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">getxattr()</span></code></a>, <a class="reference internal" href="../library/os.html#os.listxattr" title="os.listxattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">listxattr()</span></code></a>, <a class="reference internal" href="../library/os.html#os.removexattr" title="os.removexattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">removexattr()</span></code></a>,
  1723. <a class="reference internal" href="../library/os.html#os.setxattr" title="os.setxattr"><code class="xref py py-func docutils literal notranslate"><span class="pre">setxattr()</span></code></a>.</p></li>
  1724. <li><p>New interface to the scheduler. These functions
  1725. control how a process is allocated CPU time by the operating system. New
  1726. functions:
  1727. <a class="reference internal" href="../library/os.html#os.sched_get_priority_max" title="os.sched_get_priority_max"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_get_priority_max()</span></code></a>, <a class="reference internal" href="../library/os.html#os.sched_get_priority_min" title="os.sched_get_priority_min"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_get_priority_min()</span></code></a>,
  1728. <a class="reference internal" href="../library/os.html#os.sched_getaffinity" title="os.sched_getaffinity"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_getaffinity()</span></code></a>, <a class="reference internal" href="../library/os.html#os.sched_getparam" title="os.sched_getparam"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_getparam()</span></code></a>,
  1729. <a class="reference internal" href="../library/os.html#os.sched_getscheduler" title="os.sched_getscheduler"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_getscheduler()</span></code></a>, <a class="reference internal" href="../library/os.html#os.sched_rr_get_interval" title="os.sched_rr_get_interval"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_rr_get_interval()</span></code></a>,
  1730. <a class="reference internal" href="../library/os.html#os.sched_setaffinity" title="os.sched_setaffinity"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_setaffinity()</span></code></a>, <a class="reference internal" href="../library/os.html#os.sched_setparam" title="os.sched_setparam"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_setparam()</span></code></a>,
  1731. <a class="reference internal" href="../library/os.html#os.sched_setscheduler" title="os.sched_setscheduler"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_setscheduler()</span></code></a>, <a class="reference internal" href="../library/os.html#os.sched_yield" title="os.sched_yield"><code class="xref py py-func docutils literal notranslate"><span class="pre">sched_yield()</span></code></a>,</p></li>
  1732. <li><p>New functions to control the file system:</p>
  1733. <ul>
  1734. <li><p><a class="reference internal" href="../library/os.html#os.posix_fadvise" title="os.posix_fadvise"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_fadvise()</span></code></a>: Announces an intention to access data in a
  1735. specific pattern thus allowing the kernel to make optimizations.</p></li>
  1736. <li><p><a class="reference internal" href="../library/os.html#os.posix_fallocate" title="os.posix_fallocate"><code class="xref py py-func docutils literal notranslate"><span class="pre">posix_fallocate()</span></code></a>: Ensures that enough disk space is allocated
  1737. for a file.</p></li>
  1738. <li><p><a class="reference internal" href="../library/os.html#os.sync" title="os.sync"><code class="xref py py-func docutils literal notranslate"><span class="pre">sync()</span></code></a>: Force write of everything to disk.</p></li>
  1739. </ul>
  1740. </li>
  1741. <li><p>Additional new posix functions:</p>
  1742. <ul>
  1743. <li><p><a class="reference internal" href="../library/os.html#os.lockf" title="os.lockf"><code class="xref py py-func docutils literal notranslate"><span class="pre">lockf()</span></code></a>: Apply, test or remove a POSIX lock on an open file descriptor.</p></li>
  1744. <li><p><a class="reference internal" href="../library/os.html#os.pread" title="os.pread"><code class="xref py py-func docutils literal notranslate"><span class="pre">pread()</span></code></a>: Read from a file descriptor at an offset, the file
  1745. offset remains unchanged.</p></li>
  1746. <li><p><a class="reference internal" href="../library/os.html#os.pwrite" title="os.pwrite"><code class="xref py py-func docutils literal notranslate"><span class="pre">pwrite()</span></code></a>: Write to a file descriptor from an offset, leaving
  1747. the file offset unchanged.</p></li>
  1748. <li><p><a class="reference internal" href="../library/os.html#os.readv" title="os.readv"><code class="xref py py-func docutils literal notranslate"><span class="pre">readv()</span></code></a>: Read from a file descriptor into a number of writable buffers.</p></li>
  1749. <li><p><a class="reference internal" href="../library/os.html#os.truncate" title="os.truncate"><code class="xref py py-func docutils literal notranslate"><span class="pre">truncate()</span></code></a>: Truncate the file corresponding to <em>path</em>, so that
  1750. it is at most <em>length</em> bytes in size.</p></li>
  1751. <li><p><a class="reference internal" href="../library/os.html#os.waitid" title="os.waitid"><code class="xref py py-func docutils literal notranslate"><span class="pre">waitid()</span></code></a>: Wait for the completion of one or more child processes.</p></li>
  1752. <li><p><a class="reference internal" href="../library/os.html#os.writev" title="os.writev"><code class="xref py py-func docutils literal notranslate"><span class="pre">writev()</span></code></a>: Write the contents of <em>buffers</em> to a file descriptor,
  1753. where <em>buffers</em> is an arbitrary sequence of buffers.</p></li>
  1754. <li><p><a class="reference internal" href="../library/os.html#os.getgrouplist" title="os.getgrouplist"><code class="xref py py-func docutils literal notranslate"><span class="pre">getgrouplist()</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9344">bpo-9344</a>): Return list of group ids that
  1755. specified user belongs to.</p></li>
  1756. </ul>
  1757. </li>
  1758. <li><p><a class="reference internal" href="../library/os.html#os.times" title="os.times"><code class="xref py py-func docutils literal notranslate"><span class="pre">times()</span></code></a> and <a class="reference internal" href="../library/os.html#os.uname" title="os.uname"><code class="xref py py-func docutils literal notranslate"><span class="pre">uname()</span></code></a>: Return type changed from a tuple to
  1759. a tuple-like object with named attributes.</p></li>
  1760. <li><p>Some platforms now support additional constants for the <a class="reference internal" href="../library/os.html#os.lseek" title="os.lseek"><code class="xref py py-func docutils literal notranslate"><span class="pre">lseek()</span></code></a>
  1761. function, such as <code class="docutils literal notranslate"><span class="pre">os.SEEK_HOLE</span></code> and <code class="docutils literal notranslate"><span class="pre">os.SEEK_DATA</span></code>.</p></li>
  1762. <li><p>New constants <a class="reference internal" href="../library/os.html#os.RTLD_LAZY" title="os.RTLD_LAZY"><code class="xref py py-const docutils literal notranslate"><span class="pre">RTLD_LAZY</span></code></a>, <a class="reference internal" href="../library/os.html#os.RTLD_NOW" title="os.RTLD_NOW"><code class="xref py py-const docutils literal notranslate"><span class="pre">RTLD_NOW</span></code></a>,
  1763. <a class="reference internal" href="../library/os.html#os.RTLD_GLOBAL" title="os.RTLD_GLOBAL"><code class="xref py py-const docutils literal notranslate"><span class="pre">RTLD_GLOBAL</span></code></a>, <a class="reference internal" href="../library/os.html#os.RTLD_LOCAL" title="os.RTLD_LOCAL"><code class="xref py py-const docutils literal notranslate"><span class="pre">RTLD_LOCAL</span></code></a>, <a class="reference internal" href="../library/os.html#os.RTLD_NODELETE" title="os.RTLD_NODELETE"><code class="xref py py-const docutils literal notranslate"><span class="pre">RTLD_NODELETE</span></code></a>,
  1764. <a class="reference internal" href="../library/os.html#os.RTLD_NOLOAD" title="os.RTLD_NOLOAD"><code class="xref py py-const docutils literal notranslate"><span class="pre">RTLD_NOLOAD</span></code></a>, and <a class="reference internal" href="../library/os.html#os.RTLD_DEEPBIND" title="os.RTLD_DEEPBIND"><code class="xref py py-const docutils literal notranslate"><span class="pre">RTLD_DEEPBIND</span></code></a> are available on
  1765. platforms that support them. These are for use with the
  1766. <a class="reference internal" href="../library/sys.html#sys.setdlopenflags" title="sys.setdlopenflags"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.setdlopenflags()</span></code></a> function, and supersede the similar constants
  1767. defined in <a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">DLFCN</span></code>. (Contributed by Victor Stinner
  1768. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13226">bpo-13226</a>.)</p></li>
  1769. <li><p><a class="reference internal" href="../library/os.html#os.symlink" title="os.symlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.symlink()</span></code></a> now accepts (and ignores) the <code class="docutils literal notranslate"><span class="pre">target_is_directory</span></code>
  1770. keyword argument on non-Windows platforms, to ease cross-platform support.</p></li>
  1771. </ul>
  1772. </section>
  1773. <section id="pdb">
  1774. <h3>pdb<a class="headerlink" href="#pdb" title="Link to this heading">¶</a></h3>
  1775. <p>Tab-completion is now available not only for command names, but also their
  1776. arguments. For example, for the <code class="docutils literal notranslate"><span class="pre">break</span></code> command, function and file names
  1777. are completed.</p>
  1778. <p>(Contributed by Georg Brandl in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14210">bpo-14210</a>)</p>
  1779. </section>
  1780. <section id="pickle">
  1781. <h3>pickle<a class="headerlink" href="#pickle" title="Link to this heading">¶</a></h3>
  1782. <p><a class="reference internal" href="../library/pickle.html#pickle.Pickler" title="pickle.Pickler"><code class="xref py py-class docutils literal notranslate"><span class="pre">pickle.Pickler</span></code></a> objects now have an optional
  1783. <a class="reference internal" href="../library/pickle.html#pickle.Pickler.dispatch_table" title="pickle.Pickler.dispatch_table"><code class="xref py py-attr docutils literal notranslate"><span class="pre">dispatch_table</span></code></a> attribute allowing per-pickler
  1784. reduction functions to be set.</p>
  1785. <p>(Contributed by Richard Oudkerk in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14166">bpo-14166</a>.)</p>
  1786. </section>
  1787. <section id="pydoc">
  1788. <h3>pydoc<a class="headerlink" href="#pydoc" title="Link to this heading">¶</a></h3>
  1789. <p>The Tk GUI and the <code class="xref py py-func docutils literal notranslate"><span class="pre">serve()</span></code> function have been removed from the
  1790. <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: <code class="docutils literal notranslate"><span class="pre">pydoc</span> <span class="pre">-g</span></code> and <code class="xref py py-func docutils literal notranslate"><span class="pre">serve()</span></code> have been deprecated
  1791. in Python 3.2.</p>
  1792. </section>
  1793. <section id="re">
  1794. <h3>re<a class="headerlink" href="#re" title="Link to this heading">¶</a></h3>
  1795. <p><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> regular expressions now support <code class="docutils literal notranslate"><span class="pre">\u</span></code> and <code class="docutils literal notranslate"><span class="pre">\U</span></code> escapes.</p>
  1796. <p>(Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=3665">bpo-3665</a>.)</p>
  1797. </section>
  1798. <section id="sched">
  1799. <h3>sched<a class="headerlink" href="#sched" title="Link to this heading">¶</a></h3>
  1800. <ul class="simple">
  1801. <li><p><a class="reference internal" href="../library/sched.html#sched.scheduler.run" title="sched.scheduler.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">run()</span></code></a> now accepts a <em>blocking</em> parameter which when
  1802. set to false makes the method execute the scheduled events due to expire
  1803. soonest (if any) and then return immediately.
  1804. This is useful in case you want to use the <a class="reference internal" href="../library/sched.html#sched.scheduler" title="sched.scheduler"><code class="xref py py-class docutils literal notranslate"><span class="pre">scheduler</span></code></a> in
  1805. non-blocking applications. (Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13449">bpo-13449</a>.)</p></li>
  1806. <li><p><a class="reference internal" href="../library/sched.html#sched.scheduler" title="sched.scheduler"><code class="xref py py-class docutils literal notranslate"><span class="pre">scheduler</span></code></a> class can now be safely used in multi-threaded
  1807. environments. (Contributed by Josiah Carlson and Giampaolo Rodolà in
  1808. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8684">bpo-8684</a>.)</p></li>
  1809. <li><p><em>timefunc</em> and <em>delayfunct</em> parameters of <a class="reference internal" href="../library/sched.html#sched.scheduler" title="sched.scheduler"><code class="xref py py-class docutils literal notranslate"><span class="pre">scheduler</span></code></a> class
  1810. constructor are now optional and defaults to <a class="reference internal" href="../library/time.html#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.time()</span></code></a> and
  1811. <a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.sleep()</span></code></a> respectively. (Contributed by Chris Clark in
  1812. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13245">bpo-13245</a>.)</p></li>
  1813. <li><p><a class="reference internal" href="../library/sched.html#sched.scheduler.enter" title="sched.scheduler.enter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enter()</span></code></a> and <a class="reference internal" href="../library/sched.html#sched.scheduler.enterabs" title="sched.scheduler.enterabs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enterabs()</span></code></a>
  1814. <em>argument</em> parameter is now optional. (Contributed by Chris Clark in
  1815. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13245">bpo-13245</a>.)</p></li>
  1816. <li><p><a class="reference internal" href="../library/sched.html#sched.scheduler.enter" title="sched.scheduler.enter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enter()</span></code></a> and <a class="reference internal" href="../library/sched.html#sched.scheduler.enterabs" title="sched.scheduler.enterabs"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enterabs()</span></code></a>
  1817. now accept a <em>kwargs</em> parameter. (Contributed by Chris Clark in
  1818. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13245">bpo-13245</a>.)</p></li>
  1819. </ul>
  1820. </section>
  1821. <section id="select">
  1822. <h3>select<a class="headerlink" href="#select" title="Link to this heading">¶</a></h3>
  1823. <p>Solaris and derivative platforms have a new class <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">select.devpoll</span></code></a>
  1824. for high performance asynchronous sockets via <code class="file docutils literal notranslate"><span class="pre">/dev/poll</span></code>.
  1825. (Contributed by Jesús Cea Avión in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6397">bpo-6397</a>.)</p>
  1826. </section>
  1827. <section id="shlex">
  1828. <h3>shlex<a class="headerlink" href="#shlex" title="Link to this heading">¶</a></h3>
  1829. <p>The previously undocumented helper function <code class="docutils literal notranslate"><span class="pre">quote</span></code> from the
  1830. <a class="reference internal" href="../library/pipes.html#module-pipes" title="pipes: A Python interface to Unix shell pipelines. (deprecated) (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pipes</span></code></a> modules has been moved to the <a class="reference internal" href="../library/shlex.html#module-shlex" title="shlex: Simple lexical analysis for Unix shell-like languages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">shlex</span></code></a> module and
  1831. documented. <a class="reference internal" href="../library/shlex.html#shlex.quote" title="shlex.quote"><code class="xref py py-func docutils literal notranslate"><span class="pre">quote()</span></code></a> properly escapes all characters in a string
  1832. that might be otherwise given special meaning by the shell.</p>
  1833. </section>
  1834. <section id="shutil">
  1835. <h3>shutil<a class="headerlink" href="#shutil" title="Link to this heading">¶</a></h3>
  1836. <ul class="simple">
  1837. <li><p>New functions:</p>
  1838. <ul>
  1839. <li><p><a class="reference internal" href="../library/shutil.html#shutil.disk_usage" title="shutil.disk_usage"><code class="xref py py-func docutils literal notranslate"><span class="pre">disk_usage()</span></code></a>: provides total, used and free disk space
  1840. statistics. (Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12442">bpo-12442</a>.)</p></li>
  1841. <li><p><a class="reference internal" href="../library/shutil.html#shutil.chown" title="shutil.chown"><code class="xref py py-func docutils literal notranslate"><span class="pre">chown()</span></code></a>: allows one to change user and/or group of the given
  1842. path also specifying the user/group names and not only their numeric
  1843. ids. (Contributed by Sandro Tosi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12191">bpo-12191</a>.)</p></li>
  1844. <li><p><a class="reference internal" href="../library/shutil.html#shutil.get_terminal_size" title="shutil.get_terminal_size"><code class="xref py py-func docutils literal notranslate"><span class="pre">shutil.get_terminal_size()</span></code></a>: returns the size of the terminal window
  1845. to which the interpreter is attached. (Contributed by Zbigniew
  1846. Jędrzejewski-Szmek in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13609">bpo-13609</a>.)</p></li>
  1847. </ul>
  1848. </li>
  1849. <li><p><a class="reference internal" href="../library/shutil.html#shutil.copy2" title="shutil.copy2"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy2()</span></code></a> and <a class="reference internal" href="../library/shutil.html#shutil.copystat" title="shutil.copystat"><code class="xref py py-func docutils literal notranslate"><span class="pre">copystat()</span></code></a> now preserve file
  1850. timestamps with nanosecond precision on platforms that support it.
  1851. They also preserve file “extended attributes” on Linux. (Contributed
  1852. by Larry Hastings in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14127">bpo-14127</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15238">bpo-15238</a>.)</p></li>
  1853. <li><p>Several functions now take an optional <code class="docutils literal notranslate"><span class="pre">symlinks</span></code> argument: when that
  1854. parameter is true, symlinks aren’t dereferenced and the operation instead
  1855. acts on the symlink itself (or creates one, if relevant).
  1856. (Contributed by Hynek Schlawack in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12715">bpo-12715</a>.)</p></li>
  1857. <li><p>When copying files to a different file system, <a class="reference internal" href="../library/shutil.html#shutil.move" title="shutil.move"><code class="xref py py-func docutils literal notranslate"><span class="pre">move()</span></code></a> now
  1858. handles symlinks the way the posix <code class="docutils literal notranslate"><span class="pre">mv</span></code> command does, recreating the
  1859. symlink rather than copying the target file contents. (Contributed by
  1860. Jonathan Niehof in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9993">bpo-9993</a>.) <a class="reference internal" href="../library/shutil.html#shutil.move" title="shutil.move"><code class="xref py py-func docutils literal notranslate"><span class="pre">move()</span></code></a> now also returns
  1861. the <code class="docutils literal notranslate"><span class="pre">dst</span></code> argument as its result.</p></li>
  1862. <li><p><a class="reference internal" href="../library/shutil.html#shutil.rmtree" title="shutil.rmtree"><code class="xref py py-func docutils literal notranslate"><span class="pre">rmtree()</span></code></a> is now resistant to symlink attacks on platforms
  1863. which support the new <code class="docutils literal notranslate"><span class="pre">dir_fd</span></code> parameter in <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> and
  1864. <a class="reference internal" href="../library/os.html#os.unlink" title="os.unlink"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.unlink()</span></code></a>. (Contributed by Martin von Löwis and Hynek Schlawack
  1865. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=4489">bpo-4489</a>.)</p></li>
  1866. </ul>
  1867. </section>
  1868. <section id="signal">
  1869. <h3>signal<a class="headerlink" href="#signal" title="Link to this heading">¶</a></h3>
  1870. <ul class="simple">
  1871. <li><p>The <a class="reference internal" href="../library/signal.html#module-signal" title="signal: Set handlers for asynchronous events."><code class="xref py py-mod docutils literal notranslate"><span class="pre">signal</span></code></a> module has new functions:</p>
  1872. <ul>
  1873. <li><p><a class="reference internal" href="../library/signal.html#signal.pthread_sigmask" title="signal.pthread_sigmask"><code class="xref py py-func docutils literal notranslate"><span class="pre">pthread_sigmask()</span></code></a>: fetch and/or change the signal mask of the
  1874. calling thread (Contributed by Jean-Paul Calderone in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8407">bpo-8407</a>);</p></li>
  1875. <li><p><a class="reference internal" href="../library/signal.html#signal.pthread_kill" title="signal.pthread_kill"><code class="xref py py-func docutils literal notranslate"><span class="pre">pthread_kill()</span></code></a>: send a signal to a thread;</p></li>
  1876. <li><p><a class="reference internal" href="../library/signal.html#signal.sigpending" title="signal.sigpending"><code class="xref py py-func docutils literal notranslate"><span class="pre">sigpending()</span></code></a>: examine pending functions;</p></li>
  1877. <li><p><a class="reference internal" href="../library/signal.html#signal.sigwait" title="signal.sigwait"><code class="xref py py-func docutils literal notranslate"><span class="pre">sigwait()</span></code></a>: wait a signal;</p></li>
  1878. <li><p><a class="reference internal" href="../library/signal.html#signal.sigwaitinfo" title="signal.sigwaitinfo"><code class="xref py py-func docutils literal notranslate"><span class="pre">sigwaitinfo()</span></code></a>: wait for a signal, returning detailed
  1879. information about it;</p></li>
  1880. <li><p><a class="reference internal" href="../library/signal.html#signal.sigtimedwait" title="signal.sigtimedwait"><code class="xref py py-func docutils literal notranslate"><span class="pre">sigtimedwait()</span></code></a>: like <a class="reference internal" href="../library/signal.html#signal.sigwaitinfo" title="signal.sigwaitinfo"><code class="xref py py-func docutils literal notranslate"><span class="pre">sigwaitinfo()</span></code></a> but with a
  1881. timeout.</p></li>
  1882. </ul>
  1883. </li>
  1884. <li><p>The signal handler writes the signal number as a single byte instead of
  1885. a nul byte into the wakeup file descriptor. So it is possible to wait more
  1886. than one signal and know which signals were raised.</p></li>
  1887. <li><p><a class="reference internal" href="../library/signal.html#signal.signal" title="signal.signal"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.signal()</span></code></a> and <a class="reference internal" href="../library/signal.html#signal.siginterrupt" title="signal.siginterrupt"><code class="xref py py-func docutils literal notranslate"><span class="pre">signal.siginterrupt()</span></code></a> raise an OSError,
  1888. instead of a RuntimeError: OSError has an errno attribute.</p></li>
  1889. </ul>
  1890. </section>
  1891. <section id="smtpd">
  1892. <h3>smtpd<a class="headerlink" href="#smtpd" title="Link to this heading">¶</a></h3>
  1893. <p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code> module now supports <span class="target" id="index-26"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc5321.html"><strong>RFC 5321</strong></a> (extended SMTP) and <span class="target" id="index-27"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc1870.html"><strong>RFC 1870</strong></a>
  1894. (size extension). Per the standard, these extensions are enabled if and only
  1895. if the client initiates the session with an <code class="docutils literal notranslate"><span class="pre">EHLO</span></code> command.</p>
  1896. <p>(Initial <code class="docutils literal notranslate"><span class="pre">ELHO</span></code> support by Alberto Trevino. Size extension by Juhana
  1897. Jauhiainen. Substantial additional work on the patch contributed by Michele
  1898. Orrù and Dan Boswell. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8739">bpo-8739</a>)</p>
  1899. </section>
  1900. <section id="smtplib">
  1901. <h3>smtplib<a class="headerlink" href="#smtplib" title="Link to this heading">¶</a></h3>
  1902. <p>The <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP" title="smtplib.SMTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTP</span></code></a>, <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP_SSL" title="smtplib.SMTP_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTP_SSL</span></code></a>, and
  1903. <a class="reference internal" href="../library/smtplib.html#smtplib.LMTP" title="smtplib.LMTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">LMTP</span></code></a> classes now accept a <code class="docutils literal notranslate"><span class="pre">source_address</span></code> keyword argument
  1904. to specify the <code class="docutils literal notranslate"><span class="pre">(host,</span> <span class="pre">port)</span></code> to use as the source address in the bind call
  1905. when creating the outgoing socket. (Contributed by Paulo Scardine in
  1906. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11281">bpo-11281</a>.)</p>
  1907. <p><a class="reference internal" href="../library/smtplib.html#smtplib.SMTP" title="smtplib.SMTP"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTP</span></code></a> now supports the context management protocol, allowing an
  1908. <code class="docutils literal notranslate"><span class="pre">SMTP</span></code> instance to be used in a <code class="docutils literal notranslate"><span class="pre">with</span></code> statement. (Contributed
  1909. by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11289">bpo-11289</a>.)</p>
  1910. <p>The <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP_SSL" title="smtplib.SMTP_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTP_SSL</span></code></a> constructor and the <a class="reference internal" href="../library/smtplib.html#smtplib.SMTP.starttls" title="smtplib.SMTP.starttls"><code class="xref py py-meth docutils literal notranslate"><span class="pre">starttls()</span></code></a>
  1911. method now accept an SSLContext parameter to control parameters of the secure
  1912. channel. (Contributed by Kasun Herath in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8809">bpo-8809</a>.)</p>
  1913. </section>
  1914. <section id="socket">
  1915. <h3>socket<a class="headerlink" href="#socket" title="Link to this heading">¶</a></h3>
  1916. <ul>
  1917. <li><p>The <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket</span></code></a> class now exposes additional methods to process
  1918. ancillary data when supported by the underlying platform:</p>
  1919. <ul class="simple">
  1920. <li><p><a class="reference internal" href="../library/socket.html#socket.socket.sendmsg" title="socket.socket.sendmsg"><code class="xref py py-func docutils literal notranslate"><span class="pre">sendmsg()</span></code></a></p></li>
  1921. <li><p><a class="reference internal" href="../library/socket.html#socket.socket.recvmsg" title="socket.socket.recvmsg"><code class="xref py py-func docutils literal notranslate"><span class="pre">recvmsg()</span></code></a></p></li>
  1922. <li><p><a class="reference internal" href="../library/socket.html#socket.socket.recvmsg_into" title="socket.socket.recvmsg_into"><code class="xref py py-func docutils literal notranslate"><span class="pre">recvmsg_into()</span></code></a></p></li>
  1923. </ul>
  1924. <p>(Contributed by David Watson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6560">bpo-6560</a>, based on an earlier patch by
  1925. Heiko Wundram)</p>
  1926. </li>
  1927. <li><p>The <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket</span></code></a> class now supports the PF_CAN protocol family
  1928. (<a class="reference external" href="https://en.wikipedia.org/wiki/Socketcan">https://en.wikipedia.org/wiki/Socketcan</a>), on Linux
  1929. (<a class="reference external" href="https://lwn.net/Articles/253425">https://lwn.net/Articles/253425</a>).</p>
  1930. <p>(Contributed by Matthias Fuchs, updated by Tiago Gonçalves in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10141">bpo-10141</a>.)</p>
  1931. </li>
  1932. <li><p>The <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket</span></code></a> class now supports the PF_RDS protocol family
  1933. (<a class="reference external" href="https://en.wikipedia.org/wiki/Reliable_Datagram_Sockets">https://en.wikipedia.org/wiki/Reliable_Datagram_Sockets</a> and
  1934. <a class="reference external" href="https://web.archive.org/web/20130115155505/https://oss.oracle.com/projects/rds/">https://oss.oracle.com/projects/rds</a>).</p></li>
  1935. <li><p>The <a class="reference internal" href="../library/socket.html#socket.socket" title="socket.socket"><code class="xref py py-class docutils literal notranslate"><span class="pre">socket</span></code></a> class now supports the <code class="docutils literal notranslate"><span class="pre">PF_SYSTEM</span></code> protocol
  1936. family on OS X. (Contributed by Michael Goderbauer in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13777">bpo-13777</a>.)</p></li>
  1937. <li><p>New function <a class="reference internal" href="../library/socket.html#socket.sethostname" title="socket.sethostname"><code class="xref py py-func docutils literal notranslate"><span class="pre">sethostname()</span></code></a> allows the hostname to be set
  1938. on Unix systems if the calling process has sufficient privileges.
  1939. (Contributed by Ross Lagerwall in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10866">bpo-10866</a>.)</p></li>
  1940. </ul>
  1941. </section>
  1942. <section id="socketserver">
  1943. <h3>socketserver<a class="headerlink" href="#socketserver" title="Link to this heading">¶</a></h3>
  1944. <p><a class="reference internal" href="../library/socketserver.html#socketserver.BaseServer" title="socketserver.BaseServer"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseServer</span></code></a> now has an overridable method
  1945. <a class="reference internal" href="../library/socketserver.html#socketserver.BaseServer.service_actions" title="socketserver.BaseServer.service_actions"><code class="xref py py-meth docutils literal notranslate"><span class="pre">service_actions()</span></code></a> that is called by the
  1946. <a class="reference internal" href="../library/socketserver.html#socketserver.BaseServer.serve_forever" title="socketserver.BaseServer.serve_forever"><code class="xref py py-meth docutils literal notranslate"><span class="pre">serve_forever()</span></code></a> method in the service loop.
  1947. <a class="reference internal" href="../library/socketserver.html#socketserver.ForkingMixIn" title="socketserver.ForkingMixIn"><code class="xref py py-class docutils literal notranslate"><span class="pre">ForkingMixIn</span></code></a> now uses this to clean up zombie
  1948. child processes. (Contributed by Justin Warkentin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11109">bpo-11109</a>.)</p>
  1949. </section>
  1950. <section id="sqlite3">
  1951. <h3>sqlite3<a class="headerlink" href="#sqlite3" title="Link to this heading">¶</a></h3>
  1952. <p>New <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection" title="sqlite3.Connection"><code class="xref py py-class docutils literal notranslate"><span class="pre">sqlite3.Connection</span></code></a> method
  1953. <a class="reference internal" href="../library/sqlite3.html#sqlite3.Connection.set_trace_callback" title="sqlite3.Connection.set_trace_callback"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_trace_callback()</span></code></a> can be used to capture a trace of
  1954. all sql commands processed by sqlite. (Contributed by Torsten Landschoff
  1955. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11688">bpo-11688</a>.)</p>
  1956. </section>
  1957. <section id="ssl">
  1958. <h3>ssl<a class="headerlink" href="#ssl" title="Link to this heading">¶</a></h3>
  1959. <ul>
  1960. <li><p>The <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> module has two new random generation functions:</p>
  1961. <ul class="simple">
  1962. <li><p><a class="reference internal" href="../library/ssl.html#ssl.RAND_bytes" title="ssl.RAND_bytes"><code class="xref py py-func docutils literal notranslate"><span class="pre">RAND_bytes()</span></code></a>: generate cryptographically strong
  1963. pseudo-random bytes.</p></li>
  1964. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">RAND_pseudo_bytes()</span></code>: generate pseudo-random bytes.</p></li>
  1965. </ul>
  1966. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12049">bpo-12049</a>.)</p>
  1967. </li>
  1968. <li><p>The <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> module now exposes a finer-grained exception hierarchy
  1969. in order to make it easier to inspect the various kinds of errors.
  1970. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11183">bpo-11183</a>.)</p></li>
  1971. <li><p><a class="reference internal" href="../library/ssl.html#ssl.SSLContext.load_cert_chain" title="ssl.SSLContext.load_cert_chain"><code class="xref py py-meth docutils literal notranslate"><span class="pre">load_cert_chain()</span></code></a> now accepts a <em>password</em> argument
  1972. to be used if the private key is encrypted.
  1973. (Contributed by Adam Simpkins in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12803">bpo-12803</a>.)</p></li>
  1974. <li><p>Diffie-Hellman key exchange, both regular and Elliptic Curve-based, is
  1975. now supported through the <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.load_dh_params" title="ssl.SSLContext.load_dh_params"><code class="xref py py-meth docutils literal notranslate"><span class="pre">load_dh_params()</span></code></a> and
  1976. <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_ecdh_curve" title="ssl.SSLContext.set_ecdh_curve"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_ecdh_curve()</span></code></a> methods.
  1977. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13626">bpo-13626</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13627">bpo-13627</a>.)</p></li>
  1978. <li><p>SSL sockets have a new <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.get_channel_binding" title="ssl.SSLSocket.get_channel_binding"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_channel_binding()</span></code></a> method
  1979. allowing the implementation of certain authentication mechanisms such as
  1980. SCRAM-SHA-1-PLUS. (Contributed by Jacek Konieczny in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12551">bpo-12551</a>.)</p></li>
  1981. <li><p>You can query the SSL compression algorithm used by an SSL socket, thanks
  1982. to its new <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.compression" title="ssl.SSLSocket.compression"><code class="xref py py-meth docutils literal notranslate"><span class="pre">compression()</span></code></a> method. The new attribute
  1983. <a class="reference internal" href="../library/ssl.html#ssl.OP_NO_COMPRESSION" title="ssl.OP_NO_COMPRESSION"><code class="xref py py-const docutils literal notranslate"><span class="pre">OP_NO_COMPRESSION</span></code></a> can be used to disable compression.
  1984. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13634">bpo-13634</a>.)</p></li>
  1985. <li><p>Support has been added for the Next Protocol Negotiation extension using
  1986. the <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.set_npn_protocols" title="ssl.SSLContext.set_npn_protocols"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLContext.set_npn_protocols()</span></code></a> method.
  1987. (Contributed by Colin Marc in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14204">bpo-14204</a>.)</p></li>
  1988. <li><p>SSL errors can now be introspected more easily thanks to
  1989. <a class="reference internal" href="../library/ssl.html#ssl.SSLError.library" title="ssl.SSLError.library"><code class="xref py py-attr docutils literal notranslate"><span class="pre">library</span></code></a> and <a class="reference internal" href="../library/ssl.html#ssl.SSLError.reason" title="ssl.SSLError.reason"><code class="xref py py-attr docutils literal notranslate"><span class="pre">reason</span></code></a> attributes.
  1990. (Contributed by Antoine Pitrou in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14837">bpo-14837</a>.)</p></li>
  1991. <li><p>The <a class="reference internal" href="../library/ssl.html#ssl.get_server_certificate" title="ssl.get_server_certificate"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_server_certificate()</span></code></a> function now supports IPv6.
  1992. (Contributed by Charles-François Natali in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11811">bpo-11811</a>.)</p></li>
  1993. <li><p>New attribute <a class="reference internal" href="../library/ssl.html#ssl.OP_CIPHER_SERVER_PREFERENCE" title="ssl.OP_CIPHER_SERVER_PREFERENCE"><code class="xref py py-const docutils literal notranslate"><span class="pre">OP_CIPHER_SERVER_PREFERENCE</span></code></a> allows setting
  1994. SSLv3 server sockets to use the server’s cipher ordering preference rather
  1995. than the client’s (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13635">bpo-13635</a>).</p></li>
  1996. </ul>
  1997. </section>
  1998. <section id="stat">
  1999. <h3>stat<a class="headerlink" href="#stat" title="Link to this heading">¶</a></h3>
  2000. <p>The undocumented tarfile.filemode function has been moved to
  2001. <a class="reference internal" href="../library/stat.html#stat.filemode" title="stat.filemode"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat.filemode()</span></code></a>. It can be used to convert a file’s mode to a string of
  2002. the form ‘-rwxrwxrwx’.</p>
  2003. <p>(Contributed by Giampaolo Rodolà in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14807">bpo-14807</a>.)</p>
  2004. </section>
  2005. <section id="struct">
  2006. <h3>struct<a class="headerlink" href="#struct" title="Link to this heading">¶</a></h3>
  2007. <p>The <a class="reference internal" href="../library/struct.html#module-struct" title="struct: Interpret bytes as packed binary data."><code class="xref py py-mod docutils literal notranslate"><span class="pre">struct</span></code></a> module now supports <code class="xref c c-type docutils literal notranslate"><span class="pre">ssize_t</span></code> and <code class="xref c c-type docutils literal notranslate"><span class="pre">size_t</span></code> via the
  2008. new codes <code class="docutils literal notranslate"><span class="pre">n</span></code> and <code class="docutils literal notranslate"><span class="pre">N</span></code>, respectively. (Contributed by Antoine Pitrou
  2009. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=3163">bpo-3163</a>.)</p>
  2010. </section>
  2011. <section id="subprocess">
  2012. <h3>subprocess<a class="headerlink" href="#subprocess" title="Link to this heading">¶</a></h3>
  2013. <p>Command strings can now be bytes objects on posix platforms. (Contributed by
  2014. Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8513">bpo-8513</a>.)</p>
  2015. <p>A new constant <a class="reference internal" href="../library/subprocess.html#subprocess.DEVNULL" title="subprocess.DEVNULL"><code class="xref py py-const docutils literal notranslate"><span class="pre">DEVNULL</span></code></a> allows suppressing output in a
  2016. platform-independent fashion. (Contributed by Ross Lagerwall in
  2017. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5870">bpo-5870</a>.)</p>
  2018. </section>
  2019. <section id="sys">
  2020. <h3>sys<a class="headerlink" href="#sys" title="Link to this heading">¶</a></h3>
  2021. <p>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 has a new <a class="reference internal" href="../library/sys.html#sys.thread_info" title="sys.thread_info"><code class="xref py py-data docutils literal notranslate"><span class="pre">thread_info</span></code></a> <a class="reference internal" href="../glossary.html#term-named-tuple"><span class="xref std std-term">named
  2022. tuple</span></a> holding information about the thread implementation
  2023. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11223">bpo-11223</a>).</p>
  2024. </section>
  2025. <section id="tarfile">
  2026. <h3>tarfile<a class="headerlink" href="#tarfile" title="Link to this heading">¶</a></h3>
  2027. <p><a class="reference internal" href="../library/tarfile.html#module-tarfile" title="tarfile: Read and write tar-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tarfile</span></code></a> now supports <code class="docutils literal notranslate"><span class="pre">lzma</span></code> encoding via the <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> module.
  2028. (Contributed by Lars Gustäbel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5689">bpo-5689</a>.)</p>
  2029. </section>
  2030. <section id="tempfile">
  2031. <h3>tempfile<a class="headerlink" href="#tempfile" title="Link to this heading">¶</a></h3>
  2032. <p><a class="reference internal" href="../library/tempfile.html#tempfile.SpooledTemporaryFile" title="tempfile.SpooledTemporaryFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">tempfile.SpooledTemporaryFile</span></code></a>'s
  2033. <code class="xref py py-meth docutils literal notranslate"><span class="pre">truncate()</span></code> method now accepts
  2034. a <code class="docutils literal notranslate"><span class="pre">size</span></code> parameter. (Contributed by Ryan Kelly in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9957">bpo-9957</a>.)</p>
  2035. </section>
  2036. <section id="textwrap">
  2037. <h3>textwrap<a class="headerlink" href="#textwrap" title="Link to this heading">¶</a></h3>
  2038. <p>The <a class="reference internal" href="../library/textwrap.html#module-textwrap" title="textwrap: Text wrapping and filling"><code class="xref py py-mod docutils literal notranslate"><span class="pre">textwrap</span></code></a> module has a new <a class="reference internal" href="../library/textwrap.html#textwrap.indent" title="textwrap.indent"><code class="xref py py-func docutils literal notranslate"><span class="pre">indent()</span></code></a> that makes
  2039. it straightforward to add a common prefix to selected lines in a block
  2040. of text (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13857">bpo-13857</a>).</p>
  2041. </section>
  2042. <section id="threading">
  2043. <h3>threading<a class="headerlink" href="#threading" title="Link to this heading">¶</a></h3>
  2044. <p><a class="reference internal" href="../library/threading.html#threading.Condition" title="threading.Condition"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Condition</span></code></a>, <a class="reference internal" href="../library/threading.html#threading.Semaphore" title="threading.Semaphore"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Semaphore</span></code></a>,
  2045. <a class="reference internal" href="../library/threading.html#threading.BoundedSemaphore" title="threading.BoundedSemaphore"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.BoundedSemaphore</span></code></a>, <a class="reference internal" href="../library/threading.html#threading.Event" title="threading.Event"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Event</span></code></a>, and
  2046. <a class="reference internal" href="../library/threading.html#threading.Timer" title="threading.Timer"><code class="xref py py-class docutils literal notranslate"><span class="pre">threading.Timer</span></code></a>, all of which used to be factory functions returning a
  2047. class instance, are now classes and may be subclassed. (Contributed by Éric
  2048. Araujo in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10968">bpo-10968</a>.)</p>
  2049. <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">threading.Thread</span></code></a> constructor now accepts a <code class="docutils literal notranslate"><span class="pre">daemon</span></code> keyword
  2050. argument to override the default behavior of inheriting the <code class="docutils literal notranslate"><span class="pre">daemon</span></code> flag
  2051. value from the parent thread (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6064">bpo-6064</a>).</p>
  2052. <p>The formerly private function <code class="docutils literal notranslate"><span class="pre">_thread.get_ident</span></code> is now available as the
  2053. public function <a class="reference internal" href="../library/threading.html#threading.get_ident" title="threading.get_ident"><code class="xref py py-func docutils literal notranslate"><span class="pre">threading.get_ident()</span></code></a>. This eliminates several cases of
  2054. direct access to the <code class="docutils literal notranslate"><span class="pre">_thread</span></code> module in the stdlib. Third party code that
  2055. used <code class="docutils literal notranslate"><span class="pre">_thread.get_ident</span></code> should likewise be changed to use the new public
  2056. interface.</p>
  2057. </section>
  2058. <section id="time">
  2059. <h3>time<a class="headerlink" href="#time" title="Link to this heading">¶</a></h3>
  2060. <p>The <span class="target" id="index-28"></span><a class="pep reference external" href="https://peps.python.org/pep-0418/"><strong>PEP 418</strong></a> added new functions to the <a class="reference internal" href="../library/time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> module:</p>
  2061. <ul class="simple">
  2062. <li><p><a class="reference internal" href="../library/time.html#time.get_clock_info" title="time.get_clock_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_clock_info()</span></code></a>: Get information on a clock.</p></li>
  2063. <li><p><a class="reference internal" href="../library/time.html#time.monotonic" title="time.monotonic"><code class="xref py py-func docutils literal notranslate"><span class="pre">monotonic()</span></code></a>: Monotonic clock (cannot go backward), not affected
  2064. by system clock updates.</p></li>
  2065. <li><p><a class="reference internal" href="../library/time.html#time.perf_counter" title="time.perf_counter"><code class="xref py py-func docutils literal notranslate"><span class="pre">perf_counter()</span></code></a>: Performance counter with the highest available
  2066. resolution to measure a short duration.</p></li>
  2067. <li><p><a class="reference internal" href="../library/time.html#time.process_time" title="time.process_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">process_time()</span></code></a>: Sum of the system and user CPU time of the
  2068. current process.</p></li>
  2069. </ul>
  2070. <p>Other new functions:</p>
  2071. <ul class="simple">
  2072. <li><p><a class="reference internal" href="../library/time.html#time.clock_getres" title="time.clock_getres"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_getres()</span></code></a>, <a class="reference internal" href="../library/time.html#time.clock_gettime" title="time.clock_gettime"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_gettime()</span></code></a> and
  2073. <a class="reference internal" href="../library/time.html#time.clock_settime" title="time.clock_settime"><code class="xref py py-func docutils literal notranslate"><span class="pre">clock_settime()</span></code></a> functions with <code class="samp docutils literal notranslate"><span class="pre">CLOCK_</span><em><span class="pre">xxx</span></em></code> constants.
  2074. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10278">bpo-10278</a>.)</p></li>
  2075. </ul>
  2076. <p>To improve cross platform consistency, <a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">sleep()</span></code></a> now raises a
  2077. <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> when passed a negative sleep value. Previously this was an
  2078. error on posix, but produced an infinite sleep on Windows.</p>
  2079. </section>
  2080. <section id="types">
  2081. <h3>types<a class="headerlink" href="#types" title="Link to this heading">¶</a></h3>
  2082. <p>Add a new <a class="reference internal" href="../library/types.html#types.MappingProxyType" title="types.MappingProxyType"><code class="xref py py-class docutils literal notranslate"><span class="pre">types.MappingProxyType</span></code></a> class: Read-only proxy of a mapping.
  2083. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14386">bpo-14386</a>)</p>
  2084. <p>The new functions <a class="reference internal" href="../library/types.html#types.new_class" title="types.new_class"><code class="xref py py-func docutils literal notranslate"><span class="pre">types.new_class()</span></code></a> and <a class="reference internal" href="../library/types.html#types.prepare_class" title="types.prepare_class"><code class="xref py py-func docutils literal notranslate"><span class="pre">types.prepare_class()</span></code></a> provide support
  2085. for <span class="target" id="index-29"></span><a class="pep reference external" href="https://peps.python.org/pep-3115/"><strong>PEP 3115</strong></a> compliant dynamic type creation. (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14588">bpo-14588</a>)</p>
  2086. </section>
  2087. <section id="unittest">
  2088. <h3>unittest<a class="headerlink" href="#unittest" title="Link to this heading">¶</a></h3>
  2089. <p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertRaises" title="unittest.TestCase.assertRaises"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertRaises()</span></code></a>, <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertRaisesRegex" title="unittest.TestCase.assertRaisesRegex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertRaisesRegex()</span></code></a>, <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertWarns" title="unittest.TestCase.assertWarns"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertWarns()</span></code></a>, and
  2090. <a class="reference internal" href="../library/unittest.html#unittest.TestCase.assertWarnsRegex" title="unittest.TestCase.assertWarnsRegex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertWarnsRegex()</span></code></a> now accept a keyword argument <em>msg</em> when used as
  2091. context managers. (Contributed by Ezio Melotti and Winston Ewert in
  2092. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10775">bpo-10775</a>.)</p>
  2093. <p><a class="reference internal" href="../library/unittest.html#unittest.TestCase.run" title="unittest.TestCase.run"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unittest.TestCase.run()</span></code></a> now returns the <a class="reference internal" href="../library/unittest.html#unittest.TestResult" title="unittest.TestResult"><code class="xref py py-class docutils literal notranslate"><span class="pre">TestResult</span></code></a>
  2094. object.</p>
  2095. </section>
  2096. <section id="urllib">
  2097. <h3>urllib<a class="headerlink" href="#urllib" title="Link to this heading">¶</a></h3>
  2098. <p>The <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, now accepts a <em>method</em> argument
  2099. used by <a class="reference internal" href="../library/urllib.request.html#urllib.request.Request.get_method" title="urllib.request.Request.get_method"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_method()</span></code></a> to determine what HTTP method
  2100. should be used. For example, this will send a <code class="docutils literal notranslate"><span class="pre">'HEAD'</span></code> request:</p>
  2101. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">urlopen</span><span class="p">(</span><span class="n">Request</span><span class="p">(</span><span class="s1">&#39;https://www.python.org&#39;</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;HEAD&#39;</span><span class="p">))</span>
  2102. </pre></div>
  2103. </div>
  2104. <p>(<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1673007">bpo-1673007</a>)</p>
  2105. </section>
  2106. <section id="webbrowser">
  2107. <h3>webbrowser<a class="headerlink" href="#webbrowser" title="Link to this heading">¶</a></h3>
  2108. <p>The <a class="reference internal" href="../library/webbrowser.html#module-webbrowser" title="webbrowser: Easy-to-use controller for web browsers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">webbrowser</span></code></a> module supports more “browsers”: Google Chrome (named
  2109. <strong class="program">chrome</strong>, <strong class="program">chromium</strong>, <strong class="program">chrome-browser</strong> or
  2110. <strong class="program">chromium-browser</strong> depending on the version and operating system),
  2111. and the generic launchers <strong class="program">xdg-open</strong>, from the FreeDesktop.org
  2112. project, and <strong class="program">gvfs-open</strong>, which is the default URI handler for GNOME
  2113. 3. (The former contributed by Arnaud Calmettes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13620">bpo-13620</a>, the latter
  2114. by Matthias Klose in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14493">bpo-14493</a>.)</p>
  2115. </section>
  2116. <section id="xml-etree-elementtree">
  2117. <h3>xml.etree.ElementTree<a class="headerlink" href="#xml-etree-elementtree" title="Link to this heading">¶</a></h3>
  2118. <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> module now imports its C accelerator by
  2119. default; there is no longer a need to explicitly import
  2120. <code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.cElementTree</span></code> (this module stays for backwards compatibility,
  2121. but is now deprecated). In addition, the <code class="docutils literal notranslate"><span class="pre">iter</span></code> family of methods of
  2122. <a class="reference internal" href="../library/xml.etree.elementtree.html#xml.etree.ElementTree.Element" title="xml.etree.ElementTree.Element"><code class="xref py py-class docutils literal notranslate"><span class="pre">Element</span></code></a> has been optimized (rewritten in C).
  2123. The module’s documentation has also been greatly improved with added examples
  2124. and a more detailed reference.</p>
  2125. </section>
  2126. <section id="zlib">
  2127. <h3>zlib<a class="headerlink" href="#zlib" title="Link to this heading">¶</a></h3>
  2128. <p>New attribute <a class="reference internal" href="../library/zlib.html#zlib.Decompress.eof" title="zlib.Decompress.eof"><code class="xref py py-attr docutils literal notranslate"><span class="pre">zlib.Decompress.eof</span></code></a> makes it possible to distinguish
  2129. between a properly formed compressed stream and an incomplete or truncated one.
  2130. (Contributed by Nadeem Vawda in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12646">bpo-12646</a>.)</p>
  2131. <p>New attribute <a class="reference internal" href="../library/zlib.html#zlib.ZLIB_RUNTIME_VERSION" title="zlib.ZLIB_RUNTIME_VERSION"><code class="xref py py-const docutils literal notranslate"><span class="pre">zlib.ZLIB_RUNTIME_VERSION</span></code></a> reports the version string of
  2132. the underlying <code class="docutils literal notranslate"><span class="pre">zlib</span></code> library that is loaded at runtime. (Contributed by
  2133. Torsten Landschoff in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12306">bpo-12306</a>.)</p>
  2134. </section>
  2135. </section>
  2136. <section id="optimizations">
  2137. <h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading">¶</a></h2>
  2138. <p>Major performance enhancements have been added:</p>
  2139. <ul>
  2140. <li><p>Thanks to <span class="target" id="index-30"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a>, some operations on Unicode strings have been optimized:</p>
  2141. <ul class="simple">
  2142. <li><p>the memory footprint is divided by 2 to 4 depending on the text</p></li>
  2143. <li><p>encode an ASCII string to UTF-8 doesn’t need to encode characters anymore,
  2144. the UTF-8 representation is shared with the ASCII representation</p></li>
  2145. <li><p>the UTF-8 encoder has been optimized</p></li>
  2146. <li><p>repeating a single ASCII letter and getting a substring of an ASCII string
  2147. is 4 times faster</p></li>
  2148. </ul>
  2149. </li>
  2150. <li><p>UTF-8 is now 2x to 4x faster. UTF-16 encoding is now up to 10x faster.</p>
  2151. <p>(Contributed by Serhiy Storchaka, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14624">bpo-14624</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14738">bpo-14738</a> and
  2152. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15026">bpo-15026</a>.)</p>
  2153. </li>
  2154. </ul>
  2155. </section>
  2156. <section id="build-and-c-api-changes">
  2157. <h2>Build and C API Changes<a class="headerlink" href="#build-and-c-api-changes" title="Link to this heading">¶</a></h2>
  2158. <p>Changes to Python’s build process and to the C API include:</p>
  2159. <ul class="simple">
  2160. <li><p>New <span class="target" id="index-31"></span><a class="pep reference external" href="https://peps.python.org/pep-3118/"><strong>PEP 3118</strong></a> related function:</p>
  2161. <ul>
  2162. <li><p><a class="reference internal" href="../c-api/memoryview.html#c.PyMemoryView_FromMemory" title="PyMemoryView_FromMemory"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMemoryView_FromMemory()</span></code></a></p></li>
  2163. </ul>
  2164. </li>
  2165. <li><p><span class="target" id="index-32"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a> added new Unicode types, macros and functions:</p>
  2166. <ul>
  2167. <li><p>High-level API:</p>
  2168. <ul>
  2169. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_CopyCharacters" title="PyUnicode_CopyCharacters"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_CopyCharacters()</span></code></a></p></li>
  2170. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FindChar" title="PyUnicode_FindChar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FindChar()</span></code></a></p></li>
  2171. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GetLength" title="PyUnicode_GetLength"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetLength()</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GET_LENGTH" title="PyUnicode_GET_LENGTH"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_GET_LENGTH</span></code></a></p></li>
  2172. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_New" title="PyUnicode_New"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_New()</span></code></a></p></li>
  2173. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Substring" title="PyUnicode_Substring"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Substring()</span></code></a></p></li>
  2174. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_ReadChar" title="PyUnicode_ReadChar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_ReadChar()</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_WriteChar" title="PyUnicode_WriteChar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_WriteChar()</span></code></a></p></li>
  2175. </ul>
  2176. </li>
  2177. <li><p>Low-level API:</p>
  2178. <ul>
  2179. <li><p><a class="reference internal" href="../c-api/unicode.html#c.Py_UCS1" title="Py_UCS1"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UCS1</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.Py_UCS2" title="Py_UCS2"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UCS2</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.Py_UCS4" title="Py_UCS4"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UCS4</span></code></a> types</p></li>
  2180. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyASCIIObject" title="PyASCIIObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyASCIIObject</span></code></a> and <a class="reference internal" href="../c-api/unicode.html#c.PyCompactUnicodeObject" title="PyCompactUnicodeObject"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyCompactUnicodeObject</span></code></a> structures</p></li>
  2181. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_READY" title="PyUnicode_READY"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_READY</span></code></a></p></li>
  2182. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromKindAndData" title="PyUnicode_FromKindAndData"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromKindAndData()</span></code></a></p></li>
  2183. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUCS4" title="PyUnicode_AsUCS4"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUCS4()</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUCS4Copy" title="PyUnicode_AsUCS4Copy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUCS4Copy()</span></code></a></p></li>
  2184. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_DATA" title="PyUnicode_DATA"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_DATA</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_1BYTE_DATA" title="PyUnicode_1BYTE_DATA"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_1BYTE_DATA</span></code></a>,
  2185. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_2BYTE_DATA" title="PyUnicode_2BYTE_DATA"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_2BYTE_DATA</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_4BYTE_DATA" title="PyUnicode_4BYTE_DATA"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_4BYTE_DATA</span></code></a></p></li>
  2186. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_KIND" title="PyUnicode_KIND"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_KIND</span></code></a> with <code class="xref c c-enum docutils literal notranslate"><span class="pre">PyUnicode_Kind</span></code> enum:
  2187. <code class="xref c c-data docutils literal notranslate"><span class="pre">PyUnicode_WCHAR_KIND</span></code>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_1BYTE_KIND" title="PyUnicode_1BYTE_KIND"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyUnicode_1BYTE_KIND</span></code></a>,
  2188. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_2BYTE_KIND" title="PyUnicode_2BYTE_KIND"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyUnicode_2BYTE_KIND</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_4BYTE_KIND" title="PyUnicode_4BYTE_KIND"><code class="xref c c-data docutils literal notranslate"><span class="pre">PyUnicode_4BYTE_KIND</span></code></a></p></li>
  2189. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_READ" title="PyUnicode_READ"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_READ</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_READ_CHAR" title="PyUnicode_READ_CHAR"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_READ_CHAR</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_WRITE" title="PyUnicode_WRITE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_WRITE</span></code></a></p></li>
  2190. <li><p><a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_MAX_CHAR_VALUE" title="PyUnicode_MAX_CHAR_VALUE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_MAX_CHAR_VALUE</span></code></a></p></li>
  2191. </ul>
  2192. </li>
  2193. </ul>
  2194. </li>
  2195. <li><p><a class="reference internal" href="../c-api/arg.html#c.PyArg_ParseTuple" title="PyArg_ParseTuple"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyArg_ParseTuple</span></code></a> now accepts a <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> for the <code class="docutils literal notranslate"><span class="pre">c</span></code>
  2196. format (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12380">bpo-12380</a>).</p></li>
  2197. </ul>
  2198. </section>
  2199. <section id="deprecated">
  2200. <h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading">¶</a></h2>
  2201. <section id="unsupported-operating-systems">
  2202. <h3>Unsupported Operating Systems<a class="headerlink" href="#unsupported-operating-systems" title="Link to this heading">¶</a></h3>
  2203. <p>OS/2 and VMS are no longer supported due to the lack of a maintainer.</p>
  2204. <p>Windows 2000 and Windows platforms which set <code class="docutils literal notranslate"><span class="pre">COMSPEC</span></code> to <code class="docutils literal notranslate"><span class="pre">command.com</span></code>
  2205. are no longer supported due to maintenance burden.</p>
  2206. <p>OSF support, which was deprecated in 3.2, has been completely removed.</p>
  2207. </section>
  2208. <section id="deprecated-python-modules-functions-and-methods">
  2209. <h3>Deprecated Python modules, functions and methods<a class="headerlink" href="#deprecated-python-modules-functions-and-methods" title="Link to this heading">¶</a></h3>
  2210. <ul class="simple">
  2211. <li><p>Passing a non-empty string to <code class="docutils literal notranslate"><span class="pre">object.__format__()</span></code> is deprecated, and
  2212. will produce a <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> in Python 3.4 (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9856">bpo-9856</a>).</p></li>
  2213. <li><p>The <code class="docutils literal notranslate"><span class="pre">unicode_internal</span></code> codec has been deprecated because of the
  2214. <span class="target" id="index-33"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a>, use UTF-8, UTF-16 (<code class="docutils literal notranslate"><span class="pre">utf-16-le</span></code> or <code class="docutils literal notranslate"><span class="pre">utf-16-be</span></code>), or UTF-32
  2215. (<code class="docutils literal notranslate"><span class="pre">utf-32-le</span></code> or <code class="docutils literal notranslate"><span class="pre">utf-32-be</span></code>)</p></li>
  2216. <li><p><a class="reference internal" href="../library/ftplib.html#ftplib.FTP.nlst" title="ftplib.FTP.nlst"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ftplib.FTP.nlst()</span></code></a> and <a class="reference internal" href="../library/ftplib.html#ftplib.FTP.dir" title="ftplib.FTP.dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ftplib.FTP.dir()</span></code></a>: use
  2217. <a class="reference internal" href="../library/ftplib.html#ftplib.FTP.mlsd" title="ftplib.FTP.mlsd"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ftplib.FTP.mlsd()</span></code></a></p></li>
  2218. <li><p><code class="xref py py-func docutils literal notranslate"><span class="pre">platform.popen()</span></code>: use the <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module. Check especially
  2219. the <a class="reference internal" href="../library/subprocess.html#subprocess-replacements"><span class="std std-ref">Replacing Older Functions with the subprocess Module</span></a> section (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11377">bpo-11377</a>).</p></li>
  2220. <li><p><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13374">bpo-13374</a>: The Windows bytes API has been deprecated in the <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a>
  2221. module. Use Unicode filenames, instead of bytes filenames, to not depend on
  2222. the ANSI code page anymore and to support any filename.</p></li>
  2223. <li><p><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13988">bpo-13988</a>: The <code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.etree.cElementTree</span></code> module is deprecated. The
  2224. accelerator is used automatically whenever available.</p></li>
  2225. <li><p>The behaviour of <code class="xref py py-func docutils literal notranslate"><span class="pre">time.clock()</span></code> depends on the platform: use the new
  2226. <a class="reference internal" href="../library/time.html#time.perf_counter" title="time.perf_counter"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.perf_counter()</span></code></a> or <a class="reference internal" href="../library/time.html#time.process_time" title="time.process_time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.process_time()</span></code></a> function instead,
  2227. depending on your requirements, to have a well defined behaviour.</p></li>
  2228. <li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">os.stat_float_times()</span></code> function is deprecated.</p></li>
  2229. <li><p><a class="reference internal" href="../library/abc.html#module-abc" title="abc: Abstract base classes according to :pep:`3119`."><code class="xref py py-mod docutils literal notranslate"><span class="pre">abc</span></code></a> module:</p>
  2230. <ul>
  2231. <li><p><a class="reference internal" href="../library/abc.html#abc.abstractproperty" title="abc.abstractproperty"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.abstractproperty</span></code></a> has been deprecated, use <a class="reference internal" href="../library/functions.html#property" title="property"><code class="xref py py-class docutils literal notranslate"><span class="pre">property</span></code></a>
  2232. with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.abstractmethod()</span></code></a> instead.</p></li>
  2233. <li><p><a class="reference internal" href="../library/abc.html#abc.abstractclassmethod" title="abc.abstractclassmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.abstractclassmethod</span></code></a> has been deprecated, use
  2234. <a class="reference internal" href="../library/functions.html#classmethod" title="classmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">classmethod</span></code></a> with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.abstractmethod()</span></code></a> instead.</p></li>
  2235. <li><p><a class="reference internal" href="../library/abc.html#abc.abstractstaticmethod" title="abc.abstractstaticmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.abstractstaticmethod</span></code></a> has been deprecated, use
  2236. <a class="reference internal" href="../library/functions.html#staticmethod" title="staticmethod"><code class="xref py py-class docutils literal notranslate"><span class="pre">staticmethod</span></code></a> with <a class="reference internal" href="../library/abc.html#abc.abstractmethod" title="abc.abstractmethod"><code class="xref py py-func docutils literal notranslate"><span class="pre">abc.abstractmethod()</span></code></a> instead.</p></li>
  2237. </ul>
  2238. </li>
  2239. <li><p><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> package:</p>
  2240. <ul>
  2241. <li><p><a class="reference internal" href="../library/importlib.html#importlib.abc.SourceLoader.path_mtime" title="importlib.abc.SourceLoader.path_mtime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.SourceLoader.path_mtime()</span></code></a> is now deprecated in favour of
  2242. <a class="reference internal" href="../library/importlib.html#importlib.abc.SourceLoader.path_stats" title="importlib.abc.SourceLoader.path_stats"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.SourceLoader.path_stats()</span></code></a> as bytecode files now store
  2243. both the modification time and size of the source file the bytecode file was
  2244. compiled from.</p></li>
  2245. </ul>
  2246. </li>
  2247. </ul>
  2248. </section>
  2249. <section id="deprecated-functions-and-types-of-the-c-api">
  2250. <h3>Deprecated functions and types of the C API<a class="headerlink" href="#deprecated-functions-and-types-of-the-c-api" title="Link to this heading">¶</a></h3>
  2251. <p>The <a class="reference internal" href="../c-api/unicode.html#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE</span></code></a> has been deprecated by <span class="target" id="index-34"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a> and will be
  2252. removed in Python 4. All functions using this type are deprecated:</p>
  2253. <p>Unicode functions and methods using <a class="reference internal" href="../c-api/unicode.html#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE</span></code></a> and
  2254. <span class="c-expr sig sig-inline c"><a class="reference internal" href="../c-api/unicode.html#c.Py_UNICODE" title="Py_UNICODE"><span class="n">Py_UNICODE</span></a><span class="p">*</span></span> types:</p>
  2255. <ul class="simple">
  2256. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_FromUnicode</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromWideChar" title="PyUnicode_FromWideChar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromWideChar()</span></code></a> or
  2257. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromKindAndData" title="PyUnicode_FromKindAndData"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromKindAndData()</span></code></a></p></li>
  2258. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_AS_UNICODE</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicode()</span></code>,
  2259. <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicodeAndSize()</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsWideCharString" title="PyUnicode_AsWideCharString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsWideCharString()</span></code></a></p></li>
  2260. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_AS_DATA</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_DATA" title="PyUnicode_DATA"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_DATA</span></code></a> with
  2261. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_READ" title="PyUnicode_READ"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_READ</span></code></a> and <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_WRITE" title="PyUnicode_WRITE"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_WRITE</span></code></a></p></li>
  2262. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_GET_SIZE</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetSize()</span></code>: use
  2263. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GET_LENGTH" title="PyUnicode_GET_LENGTH"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_GET_LENGTH</span></code></a> or <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GetLength" title="PyUnicode_GetLength"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetLength()</span></code></a></p></li>
  2264. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_GET_DATA_SIZE</span></code>: use
  2265. <code class="docutils literal notranslate"><span class="pre">PyUnicode_GET_LENGTH(str)</span> <span class="pre">*</span> <span class="pre">PyUnicode_KIND(str)</span></code> (only work on ready
  2266. strings)</p></li>
  2267. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicodeCopy()</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUCS4Copy" title="PyUnicode_AsUCS4Copy"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUCS4Copy()</span></code></a> or
  2268. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsWideCharString" title="PyUnicode_AsWideCharString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsWideCharString()</span></code></a></p></li>
  2269. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetMax()</span></code></p></li>
  2270. </ul>
  2271. <p>Functions and macros manipulating Py_UNICODE* strings:</p>
  2272. <ul class="simple">
  2273. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strlen()</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GetLength" title="PyUnicode_GetLength"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_GetLength()</span></code></a> or
  2274. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_GET_LENGTH" title="PyUnicode_GET_LENGTH"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PyUnicode_GET_LENGTH</span></code></a></p></li>
  2275. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strcat()</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_CopyCharacters" title="PyUnicode_CopyCharacters"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_CopyCharacters()</span></code></a> or
  2276. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FromFormat" title="PyUnicode_FromFormat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FromFormat()</span></code></a></p></li>
  2277. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strcpy()</span></code>, <code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strncpy()</span></code>,
  2278. <code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_COPY()</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_CopyCharacters" title="PyUnicode_CopyCharacters"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_CopyCharacters()</span></code></a> or
  2279. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Substring" title="PyUnicode_Substring"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Substring()</span></code></a></p></li>
  2280. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strcmp()</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Compare" title="PyUnicode_Compare"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Compare()</span></code></a></p></li>
  2281. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strncmp()</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Tailmatch" title="PyUnicode_Tailmatch"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Tailmatch()</span></code></a></p></li>
  2282. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strchr()</span></code>, <code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_strrchr()</span></code>: use
  2283. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FindChar" title="PyUnicode_FindChar"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FindChar()</span></code></a></p></li>
  2284. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_FILL()</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Fill" title="PyUnicode_Fill"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Fill()</span></code></a></p></li>
  2285. <li><p><code class="xref c c-macro docutils literal notranslate"><span class="pre">Py_UNICODE_MATCH</span></code></p></li>
  2286. </ul>
  2287. <p>Encoders:</p>
  2288. <ul class="simple">
  2289. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Encode()</span></code>: use <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsEncodedObject()</span></code></p></li>
  2290. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF7()</span></code></p></li>
  2291. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF8()</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUTF8" title="PyUnicode_AsUTF8"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUTF8()</span></code></a> or
  2292. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUTF8String" title="PyUnicode_AsUTF8String"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUTF8String()</span></code></a></p></li>
  2293. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF32()</span></code></p></li>
  2294. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUTF16()</span></code></p></li>
  2295. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeUnicodeEscape()</span></code> use
  2296. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsUnicodeEscapeString" title="PyUnicode_AsUnicodeEscapeString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsUnicodeEscapeString()</span></code></a></p></li>
  2297. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeRawUnicodeEscape()</span></code> use
  2298. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsRawUnicodeEscapeString" title="PyUnicode_AsRawUnicodeEscapeString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsRawUnicodeEscapeString()</span></code></a></p></li>
  2299. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeLatin1()</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsLatin1String" title="PyUnicode_AsLatin1String"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsLatin1String()</span></code></a></p></li>
  2300. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeASCII()</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsASCIIString" title="PyUnicode_AsASCIIString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsASCIIString()</span></code></a></p></li>
  2301. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeCharmap()</span></code></p></li>
  2302. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_TranslateCharmap()</span></code></p></li>
  2303. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeMBCS()</span></code>: use <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_AsMBCSString" title="PyUnicode_AsMBCSString"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsMBCSString()</span></code></a> or
  2304. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_EncodeCodePage" title="PyUnicode_EncodeCodePage"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeCodePage()</span></code></a> (with <code class="docutils literal notranslate"><span class="pre">CP_ACP</span></code> code_page)</p></li>
  2305. <li><p><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_EncodeDecimal()</span></code>,
  2306. <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_TransformDecimalToASCII()</span></code></p></li>
  2307. </ul>
  2308. </section>
  2309. <section id="deprecated-features">
  2310. <h3>Deprecated features<a class="headerlink" href="#deprecated-features" title="Link to this heading">¶</a></h3>
  2311. <p>The <a class="reference internal" href="../library/array.html#module-array" title="array: Space efficient arrays of uniformly typed numeric values."><code class="xref py py-mod docutils literal notranslate"><span class="pre">array</span></code></a> module’s <code class="docutils literal notranslate"><span class="pre">'u'</span></code> format code is now deprecated and will be
  2312. removed in Python 4 together with the rest of the (<a class="reference internal" href="../c-api/unicode.html#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE</span></code></a>) API.</p>
  2313. </section>
  2314. </section>
  2315. <section id="porting-to-python-3-3">
  2316. <h2>Porting to Python 3.3<a class="headerlink" href="#porting-to-python-3-3" title="Link to this heading">¶</a></h2>
  2317. <p>This section lists previously described changes and other bugfixes
  2318. that may require changes to your code.</p>
  2319. <section id="porting-python-code">
  2320. <span id="portingpythoncode"></span><h3>Porting Python code<a class="headerlink" href="#porting-python-code" title="Link to this heading">¶</a></h3>
  2321. <ul class="simple">
  2322. <li><p>Hash randomization is enabled by default. Set the <span class="target" id="index-35"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHASHSEED"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHASHSEED</span></code></a>
  2323. environment variable to <code class="docutils literal notranslate"><span class="pre">0</span></code> to disable hash randomization. See also the
  2324. <a class="reference internal" href="../reference/datamodel.html#object.__hash__" title="object.__hash__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__hash__()</span></code></a> method.</p></li>
  2325. <li><p><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12326">bpo-12326</a>: On Linux, sys.platform doesn’t contain the major version
  2326. anymore. It is now always ‘linux’, instead of ‘linux2’ or ‘linux3’ depending
  2327. on the Linux version used to build Python. Replace sys.platform == ‘linux2’
  2328. with sys.platform.startswith(‘linux’), or directly sys.platform == ‘linux’ if
  2329. you don’t need to support older Python versions.</p></li>
  2330. <li><p><a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13847">bpo-13847</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14180">bpo-14180</a>: <a class="reference internal" href="../library/time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> and <a class="reference internal" href="../library/datetime.html#module-datetime" title="datetime: Basic date and time types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code></a>:
  2331. <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> is now raised instead of <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> if a
  2332. timestamp is out of range. <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is now raised if C functions
  2333. <code class="xref c c-func docutils literal notranslate"><span class="pre">gmtime()</span></code> or <code class="xref c c-func docutils literal notranslate"><span class="pre">localtime()</span></code> failed.</p></li>
  2334. <li><p>The default finders used by import now utilize a cache of what is contained
  2335. within a specific directory. If you create a Python source file or sourceless
  2336. bytecode file, make sure to call <a class="reference internal" href="../library/importlib.html#importlib.invalidate_caches" title="importlib.invalidate_caches"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.invalidate_caches()</span></code></a> to clear
  2337. out the cache for the finders to notice the new file.</p></li>
  2338. <li><p><a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a> now uses the full name of the module that was attempted to
  2339. be imported. Doctests that check ImportErrors’ message will need to be
  2340. updated to use the full name of the module instead of just the tail of the
  2341. name.</p></li>
  2342. <li><p>The <em>index</em> argument to <a class="reference internal" href="../library/functions.html#import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> now defaults to 0 instead of -1
  2343. and no longer support negative values. It was an oversight when <span class="target" id="index-36"></span><a class="pep reference external" href="https://peps.python.org/pep-0328/"><strong>PEP 328</strong></a> was
  2344. implemented that the default value remained -1. If you need to continue to
  2345. perform a relative import followed by an absolute import, then perform the
  2346. relative import using an index of 1, followed by another import using an
  2347. index of 0. It is preferred, though, that you use
  2348. <a class="reference internal" href="../library/importlib.html#importlib.import_module" title="importlib.import_module"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.import_module()</span></code></a> rather than call <a class="reference internal" href="../library/functions.html#import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> directly.</p></li>
  2349. <li><p><a class="reference internal" href="../library/functions.html#import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> no longer allows one to use an index value other than 0
  2350. for top-level modules. E.g. <code class="docutils literal notranslate"><span class="pre">__import__('sys',</span> <span class="pre">level=1)</span></code> is now an error.</p></li>
  2351. <li><p>Because <a class="reference internal" href="../library/sys.html#sys.meta_path" title="sys.meta_path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.meta_path</span></code></a> and <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> now have finders on
  2352. them by default, you will most likely want to use <code class="xref py py-meth docutils literal notranslate"><span class="pre">list.insert()</span></code> instead
  2353. of <code class="xref py py-meth docutils literal notranslate"><span class="pre">list.append()</span></code> to add to those lists.</p></li>
  2354. <li><p>Because <code class="docutils literal notranslate"><span class="pre">None</span></code> is now inserted into <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>, if you
  2355. are clearing out entries in the dictionary of paths that do not have a
  2356. finder, you will need to remove keys paired with values of <code class="docutils literal notranslate"><span class="pre">None</span></code> <strong>and</strong>
  2357. <code class="xref py py-class docutils literal notranslate"><span class="pre">imp.NullImporter</span></code> to be backwards-compatible. This will lead to extra
  2358. overhead on older versions of Python that re-insert <code class="docutils literal notranslate"><span class="pre">None</span></code> into
  2359. <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> where it represents the use of implicit
  2360. finders, but semantically it should not change anything.</p></li>
  2361. <li><p><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.abc.Finder</span></code> no longer specifies a <code class="docutils literal notranslate"><span class="pre">find_module()</span></code> abstract
  2362. method that must be implemented. If you were relying on subclasses to
  2363. implement that method, make sure to check for the method’s existence first.
  2364. You will probably want to check for <code class="docutils literal notranslate"><span class="pre">find_loader()</span></code> first, though, in the
  2365. case of working with <a class="reference internal" href="../glossary.html#term-path-entry-finder"><span class="xref std std-term">path entry finders</span></a>.</p></li>
  2366. <li><p><a class="reference internal" href="../library/pkgutil.html#module-pkgutil" title="pkgutil: Utilities for the import system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pkgutil</span></code></a> has been converted to use <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> internally. This
  2367. eliminates many edge cases where the old behaviour of the <span class="target" id="index-37"></span><a class="pep reference external" href="https://peps.python.org/pep-0302/"><strong>PEP 302</strong></a> import
  2368. emulation failed to match the behaviour of the real import system. The
  2369. import emulation itself is still present, but is now deprecated. The
  2370. <a class="reference internal" href="../library/pkgutil.html#pkgutil.iter_importers" title="pkgutil.iter_importers"><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.iter_importers()</span></code></a> and <a class="reference internal" href="../library/pkgutil.html#pkgutil.walk_packages" title="pkgutil.walk_packages"><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.walk_packages()</span></code></a> functions
  2371. special case the standard import hooks so they are still supported even
  2372. though they do not provide the non-standard <code class="docutils literal notranslate"><span class="pre">iter_modules()</span></code> method.</p></li>
  2373. <li><p>A longstanding RFC-compliance bug (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1079">bpo-1079</a>) in the parsing done by
  2374. <a class="reference internal" href="../library/email.header.html#email.header.decode_header" title="email.header.decode_header"><code class="xref py py-func docutils literal notranslate"><span class="pre">email.header.decode_header()</span></code></a> has been fixed. Code that uses the
  2375. standard idiom to convert encoded headers into unicode
  2376. (<code class="docutils literal notranslate"><span class="pre">str(make_header(decode_header(h))</span></code>) will see no change, but code that
  2377. looks at the individual tuples returned by decode_header will see that
  2378. whitespace that precedes or follows <code class="docutils literal notranslate"><span class="pre">ASCII</span></code> sections is now included in the
  2379. <code class="docutils literal notranslate"><span class="pre">ASCII</span></code> section. Code that builds headers using <code class="docutils literal notranslate"><span class="pre">make_header</span></code> should
  2380. also continue to work without change, since <code class="docutils literal notranslate"><span class="pre">make_header</span></code> continues to add
  2381. whitespace between <code class="docutils literal notranslate"><span class="pre">ASCII</span></code> and non-<code class="docutils literal notranslate"><span class="pre">ASCII</span></code> sections if it is not already
  2382. present in the input strings.</p></li>
  2383. <li><p><a class="reference internal" href="../library/email.utils.html#email.utils.formataddr" title="email.utils.formataddr"><code class="xref py py-func docutils literal notranslate"><span class="pre">email.utils.formataddr()</span></code></a> now does the correct content transfer
  2384. encoding when passed non-<code class="docutils literal notranslate"><span class="pre">ASCII</span></code> display names. Any code that depended on
  2385. the previous buggy behavior that preserved the non-<code class="docutils literal notranslate"><span class="pre">ASCII</span></code> unicode in the
  2386. formatted output string will need to be changed (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1690608">bpo-1690608</a>).</p></li>
  2387. <li><p><a class="reference internal" href="../library/poplib.html#poplib.POP3.quit" title="poplib.POP3.quit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">poplib.POP3.quit()</span></code></a> may now raise protocol errors like all other
  2388. <code class="docutils literal notranslate"><span class="pre">poplib</span></code> methods. Code that assumes <code class="docutils literal notranslate"><span class="pre">quit</span></code> does not raise
  2389. <a class="reference internal" href="../library/poplib.html#poplib.error_proto" title="poplib.error_proto"><code class="xref py py-exc docutils literal notranslate"><span class="pre">poplib.error_proto</span></code></a> errors may need to be changed if errors on <code class="docutils literal notranslate"><span class="pre">quit</span></code>
  2390. are encountered by a particular application (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11291">bpo-11291</a>).</p></li>
  2391. <li><p>The <code class="docutils literal notranslate"><span class="pre">strict</span></code> argument to <a class="reference internal" href="../library/email.parser.html#email.parser.Parser" title="email.parser.Parser"><code class="xref py py-class docutils literal notranslate"><span class="pre">email.parser.Parser</span></code></a>, deprecated since
  2392. Python 2.4, has finally been removed.</p></li>
  2393. <li><p>The deprecated method <code class="docutils literal notranslate"><span class="pre">unittest.TestCase.assertSameElements</span></code> has been
  2394. removed.</p></li>
  2395. <li><p>The deprecated variable <code class="docutils literal notranslate"><span class="pre">time.accept2dyear</span></code> has been removed.</p></li>
  2396. <li><p>The deprecated <code class="docutils literal notranslate"><span class="pre">Context._clamp</span></code> attribute has been removed from the
  2397. <a class="reference internal" href="../library/decimal.html#module-decimal" title="decimal: Implementation of the General Decimal Arithmetic Specification."><code class="xref py py-mod docutils literal notranslate"><span class="pre">decimal</span></code></a> module. It was previously replaced by the public attribute
  2398. <code class="xref py py-attr docutils literal notranslate"><span class="pre">clamp</span></code>. (See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8540">bpo-8540</a>.)</p></li>
  2399. <li><p>The undocumented internal helper class <code class="docutils literal notranslate"><span class="pre">SSLFakeFile</span></code> has been removed
  2400. from <a class="reference internal" href="../library/smtplib.html#module-smtplib" title="smtplib: SMTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtplib</span></code></a>, since its functionality has long been provided directly
  2401. by <a class="reference internal" href="../library/socket.html#socket.socket.makefile" title="socket.socket.makefile"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.socket.makefile()</span></code></a>.</p></li>
  2402. <li><p>Passing a negative value to <a class="reference internal" href="../library/time.html#time.sleep" title="time.sleep"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.sleep()</span></code></a> on Windows now raises an
  2403. error instead of sleeping forever. It has always raised an error on posix.</p></li>
  2404. <li><p>The <code class="docutils literal notranslate"><span class="pre">ast.__version__</span></code> constant has been removed. If you need to
  2405. make decisions affected by the AST version, use <a class="reference internal" href="../library/sys.html#sys.version_info" title="sys.version_info"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.version_info</span></code></a>
  2406. to make the decision.</p></li>
  2407. <li><p>Code that used to work around the fact that the <a class="reference internal" href="../library/threading.html#module-threading" title="threading: Thread-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">threading</span></code></a> module used
  2408. factory functions by subclassing the private classes will need to change to
  2409. subclass the now-public classes.</p></li>
  2410. <li><p>The undocumented debugging machinery in the threading module has been
  2411. removed, simplifying the code. This should have no effect on production
  2412. code, but is mentioned here in case any application debug frameworks were
  2413. interacting with it (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13550">bpo-13550</a>).</p></li>
  2414. </ul>
  2415. </section>
  2416. <section id="porting-c-code">
  2417. <h3>Porting C code<a class="headerlink" href="#porting-c-code" title="Link to this heading">¶</a></h3>
  2418. <ul>
  2419. <li><p>In the course of changes to the buffer API the undocumented
  2420. <code class="xref c c-member docutils literal notranslate"><span class="pre">smalltable</span></code> member of the
  2421. <a class="reference internal" href="../c-api/buffer.html#c.Py_buffer" title="Py_buffer"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_buffer</span></code></a> structure has been removed and the
  2422. layout of the <code class="xref c c-type docutils literal notranslate"><span class="pre">PyMemoryViewObject</span></code> has changed.</p>
  2423. <p>All extensions relying on the relevant parts in <code class="docutils literal notranslate"><span class="pre">memoryobject.h</span></code>
  2424. or <code class="docutils literal notranslate"><span class="pre">object.h</span></code> must be rebuilt.</p>
  2425. </li>
  2426. <li><p>Due to <a class="reference internal" href="#pep-393"><span class="std std-ref">PEP 393</span></a>, the <a class="reference internal" href="../c-api/unicode.html#c.Py_UNICODE" title="Py_UNICODE"><code class="xref c c-type docutils literal notranslate"><span class="pre">Py_UNICODE</span></code></a> type and all
  2427. functions using this type are deprecated (but will stay available for
  2428. at least five years). If you were using low-level Unicode APIs to
  2429. construct and access unicode objects and you want to benefit of the
  2430. memory footprint reduction provided by <span class="target" id="index-38"></span><a class="pep reference external" href="https://peps.python.org/pep-0393/"><strong>PEP 393</strong></a>, you have to convert
  2431. your code to the new <a class="reference internal" href="../c-api/unicode.html"><span class="doc">Unicode API</span></a>.</p>
  2432. <p>However, if you only have been using high-level functions such as
  2433. <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Concat" title="PyUnicode_Concat"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Concat()</span></code></a>, <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_Join" title="PyUnicode_Join"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_Join()</span></code></a> or
  2434. <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>, your code will automatically take
  2435. advantage of the new unicode representations.</p>
  2436. </li>
  2437. <li><p><a class="reference internal" href="../c-api/import.html#c.PyImport_GetMagicNumber" title="PyImport_GetMagicNumber"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_GetMagicNumber()</span></code></a> now returns <code class="docutils literal notranslate"><span class="pre">-1</span></code> upon failure.</p></li>
  2438. <li><p>As a negative value for the <em>level</em> argument to <a class="reference internal" href="../library/functions.html#import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a> is no
  2439. longer valid, the same now holds for <a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModuleLevel" title="PyImport_ImportModuleLevel"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModuleLevel()</span></code></a>.
  2440. This also means that the value of <em>level</em> used by
  2441. <a class="reference internal" href="../c-api/import.html#c.PyImport_ImportModuleEx" title="PyImport_ImportModuleEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ImportModuleEx()</span></code></a> is now <code class="docutils literal notranslate"><span class="pre">0</span></code> instead of <code class="docutils literal notranslate"><span class="pre">-1</span></code>.</p></li>
  2442. </ul>
  2443. </section>
  2444. <section id="building-c-extensions">
  2445. <h3>Building C extensions<a class="headerlink" href="#building-c-extensions" title="Link to this heading">¶</a></h3>
  2446. <ul>
  2447. <li><p>The range of possible file names for C extensions has been narrowed.
  2448. Very rarely used spellings have been suppressed: under POSIX, files
  2449. named <code class="docutils literal notranslate"><span class="pre">xxxmodule.so</span></code>, <code class="docutils literal notranslate"><span class="pre">xxxmodule.abi3.so</span></code> and
  2450. <code class="docutils literal notranslate"><span class="pre">xxxmodule.cpython-*.so</span></code> are no longer recognized as implementing
  2451. the <code class="docutils literal notranslate"><span class="pre">xxx</span></code> module. If you had been generating such files, you have
  2452. to switch to the other spellings (i.e., remove the <code class="docutils literal notranslate"><span class="pre">module</span></code> string
  2453. from the file names).</p>
  2454. <p>(implemented in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=14040">bpo-14040</a>.)</p>
  2455. </li>
  2456. </ul>
  2457. </section>
  2458. <section id="command-line-switch-changes">
  2459. <h3>Command Line Switch Changes<a class="headerlink" href="#command-line-switch-changes" title="Link to this heading">¶</a></h3>
  2460. <ul>
  2461. <li><p>The -Q command-line flag and related artifacts have been removed. Code
  2462. checking sys.flags.division_warning will need updating.</p>
  2463. <p>(<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=10998">bpo-10998</a>, contributed by Éric Araujo.)</p>
  2464. </li>
  2465. <li><p>When <strong class="program">python</strong> is started with <a class="reference internal" href="../using/cmdline.html#cmdoption-S"><code class="xref std std-option docutils literal notranslate"><span class="pre">-S</span></code></a>, <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">site</span></code>
  2466. will no longer add site-specific paths to the module search paths. In
  2467. previous versions, it did.</p>
  2468. <p>(<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11591">bpo-11591</a>, contributed by Carl Meyer with editions by Éric Araujo.)</p>
  2469. </li>
  2470. </ul>
  2471. </section>
  2472. </section>
  2473. </section>
  2474. <div class="clearer"></div>
  2475. </div>
  2476. </div>
  2477. </div>
  2478. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  2479. <div class="sphinxsidebarwrapper">
  2480. <div>
  2481. <h3><a href="../contents.html">Table of Contents</a></h3>
  2482. <ul>
  2483. <li><a class="reference internal" href="#">What’s New In Python 3.3</a><ul>
  2484. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  2485. <li><a class="reference internal" href="#pep-405-virtual-environments">PEP 405: Virtual Environments</a></li>
  2486. <li><a class="reference internal" href="#pep-420-implicit-namespace-packages">PEP 420: Implicit Namespace Packages</a></li>
  2487. <li><a class="reference internal" href="#pep-3118-new-memoryview-implementation-and-buffer-protocol-documentation">PEP 3118: New memoryview implementation and buffer protocol documentation</a><ul>
  2488. <li><a class="reference internal" href="#features">Features</a></li>
  2489. <li><a class="reference internal" href="#api-changes">API changes</a></li>
  2490. </ul>
  2491. </li>
  2492. <li><a class="reference internal" href="#pep-393-flexible-string-representation">PEP 393: Flexible String Representation</a><ul>
  2493. <li><a class="reference internal" href="#functionality">Functionality</a></li>
  2494. <li><a class="reference internal" href="#performance-and-resource-usage">Performance and resource usage</a></li>
  2495. </ul>
  2496. </li>
  2497. <li><a class="reference internal" href="#pep-397-python-launcher-for-windows">PEP 397: Python Launcher for Windows</a></li>
  2498. <li><a class="reference internal" href="#pep-3151-reworking-the-os-and-io-exception-hierarchy">PEP 3151: Reworking the OS and IO exception hierarchy</a></li>
  2499. <li><a class="reference internal" href="#pep-380-syntax-for-delegating-to-a-subgenerator">PEP 380: Syntax for Delegating to a Subgenerator</a></li>
  2500. <li><a class="reference internal" href="#pep-409-suppressing-exception-context">PEP 409: Suppressing exception context</a></li>
  2501. <li><a class="reference internal" href="#pep-414-explicit-unicode-literals">PEP 414: Explicit Unicode literals</a></li>
  2502. <li><a class="reference internal" href="#pep-3155-qualified-name-for-classes-and-functions">PEP 3155: Qualified name for classes and functions</a></li>
  2503. <li><a class="reference internal" href="#pep-412-key-sharing-dictionary">PEP 412: Key-Sharing Dictionary</a></li>
  2504. <li><a class="reference internal" href="#pep-362-function-signature-object">PEP 362: Function Signature Object</a></li>
  2505. <li><a class="reference internal" href="#pep-421-adding-sys-implementation">PEP 421: Adding sys.implementation</a><ul>
  2506. <li><a class="reference internal" href="#simplenamespace">SimpleNamespace</a></li>
  2507. </ul>
  2508. </li>
  2509. <li><a class="reference internal" href="#using-importlib-as-the-implementation-of-import">Using importlib as the Implementation of Import</a><ul>
  2510. <li><a class="reference internal" href="#new-apis">New APIs</a></li>
  2511. <li><a class="reference internal" href="#visible-changes">Visible Changes</a></li>
  2512. </ul>
  2513. </li>
  2514. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  2515. <li><a class="reference internal" href="#a-finer-grained-import-lock">A Finer-Grained Import Lock</a></li>
  2516. <li><a class="reference internal" href="#builtin-functions-and-types">Builtin functions and types</a></li>
  2517. <li><a class="reference internal" href="#new-modules">New Modules</a><ul>
  2518. <li><a class="reference internal" href="#faulthandler">faulthandler</a></li>
  2519. <li><a class="reference internal" href="#ipaddress">ipaddress</a></li>
  2520. <li><a class="reference internal" href="#lzma">lzma</a></li>
  2521. </ul>
  2522. </li>
  2523. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  2524. <li><a class="reference internal" href="#abc">abc</a></li>
  2525. <li><a class="reference internal" href="#array">array</a></li>
  2526. <li><a class="reference internal" href="#base64">base64</a></li>
  2527. <li><a class="reference internal" href="#binascii">binascii</a></li>
  2528. <li><a class="reference internal" href="#bz2">bz2</a></li>
  2529. <li><a class="reference internal" href="#codecs">codecs</a></li>
  2530. <li><a class="reference internal" href="#collections">collections</a></li>
  2531. <li><a class="reference internal" href="#contextlib">contextlib</a></li>
  2532. <li><a class="reference internal" href="#crypt">crypt</a></li>
  2533. <li><a class="reference internal" href="#curses">curses</a></li>
  2534. <li><a class="reference internal" href="#datetime">datetime</a></li>
  2535. <li><a class="reference internal" href="#decimal">decimal</a><ul>
  2536. <li><a class="reference internal" href="#id1">Features</a></li>
  2537. <li><a class="reference internal" href="#id2">API changes</a></li>
  2538. </ul>
  2539. </li>
  2540. <li><a class="reference internal" href="#email">email</a><ul>
  2541. <li><a class="reference internal" href="#policy-framework">Policy Framework</a></li>
  2542. <li><a class="reference internal" href="#provisional-policy-with-new-header-api">Provisional Policy with New Header API</a></li>
  2543. <li><a class="reference internal" href="#other-api-changes">Other API Changes</a></li>
  2544. </ul>
  2545. </li>
  2546. <li><a class="reference internal" href="#ftplib">ftplib</a></li>
  2547. <li><a class="reference internal" href="#functools">functools</a></li>
  2548. <li><a class="reference internal" href="#gc">gc</a></li>
  2549. <li><a class="reference internal" href="#hmac">hmac</a></li>
  2550. <li><a class="reference internal" href="#http">http</a></li>
  2551. <li><a class="reference internal" href="#html">html</a></li>
  2552. <li><a class="reference internal" href="#imaplib">imaplib</a></li>
  2553. <li><a class="reference internal" href="#inspect">inspect</a></li>
  2554. <li><a class="reference internal" href="#io">io</a></li>
  2555. <li><a class="reference internal" href="#itertools">itertools</a></li>
  2556. <li><a class="reference internal" href="#logging">logging</a></li>
  2557. <li><a class="reference internal" href="#math">math</a></li>
  2558. <li><a class="reference internal" href="#mmap">mmap</a></li>
  2559. <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
  2560. <li><a class="reference internal" href="#nntplib">nntplib</a></li>
  2561. <li><a class="reference internal" href="#os">os</a></li>
  2562. <li><a class="reference internal" href="#pdb">pdb</a></li>
  2563. <li><a class="reference internal" href="#pickle">pickle</a></li>
  2564. <li><a class="reference internal" href="#pydoc">pydoc</a></li>
  2565. <li><a class="reference internal" href="#re">re</a></li>
  2566. <li><a class="reference internal" href="#sched">sched</a></li>
  2567. <li><a class="reference internal" href="#select">select</a></li>
  2568. <li><a class="reference internal" href="#shlex">shlex</a></li>
  2569. <li><a class="reference internal" href="#shutil">shutil</a></li>
  2570. <li><a class="reference internal" href="#signal">signal</a></li>
  2571. <li><a class="reference internal" href="#smtpd">smtpd</a></li>
  2572. <li><a class="reference internal" href="#smtplib">smtplib</a></li>
  2573. <li><a class="reference internal" href="#socket">socket</a></li>
  2574. <li><a class="reference internal" href="#socketserver">socketserver</a></li>
  2575. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  2576. <li><a class="reference internal" href="#ssl">ssl</a></li>
  2577. <li><a class="reference internal" href="#stat">stat</a></li>
  2578. <li><a class="reference internal" href="#struct">struct</a></li>
  2579. <li><a class="reference internal" href="#subprocess">subprocess</a></li>
  2580. <li><a class="reference internal" href="#sys">sys</a></li>
  2581. <li><a class="reference internal" href="#tarfile">tarfile</a></li>
  2582. <li><a class="reference internal" href="#tempfile">tempfile</a></li>
  2583. <li><a class="reference internal" href="#textwrap">textwrap</a></li>
  2584. <li><a class="reference internal" href="#threading">threading</a></li>
  2585. <li><a class="reference internal" href="#time">time</a></li>
  2586. <li><a class="reference internal" href="#types">types</a></li>
  2587. <li><a class="reference internal" href="#unittest">unittest</a></li>
  2588. <li><a class="reference internal" href="#urllib">urllib</a></li>
  2589. <li><a class="reference internal" href="#webbrowser">webbrowser</a></li>
  2590. <li><a class="reference internal" href="#xml-etree-elementtree">xml.etree.ElementTree</a></li>
  2591. <li><a class="reference internal" href="#zlib">zlib</a></li>
  2592. </ul>
  2593. </li>
  2594. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  2595. <li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
  2596. <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
  2597. <li><a class="reference internal" href="#unsupported-operating-systems">Unsupported Operating Systems</a></li>
  2598. <li><a class="reference internal" href="#deprecated-python-modules-functions-and-methods">Deprecated Python modules, functions and methods</a></li>
  2599. <li><a class="reference internal" href="#deprecated-functions-and-types-of-the-c-api">Deprecated functions and types of the C API</a></li>
  2600. <li><a class="reference internal" href="#deprecated-features">Deprecated features</a></li>
  2601. </ul>
  2602. </li>
  2603. <li><a class="reference internal" href="#porting-to-python-3-3">Porting to Python 3.3</a><ul>
  2604. <li><a class="reference internal" href="#porting-python-code">Porting Python code</a></li>
  2605. <li><a class="reference internal" href="#porting-c-code">Porting C code</a></li>
  2606. <li><a class="reference internal" href="#building-c-extensions">Building C extensions</a></li>
  2607. <li><a class="reference internal" href="#command-line-switch-changes">Command Line Switch Changes</a></li>
  2608. </ul>
  2609. </li>
  2610. </ul>
  2611. </li>
  2612. </ul>
  2613. </div>
  2614. <div>
  2615. <h4>Previous topic</h4>
  2616. <p class="topless"><a href="3.4.html"
  2617. title="previous chapter">What’s New In Python 3.4</a></p>
  2618. </div>
  2619. <div>
  2620. <h4>Next topic</h4>
  2621. <p class="topless"><a href="3.2.html"
  2622. title="next chapter">What’s New In Python 3.2</a></p>
  2623. </div>
  2624. <div role="note" aria-label="source link">
  2625. <h3>This Page</h3>
  2626. <ul class="this-page-menu">
  2627. <li><a href="../bugs.html">Report a Bug</a></li>
  2628. <li>
  2629. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.3.rst"
  2630. rel="nofollow">Show Source
  2631. </a>
  2632. </li>
  2633. </ul>
  2634. </div>
  2635. </div>
  2636. <div id="sidebarbutton" title="Collapse sidebar">
  2637. <span>«</span>
  2638. </div>
  2639. </div>
  2640. <div class="clearer"></div>
  2641. </div>
  2642. <div class="related" role="navigation" aria-label="related navigation">
  2643. <h3>Navigation</h3>
  2644. <ul>
  2645. <li class="right" style="margin-right: 10px">
  2646. <a href="../genindex.html" title="General Index"
  2647. >index</a></li>
  2648. <li class="right" >
  2649. <a href="../py-modindex.html" title="Python Module Index"
  2650. >modules</a> |</li>
  2651. <li class="right" >
  2652. <a href="3.2.html" title="What’s New In Python 3.2"
  2653. >next</a> |</li>
  2654. <li class="right" >
  2655. <a href="3.4.html" title="What’s New In Python 3.4"
  2656. >previous</a> |</li>
  2657. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  2658. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  2659. <li class="switchers">
  2660. <div class="language_switcher_placeholder"></div>
  2661. <div class="version_switcher_placeholder"></div>
  2662. </li>
  2663. <li>
  2664. </li>
  2665. <li id="cpython-language-and-version">
  2666. <a href="../index.html">3.12.3 Documentation</a> &#187;
  2667. </li>
  2668. <li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> &#187;</li>
  2669. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.3</a></li>
  2670. <li class="right">
  2671. <div class="inline-search" role="search">
  2672. <form class="inline-search" action="../search.html" method="get">
  2673. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  2674. <input type="submit" value="Go" />
  2675. </form>
  2676. </div>
  2677. |
  2678. </li>
  2679. <li class="right">
  2680. <label class="theme-selector-label">
  2681. Theme
  2682. <select class="theme-selector" oninput="activateTheme(this.value)">
  2683. <option value="auto" selected>Auto</option>
  2684. <option value="light">Light</option>
  2685. <option value="dark">Dark</option>
  2686. </select>
  2687. </label> |</li>
  2688. </ul>
  2689. </div>
  2690. <div class="footer">
  2691. &copy;
  2692. <a href="../copyright.html">
  2693. Copyright
  2694. </a>
  2695. 2001-2024, Python Software Foundation.
  2696. <br />
  2697. This page is licensed under the Python Software Foundation License Version 2.
  2698. <br />
  2699. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  2700. <br />
  2701. See <a href="/license.html">History and License</a> for more information.<br />
  2702. <br />
  2703. The Python Software Foundation is a non-profit corporation.
  2704. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  2705. <br />
  2706. <br />
  2707. Last updated on Apr 09, 2024 (13:47 UTC).
  2708. <a href="/bugs.html">Found a bug</a>?
  2709. <br />
  2710. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  2711. </div>
  2712. </body>
  2713. </html>
上海开阖软件有限公司 沪ICP备12045867号-1