gooderp18绿色标准版
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

2597 lines
299KB

  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.6" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/whatsnew/3.6.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Editors, Elvis Pranskevichus < elvis@magic.io>, Yury Selivanov < yury@magic.io>,. This article explains the new features in Python 3.6, compared to 3.5. Python 3.6 was released on December 23, 2016..." />
  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="Editors, Elvis Pranskevichus < elvis@magic.io>, Yury Selivanov < yury@magic.io>,. This article explains the new features in Python 3.6, compared to 3.5. Python 3.6 was released on December 23, 2016..." />
  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.6 &#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.5" href="3.5.html" />
  33. <link rel="prev" title="What’s New In Python 3.7" href="3.7.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/whatsnew/3.6.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.6</a><ul>
  86. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  87. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  88. <li><a class="reference internal" href="#pep-498-formatted-string-literals">PEP 498: Formatted string literals</a></li>
  89. <li><a class="reference internal" href="#pep-526-syntax-for-variable-annotations">PEP 526: Syntax for variable annotations</a></li>
  90. <li><a class="reference internal" href="#pep-515-underscores-in-numeric-literals">PEP 515: Underscores in Numeric Literals</a></li>
  91. <li><a class="reference internal" href="#pep-525-asynchronous-generators">PEP 525: Asynchronous Generators</a></li>
  92. <li><a class="reference internal" href="#pep-530-asynchronous-comprehensions">PEP 530: Asynchronous Comprehensions</a></li>
  93. <li><a class="reference internal" href="#pep-487-simpler-customization-of-class-creation">PEP 487: Simpler customization of class creation</a></li>
  94. <li><a class="reference internal" href="#pep-487-descriptor-protocol-enhancements">PEP 487: Descriptor Protocol Enhancements</a></li>
  95. <li><a class="reference internal" href="#pep-519-adding-a-file-system-path-protocol">PEP 519: Adding a file system path protocol</a></li>
  96. <li><a class="reference internal" href="#pep-495-local-time-disambiguation">PEP 495: Local Time Disambiguation</a></li>
  97. <li><a class="reference internal" href="#pep-529-change-windows-filesystem-encoding-to-utf-8">PEP 529: Change Windows filesystem encoding to UTF-8</a></li>
  98. <li><a class="reference internal" href="#pep-528-change-windows-console-encoding-to-utf-8">PEP 528: Change Windows console encoding to UTF-8</a></li>
  99. <li><a class="reference internal" href="#pep-520-preserving-class-attribute-definition-order">PEP 520: Preserving Class Attribute Definition Order</a></li>
  100. <li><a class="reference internal" href="#pep-468-preserving-keyword-argument-order">PEP 468: Preserving Keyword Argument Order</a></li>
  101. <li><a class="reference internal" href="#new-dict-implementation">New <span class="xref std std-ref">dict</span> implementation</a></li>
  102. <li><a class="reference internal" href="#pep-523-adding-a-frame-evaluation-api-to-cpython">PEP 523: Adding a frame evaluation API to CPython</a></li>
  103. <li><a class="reference internal" href="#pythonmalloc-environment-variable">PYTHONMALLOC environment variable</a></li>
  104. <li><a class="reference internal" href="#dtrace-and-systemtap-probing-support">DTrace and SystemTap probing support</a></li>
  105. </ul>
  106. </li>
  107. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  108. <li><a class="reference internal" href="#new-modules">New Modules</a><ul>
  109. <li><a class="reference internal" href="#secrets">secrets</a></li>
  110. </ul>
  111. </li>
  112. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  113. <li><a class="reference internal" href="#array">array</a></li>
  114. <li><a class="reference internal" href="#ast">ast</a></li>
  115. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  116. <li><a class="reference internal" href="#binascii">binascii</a></li>
  117. <li><a class="reference internal" href="#cmath">cmath</a></li>
  118. <li><a class="reference internal" href="#collections">collections</a></li>
  119. <li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li>
  120. <li><a class="reference internal" href="#contextlib">contextlib</a></li>
  121. <li><a class="reference internal" href="#datetime">datetime</a></li>
  122. <li><a class="reference internal" href="#decimal">decimal</a></li>
  123. <li><a class="reference internal" href="#distutils">distutils</a></li>
  124. <li><a class="reference internal" href="#email">email</a></li>
  125. <li><a class="reference internal" href="#encodings">encodings</a></li>
  126. <li><a class="reference internal" href="#enum">enum</a></li>
  127. <li><a class="reference internal" href="#faulthandler">faulthandler</a></li>
  128. <li><a class="reference internal" href="#fileinput">fileinput</a></li>
  129. <li><a class="reference internal" href="#hashlib">hashlib</a></li>
  130. <li><a class="reference internal" href="#http-client">http.client</a></li>
  131. <li><a class="reference internal" href="#idlelib-and-idle">idlelib and IDLE</a></li>
  132. <li><a class="reference internal" href="#importlib">importlib</a></li>
  133. <li><a class="reference internal" href="#inspect">inspect</a></li>
  134. <li><a class="reference internal" href="#json">json</a></li>
  135. <li><a class="reference internal" href="#logging">logging</a></li>
  136. <li><a class="reference internal" href="#math">math</a></li>
  137. <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
  138. <li><a class="reference internal" href="#os">os</a></li>
  139. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  140. <li><a class="reference internal" href="#pdb">pdb</a></li>
  141. <li><a class="reference internal" href="#pickle">pickle</a></li>
  142. <li><a class="reference internal" href="#pickletools">pickletools</a></li>
  143. <li><a class="reference internal" href="#pydoc">pydoc</a></li>
  144. <li><a class="reference internal" href="#random">random</a></li>
  145. <li><a class="reference internal" href="#re">re</a></li>
  146. <li><a class="reference internal" href="#readline">readline</a></li>
  147. <li><a class="reference internal" href="#rlcompleter">rlcompleter</a></li>
  148. <li><a class="reference internal" href="#shlex">shlex</a></li>
  149. <li><a class="reference internal" href="#site">site</a></li>
  150. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  151. <li><a class="reference internal" href="#socket">socket</a></li>
  152. <li><a class="reference internal" href="#socketserver">socketserver</a></li>
  153. <li><a class="reference internal" href="#ssl">ssl</a></li>
  154. <li><a class="reference internal" href="#statistics">statistics</a></li>
  155. <li><a class="reference internal" href="#struct">struct</a></li>
  156. <li><a class="reference internal" href="#subprocess">subprocess</a></li>
  157. <li><a class="reference internal" href="#sys">sys</a></li>
  158. <li><a class="reference internal" href="#telnetlib">telnetlib</a></li>
  159. <li><a class="reference internal" href="#time">time</a></li>
  160. <li><a class="reference internal" href="#timeit">timeit</a></li>
  161. <li><a class="reference internal" href="#tkinter">tkinter</a></li>
  162. <li><a class="reference internal" href="#traceback">traceback</a></li>
  163. <li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
  164. <li><a class="reference internal" href="#typing">typing</a></li>
  165. <li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
  166. <li><a class="reference internal" href="#unittest-mock">unittest.mock</a></li>
  167. <li><a class="reference internal" href="#urllib-request">urllib.request</a></li>
  168. <li><a class="reference internal" href="#urllib-robotparser">urllib.robotparser</a></li>
  169. <li><a class="reference internal" href="#venv">venv</a></li>
  170. <li><a class="reference internal" href="#warnings">warnings</a></li>
  171. <li><a class="reference internal" href="#winreg">winreg</a></li>
  172. <li><a class="reference internal" href="#winsound">winsound</a></li>
  173. <li><a class="reference internal" href="#xmlrpc-client">xmlrpc.client</a></li>
  174. <li><a class="reference internal" href="#zipfile">zipfile</a></li>
  175. <li><a class="reference internal" href="#zlib">zlib</a></li>
  176. </ul>
  177. </li>
  178. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  179. <li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
  180. <li><a class="reference internal" href="#other-improvements">Other Improvements</a></li>
  181. <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
  182. <li><a class="reference internal" href="#new-keywords">New Keywords</a></li>
  183. <li><a class="reference internal" href="#deprecated-python-behavior">Deprecated Python behavior</a></li>
  184. <li><a class="reference internal" href="#deprecated-python-modules-functions-and-methods">Deprecated Python modules, functions and methods</a><ul>
  185. <li><a class="reference internal" href="#asynchat">asynchat</a></li>
  186. <li><a class="reference internal" href="#asyncore">asyncore</a></li>
  187. <li><a class="reference internal" href="#dbm">dbm</a></li>
  188. <li><a class="reference internal" href="#id2">distutils</a></li>
  189. <li><a class="reference internal" href="#grp">grp</a></li>
  190. <li><a class="reference internal" href="#id3">importlib</a></li>
  191. <li><a class="reference internal" href="#id4">os</a></li>
  192. <li><a class="reference internal" href="#id5">re</a></li>
  193. <li><a class="reference internal" href="#id6">ssl</a></li>
  194. <li><a class="reference internal" href="#id7">tkinter</a></li>
  195. <li><a class="reference internal" href="#whatsnew36-venv">venv</a></li>
  196. </ul>
  197. </li>
  198. <li><a class="reference internal" href="#xml">xml</a></li>
  199. <li><a class="reference internal" href="#deprecated-functions-and-types-of-the-c-api">Deprecated functions and types of the C API</a></li>
  200. <li><a class="reference internal" href="#deprecated-build-options">Deprecated Build Options</a></li>
  201. </ul>
  202. </li>
  203. <li><a class="reference internal" href="#removed">Removed</a><ul>
  204. <li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
  205. </ul>
  206. </li>
  207. <li><a class="reference internal" href="#porting-to-python-3-6">Porting to Python 3.6</a><ul>
  208. <li><a class="reference internal" href="#changes-in-python-command-behavior">Changes in ‘python’ Command Behavior</a></li>
  209. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  210. <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
  211. <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
  212. </ul>
  213. </li>
  214. <li><a class="reference internal" href="#notable-changes-in-python-3-6-2">Notable changes in Python 3.6.2</a><ul>
  215. <li><a class="reference internal" href="#new-make-regen-all-build-target">New <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> build target</a></li>
  216. <li><a class="reference internal" href="#removal-of-make-touch-build-target">Removal of <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> build target</a></li>
  217. </ul>
  218. </li>
  219. <li><a class="reference internal" href="#notable-changes-in-python-3-6-4">Notable changes in Python 3.6.4</a></li>
  220. <li><a class="reference internal" href="#notable-changes-in-python-3-6-5">Notable changes in Python 3.6.5</a></li>
  221. <li><a class="reference internal" href="#notable-changes-in-python-3-6-7">Notable changes in Python 3.6.7</a></li>
  222. <li><a class="reference internal" href="#notable-changes-in-python-3-6-10">Notable changes in Python 3.6.10</a></li>
  223. <li><a class="reference internal" href="#notable-changes-in-python-3-6-13">Notable changes in Python 3.6.13</a></li>
  224. <li><a class="reference internal" href="#notable-changes-in-python-3-6-14">Notable changes in Python 3.6.14</a></li>
  225. </ul>
  226. </li>
  227. </ul>
  228. </div>
  229. <div>
  230. <h4>Previous topic</h4>
  231. <p class="topless"><a href="3.7.html"
  232. title="previous chapter">What’s New In Python 3.7</a></p>
  233. </div>
  234. <div>
  235. <h4>Next topic</h4>
  236. <p class="topless"><a href="3.5.html"
  237. title="next chapter">What’s New In Python 3.5</a></p>
  238. </div>
  239. <div role="note" aria-label="source link">
  240. <h3>This Page</h3>
  241. <ul class="this-page-menu">
  242. <li><a href="../bugs.html">Report a Bug</a></li>
  243. <li>
  244. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.6.rst"
  245. rel="nofollow">Show Source
  246. </a>
  247. </li>
  248. </ul>
  249. </div>
  250. </nav>
  251. </div>
  252. </div>
  253. <div class="related" role="navigation" aria-label="related navigation">
  254. <h3>Navigation</h3>
  255. <ul>
  256. <li class="right" style="margin-right: 10px">
  257. <a href="../genindex.html" title="General Index"
  258. accesskey="I">index</a></li>
  259. <li class="right" >
  260. <a href="../py-modindex.html" title="Python Module Index"
  261. >modules</a> |</li>
  262. <li class="right" >
  263. <a href="3.5.html" title="What’s New In Python 3.5"
  264. accesskey="N">next</a> |</li>
  265. <li class="right" >
  266. <a href="3.7.html" title="What’s New In Python 3.7"
  267. accesskey="P">previous</a> |</li>
  268. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  269. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  270. <li class="switchers">
  271. <div class="language_switcher_placeholder"></div>
  272. <div class="version_switcher_placeholder"></div>
  273. </li>
  274. <li>
  275. </li>
  276. <li id="cpython-language-and-version">
  277. <a href="../index.html">3.12.3 Documentation</a> &#187;
  278. </li>
  279. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">What’s New in Python</a> &#187;</li>
  280. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.6</a></li>
  281. <li class="right">
  282. <div class="inline-search" role="search">
  283. <form class="inline-search" action="../search.html" method="get">
  284. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  285. <input type="submit" value="Go" />
  286. </form>
  287. </div>
  288. |
  289. </li>
  290. <li class="right">
  291. <label class="theme-selector-label">
  292. Theme
  293. <select class="theme-selector" oninput="activateTheme(this.value)">
  294. <option value="auto" selected>Auto</option>
  295. <option value="light">Light</option>
  296. <option value="dark">Dark</option>
  297. </select>
  298. </label> |</li>
  299. </ul>
  300. </div>
  301. <div class="document">
  302. <div class="documentwrapper">
  303. <div class="bodywrapper">
  304. <div class="body" role="main">
  305. <section id="what-s-new-in-python-3-6">
  306. <h1>What’s New In Python 3.6<a class="headerlink" href="#what-s-new-in-python-3-6" title="Link to this heading">¶</a></h1>
  307. <dl class="field-list simple">
  308. <dt class="field-odd">Editors<span class="colon">:</span></dt>
  309. <dd class="field-odd"><p>Elvis Pranskevichus &lt;<a class="reference external" href="mailto:elvis&#37;&#52;&#48;magic&#46;io">elvis<span>&#64;</span>magic<span>&#46;</span>io</a>&gt;, Yury Selivanov &lt;<a class="reference external" href="mailto:yury&#37;&#52;&#48;magic&#46;io">yury<span>&#64;</span>magic<span>&#46;</span>io</a>&gt;</p>
  310. </dd>
  311. </dl>
  312. <p>This article explains the new features in Python 3.6, compared to 3.5.
  313. Python 3.6 was released on December 23, 2016.  See the
  314. <a class="reference external" href="https://docs.python.org/3.6/whatsnew/changelog.html">changelog</a> for a full
  315. list of changes.</p>
  316. <div class="admonition seealso">
  317. <p class="admonition-title">See also</p>
  318. <p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0494/"><strong>PEP 494</strong></a> - Python 3.6 Release Schedule</p>
  319. </div>
  320. <section id="summary-release-highlights">
  321. <h2>Summary – Release highlights<a class="headerlink" href="#summary-release-highlights" title="Link to this heading">¶</a></h2>
  322. <p>New syntax features:</p>
  323. <ul class="simple">
  324. <li><p><a class="reference internal" href="#whatsnew36-pep498"><span class="std std-ref">PEP 498</span></a>, formatted string literals.</p></li>
  325. <li><p><a class="reference internal" href="#whatsnew36-pep515"><span class="std std-ref">PEP 515</span></a>, underscores in numeric literals.</p></li>
  326. <li><p><a class="reference internal" href="#whatsnew36-pep526"><span class="std std-ref">PEP 526</span></a>, syntax for variable annotations.</p></li>
  327. <li><p><a class="reference internal" href="#whatsnew36-pep525"><span class="std std-ref">PEP 525</span></a>, asynchronous generators.</p></li>
  328. <li><p><a class="reference internal" href="#whatsnew36-pep530"><span class="std std-ref">PEP 530</span></a>: asynchronous comprehensions.</p></li>
  329. </ul>
  330. <p>New library modules:</p>
  331. <ul class="simple">
  332. <li><p><a class="reference internal" href="../library/secrets.html#module-secrets" title="secrets: Generate secure random numbers for managing secrets."><code class="xref py py-mod docutils literal notranslate"><span class="pre">secrets</span></code></a>: <a class="reference internal" href="#whatsnew36-pep506"><span class="std std-ref">PEP 506 – Adding A Secrets Module To The Standard Library</span></a>.</p></li>
  333. </ul>
  334. <p>CPython implementation improvements:</p>
  335. <ul class="simple">
  336. <li><p>The <a class="reference internal" href="../library/stdtypes.html#typesmapping"><span class="std std-ref">dict</span></a> type has been reimplemented to use
  337. a <a class="reference internal" href="#whatsnew36-compactdict"><span class="std std-ref">more compact representation</span></a>
  338. based on <a class="reference external" href="https://mail.python.org/pipermail/python-dev/2012-December/123028.html">a proposal by Raymond Hettinger</a>
  339. and similar to the <a class="reference external" href="https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html">PyPy dict implementation</a>. This resulted in dictionaries
  340. using 20% to 25% less memory when compared to Python 3.5.</p></li>
  341. <li><p>Customization of class creation has been simplified with the
  342. <a class="reference internal" href="#whatsnew36-pep487"><span class="std std-ref">new protocol</span></a>.</p></li>
  343. <li><p>The class attribute definition order is
  344. <a class="reference internal" href="#whatsnew36-pep520"><span class="std std-ref">now preserved</span></a>.</p></li>
  345. <li><p>The order of elements in <code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> now
  346. <a class="reference internal" href="#whatsnew36-pep468"><span class="std std-ref">corresponds to the order</span></a> in which keyword
  347. arguments were passed to the function.</p></li>
  348. <li><p>DTrace and SystemTap <a class="reference internal" href="#whatsnew36-tracing"><span class="std std-ref">probing support</span></a> has
  349. been added.</p></li>
  350. <li><p>The new <a class="reference internal" href="#whatsnew36-pythonmalloc"><span class="std std-ref">PYTHONMALLOC</span></a> environment variable
  351. can now be used to debug the interpreter memory allocation and access
  352. errors.</p></li>
  353. </ul>
  354. <p>Significant improvements in the standard library:</p>
  355. <ul class="simple">
  356. <li><p>The <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> module has received new features, significant
  357. usability and performance improvements, and a fair amount of bug fixes.
  358. Starting with Python 3.6 the <code class="docutils literal notranslate"><span class="pre">asyncio</span></code> module is no longer provisional
  359. and its API is considered stable.</p></li>
  360. <li><p>A new <a class="reference internal" href="#whatsnew36-pep519"><span class="std std-ref">file system path protocol</span></a> has been
  361. implemented to support <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like objects</span></a>.
  362. All standard library functions operating on paths have been updated to
  363. work with the new protocol.</p></li>
  364. <li><p>The <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> module has gained support for
  365. <a class="reference internal" href="#whatsnew36-pep495"><span class="std std-ref">Local Time Disambiguation</span></a>.</p></li>
  366. <li><p>The <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module received a number of
  367. <a class="reference internal" href="#whatsnew36-typing"><span class="std std-ref">improvements</span></a>.</p></li>
  368. <li><p>The <a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a> module has been significantly reworked
  369. and is now used to provide better output for <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a>
  370. as well as provide better diagnostics for memory allocation errors.
  371. See the <a class="reference internal" href="#whatsnew36-pythonmalloc"><span class="std std-ref">PYTHONMALLOC section</span></a> for more
  372. information.</p></li>
  373. </ul>
  374. <p>Security improvements:</p>
  375. <ul class="simple">
  376. <li><p>The new <a class="reference internal" href="../library/secrets.html#module-secrets" title="secrets: Generate secure random numbers for managing secrets."><code class="xref py py-mod docutils literal notranslate"><span class="pre">secrets</span></code></a> module has been added to simplify the generation of
  377. cryptographically strong pseudo-random numbers suitable for
  378. managing secrets such as account authentication, tokens, and similar.</p></li>
  379. <li><p>On Linux, <a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.urandom()</span></code></a> now blocks until the system urandom entropy
  380. pool is initialized to increase the security. See the <span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0524/"><strong>PEP 524</strong></a> for the
  381. rationale.</p></li>
  382. <li><p>The <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> and <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> modules now support OpenSSL 1.1.0.</p></li>
  383. <li><p>The default settings and feature set of 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 have been
  384. improved.</p></li>
  385. <li><p>The <a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> module received support for the BLAKE2, SHA-3 and SHAKE
  386. hash algorithms and the <a class="reference internal" href="../library/hashlib.html#hashlib.scrypt" title="hashlib.scrypt"><code class="xref py py-func docutils literal notranslate"><span class="pre">scrypt()</span></code></a> key derivation function.</p></li>
  387. </ul>
  388. <p>Windows improvements:</p>
  389. <ul class="simple">
  390. <li><p><a class="reference internal" href="#whatsnew36-pep528"><span class="std std-ref">PEP 528</span></a> and <a class="reference internal" href="#whatsnew36-pep529"><span class="std std-ref">PEP 529</span></a>,
  391. Windows filesystem and console encoding changed to UTF-8.</p></li>
  392. <li><p>The <code class="docutils literal notranslate"><span class="pre">py.exe</span></code> launcher, when used interactively, no longer prefers
  393. Python 2 over Python 3 when the user doesn’t specify a version (via
  394. command line arguments or a config file). Handling of shebang lines
  395. remains unchanged - “python” refers to Python 2 in that case.</p></li>
  396. <li><p><code class="docutils literal notranslate"><span class="pre">python.exe</span></code> and <code class="docutils literal notranslate"><span class="pre">pythonw.exe</span></code> have been marked as long-path aware,
  397. which means that the 260 character path limit may no longer apply.
  398. See <a class="reference internal" href="../using/windows.html#max-path"><span class="std std-ref">removing the MAX_PATH limitation</span></a> for details.</p></li>
  399. <li><p>A <code class="docutils literal notranslate"><span class="pre">._pth</span></code> file can be added to force isolated mode and fully specify
  400. all search paths to avoid registry and environment lookup. See
  401. <a class="reference internal" href="../using/windows.html#windows-finding-modules"><span class="std std-ref">the documentation</span></a> for more information.</p></li>
  402. <li><p>A <code class="docutils literal notranslate"><span class="pre">python36.zip</span></code> file now works as a landmark to infer
  403. <span class="target" id="index-2"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHOME</span></code></a>. See <a class="reference internal" href="../using/windows.html#windows-finding-modules"><span class="std std-ref">the documentation</span></a> for
  404. more information.</p></li>
  405. </ul>
  406. </section>
  407. <section id="new-features">
  408. <h2>New Features<a class="headerlink" href="#new-features" title="Link to this heading">¶</a></h2>
  409. <section id="pep-498-formatted-string-literals">
  410. <span id="whatsnew36-pep498"></span><h3>PEP 498: Formatted string literals<a class="headerlink" href="#pep-498-formatted-string-literals" title="Link to this heading">¶</a></h3>
  411. <p><span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0498/"><strong>PEP 498</strong></a> introduces a new kind of string literals: <em>f-strings</em>, or
  412. <a class="reference internal" href="../reference/lexical_analysis.html#f-strings"><span class="std std-ref">formatted string literals</span></a>.</p>
  413. <p>Formatted string literals are prefixed with <code class="docutils literal notranslate"><span class="pre">'f'</span></code> and are similar to
  414. the format strings accepted by <a class="reference internal" href="../library/stdtypes.html#str.format" title="str.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">str.format()</span></code></a>. They contain replacement
  415. fields surrounded by curly braces. The replacement fields are expressions,
  416. which are evaluated at run time, and then formatted using the
  417. <a class="reference internal" href="../library/functions.html#format" title="format"><code class="xref py py-func docutils literal notranslate"><span class="pre">format()</span></code></a> protocol:</p>
  418. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Fred&quot;</span>
  419. <span class="gp">&gt;&gt;&gt; </span><span class="sa">f</span><span class="s2">&quot;He said his name is </span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">.&quot;</span>
  420. <span class="go">&#39;He said his name is Fred.&#39;</span>
  421. <span class="gp">&gt;&gt;&gt; </span><span class="n">width</span> <span class="o">=</span> <span class="mi">10</span>
  422. <span class="gp">&gt;&gt;&gt; </span><span class="n">precision</span> <span class="o">=</span> <span class="mi">4</span>
  423. <span class="gp">&gt;&gt;&gt; </span><span class="n">value</span> <span class="o">=</span> <span class="n">decimal</span><span class="o">.</span><span class="n">Decimal</span><span class="p">(</span><span class="s2">&quot;12.34567&quot;</span><span class="p">)</span>
  424. <span class="gp">&gt;&gt;&gt; </span><span class="sa">f</span><span class="s2">&quot;result: </span><span class="si">{</span><span class="n">value</span><span class="si">:{</span><span class="n">width</span><span class="si">}</span><span class="s2">.</span><span class="si">{</span><span class="n">precision</span><span class="si">}}</span><span class="s2">&quot;</span> <span class="c1"># nested fields</span>
  425. <span class="go">&#39;result: 12.35&#39;</span>
  426. </pre></div>
  427. </div>
  428. <div class="admonition seealso">
  429. <p class="admonition-title">See also</p>
  430. <dl class="simple">
  431. <dt><span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0498/"><strong>PEP 498</strong></a> – Literal String Interpolation.</dt><dd><p>PEP written and implemented by Eric V. Smith.</p>
  432. </dd>
  433. </dl>
  434. <p><a class="reference internal" href="../reference/lexical_analysis.html#f-strings"><span class="std std-ref">Feature documentation</span></a>.</p>
  435. </div>
  436. </section>
  437. <section id="pep-526-syntax-for-variable-annotations">
  438. <span id="whatsnew36-pep526"></span><h3>PEP 526: Syntax for variable annotations<a class="headerlink" href="#pep-526-syntax-for-variable-annotations" title="Link to this heading">¶</a></h3>
  439. <p><span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0484/"><strong>PEP 484</strong></a> introduced the standard for type annotations of function
  440. parameters, a.k.a. type hints. This PEP adds syntax to Python for annotating
  441. the types of variables including class variables and instance variables:</p>
  442. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">primes</span><span class="p">:</span> <span class="n">List</span><span class="p">[</span><span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
  443. <span class="n">captain</span><span class="p">:</span> <span class="nb">str</span> <span class="c1"># Note: no initial value!</span>
  444. <span class="k">class</span> <span class="nc">Starship</span><span class="p">:</span>
  445. <span class="n">stats</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">int</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
  446. </pre></div>
  447. </div>
  448. <p>Just as for function annotations, the Python interpreter does not attach any
  449. particular meaning to variable annotations and only stores them in the
  450. <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code> attribute of a class or module.</p>
  451. <p>In contrast to variable declarations in statically typed languages,
  452. the goal of annotation syntax is to provide an easy way to specify structured
  453. type metadata for third party tools and libraries via the abstract syntax tree
  454. and the <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code> attribute.</p>
  455. <div class="admonition seealso">
  456. <p class="admonition-title">See also</p>
  457. <dl class="simple">
  458. <dt><span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-0526/"><strong>PEP 526</strong></a> – Syntax for variable annotations.</dt><dd><p>PEP written by Ryan Gonzalez, Philip House, Ivan Levkivskyi, Lisa Roach,
  459. and Guido van Rossum. Implemented by Ivan Levkivskyi.</p>
  460. </dd>
  461. </dl>
  462. <p>Tools that use or will use the new syntax:
  463. <a class="reference external" href="https://www.mypy-lang.org/">mypy</a>,
  464. <a class="reference external" href="https://github.com/google/pytype">pytype</a>, PyCharm, etc.</p>
  465. </div>
  466. </section>
  467. <section id="pep-515-underscores-in-numeric-literals">
  468. <span id="whatsnew36-pep515"></span><h3>PEP 515: Underscores in Numeric Literals<a class="headerlink" href="#pep-515-underscores-in-numeric-literals" title="Link to this heading">¶</a></h3>
  469. <p><span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0515/"><strong>PEP 515</strong></a> adds the ability to use underscores in numeric literals for
  470. improved readability. For example:</p>
  471. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="mi">1_000_000_000_000_000</span>
  472. <span class="go">1000000000000000</span>
  473. <span class="gp">&gt;&gt;&gt; </span><span class="mh">0x_FF_FF_FF_FF</span>
  474. <span class="go">4294967295</span>
  475. </pre></div>
  476. </div>
  477. <p>Single underscores are allowed between digits and after any base
  478. specifier. Leading, trailing, or multiple underscores in a row are not
  479. allowed.</p>
  480. <p>The <a class="reference internal" href="../library/string.html#formatspec"><span class="std std-ref">string formatting</span></a> language also now has support
  481. for the <code class="docutils literal notranslate"><span class="pre">'_'</span></code> option to signal the use of an underscore for a thousands
  482. separator for floating point presentation types and for integer
  483. presentation type <code class="docutils literal notranslate"><span class="pre">'d'</span></code>. For integer presentation types <code class="docutils literal notranslate"><span class="pre">'b'</span></code>,
  484. <code class="docutils literal notranslate"><span class="pre">'o'</span></code>, <code class="docutils literal notranslate"><span class="pre">'x'</span></code>, and <code class="docutils literal notranslate"><span class="pre">'X'</span></code>, underscores will be inserted every 4
  485. digits:</p>
  486. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;{:_}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mi">1000000</span><span class="p">)</span>
  487. <span class="go">&#39;1_000_000&#39;</span>
  488. <span class="gp">&gt;&gt;&gt; </span><span class="s1">&#39;{:_x}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="mh">0xFFFFFFFF</span><span class="p">)</span>
  489. <span class="go">&#39;ffff_ffff&#39;</span>
  490. </pre></div>
  491. </div>
  492. <div class="admonition seealso">
  493. <p class="admonition-title">See also</p>
  494. <dl class="simple">
  495. <dt><span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0515/"><strong>PEP 515</strong></a> – Underscores in Numeric Literals</dt><dd><p>PEP written by Georg Brandl and Serhiy Storchaka.</p>
  496. </dd>
  497. </dl>
  498. </div>
  499. </section>
  500. <section id="pep-525-asynchronous-generators">
  501. <span id="whatsnew36-pep525"></span><h3>PEP 525: Asynchronous Generators<a class="headerlink" href="#pep-525-asynchronous-generators" title="Link to this heading">¶</a></h3>
  502. <p><span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0492/"><strong>PEP 492</strong></a> introduced support for native coroutines and <code class="docutils literal notranslate"><span class="pre">async</span></code> / <code class="docutils literal notranslate"><span class="pre">await</span></code>
  503. syntax to Python 3.5. A notable limitation of the Python 3.5 implementation
  504. is that it was not possible to use <code class="docutils literal notranslate"><span class="pre">await</span></code> and <code class="docutils literal notranslate"><span class="pre">yield</span></code> in the same
  505. function body. In Python 3.6 this restriction has been lifted, making it
  506. possible to define <em>asynchronous generators</em>:</p>
  507. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">async</span> <span class="k">def</span> <span class="nf">ticker</span><span class="p">(</span><span class="n">delay</span><span class="p">,</span> <span class="n">to</span><span class="p">):</span>
  508. <span class="w"> </span><span class="sd">&quot;&quot;&quot;Yield numbers from 0 to *to* every *delay* seconds.&quot;&quot;&quot;</span>
  509. <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="n">to</span><span class="p">):</span>
  510. <span class="k">yield</span> <span class="n">i</span>
  511. <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">delay</span><span class="p">)</span>
  512. </pre></div>
  513. </div>
  514. <p>The new syntax allows for faster and more concise code.</p>
  515. <div class="admonition seealso">
  516. <p class="admonition-title">See also</p>
  517. <dl class="simple">
  518. <dt><span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0525/"><strong>PEP 525</strong></a> – Asynchronous Generators</dt><dd><p>PEP written and implemented by Yury Selivanov.</p>
  519. </dd>
  520. </dl>
  521. </div>
  522. </section>
  523. <section id="pep-530-asynchronous-comprehensions">
  524. <span id="whatsnew36-pep530"></span><h3>PEP 530: Asynchronous Comprehensions<a class="headerlink" href="#pep-530-asynchronous-comprehensions" title="Link to this heading">¶</a></h3>
  525. <p><span class="target" id="index-11"></span><a class="pep reference external" href="https://peps.python.org/pep-0530/"><strong>PEP 530</strong></a> adds support for using <code class="docutils literal notranslate"><span class="pre">async</span> <span class="pre">for</span></code> in list, set, dict
  526. comprehensions and generator expressions:</p>
  527. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">result</span> <span class="o">=</span> <span class="p">[</span><span class="n">i</span> <span class="k">async</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">aiter</span><span class="p">()</span> <span class="k">if</span> <span class="n">i</span> <span class="o">%</span> <span class="mi">2</span><span class="p">]</span>
  528. </pre></div>
  529. </div>
  530. <p>Additionally, <code class="docutils literal notranslate"><span class="pre">await</span></code> expressions are supported in all kinds
  531. of comprehensions:</p>
  532. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">result</span> <span class="o">=</span> <span class="p">[</span><span class="k">await</span> <span class="n">fun</span><span class="p">()</span> <span class="k">for</span> <span class="n">fun</span> <span class="ow">in</span> <span class="n">funcs</span> <span class="k">if</span> <span class="k">await</span> <span class="n">condition</span><span class="p">()]</span>
  533. </pre></div>
  534. </div>
  535. <div class="admonition seealso">
  536. <p class="admonition-title">See also</p>
  537. <dl class="simple">
  538. <dt><span class="target" id="index-12"></span><a class="pep reference external" href="https://peps.python.org/pep-0530/"><strong>PEP 530</strong></a> – Asynchronous Comprehensions</dt><dd><p>PEP written and implemented by Yury Selivanov.</p>
  539. </dd>
  540. </dl>
  541. </div>
  542. </section>
  543. <section id="pep-487-simpler-customization-of-class-creation">
  544. <span id="whatsnew36-pep487"></span><h3>PEP 487: Simpler customization of class creation<a class="headerlink" href="#pep-487-simpler-customization-of-class-creation" title="Link to this heading">¶</a></h3>
  545. <p>It is now possible to customize subclass creation without using a metaclass.
  546. The new <code class="docutils literal notranslate"><span class="pre">__init_subclass__</span></code> classmethod will be called on the base class
  547. whenever a new subclass is created:</p>
  548. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">PluginBase</span><span class="p">:</span>
  549. <span class="n">subclasses</span> <span class="o">=</span> <span class="p">[]</span>
  550. <span class="k">def</span> <span class="nf">__init_subclass__</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
  551. <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__init_subclass__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
  552. <span class="bp">cls</span><span class="o">.</span><span class="n">subclasses</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">cls</span><span class="p">)</span>
  553. <span class="k">class</span> <span class="nc">Plugin1</span><span class="p">(</span><span class="n">PluginBase</span><span class="p">):</span>
  554. <span class="k">pass</span>
  555. <span class="k">class</span> <span class="nc">Plugin2</span><span class="p">(</span><span class="n">PluginBase</span><span class="p">):</span>
  556. <span class="k">pass</span>
  557. </pre></div>
  558. </div>
  559. <p>In order to allow zero-argument <a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a> calls to work correctly from
  560. <a class="reference internal" href="../reference/datamodel.html#object.__init_subclass__" title="object.__init_subclass__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__init_subclass__()</span></code></a> implementations, custom metaclasses must
  561. ensure that the new <code class="docutils literal notranslate"><span class="pre">__classcell__</span></code> namespace entry is propagated to
  562. <code class="docutils literal notranslate"><span class="pre">type.__new__</span></code> (as described in <a class="reference internal" href="../reference/datamodel.html#class-object-creation"><span class="std std-ref">Creating the class object</span></a>).</p>
  563. <div class="admonition seealso">
  564. <p class="admonition-title">See also</p>
  565. <dl class="simple">
  566. <dt><span class="target" id="index-13"></span><a class="pep reference external" href="https://peps.python.org/pep-0487/"><strong>PEP 487</strong></a> – Simpler customization of class creation</dt><dd><p>PEP written and implemented by Martin Teichmann.</p>
  567. </dd>
  568. </dl>
  569. <p><a class="reference internal" href="../reference/datamodel.html#class-customization"><span class="std std-ref">Feature documentation</span></a></p>
  570. </div>
  571. </section>
  572. <section id="pep-487-descriptor-protocol-enhancements">
  573. <span id="whatsnew36-pep487-descriptors"></span><h3>PEP 487: Descriptor Protocol Enhancements<a class="headerlink" href="#pep-487-descriptor-protocol-enhancements" title="Link to this heading">¶</a></h3>
  574. <p><span class="target" id="index-14"></span><a class="pep reference external" href="https://peps.python.org/pep-0487/"><strong>PEP 487</strong></a> extends the descriptor protocol to include the new optional
  575. <a class="reference internal" href="../reference/datamodel.html#object.__set_name__" title="object.__set_name__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__set_name__()</span></code></a> method. Whenever a new class is defined, the new
  576. method will be called on all descriptors included in the definition, providing
  577. them with a reference to the class being defined and the name given to the
  578. descriptor within the class namespace. In other words, instances of
  579. descriptors can now know the attribute name of the descriptor in the
  580. owner class:</p>
  581. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">IntField</span><span class="p">:</span>
  582. <span class="k">def</span> <span class="fm">__get__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">instance</span><span class="p">,</span> <span class="n">owner</span><span class="p">):</span>
  583. <span class="k">return</span> <span class="n">instance</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">]</span>
  584. <span class="k">def</span> <span class="fm">__set__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">instance</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
  585. <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
  586. <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;expecting integer in </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">)</span>
  587. <span class="n">instance</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
  588. <span class="c1"># this is the new initializer:</span>
  589. <span class="k">def</span> <span class="nf">__set_name__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">owner</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
  590. <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
  591. <span class="k">class</span> <span class="nc">Model</span><span class="p">:</span>
  592. <span class="n">int_field</span> <span class="o">=</span> <span class="n">IntField</span><span class="p">()</span>
  593. </pre></div>
  594. </div>
  595. <div class="admonition seealso">
  596. <p class="admonition-title">See also</p>
  597. <dl class="simple">
  598. <dt><span class="target" id="index-15"></span><a class="pep reference external" href="https://peps.python.org/pep-0487/"><strong>PEP 487</strong></a> – Simpler customization of class creation</dt><dd><p>PEP written and implemented by Martin Teichmann.</p>
  599. </dd>
  600. </dl>
  601. <p><a class="reference internal" href="../reference/datamodel.html#descriptors"><span class="std std-ref">Feature documentation</span></a></p>
  602. </div>
  603. </section>
  604. <section id="pep-519-adding-a-file-system-path-protocol">
  605. <span id="whatsnew36-pep519"></span><h3>PEP 519: Adding a file system path protocol<a class="headerlink" href="#pep-519-adding-a-file-system-path-protocol" title="Link to this heading">¶</a></h3>
  606. <p>File system paths have historically been represented as <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>
  607. or <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> objects. This has led to people who write code which
  608. operate on file system paths to assume that such objects are only one
  609. of those two types (an <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a> representing a file descriptor
  610. does not count as that is not a file path). Unfortunately that
  611. assumption prevents alternative object representations of file system
  612. paths like <a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> from working with pre-existing code,
  613. including Python’s standard library.</p>
  614. <p>To fix this situation, a new interface represented by
  615. <a class="reference internal" href="../library/os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a> has been defined. By implementing the
  616. <a class="reference internal" href="../library/os.html#os.PathLike.__fspath__" title="os.PathLike.__fspath__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__fspath__()</span></code></a> method, an object signals that it
  617. represents a path. An object can then provide a low-level
  618. representation of a file system path as a <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> or
  619. <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> object. This means an object is considered
  620. <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like</span></a> if it implements
  621. <a class="reference internal" href="../library/os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a> or is a <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> or <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> object
  622. which represents a file system path. Code can use <a class="reference internal" href="../library/os.html#os.fspath" title="os.fspath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fspath()</span></code></a>,
  623. <a class="reference internal" href="../library/os.html#os.fsdecode" title="os.fsdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsdecode()</span></code></a>, or <a class="reference internal" href="../library/os.html#os.fsencode" title="os.fsencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsencode()</span></code></a> to explicitly get a
  624. <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> and/or <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> representation of a path-like
  625. object.</p>
  626. <p>The built-in <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> function has been updated to accept
  627. <a class="reference internal" href="../library/os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a> objects, as have all relevant functions in the
  628. <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> and <a class="reference internal" href="../library/os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> modules, and most other functions and
  629. classes in the standard library. The <a class="reference internal" href="../library/os.html#os.DirEntry" title="os.DirEntry"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.DirEntry</span></code></a> class
  630. and relevant classes in <a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> have also been updated to
  631. implement <a class="reference internal" href="../library/os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a>.</p>
  632. <p>The hope is that updating the fundamental functions for operating
  633. on file system paths will lead to third-party code to implicitly
  634. support all <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like objects</span></a> without any
  635. code changes, or at least very minimal ones (e.g. calling
  636. <a class="reference internal" href="../library/os.html#os.fspath" title="os.fspath"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fspath()</span></code></a> at the beginning of code before operating on a
  637. path-like object).</p>
  638. <p>Here are some examples of how the new interface allows for
  639. <a class="reference internal" href="../library/pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">pathlib.Path</span></code></a> to be used more easily and transparently with
  640. pre-existing code:</p>
  641. <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">pathlib</span>
  642. <span class="gp">&gt;&gt;&gt; </span><span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s2">&quot;README&quot;</span><span class="p">))</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
  643. <span class="gp">... </span> <span class="n">contents</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
  644. <span class="gp">...</span>
  645. <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">os.path</span>
  646. <span class="gp">&gt;&gt;&gt; </span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s2">&quot;some_file.txt&quot;</span><span class="p">))</span>
  647. <span class="go">(&#39;some_file&#39;, &#39;.txt&#39;)</span>
  648. <span class="gp">&gt;&gt;&gt; </span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s2">&quot;/a/b&quot;</span><span class="p">,</span> <span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s2">&quot;c&quot;</span><span class="p">))</span>
  649. <span class="go">&#39;/a/b/c&#39;</span>
  650. <span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">os</span>
  651. <span class="gp">&gt;&gt;&gt; </span><span class="n">os</span><span class="o">.</span><span class="n">fspath</span><span class="p">(</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s2">&quot;some_file.txt&quot;</span><span class="p">))</span>
  652. <span class="go">&#39;some_file.txt&#39;</span>
  653. </pre></div>
  654. </div>
  655. <p>(Implemented by Brett Cannon, Ethan Furman, Dusty Phillips, and Jelle Zijlstra.)</p>
  656. <div class="admonition seealso">
  657. <p class="admonition-title">See also</p>
  658. <dl class="simple">
  659. <dt><span class="target" id="index-16"></span><a class="pep reference external" href="https://peps.python.org/pep-0519/"><strong>PEP 519</strong></a> – Adding a file system path protocol</dt><dd><p>PEP written by Brett Cannon and Koos Zevenhoven.</p>
  660. </dd>
  661. </dl>
  662. </div>
  663. </section>
  664. <section id="pep-495-local-time-disambiguation">
  665. <span id="whatsnew36-pep495"></span><h3>PEP 495: Local Time Disambiguation<a class="headerlink" href="#pep-495-local-time-disambiguation" title="Link to this heading">¶</a></h3>
  666. <p>In most world locations, there have been and will be times when local clocks
  667. are moved back. In those times, intervals are introduced in which local
  668. clocks show the same time twice in the same day. In these situations, the
  669. information displayed on a local clock (or stored in a Python datetime
  670. instance) is insufficient to identify a particular moment in time.</p>
  671. <p><span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0495/"><strong>PEP 495</strong></a> adds the new <em>fold</em> attribute to instances of
  672. <a class="reference internal" href="../library/datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.datetime</span></code></a> and <a class="reference internal" href="../library/datetime.html#datetime.time" title="datetime.time"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime.time</span></code></a> classes to differentiate
  673. between two moments in time for which local times are the same:</p>
  674. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">u0</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">(</span><span class="mi">2016</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="n">tzinfo</span><span class="o">=</span><span class="n">timezone</span><span class="o">.</span><span class="n">utc</span><span class="p">)</span>
  675. <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>
  676. <span class="gp">... </span> <span class="n">u</span> <span class="o">=</span> <span class="n">u0</span> <span class="o">+</span> <span class="n">i</span><span class="o">*</span><span class="n">HOUR</span>
  677. <span class="gp">... </span> <span class="n">t</span> <span class="o">=</span> <span class="n">u</span><span class="o">.</span><span class="n">astimezone</span><span class="p">(</span><span class="n">Eastern</span><span class="p">)</span>
  678. <span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">u</span><span class="o">.</span><span class="n">time</span><span class="p">(),</span> <span class="s1">&#39;UTC =&#39;</span><span class="p">,</span> <span class="n">t</span><span class="o">.</span><span class="n">time</span><span class="p">(),</span> <span class="n">t</span><span class="o">.</span><span class="n">tzname</span><span class="p">(),</span> <span class="n">t</span><span class="o">.</span><span class="n">fold</span><span class="p">)</span>
  679. <span class="gp">...</span>
  680. <span class="go">04:00:00 UTC = 00:00:00 EDT 0</span>
  681. <span class="go">05:00:00 UTC = 01:00:00 EDT 0</span>
  682. <span class="go">06:00:00 UTC = 01:00:00 EST 1</span>
  683. <span class="go">07:00:00 UTC = 02:00:00 EST 0</span>
  684. </pre></div>
  685. </div>
  686. <p>The values of the <a class="reference internal" href="../library/datetime.html#datetime.datetime.fold" title="datetime.datetime.fold"><code class="xref py py-attr docutils literal notranslate"><span class="pre">fold</span></code></a> attribute have the
  687. value <code class="docutils literal notranslate"><span class="pre">0</span></code> for all instances except those that represent the second
  688. (chronologically) moment in time in an ambiguous case.</p>
  689. <div class="admonition seealso">
  690. <p class="admonition-title">See also</p>
  691. <dl class="simple">
  692. <dt><span class="target" id="index-18"></span><a class="pep reference external" href="https://peps.python.org/pep-0495/"><strong>PEP 495</strong></a> – Local Time Disambiguation</dt><dd><p>PEP written by Alexander Belopolsky and Tim Peters, implementation
  693. by Alexander Belopolsky.</p>
  694. </dd>
  695. </dl>
  696. </div>
  697. </section>
  698. <section id="pep-529-change-windows-filesystem-encoding-to-utf-8">
  699. <span id="whatsnew36-pep529"></span><h3>PEP 529: Change Windows filesystem encoding to UTF-8<a class="headerlink" href="#pep-529-change-windows-filesystem-encoding-to-utf-8" title="Link to this heading">¶</a></h3>
  700. <p>Representing filesystem paths is best performed with str (Unicode) rather than
  701. bytes. However, there are some situations where using bytes is sufficient and
  702. correct.</p>
  703. <p>Prior to Python 3.6, data loss could result when using bytes paths on Windows.
  704. With this change, using bytes to represent paths is now supported on Windows,
  705. provided those bytes are encoded with the encoding returned by
  706. <a class="reference internal" href="../library/sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a>, which now defaults to <code class="docutils literal notranslate"><span class="pre">'utf-8'</span></code>.</p>
  707. <p>Applications that do not use str to represent paths should use
  708. <a class="reference internal" href="../library/os.html#os.fsencode" title="os.fsencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsencode()</span></code></a> and <a class="reference internal" href="../library/os.html#os.fsdecode" title="os.fsdecode"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.fsdecode()</span></code></a> to ensure their bytes are
  709. correctly encoded. To revert to the previous behaviour, set
  710. <span class="target" id="index-19"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONLEGACYWINDOWSFSENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONLEGACYWINDOWSFSENCODING</span></code></a> or call
  711. <a class="reference internal" href="../library/sys.html#sys._enablelegacywindowsfsencoding" title="sys._enablelegacywindowsfsencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys._enablelegacywindowsfsencoding()</span></code></a>.</p>
  712. <p>See <span class="target" id="index-20"></span><a class="pep reference external" href="https://peps.python.org/pep-0529/"><strong>PEP 529</strong></a> for more information and discussion of code modifications that
  713. may be required.</p>
  714. </section>
  715. <section id="pep-528-change-windows-console-encoding-to-utf-8">
  716. <span id="whatsnew36-pep528"></span><h3>PEP 528: Change Windows console encoding to UTF-8<a class="headerlink" href="#pep-528-change-windows-console-encoding-to-utf-8" title="Link to this heading">¶</a></h3>
  717. <p>The default console on Windows will now accept all Unicode characters and
  718. provide correctly read str objects to Python code. <code class="docutils literal notranslate"><span class="pre">sys.stdin</span></code>,
  719. <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code> and <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> now default to utf-8 encoding.</p>
  720. <p>This change only applies when using an interactive console, and not when
  721. redirecting files or pipes. To revert to the previous behaviour for interactive
  722. console use, set <span class="target" id="index-21"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONLEGACYWINDOWSSTDIO"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONLEGACYWINDOWSSTDIO</span></code></a>.</p>
  723. <div class="admonition seealso">
  724. <p class="admonition-title">See also</p>
  725. <dl class="simple">
  726. <dt><span class="target" id="index-22"></span><a class="pep reference external" href="https://peps.python.org/pep-0528/"><strong>PEP 528</strong></a> – Change Windows console encoding to UTF-8</dt><dd><p>PEP written and implemented by Steve Dower.</p>
  727. </dd>
  728. </dl>
  729. </div>
  730. </section>
  731. <section id="pep-520-preserving-class-attribute-definition-order">
  732. <span id="whatsnew36-pep520"></span><h3>PEP 520: Preserving Class Attribute Definition Order<a class="headerlink" href="#pep-520-preserving-class-attribute-definition-order" title="Link to this heading">¶</a></h3>
  733. <p>Attributes in a class definition body have a natural ordering: the same
  734. order in which the names appear in the source. This order is now
  735. preserved in the new class’s <a class="reference internal" href="../library/stdtypes.html#object.__dict__" title="object.__dict__"><code class="xref py py-attr docutils literal notranslate"><span class="pre">__dict__</span></code></a> attribute.</p>
  736. <p>Also, the effective default class <em>execution</em> namespace (returned from
  737. <a class="reference internal" href="../reference/datamodel.html#prepare"><span class="std std-ref">type.__prepare__()</span></a>) is now an insertion-order-preserving
  738. mapping.</p>
  739. <div class="admonition seealso">
  740. <p class="admonition-title">See also</p>
  741. <dl class="simple">
  742. <dt><span class="target" id="index-23"></span><a class="pep reference external" href="https://peps.python.org/pep-0520/"><strong>PEP 520</strong></a> – Preserving Class Attribute Definition Order</dt><dd><p>PEP written and implemented by Eric Snow.</p>
  743. </dd>
  744. </dl>
  745. </div>
  746. </section>
  747. <section id="pep-468-preserving-keyword-argument-order">
  748. <span id="whatsnew36-pep468"></span><h3>PEP 468: Preserving Keyword Argument Order<a class="headerlink" href="#pep-468-preserving-keyword-argument-order" title="Link to this heading">¶</a></h3>
  749. <p><code class="docutils literal notranslate"><span class="pre">**kwargs</span></code> in a function signature is now guaranteed to be an
  750. insertion-order-preserving mapping.</p>
  751. <div class="admonition seealso">
  752. <p class="admonition-title">See also</p>
  753. <dl class="simple">
  754. <dt><span class="target" id="index-24"></span><a class="pep reference external" href="https://peps.python.org/pep-0468/"><strong>PEP 468</strong></a> – Preserving Keyword Argument Order</dt><dd><p>PEP written and implemented by Eric Snow.</p>
  755. </dd>
  756. </dl>
  757. </div>
  758. </section>
  759. <section id="new-dict-implementation">
  760. <span id="whatsnew36-compactdict"></span><h3>New <a class="reference internal" href="../library/stdtypes.html#typesmapping"><span class="std std-ref">dict</span></a> implementation<a class="headerlink" href="#new-dict-implementation" title="Link to this heading">¶</a></h3>
  761. <p>The <a class="reference internal" href="../library/stdtypes.html#typesmapping"><span class="std std-ref">dict</span></a> type now uses a “compact” representation
  762. based on <a class="reference external" href="https://mail.python.org/pipermail/python-dev/2012-December/123028.html">a proposal by Raymond Hettinger</a>
  763. which was <a class="reference external" href="https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html">first implemented by PyPy</a>.
  764. The memory usage of the new <a class="reference internal" href="../library/stdtypes.html#dict" title="dict"><code class="xref py py-func docutils literal notranslate"><span class="pre">dict()</span></code></a> is between 20% and 25% smaller
  765. compared to Python 3.5.</p>
  766. <p>The order-preserving aspect of this new implementation is considered an
  767. implementation detail and should not be relied upon (this may change in
  768. the future, but it is desired to have this new dict implementation in
  769. the language for a few releases before changing the language spec to mandate
  770. order-preserving semantics for all current and future Python
  771. implementations; this also helps preserve backwards-compatibility
  772. with older versions of the language where random iteration order is
  773. still in effect, e.g. Python 3.5).</p>
  774. <p>(Contributed by INADA Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27350">bpo-27350</a>. Idea
  775. <a class="reference external" href="https://mail.python.org/pipermail/python-dev/2012-December/123028.html">originally suggested by Raymond Hettinger</a>.)</p>
  776. </section>
  777. <section id="pep-523-adding-a-frame-evaluation-api-to-cpython">
  778. <span id="whatsnew36-pep523"></span><h3>PEP 523: Adding a frame evaluation API to CPython<a class="headerlink" href="#pep-523-adding-a-frame-evaluation-api-to-cpython" title="Link to this heading">¶</a></h3>
  779. <p>While Python provides extensive support to customize how code
  780. executes, one place it has not done so is in the evaluation of frame
  781. objects. If you wanted some way to intercept frame evaluation in
  782. Python there really wasn’t any way without directly manipulating
  783. function pointers for defined functions.</p>
  784. <p><span class="target" id="index-25"></span><a class="pep reference external" href="https://peps.python.org/pep-0523/"><strong>PEP 523</strong></a> changes this by providing an API to make frame
  785. evaluation pluggable at the C level. This will allow for tools such
  786. as debuggers and JITs to intercept frame evaluation before the
  787. execution of Python code begins. This enables the use of alternative
  788. evaluation implementations for Python code, tracking frame
  789. evaluation, etc.</p>
  790. <p>This API is not part of the limited C API and is marked as private to
  791. signal that usage of this API is expected to be limited and only
  792. applicable to very select, low-level use-cases. Semantics of the
  793. API will change with Python as necessary.</p>
  794. <div class="admonition seealso">
  795. <p class="admonition-title">See also</p>
  796. <dl class="simple">
  797. <dt><span class="target" id="index-26"></span><a class="pep reference external" href="https://peps.python.org/pep-0523/"><strong>PEP 523</strong></a> – Adding a frame evaluation API to CPython</dt><dd><p>PEP written by Brett Cannon and Dino Viehland.</p>
  798. </dd>
  799. </dl>
  800. </div>
  801. </section>
  802. <section id="pythonmalloc-environment-variable">
  803. <span id="whatsnew36-pythonmalloc"></span><h3>PYTHONMALLOC environment variable<a class="headerlink" href="#pythonmalloc-environment-variable" title="Link to this heading">¶</a></h3>
  804. <p>The new <span class="target" id="index-27"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONMALLOC"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONMALLOC</span></code></a> environment variable allows setting the Python
  805. memory allocators and installing debug hooks.</p>
  806. <p>It is now possible to install debug hooks on Python memory allocators on Python
  807. compiled in release mode using <code class="docutils literal notranslate"><span class="pre">PYTHONMALLOC=debug</span></code>. Effects of debug hooks:</p>
  808. <ul class="simple">
  809. <li><p>Newly allocated memory is filled with the byte <code class="docutils literal notranslate"><span class="pre">0xCB</span></code></p></li>
  810. <li><p>Freed memory is filled with the byte <code class="docutils literal notranslate"><span class="pre">0xDB</span></code></p></li>
  811. <li><p>Detect violations of the Python memory allocator API. For example,
  812. <a class="reference internal" href="../c-api/memory.html#c.PyObject_Free" title="PyObject_Free"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Free()</span></code></a> called on a memory block allocated by
  813. <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a>.</p></li>
  814. <li><p>Detect writes before the start of a buffer (buffer underflows)</p></li>
  815. <li><p>Detect writes after the end of a buffer (buffer overflows)</p></li>
  816. <li><p>Check that the <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">GIL</span></a> is held when allocator
  817. functions of <a class="reference internal" href="../c-api/memory.html#c.PYMEM_DOMAIN_OBJ" title="PYMEM_DOMAIN_OBJ"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PYMEM_DOMAIN_OBJ</span></code></a> (ex: <a class="reference internal" href="../c-api/memory.html#c.PyObject_Malloc" title="PyObject_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Malloc()</span></code></a>) and
  818. <a class="reference internal" href="../c-api/memory.html#c.PYMEM_DOMAIN_MEM" title="PYMEM_DOMAIN_MEM"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PYMEM_DOMAIN_MEM</span></code></a> (ex: <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a>) domains are called.</p></li>
  819. </ul>
  820. <p>Checking if the GIL is held is also a new feature of Python 3.6.</p>
  821. <p>See the <a class="reference internal" href="../c-api/memory.html#c.PyMem_SetupDebugHooks" title="PyMem_SetupDebugHooks"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_SetupDebugHooks()</span></code></a> function for debug hooks on Python
  822. memory allocators.</p>
  823. <p>It is now also possible to force the usage of the <code class="xref c c-func docutils literal notranslate"><span class="pre">malloc()</span></code> allocator of
  824. the C library for all Python memory allocations using <code class="docutils literal notranslate"><span class="pre">PYTHONMALLOC=malloc</span></code>.
  825. This is helpful when using external memory debuggers like Valgrind on
  826. a Python compiled in release mode.</p>
  827. <p>On error, the debug hooks on Python memory allocators now use the
  828. <a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a> module to get the traceback where a memory block was
  829. allocated.</p>
  830. <p>Example of fatal error on buffer overflow using
  831. <code class="docutils literal notranslate"><span class="pre">python3.6</span> <span class="pre">-X</span> <span class="pre">tracemalloc=5</span></code> (store 5 frames in traces):</p>
  832. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Debug</span> <span class="n">memory</span> <span class="n">block</span> <span class="n">at</span> <span class="n">address</span> <span class="n">p</span><span class="o">=</span><span class="mh">0x7fbcd41666f8</span><span class="p">:</span> <span class="n">API</span> <span class="s1">&#39;o&#39;</span>
  833. <span class="mi">4</span> <span class="nb">bytes</span> <span class="n">originally</span> <span class="n">requested</span>
  834. <span class="n">The</span> <span class="mi">7</span> <span class="n">pad</span> <span class="nb">bytes</span> <span class="n">at</span> <span class="n">p</span><span class="o">-</span><span class="mi">7</span> <span class="n">are</span> <span class="n">FORBIDDENBYTE</span><span class="p">,</span> <span class="k">as</span> <span class="n">expected</span><span class="o">.</span>
  835. <span class="n">The</span> <span class="mi">8</span> <span class="n">pad</span> <span class="nb">bytes</span> <span class="n">at</span> <span class="n">tail</span><span class="o">=</span><span class="mh">0x7fbcd41666fc</span> <span class="n">are</span> <span class="ow">not</span> <span class="nb">all</span> <span class="n">FORBIDDENBYTE</span> <span class="p">(</span><span class="mh">0xfb</span><span class="p">):</span>
  836. <span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">0</span><span class="p">:</span> <span class="mh">0x02</span> <span class="o">***</span> <span class="n">OUCH</span>
  837. <span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">1</span><span class="p">:</span> <span class="mh">0xfb</span>
  838. <span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">2</span><span class="p">:</span> <span class="mh">0xfb</span>
  839. <span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">3</span><span class="p">:</span> <span class="mh">0xfb</span>
  840. <span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">4</span><span class="p">:</span> <span class="mh">0xfb</span>
  841. <span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">5</span><span class="p">:</span> <span class="mh">0xfb</span>
  842. <span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">6</span><span class="p">:</span> <span class="mh">0xfb</span>
  843. <span class="n">at</span> <span class="n">tail</span><span class="o">+</span><span class="mi">7</span><span class="p">:</span> <span class="mh">0xfb</span>
  844. <span class="n">The</span> <span class="n">block</span> <span class="n">was</span> <span class="n">made</span> <span class="n">by</span> <span class="n">call</span> <span class="c1">#1233329 to debug malloc/realloc.</span>
  845. <span class="n">Data</span> <span class="n">at</span> <span class="n">p</span><span class="p">:</span> <span class="mi">1</span><span class="n">a</span> <span class="mi">2</span><span class="n">b</span> <span class="mi">30</span> <span class="mi">00</span>
  846. <span class="n">Memory</span> <span class="n">block</span> <span class="n">allocated</span> <span class="n">at</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">first</span><span class="p">):</span>
  847. <span class="n">File</span> <span class="s2">&quot;test/test_bytes.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">323</span>
  848. <span class="n">File</span> <span class="s2">&quot;unittest/case.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">600</span>
  849. <span class="n">File</span> <span class="s2">&quot;unittest/case.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">648</span>
  850. <span class="n">File</span> <span class="s2">&quot;unittest/suite.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">122</span>
  851. <span class="n">File</span> <span class="s2">&quot;unittest/suite.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">84</span>
  852. <span class="n">Fatal</span> <span class="n">Python</span> <span class="n">error</span><span class="p">:</span> <span class="n">bad</span> <span class="n">trailing</span> <span class="n">pad</span> <span class="n">byte</span>
  853. <span class="n">Current</span> <span class="n">thread</span> <span class="mh">0x00007fbcdbd32700</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">first</span><span class="p">):</span>
  854. <span class="n">File</span> <span class="s2">&quot;test/test_bytes.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">323</span> <span class="ow">in</span> <span class="n">test_hex</span>
  855. <span class="n">File</span> <span class="s2">&quot;unittest/case.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">600</span> <span class="ow">in</span> <span class="n">run</span>
  856. <span class="n">File</span> <span class="s2">&quot;unittest/case.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">648</span> <span class="ow">in</span> <span class="fm">__call__</span>
  857. <span class="n">File</span> <span class="s2">&quot;unittest/suite.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">122</span> <span class="ow">in</span> <span class="n">run</span>
  858. <span class="n">File</span> <span class="s2">&quot;unittest/suite.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">84</span> <span class="ow">in</span> <span class="fm">__call__</span>
  859. <span class="n">File</span> <span class="s2">&quot;unittest/suite.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">122</span> <span class="ow">in</span> <span class="n">run</span>
  860. <span class="n">File</span> <span class="s2">&quot;unittest/suite.py&quot;</span><span class="p">,</span> <span class="n">line</span> <span class="mi">84</span> <span class="ow">in</span> <span class="fm">__call__</span>
  861. <span class="o">...</span>
  862. </pre></div>
  863. </div>
  864. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26516">bpo-26516</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26564">bpo-26564</a>.)</p>
  865. </section>
  866. <section id="dtrace-and-systemtap-probing-support">
  867. <span id="whatsnew36-tracing"></span><h3>DTrace and SystemTap probing support<a class="headerlink" href="#dtrace-and-systemtap-probing-support" title="Link to this heading">¶</a></h3>
  868. <p>Python can now be built <code class="docutils literal notranslate"><span class="pre">--with-dtrace</span></code> which enables static markers
  869. for the following events in the interpreter:</p>
  870. <ul class="simple">
  871. <li><p>function call/return</p></li>
  872. <li><p>garbage collection started/finished</p></li>
  873. <li><p>line of code executed.</p></li>
  874. </ul>
  875. <p>This can be used to instrument running interpreters in production,
  876. without the need to recompile specific <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug builds</span></a> or
  877. providing application-specific profiling/debugging code.</p>
  878. <p>More details in <a class="reference internal" href="../howto/instrumentation.html#instrumentation"><span class="std std-ref">Instrumenting CPython with DTrace and SystemTap</span></a>.</p>
  879. <p>The current implementation is tested on Linux and macOS. Additional
  880. markers may be added in the future.</p>
  881. <p>(Contributed by Łukasz Langa in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21590">bpo-21590</a>, based on patches by
  882. Jesús Cea Avión, David Malcolm, and Nikhil Benesch.)</p>
  883. </section>
  884. </section>
  885. <section id="other-language-changes">
  886. <h2>Other Language Changes<a class="headerlink" href="#other-language-changes" title="Link to this heading">¶</a></h2>
  887. <p>Some smaller changes made to the core Python language are:</p>
  888. <ul class="simple">
  889. <li><p>A <code class="docutils literal notranslate"><span class="pre">global</span></code> or <code class="docutils literal notranslate"><span class="pre">nonlocal</span></code> statement must now textually appear
  890. before the first use of the affected name in the same scope.
  891. Previously this was a <a class="reference internal" href="../library/exceptions.html#SyntaxWarning" title="SyntaxWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxWarning</span></code></a>.</p></li>
  892. <li><p>It is now possible to set a <a class="reference internal" href="../reference/datamodel.html#specialnames"><span class="std std-ref">special method</span></a> to
  893. <code class="docutils literal notranslate"><span class="pre">None</span></code> to indicate that the corresponding operation is not available.
  894. For example, if a class sets <code class="xref py py-meth docutils literal notranslate"><span class="pre">__iter__()</span></code> to <code class="docutils literal notranslate"><span class="pre">None</span></code>, the class
  895. is not iterable.
  896. (Contributed by Andrew Barnert and Ivan Levkivskyi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25958">bpo-25958</a>.)</p></li>
  897. <li><p>Long sequences of repeated traceback lines are now abbreviated as
  898. <code class="docutils literal notranslate"><span class="pre">&quot;[Previous</span> <span class="pre">line</span> <span class="pre">repeated</span> <span class="pre">{count}</span> <span class="pre">more</span> <span class="pre">times]&quot;</span></code> (see
  899. <a class="reference internal" href="#whatsnew36-traceback"><span class="std std-ref">traceback</span></a> for an example).
  900. (Contributed by Emanuel Barry in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26823">bpo-26823</a>.)</p></li>
  901. <li><p>Import now raises the new exception <a class="reference internal" href="../library/exceptions.html#ModuleNotFoundError" title="ModuleNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ModuleNotFoundError</span></code></a>
  902. (subclass of <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>) when it cannot find a module. Code
  903. that currently checks for ImportError (in try-except) will still work.
  904. (Contributed by Eric Snow in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15767">bpo-15767</a>.)</p></li>
  905. <li><p>Class methods relying on zero-argument <code class="docutils literal notranslate"><span class="pre">super()</span></code> will now work correctly
  906. when called from metaclass methods during class creation.
  907. (Contributed by Martin Teichmann in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23722">bpo-23722</a>.)</p></li>
  908. </ul>
  909. </section>
  910. <section id="new-modules">
  911. <h2>New Modules<a class="headerlink" href="#new-modules" title="Link to this heading">¶</a></h2>
  912. <section id="secrets">
  913. <span id="whatsnew36-pep506"></span><h3>secrets<a class="headerlink" href="#secrets" title="Link to this heading">¶</a></h3>
  914. <p>The main purpose of the new <a class="reference internal" href="../library/secrets.html#module-secrets" title="secrets: Generate secure random numbers for managing secrets."><code class="xref py py-mod docutils literal notranslate"><span class="pre">secrets</span></code></a> module is to provide an obvious way
  915. to reliably generate cryptographically strong pseudo-random values suitable
  916. for managing secrets, such as account authentication, tokens, and similar.</p>
  917. <div class="admonition warning">
  918. <p class="admonition-title">Warning</p>
  919. <p>Note that the pseudo-random generators in the <a class="reference internal" href="../library/random.html#module-random" title="random: Generate pseudo-random numbers with various common distributions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">random</span></code></a> module
  920. should <em>NOT</em> be used for security purposes. Use <a class="reference internal" href="../library/secrets.html#module-secrets" title="secrets: Generate secure random numbers for managing secrets."><code class="xref py py-mod docutils literal notranslate"><span class="pre">secrets</span></code></a>
  921. on Python 3.6+ and <a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.urandom()</span></code></a> on Python 3.5 and earlier.</p>
  922. </div>
  923. <div class="admonition seealso">
  924. <p class="admonition-title">See also</p>
  925. <dl class="simple">
  926. <dt><span class="target" id="index-28"></span><a class="pep reference external" href="https://peps.python.org/pep-0506/"><strong>PEP 506</strong></a> – Adding A Secrets Module To The Standard Library</dt><dd><p>PEP written and implemented by Steven D’Aprano.</p>
  927. </dd>
  928. </dl>
  929. </div>
  930. </section>
  931. </section>
  932. <section id="improved-modules">
  933. <h2>Improved Modules<a class="headerlink" href="#improved-modules" title="Link to this heading">¶</a></h2>
  934. <section id="array">
  935. <h3>array<a class="headerlink" href="#array" title="Link to this heading">¶</a></h3>
  936. <p>Exhausted iterators of <a class="reference internal" href="../library/array.html#array.array" title="array.array"><code class="xref py py-class docutils literal notranslate"><span class="pre">array.array</span></code></a> will now stay exhausted even
  937. if the iterated array is extended. This is consistent with the behavior
  938. of other mutable sequences.</p>
  939. <p>Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26492">bpo-26492</a>.</p>
  940. </section>
  941. <section id="ast">
  942. <h3>ast<a class="headerlink" href="#ast" title="Link to this heading">¶</a></h3>
  943. <p>The new <a class="reference internal" href="../library/ast.html#ast.Constant" title="ast.Constant"><code class="xref py py-class docutils literal notranslate"><span class="pre">ast.Constant</span></code></a> AST node has been added. It can be used
  944. by external AST optimizers for the purposes of constant folding.</p>
  945. <p>Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26146">bpo-26146</a>.</p>
  946. </section>
  947. <section id="asyncio">
  948. <h3>asyncio<a class="headerlink" href="#asyncio" title="Link to this heading">¶</a></h3>
  949. <p>Starting with Python 3.6 the <code class="docutils literal notranslate"><span class="pre">asyncio</span></code> module is no longer provisional and its
  950. API is considered stable.</p>
  951. <p>Notable changes in the <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a> module since Python 3.5.0
  952. (all backported to 3.5.x due to the provisional status):</p>
  953. <ul class="simple">
  954. <li><p>The <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.get_event_loop" title="asyncio.get_event_loop"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_event_loop()</span></code></a> function has been changed to
  955. always return the currently running loop when called from coroutines
  956. and callbacks.
  957. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28613">bpo-28613</a>.)</p></li>
  958. <li><p>The <a class="reference internal" href="../library/asyncio-future.html#asyncio.ensure_future" title="asyncio.ensure_future"><code class="xref py py-func docutils literal notranslate"><span class="pre">ensure_future()</span></code></a> function and all functions that
  959. use it, such as <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.run_until_complete" title="asyncio.loop.run_until_complete"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.run_until_complete()</span></code></a>,
  960. now accept all kinds of <a class="reference internal" href="../glossary.html#term-awaitable"><span class="xref std std-term">awaitable objects</span></a>.
  961. (Contributed by Yury Selivanov.)</p></li>
  962. <li><p>New <a class="reference internal" href="../library/asyncio-task.html#asyncio.run_coroutine_threadsafe" title="asyncio.run_coroutine_threadsafe"><code class="xref py py-func docutils literal notranslate"><span class="pre">run_coroutine_threadsafe()</span></code></a> function to submit
  963. coroutines to event loops from other threads.
  964. (Contributed by Vincent Michel.)</p></li>
  965. <li><p>New <a class="reference internal" href="../library/asyncio-protocol.html#asyncio.BaseTransport.is_closing" title="asyncio.BaseTransport.is_closing"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Transport.is_closing()</span></code></a>
  966. method to check if the transport is closing or closed.
  967. (Contributed by Yury Selivanov.)</p></li>
  968. <li><p>The <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_server" title="asyncio.loop.create_server"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_server()</span></code></a>
  969. method can now accept a list of hosts.
  970. (Contributed by Yann Sionneau.)</p></li>
  971. <li><p>New <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_future" title="asyncio.loop.create_future"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.create_future()</span></code></a>
  972. method to create Future objects. This allows alternative event
  973. loop implementations, such as
  974. <a class="reference external" href="https://github.com/MagicStack/uvloop">uvloop</a>, to provide a faster
  975. <a class="reference internal" href="../library/asyncio-future.html#asyncio.Future" title="asyncio.Future"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Future</span></code></a> implementation.
  976. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27041">bpo-27041</a>.)</p></li>
  977. <li><p>New <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.get_exception_handler" title="asyncio.loop.get_exception_handler"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.get_exception_handler()</span></code></a>
  978. method to get the current exception handler.
  979. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27040">bpo-27040</a>.)</p></li>
  980. <li><p>New <a class="reference internal" href="../library/asyncio-stream.html#asyncio.StreamReader.readuntil" title="asyncio.StreamReader.readuntil"><code class="xref py py-meth docutils literal notranslate"><span class="pre">StreamReader.readuntil()</span></code></a>
  981. method to read data from the stream until a separator bytes
  982. sequence appears.
  983. (Contributed by Mark Korenberg.)</p></li>
  984. <li><p>The performance of <a class="reference internal" href="../library/asyncio-stream.html#asyncio.StreamReader.readexactly" title="asyncio.StreamReader.readexactly"><code class="xref py py-meth docutils literal notranslate"><span class="pre">StreamReader.readexactly()</span></code></a>
  985. has been improved.
  986. (Contributed by Mark Korenberg in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28370">bpo-28370</a>.)</p></li>
  987. <li><p>The <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.getaddrinfo" title="asyncio.loop.getaddrinfo"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.getaddrinfo()</span></code></a>
  988. method is optimized to avoid calling the system <code class="docutils literal notranslate"><span class="pre">getaddrinfo</span></code>
  989. function if the address is already resolved.
  990. (Contributed by A. Jesse Jiryu Davis.)</p></li>
  991. <li><p>The <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.stop" title="asyncio.loop.stop"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.stop()</span></code></a>
  992. method has been changed to stop the loop immediately after
  993. the current iteration. Any new callbacks scheduled as a result
  994. of the last iteration will be discarded.
  995. (Contributed by Guido van Rossum in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25593">bpo-25593</a>.)</p></li>
  996. <li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">Future.set_exception</span></code>
  997. will now raise <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> when passed an instance of
  998. the <a class="reference internal" href="../library/exceptions.html#StopIteration" title="StopIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code></a> exception.
  999. (Contributed by Chris Angelico in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26221">bpo-26221</a>.)</p></li>
  1000. <li><p>New <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.connect_accepted_socket" title="asyncio.loop.connect_accepted_socket"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.connect_accepted_socket()</span></code></a>
  1001. method to be used by servers that accept connections outside of asyncio,
  1002. but that use asyncio to handle them.
  1003. (Contributed by Jim Fulton in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27392">bpo-27392</a>.)</p></li>
  1004. <li><p><code class="docutils literal notranslate"><span class="pre">TCP_NODELAY</span></code> flag is now set for all TCP transports by default.
  1005. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27456">bpo-27456</a>.)</p></li>
  1006. <li><p>New <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.shutdown_asyncgens" title="asyncio.loop.shutdown_asyncgens"><code class="xref py py-meth docutils literal notranslate"><span class="pre">loop.shutdown_asyncgens()</span></code></a>
  1007. to properly close pending asynchronous generators before closing the
  1008. loop.
  1009. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28003">bpo-28003</a>.)</p></li>
  1010. <li><p><a class="reference internal" href="../library/asyncio-future.html#asyncio.Future" title="asyncio.Future"><code class="xref py py-class docutils literal notranslate"><span class="pre">Future</span></code></a> and <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">Task</span></code></a>
  1011. classes now have an optimized C implementation which makes asyncio
  1012. code up to 30% faster.
  1013. (Contributed by Yury Selivanov and INADA Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26081">bpo-26081</a>
  1014. and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28544">bpo-28544</a>.)</p></li>
  1015. </ul>
  1016. </section>
  1017. <section id="binascii">
  1018. <h3>binascii<a class="headerlink" href="#binascii" title="Link to this heading">¶</a></h3>
  1019. <p>The <a class="reference internal" href="../library/binascii.html#binascii.b2a_base64" title="binascii.b2a_base64"><code class="xref py py-func docutils literal notranslate"><span class="pre">b2a_base64()</span></code></a> function now accepts an optional <em>newline</em>
  1020. keyword argument to control whether the newline character is appended to the
  1021. return value.
  1022. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25357">bpo-25357</a>.)</p>
  1023. </section>
  1024. <section id="cmath">
  1025. <h3>cmath<a class="headerlink" href="#cmath" title="Link to this heading">¶</a></h3>
  1026. <p>The new <a class="reference internal" href="../library/cmath.html#cmath.tau" title="cmath.tau"><code class="xref py py-const docutils literal notranslate"><span class="pre">cmath.tau</span></code></a> (<em>τ</em>) constant has been added.
  1027. (Contributed by Lisa Roach in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12345">bpo-12345</a>, see <span class="target" id="index-29"></span><a class="pep reference external" href="https://peps.python.org/pep-0628/"><strong>PEP 628</strong></a> for details.)</p>
  1028. <p>New constants: <a class="reference internal" href="../library/cmath.html#cmath.inf" title="cmath.inf"><code class="xref py py-const docutils literal notranslate"><span class="pre">cmath.inf</span></code></a> and <a class="reference internal" href="../library/cmath.html#cmath.nan" title="cmath.nan"><code class="xref py py-const docutils literal notranslate"><span class="pre">cmath.nan</span></code></a> to
  1029. match <a class="reference internal" href="../library/math.html#math.inf" title="math.inf"><code class="xref py py-const docutils literal notranslate"><span class="pre">math.inf</span></code></a> and <a class="reference internal" href="../library/math.html#math.nan" title="math.nan"><code class="xref py py-const docutils literal notranslate"><span class="pre">math.nan</span></code></a>, and also <a class="reference internal" href="../library/cmath.html#cmath.infj" title="cmath.infj"><code class="xref py py-const docutils literal notranslate"><span class="pre">cmath.infj</span></code></a>
  1030. and <a class="reference internal" href="../library/cmath.html#cmath.nanj" title="cmath.nanj"><code class="xref py py-const docutils literal notranslate"><span class="pre">cmath.nanj</span></code></a> to match the format used by complex repr.
  1031. (Contributed by Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23229">bpo-23229</a>.)</p>
  1032. </section>
  1033. <section id="collections">
  1034. <h3>collections<a class="headerlink" href="#collections" title="Link to this heading">¶</a></h3>
  1035. <p>The new <a class="reference internal" href="../library/collections.abc.html#collections.abc.Collection" title="collections.abc.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">Collection</span></code></a> abstract base class has been
  1036. added to represent sized iterable container classes.
  1037. (Contributed by Ivan Levkivskyi, docs by Neil Girdhar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27598">bpo-27598</a>.)</p>
  1038. <p>The new <a class="reference internal" href="../library/collections.abc.html#collections.abc.Reversible" title="collections.abc.Reversible"><code class="xref py py-class docutils literal notranslate"><span class="pre">Reversible</span></code></a> abstract base class represents
  1039. iterable classes that also provide the <code class="xref py py-meth docutils literal notranslate"><span class="pre">__reversed__()</span></code> method.
  1040. (Contributed by Ivan Levkivskyi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25987">bpo-25987</a>.)</p>
  1041. <p>The new <a class="reference internal" href="../library/collections.abc.html#collections.abc.AsyncGenerator" title="collections.abc.AsyncGenerator"><code class="xref py py-class docutils literal notranslate"><span class="pre">AsyncGenerator</span></code></a> abstract base class represents
  1042. asynchronous generators.
  1043. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28720">bpo-28720</a>.)</p>
  1044. <p>The <a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a> function now accepts an optional
  1045. keyword argument <em>module</em>, which, when specified, is used for
  1046. the <code class="docutils literal notranslate"><span class="pre">__module__</span></code> attribute of the returned named tuple class.
  1047. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17941">bpo-17941</a>.)</p>
  1048. <p>The <em>verbose</em> and <em>rename</em> arguments for
  1049. <a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a> are now keyword-only.
  1050. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25628">bpo-25628</a>.)</p>
  1051. <p>Recursive <a class="reference internal" href="../library/collections.html#collections.deque" title="collections.deque"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.deque</span></code></a> instances can now be pickled.
  1052. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26482">bpo-26482</a>.)</p>
  1053. </section>
  1054. <section id="concurrent-futures">
  1055. <h3>concurrent.futures<a class="headerlink" href="#concurrent-futures" title="Link to this heading">¶</a></h3>
  1056. <p>The <a class="reference internal" href="../library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor" title="concurrent.futures.ThreadPoolExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">ThreadPoolExecutor</span></code></a>
  1057. class constructor now accepts an optional <em>thread_name_prefix</em> argument
  1058. to make it possible to customize the names of the threads created by the
  1059. pool.
  1060. (Contributed by Gregory P. Smith in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27664">bpo-27664</a>.)</p>
  1061. </section>
  1062. <section id="contextlib">
  1063. <h3>contextlib<a class="headerlink" href="#contextlib" title="Link to this heading">¶</a></h3>
  1064. <p>The <a class="reference internal" href="../library/contextlib.html#contextlib.AbstractContextManager" title="contextlib.AbstractContextManager"><code class="xref py py-class docutils literal notranslate"><span class="pre">contextlib.AbstractContextManager</span></code></a> class has been added to
  1065. provide an abstract base class for context managers. It provides a
  1066. sensible default implementation for <code class="docutils literal notranslate"><span class="pre">__enter__()</span></code> which returns
  1067. <code class="docutils literal notranslate"><span class="pre">self</span></code> and leaves <code class="docutils literal notranslate"><span class="pre">__exit__()</span></code> an abstract method. A matching
  1068. class has been added to the <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module as
  1069. <a class="reference internal" href="../library/typing.html#typing.ContextManager" title="typing.ContextManager"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.ContextManager</span></code></a>.
  1070. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25609">bpo-25609</a>.)</p>
  1071. </section>
  1072. <section id="datetime">
  1073. <h3>datetime<a class="headerlink" href="#datetime" title="Link to this heading">¶</a></h3>
  1074. <p>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> and <a class="reference internal" href="../library/datetime.html#datetime.time" title="datetime.time"><code class="xref py py-class docutils literal notranslate"><span class="pre">time</span></code></a> classes have
  1075. the new <code class="xref py py-attr docutils literal notranslate"><span class="pre">fold</span></code> attribute used to disambiguate local time
  1076. when necessary. Many functions in the <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> have been
  1077. updated to support local time disambiguation.
  1078. See <a class="reference internal" href="#whatsnew36-pep495"><span class="std std-ref">Local Time Disambiguation</span></a> section for more
  1079. information.
  1080. (Contributed by Alexander Belopolsky in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24773">bpo-24773</a>.)</p>
  1081. <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.strftime()</span></code></a> and
  1082. <a class="reference internal" href="../library/datetime.html#datetime.date.strftime" title="datetime.date.strftime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">date.strftime()</span></code></a> methods now support
  1083. ISO 8601 date directives <code class="docutils literal notranslate"><span class="pre">%G</span></code>, <code class="docutils literal notranslate"><span class="pre">%u</span></code> and <code class="docutils literal notranslate"><span class="pre">%V</span></code>.
  1084. (Contributed by Ashley Anderson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12006">bpo-12006</a>.)</p>
  1085. <p>The <a class="reference internal" href="../library/datetime.html#datetime.datetime.isoformat" title="datetime.datetime.isoformat"><code class="xref py py-func docutils literal notranslate"><span class="pre">datetime.isoformat()</span></code></a> function
  1086. now accepts an optional <em>timespec</em> argument that specifies the number
  1087. of additional components of the time value to include.
  1088. (Contributed by Alessandro Cucci and Alexander Belopolsky in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19475">bpo-19475</a>.)</p>
  1089. <p>The <a class="reference internal" href="../library/datetime.html#datetime.datetime.combine" title="datetime.datetime.combine"><code class="xref py py-meth docutils literal notranslate"><span class="pre">datetime.combine()</span></code></a> now
  1090. accepts an optional <em>tzinfo</em> argument.
  1091. (Contributed by Alexander Belopolsky in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27661">bpo-27661</a>.)</p>
  1092. </section>
  1093. <section id="decimal">
  1094. <h3>decimal<a class="headerlink" href="#decimal" title="Link to this heading">¶</a></h3>
  1095. <p>New <a class="reference internal" href="../library/decimal.html#decimal.Decimal.as_integer_ratio" title="decimal.Decimal.as_integer_ratio"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Decimal.as_integer_ratio()</span></code></a>
  1096. method that returns a pair <code class="docutils literal notranslate"><span class="pre">(n,</span> <span class="pre">d)</span></code> of integers that represent the given
  1097. <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> instance as a fraction, in lowest terms and
  1098. with a positive denominator:</p>
  1099. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">Decimal</span><span class="p">(</span><span class="s1">&#39;-3.14&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">as_integer_ratio</span><span class="p">()</span>
  1100. <span class="go">(-157, 50)</span>
  1101. </pre></div>
  1102. </div>
  1103. <p>(Contributed by Stefan Krah amd Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25928">bpo-25928</a>.)</p>
  1104. </section>
  1105. <section id="distutils">
  1106. <h3>distutils<a class="headerlink" href="#distutils" title="Link to this heading">¶</a></h3>
  1107. <p>The <code class="docutils literal notranslate"><span class="pre">default_format</span></code> attribute has been removed from
  1108. <code class="docutils literal notranslate"><span class="pre">distutils.command.sdist.sdist</span></code> and the <code class="docutils literal notranslate"><span class="pre">formats</span></code>
  1109. attribute defaults to <code class="docutils literal notranslate"><span class="pre">['gztar']</span></code>. Although not anticipated,
  1110. any code relying on the presence of <code class="docutils literal notranslate"><span class="pre">default_format</span></code> may
  1111. need to be adapted. See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27819">bpo-27819</a> for more details.</p>
  1112. </section>
  1113. <section id="email">
  1114. <h3>email<a class="headerlink" href="#email" title="Link to this heading">¶</a></h3>
  1115. <p>The new email API, enabled via the <em>policy</em> keyword to various constructors, is
  1116. no longer provisional. The <a class="reference internal" href="../library/email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a> documentation has been reorganized and
  1117. rewritten to focus on the new API, while retaining the old documentation for
  1118. the legacy API. (Contributed by R. David Murray in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24277">bpo-24277</a>.)</p>
  1119. <p>The <a class="reference internal" href="../library/email.mime.html#module-email.mime" title="email.mime: Build MIME messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.mime</span></code></a> classes now all accept an optional <em>policy</em> keyword.
  1120. (Contributed by Berker Peksag in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27331">bpo-27331</a>.)</p>
  1121. <p>The <a class="reference internal" href="../library/email.generator.html#email.generator.DecodedGenerator" title="email.generator.DecodedGenerator"><code class="xref py py-class docutils literal notranslate"><span class="pre">DecodedGenerator</span></code></a> now supports the <em>policy</em>
  1122. keyword.</p>
  1123. <p>There is a new <a class="reference internal" href="../library/email.policy.html#module-email.policy" title="email.policy: Controlling the parsing and generating of messages"><code class="xref py py-mod docutils literal notranslate"><span class="pre">policy</span></code></a> attribute,
  1124. <a class="reference internal" href="../library/email.policy.html#email.policy.Policy.message_factory" title="email.policy.Policy.message_factory"><code class="xref py py-attr docutils literal notranslate"><span class="pre">message_factory</span></code></a>, that controls what class is used
  1125. by default when the parser creates new message objects. For the
  1126. <a class="reference internal" href="../library/email.policy.html#email.policy.compat32" title="email.policy.compat32"><code class="xref py py-attr docutils literal notranslate"><span class="pre">email.policy.compat32</span></code></a> policy this is <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>,
  1127. for the new policies it is <a class="reference internal" href="../library/email.message.html#email.message.EmailMessage" title="email.message.EmailMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">EmailMessage</span></code></a>.
  1128. (Contributed by R. David Murray in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20476">bpo-20476</a>.)</p>
  1129. </section>
  1130. <section id="encodings">
  1131. <h3>encodings<a class="headerlink" href="#encodings" title="Link to this heading">¶</a></h3>
  1132. <p>On Windows, added the <code class="docutils literal notranslate"><span class="pre">'oem'</span></code> encoding to use <code class="docutils literal notranslate"><span class="pre">CP_OEMCP</span></code>, and the <code class="docutils literal notranslate"><span class="pre">'ansi'</span></code>
  1133. alias for the existing <code class="docutils literal notranslate"><span class="pre">'mbcs'</span></code> encoding, which uses the <code class="docutils literal notranslate"><span class="pre">CP_ACP</span></code> code page.
  1134. (Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27959">bpo-27959</a>.)</p>
  1135. </section>
  1136. <section id="enum">
  1137. <h3>enum<a class="headerlink" href="#enum" title="Link to this heading">¶</a></h3>
  1138. <p>Two new enumeration base classes have been added to the <a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a> module:
  1139. <a class="reference internal" href="../library/enum.html#enum.Flag" title="enum.Flag"><code class="xref py py-class docutils literal notranslate"><span class="pre">Flag</span></code></a> and <code class="xref py py-class docutils literal notranslate"><span class="pre">IntFlags</span></code>. Both are used to define
  1140. constants that can be combined using the bitwise operators.
  1141. (Contributed by Ethan Furman in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23591">bpo-23591</a>.)</p>
  1142. <p>Many standard library modules have been updated to use the
  1143. <code class="xref py py-class docutils literal notranslate"><span class="pre">IntFlags</span></code> class for their constants.</p>
  1144. <p>The new <a class="reference internal" href="../library/enum.html#enum.auto" title="enum.auto"><code class="xref py py-class docutils literal notranslate"><span class="pre">enum.auto</span></code></a> value can be used to assign values to enum
  1145. members automatically:</p>
  1146. <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">enum</span> <span class="kn">import</span> <span class="n">Enum</span><span class="p">,</span> <span class="n">auto</span>
  1147. <span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">Color</span><span class="p">(</span><span class="n">Enum</span><span class="p">):</span>
  1148. <span class="gp">... </span> <span class="n">red</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span>
  1149. <span class="gp">... </span> <span class="n">blue</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span>
  1150. <span class="gp">... </span> <span class="n">green</span> <span class="o">=</span> <span class="n">auto</span><span class="p">()</span>
  1151. <span class="gp">...</span>
  1152. <span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">Color</span><span class="p">)</span>
  1153. <span class="go">[&lt;Color.red: 1&gt;, &lt;Color.blue: 2&gt;, &lt;Color.green: 3&gt;]</span>
  1154. </pre></div>
  1155. </div>
  1156. </section>
  1157. <section id="faulthandler">
  1158. <h3>faulthandler<a class="headerlink" href="#faulthandler" title="Link to this heading">¶</a></h3>
  1159. <p>On Windows, the <a class="reference internal" href="../library/faulthandler.html#module-faulthandler" title="faulthandler: Dump the Python traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code></a> module now installs a handler for Windows
  1160. exceptions: see <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>. (Contributed by Victor Stinner in
  1161. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23848">bpo-23848</a>.)</p>
  1162. </section>
  1163. <section id="fileinput">
  1164. <h3>fileinput<a class="headerlink" href="#fileinput" title="Link to this heading">¶</a></h3>
  1165. <p><a class="reference internal" href="../library/fileinput.html#fileinput.hook_encoded" title="fileinput.hook_encoded"><code class="xref py py-func docutils literal notranslate"><span class="pre">hook_encoded()</span></code></a> now supports the <em>errors</em> argument.
  1166. (Contributed by Joseph Hackman in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25788">bpo-25788</a>.)</p>
  1167. </section>
  1168. <section id="hashlib">
  1169. <h3>hashlib<a class="headerlink" href="#hashlib" title="Link to this heading">¶</a></h3>
  1170. <p><a class="reference internal" href="../library/hashlib.html#module-hashlib" title="hashlib: Secure hash and message digest algorithms."><code class="xref py py-mod docutils literal notranslate"><span class="pre">hashlib</span></code></a> supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2.
  1171. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26470">bpo-26470</a>.)</p>
  1172. <p>BLAKE2 hash functions were added to the module. <a class="reference internal" href="../library/hashlib.html#hashlib.blake2b" title="hashlib.blake2b"><code class="xref py py-func docutils literal notranslate"><span class="pre">blake2b()</span></code></a>
  1173. and <a class="reference internal" href="../library/hashlib.html#hashlib.blake2s" title="hashlib.blake2s"><code class="xref py py-func docutils literal notranslate"><span class="pre">blake2s()</span></code></a> are always available and support the full
  1174. feature set of BLAKE2.
  1175. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26798">bpo-26798</a> based on code by
  1176. Dmitry Chestnykh and Samuel Neves. Documentation written by Dmitry Chestnykh.)</p>
  1177. <p>The SHA-3 hash functions <a class="reference internal" href="../library/hashlib.html#hashlib.sha3_224" title="hashlib.sha3_224"><code class="xref py py-func docutils literal notranslate"><span class="pre">sha3_224()</span></code></a>, <a class="reference internal" href="../library/hashlib.html#hashlib.sha3_256" title="hashlib.sha3_256"><code class="xref py py-func docutils literal notranslate"><span class="pre">sha3_256()</span></code></a>,
  1178. <a class="reference internal" href="../library/hashlib.html#hashlib.sha3_384" title="hashlib.sha3_384"><code class="xref py py-func docutils literal notranslate"><span class="pre">sha3_384()</span></code></a>, <a class="reference internal" href="../library/hashlib.html#hashlib.sha3_512" title="hashlib.sha3_512"><code class="xref py py-func docutils literal notranslate"><span class="pre">sha3_512()</span></code></a>, and SHAKE hash functions
  1179. <a class="reference internal" href="../library/hashlib.html#hashlib.shake_128" title="hashlib.shake_128"><code class="xref py py-func docutils literal notranslate"><span class="pre">shake_128()</span></code></a> and <a class="reference internal" href="../library/hashlib.html#hashlib.shake_256" title="hashlib.shake_256"><code class="xref py py-func docutils literal notranslate"><span class="pre">shake_256()</span></code></a> were added.
  1180. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16113">bpo-16113</a>. Keccak Code Package
  1181. by Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche, and
  1182. Ronny Van Keer.)</p>
  1183. <p>The password-based key derivation function <a class="reference internal" href="../library/hashlib.html#hashlib.scrypt" title="hashlib.scrypt"><code class="xref py py-func docutils literal notranslate"><span class="pre">scrypt()</span></code></a> is now
  1184. available with OpenSSL 1.1.0 and newer.
  1185. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27928">bpo-27928</a>.)</p>
  1186. </section>
  1187. <section id="http-client">
  1188. <h3>http.client<a class="headerlink" href="#http-client" title="Link to this heading">¶</a></h3>
  1189. <p><a class="reference internal" href="../library/http.client.html#http.client.HTTPConnection.request" title="http.client.HTTPConnection.request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HTTPConnection.request()</span></code></a> and
  1190. <a class="reference internal" href="../library/http.client.html#http.client.HTTPConnection.endheaders" title="http.client.HTTPConnection.endheaders"><code class="xref py py-meth docutils literal notranslate"><span class="pre">endheaders()</span></code></a> both now support
  1191. chunked encoding request bodies.
  1192. (Contributed by Demian Brecht and Rolf Krahl in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12319">bpo-12319</a>.)</p>
  1193. </section>
  1194. <section id="idlelib-and-idle">
  1195. <h3>idlelib and IDLE<a class="headerlink" href="#idlelib-and-idle" title="Link to this heading">¶</a></h3>
  1196. <p>The idlelib package is being modernized and refactored to make IDLE look and
  1197. work better and to make the code easier to understand, test, and improve. Part
  1198. of making IDLE look better, especially on Linux and Mac, is using ttk widgets,
  1199. mostly in the dialogs. As a result, IDLE no longer runs with tcl/tk 8.4. It
  1200. now requires tcl/tk 8.5 or 8.6. We recommend running the latest release of
  1201. either.</p>
  1202. <p>‘Modernizing’ includes renaming and consolidation of idlelib modules. The
  1203. renaming of files with partial uppercase names is similar to the renaming of,
  1204. for instance, Tkinter and TkFont to tkinter and tkinter.font in 3.0. As a
  1205. result, imports of idlelib files that worked in 3.5 will usually not work in
  1206. 3.6. At least a module name change will be needed (see idlelib/README.txt),
  1207. sometimes more. (Name changes contributed by Al Swiegart and Terry Reedy in
  1208. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24225">bpo-24225</a>. Most idlelib patches since have been and will be part of the
  1209. process.)</p>
  1210. <p>In compensation, the eventual result with be that some idlelib classes will be
  1211. easier to use, with better APIs and docstrings explaining them. Additional
  1212. useful information will be added to idlelib when available.</p>
  1213. <p>New in 3.6.2:</p>
  1214. <p>Multiple fixes for autocompletion. (Contributed by Louie Lu in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15786">bpo-15786</a>.)</p>
  1215. <p>New in 3.6.3:</p>
  1216. <p>Module Browser (on the File menu, formerly called Class Browser),
  1217. now displays nested functions and classes in addition to top-level
  1218. functions and classes.
  1219. (Contributed by Guilherme Polo, Cheryl Sabella, and Terry Jan Reedy
  1220. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1612262">bpo-1612262</a>.)</p>
  1221. <p>The IDLE features formerly implemented as extensions have been reimplemented
  1222. as normal features. Their settings have been moved from the Extensions tab
  1223. to other dialog tabs.
  1224. (Contributed by Charles Wohlganger and Terry Jan Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27099">bpo-27099</a>.)</p>
  1225. <p>The Settings dialog (Options, Configure IDLE) has been partly rewritten
  1226. to improve both appearance and function.
  1227. (Contributed by Cheryl Sabella and Terry Jan Reedy in multiple issues.)</p>
  1228. <p>New in 3.6.4:</p>
  1229. <p>The font sample now includes a selection of non-Latin characters so that
  1230. users can better see the effect of selecting a particular font.
  1231. (Contributed by Terry Jan Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13802">bpo-13802</a>.)
  1232. The sample can be edited to include other characters.
  1233. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31860">bpo-31860</a>.)</p>
  1234. <p>New in 3.6.6:</p>
  1235. <p>Editor code context option revised. Box displays all context lines up to
  1236. maxlines. Clicking on a context line jumps the editor to that line. Context
  1237. colors for custom themes is added to Highlights tab of Settings dialog.
  1238. (Contributed by Cheryl Sabella and Terry Jan Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33642">bpo-33642</a>,
  1239. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33768">bpo-33768</a>, and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33679">bpo-33679</a>.)</p>
  1240. <p>On Windows, a new API call tells Windows that tk scales for DPI. On Windows
  1241. 8.1+ or 10, with DPI compatibility properties of the Python binary
  1242. unchanged, and a monitor resolution greater than 96 DPI, this should
  1243. make text and lines sharper. It should otherwise have no effect.
  1244. (Contributed by Terry Jan Reedy in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33656">bpo-33656</a>.)</p>
  1245. <p>New in 3.6.7:</p>
  1246. <p>Output over N lines (50 by default) is squeezed down to a button.
  1247. N can be changed in the PyShell section of the General page of the
  1248. Settings dialog. Fewer, but possibly extra long, lines can be squeezed by
  1249. right clicking on the output. Squeezed output can be expanded in place
  1250. by double-clicking the button or into the clipboard or a separate window
  1251. by right-clicking the button. (Contributed by Tal Einat in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1529353">bpo-1529353</a>.)</p>
  1252. </section>
  1253. <section id="importlib">
  1254. <h3>importlib<a class="headerlink" href="#importlib" title="Link to this heading">¶</a></h3>
  1255. <p>Import now raises the new exception <a class="reference internal" href="../library/exceptions.html#ModuleNotFoundError" title="ModuleNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ModuleNotFoundError</span></code></a>
  1256. (subclass of <a class="reference internal" href="../library/exceptions.html#ImportError" title="ImportError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportError</span></code></a>) when it cannot find a module. Code
  1257. that current checks for <code class="docutils literal notranslate"><span class="pre">ImportError</span></code> (in try-except) will still work.
  1258. (Contributed by Eric Snow in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15767">bpo-15767</a>.)</p>
  1259. <p><a class="reference internal" href="../library/importlib.html#importlib.util.LazyLoader" title="importlib.util.LazyLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.util.LazyLoader</span></code></a> now calls
  1260. <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.create_module" title="importlib.abc.Loader.create_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_module()</span></code></a> on the wrapped loader, removing the
  1261. restriction that <a class="reference internal" href="../library/importlib.html#importlib.machinery.BuiltinImporter" title="importlib.machinery.BuiltinImporter"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.BuiltinImporter</span></code></a> and
  1262. <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> couldn’t be used with
  1263. <a class="reference internal" href="../library/importlib.html#importlib.util.LazyLoader" title="importlib.util.LazyLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.util.LazyLoader</span></code></a>.</p>
  1264. <p><a class="reference internal" href="../library/importlib.html#importlib.util.cache_from_source" title="importlib.util.cache_from_source"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.cache_from_source()</span></code></a>,
  1265. <a class="reference internal" href="../library/importlib.html#importlib.util.source_from_cache" title="importlib.util.source_from_cache"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.source_from_cache()</span></code></a>, and
  1266. <a class="reference internal" href="../library/importlib.html#importlib.util.spec_from_file_location" title="importlib.util.spec_from_file_location"><code class="xref py py-func docutils literal notranslate"><span class="pre">importlib.util.spec_from_file_location()</span></code></a> now accept a
  1267. <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
  1268. </section>
  1269. <section id="inspect">
  1270. <h3>inspect<a class="headerlink" href="#inspect" title="Link to this heading">¶</a></h3>
  1271. <p>The <a class="reference internal" href="../library/inspect.html#inspect.signature" title="inspect.signature"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.signature()</span></code></a> function now reports the
  1272. implicit <code class="docutils literal notranslate"><span class="pre">.0</span></code> parameters generated by the compiler for comprehension and
  1273. generator expression scopes as if they were positional-only parameters called
  1274. <code class="docutils literal notranslate"><span class="pre">implicit0</span></code>. (Contributed by Jelle Zijlstra in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19611">bpo-19611</a>.)</p>
  1275. <p>To reduce code churn when upgrading from Python 2.7 and the legacy
  1276. <code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getargspec()</span></code> API, the previously documented deprecation of
  1277. <a class="reference internal" href="../library/inspect.html#inspect.getfullargspec" title="inspect.getfullargspec"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getfullargspec()</span></code></a> has been reversed. While this function is
  1278. convenient for single/source Python 2/3 code bases, the richer
  1279. <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> interface remains the recommended approach for new
  1280. code. (Contributed by Nick Coghlan in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27172">bpo-27172</a>)</p>
  1281. </section>
  1282. <section id="json">
  1283. <h3>json<a class="headerlink" href="#json" title="Link to this heading">¶</a></h3>
  1284. <p><a class="reference internal" href="../library/json.html#json.load" title="json.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.load()</span></code></a> and <a class="reference internal" href="../library/json.html#json.loads" title="json.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">json.loads()</span></code></a> now support binary input. Encoded
  1285. JSON should be represented using either UTF-8, UTF-16, or UTF-32.
  1286. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17909">bpo-17909</a>.)</p>
  1287. </section>
  1288. <section id="logging">
  1289. <h3>logging<a class="headerlink" href="#logging" title="Link to this heading">¶</a></h3>
  1290. <p>The new <a class="reference internal" href="../library/logging.handlers.html#logging.handlers.WatchedFileHandler.reopenIfNeeded" title="logging.handlers.WatchedFileHandler.reopenIfNeeded"><code class="xref py py-meth docutils literal notranslate"><span class="pre">WatchedFileHandler.reopenIfNeeded()</span></code></a>
  1291. method has been added to add the ability to check if the log file needs to
  1292. be reopened.
  1293. (Contributed by Marian Horban in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24884">bpo-24884</a>.)</p>
  1294. </section>
  1295. <section id="math">
  1296. <h3>math<a class="headerlink" href="#math" title="Link to this heading">¶</a></h3>
  1297. <p>The tau (<em>τ</em>) constant has been added to 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> and <a class="reference internal" href="../library/cmath.html#module-cmath" title="cmath: Mathematical functions for complex numbers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">cmath</span></code></a>
  1298. modules.
  1299. (Contributed by Lisa Roach in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12345">bpo-12345</a>, see <span class="target" id="index-30"></span><a class="pep reference external" href="https://peps.python.org/pep-0628/"><strong>PEP 628</strong></a> for details.)</p>
  1300. </section>
  1301. <section id="multiprocessing">
  1302. <h3>multiprocessing<a class="headerlink" href="#multiprocessing" title="Link to this heading">¶</a></h3>
  1303. <p><a class="reference internal" href="../library/multiprocessing.html#multiprocessing-proxy-objects"><span class="std std-ref">Proxy Objects</span></a> returned by
  1304. <a class="reference internal" href="../library/multiprocessing.html#multiprocessing.Manager" title="multiprocessing.Manager"><code class="xref py py-func docutils literal notranslate"><span class="pre">multiprocessing.Manager()</span></code></a> can now be nested.
  1305. (Contributed by Davin Potts in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6766">bpo-6766</a>.)</p>
  1306. </section>
  1307. <section id="os">
  1308. <h3>os<a class="headerlink" href="#os" title="Link to this heading">¶</a></h3>
  1309. <p>See the summary of <a class="reference internal" href="#whatsnew36-pep519"><span class="std std-ref">PEP 519</span></a> for details on how the
  1310. <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> and <a class="reference internal" href="../library/os.path.html#module-os.path" title="os.path: Operations on pathnames."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os.path</span></code></a> modules now support
  1311. <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like objects</span></a>.</p>
  1312. <p><a class="reference internal" href="../library/os.html#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> now supports <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> paths on Windows.</p>
  1313. <p>A new <a class="reference internal" href="../library/os.html#os.scandir.close" title="os.scandir.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code></a> method allows explicitly closing a
  1314. <a class="reference internal" href="../library/os.html#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> iterator. The <a class="reference internal" href="../library/os.html#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code></a> iterator now
  1315. supports the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a> protocol. If a <code class="xref py py-func docutils literal notranslate"><span class="pre">scandir()</span></code>
  1316. iterator is neither exhausted nor explicitly closed a <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a>
  1317. will be emitted in its destructor.
  1318. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25994">bpo-25994</a>.)</p>
  1319. <p>On Linux, <a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.urandom()</span></code></a> now blocks until the system urandom entropy pool
  1320. is initialized to increase the security. See the <span class="target" id="index-31"></span><a class="pep reference external" href="https://peps.python.org/pep-0524/"><strong>PEP 524</strong></a> for the rationale.</p>
  1321. <p>The Linux <code class="docutils literal notranslate"><span class="pre">getrandom()</span></code> syscall (get random bytes) is now exposed as the new
  1322. <a class="reference internal" href="../library/os.html#os.getrandom" title="os.getrandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.getrandom()</span></code></a> function.
  1323. (Contributed by Victor Stinner, part of the <span class="target" id="index-32"></span><a class="pep reference external" href="https://peps.python.org/pep-0524/"><strong>PEP 524</strong></a>)</p>
  1324. </section>
  1325. <section id="pathlib">
  1326. <h3>pathlib<a class="headerlink" href="#pathlib" title="Link to this heading">¶</a></h3>
  1327. <p><a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> now supports <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like objects</span></a>.
  1328. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27186">bpo-27186</a>.)</p>
  1329. <p>See the summary of <a class="reference internal" href="#whatsnew36-pep519"><span class="std std-ref">PEP 519</span></a> for details.</p>
  1330. </section>
  1331. <section id="pdb">
  1332. <h3>pdb<a class="headerlink" href="#pdb" title="Link to this heading">¶</a></h3>
  1333. <p>The <a class="reference internal" href="../library/pdb.html#pdb.Pdb" title="pdb.Pdb"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pdb</span></code></a> class constructor has a new optional <em>readrc</em> argument
  1334. to control whether <code class="docutils literal notranslate"><span class="pre">.pdbrc</span></code> files should be read.</p>
  1335. </section>
  1336. <section id="pickle">
  1337. <h3>pickle<a class="headerlink" href="#pickle" title="Link to this heading">¶</a></h3>
  1338. <p>Objects that need <code class="docutils literal notranslate"><span class="pre">__new__</span></code> called with keyword arguments can now be pickled
  1339. using <a class="reference internal" href="../library/pickle.html#pickle-protocols"><span class="std std-ref">pickle protocols</span></a> older than protocol version 4.
  1340. Protocol version 4 already supports this case. (Contributed by Serhiy
  1341. Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24164">bpo-24164</a>.)</p>
  1342. </section>
  1343. <section id="pickletools">
  1344. <h3>pickletools<a class="headerlink" href="#pickletools" title="Link to this heading">¶</a></h3>
  1345. <p><a class="reference internal" href="../library/pickletools.html#pickletools.dis" title="pickletools.dis"><code class="xref py py-func docutils literal notranslate"><span class="pre">pickletools.dis()</span></code></a> now outputs the implicit memo index for the
  1346. <code class="docutils literal notranslate"><span class="pre">MEMOIZE</span></code> opcode.
  1347. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25382">bpo-25382</a>.)</p>
  1348. </section>
  1349. <section id="pydoc">
  1350. <h3>pydoc<a class="headerlink" href="#pydoc" title="Link to this heading">¶</a></h3>
  1351. <p>The <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> module has learned to respect the <code class="docutils literal notranslate"><span class="pre">MANPAGER</span></code>
  1352. environment variable.
  1353. (Contributed by Matthias Klose in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=8637">bpo-8637</a>.)</p>
  1354. <p><a class="reference internal" href="../library/functions.html#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a> and <a class="reference internal" href="../library/pydoc.html#module-pydoc" title="pydoc: Documentation generator and online help system."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pydoc</span></code></a> can now list named tuple fields in the
  1355. order they were defined rather than alphabetically.
  1356. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24879">bpo-24879</a>.)</p>
  1357. </section>
  1358. <section id="random">
  1359. <h3>random<a class="headerlink" href="#random" title="Link to this heading">¶</a></h3>
  1360. <p>The new <a class="reference internal" href="../library/random.html#random.choices" title="random.choices"><code class="xref py py-func docutils literal notranslate"><span class="pre">choices()</span></code></a> function returns a list of elements of
  1361. specified size from the given population with optional weights.
  1362. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18844">bpo-18844</a>.)</p>
  1363. </section>
  1364. <section id="re">
  1365. <h3>re<a class="headerlink" href="#re" title="Link to this heading">¶</a></h3>
  1366. <p>Added support of modifier spans in regular expressions. Examples:
  1367. <code class="docutils literal notranslate"><span class="pre">'(?i:p)ython'</span></code> matches <code class="docutils literal notranslate"><span class="pre">'python'</span></code> and <code class="docutils literal notranslate"><span class="pre">'Python'</span></code>, but not <code class="docutils literal notranslate"><span class="pre">'PYTHON'</span></code>;
  1368. <code class="docutils literal notranslate"><span class="pre">'(?i)g(?-i:v)r'</span></code> matches <code class="docutils literal notranslate"><span class="pre">'GvR'</span></code> and <code class="docutils literal notranslate"><span class="pre">'gvr'</span></code>, but not <code class="docutils literal notranslate"><span class="pre">'GVR'</span></code>.
  1369. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=433028">bpo-433028</a>.)</p>
  1370. <p>Match object groups can be accessed by <code class="docutils literal notranslate"><span class="pre">__getitem__</span></code>, which is
  1371. equivalent to <code class="docutils literal notranslate"><span class="pre">group()</span></code>. So <code class="docutils literal notranslate"><span class="pre">mo['name']</span></code> is now equivalent to
  1372. <code class="docutils literal notranslate"><span class="pre">mo.group('name')</span></code>. (Contributed by Eric Smith in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24454">bpo-24454</a>.)</p>
  1373. <p><a class="reference internal" href="../library/re.html#re.Match" title="re.Match"><code class="xref py py-class docutils literal notranslate"><span class="pre">Match</span></code></a> objects now support
  1374. <a class="reference internal" href="../reference/datamodel.html#object.__index__" title="object.__index__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">index-like</span> <span class="pre">objects</span></code></a> as group
  1375. indices.
  1376. (Contributed by Jeroen Demeyer and Xiang Zhang in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27177">bpo-27177</a>.)</p>
  1377. </section>
  1378. <section id="readline">
  1379. <h3>readline<a class="headerlink" href="#readline" title="Link to this heading">¶</a></h3>
  1380. <p>Added <a class="reference internal" href="../library/readline.html#readline.set_auto_history" title="readline.set_auto_history"><code class="xref py py-func docutils literal notranslate"><span class="pre">set_auto_history()</span></code></a> to enable or disable
  1381. automatic addition of input to the history list. (Contributed by
  1382. Tyler Crompton in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26870">bpo-26870</a>.)</p>
  1383. </section>
  1384. <section id="rlcompleter">
  1385. <h3>rlcompleter<a class="headerlink" href="#rlcompleter" title="Link to this heading">¶</a></h3>
  1386. <p>Private and special attribute names now are omitted unless the prefix starts
  1387. with underscores. A space or a colon is added after some completed keywords.
  1388. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25011">bpo-25011</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25209">bpo-25209</a>.)</p>
  1389. </section>
  1390. <section id="shlex">
  1391. <h3>shlex<a class="headerlink" href="#shlex" title="Link to this heading">¶</a></h3>
  1392. <p>The <a class="reference internal" href="../library/shlex.html#shlex.shlex" title="shlex.shlex"><code class="xref py py-class docutils literal notranslate"><span class="pre">shlex</span></code></a> has much
  1393. <a class="reference internal" href="../library/shlex.html#improved-shell-compatibility"><span class="std std-ref">improved shell compatibility</span></a>
  1394. through the new <em>punctuation_chars</em> argument to control which characters
  1395. are treated as punctuation.
  1396. (Contributed by Vinay Sajip in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=1521950">bpo-1521950</a>.)</p>
  1397. </section>
  1398. <section id="site">
  1399. <h3>site<a class="headerlink" href="#site" title="Link to this heading">¶</a></h3>
  1400. <p>When specifying paths to add to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> in a <code class="docutils literal notranslate"><span class="pre">.pth</span></code> file,
  1401. you may now specify file paths on top of directories (e.g. zip files).
  1402. (Contributed by Wolfgang Langner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26587">bpo-26587</a>).</p>
  1403. </section>
  1404. <section id="sqlite3">
  1405. <h3>sqlite3<a class="headerlink" href="#sqlite3" title="Link to this heading">¶</a></h3>
  1406. <p><a class="reference internal" href="../library/sqlite3.html#sqlite3.Cursor.lastrowid" title="sqlite3.Cursor.lastrowid"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sqlite3.Cursor.lastrowid</span></code></a> now supports the <code class="docutils literal notranslate"><span class="pre">REPLACE</span></code> statement.
  1407. (Contributed by Alex LordThorsen in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16864">bpo-16864</a>.)</p>
  1408. </section>
  1409. <section id="socket">
  1410. <h3>socket<a class="headerlink" href="#socket" title="Link to this heading">¶</a></h3>
  1411. <p>The <a class="reference internal" href="../library/socket.html#socket.socket.ioctl" title="socket.socket.ioctl"><code class="xref py py-func docutils literal notranslate"><span class="pre">ioctl()</span></code></a> function now supports the
  1412. <a class="reference internal" href="../library/socket.html#socket.SIO_LOOPBACK_FAST_PATH" title="socket.SIO_LOOPBACK_FAST_PATH"><code class="xref py py-const docutils literal notranslate"><span class="pre">SIO_LOOPBACK_FAST_PATH</span></code></a> control code.
  1413. (Contributed by Daniel Stokes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26536">bpo-26536</a>.)</p>
  1414. <p>The <a class="reference internal" href="../library/socket.html#socket.socket.getsockopt" title="socket.socket.getsockopt"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getsockopt()</span></code></a> constants <code class="docutils literal notranslate"><span class="pre">SO_DOMAIN</span></code>,
  1415. <code class="docutils literal notranslate"><span class="pre">SO_PROTOCOL</span></code>, <code class="docutils literal notranslate"><span class="pre">SO_PEERSEC</span></code>, and <code class="docutils literal notranslate"><span class="pre">SO_PASSSEC</span></code> are now supported.
  1416. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26907">bpo-26907</a>.)</p>
  1417. <p>The <a class="reference internal" href="../library/socket.html#socket.socket.setsockopt" title="socket.socket.setsockopt"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setsockopt()</span></code></a> now supports the
  1418. <code class="docutils literal notranslate"><span class="pre">setsockopt(level,</span> <span class="pre">optname,</span> <span class="pre">None,</span> <span class="pre">optlen:</span> <span class="pre">int)</span></code> form.
  1419. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27744">bpo-27744</a>.)</p>
  1420. <p>The socket module now supports the address family
  1421. <a class="reference internal" href="../library/socket.html#socket.AF_ALG" title="socket.AF_ALG"><code class="xref py py-const docutils literal notranslate"><span class="pre">AF_ALG</span></code></a> to interface with Linux Kernel crypto API. <code class="docutils literal notranslate"><span class="pre">ALG_*</span></code>,
  1422. <code class="docutils literal notranslate"><span class="pre">SOL_ALG</span></code> and <a class="reference internal" href="../library/socket.html#socket.socket.sendmsg_afalg" title="socket.socket.sendmsg_afalg"><code class="xref py py-meth docutils literal notranslate"><span class="pre">sendmsg_afalg()</span></code></a> were added.
  1423. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27744">bpo-27744</a> with support from
  1424. Victor Stinner.)</p>
  1425. <p>New Linux constants <code class="docutils literal notranslate"><span class="pre">TCP_USER_TIMEOUT</span></code> and <code class="docutils literal notranslate"><span class="pre">TCP_CONGESTION</span></code> were added.
  1426. (Contributed by Omar Sandoval, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26273">bpo-26273</a>).</p>
  1427. </section>
  1428. <section id="socketserver">
  1429. <h3>socketserver<a class="headerlink" href="#socketserver" title="Link to this heading">¶</a></h3>
  1430. <p>Servers based on the <a class="reference internal" href="../library/socketserver.html#module-socketserver" title="socketserver: A framework for network servers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socketserver</span></code></a> module, including those
  1431. defined in <a class="reference internal" href="../library/http.server.html#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a>, <a class="reference internal" href="../library/xmlrpc.server.html#module-xmlrpc.server" title="xmlrpc.server: Basic XML-RPC server implementations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpc.server</span></code></a> and
  1432. <a class="reference internal" href="../library/wsgiref.html#module-wsgiref.simple_server" title="wsgiref.simple_server: A simple WSGI HTTP server."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.simple_server</span></code></a>, now support the <a class="reference internal" href="../glossary.html#term-context-manager"><span class="xref std std-term">context manager</span></a>
  1433. protocol.
  1434. (Contributed by Aviv Palivoda in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26404">bpo-26404</a>.)</p>
  1435. <p>The <code class="xref py py-attr docutils literal notranslate"><span class="pre">wfile</span></code> attribute of
  1436. <a class="reference internal" href="../library/socketserver.html#socketserver.StreamRequestHandler" title="socketserver.StreamRequestHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">StreamRequestHandler</span></code></a> classes now implements
  1437. 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> writable interface. In particular,
  1438. calling <a class="reference internal" href="../library/io.html#io.BufferedIOBase.write" title="io.BufferedIOBase.write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code></a> is now guaranteed to send the
  1439. data in full. (Contributed by Martin Panter in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26721">bpo-26721</a>.)</p>
  1440. </section>
  1441. <section id="ssl">
  1442. <h3>ssl<a class="headerlink" href="#ssl" title="Link to this heading">¶</a></h3>
  1443. <p><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> supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2.
  1444. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26470">bpo-26470</a>.)</p>
  1445. <p>3DES has been removed from the default cipher suites and ChaCha20 Poly1305
  1446. cipher suites have been added.
  1447. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27850">bpo-27850</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27766">bpo-27766</a>.)</p>
  1448. <p><a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLContext</span></code></a> has better default configuration for options
  1449. and ciphers.
  1450. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28043">bpo-28043</a>.)</p>
  1451. <p>SSL session can be copied from one client-side connection to another
  1452. with the new <a class="reference internal" href="../library/ssl.html#ssl.SSLSession" title="ssl.SSLSession"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLSession</span></code></a> class. TLS session resumption can
  1453. speed up the initial handshake, reduce latency and improve performance
  1454. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=19500">bpo-19500</a> based on a draft by
  1455. Alex Warhawk.)</p>
  1456. <p>The new <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.get_ciphers" title="ssl.SSLContext.get_ciphers"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_ciphers()</span></code></a> method can be used to
  1457. get a list of enabled ciphers in order of cipher priority.</p>
  1458. <p>All constants and flags have been converted to <a class="reference internal" href="../library/enum.html#enum.IntEnum" title="enum.IntEnum"><code class="xref py py-class docutils literal notranslate"><span class="pre">IntEnum</span></code></a> and
  1459. <code class="xref py py-class docutils literal notranslate"><span class="pre">IntFlags</span></code>.
  1460. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28025">bpo-28025</a>.)</p>
  1461. <p>Server and client-side specific TLS protocols for <a class="reference internal" href="../library/ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">SSLContext</span></code></a>
  1462. were added.
  1463. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28085">bpo-28085</a>.)</p>
  1464. <p>Added <a class="reference internal" href="../library/ssl.html#ssl.SSLContext.post_handshake_auth" title="ssl.SSLContext.post_handshake_auth"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ssl.SSLContext.post_handshake_auth</span></code></a> to enable and
  1465. <a class="reference internal" href="../library/ssl.html#ssl.SSLSocket.verify_client_post_handshake" title="ssl.SSLSocket.verify_client_post_handshake"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ssl.SSLSocket.verify_client_post_handshake()</span></code></a> to initiate TLS 1.3
  1466. post-handshake authentication.
  1467. (Contributed by Christian Heimes in <a class="reference external" href="https://github.com/python/cpython/issues/78851">gh-78851</a>.)</p>
  1468. </section>
  1469. <section id="statistics">
  1470. <h3>statistics<a class="headerlink" href="#statistics" title="Link to this heading">¶</a></h3>
  1471. <p>A new <a class="reference internal" href="../library/statistics.html#statistics.harmonic_mean" title="statistics.harmonic_mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">harmonic_mean()</span></code></a> function has been added.
  1472. (Contributed by Steven D’Aprano in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27181">bpo-27181</a>.)</p>
  1473. </section>
  1474. <section id="struct">
  1475. <h3>struct<a class="headerlink" href="#struct" title="Link to this heading">¶</a></h3>
  1476. <p><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> now supports IEEE 754 half-precision floats via the <code class="docutils literal notranslate"><span class="pre">'e'</span></code>
  1477. format specifier.
  1478. (Contributed by Eli Stevens, Mark Dickinson in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=11734">bpo-11734</a>.)</p>
  1479. </section>
  1480. <section id="subprocess">
  1481. <h3>subprocess<a class="headerlink" href="#subprocess" title="Link to this heading">¶</a></h3>
  1482. <p><a class="reference internal" href="../library/subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a> destructor now emits a <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a> warning
  1483. if the child process is still running. Use the context manager protocol (<code class="docutils literal notranslate"><span class="pre">with</span>
  1484. <span class="pre">proc:</span> <span class="pre">...</span></code>) or explicitly call the <a class="reference internal" href="../library/subprocess.html#subprocess.Popen.wait" title="subprocess.Popen.wait"><code class="xref py py-meth docutils literal notranslate"><span class="pre">wait()</span></code></a> method to
  1485. read the exit status of the child process. (Contributed by Victor Stinner in
  1486. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26741">bpo-26741</a>.)</p>
  1487. <p>The <a class="reference internal" href="../library/subprocess.html#subprocess.Popen" title="subprocess.Popen"><code class="xref py py-class docutils literal notranslate"><span class="pre">subprocess.Popen</span></code></a> constructor and all functions that pass arguments
  1488. through to it now accept <em>encoding</em> and <em>errors</em> arguments. Specifying either
  1489. of these will enable text mode for the <em>stdin</em>, <em>stdout</em> and <em>stderr</em> streams.
  1490. (Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6135">bpo-6135</a>.)</p>
  1491. </section>
  1492. <section id="sys">
  1493. <h3>sys<a class="headerlink" href="#sys" title="Link to this heading">¶</a></h3>
  1494. <p>The new <a class="reference internal" href="../library/sys.html#sys.getfilesystemencodeerrors" title="sys.getfilesystemencodeerrors"><code class="xref py py-func docutils literal notranslate"><span class="pre">getfilesystemencodeerrors()</span></code></a> function returns the name of
  1495. the error mode used to convert between Unicode filenames and bytes filenames.
  1496. (Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27781">bpo-27781</a>.)</p>
  1497. <p>On Windows the return value of the <a class="reference internal" href="../library/sys.html#sys.getwindowsversion" title="sys.getwindowsversion"><code class="xref py py-func docutils literal notranslate"><span class="pre">getwindowsversion()</span></code></a> function
  1498. now includes the <em>platform_version</em> field which contains the accurate major
  1499. version, minor version and build number of the current operating system,
  1500. rather than the version that is being emulated for the process
  1501. (Contributed by Steve Dower in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27932">bpo-27932</a>.)</p>
  1502. </section>
  1503. <section id="telnetlib">
  1504. <h3>telnetlib<a class="headerlink" href="#telnetlib" title="Link to this heading">¶</a></h3>
  1505. <p><a class="reference internal" href="../library/telnetlib.html#telnetlib.Telnet" title="telnetlib.Telnet"><code class="xref py py-class docutils literal notranslate"><span class="pre">Telnet</span></code></a> is now a context manager (contributed by
  1506. Stéphane Wirtel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25485">bpo-25485</a>).</p>
  1507. </section>
  1508. <section id="time">
  1509. <h3>time<a class="headerlink" href="#time" title="Link to this heading">¶</a></h3>
  1510. <p>The <a class="reference internal" href="../library/time.html#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">struct_time</span></code></a> attributes <code class="xref py py-attr docutils literal notranslate"><span class="pre">tm_gmtoff</span></code> and
  1511. <code class="xref py py-attr docutils literal notranslate"><span class="pre">tm_zone</span></code> are now available on all platforms.</p>
  1512. </section>
  1513. <section id="timeit">
  1514. <h3>timeit<a class="headerlink" href="#timeit" title="Link to this heading">¶</a></h3>
  1515. <p>The new <a class="reference internal" href="../library/timeit.html#timeit.Timer.autorange" title="timeit.Timer.autorange"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Timer.autorange()</span></code></a> convenience
  1516. method has been added to call <a class="reference internal" href="../library/timeit.html#timeit.Timer.timeit" title="timeit.Timer.timeit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Timer.timeit()</span></code></a>
  1517. repeatedly so that the total run time is greater or equal to 200 milliseconds.
  1518. (Contributed by Steven D’Aprano in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=6422">bpo-6422</a>.)</p>
  1519. <p><a class="reference internal" href="../library/timeit.html#module-timeit" title="timeit: Measure the execution time of small code snippets."><code class="xref py py-mod docutils literal notranslate"><span class="pre">timeit</span></code></a> now warns when there is substantial (4x) variance
  1520. between best and worst times.
  1521. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23552">bpo-23552</a>.)</p>
  1522. </section>
  1523. <section id="tkinter">
  1524. <h3>tkinter<a class="headerlink" href="#tkinter" title="Link to this heading">¶</a></h3>
  1525. <p>Added methods <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_add()</span></code>,
  1526. <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_remove()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_info()</span></code>
  1527. in the <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.Variable</span></code> class. They replace old methods
  1528. <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_variable()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace()</span></code>,
  1529. <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_vdelete()</span></code> and
  1530. <code class="xref py py-meth docutils literal notranslate"><span class="pre">trace_vinfo()</span></code> that use obsolete Tcl commands and might
  1531. not work in future versions of Tcl.
  1532. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22115">bpo-22115</a>).</p>
  1533. </section>
  1534. <section id="traceback">
  1535. <span id="whatsnew36-traceback"></span><h3>traceback<a class="headerlink" href="#traceback" title="Link to this heading">¶</a></h3>
  1536. <p>Both the traceback module and the interpreter’s builtin exception display now
  1537. abbreviate long sequences of repeated lines in tracebacks as shown in the
  1538. following example:</p>
  1539. <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">f</span><span class="p">():</span> <span class="n">f</span><span class="p">()</span>
  1540. <span class="gp">...</span>
  1541. <span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">()</span>
  1542. <span class="gt">Traceback (most recent call last):</span>
  1543. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">&lt;module&gt;</span>
  1544. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">f</span>
  1545. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">f</span>
  1546. File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n">f</span>
  1547. <span class="gr"> [Previous line repeated 995 more times]</span>
  1548. <span class="gr">RecursionError</span>: <span class="n">maximum recursion depth exceeded</span>
  1549. </pre></div>
  1550. </div>
  1551. <p>(Contributed by Emanuel Barry in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26823">bpo-26823</a>.)</p>
  1552. </section>
  1553. <section id="tracemalloc">
  1554. <h3>tracemalloc<a class="headerlink" href="#tracemalloc" title="Link to this heading">¶</a></h3>
  1555. <p>The <a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a> module now supports tracing memory allocations in
  1556. multiple different address spaces.</p>
  1557. <p>The new <a class="reference internal" href="../library/tracemalloc.html#tracemalloc.DomainFilter" title="tracemalloc.DomainFilter"><code class="xref py py-class docutils literal notranslate"><span class="pre">DomainFilter</span></code></a> filter class has been added
  1558. to filter block traces by their address space (domain).</p>
  1559. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26588">bpo-26588</a>.)</p>
  1560. </section>
  1561. <section id="typing">
  1562. <span id="whatsnew36-typing"></span><h3>typing<a class="headerlink" href="#typing" title="Link to this heading">¶</a></h3>
  1563. <p>Since the <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module is <a class="reference internal" href="../glossary.html#term-provisional-API"><span class="xref std std-term">provisional</span></a>,
  1564. all changes introduced in Python 3.6 have also been
  1565. backported to Python 3.5.x.</p>
  1566. <p>The <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module has a much improved support for generic type
  1567. aliases. For example <code class="docutils literal notranslate"><span class="pre">Dict[str,</span> <span class="pre">Tuple[S,</span> <span class="pre">T]]</span></code> is now a valid
  1568. type annotation.
  1569. (Contributed by Guido van Rossum in <a class="reference external" href="https://github.com/python/typing/pull/195">Github #195</a>.)</p>
  1570. <p>The <a class="reference internal" href="../library/typing.html#typing.ContextManager" title="typing.ContextManager"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.ContextManager</span></code></a> class has been added for
  1571. representing <a class="reference internal" href="../library/contextlib.html#contextlib.AbstractContextManager" title="contextlib.AbstractContextManager"><code class="xref py py-class docutils literal notranslate"><span class="pre">contextlib.AbstractContextManager</span></code></a>.
  1572. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25609">bpo-25609</a>.)</p>
  1573. <p>The <a class="reference internal" href="../library/typing.html#typing.Collection" title="typing.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">typing.Collection</span></code></a> class has been added for
  1574. representing <a class="reference internal" href="../library/collections.abc.html#collections.abc.Collection" title="collections.abc.Collection"><code class="xref py py-class docutils literal notranslate"><span class="pre">collections.abc.Collection</span></code></a>.
  1575. (Contributed by Ivan Levkivskyi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27598">bpo-27598</a>.)</p>
  1576. <p>The <a class="reference internal" href="../library/typing.html#typing.ClassVar" title="typing.ClassVar"><code class="xref py py-const docutils literal notranslate"><span class="pre">typing.ClassVar</span></code></a> type construct has been added to
  1577. mark class variables. As introduced in <span class="target" id="index-33"></span><a class="pep reference external" href="https://peps.python.org/pep-0526/"><strong>PEP 526</strong></a>, a variable annotation
  1578. wrapped in ClassVar indicates that a given attribute is intended to be used as
  1579. a class variable and should not be set on instances of that class.
  1580. (Contributed by Ivan Levkivskyi in <a class="reference external" href="https://github.com/python/typing/pull/280">Github #280</a>.)</p>
  1581. <p>A new <a class="reference internal" href="../library/typing.html#typing.TYPE_CHECKING" title="typing.TYPE_CHECKING"><code class="xref py py-const docutils literal notranslate"><span class="pre">TYPE_CHECKING</span></code></a> constant that is assumed to be
  1582. <code class="docutils literal notranslate"><span class="pre">True</span></code> by the static type checkers, but is <code class="docutils literal notranslate"><span class="pre">False</span></code> at runtime.
  1583. (Contributed by Guido van Rossum in <a class="reference external" href="https://github.com/python/typing/issues/230">Github #230</a>.)</p>
  1584. <p>A new <a class="reference internal" href="../library/typing.html#typing.NewType" title="typing.NewType"><code class="xref py py-func docutils literal notranslate"><span class="pre">NewType()</span></code></a> helper function has been added to create
  1585. lightweight distinct types for annotations:</p>
  1586. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">NewType</span>
  1587. <span class="n">UserId</span> <span class="o">=</span> <span class="n">NewType</span><span class="p">(</span><span class="s1">&#39;UserId&#39;</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
  1588. <span class="n">some_id</span> <span class="o">=</span> <span class="n">UserId</span><span class="p">(</span><span class="mi">524313</span><span class="p">)</span>
  1589. </pre></div>
  1590. </div>
  1591. <p>The static type checker will treat the new type as if it were a subclass
  1592. of the original type. (Contributed by Ivan Levkivskyi in <a class="reference external" href="https://github.com/python/typing/issues/189">Github #189</a>.)</p>
  1593. </section>
  1594. <section id="unicodedata">
  1595. <h3>unicodedata<a class="headerlink" href="#unicodedata" title="Link to this heading">¶</a></h3>
  1596. <p>The <a class="reference internal" href="../library/unicodedata.html#module-unicodedata" title="unicodedata: Access the Unicode Database."><code class="xref py py-mod docutils literal notranslate"><span class="pre">unicodedata</span></code></a> module now uses data from <a class="reference external" href="https://unicode.org/versions/Unicode9.0.0/">Unicode 9.0.0</a>.
  1597. (Contributed by Benjamin Peterson.)</p>
  1598. </section>
  1599. <section id="unittest-mock">
  1600. <h3>unittest.mock<a class="headerlink" href="#unittest-mock" title="Link to this heading">¶</a></h3>
  1601. <p>The <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.Mock" title="unittest.mock.Mock"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mock</span></code></a> class has the following improvements:</p>
  1602. <ul class="simple">
  1603. <li><p>Two new methods, <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.Mock.assert_called" title="unittest.mock.Mock.assert_called"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Mock.assert_called()</span></code></a> and <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.Mock.assert_called_once" title="unittest.mock.Mock.assert_called_once"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Mock.assert_called_once()</span></code></a> to check if the mock object
  1604. was called.
  1605. (Contributed by Amit Saha in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26323">bpo-26323</a>.)</p></li>
  1606. <li><p>The <a class="reference internal" href="../library/unittest.mock.html#unittest.mock.Mock.reset_mock" title="unittest.mock.Mock.reset_mock"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Mock.reset_mock()</span></code></a> method
  1607. now has two optional keyword only arguments: <em>return_value</em> and
  1608. <em>side_effect</em>.
  1609. (Contributed by Kushal Das in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21271">bpo-21271</a>.)</p></li>
  1610. </ul>
  1611. </section>
  1612. <section id="urllib-request">
  1613. <h3>urllib.request<a class="headerlink" href="#urllib-request" title="Link to this heading">¶</a></h3>
  1614. <p>If a HTTP request has a file or iterable body (other than a
  1615. bytes object) but no <code class="docutils literal notranslate"><span class="pre">Content-Length</span></code> header, rather than
  1616. throwing an error, <code class="xref py py-class docutils literal notranslate"><span class="pre">AbstractHTTPHandler</span></code> now
  1617. falls back to use chunked transfer encoding.
  1618. (Contributed by Demian Brecht and Rolf Krahl in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12319">bpo-12319</a>.)</p>
  1619. </section>
  1620. <section id="urllib-robotparser">
  1621. <h3>urllib.robotparser<a class="headerlink" href="#urllib-robotparser" title="Link to this heading">¶</a></h3>
  1622. <p><a class="reference internal" href="../library/urllib.robotparser.html#urllib.robotparser.RobotFileParser" title="urllib.robotparser.RobotFileParser"><code class="xref py py-class docutils literal notranslate"><span class="pre">RobotFileParser</span></code></a> now supports the <code class="docutils literal notranslate"><span class="pre">Crawl-delay</span></code> and
  1623. <code class="docutils literal notranslate"><span class="pre">Request-rate</span></code> extensions.
  1624. (Contributed by Nikolay Bogoychev in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16099">bpo-16099</a>.)</p>
  1625. </section>
  1626. <section id="venv">
  1627. <h3>venv<a class="headerlink" href="#venv" title="Link to this heading">¶</a></h3>
  1628. <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> accepts a new parameter <code class="docutils literal notranslate"><span class="pre">--prompt</span></code>. This parameter provides an
  1629. alternative prefix for the virtual environment. (Proposed by Łukasz Balcerzak
  1630. and ported to 3.6 by Stéphane Wirtel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22829">bpo-22829</a>.)</p>
  1631. </section>
  1632. <section id="warnings">
  1633. <h3>warnings<a class="headerlink" href="#warnings" title="Link to this heading">¶</a></h3>
  1634. <p>A new optional <em>source</em> parameter has been added to the
  1635. <a class="reference internal" href="../library/warnings.html#warnings.warn_explicit" title="warnings.warn_explicit"><code class="xref py py-func docutils literal notranslate"><span class="pre">warnings.warn_explicit()</span></code></a> function: the destroyed object which emitted a
  1636. <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a>. A <em>source</em> attribute has also been added to
  1637. <code class="xref py py-class docutils literal notranslate"><span class="pre">warnings.WarningMessage</span></code> (contributed by Victor Stinner in
  1638. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26568">bpo-26568</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26567">bpo-26567</a>).</p>
  1639. <p>When a <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a> warning is logged, the <a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a> module is now
  1640. used to try to retrieve the traceback where the destroyed object was allocated.</p>
  1641. <p>Example with the script <code class="docutils literal notranslate"><span class="pre">example.py</span></code>:</p>
  1642. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">warnings</span>
  1643. <span class="k">def</span> <span class="nf">func</span><span class="p">():</span>
  1644. <span class="k">return</span> <span class="nb">open</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span>
  1645. <span class="n">f</span> <span class="o">=</span> <span class="n">func</span><span class="p">()</span>
  1646. <span class="n">f</span> <span class="o">=</span> <span class="kc">None</span>
  1647. </pre></div>
  1648. </div>
  1649. <p>Output of the command <code class="docutils literal notranslate"><span class="pre">python3.6</span> <span class="pre">-Wd</span> <span class="pre">-X</span> <span class="pre">tracemalloc=5</span> <span class="pre">example.py</span></code>:</p>
  1650. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">example</span><span class="o">.</span><span class="n">py</span><span class="p">:</span><span class="mi">7</span><span class="p">:</span> <span class="ne">ResourceWarning</span><span class="p">:</span> <span class="n">unclosed</span> <span class="n">file</span> <span class="o">&lt;</span><span class="n">_io</span><span class="o">.</span><span class="n">TextIOWrapper</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;example.py&#39;</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;r&#39;</span> <span class="n">encoding</span><span class="o">=</span><span class="s1">&#39;UTF-8&#39;</span><span class="o">&gt;</span>
  1651. <span class="n">f</span> <span class="o">=</span> <span class="kc">None</span>
  1652. <span class="n">Object</span> <span class="n">allocated</span> <span class="n">at</span> <span class="p">(</span><span class="n">most</span> <span class="n">recent</span> <span class="n">call</span> <span class="n">first</span><span class="p">):</span>
  1653. <span class="n">File</span> <span class="s2">&quot;example.py&quot;</span><span class="p">,</span> <span class="n">lineno</span> <span class="mi">4</span>
  1654. <span class="k">return</span> <span class="nb">open</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span>
  1655. <span class="n">File</span> <span class="s2">&quot;example.py&quot;</span><span class="p">,</span> <span class="n">lineno</span> <span class="mi">6</span>
  1656. <span class="n">f</span> <span class="o">=</span> <span class="n">func</span><span class="p">()</span>
  1657. </pre></div>
  1658. </div>
  1659. <p>The “Object allocated at” traceback is new and is only displayed if
  1660. <a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a> is tracing Python memory allocations and if the
  1661. <a class="reference internal" href="../library/warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> module was already imported.</p>
  1662. </section>
  1663. <section id="winreg">
  1664. <h3>winreg<a class="headerlink" href="#winreg" title="Link to this heading">¶</a></h3>
  1665. <p>Added the 64-bit integer type <a class="reference internal" href="../library/winreg.html#winreg.REG_QWORD" title="winreg.REG_QWORD"><code class="xref py py-data docutils literal notranslate"><span class="pre">REG_QWORD</span></code></a>.
  1666. (Contributed by Clement Rouault in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23026">bpo-23026</a>.)</p>
  1667. </section>
  1668. <section id="winsound">
  1669. <h3>winsound<a class="headerlink" href="#winsound" title="Link to this heading">¶</a></h3>
  1670. <p>Allowed keyword arguments to be passed to <a class="reference internal" href="../library/winsound.html#winsound.Beep" title="winsound.Beep"><code class="xref py py-func docutils literal notranslate"><span class="pre">Beep</span></code></a>,
  1671. <a class="reference internal" href="../library/winsound.html#winsound.MessageBeep" title="winsound.MessageBeep"><code class="xref py py-func docutils literal notranslate"><span class="pre">MessageBeep</span></code></a>, and <a class="reference internal" href="../library/winsound.html#winsound.PlaySound" title="winsound.PlaySound"><code class="xref py py-func docutils literal notranslate"><span class="pre">PlaySound</span></code></a> (<a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27982">bpo-27982</a>).</p>
  1672. </section>
  1673. <section id="xmlrpc-client">
  1674. <h3>xmlrpc.client<a class="headerlink" href="#xmlrpc-client" title="Link to this heading">¶</a></h3>
  1675. <p>The <a class="reference internal" href="../library/xmlrpc.client.html#module-xmlrpc.client" title="xmlrpc.client: XML-RPC client access."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpc.client</span></code></a> module now supports unmarshalling
  1676. additional data types used by the Apache XML-RPC implementation
  1677. for numerics and <code class="docutils literal notranslate"><span class="pre">None</span></code>.
  1678. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26885">bpo-26885</a>.)</p>
  1679. </section>
  1680. <section id="zipfile">
  1681. <h3>zipfile<a class="headerlink" href="#zipfile" title="Link to this heading">¶</a></h3>
  1682. <p>A new <a class="reference internal" href="../library/zipfile.html#zipfile.ZipInfo.from_file" title="zipfile.ZipInfo.from_file"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ZipInfo.from_file()</span></code></a> class method
  1683. allows making a <a class="reference internal" href="../library/zipfile.html#zipfile.ZipInfo" title="zipfile.ZipInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">ZipInfo</span></code></a> instance from a filesystem file.
  1684. A new <a class="reference internal" href="../library/zipfile.html#zipfile.ZipInfo.is_dir" title="zipfile.ZipInfo.is_dir"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ZipInfo.is_dir()</span></code></a> method can be used
  1685. to check if the <a class="reference internal" href="../library/zipfile.html#zipfile.ZipInfo" title="zipfile.ZipInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">ZipInfo</span></code></a> instance represents a directory.
  1686. (Contributed by Thomas Kluyver in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26039">bpo-26039</a>.)</p>
  1687. <p>The <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile.open" title="zipfile.ZipFile.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ZipFile.open()</span></code></a> method can now be used to
  1688. write data into a ZIP file, as well as for extracting data.
  1689. (Contributed by Thomas Kluyver in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26039">bpo-26039</a>.)</p>
  1690. </section>
  1691. <section id="zlib">
  1692. <h3>zlib<a class="headerlink" href="#zlib" title="Link to this heading">¶</a></h3>
  1693. <p>The <a class="reference internal" href="../library/zlib.html#zlib.compress" title="zlib.compress"><code class="xref py py-func docutils literal notranslate"><span class="pre">compress()</span></code></a> and <a class="reference internal" href="../library/zlib.html#zlib.decompress" title="zlib.decompress"><code class="xref py py-func docutils literal notranslate"><span class="pre">decompress()</span></code></a> functions now accept
  1694. keyword arguments.
  1695. (Contributed by Aviv Palivoda in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26243">bpo-26243</a> and
  1696. Xiang Zhang in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=16764">bpo-16764</a> respectively.)</p>
  1697. </section>
  1698. </section>
  1699. <section id="optimizations">
  1700. <h2>Optimizations<a class="headerlink" href="#optimizations" title="Link to this heading">¶</a></h2>
  1701. <ul class="simple">
  1702. <li><p>The Python interpreter now uses a 16-bit wordcode instead of bytecode which
  1703. made a number of opcode optimizations possible.
  1704. (Contributed by Demur Rumed with input and reviews from
  1705. Serhiy Storchaka and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26647">bpo-26647</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28050">bpo-28050</a>.)</p></li>
  1706. <li><p>The <a class="reference internal" href="../library/asyncio-future.html#asyncio.Future" title="asyncio.Future"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Future</span></code></a> class now has an optimized C implementation.
  1707. (Contributed by Yury Selivanov and INADA Naoki in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26081">bpo-26081</a>.)</p></li>
  1708. <li><p>The <a class="reference internal" href="../library/asyncio-task.html#asyncio.Task" title="asyncio.Task"><code class="xref py py-class docutils literal notranslate"><span class="pre">asyncio.Task</span></code></a> class now has an optimized
  1709. C implementation. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28544">bpo-28544</a>.)</p></li>
  1710. <li><p>Various implementation improvements in the <a class="reference internal" href="../library/typing.html#module-typing" title="typing: Support for type hints (see :pep:`484`)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">typing</span></code></a> module
  1711. (such as caching of generic types) allow up to 30 times performance
  1712. improvements and reduced memory footprint.</p></li>
  1713. <li><p>The ASCII decoder is now up to 60 times as fast for error handlers
  1714. <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code>, <code class="docutils literal notranslate"><span class="pre">ignore</span></code> and <code class="docutils literal notranslate"><span class="pre">replace</span></code> (Contributed
  1715. by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=24870">bpo-24870</a>).</p></li>
  1716. <li><p>The ASCII and the Latin1 encoders are now up to 3 times as fast for the
  1717. error handler <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code>
  1718. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25227">bpo-25227</a>).</p></li>
  1719. <li><p>The UTF-8 encoder is now up to 75 times as fast for error handlers
  1720. <code class="docutils literal notranslate"><span class="pre">ignore</span></code>, <code class="docutils literal notranslate"><span class="pre">replace</span></code>, <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code>, <code class="docutils literal notranslate"><span class="pre">surrogatepass</span></code> (Contributed
  1721. by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25267">bpo-25267</a>).</p></li>
  1722. <li><p>The UTF-8 decoder is now up to 15 times as fast for error handlers
  1723. <code class="docutils literal notranslate"><span class="pre">ignore</span></code>, <code class="docutils literal notranslate"><span class="pre">replace</span></code> and <code class="docutils literal notranslate"><span class="pre">surrogateescape</span></code> (Contributed
  1724. by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25301">bpo-25301</a>).</p></li>
  1725. <li><p><code class="docutils literal notranslate"><span class="pre">bytes</span> <span class="pre">%</span> <span class="pre">args</span></code> is now up to 2 times faster. (Contributed by Victor Stinner
  1726. in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25349">bpo-25349</a>).</p></li>
  1727. <li><p><code class="docutils literal notranslate"><span class="pre">bytearray</span> <span class="pre">%</span> <span class="pre">args</span></code> is now between 2.5 and 5 times faster. (Contributed by
  1728. Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25399">bpo-25399</a>).</p></li>
  1729. <li><p>Optimize <a class="reference internal" href="../library/stdtypes.html#bytes.fromhex" title="bytes.fromhex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytes.fromhex()</span></code></a> and <a class="reference internal" href="../library/stdtypes.html#bytearray.fromhex" title="bytearray.fromhex"><code class="xref py py-meth docutils literal notranslate"><span class="pre">bytearray.fromhex()</span></code></a>: they are now
  1730. between 2x and 3.5x faster. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25401">bpo-25401</a>).</p></li>
  1731. <li><p>Optimize <code class="docutils literal notranslate"><span class="pre">bytes.replace(b'',</span> <span class="pre">b'.')</span></code> and <code class="docutils literal notranslate"><span class="pre">bytearray.replace(b'',</span> <span class="pre">b'.')</span></code>:
  1732. up to 80% faster. (Contributed by Josh Snider in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26574">bpo-26574</a>).</p></li>
  1733. <li><p>Allocator functions of the <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a> domain
  1734. (<a class="reference internal" href="../c-api/memory.html#c.PYMEM_DOMAIN_MEM" title="PYMEM_DOMAIN_MEM"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PYMEM_DOMAIN_MEM</span></code></a>) now use the <a class="reference internal" href="../c-api/memory.html#pymalloc"><span class="std std-ref">pymalloc memory allocator</span></a> instead of <code class="xref c c-func docutils literal notranslate"><span class="pre">malloc()</span></code> function of the C library. The
  1735. pymalloc allocator is optimized for objects smaller or equal to 512 bytes
  1736. with a short lifetime, and use <code class="xref c c-func docutils literal notranslate"><span class="pre">malloc()</span></code> for larger memory blocks.
  1737. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26249">bpo-26249</a>).</p></li>
  1738. <li><p><a class="reference internal" href="../library/pickle.html#pickle.load" title="pickle.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">pickle.load()</span></code></a> and <a class="reference internal" href="../library/pickle.html#pickle.loads" title="pickle.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">pickle.loads()</span></code></a> are now up to 10% faster when
  1739. deserializing many small objects (Contributed by Victor Stinner in
  1740. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27056">bpo-27056</a>).</p></li>
  1741. <li><p>Passing <a class="reference internal" href="../glossary.html#term-keyword-argument"><span class="xref std std-term">keyword arguments</span></a> to a function has an
  1742. overhead in comparison with passing <a class="reference internal" href="../glossary.html#term-positional-argument"><span class="xref std std-term">positional arguments</span></a>. Now in extension functions implemented with using
  1743. Argument Clinic this overhead is significantly decreased.
  1744. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27574">bpo-27574</a>).</p></li>
  1745. <li><p>Optimized <a class="reference internal" href="../library/glob.html#glob.glob" title="glob.glob"><code class="xref py py-func docutils literal notranslate"><span class="pre">glob()</span></code></a> and <a class="reference internal" href="../library/glob.html#glob.iglob" title="glob.iglob"><code class="xref py py-func docutils literal notranslate"><span class="pre">iglob()</span></code></a> functions in the
  1746. <a class="reference internal" href="../library/glob.html#module-glob" title="glob: Unix shell style pathname pattern expansion."><code class="xref py py-mod docutils literal notranslate"><span class="pre">glob</span></code></a> module; they are now about 3–6 times faster.
  1747. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25596">bpo-25596</a>).</p></li>
  1748. <li><p>Optimized globbing in <a class="reference internal" href="../library/pathlib.html#module-pathlib" title="pathlib: Object-oriented filesystem paths"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pathlib</span></code></a> by using <a class="reference internal" href="../library/os.html#os.scandir" title="os.scandir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.scandir()</span></code></a>;
  1749. it is now about 1.5–4 times faster.
  1750. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26032">bpo-26032</a>).</p></li>
  1751. <li><p><a class="reference internal" href="../library/xml.etree.elementtree.html#module-xml.etree.ElementTree" title="xml.etree.ElementTree: Implementation of the ElementTree API."><code class="xref py py-class docutils literal notranslate"><span class="pre">xml.etree.ElementTree</span></code></a> parsing, iteration and deepcopy performance
  1752. has been significantly improved.
  1753. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25638">bpo-25638</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25873">bpo-25873</a>,
  1754. and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25869">bpo-25869</a>.)</p></li>
  1755. <li><p>Creation of <a class="reference internal" href="../library/fractions.html#fractions.Fraction" title="fractions.Fraction"><code class="xref py py-class docutils literal notranslate"><span class="pre">fractions.Fraction</span></code></a> instances from floats and
  1756. decimals is now 2 to 3 times faster.
  1757. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25971">bpo-25971</a>.)</p></li>
  1758. </ul>
  1759. </section>
  1760. <section id="build-and-c-api-changes">
  1761. <h2>Build and C API Changes<a class="headerlink" href="#build-and-c-api-changes" title="Link to this heading">¶</a></h2>
  1762. <ul class="simple">
  1763. <li><p>Python now requires some C99 support in the toolchain to build.
  1764. Most notably, Python now uses standard integer types and macros in
  1765. place of custom macros like <code class="docutils literal notranslate"><span class="pre">PY_LONG_LONG</span></code>.
  1766. For more information, see <span class="target" id="index-34"></span><a class="pep reference external" href="https://peps.python.org/pep-0007/"><strong>PEP 7</strong></a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17884">bpo-17884</a>.</p></li>
  1767. <li><p>Cross-compiling CPython with the Android NDK and the Android API level set to
  1768. 21 (Android 5.0 Lollipop) or greater runs successfully. While Android is not
  1769. yet a supported platform, the Python test suite runs on the Android emulator
  1770. with only about 16 tests failures. See the Android meta-issue <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26865">bpo-26865</a>.</p></li>
  1771. <li><p>The <code class="docutils literal notranslate"><span class="pre">--enable-optimizations</span></code> configure flag has been added. Turning it on
  1772. will activate expensive optimizations like PGO.
  1773. (Original patch by Alecsandru Patrascu of Intel in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26359">bpo-26359</a>.)</p></li>
  1774. <li><p>The <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">GIL</span></a> must now be held when allocator
  1775. functions of <a class="reference internal" href="../c-api/memory.html#c.PYMEM_DOMAIN_OBJ" title="PYMEM_DOMAIN_OBJ"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PYMEM_DOMAIN_OBJ</span></code></a> (ex: <a class="reference internal" href="../c-api/memory.html#c.PyObject_Malloc" title="PyObject_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Malloc()</span></code></a>) and
  1776. <a class="reference internal" href="../c-api/memory.html#c.PYMEM_DOMAIN_MEM" title="PYMEM_DOMAIN_MEM"><code class="xref c c-macro docutils literal notranslate"><span class="pre">PYMEM_DOMAIN_MEM</span></code></a> (ex: <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a>) domains are called.</p></li>
  1777. <li><p>New <a class="reference internal" href="../c-api/init.html#c.Py_FinalizeEx" title="Py_FinalizeEx"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_FinalizeEx()</span></code></a> API which indicates if flushing buffered data
  1778. failed.
  1779. (Contributed by Martin Panter in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5319">bpo-5319</a>.)</p></li>
  1780. <li><p><a class="reference internal" href="../c-api/arg.html#c.PyArg_ParseTupleAndKeywords" title="PyArg_ParseTupleAndKeywords"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyArg_ParseTupleAndKeywords()</span></code></a> now supports <a class="reference internal" href="../glossary.html#positional-only-parameter"><span class="std std-ref">positional-only
  1781. parameters</span></a>. Positional-only parameters are
  1782. defined by empty names.
  1783. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26282">bpo-26282</a>).</p></li>
  1784. <li><p><code class="docutils literal notranslate"><span class="pre">PyTraceback_Print</span></code> method now abbreviates long sequences of repeated lines
  1785. as <code class="docutils literal notranslate"><span class="pre">&quot;[Previous</span> <span class="pre">line</span> <span class="pre">repeated</span> <span class="pre">{count}</span> <span class="pre">more</span> <span class="pre">times]&quot;</span></code>.
  1786. (Contributed by Emanuel Barry in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26823">bpo-26823</a>.)</p></li>
  1787. <li><p>The new <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetImportErrorSubclass" title="PyErr_SetImportErrorSubclass"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetImportErrorSubclass()</span></code></a> function allows for
  1788. specifying a subclass of <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> to raise.
  1789. (Contributed by Eric Snow in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=15767">bpo-15767</a>.)</p></li>
  1790. <li><p>The new <a class="reference internal" href="../c-api/exceptions.html#c.PyErr_ResourceWarning" title="PyErr_ResourceWarning"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_ResourceWarning()</span></code></a> function can be used to generate
  1791. a <a class="reference internal" href="../library/exceptions.html#ResourceWarning" title="ResourceWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ResourceWarning</span></code></a> providing the source of the resource allocation.
  1792. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26567">bpo-26567</a>.)</p></li>
  1793. <li><p>The new <a class="reference internal" href="../c-api/sys.html#c.PyOS_FSPath" title="PyOS_FSPath"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyOS_FSPath()</span></code></a> function returns the file system
  1794. representation of a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.
  1795. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27186">bpo-27186</a>.)</p></li>
  1796. <li><p>The <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FSConverter" title="PyUnicode_FSConverter"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FSConverter()</span></code></a> and <a class="reference internal" href="../c-api/unicode.html#c.PyUnicode_FSDecoder" title="PyUnicode_FSDecoder"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_FSDecoder()</span></code></a>
  1797. functions will now accept <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like objects</span></a>.</p></li>
  1798. </ul>
  1799. </section>
  1800. <section id="other-improvements">
  1801. <h2>Other Improvements<a class="headerlink" href="#other-improvements" title="Link to this heading">¶</a></h2>
  1802. <ul>
  1803. <li><p>When <a class="reference internal" href="../using/cmdline.html#cmdoption-version"><code class="xref std std-option docutils literal notranslate"><span class="pre">--version</span></code></a> (short form: <a class="reference internal" href="../using/cmdline.html#cmdoption-V"><code class="xref std std-option docutils literal notranslate"><span class="pre">-V</span></code></a>) is supplied twice,
  1804. Python prints <a class="reference internal" href="../library/sys.html#sys.version" title="sys.version"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.version</span></code></a> for detailed information.</p>
  1805. <div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>./python<span class="w"> </span>-VV
  1806. <span class="go">Python 3.6.0b4+ (3.6:223967b49e49+, Nov 21 2016, 20:55:04)</span>
  1807. <span class="go">[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]</span>
  1808. </pre></div>
  1809. </div>
  1810. </li>
  1811. </ul>
  1812. </section>
  1813. <section id="deprecated">
  1814. <h2>Deprecated<a class="headerlink" href="#deprecated" title="Link to this heading">¶</a></h2>
  1815. <section id="new-keywords">
  1816. <h3>New Keywords<a class="headerlink" href="#new-keywords" title="Link to this heading">¶</a></h3>
  1817. <p><code class="docutils literal notranslate"><span class="pre">async</span></code> and <code class="docutils literal notranslate"><span class="pre">await</span></code> are not recommended to be used as variable, class,
  1818. function or module names. Introduced by <span class="target" id="index-35"></span><a class="pep reference external" href="https://peps.python.org/pep-0492/"><strong>PEP 492</strong></a> in Python 3.5, they will
  1819. become proper keywords in Python 3.7. Starting in Python 3.6, the use of
  1820. <code class="docutils literal notranslate"><span class="pre">async</span></code> or <code class="docutils literal notranslate"><span class="pre">await</span></code> as names will generate a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>.</p>
  1821. </section>
  1822. <section id="deprecated-python-behavior">
  1823. <h3>Deprecated Python behavior<a class="headerlink" href="#deprecated-python-behavior" title="Link to this heading">¶</a></h3>
  1824. <p>Raising the <a class="reference internal" href="../library/exceptions.html#StopIteration" title="StopIteration"><code class="xref py py-exc docutils literal notranslate"><span class="pre">StopIteration</span></code></a> exception inside a generator will now
  1825. generate a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>, and will trigger a <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>
  1826. in Python 3.7. See <a class="reference internal" href="3.5.html#whatsnew-pep-479"><span class="std std-ref">PEP 479: Change StopIteration handling inside generators</span></a> for details.</p>
  1827. <p>The <code class="xref py py-meth docutils literal notranslate"><span class="pre">__aiter__()</span></code> method is now expected to return an asynchronous
  1828. iterator directly instead of returning an awaitable as previously.
  1829. Doing the former will trigger a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>. Backward
  1830. compatibility will be removed in Python 3.7.
  1831. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27243">bpo-27243</a>.)</p>
  1832. <p>A backslash-character pair that is not a valid escape sequence now generates
  1833. a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a>. Although this will eventually become a
  1834. <a class="reference internal" href="../library/exceptions.html#SyntaxError" title="SyntaxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SyntaxError</span></code></a>, that will not be for several Python releases.
  1835. (Contributed by Emanuel Barry in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27364">bpo-27364</a>.)</p>
  1836. <p>When performing a relative import, falling back on <code class="docutils literal notranslate"><span class="pre">__name__</span></code> and
  1837. <code class="docutils literal notranslate"><span class="pre">__path__</span></code> from the calling module when <code class="docutils literal notranslate"><span class="pre">__spec__</span></code> or
  1838. <code class="docutils literal notranslate"><span class="pre">__package__</span></code> are not defined now raises an <a class="reference internal" href="../library/exceptions.html#ImportWarning" title="ImportWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportWarning</span></code></a>.
  1839. (Contributed by Rose Ames in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25791">bpo-25791</a>.)</p>
  1840. </section>
  1841. <section id="deprecated-python-modules-functions-and-methods">
  1842. <h3>Deprecated Python modules, functions and methods<a class="headerlink" href="#deprecated-python-modules-functions-and-methods" title="Link to this heading">¶</a></h3>
  1843. <section id="asynchat">
  1844. <h4>asynchat<a class="headerlink" href="#asynchat" title="Link to this heading">¶</a></h4>
  1845. <p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">asynchat</span></code> has been deprecated in favor of <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a>.
  1846. (Contributed by Mariatta in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25002">bpo-25002</a>.)</p>
  1847. </section>
  1848. <section id="asyncore">
  1849. <h4>asyncore<a class="headerlink" href="#asyncore" title="Link to this heading">¶</a></h4>
  1850. <p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncore</span></code> has been deprecated in favor of <a class="reference internal" href="../library/asyncio.html#module-asyncio" title="asyncio: Asynchronous I/O."><code class="xref py py-mod docutils literal notranslate"><span class="pre">asyncio</span></code></a>.
  1851. (Contributed by Mariatta in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25002">bpo-25002</a>.)</p>
  1852. </section>
  1853. <section id="dbm">
  1854. <h4>dbm<a class="headerlink" href="#dbm" title="Link to this heading">¶</a></h4>
  1855. <p>Unlike other <a class="reference internal" href="../library/dbm.html#module-dbm" title="dbm: Interfaces to various Unix &quot;database&quot; formats."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm</span></code></a> implementations, the <a class="reference internal" href="../library/dbm.html#module-dbm.dumb" title="dbm.dumb: Portable implementation of the simple DBM interface."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dbm.dumb</span></code></a> module
  1856. creates databases with the <code class="docutils literal notranslate"><span class="pre">'rw'</span></code> mode and allows modifying the database
  1857. opened with the <code class="docutils literal notranslate"><span class="pre">'r'</span></code> mode. This behavior is now deprecated and will
  1858. be removed in 3.8.
  1859. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21708">bpo-21708</a>.)</p>
  1860. </section>
  1861. <section id="id2">
  1862. <h4>distutils<a class="headerlink" href="#id2" title="Link to this heading">¶</a></h4>
  1863. <p>The undocumented <code class="docutils literal notranslate"><span class="pre">extra_path</span></code> argument to the
  1864. <code class="docutils literal notranslate"><span class="pre">distutils.Distribution</span></code> constructor is now considered deprecated
  1865. and will raise a warning if set. Support for this parameter will be
  1866. removed in a future Python release. See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27919">bpo-27919</a> for details.</p>
  1867. </section>
  1868. <section id="grp">
  1869. <h4>grp<a class="headerlink" href="#grp" title="Link to this heading">¶</a></h4>
  1870. <p>The support of non-integer arguments in <a class="reference internal" href="../library/grp.html#grp.getgrgid" title="grp.getgrgid"><code class="xref py py-func docutils literal notranslate"><span class="pre">getgrgid()</span></code></a> has been
  1871. deprecated.
  1872. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26129">bpo-26129</a>.)</p>
  1873. </section>
  1874. <section id="id3">
  1875. <h4>importlib<a class="headerlink" href="#id3" title="Link to this heading">¶</a></h4>
  1876. <p>The <a class="reference internal" href="../library/importlib.html#importlib.machinery.SourceFileLoader.load_module" title="importlib.machinery.SourceFileLoader.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.SourceFileLoader.load_module()</span></code></a> and
  1877. <a class="reference internal" href="../library/importlib.html#importlib.machinery.SourcelessFileLoader.load_module" title="importlib.machinery.SourcelessFileLoader.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.machinery.SourcelessFileLoader.load_module()</span></code></a> methods
  1878. are now deprecated. They were the only remaining implementations of
  1879. <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.load_module" title="importlib.abc.Loader.load_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.load_module()</span></code></a> in <a class="reference internal" href="../library/importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> that had not
  1880. been deprecated in previous versions of Python in favour of
  1881. <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.exec_module" title="importlib.abc.Loader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.exec_module()</span></code></a>.</p>
  1882. <p>The <a class="reference internal" href="../library/importlib.html#importlib.machinery.WindowsRegistryFinder" title="importlib.machinery.WindowsRegistryFinder"><code class="xref py py-class docutils literal notranslate"><span class="pre">importlib.machinery.WindowsRegistryFinder</span></code></a> class is now
  1883. deprecated. As of 3.6.0, it is still added to <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> by
  1884. default (on Windows), but this may change in future releases.</p>
  1885. </section>
  1886. <section id="id4">
  1887. <h4>os<a class="headerlink" href="#id4" title="Link to this heading">¶</a></h4>
  1888. <p>Undocumented support of general <a class="reference internal" href="../glossary.html#term-bytes-like-object"><span class="xref std std-term">bytes-like objects</span></a>
  1889. as paths in <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal notranslate"><span class="pre">os</span></code></a> functions, <a class="reference internal" href="../library/functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> and similar functions is
  1890. now deprecated.
  1891. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25791">bpo-25791</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26754">bpo-26754</a>.)</p>
  1892. </section>
  1893. <section id="id5">
  1894. <h4>re<a class="headerlink" href="#id5" title="Link to this heading">¶</a></h4>
  1895. <p>Support for inline flags <code class="docutils literal notranslate"><span class="pre">(?letters)</span></code> in the middle of the regular
  1896. expression has been deprecated and will be removed in a future Python
  1897. version. Flags at the start of a regular expression are still allowed.
  1898. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22493">bpo-22493</a>.)</p>
  1899. </section>
  1900. <section id="id6">
  1901. <h4>ssl<a class="headerlink" href="#id6" title="Link to this heading">¶</a></h4>
  1902. <p>OpenSSL 0.9.8, 1.0.0 and 1.0.1 are deprecated and no longer supported.
  1903. In the future 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 will require at least OpenSSL 1.0.2 or
  1904. 1.1.0.</p>
  1905. <p>SSL-related arguments like <code class="docutils literal notranslate"><span class="pre">certfile</span></code>, <code class="docutils literal notranslate"><span class="pre">keyfile</span></code> and <code class="docutils literal notranslate"><span class="pre">check_hostname</span></code>
  1906. in <a class="reference internal" href="../library/ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a>, <a class="reference internal" href="../library/http.client.html#module-http.client" title="http.client: HTTP and HTTPS protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.client</span></code></a>, <a class="reference internal" href="../library/imaplib.html#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a>, <a class="reference internal" href="../library/poplib.html#module-poplib" title="poplib: POP3 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">poplib</span></code></a>,
  1907. and <a class="reference internal" href="../library/smtplib.html#module-smtplib" title="smtplib: SMTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">smtplib</span></code></a> have been deprecated in favor of <code class="docutils literal notranslate"><span class="pre">context</span></code>.
  1908. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28022">bpo-28022</a>.)</p>
  1909. <p>A couple of protocols and functions of 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 are now
  1910. deprecated. Some features will no longer be available in future versions
  1911. of OpenSSL. Other features are deprecated in favor of a different API.
  1912. (Contributed by Christian Heimes in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28022">bpo-28022</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26470">bpo-26470</a>.)</p>
  1913. </section>
  1914. <section id="id7">
  1915. <h4>tkinter<a class="headerlink" href="#id7" title="Link to this heading">¶</a></h4>
  1916. <p>The <a class="reference internal" href="../library/tkinter.tix.html#module-tkinter.tix" title="tkinter.tix: Tk Extension Widgets for Tkinter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.tix</span></code></a> module is now deprecated. <a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> users
  1917. should use <a class="reference internal" href="../library/tkinter.ttk.html#module-tkinter.ttk" title="tkinter.ttk: Tk themed widget set"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter.ttk</span></code></a> instead.</p>
  1918. </section>
  1919. <section id="whatsnew36-venv">
  1920. <span id="id8"></span><h4>venv<a class="headerlink" href="#whatsnew36-venv" title="Link to this heading">¶</a></h4>
  1921. <p>The <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> script has been deprecated in favour of <code class="docutils literal notranslate"><span class="pre">python3</span> <span class="pre">-m</span> <span class="pre">venv</span></code>.
  1922. This prevents confusion as to what Python interpreter <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> is
  1923. connected to and thus what Python interpreter will be used by the virtual
  1924. environment. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25154">bpo-25154</a>.)</p>
  1925. </section>
  1926. </section>
  1927. <section id="xml">
  1928. <h3>xml<a class="headerlink" href="#xml" title="Link to this heading">¶</a></h3>
  1929. <ul class="simple">
  1930. <li><p>As mitigation against DTD and external entity retrieval, the
  1931. <a class="reference internal" href="../library/xml.dom.minidom.html#module-xml.dom.minidom" title="xml.dom.minidom: Minimal Document Object Model (DOM) implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code></a> and <a class="reference internal" href="../library/xml.sax.html#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code></a> modules no longer process
  1932. external entities by default.
  1933. (Contributed by Christian Heimes in <a class="reference external" href="https://github.com/python/cpython/issues/61441">gh-61441</a>.)</p></li>
  1934. </ul>
  1935. </section>
  1936. <section id="deprecated-functions-and-types-of-the-c-api">
  1937. <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>
  1938. <p>Undocumented functions <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsEncodedObject()</span></code>,
  1939. <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsDecodedObject()</span></code>, <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsEncodedUnicode()</span></code>
  1940. and <code class="xref c c-func docutils literal notranslate"><span class="pre">PyUnicode_AsDecodedUnicode()</span></code> are deprecated now.
  1941. Use the <a class="reference internal" href="../c-api/codec.html#codec-registry"><span class="std std-ref">generic codec based API</span></a> instead.</p>
  1942. </section>
  1943. <section id="deprecated-build-options">
  1944. <h3>Deprecated Build Options<a class="headerlink" href="#deprecated-build-options" title="Link to this heading">¶</a></h3>
  1945. <p>The <code class="docutils literal notranslate"><span class="pre">--with-system-ffi</span></code> configure flag is now on by default on non-macOS
  1946. UNIX platforms. It may be disabled by using <code class="docutils literal notranslate"><span class="pre">--without-system-ffi</span></code>, but
  1947. using the flag is deprecated and will not be accepted in Python 3.7.
  1948. macOS is unaffected by this change. Note that many OS distributors already
  1949. use the <code class="docutils literal notranslate"><span class="pre">--with-system-ffi</span></code> flag when building their system Python.</p>
  1950. </section>
  1951. </section>
  1952. <section id="removed">
  1953. <h2>Removed<a class="headerlink" href="#removed" title="Link to this heading">¶</a></h2>
  1954. <section id="api-and-feature-removals">
  1955. <h3>API and Feature Removals<a class="headerlink" href="#api-and-feature-removals" title="Link to this heading">¶</a></h3>
  1956. <ul class="simple">
  1957. <li><p>Unknown escapes consisting of <code class="docutils literal notranslate"><span class="pre">'\'</span></code> and an ASCII letter in
  1958. regular expressions will now cause an error. In replacement templates for
  1959. <a class="reference internal" href="../library/re.html#re.sub" title="re.sub"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.sub()</span></code></a> they are still allowed, but deprecated.
  1960. The <a class="reference internal" href="../library/re.html#re.LOCALE" title="re.LOCALE"><code class="xref py py-const docutils literal notranslate"><span class="pre">re.LOCALE</span></code></a> flag can now only be used with binary patterns.</p></li>
  1961. <li><p><code class="docutils literal notranslate"><span class="pre">inspect.getmoduleinfo()</span></code> was removed (was deprecated since CPython 3.3).
  1962. <a class="reference internal" href="../library/inspect.html#inspect.getmodulename" title="inspect.getmodulename"><code class="xref py py-func docutils literal notranslate"><span class="pre">inspect.getmodulename()</span></code></a> should be used for obtaining the module
  1963. name for a given path.
  1964. (Contributed by Yury Selivanov in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=13248">bpo-13248</a>.)</p></li>
  1965. <li><p><code class="docutils literal notranslate"><span class="pre">traceback.Ignore</span></code> class and <code class="docutils literal notranslate"><span class="pre">traceback.usage</span></code>, <code class="docutils literal notranslate"><span class="pre">traceback.modname</span></code>,
  1966. <code class="docutils literal notranslate"><span class="pre">traceback.fullmodname</span></code>, <code class="docutils literal notranslate"><span class="pre">traceback.find_lines_from_code</span></code>,
  1967. <code class="docutils literal notranslate"><span class="pre">traceback.find_lines</span></code>, <code class="docutils literal notranslate"><span class="pre">traceback.find_strings</span></code>,
  1968. <code class="docutils literal notranslate"><span class="pre">traceback.find_executable_lines</span></code> methods were removed from the
  1969. <a class="reference internal" href="../library/traceback.html#module-traceback" title="traceback: Print or retrieve a stack traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">traceback</span></code></a> module. They were undocumented methods deprecated since
  1970. Python 3.2 and equivalent functionality is available from private methods.</p></li>
  1971. <li><p>The <code class="docutils literal notranslate"><span class="pre">tk_menuBar()</span></code> and <code class="docutils literal notranslate"><span class="pre">tk_bindForTraversal()</span></code> dummy methods in
  1972. <a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> widget classes were removed (corresponding Tk commands
  1973. were obsolete since Tk 4.0).</p></li>
  1974. <li><p>The <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile.open" title="zipfile.ZipFile.open"><code class="xref py py-meth docutils literal notranslate"><span class="pre">open()</span></code></a> method of the <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile" title="zipfile.ZipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">zipfile.ZipFile</span></code></a>
  1975. class no longer supports the <code class="docutils literal notranslate"><span class="pre">'U'</span></code> mode (was deprecated since Python 3.4).
  1976. Use <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.TextIOWrapper</span></code></a> for reading compressed text files in
  1977. <a class="reference internal" href="../glossary.html#term-universal-newlines"><span class="xref std std-term">universal newlines</span></a> mode.</p></li>
  1978. <li><p>The undocumented <code class="docutils literal notranslate"><span class="pre">IN</span></code>, <code class="docutils literal notranslate"><span class="pre">CDROM</span></code>, <code class="docutils literal notranslate"><span class="pre">DLFCN</span></code>, <code class="docutils literal notranslate"><span class="pre">TYPES</span></code>, <code class="docutils literal notranslate"><span class="pre">CDIO</span></code>, and
  1979. <code class="docutils literal notranslate"><span class="pre">STROPTS</span></code> modules have been removed. They had been available in the
  1980. platform specific <code class="docutils literal notranslate"><span class="pre">Lib/plat-*/</span></code> directories, but were chronically out of
  1981. date, inconsistently available across platforms, and unmaintained. The
  1982. script that created these modules is still available in the source
  1983. distribution at <a class="reference external" href="https://github.com/python/cpython/blob/v3.6.15/Tools/scripts/h2py.py">Tools/scripts/h2py.py</a>.</p></li>
  1984. <li><p>The deprecated <code class="docutils literal notranslate"><span class="pre">asynchat.fifo</span></code> class has been removed.</p></li>
  1985. </ul>
  1986. </section>
  1987. </section>
  1988. <section id="porting-to-python-3-6">
  1989. <h2>Porting to Python 3.6<a class="headerlink" href="#porting-to-python-3-6" title="Link to this heading">¶</a></h2>
  1990. <p>This section lists previously described changes and other bugfixes
  1991. that may require changes to your code.</p>
  1992. <section id="changes-in-python-command-behavior">
  1993. <h3>Changes in ‘python’ Command Behavior<a class="headerlink" href="#changes-in-python-command-behavior" title="Link to this heading">¶</a></h3>
  1994. <ul class="simple">
  1995. <li><p>The output of a special Python build with defined <code class="docutils literal notranslate"><span class="pre">COUNT_ALLOCS</span></code>,
  1996. <code class="docutils literal notranslate"><span class="pre">SHOW_ALLOC_COUNT</span></code> or <code class="docutils literal notranslate"><span class="pre">SHOW_TRACK_COUNT</span></code> macros is now off by
  1997. default. It can be re-enabled using the <code class="docutils literal notranslate"><span class="pre">-X</span> <span class="pre">showalloccount</span></code> option.
  1998. It now outputs to <code class="docutils literal notranslate"><span class="pre">stderr</span></code> instead of <code class="docutils literal notranslate"><span class="pre">stdout</span></code>.
  1999. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23034">bpo-23034</a>.)</p></li>
  2000. </ul>
  2001. </section>
  2002. <section id="changes-in-the-python-api">
  2003. <h3>Changes in the Python API<a class="headerlink" href="#changes-in-the-python-api" title="Link to this heading">¶</a></h3>
  2004. <ul>
  2005. <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> will no longer allow combining the <code class="docutils literal notranslate"><span class="pre">'U'</span></code> mode flag
  2006. with <code class="docutils literal notranslate"><span class="pre">'+'</span></code>.
  2007. (Contributed by Jeff Balogh and John O’Connor in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=2091">bpo-2091</a>.)</p></li>
  2008. <li><p><a class="reference internal" href="../library/sqlite3.html#module-sqlite3" title="sqlite3: A DB-API 2.0 implementation using SQLite 3.x."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sqlite3</span></code></a> no longer implicitly commits an open transaction before DDL
  2009. statements.</p></li>
  2010. <li><p>On Linux, <a class="reference internal" href="../library/os.html#os.urandom" title="os.urandom"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.urandom()</span></code></a> now blocks until the system urandom entropy pool
  2011. is initialized to increase the security.</p></li>
  2012. <li><p>When <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.exec_module" title="importlib.abc.Loader.exec_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.exec_module()</span></code></a> is defined,
  2013. <a class="reference internal" href="../library/importlib.html#importlib.abc.Loader.create_module" title="importlib.abc.Loader.create_module"><code class="xref py py-meth docutils literal notranslate"><span class="pre">importlib.abc.Loader.create_module()</span></code></a> must also be defined.</p></li>
  2014. <li><p><a class="reference internal" href="../c-api/exceptions.html#c.PyErr_SetImportError" title="PyErr_SetImportError"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyErr_SetImportError()</span></code></a> now sets <a class="reference internal" href="../library/exceptions.html#TypeError" title="TypeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">TypeError</span></code></a> when its <strong>msg</strong>
  2015. argument is not set. Previously only <code class="docutils literal notranslate"><span class="pre">NULL</span></code> was returned.</p></li>
  2016. <li><p>The format of the <a class="reference internal" href="../reference/datamodel.html#codeobject.co_lnotab" title="codeobject.co_lnotab"><code class="xref py py-attr docutils literal notranslate"><span class="pre">co_lnotab</span></code></a> attribute of code objects
  2017. changed to support
  2018. a negative line number delta. By default, Python does not emit bytecode with
  2019. a negative line number delta. Functions using <a class="reference internal" href="../reference/datamodel.html#frame.f_lineno" title="frame.f_lineno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">frame.f_lineno</span></code></a>,
  2020. <code class="docutils literal notranslate"><span class="pre">PyFrame_GetLineNumber()</span></code> or <code class="docutils literal notranslate"><span class="pre">PyCode_Addr2Line()</span></code> are not affected.
  2021. Functions directly decoding <code class="xref py py-attr docutils literal notranslate"><span class="pre">co_lnotab</span></code> should be updated to use a signed
  2022. 8-bit integer type for the line number delta, but this is only required to
  2023. support applications using a negative line number delta. See
  2024. <code class="docutils literal notranslate"><span class="pre">Objects/lnotab_notes.txt</span></code> for the <code class="xref py py-attr docutils literal notranslate"><span class="pre">co_lnotab</span></code> format and how to decode
  2025. it, and see the <span class="target" id="index-36"></span><a class="pep reference external" href="https://peps.python.org/pep-0511/"><strong>PEP 511</strong></a> for the rationale.</p></li>
  2026. <li><p>The functions in the <a class="reference internal" href="../library/compileall.html#module-compileall" title="compileall: Tools for byte-compiling all Python source files in a directory tree."><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code></a> module now return booleans instead
  2027. of <code class="docutils literal notranslate"><span class="pre">1</span></code> or <code class="docutils literal notranslate"><span class="pre">0</span></code> to represent success or failure, respectively. Thanks to
  2028. booleans being a subclass of integers, this should only be an issue if you
  2029. were doing identity checks for <code class="docutils literal notranslate"><span class="pre">1</span></code> or <code class="docutils literal notranslate"><span class="pre">0</span></code>. See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25768">bpo-25768</a>.</p></li>
  2030. <li><p>Reading the <code class="xref py py-attr docutils literal notranslate"><span class="pre">port</span></code> attribute of
  2031. <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.urlsplit" title="urllib.parse.urlsplit"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.urlsplit()</span></code></a> and <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.urlparse" title="urllib.parse.urlparse"><code class="xref py py-func docutils literal notranslate"><span class="pre">urlparse()</span></code></a> results
  2032. now raises <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> for out-of-range values, rather than
  2033. returning <a class="reference internal" href="../library/constants.html#None" title="None"><code class="xref py py-const docutils literal notranslate"><span class="pre">None</span></code></a>. See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=20059">bpo-20059</a>.</p></li>
  2034. <li><p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">imp</span></code> module now raises a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> instead of
  2035. <a class="reference internal" href="../library/exceptions.html#PendingDeprecationWarning" title="PendingDeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PendingDeprecationWarning</span></code></a>.</p></li>
  2036. <li><p>The following modules have had missing APIs added to their <code class="xref py py-attr docutils literal notranslate"><span class="pre">__all__</span></code>
  2037. attributes to match the documented APIs:
  2038. <a class="reference internal" href="../library/calendar.html#module-calendar" title="calendar: Functions for working with calendars, including some emulation of the Unix cal program."><code class="xref py py-mod docutils literal notranslate"><span class="pre">calendar</span></code></a>, <a class="reference internal" href="../library/cgi.html#module-cgi" title="cgi: Helpers for running Python scripts via the Common Gateway Interface. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cgi</span></code></a>, <a class="reference internal" href="../library/csv.html#module-csv" title="csv: Write and read tabular data to and from delimited files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">csv</span></code></a>,
  2039. <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">ElementTree</span></code></a>, <a class="reference internal" href="../library/enum.html#module-enum" title="enum: Implementation of an enumeration class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">enum</span></code></a>,
  2040. <a class="reference internal" href="../library/fileinput.html#module-fileinput" title="fileinput: Loop over standard input or a list of files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">fileinput</span></code></a>, <a class="reference internal" href="../library/ftplib.html#module-ftplib" title="ftplib: FTP protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ftplib</span></code></a>, <a class="reference internal" href="../library/logging.html#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a>, <a class="reference internal" href="../library/mailbox.html#module-mailbox" title="mailbox: Manipulate mailboxes in various formats"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mailbox</span></code></a>,
  2041. <a class="reference internal" href="../library/mimetypes.html#module-mimetypes" title="mimetypes: Mapping of filename extensions to MIME types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">mimetypes</span></code></a>, <a class="reference internal" href="../library/optparse.html#module-optparse" title="optparse: Command-line option parsing library. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">optparse</span></code></a>, <a class="reference internal" href="../library/plistlib.html#module-plistlib" title="plistlib: Generate and parse Apple plist files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">plistlib</span></code></a>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">smtpd</span></code>,
  2042. <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>, <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>, <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> and
  2043. <a class="reference internal" href="../library/wave.html#module-wave" title="wave: Provide an interface to the WAV sound format."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wave</span></code></a>. This means they will export new symbols when <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">*</span></code>
  2044. is used.
  2045. (Contributed by Joel Taddei and Jacek Kołodziej in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23883">bpo-23883</a>.)</p></li>
  2046. <li><p>When performing a relative import, if <code class="docutils literal notranslate"><span class="pre">__package__</span></code> does not compare equal
  2047. to <code class="docutils literal notranslate"><span class="pre">__spec__.parent</span></code> then <a class="reference internal" href="../library/exceptions.html#ImportWarning" title="ImportWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ImportWarning</span></code></a> is raised.
  2048. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25791">bpo-25791</a>.)</p></li>
  2049. <li><p>When a relative import is performed and no parent package is known, then
  2050. <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> will be raised. Previously, <a class="reference internal" href="../library/exceptions.html#SystemError" title="SystemError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemError</span></code></a> could be
  2051. raised. (Contributed by Brett Cannon in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18018">bpo-18018</a>.)</p></li>
  2052. <li><p>Servers based on the <a class="reference internal" href="../library/socketserver.html#module-socketserver" title="socketserver: A framework for network servers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">socketserver</span></code></a> module, including those
  2053. defined in <a class="reference internal" href="../library/http.server.html#module-http.server" title="http.server: HTTP server and request handlers."><code class="xref py py-mod docutils literal notranslate"><span class="pre">http.server</span></code></a>, <a class="reference internal" href="../library/xmlrpc.server.html#module-xmlrpc.server" title="xmlrpc.server: Basic XML-RPC server implementations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xmlrpc.server</span></code></a> and
  2054. <a class="reference internal" href="../library/wsgiref.html#module-wsgiref.simple_server" title="wsgiref.simple_server: A simple WSGI HTTP server."><code class="xref py py-mod docutils literal notranslate"><span class="pre">wsgiref.simple_server</span></code></a>, now only catch exceptions derived
  2055. from <a class="reference internal" href="../library/exceptions.html#Exception" title="Exception"><code class="xref py py-exc docutils literal notranslate"><span class="pre">Exception</span></code></a>. Therefore if a request handler raises
  2056. an exception like <a class="reference internal" href="../library/exceptions.html#SystemExit" title="SystemExit"><code class="xref py py-exc docutils literal notranslate"><span class="pre">SystemExit</span></code></a> or <a class="reference internal" href="../library/exceptions.html#KeyboardInterrupt" title="KeyboardInterrupt"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyboardInterrupt</span></code></a>,
  2057. <a class="reference internal" href="../library/socketserver.html#socketserver.BaseServer.handle_error" title="socketserver.BaseServer.handle_error"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handle_error()</span></code></a> is no longer called, and
  2058. the exception will stop a single-threaded server. (Contributed by
  2059. Martin Panter in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23430">bpo-23430</a>.)</p></li>
  2060. <li><p><a class="reference internal" href="../library/spwd.html#spwd.getspnam" title="spwd.getspnam"><code class="xref py py-func docutils literal notranslate"><span class="pre">spwd.getspnam()</span></code></a> now raises a <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> instead of
  2061. <a class="reference internal" href="../library/exceptions.html#KeyError" title="KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> if the user doesn’t have privileges.</p></li>
  2062. <li><p>The <a class="reference internal" href="../library/socket.html#socket.socket.close" title="socket.socket.close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">socket.socket.close()</span></code></a> method now raises an exception if
  2063. an error (e.g. <code class="docutils literal notranslate"><span class="pre">EBADF</span></code>) was reported by the underlying system call.
  2064. (Contributed by Martin Panter in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26685">bpo-26685</a>.)</p></li>
  2065. <li><p>The <em>decode_data</em> argument for the <code class="xref py py-class docutils literal notranslate"><span class="pre">smtpd.SMTPChannel</span></code> and
  2066. <code class="xref py py-class docutils literal notranslate"><span class="pre">smtpd.SMTPServer</span></code> constructors is now <code class="docutils literal notranslate"><span class="pre">False</span></code> by default.
  2067. This means that the argument passed to
  2068. <code class="xref py py-meth docutils literal notranslate"><span class="pre">process_message()</span></code> is now a bytes object by
  2069. default, and <code class="xref py py-meth docutils literal notranslate"><span class="pre">process_message()</span></code> will be passed keyword arguments.
  2070. Code that has already been updated in accordance with the deprecation
  2071. warning generated by 3.5 will not be affected.</p></li>
  2072. <li><p>All optional arguments of the <a class="reference internal" href="../library/json.html#json.dump" title="json.dump"><code class="xref py py-func docutils literal notranslate"><span class="pre">dump()</span></code></a>, <a class="reference internal" href="../library/json.html#json.dumps" title="json.dumps"><code class="xref py py-func docutils literal notranslate"><span class="pre">dumps()</span></code></a>,
  2073. <a class="reference internal" href="../library/json.html#json.load" title="json.load"><code class="xref py py-func docutils literal notranslate"><span class="pre">load()</span></code></a> and <a class="reference internal" href="../library/json.html#json.loads" title="json.loads"><code class="xref py py-func docutils literal notranslate"><span class="pre">loads()</span></code></a> functions and
  2074. <a class="reference internal" href="../library/json.html#json.JSONEncoder" title="json.JSONEncoder"><code class="xref py py-class docutils literal notranslate"><span class="pre">JSONEncoder</span></code></a> and <a class="reference internal" href="../library/json.html#json.JSONDecoder" title="json.JSONDecoder"><code class="xref py py-class docutils literal notranslate"><span class="pre">JSONDecoder</span></code></a> class
  2075. constructors in the <a class="reference internal" href="../library/json.html#module-json" title="json: Encode and decode the JSON format."><code class="xref py py-mod docutils literal notranslate"><span class="pre">json</span></code></a> module are now <a class="reference internal" href="../glossary.html#keyword-only-parameter"><span class="std std-ref">keyword-only</span></a>.
  2076. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=18726">bpo-18726</a>.)</p></li>
  2077. <li><p>Subclasses of <a class="reference internal" href="../library/functions.html#type" title="type"><code class="xref py py-class docutils literal notranslate"><span class="pre">type</span></code></a> which don’t override <code class="docutils literal notranslate"><span class="pre">type.__new__</span></code> may no
  2078. longer use the one-argument form to get the type of an object.</p></li>
  2079. <li><p>As part of <span class="target" id="index-37"></span><a class="pep reference external" href="https://peps.python.org/pep-0487/"><strong>PEP 487</strong></a>, the handling of keyword arguments passed to
  2080. <a class="reference internal" href="../library/functions.html#type" title="type"><code class="xref py py-class docutils literal notranslate"><span class="pre">type</span></code></a> (other than the metaclass hint, <code class="docutils literal notranslate"><span class="pre">metaclass</span></code>) is now
  2081. consistently delegated to <a class="reference internal" href="../reference/datamodel.html#object.__init_subclass__" title="object.__init_subclass__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__init_subclass__()</span></code></a>. This means that
  2082. <code class="xref py py-meth docutils literal notranslate"><span class="pre">type.__new__()</span></code> and <code class="xref py py-meth docutils literal notranslate"><span class="pre">type.__init__()</span></code> both now accept arbitrary
  2083. keyword arguments, but <a class="reference internal" href="../reference/datamodel.html#object.__init_subclass__" title="object.__init_subclass__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">object.__init_subclass__()</span></code></a> (which is called from
  2084. <code class="xref py py-meth docutils literal notranslate"><span class="pre">type.__new__()</span></code>) will reject them by default. Custom metaclasses
  2085. accepting additional keyword arguments will need to adjust their calls to
  2086. <code class="xref py py-meth docutils literal notranslate"><span class="pre">type.__new__()</span></code> (whether direct or via <a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-class docutils literal notranslate"><span class="pre">super</span></code></a>) accordingly.</p></li>
  2087. <li><p>In <code class="docutils literal notranslate"><span class="pre">distutils.command.sdist.sdist</span></code>, the <code class="docutils literal notranslate"><span class="pre">default_format</span></code>
  2088. attribute has been removed and is no longer honored. Instead, the
  2089. gzipped tarfile format is the default on all platforms and no
  2090. platform-specific selection is made.
  2091. In environments where distributions are
  2092. built on Windows and zip distributions are required, configure
  2093. the project with a <code class="docutils literal notranslate"><span class="pre">setup.cfg</span></code> file containing the following:</p>
  2094. <div class="highlight-ini notranslate"><div class="highlight"><pre><span></span><span class="k">[sdist]</span>
  2095. <span class="na">formats</span><span class="o">=</span><span class="s">zip</span>
  2096. </pre></div>
  2097. </div>
  2098. <p>This behavior has also been backported to earlier Python versions
  2099. by Setuptools 26.0.0.</p>
  2100. </li>
  2101. <li><p>In the <a class="reference internal" href="../library/urllib.request.html#module-urllib.request" title="urllib.request: Extensible library for opening URLs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">urllib.request</span></code></a> module and the
  2102. <a class="reference internal" href="../library/http.client.html#http.client.HTTPConnection.request" title="http.client.HTTPConnection.request"><code class="xref py py-meth docutils literal notranslate"><span class="pre">http.client.HTTPConnection.request()</span></code></a> method, if no Content-Length
  2103. header field has been specified and the request body is a file object,
  2104. it is now sent with HTTP 1.1 chunked encoding. If a file object has to
  2105. be sent to a HTTP 1.0 server, the Content-Length value now has to be
  2106. specified by the caller.
  2107. (Contributed by Demian Brecht and Rolf Krahl with tweaks from
  2108. Martin Panter in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12319">bpo-12319</a>.)</p></li>
  2109. <li><p>The <a class="reference internal" href="../library/csv.html#csv.DictReader" title="csv.DictReader"><code class="xref py py-class docutils literal notranslate"><span class="pre">DictReader</span></code></a> now returns rows of type
  2110. <a class="reference internal" href="../library/collections.html#collections.OrderedDict" title="collections.OrderedDict"><code class="xref py py-class docutils literal notranslate"><span class="pre">OrderedDict</span></code></a>.
  2111. (Contributed by Steve Holden in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27842">bpo-27842</a>.)</p></li>
  2112. <li><p>The <a class="reference internal" href="../library/crypt.html#crypt.METHOD_CRYPT" title="crypt.METHOD_CRYPT"><code class="xref py py-const docutils literal notranslate"><span class="pre">crypt.METHOD_CRYPT</span></code></a> will no longer be added to <code class="docutils literal notranslate"><span class="pre">crypt.methods</span></code>
  2113. if unsupported by the platform.
  2114. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25287">bpo-25287</a>.)</p></li>
  2115. <li><p>The <em>verbose</em> and <em>rename</em> arguments for
  2116. <a class="reference internal" href="../library/collections.html#collections.namedtuple" title="collections.namedtuple"><code class="xref py py-func docutils literal notranslate"><span class="pre">namedtuple()</span></code></a> are now keyword-only.
  2117. (Contributed by Raymond Hettinger in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25628">bpo-25628</a>.)</p></li>
  2118. <li><p>On Linux, <a class="reference internal" href="../library/ctypes.html#ctypes.util.find_library" title="ctypes.util.find_library"><code class="xref py py-func docutils literal notranslate"><span class="pre">ctypes.util.find_library()</span></code></a> now looks in
  2119. <code class="docutils literal notranslate"><span class="pre">LD_LIBRARY_PATH</span></code> for shared libraries.
  2120. (Contributed by Vinay Sajip in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=9998">bpo-9998</a>.)</p></li>
  2121. <li><p>The <a class="reference internal" href="../library/imaplib.html#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">imaplib.IMAP4</span></code></a> class now handles flags containing the
  2122. <code class="docutils literal notranslate"><span class="pre">']'</span></code> character in messages sent from the server to improve
  2123. real-world compatibility.
  2124. (Contributed by Lita Cho in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=21815">bpo-21815</a>.)</p></li>
  2125. <li><p>The <code class="xref py py-func docutils literal notranslate"><span class="pre">mmap.write()</span></code> function now returns the number
  2126. of bytes written like other write methods.
  2127. (Contributed by Jakub Stasiak in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26335">bpo-26335</a>.)</p></li>
  2128. <li><p>The <a class="reference internal" href="../library/pkgutil.html#pkgutil.iter_modules" title="pkgutil.iter_modules"><code class="xref py py-func docutils literal notranslate"><span class="pre">pkgutil.iter_modules()</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>
  2129. functions now return <a class="reference internal" href="../library/pkgutil.html#pkgutil.ModuleInfo" title="pkgutil.ModuleInfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModuleInfo</span></code></a> named tuples.
  2130. (Contributed by Ramchandra Apte in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=17211">bpo-17211</a>.)</p></li>
  2131. <li><p><a class="reference internal" href="../library/re.html#re.sub" title="re.sub"><code class="xref py py-func docutils literal notranslate"><span class="pre">re.sub()</span></code></a> now raises an error for invalid numerical group
  2132. references in replacement templates even if the pattern is not
  2133. found in the string. The error message for invalid group references
  2134. now includes the group index and the position of the reference.
  2135. (Contributed by SilentGhost, Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25953">bpo-25953</a>.)</p></li>
  2136. <li><p><a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile" title="zipfile.ZipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">zipfile.ZipFile</span></code></a> will now raise <a class="reference internal" href="../library/exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> for
  2137. unrecognized compression values. Previously a plain <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>
  2138. was raised. Additionally, calling <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile" title="zipfile.ZipFile"><code class="xref py py-class docutils literal notranslate"><span class="pre">ZipFile</span></code></a> methods
  2139. on a closed ZipFile or calling the <a class="reference internal" href="../library/zipfile.html#zipfile.ZipFile.write" title="zipfile.ZipFile.write"><code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code></a> method
  2140. on a ZipFile created with mode <code class="docutils literal notranslate"><span class="pre">'r'</span></code> will raise a <a class="reference internal" href="../library/exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a>.
  2141. Previously, a <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> was raised in those scenarios.</p></li>
  2142. <li><p>when custom metaclasses are combined with zero-argument <a class="reference internal" href="../library/functions.html#super" title="super"><code class="xref py py-func docutils literal notranslate"><span class="pre">super()</span></code></a> or
  2143. direct references from methods to the implicit <code class="docutils literal notranslate"><span class="pre">__class__</span></code> closure
  2144. variable, the implicit <code class="docutils literal notranslate"><span class="pre">__classcell__</span></code> namespace entry must now be passed
  2145. up to <code class="docutils literal notranslate"><span class="pre">type.__new__</span></code> for initialisation. Failing to do so will result in
  2146. a <a class="reference internal" href="../library/exceptions.html#DeprecationWarning" title="DeprecationWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">DeprecationWarning</span></code></a> in Python 3.6 and a <a class="reference internal" href="../library/exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> in
  2147. Python 3.8.</p></li>
  2148. <li><p>With the introduction of <a class="reference internal" href="../library/exceptions.html#ModuleNotFoundError" title="ModuleNotFoundError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ModuleNotFoundError</span></code></a>, import system consumers
  2149. may start expecting import system replacements to raise that more specific
  2150. exception when appropriate, rather than the less-specific <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>.
  2151. To provide future compatibility with such consumers, implementors of
  2152. alternative import systems that completely replace <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> will
  2153. need to update their implementations to raise the new subclass when a module
  2154. can’t be found at all. Implementors of compliant plugins to the default
  2155. import system shouldn’t need to make any changes, as the default import
  2156. system will raise the new subclass when appropriate.</p></li>
  2157. </ul>
  2158. </section>
  2159. <section id="changes-in-the-c-api">
  2160. <h3>Changes in the C API<a class="headerlink" href="#changes-in-the-c-api" title="Link to this heading">¶</a></h3>
  2161. <ul class="simple">
  2162. <li><p>The <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a> allocator family now uses the <a class="reference internal" href="../c-api/memory.html#pymalloc"><span class="std std-ref">pymalloc allocator</span></a> rather than the system <code class="xref c c-func docutils literal notranslate"><span class="pre">malloc()</span></code>. Applications calling
  2163. <a class="reference internal" href="../c-api/memory.html#c.PyMem_Malloc" title="PyMem_Malloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_Malloc()</span></code></a> without holding the GIL can now crash. Set the
  2164. <span class="target" id="index-38"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONMALLOC"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONMALLOC</span></code></a> environment variable to <code class="docutils literal notranslate"><span class="pre">debug</span></code> to validate the
  2165. usage of memory allocators in your application. See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26249">bpo-26249</a>.</p></li>
  2166. <li><p><a class="reference internal" href="../c-api/sys.html#c.Py_Exit" title="Py_Exit"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Exit()</span></code></a> (and the main interpreter) now override the exit status
  2167. with 120 if flushing buffered data failed. See <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=5319">bpo-5319</a>.</p></li>
  2168. </ul>
  2169. </section>
  2170. <section id="cpython-bytecode-changes">
  2171. <h3>CPython bytecode changes<a class="headerlink" href="#cpython-bytecode-changes" title="Link to this heading">¶</a></h3>
  2172. <p>There have been several major changes to the <a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a> in Python 3.6.</p>
  2173. <ul class="simple">
  2174. <li><p>The Python interpreter now uses a 16-bit wordcode instead of bytecode.
  2175. (Contributed by Demur Rumed with input and reviews from
  2176. Serhiy Storchaka and Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=26647">bpo-26647</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28050">bpo-28050</a>.)</p></li>
  2177. <li><p>The new <a class="reference internal" href="../library/dis.html#opcode-FORMAT_VALUE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">FORMAT_VALUE</span></code></a> and <a class="reference internal" href="../library/dis.html#opcode-BUILD_STRING"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_STRING</span></code></a> opcodes as part
  2178. of the <a class="reference internal" href="#whatsnew36-pep498"><span class="std std-ref">formatted string literal</span></a> implementation.
  2179. (Contributed by Eric Smith in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=25483">bpo-25483</a> and
  2180. Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27078">bpo-27078</a>.)</p></li>
  2181. <li><p>The new <a class="reference internal" href="../library/dis.html#opcode-BUILD_CONST_KEY_MAP"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_CONST_KEY_MAP</span></code></a> opcode to optimize the creation
  2182. of dictionaries with constant keys.
  2183. (Contributed by Serhiy Storchaka in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27140">bpo-27140</a>.)</p></li>
  2184. <li><p>The function call opcodes have been heavily reworked for better performance
  2185. and simpler implementation.
  2186. The <a class="reference internal" href="../library/dis.html#opcode-MAKE_FUNCTION"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">MAKE_FUNCTION</span></code></a>, <code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FUNCTION</span></code>,
  2187. <code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FUNCTION_KW</span></code> and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_MAP_UNPACK_WITH_CALL</span></code> opcodes
  2188. have been modified, the new <a class="reference internal" href="../library/dis.html#opcode-CALL_FUNCTION_EX"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FUNCTION_EX</span></code></a> and
  2189. <code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_TUPLE_UNPACK_WITH_CALL</span></code> have been added, and
  2190. <code class="docutils literal notranslate"><span class="pre">CALL_FUNCTION_VAR</span></code>, <code class="docutils literal notranslate"><span class="pre">CALL_FUNCTION_VAR_KW</span></code> and <code class="docutils literal notranslate"><span class="pre">MAKE_CLOSURE</span></code> opcodes
  2191. have been removed.
  2192. (Contributed by Demur Rumed in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27095">bpo-27095</a>, and Serhiy Storchaka in
  2193. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27213">bpo-27213</a>, <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=28257">bpo-28257</a>.)</p></li>
  2194. <li><p>The new <a class="reference internal" href="../library/dis.html#opcode-SETUP_ANNOTATIONS"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">SETUP_ANNOTATIONS</span></code></a> and <code class="xref std std-opcode docutils literal notranslate"><span class="pre">STORE_ANNOTATION</span></code> opcodes
  2195. have been added to support the new <a class="reference internal" href="../glossary.html#term-variable-annotation"><span class="xref std std-term">variable annotation</span></a> syntax.
  2196. (Contributed by Ivan Levkivskyi in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=27985">bpo-27985</a>.)</p></li>
  2197. </ul>
  2198. </section>
  2199. </section>
  2200. <section id="notable-changes-in-python-3-6-2">
  2201. <h2>Notable changes in Python 3.6.2<a class="headerlink" href="#notable-changes-in-python-3-6-2" title="Link to this heading">¶</a></h2>
  2202. <section id="new-make-regen-all-build-target">
  2203. <h3>New <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> build target<a class="headerlink" href="#new-make-regen-all-build-target" title="Link to this heading">¶</a></h3>
  2204. <p>To simplify cross-compilation, and to ensure that CPython can reliably be
  2205. compiled without requiring an existing version of Python to already be
  2206. available, the autotools-based build system no longer attempts to implicitly
  2207. recompile generated files based on file modification times.</p>
  2208. <p>Instead, a new <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> command has been added to force regeneration
  2209. of these files when desired (e.g. after an initial version of Python has
  2210. already been built based on the pregenerated versions).</p>
  2211. <p>More selective regeneration targets are also defined - see
  2212. <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Makefile.pre.in">Makefile.pre.in</a> for details.</p>
  2213. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23404">bpo-23404</a>.)</p>
  2214. <div class="versionadded">
  2215. <p><span class="versionmodified added">New in version 3.6.2.</span></p>
  2216. </div>
  2217. </section>
  2218. <section id="removal-of-make-touch-build-target">
  2219. <h3>Removal of <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> build target<a class="headerlink" href="#removal-of-make-touch-build-target" title="Link to this heading">¶</a></h3>
  2220. <p>The <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> build target previously used to request implicit regeneration
  2221. of generated files by updating their modification times has been removed.</p>
  2222. <p>It has been replaced by the new <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> target.</p>
  2223. <p>(Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=23404">bpo-23404</a>.)</p>
  2224. <div class="versionchanged">
  2225. <p><span class="versionmodified changed">Changed in version 3.6.2.</span></p>
  2226. </div>
  2227. </section>
  2228. </section>
  2229. <section id="notable-changes-in-python-3-6-4">
  2230. <h2>Notable changes in Python 3.6.4<a class="headerlink" href="#notable-changes-in-python-3-6-4" title="Link to this heading">¶</a></h2>
  2231. <p>The <code class="docutils literal notranslate"><span class="pre">PyExc_RecursionErrorInst</span></code> singleton that was part of the public API
  2232. has been removed as its members being never cleared may cause a segfault
  2233. during finalization of the interpreter.
  2234. (Contributed by Xavier de Gaye in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=22898">bpo-22898</a> and <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=30697">bpo-30697</a>.)</p>
  2235. </section>
  2236. <section id="notable-changes-in-python-3-6-5">
  2237. <h2>Notable changes in Python 3.6.5<a class="headerlink" href="#notable-changes-in-python-3-6-5" title="Link to this heading">¶</a></h2>
  2238. <p>The <a class="reference internal" href="../library/locale.html#locale.localeconv" title="locale.localeconv"><code class="xref py py-func docutils literal notranslate"><span class="pre">locale.localeconv()</span></code></a> function now sets temporarily the <code class="docutils literal notranslate"><span class="pre">LC_CTYPE</span></code>
  2239. locale to the <code class="docutils literal notranslate"><span class="pre">LC_NUMERIC</span></code> locale in some cases.
  2240. (Contributed by Victor Stinner in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=31900">bpo-31900</a>.)</p>
  2241. </section>
  2242. <section id="notable-changes-in-python-3-6-7">
  2243. <h2>Notable changes in Python 3.6.7<a class="headerlink" href="#notable-changes-in-python-3-6-7" title="Link to this heading">¶</a></h2>
  2244. <p><a class="reference internal" href="../library/xml.dom.minidom.html#module-xml.dom.minidom" title="xml.dom.minidom: Minimal Document Object Model (DOM) implementation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.dom.minidom</span></code></a> and <a class="reference internal" href="../library/xml.sax.html#module-xml.sax" title="xml.sax: Package containing SAX2 base classes and convenience functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">xml.sax</span></code></a> modules no longer process
  2245. external entities by default. See also <a class="reference external" href="https://github.com/python/cpython/issues/61441">gh-61441</a>.</p>
  2246. <p>In 3.6.7 the <a class="reference internal" href="../library/tokenize.html#module-tokenize" title="tokenize: Lexical scanner for Python source code."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tokenize</span></code></a> module now implicitly emits a <code class="docutils literal notranslate"><span class="pre">NEWLINE</span></code> token
  2247. when provided with input that does not have a trailing new line. This behavior
  2248. now matches what the C tokenizer does internally.
  2249. (Contributed by Ammar Askar in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=33899">bpo-33899</a>.)</p>
  2250. </section>
  2251. <section id="notable-changes-in-python-3-6-10">
  2252. <h2>Notable changes in Python 3.6.10<a class="headerlink" href="#notable-changes-in-python-3-6-10" title="Link to this heading">¶</a></h2>
  2253. <p>Due to significant security concerns, the <em>reuse_address</em> parameter of
  2254. <a class="reference internal" href="../library/asyncio-eventloop.html#asyncio.loop.create_datagram_endpoint" title="asyncio.loop.create_datagram_endpoint"><code class="xref py py-meth docutils literal notranslate"><span class="pre">asyncio.loop.create_datagram_endpoint()</span></code></a> is no longer supported. This is
  2255. because of the behavior of the socket option <code class="docutils literal notranslate"><span class="pre">SO_REUSEADDR</span></code> in UDP. For more
  2256. details, see the documentation for <code class="docutils literal notranslate"><span class="pre">loop.create_datagram_endpoint()</span></code>.
  2257. (Contributed by Kyle Stanley, Antoine Pitrou, and Yury Selivanov in
  2258. <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=37228">bpo-37228</a>.)</p>
  2259. </section>
  2260. <section id="notable-changes-in-python-3-6-13">
  2261. <h2>Notable changes in Python 3.6.13<a class="headerlink" href="#notable-changes-in-python-3-6-13" title="Link to this heading">¶</a></h2>
  2262. <p>Earlier Python versions allowed using both <code class="docutils literal notranslate"><span class="pre">;</span></code> and <code class="docutils literal notranslate"><span class="pre">&amp;</span></code> as
  2263. query parameter separators in <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.parse_qs" title="urllib.parse.parse_qs"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.parse_qs()</span></code></a> and
  2264. <a class="reference internal" href="../library/urllib.parse.html#urllib.parse.parse_qsl" title="urllib.parse.parse_qsl"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.parse_qsl()</span></code></a>. Due to security concerns, and to conform with
  2265. newer W3C recommendations, this has been changed to allow only a single
  2266. separator key, with <code class="docutils literal notranslate"><span class="pre">&amp;</span></code> as the default. This change also affects
  2267. <a class="reference internal" href="../library/cgi.html#cgi.parse" title="cgi.parse"><code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.parse()</span></code></a> and <a class="reference internal" href="../library/cgi.html#cgi.parse_multipart" title="cgi.parse_multipart"><code class="xref py py-func docutils literal notranslate"><span class="pre">cgi.parse_multipart()</span></code></a> as they use the affected
  2268. functions internally. For more details, please see their respective
  2269. documentation.
  2270. (Contributed by Adam Goldschmidt, Senthil Kumaran and Ken Jin in <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42967">bpo-42967</a>.)</p>
  2271. </section>
  2272. <section id="notable-changes-in-python-3-6-14">
  2273. <h2>Notable changes in Python 3.6.14<a class="headerlink" href="#notable-changes-in-python-3-6-14" title="Link to this heading">¶</a></h2>
  2274. <p>A security fix alters the <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> behavior to not trust the
  2275. IPv4 address sent from the remote server when setting up a passive data
  2276. channel. We reuse the ftp server IP address instead. For unusual code
  2277. requiring the old behavior, set a <code class="docutils literal notranslate"><span class="pre">trust_server_pasv_ipv4_address</span></code>
  2278. attribute on your FTP instance to <code class="docutils literal notranslate"><span class="pre">True</span></code>. (See <a class="reference external" href="https://github.com/python/cpython/issues/87451">gh-87451</a>)</p>
  2279. <p>The presence of newline or tab characters in parts of a URL allows for some
  2280. forms of attacks. Following the WHATWG specification that updates RFC 3986,
  2281. ASCII newline <code class="docutils literal notranslate"><span class="pre">\n</span></code>, <code class="docutils literal notranslate"><span class="pre">\r</span></code> and tab <code class="docutils literal notranslate"><span class="pre">\t</span></code> characters are stripped from the
  2282. URL by the parser <a class="reference internal" href="../library/urllib.parse.html#module-urllib.parse" title="urllib.parse: Parse URLs into or assemble them from components."><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse()</span></code></a> preventing such attacks. The removal
  2283. characters are controlled by a new module level variable
  2284. <code class="docutils literal notranslate"><span class="pre">urllib.parse._UNSAFE_URL_BYTES_TO_REMOVE</span></code>. (See <a class="reference external" href="https://github.com/python/cpython/issues/88048">gh-88048</a>)</p>
  2285. </section>
  2286. </section>
  2287. <div class="clearer"></div>
  2288. </div>
  2289. </div>
  2290. </div>
  2291. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  2292. <div class="sphinxsidebarwrapper">
  2293. <div>
  2294. <h3><a href="../contents.html">Table of Contents</a></h3>
  2295. <ul>
  2296. <li><a class="reference internal" href="#">What’s New In Python 3.6</a><ul>
  2297. <li><a class="reference internal" href="#summary-release-highlights">Summary – Release highlights</a></li>
  2298. <li><a class="reference internal" href="#new-features">New Features</a><ul>
  2299. <li><a class="reference internal" href="#pep-498-formatted-string-literals">PEP 498: Formatted string literals</a></li>
  2300. <li><a class="reference internal" href="#pep-526-syntax-for-variable-annotations">PEP 526: Syntax for variable annotations</a></li>
  2301. <li><a class="reference internal" href="#pep-515-underscores-in-numeric-literals">PEP 515: Underscores in Numeric Literals</a></li>
  2302. <li><a class="reference internal" href="#pep-525-asynchronous-generators">PEP 525: Asynchronous Generators</a></li>
  2303. <li><a class="reference internal" href="#pep-530-asynchronous-comprehensions">PEP 530: Asynchronous Comprehensions</a></li>
  2304. <li><a class="reference internal" href="#pep-487-simpler-customization-of-class-creation">PEP 487: Simpler customization of class creation</a></li>
  2305. <li><a class="reference internal" href="#pep-487-descriptor-protocol-enhancements">PEP 487: Descriptor Protocol Enhancements</a></li>
  2306. <li><a class="reference internal" href="#pep-519-adding-a-file-system-path-protocol">PEP 519: Adding a file system path protocol</a></li>
  2307. <li><a class="reference internal" href="#pep-495-local-time-disambiguation">PEP 495: Local Time Disambiguation</a></li>
  2308. <li><a class="reference internal" href="#pep-529-change-windows-filesystem-encoding-to-utf-8">PEP 529: Change Windows filesystem encoding to UTF-8</a></li>
  2309. <li><a class="reference internal" href="#pep-528-change-windows-console-encoding-to-utf-8">PEP 528: Change Windows console encoding to UTF-8</a></li>
  2310. <li><a class="reference internal" href="#pep-520-preserving-class-attribute-definition-order">PEP 520: Preserving Class Attribute Definition Order</a></li>
  2311. <li><a class="reference internal" href="#pep-468-preserving-keyword-argument-order">PEP 468: Preserving Keyword Argument Order</a></li>
  2312. <li><a class="reference internal" href="#new-dict-implementation">New <span class="xref std std-ref">dict</span> implementation</a></li>
  2313. <li><a class="reference internal" href="#pep-523-adding-a-frame-evaluation-api-to-cpython">PEP 523: Adding a frame evaluation API to CPython</a></li>
  2314. <li><a class="reference internal" href="#pythonmalloc-environment-variable">PYTHONMALLOC environment variable</a></li>
  2315. <li><a class="reference internal" href="#dtrace-and-systemtap-probing-support">DTrace and SystemTap probing support</a></li>
  2316. </ul>
  2317. </li>
  2318. <li><a class="reference internal" href="#other-language-changes">Other Language Changes</a></li>
  2319. <li><a class="reference internal" href="#new-modules">New Modules</a><ul>
  2320. <li><a class="reference internal" href="#secrets">secrets</a></li>
  2321. </ul>
  2322. </li>
  2323. <li><a class="reference internal" href="#improved-modules">Improved Modules</a><ul>
  2324. <li><a class="reference internal" href="#array">array</a></li>
  2325. <li><a class="reference internal" href="#ast">ast</a></li>
  2326. <li><a class="reference internal" href="#asyncio">asyncio</a></li>
  2327. <li><a class="reference internal" href="#binascii">binascii</a></li>
  2328. <li><a class="reference internal" href="#cmath">cmath</a></li>
  2329. <li><a class="reference internal" href="#collections">collections</a></li>
  2330. <li><a class="reference internal" href="#concurrent-futures">concurrent.futures</a></li>
  2331. <li><a class="reference internal" href="#contextlib">contextlib</a></li>
  2332. <li><a class="reference internal" href="#datetime">datetime</a></li>
  2333. <li><a class="reference internal" href="#decimal">decimal</a></li>
  2334. <li><a class="reference internal" href="#distutils">distutils</a></li>
  2335. <li><a class="reference internal" href="#email">email</a></li>
  2336. <li><a class="reference internal" href="#encodings">encodings</a></li>
  2337. <li><a class="reference internal" href="#enum">enum</a></li>
  2338. <li><a class="reference internal" href="#faulthandler">faulthandler</a></li>
  2339. <li><a class="reference internal" href="#fileinput">fileinput</a></li>
  2340. <li><a class="reference internal" href="#hashlib">hashlib</a></li>
  2341. <li><a class="reference internal" href="#http-client">http.client</a></li>
  2342. <li><a class="reference internal" href="#idlelib-and-idle">idlelib and IDLE</a></li>
  2343. <li><a class="reference internal" href="#importlib">importlib</a></li>
  2344. <li><a class="reference internal" href="#inspect">inspect</a></li>
  2345. <li><a class="reference internal" href="#json">json</a></li>
  2346. <li><a class="reference internal" href="#logging">logging</a></li>
  2347. <li><a class="reference internal" href="#math">math</a></li>
  2348. <li><a class="reference internal" href="#multiprocessing">multiprocessing</a></li>
  2349. <li><a class="reference internal" href="#os">os</a></li>
  2350. <li><a class="reference internal" href="#pathlib">pathlib</a></li>
  2351. <li><a class="reference internal" href="#pdb">pdb</a></li>
  2352. <li><a class="reference internal" href="#pickle">pickle</a></li>
  2353. <li><a class="reference internal" href="#pickletools">pickletools</a></li>
  2354. <li><a class="reference internal" href="#pydoc">pydoc</a></li>
  2355. <li><a class="reference internal" href="#random">random</a></li>
  2356. <li><a class="reference internal" href="#re">re</a></li>
  2357. <li><a class="reference internal" href="#readline">readline</a></li>
  2358. <li><a class="reference internal" href="#rlcompleter">rlcompleter</a></li>
  2359. <li><a class="reference internal" href="#shlex">shlex</a></li>
  2360. <li><a class="reference internal" href="#site">site</a></li>
  2361. <li><a class="reference internal" href="#sqlite3">sqlite3</a></li>
  2362. <li><a class="reference internal" href="#socket">socket</a></li>
  2363. <li><a class="reference internal" href="#socketserver">socketserver</a></li>
  2364. <li><a class="reference internal" href="#ssl">ssl</a></li>
  2365. <li><a class="reference internal" href="#statistics">statistics</a></li>
  2366. <li><a class="reference internal" href="#struct">struct</a></li>
  2367. <li><a class="reference internal" href="#subprocess">subprocess</a></li>
  2368. <li><a class="reference internal" href="#sys">sys</a></li>
  2369. <li><a class="reference internal" href="#telnetlib">telnetlib</a></li>
  2370. <li><a class="reference internal" href="#time">time</a></li>
  2371. <li><a class="reference internal" href="#timeit">timeit</a></li>
  2372. <li><a class="reference internal" href="#tkinter">tkinter</a></li>
  2373. <li><a class="reference internal" href="#traceback">traceback</a></li>
  2374. <li><a class="reference internal" href="#tracemalloc">tracemalloc</a></li>
  2375. <li><a class="reference internal" href="#typing">typing</a></li>
  2376. <li><a class="reference internal" href="#unicodedata">unicodedata</a></li>
  2377. <li><a class="reference internal" href="#unittest-mock">unittest.mock</a></li>
  2378. <li><a class="reference internal" href="#urllib-request">urllib.request</a></li>
  2379. <li><a class="reference internal" href="#urllib-robotparser">urllib.robotparser</a></li>
  2380. <li><a class="reference internal" href="#venv">venv</a></li>
  2381. <li><a class="reference internal" href="#warnings">warnings</a></li>
  2382. <li><a class="reference internal" href="#winreg">winreg</a></li>
  2383. <li><a class="reference internal" href="#winsound">winsound</a></li>
  2384. <li><a class="reference internal" href="#xmlrpc-client">xmlrpc.client</a></li>
  2385. <li><a class="reference internal" href="#zipfile">zipfile</a></li>
  2386. <li><a class="reference internal" href="#zlib">zlib</a></li>
  2387. </ul>
  2388. </li>
  2389. <li><a class="reference internal" href="#optimizations">Optimizations</a></li>
  2390. <li><a class="reference internal" href="#build-and-c-api-changes">Build and C API Changes</a></li>
  2391. <li><a class="reference internal" href="#other-improvements">Other Improvements</a></li>
  2392. <li><a class="reference internal" href="#deprecated">Deprecated</a><ul>
  2393. <li><a class="reference internal" href="#new-keywords">New Keywords</a></li>
  2394. <li><a class="reference internal" href="#deprecated-python-behavior">Deprecated Python behavior</a></li>
  2395. <li><a class="reference internal" href="#deprecated-python-modules-functions-and-methods">Deprecated Python modules, functions and methods</a><ul>
  2396. <li><a class="reference internal" href="#asynchat">asynchat</a></li>
  2397. <li><a class="reference internal" href="#asyncore">asyncore</a></li>
  2398. <li><a class="reference internal" href="#dbm">dbm</a></li>
  2399. <li><a class="reference internal" href="#id2">distutils</a></li>
  2400. <li><a class="reference internal" href="#grp">grp</a></li>
  2401. <li><a class="reference internal" href="#id3">importlib</a></li>
  2402. <li><a class="reference internal" href="#id4">os</a></li>
  2403. <li><a class="reference internal" href="#id5">re</a></li>
  2404. <li><a class="reference internal" href="#id6">ssl</a></li>
  2405. <li><a class="reference internal" href="#id7">tkinter</a></li>
  2406. <li><a class="reference internal" href="#whatsnew36-venv">venv</a></li>
  2407. </ul>
  2408. </li>
  2409. <li><a class="reference internal" href="#xml">xml</a></li>
  2410. <li><a class="reference internal" href="#deprecated-functions-and-types-of-the-c-api">Deprecated functions and types of the C API</a></li>
  2411. <li><a class="reference internal" href="#deprecated-build-options">Deprecated Build Options</a></li>
  2412. </ul>
  2413. </li>
  2414. <li><a class="reference internal" href="#removed">Removed</a><ul>
  2415. <li><a class="reference internal" href="#api-and-feature-removals">API and Feature Removals</a></li>
  2416. </ul>
  2417. </li>
  2418. <li><a class="reference internal" href="#porting-to-python-3-6">Porting to Python 3.6</a><ul>
  2419. <li><a class="reference internal" href="#changes-in-python-command-behavior">Changes in ‘python’ Command Behavior</a></li>
  2420. <li><a class="reference internal" href="#changes-in-the-python-api">Changes in the Python API</a></li>
  2421. <li><a class="reference internal" href="#changes-in-the-c-api">Changes in the C API</a></li>
  2422. <li><a class="reference internal" href="#cpython-bytecode-changes">CPython bytecode changes</a></li>
  2423. </ul>
  2424. </li>
  2425. <li><a class="reference internal" href="#notable-changes-in-python-3-6-2">Notable changes in Python 3.6.2</a><ul>
  2426. <li><a class="reference internal" href="#new-make-regen-all-build-target">New <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">regen-all</span></code> build target</a></li>
  2427. <li><a class="reference internal" href="#removal-of-make-touch-build-target">Removal of <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">touch</span></code> build target</a></li>
  2428. </ul>
  2429. </li>
  2430. <li><a class="reference internal" href="#notable-changes-in-python-3-6-4">Notable changes in Python 3.6.4</a></li>
  2431. <li><a class="reference internal" href="#notable-changes-in-python-3-6-5">Notable changes in Python 3.6.5</a></li>
  2432. <li><a class="reference internal" href="#notable-changes-in-python-3-6-7">Notable changes in Python 3.6.7</a></li>
  2433. <li><a class="reference internal" href="#notable-changes-in-python-3-6-10">Notable changes in Python 3.6.10</a></li>
  2434. <li><a class="reference internal" href="#notable-changes-in-python-3-6-13">Notable changes in Python 3.6.13</a></li>
  2435. <li><a class="reference internal" href="#notable-changes-in-python-3-6-14">Notable changes in Python 3.6.14</a></li>
  2436. </ul>
  2437. </li>
  2438. </ul>
  2439. </div>
  2440. <div>
  2441. <h4>Previous topic</h4>
  2442. <p class="topless"><a href="3.7.html"
  2443. title="previous chapter">What’s New In Python 3.7</a></p>
  2444. </div>
  2445. <div>
  2446. <h4>Next topic</h4>
  2447. <p class="topless"><a href="3.5.html"
  2448. title="next chapter">What’s New In Python 3.5</a></p>
  2449. </div>
  2450. <div role="note" aria-label="source link">
  2451. <h3>This Page</h3>
  2452. <ul class="this-page-menu">
  2453. <li><a href="../bugs.html">Report a Bug</a></li>
  2454. <li>
  2455. <a href="https://github.com/python/cpython/blob/main/Doc/whatsnew/3.6.rst"
  2456. rel="nofollow">Show Source
  2457. </a>
  2458. </li>
  2459. </ul>
  2460. </div>
  2461. </div>
  2462. <div id="sidebarbutton" title="Collapse sidebar">
  2463. <span>«</span>
  2464. </div>
  2465. </div>
  2466. <div class="clearer"></div>
  2467. </div>
  2468. <div class="related" role="navigation" aria-label="related navigation">
  2469. <h3>Navigation</h3>
  2470. <ul>
  2471. <li class="right" style="margin-right: 10px">
  2472. <a href="../genindex.html" title="General Index"
  2473. >index</a></li>
  2474. <li class="right" >
  2475. <a href="../py-modindex.html" title="Python Module Index"
  2476. >modules</a> |</li>
  2477. <li class="right" >
  2478. <a href="3.5.html" title="What’s New In Python 3.5"
  2479. >next</a> |</li>
  2480. <li class="right" >
  2481. <a href="3.7.html" title="What’s New In Python 3.7"
  2482. >previous</a> |</li>
  2483. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  2484. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  2485. <li class="switchers">
  2486. <div class="language_switcher_placeholder"></div>
  2487. <div class="version_switcher_placeholder"></div>
  2488. </li>
  2489. <li>
  2490. </li>
  2491. <li id="cpython-language-and-version">
  2492. <a href="../index.html">3.12.3 Documentation</a> &#187;
  2493. </li>
  2494. <li class="nav-item nav-item-1"><a href="index.html" >What’s New in Python</a> &#187;</li>
  2495. <li class="nav-item nav-item-this"><a href="">What’s New In Python 3.6</a></li>
  2496. <li class="right">
  2497. <div class="inline-search" role="search">
  2498. <form class="inline-search" action="../search.html" method="get">
  2499. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  2500. <input type="submit" value="Go" />
  2501. </form>
  2502. </div>
  2503. |
  2504. </li>
  2505. <li class="right">
  2506. <label class="theme-selector-label">
  2507. Theme
  2508. <select class="theme-selector" oninput="activateTheme(this.value)">
  2509. <option value="auto" selected>Auto</option>
  2510. <option value="light">Light</option>
  2511. <option value="dark">Dark</option>
  2512. </select>
  2513. </label> |</li>
  2514. </ul>
  2515. </div>
  2516. <div class="footer">
  2517. &copy;
  2518. <a href="../copyright.html">
  2519. Copyright
  2520. </a>
  2521. 2001-2024, Python Software Foundation.
  2522. <br />
  2523. This page is licensed under the Python Software Foundation License Version 2.
  2524. <br />
  2525. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  2526. <br />
  2527. See <a href="/license.html">History and License</a> for more information.<br />
  2528. <br />
  2529. The Python Software Foundation is a non-profit corporation.
  2530. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  2531. <br />
  2532. <br />
  2533. Last updated on Apr 09, 2024 (13:47 UTC).
  2534. <a href="/bugs.html">Found a bug</a>?
  2535. <br />
  2536. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  2537. </div>
  2538. </body>
  2539. </html>
上海开阖软件有限公司 沪ICP备12045867号-1