Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 1 | **************************** |
| 2 | What's New In Python 3.8 |
| 3 | **************************** |
| 4 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 5 | .. Rules for maintenance: |
| 6 | |
| 7 | * Anyone can add text to this document. Do not spend very much time |
| 8 | on the wording of your changes, because your text will probably |
| 9 | get rewritten to some degree. |
| 10 | |
| 11 | * The maintainer will go through Misc/NEWS periodically and add |
| 12 | changes; it's therefore more important to add your changes to |
| 13 | Misc/NEWS than to this file. |
| 14 | |
| 15 | * This is not a complete list of every single change; completeness |
| 16 | is the purpose of Misc/NEWS. Some changes I consider too small |
| 17 | or esoteric to include. If such a change is added to the text, |
| 18 | I'll just remove it. (This is another reason you shouldn't spend |
| 19 | too much time on writing your addition.) |
| 20 | |
| 21 | * If you want to draw your new text to the attention of the |
| 22 | maintainer, add 'XXX' to the beginning of the paragraph or |
| 23 | section. |
| 24 | |
| 25 | * It's OK to just add a fragmentary note about a change. For |
| 26 | example: "XXX Describe the transmogrify() function added to the |
| 27 | socket module." The maintainer will research the change and |
| 28 | write the necessary text. |
| 29 | |
| 30 | * You can comment out your additions if you like, but it's not |
| 31 | necessary (especially when a final release is some months away). |
| 32 | |
| 33 | * Credit the author of a patch or bugfix. Just the name is |
| 34 | sufficient; the e-mail address isn't necessary. |
| 35 | |
| 36 | * It's helpful to add the bug/patch number as a comment: |
| 37 | |
| 38 | XXX Describe the transmogrify() function added to the socket |
| 39 | module. |
| 40 | (Contributed by P.Y. Developer in :issue:`12345`.) |
| 41 | |
Raymond Hettinger | 66a34d3 | 2019-08-12 15:55:18 -0700 | [diff] [blame] | 42 | This saves the maintainer the effort of going through the Git log |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 43 | when researching a change. |
| 44 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 45 | :Editor: Raymond Hettinger |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 46 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 47 | This article explains the new features in Python 3.8, compared to 3.7. |
Ned Deily | 45ab51c | 2018-02-28 13:58:38 -0500 | [diff] [blame] | 48 | For full details, see the :ref:`changelog <changelog>`. |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 49 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 50 | .. testsetup:: |
Nick Coghlan | b9438ce | 2019-06-09 19:07:42 +1000 | [diff] [blame] | 51 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 52 | from datetime import date |
| 53 | from math import cos, radians |
Raymond Hettinger | 66a34d3 | 2019-08-12 15:55:18 -0700 | [diff] [blame] | 54 | from unicodedata import normalize |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 55 | import re |
| 56 | import math |
Nick Coghlan | b9438ce | 2019-06-09 19:07:42 +1000 | [diff] [blame] | 57 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 58 | |
| 59 | Summary -- Release highlights |
| 60 | ============================= |
| 61 | |
| 62 | .. This section singles out the most important changes in Python 3.8. |
| 63 | Brevity is key. |
| 64 | |
| 65 | |
| 66 | .. PEP-sized items next. |
| 67 | |
| 68 | |
| 69 | |
| 70 | New Features |
| 71 | ============ |
| 72 | |
Guido van Rossum | 09d434c | 2019-04-24 11:30:17 -0700 | [diff] [blame] | 73 | Assignment expressions |
| 74 | ---------------------- |
| 75 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 76 | There is new syntax ``:=`` that assigns values to variables as part of a larger |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 77 | expression. It is affectionately known as "the walrus operator" due to |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 78 | its resemblance to `the eyes and tusks of a walrus |
| 79 | <https://en.wikipedia.org/wiki/Walrus#/media/File:Pacific_Walrus_-_Bull_(8247646168).jpg>`_. |
| 80 | |
| 81 | In this example, the assignment expression helps avoid calling |
| 82 | :func:`len` twice:: |
Guido van Rossum | 09d434c | 2019-04-24 11:30:17 -0700 | [diff] [blame] | 83 | |
| 84 | if (n := len(a)) > 10: |
| 85 | print(f"List is too long ({n} elements, expected <= 10)") |
| 86 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 87 | A similar benefit arises during regular expression matching where |
| 88 | match objects are needed twice, once to test whether a match |
| 89 | occurred and another to extract a subgroup:: |
| 90 | |
| 91 | discount = 0.0 |
| 92 | if (mo := re.search(r'(\d+)% discount', advertisement)): |
| 93 | discount = float(mo.group(1)) / 100.0 |
| 94 | |
| 95 | The operator is also useful with while-loops that compute |
| 96 | a value to test loop termination and then need that same |
| 97 | value again in the body of the loop:: |
| 98 | |
| 99 | # Loop over fixed length blocks |
| 100 | while (block := f.read(256)) != '': |
| 101 | process(block) |
| 102 | |
| 103 | Another motivating use case arises in list comprehensions where |
| 104 | a value computed in a filtering condition is also needed in |
| 105 | the expression body:: |
| 106 | |
| 107 | [clean_name.title() for name in names |
| 108 | if (clean_name := normalize('NFC', name)) in allowed_names] |
| 109 | |
| 110 | Try to limit use of the walrus operator to clean cases that reduce |
| 111 | complexity and improve readability. |
| 112 | |
Guido van Rossum | 09d434c | 2019-04-24 11:30:17 -0700 | [diff] [blame] | 113 | See :pep:`572` for a full description. |
| 114 | |
| 115 | (Contributed by Emily Morehouse in :issue:`35224`.) |
| 116 | |
Guido van Rossum | 09d434c | 2019-04-24 11:30:17 -0700 | [diff] [blame] | 117 | |
Guido van Rossum | 843bf42 | 2019-04-29 05:49:30 -0700 | [diff] [blame] | 118 | Positional-only parameters |
| 119 | -------------------------- |
| 120 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 121 | There is a new function parameter syntax ``/`` to indicate that some |
| 122 | function parameters must be specified positionally and cannot be used as |
| 123 | keyword arguments. This is the same notation shown by ``help()`` for C |
| 124 | functions annotated with Larry Hastings' `Argument Clinic |
| 125 | <https://docs.python.org/3/howto/clinic.html>`_ tool. |
| 126 | |
| 127 | In the following example, parameters *a* and *b* are positional-only, |
| 128 | while *c* or *d* can be positional or keyword, and *e* or *f* are |
| 129 | required to be keywords:: |
| 130 | |
| 131 | def f(a, b, /, c, d, *, e, f): |
| 132 | print(a, b, c, d, e, f) |
| 133 | |
| 134 | The following is a valid call:: |
| 135 | |
| 136 | f(10, 20, 30, d=40, e=50, f=60) |
| 137 | |
| 138 | However, these are invalid calls:: |
| 139 | |
| 140 | f(10, b=20, c=30, d=40, e=50, f=60) # b cannot be a keyword argument |
| 141 | f(10, 20, 30, 40, 50, f=60) # e must be a keyword argument |
| 142 | |
| 143 | One use case for this notation is that it allows pure Python functions |
| 144 | to fully emulate behaviors of existing C coded functions. For example, |
Ammar Askar | 5a58c52 | 2020-03-27 09:37:43 -0700 | [diff] [blame^] | 145 | the built-in :func:`divmod` function does not accept keyword arguments:: |
Guido van Rossum | 843bf42 | 2019-04-29 05:49:30 -0700 | [diff] [blame] | 146 | |
Ammar Askar | 5a58c52 | 2020-03-27 09:37:43 -0700 | [diff] [blame^] | 147 | def divmod(a, b, /): |
| 148 | "Emulate the built in divmod() function" |
| 149 | return (a // b, a % b) |
Guido van Rossum | 843bf42 | 2019-04-29 05:49:30 -0700 | [diff] [blame] | 150 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 151 | Another use case is to preclude keyword arguments when the parameter |
| 152 | name is not helpful. For example, the builtin :func:`len` function has |
| 153 | the signature ``len(obj, /)``. This precludes awkward calls such as:: |
| 154 | |
| 155 | len(obj='hello') # The "obj" keyword argument impairs readability |
| 156 | |
| 157 | A further benefit of marking a parameter as positional-only is that it |
| 158 | allows the parameter name to be changed in the future without risk of |
| 159 | breaking client code. For example, in the :mod:`statistics` module, the |
| 160 | parameter name *dist* may be changed in the future. This was made |
| 161 | possible with the following function specification:: |
| 162 | |
| 163 | def quantiles(dist, /, *, n=4, method='exclusive') |
| 164 | ... |
| 165 | |
| 166 | Since the parameters to the left of ``/`` are not exposed as possible |
| 167 | keywords, the parameters names remain available for use in ``**kwargs``:: |
| 168 | |
| 169 | >>> def f(a, b, /, **kwargs): |
| 170 | ... print(a, b, kwargs) |
| 171 | ... |
| 172 | >>> f(10, 20, a=1, b=2, c=3) # a and b are used in two ways |
| 173 | 10 20 {'a': 1, 'b': 2, 'c': 3} |
| 174 | |
| 175 | This greatly simplifies the implementation of functions and methods |
| 176 | that need to accept arbitrary keyword arguments. For example, here |
Hugo van Kemenade | 547c60c | 2019-10-12 20:53:36 +0300 | [diff] [blame] | 177 | is an excerpt from code in the :mod:`collections` module:: |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 178 | |
| 179 | class Counter(dict): |
| 180 | |
| 181 | def __init__(self, iterable=None, /, **kwds): |
| 182 | # Note "iterable" is a possible keyword argument |
Guido van Rossum | 843bf42 | 2019-04-29 05:49:30 -0700 | [diff] [blame] | 183 | |
| 184 | See :pep:`570` for a full description. |
| 185 | |
| 186 | (Contributed by Pablo Galindo in :issue:`36540`.) |
| 187 | |
| 188 | .. TODO: Pablo will sprint on docs at PyCon US 2019. |
| 189 | |
| 190 | |
Nick Coghlan | 16eb3bc | 2018-06-20 21:25:01 +1000 | [diff] [blame] | 191 | Parallel filesystem cache for compiled bytecode files |
| 192 | ----------------------------------------------------- |
| 193 | |
| 194 | The new :envvar:`PYTHONPYCACHEPREFIX` setting (also available as |
| 195 | :option:`-X` ``pycache_prefix``) configures the implicit bytecode |
| 196 | cache to use a separate parallel filesystem tree, rather than |
| 197 | the default ``__pycache__`` subdirectories within each source |
| 198 | directory. |
| 199 | |
| 200 | The location of the cache is reported in :data:`sys.pycache_prefix` |
| 201 | (:const:`None` indicates the default location in ``__pycache__`` |
| 202 | subdirectories). |
| 203 | |
| 204 | (Contributed by Carl Meyer in :issue:`33499`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 205 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 206 | |
Victor Stinner | 4046069 | 2019-04-26 17:56:44 +0200 | [diff] [blame] | 207 | Debug build uses the same ABI as release build |
| 208 | ----------------------------------------------- |
| 209 | |
Hugo van Kemenade | 547c60c | 2019-10-12 20:53:36 +0300 | [diff] [blame] | 210 | Python now uses the same ABI whether it's built in release or debug mode. On |
Paul Ganssle | 5c403b2 | 2019-04-27 14:14:35 -0400 | [diff] [blame] | 211 | Unix, when Python is built in debug mode, it is now possible to load C |
| 212 | extensions built in release mode and C extensions built using the stable ABI. |
Victor Stinner | 4046069 | 2019-04-26 17:56:44 +0200 | [diff] [blame] | 213 | |
Paul Ganssle | 5c403b2 | 2019-04-27 14:14:35 -0400 | [diff] [blame] | 214 | Release builds and debug builds are now ABI compatible: defining the |
| 215 | ``Py_DEBUG`` macro no longer implies the ``Py_TRACE_REFS`` macro, which |
| 216 | introduces the only ABI incompatibility. The ``Py_TRACE_REFS`` macro, which |
| 217 | adds the :func:`sys.getobjects` function and the :envvar:`PYTHONDUMPREFS` |
| 218 | environment variable, can be set using the new ``./configure --with-trace-refs`` |
| 219 | build option. |
Victor Stinner | 4046069 | 2019-04-26 17:56:44 +0200 | [diff] [blame] | 220 | (Contributed by Victor Stinner in :issue:`36465`.) |
| 221 | |
E. M. Bray | c994c8f | 2019-05-24 17:33:47 +0200 | [diff] [blame] | 222 | On Unix, C extensions are no longer linked to libpython except on Android |
| 223 | and Cygwin. |
Victor Stinner | 4ebcd7e | 2019-05-11 04:10:03 +0200 | [diff] [blame] | 224 | It is now possible |
Paul Ganssle | 5c403b2 | 2019-04-27 14:14:35 -0400 | [diff] [blame] | 225 | for a statically linked Python to load a C extension built using a shared |
| 226 | library Python. |
Victor Stinner | 4046069 | 2019-04-26 17:56:44 +0200 | [diff] [blame] | 227 | (Contributed by Victor Stinner in :issue:`21536`.) |
| 228 | |
| 229 | On Unix, when Python is built in debug mode, import now also looks for C |
| 230 | extensions compiled in release mode and for C extensions compiled with the |
| 231 | stable ABI. |
| 232 | (Contributed by Victor Stinner in :issue:`36722`.) |
| 233 | |
Victor Stinner | 0a8e572 | 2019-05-23 03:30:23 +0200 | [diff] [blame] | 234 | To embed Python into an application, a new ``--embed`` option must be passed to |
| 235 | ``python3-config --libs --embed`` to get ``-lpython3.8`` (link the application |
| 236 | to libpython). To support both 3.8 and older, try ``python3-config --libs |
| 237 | --embed`` first and fallback to ``python3-config --libs`` (without ``--embed``) |
| 238 | if the previous command fails. |
| 239 | |
| 240 | Add a pkg-config ``python-3.8-embed`` module to embed Python into an |
| 241 | application: ``pkg-config python-3.8-embed --libs`` includes ``-lpython3.8``. |
| 242 | To support both 3.8 and older, try ``pkg-config python-X.Y-embed --libs`` first |
| 243 | and fallback to ``pkg-config python-X.Y --libs`` (without ``--embed``) if the |
| 244 | previous command fails (replace ``X.Y`` with the Python version). |
| 245 | |
| 246 | On the other hand, ``pkg-config python3.8 --libs`` no longer contains |
| 247 | ``-lpython3.8``. C extensions must not be linked to libpython (except on |
E. M. Bray | c994c8f | 2019-05-24 17:33:47 +0200 | [diff] [blame] | 248 | Android and Cygwin, whose cases are handled by the script); |
| 249 | this change is backward incompatible on purpose. |
Victor Stinner | 0a8e572 | 2019-05-23 03:30:23 +0200 | [diff] [blame] | 250 | (Contributed by Victor Stinner in :issue:`36721`.) |
| 251 | |
Eric V. Smith | 9a4135e | 2019-05-08 16:28:48 -0400 | [diff] [blame] | 252 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 253 | f-strings support ``=`` for self-documenting expressions and debugging |
| 254 | ---------------------------------------------------------------------- |
Eric V. Smith | 9a4135e | 2019-05-08 16:28:48 -0400 | [diff] [blame] | 255 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 256 | Added an ``=`` specifier to :term:`f-string`\s. An f-string such as |
| 257 | ``f'{expr=}'`` will expand to the text of the expression, an equal sign, |
| 258 | then the representation of the evaluated expression. For example: |
Eric V. Smith | 9a4135e | 2019-05-08 16:28:48 -0400 | [diff] [blame] | 259 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 260 | >>> user = 'eric_idle' |
| 261 | >>> member_since = date(1975, 7, 31) |
| 262 | >>> f'{user=} {member_since=}' |
| 263 | "user='eric_idle' member_since=datetime.date(1975, 7, 31)" |
| 264 | |
| 265 | The usual :ref:`f-string format specifiers <f-strings>` allow more |
| 266 | control over how the result of the expression is displayed:: |
| 267 | |
| 268 | >>> delta = date.today() - member_since |
| 269 | >>> f'{user=!s} {delta.days=:,d}' |
| 270 | 'user=eric_idle delta.days=16,075' |
| 271 | |
| 272 | The ``=`` specifier will display the whole expression so that |
| 273 | calculations can be shown:: |
| 274 | |
| 275 | >>> print(f'{theta=} {cos(radians(theta))=:.3f}') |
| 276 | theta=30 cos(radians(theta))=0.866 |
Eric V. Smith | 9a4135e | 2019-05-08 16:28:48 -0400 | [diff] [blame] | 277 | |
| 278 | (Contributed by Eric V. Smith and Larry Hastings in :issue:`36817`.) |
| 279 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 280 | |
Raymond Hettinger | 274bd01 | 2019-10-14 09:01:05 -0700 | [diff] [blame] | 281 | PEP 578: Python Runtime Audit Hooks |
| 282 | ----------------------------------- |
| 283 | |
| 284 | The PEP adds an Audit Hook and Verified Open Hook. Both are available from |
| 285 | Python and native code, allowing applications and frameworks written in pure |
| 286 | Python code to take advantage of extra notifications, while also allowing |
| 287 | embedders or system administrators to deploy builds of Python where auditing is |
| 288 | always enabled. |
| 289 | |
| 290 | See :pep:`578` for full details. |
| 291 | |
| 292 | |
Victor Stinner | 331a6a5 | 2019-05-27 16:39:22 +0200 | [diff] [blame] | 293 | PEP 587: Python Initialization Configuration |
| 294 | -------------------------------------------- |
| 295 | |
| 296 | The :pep:`587` adds a new C API to configure the Python Initialization |
| 297 | providing finer control on the whole configuration and better error reporting. |
| 298 | |
| 299 | New structures: |
| 300 | |
| 301 | * :c:type:`PyConfig` |
| 302 | * :c:type:`PyPreConfig` |
| 303 | * :c:type:`PyStatus` |
| 304 | * :c:type:`PyWideStringList` |
| 305 | |
| 306 | New functions: |
| 307 | |
| 308 | * :c:func:`PyConfig_Clear` |
| 309 | * :c:func:`PyConfig_InitIsolatedConfig` |
| 310 | * :c:func:`PyConfig_InitPythonConfig` |
| 311 | * :c:func:`PyConfig_Read` |
| 312 | * :c:func:`PyConfig_SetArgv` |
| 313 | * :c:func:`PyConfig_SetBytesArgv` |
| 314 | * :c:func:`PyConfig_SetBytesString` |
| 315 | * :c:func:`PyConfig_SetString` |
| 316 | * :c:func:`PyPreConfig_InitIsolatedConfig` |
| 317 | * :c:func:`PyPreConfig_InitPythonConfig` |
| 318 | * :c:func:`PyStatus_Error` |
| 319 | * :c:func:`PyStatus_Exception` |
| 320 | * :c:func:`PyStatus_Exit` |
| 321 | * :c:func:`PyStatus_IsError` |
| 322 | * :c:func:`PyStatus_IsExit` |
| 323 | * :c:func:`PyStatus_NoMemory` |
| 324 | * :c:func:`PyStatus_Ok` |
| 325 | * :c:func:`PyWideStringList_Append` |
| 326 | * :c:func:`PyWideStringList_Insert` |
| 327 | * :c:func:`Py_BytesMain` |
| 328 | * :c:func:`Py_ExitStatusException` |
| 329 | * :c:func:`Py_InitializeFromConfig` |
| 330 | * :c:func:`Py_PreInitialize` |
| 331 | * :c:func:`Py_PreInitializeFromArgs` |
| 332 | * :c:func:`Py_PreInitializeFromBytesArgs` |
| 333 | * :c:func:`Py_RunMain` |
| 334 | |
| 335 | This PEP also adds ``_PyRuntimeState.preconfig`` (:c:type:`PyPreConfig` type) |
| 336 | and ``PyInterpreterState.config`` (:c:type:`PyConfig` type) fields to these |
| 337 | internal structures. ``PyInterpreterState.config`` becomes the new |
| 338 | reference configuration, replacing global configuration variables and |
| 339 | other private variables. |
| 340 | |
| 341 | See :ref:`Python Initialization Configuration <init-config>` for the |
| 342 | documentation. |
| 343 | |
| 344 | See :pep:`587` for a full description. |
| 345 | |
| 346 | (Contributed by Victor Stinner in :issue:`36763`.) |
| 347 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 348 | |
Jeroen Demeyer | 9a13a38 | 2019-11-12 14:08:00 +0100 | [diff] [blame] | 349 | PEP 590: Vectorcall: a fast calling protocol for CPython |
| 350 | -------------------------------------------------------- |
Jeroen Demeyer | 9e3e06e | 2019-06-03 01:43:13 +0200 | [diff] [blame] | 351 | |
Jeroen Demeyer | 9a13a38 | 2019-11-12 14:08:00 +0100 | [diff] [blame] | 352 | :ref:`vectorcall` is added to the Python/C API. |
Jeroen Demeyer | 9e3e06e | 2019-06-03 01:43:13 +0200 | [diff] [blame] | 353 | It is meant to formalize existing optimizations which were already done |
| 354 | for various classes. |
Jeroen Demeyer | 9a13a38 | 2019-11-12 14:08:00 +0100 | [diff] [blame] | 355 | Any static type implementing a callable can use this protocol. |
Jeroen Demeyer | 9e3e06e | 2019-06-03 01:43:13 +0200 | [diff] [blame] | 356 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 357 | This is currently provisional. |
| 358 | The aim is to make it fully public in Python 3.9. |
Jeroen Demeyer | 9e3e06e | 2019-06-03 01:43:13 +0200 | [diff] [blame] | 359 | |
| 360 | See :pep:`590` for a full description. |
| 361 | |
Jeroen Demeyer | 9a13a38 | 2019-11-12 14:08:00 +0100 | [diff] [blame] | 362 | (Contributed by Jeroen Demeyer, Mark Shannon and Petr Viktorin in :issue:`36974`.) |
Jeroen Demeyer | 9e3e06e | 2019-06-03 01:43:13 +0200 | [diff] [blame] | 363 | |
| 364 | |
Antoine Pitrou | c879ff2 | 2019-06-09 14:47:15 +0200 | [diff] [blame] | 365 | Pickle protocol 5 with out-of-band data buffers |
| 366 | ----------------------------------------------- |
| 367 | |
| 368 | When :mod:`pickle` is used to transfer large data between Python processes |
| 369 | in order to take advantage of multi-core or multi-machine processing, |
| 370 | it is important to optimize the transfer by reducing memory copies, and |
| 371 | possibly by applying custom techniques such as data-dependent compression. |
| 372 | |
| 373 | The :mod:`pickle` protocol 5 introduces support for out-of-band buffers |
| 374 | where :pep:`3118`-compatible data can be transmitted separately from the |
| 375 | main pickle stream, at the discretion of the communication layer. |
| 376 | |
| 377 | See :pep:`574` for a full description. |
| 378 | |
| 379 | (Contributed by Antoine Pitrou in :issue:`36785`.) |
| 380 | |
| 381 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 382 | Other Language Changes |
| 383 | ====================== |
| 384 | |
Serhiy Storchaka | fe2bbb1 | 2018-03-18 09:56:52 +0200 | [diff] [blame] | 385 | * A :keyword:`continue` statement was illegal in the :keyword:`finally` clause |
| 386 | due to a problem with the implementation. In Python 3.8 this restriction |
| 387 | was lifted. |
| 388 | (Contributed by Serhiy Storchaka in :issue:`32489`.) |
| 389 | |
Raymond Hettinger | 66a34d3 | 2019-08-12 15:55:18 -0700 | [diff] [blame] | 390 | * The :class:`bool`, :class:`int`, and :class:`fractions.Fraction` types |
| 391 | now have an :meth:`~int.as_integer_ratio` method like that found in |
| 392 | :class:`float` and :class:`decimal.Decimal`. This minor API extension |
| 393 | makes it possible to write ``numerator, denominator = |
| 394 | x.as_integer_ratio()`` and have it work across multiple numeric types. |
| 395 | (Contributed by Lisa Roach in :issue:`33073` and Raymond Hettinger in |
| 396 | :issue:`37819`.) |
Lisa Roach | 5ac7043 | 2018-09-13 23:56:23 -0700 | [diff] [blame] | 397 | |
Serhiy Storchaka | bdbad71 | 2019-06-02 00:05:48 +0300 | [diff] [blame] | 398 | * Constructors of :class:`int`, :class:`float` and :class:`complex` will now |
| 399 | use the :meth:`~object.__index__` special method, if available and the |
| 400 | corresponding method :meth:`~object.__int__`, :meth:`~object.__float__` |
| 401 | or :meth:`~object.__complex__` is not available. |
| 402 | (Contributed by Serhiy Storchaka in :issue:`20092`.) |
| 403 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 404 | * Added support of ``\N{name}`` escapes in :mod:`regular expressions <re>`:: |
| 405 | |
| 406 | >>> notice = 'Copyright © 2019' |
| 407 | >>> copyright_year_pattern = re.compile(r'\N{copyright sign}\s*(\d{4})') |
| 408 | >>> int(copyright_year_pattern.search(notice).group(1)) |
| 409 | 2019 |
| 410 | |
Serhiy Storchaka | a445feb | 2018-02-10 00:08:17 +0200 | [diff] [blame] | 411 | (Contributed by Jonathan Eunice and Serhiy Storchaka in :issue:`30688`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 412 | |
Rémi Lapeyre | 6531bf6 | 2018-11-06 01:38:54 +0100 | [diff] [blame] | 413 | * Dict and dictviews are now iterable in reversed insertion order using |
| 414 | :func:`reversed`. (Contributed by Rémi Lapeyre in :issue:`33462`.) |
| 415 | |
Benjamin Peterson | c9a71dd | 2018-09-12 17:14:39 -0700 | [diff] [blame] | 416 | * The syntax allowed for keyword names in function calls was further |
| 417 | restricted. In particular, ``f((keyword)=arg)`` is no longer allowed. It was |
| 418 | never intended to permit more than a bare name on the left-hand side of a |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 419 | keyword argument assignment term. |
| 420 | (Contributed by Benjamin Peterson in :issue:`34641`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 421 | |
Raymond Hettinger | 66a34d3 | 2019-08-12 15:55:18 -0700 | [diff] [blame] | 422 | * Generalized iterable unpacking in :keyword:`yield` and |
| 423 | :keyword:`return` statements no longer requires enclosing parentheses. |
| 424 | This brings the *yield* and *return* syntax into better agreement with |
| 425 | normal assignment syntax:: |
| 426 | |
| 427 | >>> def parse(family): |
| 428 | lastname, *members = family.split() |
| 429 | return lastname.upper(), *members |
| 430 | |
| 431 | >>> parse('simpsons homer marge bart lisa sally') |
| 432 | ('SIMPSONS', 'homer', 'marge', 'bart', 'lisa', 'sally') |
| 433 | |
jChapman | 8fabae3 | 2018-09-22 21:13:10 -0400 | [diff] [blame] | 434 | (Contributed by David Cuthbert and Jordan Chapman in :issue:`32117`.) |
| 435 | |
Raymond Hettinger | 66a34d3 | 2019-08-12 15:55:18 -0700 | [diff] [blame] | 436 | * When a comma is missed in code such as ``[(10, 20) (30, 40)]``, the |
| 437 | compiler displays a :exc:`SyntaxWarning` with a helpful suggestion. |
| 438 | This improves on just having a :exc:`TypeError` indicating that the |
| 439 | first tuple was not callable. (Contributed by Serhiy Storchaka in |
| 440 | :issue:`15248`.) |
Serhiy Storchaka | 62e4481 | 2019-02-16 08:12:19 +0200 | [diff] [blame] | 441 | |
Paul Ganssle | d9503c3 | 2019-02-08 11:02:00 -0500 | [diff] [blame] | 442 | * Arithmetic operations between subclasses of :class:`datetime.date` or |
| 443 | :class:`datetime.datetime` and :class:`datetime.timedelta` objects now return |
| 444 | an instance of the subclass, rather than the base class. This also affects |
| 445 | the return type of operations whose implementation (directly or indirectly) |
| 446 | uses :class:`datetime.timedelta` arithmetic, such as |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 447 | :meth:`~datetime.datetime.astimezone`. |
Paul Ganssle | d9503c3 | 2019-02-08 11:02:00 -0500 | [diff] [blame] | 448 | (Contributed by Paul Ganssle in :issue:`32417`.) |
| 449 | |
Gregory P. Smith | 06babb2 | 2019-02-23 10:43:49 -0800 | [diff] [blame] | 450 | * When the Python interpreter is interrupted by Ctrl-C (SIGINT) and the |
| 451 | resulting :exc:`KeyboardInterrupt` exception is not caught, the Python process |
| 452 | now exits via a SIGINT signal or with the correct exit code such that the |
| 453 | calling process can detect that it died due to a Ctrl-C. Shells on POSIX |
| 454 | and Windows use this to properly terminate scripts in interactive sessions. |
| 455 | (Contributed by Google via Gregory P. Smith in :issue:`1054041`.) |
| 456 | |
Raymond Hettinger | 66a34d3 | 2019-08-12 15:55:18 -0700 | [diff] [blame] | 457 | * Some advanced styles of programming require updating the |
| 458 | :class:`types.CodeType` object for an existing function. Since code |
| 459 | objects are immutable, a new code object needs to be created, one |
| 460 | that is modeled on the existing code object. With 19 parameters, |
| 461 | this was somewhat tedious. Now, the new ``replace()`` method makes |
| 462 | it possible to create a clone with a few altered parameters. |
| 463 | |
| 464 | Here's an example that alters the :func:`statistics.mean` function to |
| 465 | prevent the *data* parameter from being used as a keyword argument:: |
| 466 | |
| 467 | >>> from statistics import mean |
| 468 | >>> mean(data=[10, 20, 90]) |
| 469 | 40 |
| 470 | >>> mean.__code__ = mean.__code__.replace(co_posonlyargcount=1) |
| 471 | >>> mean(data=[10, 20, 90]) |
| 472 | Traceback (most recent call last): |
| 473 | ... |
| 474 | TypeError: mean() got some positional-only arguments passed as keyword arguments: 'data' |
| 475 | |
Victor Stinner | a9f05d6 | 2019-05-24 23:57:23 +0200 | [diff] [blame] | 476 | (Contributed by Victor Stinner in :issue:`37032`.) |
| 477 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 478 | * For integers, the three-argument form of the :func:`pow` function now |
| 479 | permits the exponent to be negative in the case where the base is |
| 480 | relatively prime to the modulus. It then computes a modular inverse to |
| 481 | the base when the exponent is ``-1``, and a suitable power of that |
| 482 | inverse for other negative exponents. For example, to compute the |
| 483 | `modular multiplicative inverse |
| 484 | <https://en.wikipedia.org/wiki/Modular_multiplicative_inverse>`_ of 38 |
| 485 | modulo 137, write:: |
| 486 | |
| 487 | >>> pow(38, -1, 137) |
| 488 | 119 |
| 489 | >>> 119 * 38 % 137 |
| 490 | 1 |
| 491 | |
| 492 | Modular inverses arise in the solution of `linear Diophantine |
| 493 | equations <https://en.wikipedia.org/wiki/Diophantine_equation>`_. |
| 494 | For example, to find integer solutions for ``4258𝑥 + 147𝑦 = 369``, |
| 495 | first rewrite as ``4258𝑥 ≡ 369 (mod 147)`` then solve: |
| 496 | |
| 497 | >>> x = 369 * pow(4258, -1, 147) % 147 |
| 498 | >>> y = (4258 * x - 369) // -147 |
| 499 | >>> 4258 * x + 147 * y |
| 500 | 369 |
| 501 | |
Mark Dickinson | c529967 | 2019-06-02 10:24:06 +0100 | [diff] [blame] | 502 | (Contributed by Mark Dickinson in :issue:`36027`.) |
| 503 | |
Raymond Hettinger | 66a34d3 | 2019-08-12 15:55:18 -0700 | [diff] [blame] | 504 | * Dict comprehensions have been synced-up with dict literals so that the |
| 505 | key is computed first and the value second:: |
| 506 | |
| 507 | >>> # Dict comprehension |
| 508 | >>> cast = {input('role? '): input('actor? ') for i in range(2)} |
| 509 | role? King Arthur |
| 510 | actor? Chapman |
| 511 | role? Black Knight |
| 512 | actor? Cleese |
| 513 | |
| 514 | >>> # Dict literal |
| 515 | >>> cast = {input('role? '): input('actor? ')} |
| 516 | role? Sir Robin |
| 517 | actor? Eric Idle |
| 518 | |
| 519 | The guaranteed execution order is helpful with assignment expressions |
| 520 | because variables assigned in the key expression will be available in |
| 521 | the value expression:: |
| 522 | |
| 523 | >>> names = ['Martin von Löwis', 'Łukasz Langa', 'Walter Dörwald'] |
| 524 | >>> {(n := normalize('NFC', name)).casefold() : n for name in names} |
| 525 | {'martin von löwis': 'Martin von Löwis', |
| 526 | 'łukasz langa': 'Łukasz Langa', |
| 527 | 'walter dörwald': 'Walter Dörwald'} |
Pablo Galindo | b51b713 | 2019-06-25 02:41:58 +0100 | [diff] [blame] | 528 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 529 | (Contributed by Jörn Heissler in :issue:`35224`.) |
| 530 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 531 | * The :meth:`object.__reduce__` method can now return a tuple from two to |
| 532 | six elements long. Formerly, five was the limit. The new, optional sixth |
| 533 | element is a callable with a ``(obj, state)`` signature. This allows the |
| 534 | direct control over the state-updating behavior of a specific object. If |
| 535 | not *None*, this callable will have priority over the object's |
| 536 | :meth:`~__setstate__` method. |
| 537 | (Contributed by Pierre Glaser and Olivier Grisel in :issue:`35900`.) |
Serhiy Storchaka | 6543912 | 2018-10-19 17:42:06 +0300 | [diff] [blame] | 538 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 539 | New Modules |
| 540 | =========== |
| 541 | |
Barry Warsaw | 4867eaa | 2019-06-05 19:40:19 -0700 | [diff] [blame] | 542 | * The new :mod:`importlib.metadata` module provides (provisional) support for |
Raymond Hettinger | 66a34d3 | 2019-08-12 15:55:18 -0700 | [diff] [blame] | 543 | reading metadata from third-party packages. For example, it can extract an |
| 544 | installed package's version number, list of entry points, and more:: |
| 545 | |
| 546 | >>> # Note following example requires that the popular "requests" |
| 547 | >>> # package has been installed. |
| 548 | >>> |
| 549 | >>> from importlib.metadata import version, requires, files |
| 550 | >>> version('requests') |
| 551 | '2.22.0' |
| 552 | >>> list(requires('requests')) |
| 553 | ['chardet (<3.1.0,>=3.0.2)'] |
| 554 | >>> list(files('requests'))[:5] |
| 555 | [PackagePath('requests-2.22.0.dist-info/INSTALLER'), |
| 556 | PackagePath('requests-2.22.0.dist-info/LICENSE'), |
| 557 | PackagePath('requests-2.22.0.dist-info/METADATA'), |
| 558 | PackagePath('requests-2.22.0.dist-info/RECORD'), |
| 559 | PackagePath('requests-2.22.0.dist-info/WHEEL')] |
| 560 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 561 | (Contributed by Barry Warsaw and Jason R. Coombs in :issue:`34632`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 562 | |
| 563 | |
| 564 | Improved Modules |
| 565 | ================ |
| 566 | |
Guido van Rossum | 9b33ce4 | 2019-06-11 13:42:35 -0700 | [diff] [blame] | 567 | ast |
| 568 | --- |
| 569 | |
| 570 | AST nodes now have ``end_lineno`` and ``end_col_offset`` attributes, |
| 571 | which give the precise location of the end of the node. (This only |
| 572 | applies to nodes that have ``lineno`` and ``col_offset`` attributes.) |
| 573 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 574 | New function :func:`ast.get_source_segment` returns the source code |
| 575 | for a specific AST node. |
| 576 | |
| 577 | (Contributed by Ivan Levkivskyi in :issue:`33416`.) |
| 578 | |
Guido van Rossum | 9b33ce4 | 2019-06-11 13:42:35 -0700 | [diff] [blame] | 579 | The :func:`ast.parse` function has some new flags: |
| 580 | |
| 581 | * ``type_comments=True`` causes it to return the text of :pep:`484` and |
| 582 | :pep:`526` type comments associated with certain AST nodes; |
| 583 | |
| 584 | * ``mode='func_type'`` can be used to parse :pep:`484` "signature type |
| 585 | comments" (returned for function definition AST nodes); |
| 586 | |
Guido van Rossum | 10b55c1 | 2019-06-11 17:23:12 -0700 | [diff] [blame] | 587 | * ``feature_version=(3, N)`` allows specifying an earlier Python 3 |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 588 | version. For example, ``feature_version=(3, 4)`` will treat |
| 589 | :keyword:`async` and :keyword:`await` as non-reserved words. |
Guido van Rossum | 9b33ce4 | 2019-06-11 13:42:35 -0700 | [diff] [blame] | 590 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 591 | (Contributed by Guido van Rossum in :issue:`35766`.) |
Guido van Rossum | 9b33ce4 | 2019-06-11 13:42:35 -0700 | [diff] [blame] | 592 | |
| 593 | |
Victor Stinner | 6ea29c5 | 2018-09-25 08:27:08 -0700 | [diff] [blame] | 594 | asyncio |
| 595 | ------- |
| 596 | |
Kyle Stanley | 3bbb6db | 2019-10-24 00:15:25 -0400 | [diff] [blame] | 597 | :func:`asyncio.run` has graduated from the provisional to stable API. This |
| 598 | function can be used to execute a :term:`coroutine` and return the result while |
| 599 | automatically managing the event loop. For example:: |
| 600 | |
| 601 | import asyncio |
| 602 | |
| 603 | async def main(): |
| 604 | await asyncio.sleep(0) |
| 605 | return 42 |
| 606 | |
| 607 | asyncio.run(main()) |
| 608 | |
| 609 | This is *roughly* equivalent to:: |
| 610 | |
| 611 | import asyncio |
| 612 | |
| 613 | async def main(): |
| 614 | await asyncio.sleep(0) |
| 615 | return 42 |
| 616 | |
| 617 | loop = asyncio.new_event_loop() |
| 618 | asyncio.set_event_loop(loop) |
| 619 | try: |
| 620 | loop.run_until_complete(main()) |
| 621 | finally: |
| 622 | asyncio.set_event_loop(None) |
| 623 | loop.close() |
| 624 | |
| 625 | |
| 626 | The actual implementation is significantly more complex. Thus, |
| 627 | :func:`asyncio.run` should be the preferred way of running asyncio programs. |
| 628 | |
| 629 | (Contributed by Yury Selivanov in :issue:`32314`.) |
| 630 | |
Raymond Hettinger | 274bd01 | 2019-10-14 09:01:05 -0700 | [diff] [blame] | 631 | Running ``python -m asyncio`` launches a natively async REPL. This allows rapid |
| 632 | experimentation with code that has a top-level :keyword:`await`. There is no |
| 633 | longer a need to directly call ``asyncio.run()`` which would spawn a new event |
| 634 | loop on every invocation: |
| 635 | |
| 636 | .. code-block:: none |
| 637 | |
| 638 | $ python -m asyncio |
| 639 | asyncio REPL 3.8.0 |
| 640 | Use "await" directly instead of "asyncio.run()". |
| 641 | Type "help", "copyright", "credits" or "license" for more information. |
| 642 | >>> import asyncio |
| 643 | >>> await asyncio.sleep(10, result='hello') |
| 644 | hello |
| 645 | |
| 646 | (Contributed by Yury Selivanov in :issue:`37028`.) |
| 647 | |
Kyle Stanley | 3bbb6db | 2019-10-24 00:15:25 -0400 | [diff] [blame] | 648 | The exception :class:`asyncio.CancelledError` now inherits from |
| 649 | :class:`BaseException` rather than :class:`Exception`. |
| 650 | (Contributed by Yury Selivanov in :issue:`32528`.) |
| 651 | |
Victor Stinner | 6ea29c5 | 2018-09-25 08:27:08 -0700 | [diff] [blame] | 652 | On Windows, the default event loop is now :class:`~asyncio.ProactorEventLoop`. |
Victor Stinner | 01ae897 | 2019-06-03 16:28:01 +0200 | [diff] [blame] | 653 | (Contributed by Victor Stinner in :issue:`34687`.) |
| 654 | |
| 655 | :class:`~asyncio.ProactorEventLoop` now also supports UDP. |
| 656 | (Contributed by Adam Meily and Andrew Svetlov in :issue:`29883`.) |
| 657 | |
| 658 | :class:`~asyncio.ProactorEventLoop` can now be interrupted by |
| 659 | :exc:`KeyboardInterrupt` ("CTRL+C"). |
| 660 | (Contributed by Vladimir Matveev in :issue:`23057`.) |
| 661 | |
Kyle Stanley | 3bbb6db | 2019-10-24 00:15:25 -0400 | [diff] [blame] | 662 | Added :meth:`asyncio.Task.get_coro` for getting the wrapped coroutine |
| 663 | within an :class:`asyncio.Task`. |
| 664 | (Contributed by Alex Grönholm in :issue:`36999`.) |
| 665 | |
| 666 | Asyncio tasks can now be named, either by passing the ``name`` keyword |
| 667 | argument to :func:`asyncio.create_task` or |
| 668 | the :meth:`~asyncio.loop.create_task` event loop method, or by |
| 669 | calling the :meth:`~asyncio.Task.set_name` method on the task object. The |
| 670 | task name is visible in the ``repr()`` output of :class:`asyncio.Task` and |
| 671 | can also be retrieved using the :meth:`~asyncio.Task.get_name` method. |
| 672 | (Contributed by Alex Grönholm in :issue:`34270`.) |
| 673 | |
| 674 | Added support for |
| 675 | `Happy Eyeballs <https://en.wikipedia.org/wiki/Happy_Eyeballs>`_ to |
| 676 | :func:`asyncio.loop.create_connection`. To specify the behavior, two new |
| 677 | parameters have been added: *happy_eyeballs_delay* and *interleave*. The Happy |
| 678 | Eyeballs algorithm improves responsiveness in applications that support IPv4 |
| 679 | and IPv6 by attempting to simultaneously connect using both. |
| 680 | (Contributed by twisteroid ambassador in :issue:`33530`.) |
| 681 | |
Victor Stinner | 6ea29c5 | 2018-09-25 08:27:08 -0700 | [diff] [blame] | 682 | |
Matthias Bussonnier | 2ddbd21 | 2019-05-22 12:07:45 -0700 | [diff] [blame] | 683 | builtins |
| 684 | -------- |
| 685 | |
| 686 | The :func:`compile` built-in has been improved to accept the |
| 687 | ``ast.PyCF_ALLOW_TOP_LEVEL_AWAIT`` flag. With this new flag passed, |
| 688 | :func:`compile` will allow top-level ``await``, ``async for`` and ``async with`` |
| 689 | constructs that are usually considered invalid syntax. Asynchronous code object |
| 690 | marked with the ``CO_COROUTINE`` flag may then be returned. |
Matthias Bussonnier | 2ddbd21 | 2019-05-22 12:07:45 -0700 | [diff] [blame] | 691 | (Contributed by Matthias Bussonnier in :issue:`34616`) |
Terry Jan Reedy | fdcb5ae | 2018-09-25 12:45:27 -0400 | [diff] [blame] | 692 | |
Raymond Hettinger | 61a6db5 | 2019-10-13 21:31:12 -0700 | [diff] [blame] | 693 | |
Raymond Hettinger | 482b6b5 | 2019-05-01 17:48:13 -0700 | [diff] [blame] | 694 | collections |
| 695 | ----------- |
| 696 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 697 | The :meth:`~collections.somenamedtuple._asdict` method for |
| 698 | :func:`collections.namedtuple` now returns a :class:`dict` instead of a |
| 699 | :class:`collections.OrderedDict`. This works because regular dicts have |
| 700 | guaranteed ordering since Python 3.7. If the extra features of |
| 701 | :class:`OrderedDict` are required, the suggested remediation is to cast the |
| 702 | result to the desired type: ``OrderedDict(nt._asdict())``. |
Raymond Hettinger | 482b6b5 | 2019-05-01 17:48:13 -0700 | [diff] [blame] | 703 | (Contributed by Raymond Hettinger in :issue:`35864`.) |
| 704 | |
| 705 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 706 | cProfile |
| 707 | -------- |
| 708 | |
| 709 | The :class:`cProfile.Profile <profile.Profile>` class can now be used as a context manager. |
| 710 | Profile a block of code by running:: |
| 711 | |
| 712 | import cProfile |
| 713 | |
| 714 | with cProfile.Profile() as profiler: |
| 715 | # code to be profiled |
| 716 | ... |
| 717 | |
| 718 | (Contributed by Scott Sanderson in :issue:`29235`.) |
| 719 | |
| 720 | |
| 721 | csv |
| 722 | --- |
| 723 | |
| 724 | The :class:`csv.DictReader` now returns instances of :class:`dict` instead of |
| 725 | a :class:`collections.OrderedDict`. The tool is now faster and uses less |
| 726 | memory while still preserving the field order. |
fireattack | 9bfb4a7 | 2020-01-25 09:08:13 -0600 | [diff] [blame] | 727 | (Contributed by Michael Selik in :issue:`34003`.) |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 728 | |
| 729 | |
Raymond Hettinger | 61a6db5 | 2019-10-13 21:31:12 -0700 | [diff] [blame] | 730 | curses |
| 731 | ------- |
| 732 | |
| 733 | Added a new variable holding structured version information for the |
| 734 | underlying ncurses library: :data:`~curses.ncurses_version`. |
| 735 | (Contributed by Serhiy Storchaka in :issue:`31680`.) |
| 736 | |
| 737 | |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 738 | ctypes |
| 739 | ------ |
| 740 | |
| 741 | On Windows, :class:`~ctypes.CDLL` and subclasses now accept a *winmode* parameter |
| 742 | to specify flags for the underlying ``LoadLibraryEx`` call. The default flags are |
| 743 | set to only load DLL dependencies from trusted locations, including the path |
| 744 | where the DLL is stored (if a full or partial path is used to load the initial |
| 745 | DLL) and paths added by :func:`~os.add_dll_directory`. |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 746 | (Contributed by Steve Dower in :issue:`36085`.) |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 747 | |
| 748 | |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 749 | datetime |
| 750 | -------- |
| 751 | |
| 752 | Added new alternate constructors :meth:`datetime.date.fromisocalendar` and |
| 753 | :meth:`datetime.datetime.fromisocalendar`, which construct :class:`date` and |
| 754 | :class:`datetime` objects respectively from ISO year, week number, and weekday; |
| 755 | these are the inverse of each class's ``isocalendar`` method. |
| 756 | (Contributed by Paul Ganssle in :issue:`36004`.) |
| 757 | |
| 758 | |
Raymond Hettinger | b821868 | 2019-05-26 11:27:35 -0700 | [diff] [blame] | 759 | functools |
| 760 | --------- |
| 761 | |
| 762 | :func:`functools.lru_cache` can now be used as a straight decorator rather |
| 763 | than as a function returning a decorator. So both of these are now supported:: |
| 764 | |
| 765 | @lru_cache |
| 766 | def f(x): |
| 767 | ... |
| 768 | |
| 769 | @lru_cache(maxsize=256) |
| 770 | def f(x): |
| 771 | ... |
| 772 | |
| 773 | (Contributed by Raymond Hettinger in :issue:`36772`.) |
| 774 | |
Stéphane Wirtel | 93b81e1 | 2019-10-18 09:14:18 +0200 | [diff] [blame] | 775 | Added a new :func:`functools.cached_property` decorator, for computed properties |
| 776 | cached for the life of the instance. :: |
| 777 | |
| 778 | import functools |
| 779 | import statistics |
| 780 | |
| 781 | class Dataset: |
| 782 | def __init__(self, sequence_of_numbers): |
| 783 | self.data = sequence_of_numbers |
| 784 | |
| 785 | @functools.cached_property |
| 786 | def variance(self): |
| 787 | return statistics.variance(self.data) |
| 788 | |
| 789 | (Contributed by Carl Meyer in :issue:`21145`) |
| 790 | |
Raymond Hettinger | b821868 | 2019-05-26 11:27:35 -0700 | [diff] [blame] | 791 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 792 | Added a new :func:`functools.singledispatchmethod` decorator that converts |
| 793 | methods into :term:`generic functions <generic function>` using |
| 794 | :term:`single dispatch`:: |
| 795 | |
| 796 | from functools import singledispatchmethod |
| 797 | from contextlib import suppress |
| 798 | |
| 799 | class TaskManager: |
| 800 | |
| 801 | def __init__(self, tasks): |
| 802 | self.tasks = list(tasks) |
| 803 | |
| 804 | @singledispatchmethod |
| 805 | def discard(self, value): |
| 806 | with suppress(ValueError): |
| 807 | self.tasks.remove(value) |
| 808 | |
| 809 | @discard.register(list) |
| 810 | def _(self, tasks): |
| 811 | targets = set(tasks) |
| 812 | self.tasks = [x for x in self.tasks if x not in targets] |
| 813 | |
| 814 | (Contributed by Ethan Smith in :issue:`32380`) |
| 815 | |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 816 | gc |
| 817 | -- |
Paul Ganssle | 88c0937 | 2019-04-29 09:22:03 -0400 | [diff] [blame] | 818 | |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 819 | :func:`~gc.get_objects` can now receive an optional *generation* parameter |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 820 | indicating a generation to get objects from. |
| 821 | (Contributed by Pablo Galindo in :issue:`36016`.) |
Paul Ganssle | 88c0937 | 2019-04-29 09:22:03 -0400 | [diff] [blame] | 822 | |
| 823 | |
Cheryl Sabella | 637a33b | 2018-11-07 09:12:20 -0500 | [diff] [blame] | 824 | gettext |
| 825 | ------- |
| 826 | |
| 827 | Added :func:`~gettext.pgettext` and its variants. |
| 828 | (Contributed by Franz Glasner, Éric Araujo, and Cheryl Sabella in :issue:`2504`.) |
| 829 | |
Terry Jan Reedy | a72ca90 | 2019-07-31 01:03:53 -0400 | [diff] [blame] | 830 | |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 831 | gzip |
| 832 | ---- |
| 833 | |
| 834 | Added the *mtime* parameter to :func:`gzip.compress` for reproducible output. |
| 835 | (Contributed by Guo Ci Teo in :issue:`34898`.) |
| 836 | |
| 837 | A :exc:`~gzip.BadGzipFile` exception is now raised instead of :exc:`OSError` |
| 838 | for certain types of invalid or corrupt gzip files. |
| 839 | (Contributed by Filip Gruszczyński, Michele Orrù, and Zackery Spytz in |
| 840 | :issue:`6584`.) |
| 841 | |
| 842 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 843 | IDLE and idlelib |
Terry Jan Reedy | a72ca90 | 2019-07-31 01:03:53 -0400 | [diff] [blame] | 844 | ---------------- |
| 845 | |
| 846 | Output over N lines (50 by default) is squeezed down to a button. |
| 847 | N can be changed in the PyShell section of the General page of the |
| 848 | Settings dialog. Fewer, but possibly extra long, lines can be squeezed by |
| 849 | right clicking on the output. Squeezed output can be expanded in place |
| 850 | by double-clicking the button or into the clipboard or a separate window |
| 851 | by right-clicking the button. (Contributed by Tal Einat in :issue:`1529353`.) |
| 852 | |
| 853 | Add "Run Customized" to the Run menu to run a module with customized |
| 854 | settings. Any command line arguments entered are added to sys.argv. |
| 855 | They also re-appear in the box for the next customized run. One can also |
| 856 | suppress the normal Shell main module restart. (Contributed by Cheryl |
| 857 | Sabella, Terry Jan Reedy, and others in :issue:`5680` and :issue:`37627`.) |
| 858 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 859 | Added optional line numbers for IDLE editor windows. Windows |
Terry Jan Reedy | a72ca90 | 2019-07-31 01:03:53 -0400 | [diff] [blame] | 860 | open without line numbers unless set otherwise in the General |
| 861 | tab of the configuration dialog. Line numbers for an existing |
| 862 | window are shown and hidden in the Options menu. |
| 863 | (Contributed by Tal Einat and Saimadhav Heblikar in :issue:`17535`.) |
| 864 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 865 | OS native encoding is now used for converting between Python strings and Tcl |
| 866 | objects. This allows IDLE to work with emoji and other non-BMP characters. |
| 867 | These characters can be displayed or copied and pasted to or from the |
| 868 | clipboard. Converting strings from Tcl to Python and back now never fails. |
| 869 | (Many people worked on this for eight years but the problem was finally |
| 870 | solved by Serhiy Storchaka in :issue:`13153`.) |
| 871 | |
Terry Jan Reedy | a72ca90 | 2019-07-31 01:03:53 -0400 | [diff] [blame] | 872 | The changes above have been backported to 3.7 maintenance releases. |
| 873 | |
| 874 | |
Raymond Hettinger | d1e768a | 2019-03-25 13:01:13 -0700 | [diff] [blame] | 875 | inspect |
| 876 | ------- |
| 877 | |
| 878 | The :func:`inspect.getdoc` function can now find docstrings for ``__slots__`` |
| 879 | if that attribute is a :class:`dict` where the values are docstrings. |
| 880 | This provides documentation options similar to what we already have |
| 881 | for :func:`property`, :func:`classmethod`, and :func:`staticmethod`:: |
| 882 | |
| 883 | class AudioClip: |
| 884 | __slots__ = {'bit_rate': 'expressed in kilohertz to one decimal place', |
| 885 | 'duration': 'in seconds, rounded up to an integer'} |
| 886 | def __init__(self, bit_rate, duration): |
| 887 | self.bit_rate = round(bit_rate / 1000.0, 1) |
| 888 | self.duration = ceil(duration) |
Pablo Galindo | 175421b | 2019-02-23 03:02:06 +0000 | [diff] [blame] | 889 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 890 | (Contributed by Raymond Hettinger in :issue:`36326`.) |
| 891 | |
Terry Jan Reedy | a72ca90 | 2019-07-31 01:03:53 -0400 | [diff] [blame] | 892 | |
Victor Stinner | bc2aa81 | 2019-05-23 03:45:09 +0200 | [diff] [blame] | 893 | io |
| 894 | -- |
| 895 | |
| 896 | In development mode (:option:`-X` ``env``) and in debug build, the |
| 897 | :class:`io.IOBase` finalizer now logs the exception if the ``close()`` method |
| 898 | fails. The exception is ignored silently by default in release build. |
| 899 | (Contributed by Victor Stinner in :issue:`18748`.) |
| 900 | |
| 901 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 902 | itertools |
| 903 | --------- |
| 904 | |
| 905 | The :func:`itertools.accumulate` function added an option *initial* keyword |
| 906 | argument to specify an initial value:: |
| 907 | |
| 908 | >>> from itertools import accumulate |
| 909 | >>> list(accumulate([10, 5, 30, 15], initial=1000)) |
| 910 | [1000, 1010, 1015, 1045, 1060] |
| 911 | |
| 912 | (Contributed by Lisa Roach in :issue:`34659`.) |
| 913 | |
| 914 | |
HongWeipeng | f194479 | 2018-11-07 18:09:32 +0800 | [diff] [blame] | 915 | json.tool |
| 916 | --------- |
| 917 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 918 | Add option ``--json-lines`` to parse every input line as a separate JSON object. |
HongWeipeng | f194479 | 2018-11-07 18:09:32 +0800 | [diff] [blame] | 919 | (Contributed by Weipeng Hong in :issue:`31553`.) |
| 920 | |
Pablo Galindo | bc09851 | 2019-02-07 07:04:02 +0000 | [diff] [blame] | 921 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 922 | logging |
| 923 | ------- |
| 924 | |
| 925 | Added a *force* keyword argument to :func:`logging.basicConfig()` |
Serhiy Storchaka | 138ccbb | 2019-11-12 16:57:03 +0200 | [diff] [blame] | 926 | When set to true, any existing handlers attached |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 927 | to the root logger are removed and closed before carrying out the |
| 928 | configuration specified by the other arguments. |
| 929 | |
| 930 | This solves a long-standing problem. Once a logger or *basicConfig()* had |
| 931 | been called, subsequent calls to *basicConfig()* were silently ignored. |
| 932 | This made it difficult to update, experiment with, or teach the various |
| 933 | logging configuration options using the interactive prompt or a Jupyter |
| 934 | notebook. |
| 935 | |
| 936 | (Suggested by Raymond Hettinger, implemented by Dong-hee Na, and |
| 937 | reviewed by Vinay Sajip in :issue:`33897`.) |
| 938 | |
| 939 | |
Pablo Galindo | bc09851 | 2019-02-07 07:04:02 +0000 | [diff] [blame] | 940 | math |
| 941 | ---- |
| 942 | |
Raymond Hettinger | 3ff5962 | 2019-02-16 11:00:42 -0800 | [diff] [blame] | 943 | Added new function :func:`math.dist` for computing Euclidean distance |
| 944 | between two points. (Contributed by Raymond Hettinger in :issue:`33089`.) |
| 945 | |
| 946 | Expanded the :func:`math.hypot` function to handle multiple dimensions. |
| 947 | Formerly, it only supported the 2-D case. |
| 948 | (Contributed by Raymond Hettinger in :issue:`33089`.) |
| 949 | |
Pablo Galindo | bc09851 | 2019-02-07 07:04:02 +0000 | [diff] [blame] | 950 | Added new function, :func:`math.prod`, as analogous function to :func:`sum` |
| 951 | that returns the product of a 'start' value (default: 1) times an iterable of |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 952 | numbers:: |
| 953 | |
| 954 | >>> prior = 0.8 |
| 955 | >>> likelihoods = [0.625, 0.84, 0.30] |
Ashwin Vishnu | 1a8de82 | 2019-09-09 14:42:27 +0200 | [diff] [blame] | 956 | >>> math.prod(likelihoods, start=prior) |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 957 | 0.126 |
| 958 | |
Jero Bado | b1fa72a | 2019-10-18 15:48:48 +0800 | [diff] [blame] | 959 | (Contributed by Pablo Galindo in :issue:`35606`.) |
Pablo Galindo | bc09851 | 2019-02-07 07:04:02 +0000 | [diff] [blame] | 960 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 961 | Added two new combinatoric functions :func:`math.perm` and :func:`math.comb`:: |
| 962 | |
| 963 | >>> math.perm(10, 3) # Permutations of 10 things taken 3 at a time |
| 964 | 720 |
| 965 | >>> math.comb(10, 3) # Combinations of 10 things taken 3 at a time |
| 966 | 120 |
| 967 | |
| 968 | (Contributed by Yash Aggarwal, Keller Fuchs, Serhiy Storchaka, and Raymond |
| 969 | Hettinger in :issue:`37128`, :issue:`37178`, and :issue:`35431`.) |
| 970 | |
| 971 | Added a new function :func:`math.isqrt` for computing accurate integer square |
| 972 | roots without conversion to floating point. The new function supports |
| 973 | arbitrarily large integers. It is faster than ``floor(sqrt(n))`` but slower |
| 974 | than :func:`math.sqrt`:: |
| 975 | |
| 976 | >>> r = 650320427 |
| 977 | >>> s = r ** 2 |
| 978 | >>> isqrt(s - 1) # correct |
| 979 | 650320426 |
| 980 | >>> floor(sqrt(s - 1)) # incorrect |
| 981 | 650320427 |
| 982 | |
Mark Dickinson | 73934b9 | 2019-05-18 12:29:50 +0100 | [diff] [blame] | 983 | (Contributed by Mark Dickinson in :issue:`36887`.) |
| 984 | |
Mark Dickinson | a0adffb | 2019-06-01 12:21:53 +0100 | [diff] [blame] | 985 | The function :func:`math.factorial` no longer accepts arguments that are not |
| 986 | int-like. (Contributed by Pablo Galindo in :issue:`33083`.) |
| 987 | |
Zackery Spytz | 02db696 | 2019-05-27 10:48:17 -0600 | [diff] [blame] | 988 | |
| 989 | mmap |
| 990 | ---- |
| 991 | |
| 992 | The :class:`mmap.mmap` class now has an :meth:`~mmap.mmap.madvise` method to |
| 993 | access the ``madvise()`` system call. |
| 994 | (Contributed by Zackery Spytz in :issue:`32941`.) |
| 995 | |
| 996 | |
Victor Stinner | 17a5588 | 2019-05-28 16:02:50 +0200 | [diff] [blame] | 997 | multiprocessing |
| 998 | --------------- |
| 999 | |
| 1000 | Added new :mod:`multiprocessing.shared_memory` module. |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1001 | (Contributed by Davin Potts in :issue:`35813`.) |
Victor Stinner | 17a5588 | 2019-05-28 16:02:50 +0200 | [diff] [blame] | 1002 | |
| 1003 | On macOS, the *spawn* start method is now used by default. |
| 1004 | (Contributed by Victor Stinner in :issue:`33725`.) |
| 1005 | |
| 1006 | |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 1007 | os |
| 1008 | -- |
| 1009 | |
| 1010 | Added new function :func:`~os.add_dll_directory` on Windows for providing |
| 1011 | additional search paths for native dependencies when importing extension |
| 1012 | modules or loading DLLs using :mod:`ctypes`. |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1013 | (Contributed by Steve Dower in :issue:`36085`.) |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 1014 | |
Zackery Spytz | 43fdbd2 | 2019-05-29 13:57:07 -0600 | [diff] [blame] | 1015 | A new :func:`os.memfd_create` function was added to wrap the |
| 1016 | ``memfd_create()`` syscall. |
| 1017 | (Contributed by Zackery Spytz and Christian Heimes in :issue:`26836`.) |
| 1018 | |
Steve Dower | df2d4a6 | 2019-08-21 15:27:33 -0700 | [diff] [blame] | 1019 | On Windows, much of the manual logic for handling reparse points (including |
| 1020 | symlinks and directory junctions) has been delegated to the operating system. |
| 1021 | Specifically, :func:`os.stat` will now traverse anything supported by the |
| 1022 | operating system, while :func:`os.lstat` will only open reparse points that |
| 1023 | identify as "name surrogates" while others are opened as for :func:`os.stat`. |
| 1024 | In all cases, :attr:`stat_result.st_mode` will only have ``S_IFLNK`` set for |
| 1025 | symbolic links and not other kinds of reparse points. To identify other kinds |
| 1026 | of reparse point, check the new :attr:`stat_result.st_reparse_tag` attribute. |
| 1027 | |
| 1028 | On Windows, :func:`os.readlink` is now able to read directory junctions. Note |
| 1029 | that :func:`~os.path.islink` will return ``False`` for directory junctions, |
| 1030 | and so code that checks ``islink`` first will continue to treat junctions as |
| 1031 | directories, while code that handles errors from :func:`os.readlink` may now |
| 1032 | treat junctions as links. |
| 1033 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1034 | (Contributed by Steve Dower in :issue:`37834`.) |
| 1035 | |
Pablo Galindo | bc09851 | 2019-02-07 07:04:02 +0000 | [diff] [blame] | 1036 | |
Serhiy Storchaka | 0185f34 | 2018-09-18 11:28:51 +0300 | [diff] [blame] | 1037 | os.path |
| 1038 | ------- |
| 1039 | |
| 1040 | :mod:`os.path` functions that return a boolean result like |
| 1041 | :func:`~os.path.exists`, :func:`~os.path.lexists`, :func:`~os.path.isdir`, |
| 1042 | :func:`~os.path.isfile`, :func:`~os.path.islink`, and :func:`~os.path.ismount` |
| 1043 | now return ``False`` instead of raising :exc:`ValueError` or its subclasses |
| 1044 | :exc:`UnicodeEncodeError` and :exc:`UnicodeDecodeError` for paths that contain |
| 1045 | characters or bytes unrepresentable at the OS level. |
| 1046 | (Contributed by Serhiy Storchaka in :issue:`33721`.) |
| 1047 | |
Steve Dower | 8ef864d | 2019-03-12 15:15:26 -0700 | [diff] [blame] | 1048 | :func:`~os.path.expanduser` on Windows now prefers the :envvar:`USERPROFILE` |
| 1049 | environment variable and does not use :envvar:`HOME`, which is not normally set |
| 1050 | for regular user accounts. |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1051 | (Contributed by Anthony Sottile in :issue:`36264`.) |
Steve Dower | 8ef864d | 2019-03-12 15:15:26 -0700 | [diff] [blame] | 1052 | |
Serhiy Storchaka | 138ccbb | 2019-11-12 16:57:03 +0200 | [diff] [blame] | 1053 | :func:`~os.path.isdir` on Windows no longer returns ``True`` for a link to a |
Steve Dower | df2d4a6 | 2019-08-21 15:27:33 -0700 | [diff] [blame] | 1054 | non-existent directory. |
| 1055 | |
Steve Dower | 75e0649 | 2019-08-21 13:43:06 -0700 | [diff] [blame] | 1056 | :func:`~os.path.realpath` on Windows now resolves reparse points, including |
| 1057 | symlinks and directory junctions. |
| 1058 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1059 | (Contributed by Steve Dower in :issue:`37834`.) |
| 1060 | |
Serhiy Storchaka | b232df9 | 2018-10-30 13:22:42 +0200 | [diff] [blame] | 1061 | |
Serhiy Storchaka | 0185f34 | 2018-09-18 11:28:51 +0300 | [diff] [blame] | 1062 | pathlib |
| 1063 | ------- |
| 1064 | |
| 1065 | :mod:`pathlib.Path` methods that return a boolean result like |
| 1066 | :meth:`~pathlib.Path.exists()`, :meth:`~pathlib.Path.is_dir()`, |
| 1067 | :meth:`~pathlib.Path.is_file()`, :meth:`~pathlib.Path.is_mount()`, |
| 1068 | :meth:`~pathlib.Path.is_symlink()`, :meth:`~pathlib.Path.is_block_device()`, |
| 1069 | :meth:`~pathlib.Path.is_char_device()`, :meth:`~pathlib.Path.is_fifo()`, |
| 1070 | :meth:`~pathlib.Path.is_socket()` now return ``False`` instead of raising |
| 1071 | :exc:`ValueError` or its subclass :exc:`UnicodeEncodeError` for paths that |
| 1072 | contain characters unrepresentable at the OS level. |
| 1073 | (Contributed by Serhiy Storchaka in :issue:`33721`.) |
| 1074 | |
Joannah Nanjekye | 6b5b013 | 2019-05-04 11:27:10 -0400 | [diff] [blame] | 1075 | Added :meth:`pathlib.Path.link_to()` which creates a hard link pointing |
| 1076 | to a path. |
| 1077 | (Contributed by Joannah Nanjekye in :issue:`26978`) |
| 1078 | |
jab | 9e00d9e | 2018-12-28 13:03:40 -0500 | [diff] [blame] | 1079 | |
Pierre Glaser | ec6c1bd | 2019-07-01 15:51:57 +0200 | [diff] [blame] | 1080 | pickle |
| 1081 | ------ |
| 1082 | |
Pierre Glaser | ec6c1bd | 2019-07-01 15:51:57 +0200 | [diff] [blame] | 1083 | :mod:`pickle` extensions subclassing the C-optimized :class:`~pickle.Pickler` |
| 1084 | can now override the pickling logic of functions and classes by defining the |
| 1085 | special :meth:`~pickle.Pickler.reducer_override` method. |
Jero Bado | b1fa72a | 2019-10-18 15:48:48 +0800 | [diff] [blame] | 1086 | (Contributed by Pierre Glaser and Olivier Grisel in :issue:`35900`.) |
Pierre Glaser | ec6c1bd | 2019-07-01 15:51:57 +0200 | [diff] [blame] | 1087 | |
| 1088 | |
Jon Janzen | c981ad1 | 2019-05-15 22:14:38 +0200 | [diff] [blame] | 1089 | plistlib |
| 1090 | -------- |
| 1091 | |
| 1092 | Added new :class:`plistlib.UID` and enabled support for reading and writing |
| 1093 | NSKeyedArchiver-encoded binary plists. |
| 1094 | (Contributed by Jon Janzen in :issue:`26707`.) |
| 1095 | |
| 1096 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 1097 | pprint |
| 1098 | ------ |
| 1099 | |
| 1100 | The :mod:`pprint` module added a *sort_dicts* parameter to several functions. |
| 1101 | By default, those functions continue to sort dictionaries before rendering or |
Serhiy Storchaka | 138ccbb | 2019-11-12 16:57:03 +0200 | [diff] [blame] | 1102 | printing. However, if *sort_dicts* is set to false, the dictionaries retain |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 1103 | the order that keys were inserted. This can be useful for comparison to JSON |
| 1104 | inputs during debugging. |
| 1105 | |
| 1106 | In addition, there is a convenience new function, :func:`pprint.pp` that is |
Serhiy Storchaka | 138ccbb | 2019-11-12 16:57:03 +0200 | [diff] [blame] | 1107 | like :func:`pprint.pprint` but with *sort_dicts* defaulting to ``False``:: |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 1108 | |
| 1109 | >>> from pprint import pprint, pp |
| 1110 | >>> d = dict(source='input.txt', operation='filter', destination='output.txt') |
| 1111 | >>> pp(d, width=40) # Original order |
| 1112 | {'source': 'input.txt', |
| 1113 | 'operation': 'filter', |
| 1114 | 'destination': 'output.txt'} |
| 1115 | >>> pprint(d, width=40) # Keys sorted alphabetically |
| 1116 | {'destination': 'output.txt', |
| 1117 | 'operation': 'filter', |
| 1118 | 'source': 'input.txt'} |
| 1119 | |
| 1120 | (Contributed by Rémi Lapeyre in :issue:`30670`.) |
| 1121 | |
| 1122 | |
Joannah Nanjekye | 2e33ecd | 2019-05-28 13:29:04 -0300 | [diff] [blame] | 1123 | py_compile |
| 1124 | ---------- |
| 1125 | |
| 1126 | :func:`py_compile.compile` now supports silent mode. |
| 1127 | (Contributed by Joannah Nanjekye in :issue:`22640`.) |
| 1128 | |
| 1129 | |
Bo Bayles | ca80495 | 2019-05-29 03:06:12 -0500 | [diff] [blame] | 1130 | shlex |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1131 | ----- |
Bo Bayles | ca80495 | 2019-05-29 03:06:12 -0500 | [diff] [blame] | 1132 | |
| 1133 | The new :func:`shlex.join` function acts as the inverse of :func:`shlex.split`. |
| 1134 | (Contributed by Bo Bayles in :issue:`32102`.) |
Giampaolo Rodola | eb7e29f | 2019-04-09 00:34:02 +0200 | [diff] [blame] | 1135 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1136 | |
jab | 9e00d9e | 2018-12-28 13:03:40 -0500 | [diff] [blame] | 1137 | shutil |
| 1138 | ------ |
| 1139 | |
| 1140 | :func:`shutil.copytree` now accepts a new ``dirs_exist_ok`` keyword argument. |
| 1141 | (Contributed by Josh Bronson in :issue:`20849`.) |
| 1142 | |
CAM Gerlach | 89a8944 | 2019-04-06 23:47:49 -0500 | [diff] [blame] | 1143 | :func:`shutil.make_archive` now defaults to the modern pax (POSIX.1-2001) |
| 1144 | format for new archives to improve portability and standards conformance, |
| 1145 | inherited from the corresponding change to the :mod:`tarfile` module. |
| 1146 | (Contributed by C.A.M. Gerlach in :issue:`30661`.) |
| 1147 | |
Steve Dower | df2d4a6 | 2019-08-21 15:27:33 -0700 | [diff] [blame] | 1148 | :func:`shutil.rmtree` on Windows now removes directory junctions without |
| 1149 | recursively removing their contents first. |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1150 | (Contributed by Steve Dower in :issue:`37834`.) |
Steve Dower | df2d4a6 | 2019-08-21 15:27:33 -0700 | [diff] [blame] | 1151 | |
jab | 9e00d9e | 2018-12-28 13:03:40 -0500 | [diff] [blame] | 1152 | |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1153 | socket |
| 1154 | ------ |
| 1155 | |
| 1156 | Added :meth:`~socket.create_server()` and :meth:`~socket.has_dualstack_ipv6()` |
| 1157 | convenience functions to automate the necessary tasks usually involved when |
| 1158 | creating a server socket, including accepting both IPv4 and IPv6 connections |
| 1159 | on the same socket. (Contributed by Giampaolo Rodolà in :issue:`17561`.) |
| 1160 | |
| 1161 | The :func:`socket.if_nameindex()`, :func:`socket.if_nametoindex()`, and |
| 1162 | :func:`socket.if_indextoname()` functions have been implemented on Windows. |
| 1163 | (Contributed by Zackery Spytz in :issue:`37007`.) |
| 1164 | |
| 1165 | |
Christian Heimes | 9fb051f | 2018-09-23 08:32:31 +0200 | [diff] [blame] | 1166 | ssl |
| 1167 | --- |
| 1168 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 1169 | Added :attr:`~ssl.SSLContext.post_handshake_auth` to enable and |
| 1170 | :meth:`~ssl.SSLSocket.verify_client_post_handshake` to initiate TLS 1.3 |
Christian Heimes | 9fb051f | 2018-09-23 08:32:31 +0200 | [diff] [blame] | 1171 | post-handshake authentication. |
| 1172 | (Contributed by Christian Heimes in :issue:`34670`.) |
| 1173 | |
Raymond Hettinger | 47d9987 | 2019-02-21 15:06:29 -0800 | [diff] [blame] | 1174 | |
| 1175 | statistics |
| 1176 | ---------- |
| 1177 | |
| 1178 | Added :func:`statistics.fmean` as a faster, floating point variant of |
| 1179 | :func:`statistics.mean()`. (Contributed by Raymond Hettinger and |
| 1180 | Steven D'Aprano in :issue:`35904`.) |
| 1181 | |
Raymond Hettinger | 6463ba3 | 2019-04-07 09:20:03 -0700 | [diff] [blame] | 1182 | Added :func:`statistics.geometric_mean()` |
| 1183 | (Contributed by Raymond Hettinger in :issue:`27181`.) |
| 1184 | |
Raymond Hettinger | fc06a19 | 2019-03-12 00:43:27 -0700 | [diff] [blame] | 1185 | Added :func:`statistics.multimode` that returns a list of the most |
| 1186 | common values. (Contributed by Raymond Hettinger in :issue:`35892`.) |
| 1187 | |
Raymond Hettinger | 9013ccf | 2019-04-23 00:06:35 -0700 | [diff] [blame] | 1188 | Added :func:`statistics.quantiles` that divides data or a distribution |
| 1189 | in to equiprobable intervals (e.g. quartiles, deciles, or percentiles). |
| 1190 | (Contributed by Raymond Hettinger in :issue:`36546`.) |
| 1191 | |
Raymond Hettinger | 11c7953 | 2019-02-23 14:44:07 -0800 | [diff] [blame] | 1192 | Added :class:`statistics.NormalDist`, a tool for creating |
| 1193 | and manipulating normal distributions of a random variable. |
| 1194 | (Contributed by Raymond Hettinger in :issue:`36018`.) |
| 1195 | |
| 1196 | :: |
| 1197 | |
| 1198 | >>> temperature_feb = NormalDist.from_samples([4, 12, -3, 2, 7, 14]) |
Raymond Hettinger | 671d782 | 2019-05-01 17:49:12 -0700 | [diff] [blame] | 1199 | >>> temperature_feb.mean |
| 1200 | 6.0 |
| 1201 | >>> temperature_feb.stdev |
| 1202 | 6.356099432828281 |
Raymond Hettinger | 11c7953 | 2019-02-23 14:44:07 -0800 | [diff] [blame] | 1203 | |
| 1204 | >>> temperature_feb.cdf(3) # Chance of being under 3 degrees |
| 1205 | 0.3184678262814532 |
| 1206 | >>> # Relative chance of being 7 degrees versus 10 degrees |
| 1207 | >>> temperature_feb.pdf(7) / temperature_feb.pdf(10) |
| 1208 | 1.2039930378537762 |
| 1209 | |
Raymond Hettinger | 671d782 | 2019-05-01 17:49:12 -0700 | [diff] [blame] | 1210 | >>> el_niño = NormalDist(4, 2.5) |
| 1211 | >>> temperature_feb += el_niño # Add in a climate effect |
Raymond Hettinger | 11c7953 | 2019-02-23 14:44:07 -0800 | [diff] [blame] | 1212 | >>> temperature_feb |
| 1213 | NormalDist(mu=10.0, sigma=6.830080526611674) |
| 1214 | |
| 1215 | >>> temperature_feb * (9/5) + 32 # Convert to Fahrenheit |
| 1216 | NormalDist(mu=50.0, sigma=12.294144947901014) |
| 1217 | >>> temperature_feb.samples(3) # Generate random samples |
| 1218 | [7.672102882379219, 12.000027119750287, 4.647488369766392] |
| 1219 | |
Raymond Hettinger | 47d9987 | 2019-02-21 15:06:29 -0800 | [diff] [blame] | 1220 | |
Victor Stinner | ef9d9b6 | 2019-05-22 11:28:22 +0200 | [diff] [blame] | 1221 | sys |
| 1222 | --- |
| 1223 | |
| 1224 | Add new :func:`sys.unraisablehook` function which can be overridden to control |
| 1225 | how "unraisable exceptions" are handled. It is called when an exception has |
| 1226 | occurred but there is no way for Python to handle it. For example, when a |
| 1227 | destructor raises an exception or during garbage collection |
| 1228 | (:func:`gc.collect`). |
Victor Stinner | 01ae897 | 2019-06-03 16:28:01 +0200 | [diff] [blame] | 1229 | (Contributed by Victor Stinner in :issue:`36829`.) |
Victor Stinner | ef9d9b6 | 2019-05-22 11:28:22 +0200 | [diff] [blame] | 1230 | |
| 1231 | |
CAM Gerlach | e680c3d | 2019-03-21 09:44:51 -0500 | [diff] [blame] | 1232 | tarfile |
| 1233 | ------- |
| 1234 | |
| 1235 | The :mod:`tarfile` module now defaults to the modern pax (POSIX.1-2001) |
| 1236 | format for new archives, instead of the previous GNU-specific one. |
| 1237 | This improves cross-platform portability with a consistent encoding (UTF-8) |
| 1238 | in a standardized and extensible format, and offers several other benefits. |
| 1239 | (Contributed by C.A.M. Gerlach in :issue:`36268`.) |
| 1240 | |
| 1241 | |
Victor Stinner | cd590a7 | 2019-05-28 00:39:52 +0200 | [diff] [blame] | 1242 | threading |
| 1243 | --------- |
| 1244 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1245 | Add a new :func:`threading.excepthook` function which handles uncaught |
| 1246 | :meth:`threading.Thread.run` exception. It can be overridden to control how |
| 1247 | uncaught :meth:`threading.Thread.run` exceptions are handled. |
| 1248 | (Contributed by Victor Stinner in :issue:`1230540`.) |
Jake Tesler | 84846b0 | 2019-07-30 14:41:46 -0700 | [diff] [blame] | 1249 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1250 | Add a new :func:`threading.get_native_id` function and |
| 1251 | a :data:`~threading.Thread.native_id` |
| 1252 | attribute to the :class:`threading.Thread` class. These return the native |
| 1253 | integral Thread ID of the current thread assigned by the kernel. |
| 1254 | This feature is only available on certain platforms, see |
| 1255 | :func:`get_native_id <threading.get_native_id>` for more information. |
| 1256 | (Contributed by Jake Tesler in :issue:`36084`.) |
Victor Stinner | cd590a7 | 2019-05-28 00:39:52 +0200 | [diff] [blame] | 1257 | |
| 1258 | |
Tal Einat | dfba1f6 | 2018-10-24 10:20:05 +0300 | [diff] [blame] | 1259 | tokenize |
| 1260 | -------- |
| 1261 | |
| 1262 | The :mod:`tokenize` module now implicitly emits a ``NEWLINE`` token when |
| 1263 | provided with input that does not have a trailing new line. This behavior |
| 1264 | now matches what the C tokenizer does internally. |
| 1265 | (Contributed by Ammar Askar in :issue:`33899`.) |
| 1266 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1267 | |
Juliette Monsel | af5658a | 2018-10-08 18:29:24 +0200 | [diff] [blame] | 1268 | tkinter |
| 1269 | ------- |
| 1270 | |
| 1271 | Added methods :meth:`~tkinter.Spinbox.selection_from`, |
| 1272 | :meth:`~tkinter.Spinbox.selection_present`, |
| 1273 | :meth:`~tkinter.Spinbox.selection_range` and |
| 1274 | :meth:`~tkinter.Spinbox.selection_to` |
| 1275 | in the :class:`tkinter.Spinbox` class. |
| 1276 | (Contributed by Juliette Monsel in :issue:`34829`.) |
| 1277 | |
Juliette Monsel | bf03471 | 2018-10-12 18:44:10 +0200 | [diff] [blame] | 1278 | Added method :meth:`~tkinter.Canvas.moveto` |
| 1279 | in the :class:`tkinter.Canvas` class. |
| 1280 | (Contributed by Juliette Monsel in :issue:`23831`.) |
| 1281 | |
Zackery Spytz | 50866e9 | 2019-04-05 04:17:13 -0600 | [diff] [blame] | 1282 | The :class:`tkinter.PhotoImage` class now has |
| 1283 | :meth:`~tkinter.PhotoImage.transparency_get` and |
| 1284 | :meth:`~tkinter.PhotoImage.transparency_set` methods. (Contributed by |
| 1285 | Zackery Spytz in :issue:`25451`.) |
| 1286 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1287 | |
Joannah Nanjekye | 572168a | 2019-01-10 19:56:38 +0300 | [diff] [blame] | 1288 | time |
| 1289 | ---- |
| 1290 | |
| 1291 | Added new clock :data:`~time.CLOCK_UPTIME_RAW` for macOS 10.12. |
| 1292 | (Contributed by Joannah Nanjekye in :issue:`35702`.) |
| 1293 | |
Guido van Rossum | 9b33ce4 | 2019-06-11 13:42:35 -0700 | [diff] [blame] | 1294 | |
| 1295 | typing |
| 1296 | ------ |
| 1297 | |
| 1298 | The :mod:`typing` module incorporates several new features: |
| 1299 | |
Guido van Rossum | 9b33ce4 | 2019-06-11 13:42:35 -0700 | [diff] [blame] | 1300 | * A dictionary type with per-key types. See :pep:`589` and |
| 1301 | :class:`typing.TypedDict`. |
Raymond Hettinger | a329153 | 2019-10-13 23:32:03 -0700 | [diff] [blame] | 1302 | TypedDict uses only string keys. By default, every key is required |
| 1303 | to be present. Specify "total=False" to allow keys to be optional:: |
| 1304 | |
| 1305 | class Location(TypedDict, total=False): |
| 1306 | lat_long: tuple |
| 1307 | grid_square: str |
| 1308 | xy_coordinate: tuple |
Guido van Rossum | 9b33ce4 | 2019-06-11 13:42:35 -0700 | [diff] [blame] | 1309 | |
| 1310 | * Literal types. See :pep:`586` and :class:`typing.Literal`. |
Raymond Hettinger | a329153 | 2019-10-13 23:32:03 -0700 | [diff] [blame] | 1311 | Literal types indicate that a parameter or return value |
| 1312 | is constrained to one or more specific literal values:: |
| 1313 | |
| 1314 | def get_status(port: int) -> Literal['connected', 'disconnected']: |
| 1315 | ... |
Guido van Rossum | 9b33ce4 | 2019-06-11 13:42:35 -0700 | [diff] [blame] | 1316 | |
| 1317 | * "Final" variables, functions, methods and classes. See :pep:`591`, |
| 1318 | :class:`typing.Final` and :func:`typing.final`. |
Raymond Hettinger | a329153 | 2019-10-13 23:32:03 -0700 | [diff] [blame] | 1319 | The final qualifier instructs a static type checker to restrict |
| 1320 | subclassing, overriding, or reassignment:: |
| 1321 | |
| 1322 | pi: Final[float] = 3.1415926536 |
| 1323 | |
| 1324 | * Protocol definitions. See :pep:`544`, :class:`typing.Protocol` and |
| 1325 | :func:`typing.runtime_checkable`. Simple ABCs like |
| 1326 | :class:`typing.SupportsInt` are now ``Protocol`` subclasses. |
Guido van Rossum | 9b33ce4 | 2019-06-11 13:42:35 -0700 | [diff] [blame] | 1327 | |
| 1328 | * New protocol class :class:`typing.SupportsIndex`. |
| 1329 | |
| 1330 | * New functions :func:`typing.get_origin` and :func:`typing.get_args`. |
| 1331 | |
| 1332 | |
Max Bélanger | 2810dd7 | 2018-11-04 15:58:24 -0800 | [diff] [blame] | 1333 | unicodedata |
| 1334 | ----------- |
| 1335 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1336 | The :mod:`unicodedata` module has been upgraded to use the `Unicode 12.1.0 |
| 1337 | <http://blog.unicode.org/2019/05/unicode-12-1-en.html>`_ release. |
Raymond Hettinger | 482b6b5 | 2019-05-01 17:48:13 -0700 | [diff] [blame] | 1338 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1339 | New function :func:`~unicodedata.is_normalized` can be used to verify a string |
| 1340 | is in a specific normal form, often much faster than by actually normalizing |
| 1341 | the string. (Contributed by Max Belanger, David Euresti, and Greg Price in |
| 1342 | :issue:`32285` and :issue:`37966`). |
Max Bélanger | 2810dd7 | 2018-11-04 15:58:24 -0800 | [diff] [blame] | 1343 | |
Raymond Hettinger | 482b6b5 | 2019-05-01 17:48:13 -0700 | [diff] [blame] | 1344 | |
Lisa Roach | 0f221d0 | 2018-11-08 18:34:33 -0800 | [diff] [blame] | 1345 | unittest |
| 1346 | -------- |
| 1347 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 1348 | Added :class:`~unittest.mock.AsyncMock` to support an asynchronous version of |
| 1349 | :class:`~unittest.mock.Mock`. Appropriate new assert functions for testing |
| 1350 | have been added as well. |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1351 | (Contributed by Lisa Roach in :issue:`26467`). |
Lisa Roach | 77b3b77 | 2019-05-20 09:19:53 -0700 | [diff] [blame] | 1352 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1353 | Added :func:`~unittest.addModuleCleanup()` and |
| 1354 | :meth:`~unittest.TestCase.addClassCleanup()` to unittest to support |
| 1355 | cleanups for :func:`~unittest.setUpModule()` and |
| 1356 | :meth:`~unittest.TestCase.setUpClass()`. |
| 1357 | (Contributed by Lisa Roach in :issue:`24412`.) |
Lisa Roach | 0f221d0 | 2018-11-08 18:34:33 -0800 | [diff] [blame] | 1358 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1359 | Several mock assert functions now also print a list of actual calls upon |
| 1360 | failure. (Contributed by Petter Strandmark in :issue:`35047`.) |
Petter Strandmark | 001d63c | 2019-06-04 21:34:49 +0200 | [diff] [blame] | 1361 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1362 | :mod:`unittest` module gained support for coroutines to be used as test cases |
| 1363 | with :class:`unittest.IsolatedAsyncioTestCase`. |
| 1364 | (Contributed by Andrew Svetlov in :issue:`32972`.) |
Xtreak | 6a9fd66 | 2019-09-11 12:02:14 +0100 | [diff] [blame] | 1365 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1366 | Example:: |
Xtreak | 6a9fd66 | 2019-09-11 12:02:14 +0100 | [diff] [blame] | 1367 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1368 | import unittest |
Xtreak | 6a9fd66 | 2019-09-11 12:02:14 +0100 | [diff] [blame] | 1369 | |
| 1370 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1371 | class TestRequest(unittest.IsolatedAsyncioTestCase): |
Xtreak | 6a9fd66 | 2019-09-11 12:02:14 +0100 | [diff] [blame] | 1372 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1373 | async def asyncSetUp(self): |
| 1374 | self.connection = await AsyncConnection() |
Xtreak | 6a9fd66 | 2019-09-11 12:02:14 +0100 | [diff] [blame] | 1375 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1376 | async def test_get(self): |
| 1377 | response = await self.connection.get("https://example.com") |
| 1378 | self.assertEqual(response.status_code, 200) |
Xtreak | 6a9fd66 | 2019-09-11 12:02:14 +0100 | [diff] [blame] | 1379 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1380 | async def asyncTearDown(self): |
| 1381 | await self.connection.close() |
Xtreak | 6a9fd66 | 2019-09-11 12:02:14 +0100 | [diff] [blame] | 1382 | |
| 1383 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1384 | if __name__ == "__main__": |
| 1385 | unittest.main() |
Xtreak | 6a9fd66 | 2019-09-11 12:02:14 +0100 | [diff] [blame] | 1386 | |
| 1387 | |
Brett Cannon | d64ee1a | 2018-09-21 15:27:26 -0700 | [diff] [blame] | 1388 | venv |
| 1389 | ---- |
| 1390 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1391 | :mod:`venv` now includes an ``Activate.ps1`` script on all platforms for |
| 1392 | activating virtual environments under PowerShell Core 6.1. |
| 1393 | (Contributed by Brett Cannon in :issue:`32718`.) |
| 1394 | |
Brett Cannon | d64ee1a | 2018-09-21 15:27:26 -0700 | [diff] [blame] | 1395 | |
Mark Dickinson | 7abb6c0 | 2019-04-26 15:56:15 +0900 | [diff] [blame] | 1396 | weakref |
| 1397 | ------- |
| 1398 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1399 | The proxy objects returned by :func:`weakref.proxy` now support the matrix |
| 1400 | multiplication operators ``@`` and ``@=`` in addition to the other |
| 1401 | numeric operators. (Contributed by Mark Dickinson in :issue:`36669`.) |
| 1402 | |
Mark Dickinson | 7abb6c0 | 2019-04-26 15:56:15 +0900 | [diff] [blame] | 1403 | |
Christian Heimes | 17b1d5d | 2018-09-23 09:50:25 +0200 | [diff] [blame] | 1404 | xml |
| 1405 | --- |
| 1406 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1407 | As mitigation against DTD and external entity retrieval, the |
| 1408 | :mod:`xml.dom.minidom` and :mod:`xml.sax` modules no longer process |
| 1409 | external entities by default. |
| 1410 | (Contributed by Christian Heimes in :issue:`17239`.) |
Christian Heimes | 17b1d5d | 2018-09-23 09:50:25 +0200 | [diff] [blame] | 1411 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1412 | The ``.find*()`` methods in the :mod:`xml.etree.ElementTree` module |
| 1413 | support wildcard searches like ``{*}tag`` which ignores the namespace |
| 1414 | and ``{namespace}*`` which returns all tags in the given namespace. |
| 1415 | (Contributed by Stefan Behnel in :issue:`28238`.) |
Stefan Behnel | 4754168 | 2019-05-03 20:58:16 +0200 | [diff] [blame] | 1416 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1417 | The :mod:`xml.etree.ElementTree` module provides a new function |
| 1418 | :func:`–xml.etree.ElementTree.canonicalize()` that implements C14N 2.0. |
| 1419 | (Contributed by Stefan Behnel in :issue:`13611`.) |
Stefan Behnel | e1d5dd6 | 2019-05-01 22:34:13 +0200 | [diff] [blame] | 1420 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1421 | The target object of :class:`xml.etree.ElementTree.XMLParser` can |
| 1422 | receive namespace declaration events through the new callback methods |
| 1423 | ``start_ns()`` and ``end_ns()``. Additionally, the |
| 1424 | :class:`xml.etree.ElementTree.TreeBuilder` target can be configured |
| 1425 | to process events about comments and processing instructions to include |
| 1426 | them in the generated tree. |
| 1427 | (Contributed by Stefan Behnel in :issue:`36676` and :issue:`36673`.) |
| 1428 | |
Christian Heimes | 17b1d5d | 2018-09-23 09:50:25 +0200 | [diff] [blame] | 1429 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 1430 | xmlrpc |
| 1431 | ------ |
| 1432 | |
| 1433 | :class:`xmlrpc.client.ServerProxy` now supports an optional *headers* keyword |
| 1434 | argument for a sequence of HTTP headers to be sent with each request. Among |
| 1435 | other things, this makes it possible to upgrade from default basic |
| 1436 | authentication to faster session authentication. |
| 1437 | (Contributed by Cédric Krier in :issue:`35153`.) |
| 1438 | |
| 1439 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 1440 | Optimizations |
| 1441 | ============= |
| 1442 | |
Victor Stinner | 9daecf3 | 2019-01-16 00:02:35 +0100 | [diff] [blame] | 1443 | * The :mod:`subprocess` module can now use the :func:`os.posix_spawn` function |
| 1444 | in some cases for better performance. Currently, it is only used on macOS |
| 1445 | and Linux (using glibc 2.24 or newer) if all these conditions are met: |
| 1446 | |
| 1447 | * *close_fds* is false; |
Victor Stinner | f6243ac | 2019-01-23 19:00:39 +0100 | [diff] [blame] | 1448 | * *preexec_fn*, *pass_fds*, *cwd* and *start_new_session* parameters |
| 1449 | are not set; |
Victor Stinner | 8c34956 | 2019-01-16 23:38:06 +0100 | [diff] [blame] | 1450 | * the *executable* path contains a directory. |
Victor Stinner | 9daecf3 | 2019-01-16 00:02:35 +0100 | [diff] [blame] | 1451 | |
Victor Stinner | 01ae897 | 2019-06-03 16:28:01 +0200 | [diff] [blame] | 1452 | (Contributed by Joannah Nanjekye and Victor Stinner in :issue:`35537`.) |
| 1453 | |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 1454 | * :func:`shutil.copyfile`, :func:`shutil.copy`, :func:`shutil.copy2`, |
| 1455 | :func:`shutil.copytree` and :func:`shutil.move` use platform-specific |
Giampaolo Rodola | 413d955 | 2019-05-30 14:05:41 +0800 | [diff] [blame] | 1456 | "fast-copy" syscalls on Linux and macOS in order to copy the file |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 1457 | more efficiently. |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 1458 | "fast-copy" means that the copying operation occurs within the kernel, |
| 1459 | avoiding the use of userspace buffers in Python as in |
| 1460 | "``outfd.write(infd.read())``". |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 1461 | On Windows :func:`shutil.copyfile` uses a bigger default buffer size (1 MiB |
| 1462 | instead of 16 KiB) and a :func:`memoryview`-based variant of |
| 1463 | :func:`shutil.copyfileobj` is used. |
| 1464 | The speedup for copying a 512 MiB file within the same partition is about |
| 1465 | +26% on Linux, +50% on macOS and +40% on Windows. Also, much less CPU cycles |
| 1466 | are consumed. |
| 1467 | See :ref:`shutil-platform-dependent-efficient-copy-operations` section. |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1468 | (Contributed by Giampaolo Rodolà in :issue:`33671`.) |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 1469 | |
Giampaolo Rodola | 19c46a4 | 2018-11-12 06:18:15 -0800 | [diff] [blame] | 1470 | * :func:`shutil.copytree` uses :func:`os.scandir` function and all copy |
| 1471 | functions depending from it use cached :func:`os.stat` values. The speedup |
| 1472 | for copying a directory with 8000 files is around +9% on Linux, +20% on |
| 1473 | Windows and +30% on a Windows SMB share. Also the number of :func:`os.stat` |
| 1474 | syscalls is reduced by 38% making :func:`shutil.copytree` especially faster |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1475 | on network filesystems. (Contributed by Giampaolo Rodolà in :issue:`33695`.) |
Giampaolo Rodola | 19c46a4 | 2018-11-12 06:18:15 -0800 | [diff] [blame] | 1476 | |
Łukasz Langa | c51d8c9 | 2018-04-03 23:06:53 -0700 | [diff] [blame] | 1477 | * The default protocol in the :mod:`pickle` module is now Protocol 4, |
| 1478 | first introduced in Python 3.4. It offers better performance and smaller |
| 1479 | size compared to Protocol 3 available since Python 3.0. |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 1480 | |
INADA Naoki | d5c875b | 2018-07-11 17:42:49 +0900 | [diff] [blame] | 1481 | * Removed one ``Py_ssize_t`` member from ``PyGC_Head``. All GC tracked |
| 1482 | objects (e.g. tuple, list, dict) size is reduced 4 or 8 bytes. |
Jero Bado | b1fa72a | 2019-10-18 15:48:48 +0800 | [diff] [blame] | 1483 | (Contributed by Inada Naoki in :issue:`33597`.) |
INADA Naoki | d5c875b | 2018-07-11 17:42:49 +0900 | [diff] [blame] | 1484 | |
Tal Einat | 5475253 | 2018-09-10 16:11:04 +0300 | [diff] [blame] | 1485 | * :class:`uuid.UUID` now uses ``__slots__`` to reduce its memory footprint. |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1486 | (Contributed by Wouter Bolsterlee and Tal Einat in :issue:`30977`) |
Tal Einat | 5475253 | 2018-09-10 16:11:04 +0300 | [diff] [blame] | 1487 | |
Raymond Hettinger | 63fa1cf | 2019-02-16 12:02:22 -0800 | [diff] [blame] | 1488 | * Improved performance of :func:`operator.itemgetter` by 33%. Optimized |
| 1489 | argument handling and added a fast path for the common case of a single |
| 1490 | non-negative integer index into a tuple (which is the typical use case in |
| 1491 | the standard library). (Contributed by Raymond Hettinger in |
| 1492 | :issue:`35664`.) |
| 1493 | |
| 1494 | * Sped-up field lookups in :func:`collections.namedtuple`. They are now more |
| 1495 | than two times faster, making them the fastest form of instance variable |
| 1496 | lookup in Python. (Contributed by Raymond Hettinger, Pablo Galindo, and |
Joe Jevnik | f36f892 | 2019-02-21 16:00:40 -0500 | [diff] [blame] | 1497 | Joe Jevnik, Serhiy Storchaka in :issue:`32492`.) |
Raymond Hettinger | 63fa1cf | 2019-02-16 12:02:22 -0800 | [diff] [blame] | 1498 | |
Pablo Galindo | c61e229 | 2018-10-28 22:03:18 +0000 | [diff] [blame] | 1499 | * The :class:`list` constructor does not overallocate the internal item buffer |
| 1500 | if the input iterable has a known length (the input implements ``__len__``). |
Raymond Hettinger | e182318 | 2019-02-16 12:47:48 -0800 | [diff] [blame] | 1501 | This makes the created list 12% smaller on average. (Contributed by |
| 1502 | Raymond Hettinger and Pablo Galindo in :issue:`33234`.) |
Pablo Galindo | c61e229 | 2018-10-28 22:03:18 +0000 | [diff] [blame] | 1503 | |
Stefan Behnel | d8b9e1f | 2019-02-20 18:29:24 +0100 | [diff] [blame] | 1504 | * Doubled the speed of class variable writes. When a non-dunder attribute |
| 1505 | was updated, there was an unnecessary call to update slots. |
| 1506 | (Contributed by Stefan Behnel, Pablo Galindo Salgado, Raymond Hettinger, |
| 1507 | Neil Schemenauer, and Serhiy Storchaka in :issue:`36012`.) |
| 1508 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 1509 | * Reduced an overhead of converting arguments passed to many builtin functions |
| 1510 | and methods. This sped up calling some simple builtin functions and |
| 1511 | methods up to 20--50%. (Contributed by Serhiy Storchaka in :issue:`23867`, |
| 1512 | :issue:`35582` and :issue:`36127`.) |
| 1513 | |
Inada Naoki | 91234a1 | 2019-06-03 21:30:58 +0900 | [diff] [blame] | 1514 | * ``LOAD_GLOBAL`` instruction now uses new "per opcode cache" mechanism. |
| 1515 | It is about 40% faster now. (Contributed by Yury Selivanov and Inada Naoki in |
| 1516 | :issue:`26219`.) |
| 1517 | |
Serhiy Storchaka | ceeef10 | 2018-06-15 11:09:43 +0300 | [diff] [blame] | 1518 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 1519 | Build and C API Changes |
| 1520 | ======================= |
| 1521 | |
Victor Stinner | 7efc526 | 2019-06-15 03:24:41 +0200 | [diff] [blame] | 1522 | * Default :data:`sys.abiflags` became an empty string: the ``m`` flag for |
| 1523 | pymalloc became useless (builds with and without pymalloc are ABI compatible) |
| 1524 | and so has been removed. (Contributed by Victor Stinner in :issue:`36707`.) |
| 1525 | |
| 1526 | Example of changes: |
| 1527 | |
| 1528 | * Only ``python3.8`` program is installed, ``python3.8m`` program is gone. |
| 1529 | * Only ``python3.8-config`` script is installed, ``python3.8m-config`` script |
| 1530 | is gone. |
| 1531 | * The ``m`` flag has been removed from the suffix of dynamic library |
| 1532 | filenames: extension modules in the standard library as well as those |
| 1533 | produced and installed by third-party packages, like those downloaded from |
| 1534 | PyPI. On Linux, for example, the Python 3.7 suffix |
| 1535 | ``.cpython-37m-x86_64-linux-gnu.so`` became |
| 1536 | ``.cpython-38-x86_64-linux-gnu.so`` in Python 3.8. |
| 1537 | |
Victor Stinner | bd5798f | 2019-06-14 19:43:43 +0200 | [diff] [blame] | 1538 | * The header files have been reorganized to better separate the different kinds |
| 1539 | of APIs: |
| 1540 | |
| 1541 | * ``Include/*.h`` should be the portable public stable C API. |
| 1542 | * ``Include/cpython/*.h`` should be the unstable C API specific to CPython; |
Victor Stinner | af41c56 | 2019-06-20 01:44:58 +0200 | [diff] [blame] | 1543 | public API, with some private API prefixed by ``_Py`` or ``_PY``. |
Victor Stinner | bd5798f | 2019-06-14 19:43:43 +0200 | [diff] [blame] | 1544 | * ``Include/internal/*.h`` is the private internal C API very specific to |
| 1545 | CPython. This API comes with no backward compatibility warranty and should |
| 1546 | not be used outside CPython. It is only exposed for very specific needs |
| 1547 | like debuggers and profiles which has to access to CPython internals |
| 1548 | without calling functions. This API is now installed by ``make install``. |
| 1549 | |
| 1550 | (Contributed by Victor Stinner in :issue:`35134` and :issue:`35081`, |
Hugo van Kemenade | 547c60c | 2019-10-12 20:53:36 +0300 | [diff] [blame] | 1551 | work initiated by Eric Snow in Python 3.7.) |
Victor Stinner | bd5798f | 2019-06-14 19:43:43 +0200 | [diff] [blame] | 1552 | |
| 1553 | * Some macros have been converted to static inline functions: parameter types |
| 1554 | and return type are well defined, they don't have issues specific to macros, |
| 1555 | variables have a local scopes. Examples: |
| 1556 | |
| 1557 | * :c:func:`Py_INCREF`, :c:func:`Py_DECREF` |
| 1558 | * :c:func:`Py_XINCREF`, :c:func:`Py_XDECREF` |
| 1559 | * :c:func:`PyObject_INIT`, :c:func:`PyObject_INIT_VAR` |
| 1560 | * Private functions: :c:func:`_PyObject_GC_TRACK`, |
| 1561 | :c:func:`_PyObject_GC_UNTRACK`, :c:func:`_Py_Dealloc` |
| 1562 | |
| 1563 | (Contributed by Victor Stinner in :issue:`35059`.) |
| 1564 | |
Victor Stinner | bf4ac2d | 2019-01-22 17:39:03 +0100 | [diff] [blame] | 1565 | * The :c:func:`PyByteArray_Init` and :c:func:`PyByteArray_Fini` functions have |
| 1566 | been removed. They did nothing since Python 2.7.4 and Python 3.2.0, were |
| 1567 | excluded from the limited API (stable ABI), and were not documented. |
Victor Stinner | c68e3fb | 2019-06-20 22:41:25 +0200 | [diff] [blame] | 1568 | (Contributed by Victor Stinner in :issue:`35713`.) |
Victor Stinner | bf4ac2d | 2019-01-22 17:39:03 +0100 | [diff] [blame] | 1569 | |
Serhiy Storchaka | ceeef10 | 2018-06-15 11:09:43 +0300 | [diff] [blame] | 1570 | * The result of :c:func:`PyExceptionClass_Name` is now of type |
| 1571 | ``const char *`` rather of ``char *``. |
| 1572 | (Contributed by Serhiy Storchaka in :issue:`33818`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 1573 | |
Antoine Pitrou | 961d54c | 2018-07-16 19:03:03 +0200 | [diff] [blame] | 1574 | * The duality of ``Modules/Setup.dist`` and ``Modules/Setup`` has been |
| 1575 | removed. Previously, when updating the CPython source tree, one had |
| 1576 | to manually copy ``Modules/Setup.dist`` (inside the source tree) to |
| 1577 | ``Modules/Setup`` (inside the build tree) in order to reflect any changes |
| 1578 | upstream. This was of a small benefit to packagers at the expense of |
| 1579 | a frequent annoyance to developers following CPython development, as |
| 1580 | forgetting to copy the file could produce build failures. |
| 1581 | |
| 1582 | Now the build system always reads from ``Modules/Setup`` inside the source |
| 1583 | tree. People who want to customize that file are encouraged to maintain |
| 1584 | their changes in a git fork of CPython or as patch files, as they would do |
| 1585 | for any other change to the source tree. |
| 1586 | |
| 1587 | (Contributed by Antoine Pitrou in :issue:`32430`.) |
| 1588 | |
Serhiy Storchaka | 6a44f6e | 2019-02-25 17:57:58 +0200 | [diff] [blame] | 1589 | * Functions that convert Python number to C integer like |
| 1590 | :c:func:`PyLong_AsLong` and argument parsing functions like |
| 1591 | :c:func:`PyArg_ParseTuple` with integer converting format units like ``'i'`` |
| 1592 | will now use the :meth:`~object.__index__` special method instead of |
| 1593 | :meth:`~object.__int__`, if available. The deprecation warning will be |
| 1594 | emitted for objects with the ``__int__()`` method but without the |
| 1595 | ``__index__()`` method (like :class:`~decimal.Decimal` and |
| 1596 | :class:`~fractions.Fraction`). :c:func:`PyNumber_Check` will now return |
| 1597 | ``1`` for objects implementing ``__index__()``. |
Serhiy Storchaka | bdbad71 | 2019-06-02 00:05:48 +0300 | [diff] [blame] | 1598 | :c:func:`PyNumber_Long`, :c:func:`PyNumber_Float` and |
| 1599 | :c:func:`PyFloat_AsDouble` also now use the ``__index__()`` method if |
| 1600 | available. |
| 1601 | (Contributed by Serhiy Storchaka in :issue:`36048` and :issue:`20092`.) |
Serhiy Storchaka | 6a44f6e | 2019-02-25 17:57:58 +0200 | [diff] [blame] | 1602 | |
Eddie Elizondo | 364f0b0 | 2019-03-27 07:52:18 -0400 | [diff] [blame] | 1603 | * Heap-allocated type objects will now increase their reference count |
| 1604 | in :c:func:`PyObject_Init` (and its parallel macro ``PyObject_INIT``) |
| 1605 | instead of in :c:func:`PyType_GenericAlloc`. Types that modify instance |
| 1606 | allocation or deallocation may need to be adjusted. |
| 1607 | (Contributed by Eddie Elizondo in :issue:`35810`.) |
| 1608 | |
Pablo Galindo | 4a2edc3 | 2019-07-01 11:35:05 +0100 | [diff] [blame] | 1609 | * The new function :c:func:`PyCode_NewWithPosOnlyArgs` allows to create |
| 1610 | code objects like :c:func:`PyCode_New`, but with an extra *posonlyargcount* |
| 1611 | parameter for indicating the number of positional-only arguments. |
| 1612 | (Contributed by Pablo Galindo in :issue:`37221`.) |
| 1613 | |
Victor Stinner | 1ce152a | 2019-09-24 17:44:15 +0200 | [diff] [blame] | 1614 | * :c:func:`Py_SetPath` now sets :data:`sys.executable` to the program full |
| 1615 | path (:c:func:`Py_GetProgramFullPath`) rather than to the program name |
| 1616 | (:c:func:`Py_GetProgramName`). |
| 1617 | (Contributed by Victor Stinner in :issue:`38234`.) |
| 1618 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 1619 | |
| 1620 | Deprecated |
| 1621 | ========== |
| 1622 | |
Victor Stinner | 1da4462 | 2019-07-05 10:44:12 +0200 | [diff] [blame] | 1623 | * The distutils ``bdist_wininst`` command is now deprecated, use |
| 1624 | ``bdist_wheel`` (wheel packages) instead. |
| 1625 | (Contributed by Victor Stinner in :issue:`37481`.) |
| 1626 | |
Serhiy Storchaka | 02ec92f | 2018-07-24 12:03:34 +0300 | [diff] [blame] | 1627 | * Deprecated methods ``getchildren()`` and ``getiterator()`` in |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1628 | the :mod:`~xml.etree.ElementTree` module now emit a |
Serhiy Storchaka | 02ec92f | 2018-07-24 12:03:34 +0300 | [diff] [blame] | 1629 | :exc:`DeprecationWarning` instead of :exc:`PendingDeprecationWarning`. |
| 1630 | They will be removed in Python 3.9. |
| 1631 | (Contributed by Serhiy Storchaka in :issue:`29209`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 1632 | |
Elvis Pranskevichus | 22d2508 | 2018-07-30 11:42:43 +0100 | [diff] [blame] | 1633 | * Passing an object that is not an instance of |
| 1634 | :class:`concurrent.futures.ThreadPoolExecutor` to |
Kyle Stanley | 3bbb6db | 2019-10-24 00:15:25 -0400 | [diff] [blame] | 1635 | :meth:`loop.set_default_executor() <asyncio.loop.set_default_executor>` is |
Elvis Pranskevichus | 22d2508 | 2018-07-30 11:42:43 +0100 | [diff] [blame] | 1636 | deprecated and will be prohibited in Python 3.9. |
| 1637 | (Contributed by Elvis Pranskevichus in :issue:`34075`.) |
| 1638 | |
Berker Peksag | ef8861c | 2018-08-21 17:58:49 +0300 | [diff] [blame] | 1639 | * The :meth:`__getitem__` methods of :class:`xml.dom.pulldom.DOMEventStream`, |
| 1640 | :class:`wsgiref.util.FileWrapper` and :class:`fileinput.FileInput` have been |
| 1641 | deprecated. |
| 1642 | |
| 1643 | Implementations of these methods have been ignoring their *index* parameter, |
| 1644 | and returning the next item instead. |
Berker Peksag | ef8861c | 2018-08-21 17:58:49 +0300 | [diff] [blame] | 1645 | (Contributed by Berker Peksag in :issue:`9372`.) |
| 1646 | |
Raymond Hettinger | f7b57df | 2019-03-18 09:53:56 -0700 | [diff] [blame] | 1647 | * The :class:`typing.NamedTuple` class has deprecated the ``_field_types`` |
| 1648 | attribute in favor of the ``__annotations__`` attribute which has the same |
Hugo van Kemenade | 547c60c | 2019-10-12 20:53:36 +0300 | [diff] [blame] | 1649 | information. (Contributed by Raymond Hettinger in :issue:`36320`.) |
Raymond Hettinger | f7b57df | 2019-03-18 09:53:56 -0700 | [diff] [blame] | 1650 | |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 1651 | * :mod:`ast` classes ``Num``, ``Str``, ``Bytes``, ``NameConstant`` and |
| 1652 | ``Ellipsis`` are considered deprecated and will be removed in future Python |
| 1653 | versions. :class:`~ast.Constant` should be used instead. |
| 1654 | (Contributed by Serhiy Storchaka in :issue:`32892`.) |
| 1655 | |
Serhiy Storchaka | c3ea41e | 2019-08-26 10:13:19 +0300 | [diff] [blame] | 1656 | * :class:`ast.NodeVisitor` methods ``visit_Num()``, ``visit_Str()``, |
| 1657 | ``visit_Bytes()``, ``visit_NameConstant()`` and ``visit_Ellipsis()`` are |
| 1658 | deprecated now and will not be called in future Python versions. |
| 1659 | Add the :meth:`~ast.NodeVisitor.visit_Constant` method to handle all |
| 1660 | constant nodes. |
| 1661 | (Contributed by Serhiy Storchaka in :issue:`36917`.) |
| 1662 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 1663 | * The :func:`asyncio.coroutine` :term:`decorator` is deprecated and will be |
| 1664 | removed in version 3.10. Instead of ``@asyncio.coroutine``, use |
| 1665 | :keyword:`async def` instead. |
| 1666 | (Contributed by Andrew Svetlov in :issue:`36921`.) |
| 1667 | |
Kyle Stanley | 3bbb6db | 2019-10-24 00:15:25 -0400 | [diff] [blame] | 1668 | * In :mod:`asyncio`, the explicit passing of a *loop* argument has been |
| 1669 | deprecated and will be removed in version 3.10 for the following: |
| 1670 | :func:`asyncio.sleep`, :func:`asyncio.gather`, :func:`asyncio.shield`, |
| 1671 | :func:`asyncio.wait_for`, :func:`asyncio.wait`, :func:`asyncio.as_completed`, |
| 1672 | :class:`asyncio.Task`, :class:`asyncio.Lock`, :class:`asyncio.Event`, |
| 1673 | :class:`asyncio.Condition`, :class:`asyncio.Semaphore`, |
| 1674 | :class:`asyncio.BoundedSemaphore`, :class:`asyncio.Queue`, |
| 1675 | :func:`asyncio.create_subprocess_exec`, and |
| 1676 | :func:`asyncio.create_subprocess_shell`. |
| 1677 | |
| 1678 | * The explicit passing of coroutine objects to :func:`asyncio.wait` has been |
Kyle Stanley | 457306b | 2019-10-28 21:53:22 -0400 | [diff] [blame] | 1679 | deprecated and will be removed in version 3.11. |
| 1680 | (Contributed by Yury Selivanov in :issue:`34790`.) |
Kyle Stanley | 3bbb6db | 2019-10-24 00:15:25 -0400 | [diff] [blame] | 1681 | |
Serhiy Storchaka | fec35c9 | 2018-10-27 08:00:41 +0300 | [diff] [blame] | 1682 | * The following functions and methods are deprecated in the :mod:`gettext` |
| 1683 | module: :func:`~gettext.lgettext`, :func:`~gettext.ldgettext`, |
| 1684 | :func:`~gettext.lngettext` and :func:`~gettext.ldngettext`. |
| 1685 | They return encoded bytes, and it's possible that you will get unexpected |
| 1686 | Unicode-related exceptions if there are encoding problems with the |
| 1687 | translated strings. It's much better to use alternatives which return |
| 1688 | Unicode strings in Python 3. These functions have been broken for a long time. |
| 1689 | |
| 1690 | Function :func:`~gettext.bind_textdomain_codeset`, methods |
| 1691 | :meth:`~gettext.NullTranslations.output_charset` and |
| 1692 | :meth:`~gettext.NullTranslations.set_output_charset`, and the *codeset* |
| 1693 | parameter of functions :func:`~gettext.translation` and |
| 1694 | :func:`~gettext.install` are also deprecated, since they are only used for |
| 1695 | for the ``l*gettext()`` functions. |
Serhiy Storchaka | fec35c9 | 2018-10-27 08:00:41 +0300 | [diff] [blame] | 1696 | (Contributed by Serhiy Storchaka in :issue:`33710`.) |
| 1697 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1698 | * The :meth:`~threading.Thread.isAlive()` method of :class:`threading.Thread` |
| 1699 | has been deprecated. |
Dong-hee Na | 89669ff | 2019-01-17 21:14:45 +0900 | [diff] [blame] | 1700 | (Contributed by Dong-hee Na in :issue:`35283`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 1701 | |
Serhiy Storchaka | 6a44f6e | 2019-02-25 17:57:58 +0200 | [diff] [blame] | 1702 | * Many builtin and extension functions that take integer arguments will |
| 1703 | now emit a deprecation warning for :class:`~decimal.Decimal`\ s, |
| 1704 | :class:`~fractions.Fraction`\ s and any other objects that can be converted |
| 1705 | to integers only with a loss (e.g. that have the :meth:`~object.__int__` |
| 1706 | method but do not have the :meth:`~object.__index__` method). In future |
| 1707 | version they will be errors. |
| 1708 | (Contributed by Serhiy Storchaka in :issue:`36048`.) |
| 1709 | |
Serhiy Storchaka | 42a139e | 2019-04-01 09:16:35 +0300 | [diff] [blame] | 1710 | * Deprecated passing the following arguments as keyword arguments: |
| 1711 | |
| 1712 | - *func* in :func:`functools.partialmethod`, :func:`weakref.finalize`, |
| 1713 | :meth:`profile.Profile.runcall`, :meth:`cProfile.Profile.runcall`, |
| 1714 | :meth:`bdb.Bdb.runcall`, :meth:`trace.Trace.runfunc` and |
| 1715 | :func:`curses.wrapper`. |
Serhiy Storchaka | 2085bd0 | 2019-06-01 11:00:15 +0300 | [diff] [blame] | 1716 | - *function* in :meth:`unittest.TestCase.addCleanup`. |
Serhiy Storchaka | 42a139e | 2019-04-01 09:16:35 +0300 | [diff] [blame] | 1717 | - *fn* in the :meth:`~concurrent.futures.Executor.submit` method of |
| 1718 | :class:`concurrent.futures.ThreadPoolExecutor` and |
| 1719 | :class:`concurrent.futures.ProcessPoolExecutor`. |
| 1720 | - *callback* in :meth:`contextlib.ExitStack.callback`, |
| 1721 | :meth:`contextlib.AsyncExitStack.callback` and |
| 1722 | :meth:`contextlib.AsyncExitStack.push_async_callback`. |
| 1723 | - *c* and *typeid* in the :meth:`~multiprocessing.managers.Server.create` |
| 1724 | method of :class:`multiprocessing.managers.Server` and |
| 1725 | :class:`multiprocessing.managers.SharedMemoryServer`. |
| 1726 | - *obj* in :func:`weakref.finalize`. |
| 1727 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 1728 | In future releases of Python, they will be :ref:`positional-only |
Serhiy Storchaka | 42a139e | 2019-04-01 09:16:35 +0300 | [diff] [blame] | 1729 | <positional-only_parameter>`. |
| 1730 | (Contributed by Serhiy Storchaka in :issue:`36492`.) |
| 1731 | |
Serhiy Storchaka | 6a44f6e | 2019-02-25 17:57:58 +0200 | [diff] [blame] | 1732 | |
Victor Stinner | 73104fa | 2018-11-29 09:58:20 +0100 | [diff] [blame] | 1733 | API and Feature Removals |
| 1734 | ======================== |
| 1735 | |
| 1736 | The following features and APIs have been removed from Python 3.8: |
| 1737 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 1738 | * Starting with Python 3.3, importing ABCs from :mod:`collections` was |
| 1739 | deprecated, and importing should be done from :mod:`collections.abc`. Being |
| 1740 | able to import from collections was marked for removal in 3.8, but has been |
| 1741 | delayed to 3.9. (See :issue:`36952`.) |
| 1742 | |
Victor Stinner | d7538dd | 2018-12-14 13:37:26 +0100 | [diff] [blame] | 1743 | * The :mod:`macpath` module, deprecated in Python 3.7, has been removed. |
| 1744 | (Contributed by Victor Stinner in :issue:`35471`.) |
| 1745 | |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1746 | * The function :func:`platform.popen` has been removed, after having been |
| 1747 | deprecated since Python 3.3: use :func:`os.popen` instead. |
Victor Stinner | 01ae897 | 2019-06-03 16:28:01 +0200 | [diff] [blame] | 1748 | (Contributed by Victor Stinner in :issue:`35345`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 1749 | |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1750 | * The function :func:`time.clock` has been removed, after having been |
| 1751 | deprecated since Python 3.3: use :func:`time.perf_counter` or |
| 1752 | :func:`time.process_time` instead, depending |
| 1753 | on your requirements, to have well-defined behavior. |
Victor Stinner | 01ae897 | 2019-06-03 16:28:01 +0200 | [diff] [blame] | 1754 | (Contributed by Matthias Bussonnier in :issue:`36895`.) |
Matthias Bussonnier | b6a09ae | 2019-05-13 12:23:07 -0700 | [diff] [blame] | 1755 | |
Brett Cannon | a8c3424 | 2018-04-20 14:15:40 -0700 | [diff] [blame] | 1756 | * The ``pyvenv`` script has been removed in favor of ``python3.8 -m venv`` |
| 1757 | to help eliminate confusion as to what Python interpreter the ``pyvenv`` |
| 1758 | script is tied to. (Contributed by Brett Cannon in :issue:`25427`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 1759 | |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1760 | * ``parse_qs``, ``parse_qsl``, and ``escape`` are removed from the :mod:`cgi` |
| 1761 | module. They are deprecated in Python 3.2 or older. They should be imported |
Simon Willison | 1abf543 | 2019-09-11 09:25:26 -0500 | [diff] [blame] | 1762 | from the ``urllib.parse`` and ``html`` modules instead. |
INADA Naoki | 698865d | 2018-06-19 17:28:50 +0900 | [diff] [blame] | 1763 | |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1764 | * ``filemode`` function is removed from the :mod:`tarfile` module. |
INADA Naoki | 461a1c4 | 2018-06-28 17:10:36 +0900 | [diff] [blame] | 1765 | It is not documented and deprecated since Python 3.3. |
INADA Naoki | 698865d | 2018-06-19 17:28:50 +0900 | [diff] [blame] | 1766 | |
Serhiy Storchaka | 02ec92f | 2018-07-24 12:03:34 +0300 | [diff] [blame] | 1767 | * The :class:`~xml.etree.ElementTree.XMLParser` constructor no longer accepts |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1768 | the *html* argument. It never had an effect and was deprecated in Python 3.4. |
Serhiy Storchaka | 02ec92f | 2018-07-24 12:03:34 +0300 | [diff] [blame] | 1769 | All other parameters are now :ref:`keyword-only <keyword-only_parameter>`. |
| 1770 | (Contributed by Serhiy Storchaka in :issue:`29209`.) |
| 1771 | |
| 1772 | * Removed the ``doctype()`` method of :class:`~xml.etree.ElementTree.XMLParser`. |
| 1773 | (Contributed by Serhiy Storchaka in :issue:`29209`.) |
| 1774 | |
Inada Naoki | 6a16b18 | 2019-03-18 15:44:11 +0900 | [diff] [blame] | 1775 | * "unicode_internal" codec is removed. |
| 1776 | (Contributed by Inada Naoki in :issue:`36297`.) |
| 1777 | |
Aviv Palivoda | e657624 | 2019-05-09 21:05:45 +0300 | [diff] [blame] | 1778 | * The ``Cache`` and ``Statement`` objects of the :mod:`sqlite3` module are not |
| 1779 | exposed to the user. |
| 1780 | (Contributed by Aviv Palivoda in :issue:`30262`.) |
| 1781 | |
Matthias Bussonnier | 1a3faf9 | 2019-05-20 13:44:11 -0700 | [diff] [blame] | 1782 | * The ``bufsize`` keyword argument of :func:`fileinput.input` and |
| 1783 | :func:`fileinput.FileInput` which was ignored and deprecated since Python 3.6 |
Hugo van Kemenade | 547c60c | 2019-10-12 20:53:36 +0300 | [diff] [blame] | 1784 | has been removed. :issue:`36952` (Contributed by Matthias Bussonnier.) |
Matthias Bussonnier | 1a3faf9 | 2019-05-20 13:44:11 -0700 | [diff] [blame] | 1785 | |
Matthias Bussonnier | 382034b | 2019-05-28 10:30:35 -0700 | [diff] [blame] | 1786 | * The functions :func:`sys.set_coroutine_wrapper` and |
| 1787 | :func:`sys.get_coroutine_wrapper` deprecated in Python 3.7 have been removed; |
Hugo van Kemenade | 547c60c | 2019-10-12 20:53:36 +0300 | [diff] [blame] | 1788 | :issue:`36933` (Contributed by Matthias Bussonnier.) |
Matthias Bussonnier | 3880f26 | 2019-05-28 00:10:59 -0700 | [diff] [blame] | 1789 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 1790 | |
| 1791 | Porting to Python 3.8 |
| 1792 | ===================== |
| 1793 | |
| 1794 | This section lists previously described changes and other bugfixes |
| 1795 | that may require changes to your code. |
| 1796 | |
| 1797 | |
Serhiy Storchaka | 07ca9af | 2018-02-04 10:53:48 +0200 | [diff] [blame] | 1798 | Changes in Python behavior |
| 1799 | -------------------------- |
| 1800 | |
| 1801 | * Yield expressions (both ``yield`` and ``yield from`` clauses) are now disallowed |
| 1802 | in comprehensions and generator expressions (aside from the iterable expression |
Serhiy Storchaka | 2b57c43 | 2018-12-19 08:09:46 +0200 | [diff] [blame] | 1803 | in the leftmost :keyword:`!for` clause). |
Serhiy Storchaka | 07ca9af | 2018-02-04 10:53:48 +0200 | [diff] [blame] | 1804 | (Contributed by Serhiy Storchaka in :issue:`10544`.) |
| 1805 | |
Serhiy Storchaka | 3bcbedc | 2019-01-18 07:47:48 +0200 | [diff] [blame] | 1806 | * The compiler now produces a :exc:`SyntaxWarning` when identity checks |
| 1807 | (``is`` and ``is not``) are used with certain types of literals |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1808 | (e.g. strings, numbers). These can often work by accident in CPython, |
Serhiy Storchaka | 3bcbedc | 2019-01-18 07:47:48 +0200 | [diff] [blame] | 1809 | but are not guaranteed by the language spec. The warning advises users |
| 1810 | to use equality tests (``==`` and ``!=``) instead. |
| 1811 | (Contributed by Serhiy Storchaka in :issue:`34850`.) |
| 1812 | |
Serhiy Storchaka | 7a0630c | 2019-04-08 14:34:04 +0300 | [diff] [blame] | 1813 | * The CPython interpreter can swallow exceptions in some circumstances. |
Hugo van Kemenade | 547c60c | 2019-10-12 20:53:36 +0300 | [diff] [blame] | 1814 | In Python 3.8 this happens in fewer cases. In particular, exceptions |
Serhiy Storchaka | 7a0630c | 2019-04-08 14:34:04 +0300 | [diff] [blame] | 1815 | raised when getting the attribute from the type dictionary are no longer |
Hugo van Kemenade | 547c60c | 2019-10-12 20:53:36 +0300 | [diff] [blame] | 1816 | ignored. (Contributed by Serhiy Storchaka in :issue:`35459`.) |
Serhiy Storchaka | 7a0630c | 2019-04-08 14:34:04 +0300 | [diff] [blame] | 1817 | |
Serhiy Storchaka | 96aeaec | 2019-05-06 22:29:40 +0300 | [diff] [blame] | 1818 | * Removed ``__str__`` implementations from builtin types :class:`bool`, |
| 1819 | :class:`int`, :class:`float`, :class:`complex` and few classes from |
| 1820 | the standard library. They now inherit ``__str__()`` from :class:`object`. |
| 1821 | As result, defining the ``__repr__()`` method in the subclass of these |
bariod | dd6117c | 2019-09-27 20:01:33 +0200 | [diff] [blame] | 1822 | classes will affect their string representation. |
Serhiy Storchaka | 96aeaec | 2019-05-06 22:29:40 +0300 | [diff] [blame] | 1823 | (Contributed by Serhiy Storchaka in :issue:`36793`.) |
| 1824 | |
Michael Felt | 9d949f7 | 2019-04-12 16:15:32 +0200 | [diff] [blame] | 1825 | * On AIX, :attr:`sys.platform` doesn't contain the major version anymore. |
| 1826 | It is always ``'aix'``, instead of ``'aix3'`` .. ``'aix7'``. Since |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1827 | older Python versions include the version number, so it is recommended to |
| 1828 | always use ``sys.platform.startswith('aix')``. |
Michael Felt | 9d949f7 | 2019-04-12 16:15:32 +0200 | [diff] [blame] | 1829 | (Contributed by M. Felt in :issue:`36588`.) |
Serhiy Storchaka | 07ca9af | 2018-02-04 10:53:48 +0200 | [diff] [blame] | 1830 | |
Joannah Nanjekye | f781d20 | 2019-04-29 04:38:45 -0400 | [diff] [blame] | 1831 | * :c:func:`PyEval_AcquireLock` and :c:func:`PyEval_AcquireThread` now |
| 1832 | terminate the current thread if called while the interpreter is |
| 1833 | finalizing, making them consistent with :c:func:`PyEval_RestoreThread`, |
| 1834 | :c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`. If this |
Raymond Hettinger | a329153 | 2019-10-13 23:32:03 -0700 | [diff] [blame] | 1835 | behavior is not desired, guard the call by checking :c:func:`_Py_IsFinalizing` |
Joannah Nanjekye | f781d20 | 2019-04-29 04:38:45 -0400 | [diff] [blame] | 1836 | or :c:func:`sys.is_finalizing`. |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1837 | (Contributed by Joannah Nanjekye in :issue:`36475`.) |
| 1838 | |
Joannah Nanjekye | f781d20 | 2019-04-29 04:38:45 -0400 | [diff] [blame] | 1839 | |
Serhiy Storchaka | 97f1ca1 | 2018-02-01 18:49:21 +0200 | [diff] [blame] | 1840 | Changes in the Python API |
| 1841 | ------------------------- |
| 1842 | |
Victor Stinner | 689830e | 2019-06-26 17:31:12 +0200 | [diff] [blame] | 1843 | * The :func:`os.getcwdb` function now uses the UTF-8 encoding on Windows, |
| 1844 | rather than the ANSI code page: see :pep:`529` for the rationale. The |
| 1845 | function is no longer deprecated on Windows. |
| 1846 | (Contributed by Victor Stinner in :issue:`37412`.) |
| 1847 | |
Victor Stinner | d7befad | 2019-04-25 14:30:16 +0200 | [diff] [blame] | 1848 | * :class:`subprocess.Popen` can now use :func:`os.posix_spawn` in some cases |
| 1849 | for better performance. On Windows Subsystem for Linux and QEMU User |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1850 | Emulation, the :class:`Popen` constructor using :func:`os.posix_spawn` no longer raises an |
| 1851 | exception on errors like "missing program". Instead the child process fails with a |
Victor Stinner | d7befad | 2019-04-25 14:30:16 +0200 | [diff] [blame] | 1852 | non-zero :attr:`~Popen.returncode`. |
Victor Stinner | 01ae897 | 2019-06-03 16:28:01 +0200 | [diff] [blame] | 1853 | (Contributed by Joannah Nanjekye and Victor Stinner in :issue:`35537`.) |
Victor Stinner | d7befad | 2019-04-25 14:30:16 +0200 | [diff] [blame] | 1854 | |
Christian Heimes | 98d90f7 | 2019-08-27 23:36:56 +0200 | [diff] [blame] | 1855 | * The *preexec_fn* argument of * :class:`subprocess.Popen` is no longer |
| 1856 | compatible with subinterpreters. The use of the parameter in a |
| 1857 | subinterpreter now raises :exc:`RuntimeError`. |
| 1858 | (Contributed by Eric Snow in :issue:`34651`, modified by Christian Heimes |
| 1859 | in :issue:`37951`.) |
| 1860 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 1861 | * The :meth:`imap.IMAP4.logout` method no longer silently ignores arbitrary |
Victor Stinner | 74125a6 | 2019-04-15 18:23:20 +0200 | [diff] [blame] | 1862 | exceptions. |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1863 | (Contributed by Victor Stinner in :issue:`36348`.) |
Victor Stinner | 74125a6 | 2019-04-15 18:23:20 +0200 | [diff] [blame] | 1864 | |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1865 | * The function :func:`platform.popen` has been removed, after having been deprecated since |
Victor Stinner | 73104fa | 2018-11-29 09:58:20 +0100 | [diff] [blame] | 1866 | Python 3.3: use :func:`os.popen` instead. |
Victor Stinner | 01ae897 | 2019-06-03 16:28:01 +0200 | [diff] [blame] | 1867 | (Contributed by Victor Stinner in :issue:`35345`.) |
Victor Stinner | 73104fa | 2018-11-29 09:58:20 +0100 | [diff] [blame] | 1868 | |
Raymond Hettinger | fc06a19 | 2019-03-12 00:43:27 -0700 | [diff] [blame] | 1869 | * The :func:`statistics.mode` function no longer raises an exception |
| 1870 | when given multimodal data. Instead, it returns the first mode |
| 1871 | encountered in the input data. (Contributed by Raymond Hettinger |
| 1872 | in :issue:`35892`.) |
| 1873 | |
Serhiy Storchaka | 97f1ca1 | 2018-02-01 18:49:21 +0200 | [diff] [blame] | 1874 | * The :meth:`~tkinter.ttk.Treeview.selection` method of the |
| 1875 | :class:`tkinter.ttk.Treeview` class no longer takes arguments. Using it with |
| 1876 | arguments for changing the selection was deprecated in Python 3.6. Use |
| 1877 | specialized methods like :meth:`~tkinter.ttk.Treeview.selection_set` for |
| 1878 | changing the selection. (Contributed by Serhiy Storchaka in :issue:`31508`.) |
Serhiy Storchaka | 6c85efa5 | 2018-02-05 22:47:31 +0200 | [diff] [blame] | 1879 | |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1880 | * The :meth:`writexml`, :meth:`toxml` and :meth:`toprettyxml` methods of |
| 1881 | :mod:`xml.dom.minidom`, and the :meth:`write` method of :mod:`xml.etree`, |
| 1882 | now preserve the attribute order specified by the user. |
Diego Rojas | 06e1e68 | 2019-03-16 18:44:56 -0500 | [diff] [blame] | 1883 | (Contributed by Diego Rojas and Raymond Hettinger in :issue:`34160`.) |
| 1884 | |
Serhiy Storchaka | 6c85efa5 | 2018-02-05 22:47:31 +0200 | [diff] [blame] | 1885 | * A :mod:`dbm.dumb` database opened with flags ``'r'`` is now read-only. |
| 1886 | :func:`dbm.dumb.open` with flags ``'r'`` and ``'w'`` no longer creates |
| 1887 | a database if it does not exist. |
| 1888 | (Contributed by Serhiy Storchaka in :issue:`32749`.) |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 1889 | |
Serhiy Storchaka | 02ec92f | 2018-07-24 12:03:34 +0300 | [diff] [blame] | 1890 | * The ``doctype()`` method defined in a subclass of |
| 1891 | :class:`~xml.etree.ElementTree.XMLParser` will no longer be called and will |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1892 | emit a :exc:`RuntimeWarning` instead of a :exc:`DeprecationWarning`. |
Serhiy Storchaka | 02ec92f | 2018-07-24 12:03:34 +0300 | [diff] [blame] | 1893 | Define the :meth:`doctype() <xml.etree.ElementTree.TreeBuilder.doctype>` |
| 1894 | method on a target for handling an XML doctype declaration. |
| 1895 | (Contributed by Serhiy Storchaka in :issue:`29209`.) |
| 1896 | |
Serhiy Storchaka | f5e7b19 | 2018-05-20 08:48:12 +0300 | [diff] [blame] | 1897 | * A :exc:`RuntimeError` is now raised when the custom metaclass doesn't |
| 1898 | provide the ``__classcell__`` entry in the namespace passed to |
| 1899 | ``type.__new__``. A :exc:`DeprecationWarning` was emitted in Python |
| 1900 | 3.6--3.7. (Contributed by Serhiy Storchaka in :issue:`23722`.) |
| 1901 | |
Scott Sanderson | cebe80b | 2018-06-07 05:46:42 -0400 | [diff] [blame] | 1902 | * The :class:`cProfile.Profile` class can now be used as a context |
| 1903 | manager. (Contributed by Scott Sanderson in :issue:`29235`.) |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 1904 | |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 1905 | * :func:`shutil.copyfile`, :func:`shutil.copy`, :func:`shutil.copy2`, |
| 1906 | :func:`shutil.copytree` and :func:`shutil.move` use platform-specific |
| 1907 | "fast-copy" syscalls (see |
| 1908 | :ref:`shutil-platform-dependent-efficient-copy-operations` section). |
| 1909 | |
| 1910 | * :func:`shutil.copyfile` default buffer size on Windows was changed from |
| 1911 | 16 KiB to 1 MiB. |
| 1912 | |
Raymond Hettinger | 4f9ffc9 | 2019-08-05 13:33:19 -0700 | [diff] [blame] | 1913 | * The ``PyGC_Head`` struct has changed completely. All code that touched the |
Hugo van Kemenade | 547c60c | 2019-10-12 20:53:36 +0300 | [diff] [blame] | 1914 | struct member should be rewritten. (See :issue:`33597`.) |
INADA Naoki | d5c875b | 2018-07-11 17:42:49 +0900 | [diff] [blame] | 1915 | |
Raymond Hettinger | c93883c | 2019-10-20 11:25:16 -0700 | [diff] [blame] | 1916 | * The :c:type:`PyInterpreterState` struct has been moved into the "internal" |
Eric Snow | be3b295 | 2019-02-23 11:35:52 -0700 | [diff] [blame] | 1917 | header files (specifically Include/internal/pycore_pystate.h). An |
| 1918 | opaque ``PyInterpreterState`` is still available as part of the public |
| 1919 | API (and stable ABI). The docs indicate that none of the struct's |
| 1920 | fields are public, so we hope no one has been using them. However, |
| 1921 | if you do rely on one or more of those private fields and have no |
| 1922 | alternative then please open a BPO issue. We'll work on helping |
| 1923 | you adjust (possibly including adding accessor functions to the |
| 1924 | public API). (See :issue:`35886`.) |
| 1925 | |
Berker Peksag | e7d4b2f | 2018-08-22 21:21:05 +0300 | [diff] [blame] | 1926 | * The :meth:`mmap.flush() <mmap.mmap.flush>` method now returns ``None`` on |
| 1927 | success and raises an exception on error under all platforms. Previously, |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1928 | its behavior was platform-dependent: a nonzero value was returned on success; |
Berker Peksag | e7d4b2f | 2018-08-22 21:21:05 +0300 | [diff] [blame] | 1929 | zero was returned on error under Windows. A zero value was returned on |
| 1930 | success; an exception was raised on error under Unix. |
| 1931 | (Contributed by Berker Peksag in :issue:`2122`.) |
| 1932 | |
Andrés Delfino | ca68261 | 2018-11-07 14:29:14 -0300 | [diff] [blame] | 1933 | * :mod:`xml.dom.minidom` and :mod:`xml.sax` modules no longer process |
Christian Heimes | 17b1d5d | 2018-09-23 09:50:25 +0200 | [diff] [blame] | 1934 | external entities by default. |
| 1935 | (Contributed by Christian Heimes in :issue:`17239`.) |
INADA Naoki | d5c875b | 2018-07-11 17:42:49 +0900 | [diff] [blame] | 1936 | |
Xiang Zhang | 4fb0b8b | 2018-12-12 20:46:55 +0800 | [diff] [blame] | 1937 | * Deleting a key from a read-only :mod:`dbm` database (:mod:`dbm.dumb`, |
| 1938 | :mod:`dbm.gnu` or :mod:`dbm.ndbm`) raises :attr:`error` (:exc:`dbm.dumb.error`, |
| 1939 | :exc:`dbm.gnu.error` or :exc:`dbm.ndbm.error`) instead of :exc:`KeyError`. |
| 1940 | (Contributed by Xiang Zhang in :issue:`33106`.) |
| 1941 | |
Serhiy Storchaka | 85a2eef | 2020-02-17 11:03:00 +0200 | [diff] [blame] | 1942 | * Simplified AST for literals. All constants will be represented as |
| 1943 | :class:`ast.Constant` instances. Instantiating old classes ``Num``, |
| 1944 | ``Str``, ``Bytes``, ``NameConstant`` and ``Ellipsis`` will return |
| 1945 | an instance of ``Constant``. |
| 1946 | (Contributed by Serhiy Storchaka in :issue:`32892`.) |
| 1947 | |
Steve Dower | 8ef864d | 2019-03-12 15:15:26 -0700 | [diff] [blame] | 1948 | * :func:`~os.path.expanduser` on Windows now prefers the :envvar:`USERPROFILE` |
| 1949 | environment variable and does not use :envvar:`HOME`, which is not normally |
| 1950 | set for regular user accounts. |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1951 | (Contributed by Anthony Sottile in :issue:`36264`.) |
Steve Dower | 8ef864d | 2019-03-12 15:15:26 -0700 | [diff] [blame] | 1952 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1953 | * The exception :class:`asyncio.CancelledError` now inherits from |
Kyle Stanley | 3bbb6db | 2019-10-24 00:15:25 -0400 | [diff] [blame] | 1954 | :class:`BaseException` rather than :class:`Exception`. |
| 1955 | (Contributed by Yury Selivanov in :issue:`32528`.) |
| 1956 | |
| 1957 | * The function :func:`asyncio.wait_for` now correctly waits for cancellation |
| 1958 | when using an instance of :class:`asyncio.Task`. Previously, upon reaching |
| 1959 | *timeout*, it was cancelled and immediately returned. |
| 1960 | (Contributed by Elvis Pranskevichus in :issue:`32751`.) |
| 1961 | |
| 1962 | * The function :func:`asyncio.BaseTransport.get_extra_info` now returns a safe |
| 1963 | to use socket object when 'socket' is passed to the *name* parameter. |
| 1964 | (Contributed by Yury Selivanov in :issue:`37027`.) |
| 1965 | |
| 1966 | * :class:`asyncio.BufferedProtocol` has graduated to the stable API. |
Phil Jones | e634da2 | 2019-10-12 17:46:13 +0000 | [diff] [blame] | 1967 | |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 1968 | .. _bpo-36085-whatsnew: |
| 1969 | |
| 1970 | * DLL dependencies for extension modules and DLLs loaded with :mod:`ctypes` on |
| 1971 | Windows are now resolved more securely. Only the system paths, the directory |
| 1972 | containing the DLL or PYD file, and directories added with |
| 1973 | :func:`~os.add_dll_directory` are searched for load-time dependencies. |
| 1974 | Specifically, :envvar:`PATH` and the current working directory are no longer |
| 1975 | used, and modifications to these will no longer have any effect on normal DLL |
| 1976 | resolution. If your application relies on these mechanisms, you should check |
| 1977 | for :func:`~os.add_dll_directory` and if it exists, use it to add your DLLs |
Steve Dower | 79da388 | 2019-03-30 20:58:17 -0700 | [diff] [blame] | 1978 | directory while loading your library. Note that Windows 7 users will need to |
benedwards14 | 794616f | 2019-10-28 17:53:51 +0000 | [diff] [blame] | 1979 | ensure that Windows Update KB2533623 has been installed (this is also verified |
Steve Dower | 79da388 | 2019-03-30 20:58:17 -0700 | [diff] [blame] | 1980 | by the installer). |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 1981 | (Contributed by Steve Dower in :issue:`36085`.) |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 1982 | |
Pablo Galindo | f2cf1e3 | 2019-04-13 17:05:14 +0100 | [diff] [blame] | 1983 | * The header files and functions related to pgen have been removed after its |
| 1984 | replacement by a pure Python implementation. (Contributed by Pablo Galindo |
| 1985 | in :issue:`36623`.) |
| 1986 | |
Pablo Galindo | 5d23e28 | 2019-05-12 22:45:52 +0100 | [diff] [blame] | 1987 | * :class:`types.CodeType` has a new parameter in the second position of the |
| 1988 | constructor (*posonlyargcount*) to support positional-only arguments defined |
Pablo Galindo | cd74e66 | 2019-06-01 18:08:04 +0100 | [diff] [blame] | 1989 | in :pep:`570`. The first argument (*argcount*) now represents the total |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1990 | number of positional arguments (including positional-only arguments). The new |
Pablo Galindo | cd74e66 | 2019-06-01 18:08:04 +0100 | [diff] [blame] | 1991 | ``replace()`` method of :class:`types.CodeType` can be used to make the code |
| 1992 | future-proof. |
Pablo Galindo | 5d23e28 | 2019-05-12 22:45:52 +0100 | [diff] [blame] | 1993 | |
Xiang Zhang | 4fb0b8b | 2018-12-12 20:46:55 +0800 | [diff] [blame] | 1994 | |
Inada Naoki | d3c72a2 | 2019-03-23 21:04:40 +0900 | [diff] [blame] | 1995 | Changes in the C API |
| 1996 | -------------------- |
| 1997 | |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 1998 | * The :c:type:`PyCompilerFlags` structure got a new *cf_feature_version* |
Victor Stinner | 2c9b498 | 2019-06-13 02:01:29 +0200 | [diff] [blame] | 1999 | field. It should be initialized to ``PY_MINOR_VERSION``. The field is ignored |
Andrew Kuchling | bb78f6c | 2019-10-13 11:51:36 -0400 | [diff] [blame] | 2000 | by default, and is used if and only if ``PyCF_ONLY_AST`` flag is set in |
Victor Stinner | 2c9b498 | 2019-06-13 02:01:29 +0200 | [diff] [blame] | 2001 | *cf_flags*. |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 2002 | (Contributed by Guido van Rossum in :issue:`35766`.) |
Victor Stinner | 2c9b498 | 2019-06-13 02:01:29 +0200 | [diff] [blame] | 2003 | |
Victor Stinner | d5d9e81 | 2019-05-13 12:35:37 +0200 | [diff] [blame] | 2004 | * The :c:func:`PyEval_ReInitThreads` function has been removed from the C API. |
| 2005 | It should not be called explicitly: use :c:func:`PyOS_AfterFork_Child` |
| 2006 | instead. |
| 2007 | (Contributed by Victor Stinner in :issue:`36728`.) |
| 2008 | |
E. M. Bray | c994c8f | 2019-05-24 17:33:47 +0200 | [diff] [blame] | 2009 | * On Unix, C extensions are no longer linked to libpython except on Android |
| 2010 | and Cygwin. When Python is embedded, ``libpython`` must not be loaded with |
xdegaye | 254b309 | 2019-04-29 09:27:40 +0200 | [diff] [blame] | 2011 | ``RTLD_LOCAL``, but ``RTLD_GLOBAL`` instead. Previously, using |
E. M. Bray | c994c8f | 2019-05-24 17:33:47 +0200 | [diff] [blame] | 2012 | ``RTLD_LOCAL``, it was already not possible to load C extensions which |
| 2013 | were not linked to ``libpython``, like C extensions of the standard |
| 2014 | library built by the ``*shared*`` section of ``Modules/Setup``. |
Victor Stinner | 01ae897 | 2019-06-03 16:28:01 +0200 | [diff] [blame] | 2015 | (Contributed by Victor Stinner in :issue:`21536`.) |
Victor Stinner | 8c3ecc6 | 2019-04-25 20:13:10 +0200 | [diff] [blame] | 2016 | |
Inada Naoki | d3c72a2 | 2019-03-23 21:04:40 +0900 | [diff] [blame] | 2017 | * Use of ``#`` variants of formats in parsing or building value (e.g. |
| 2018 | :c:func:`PyArg_ParseTuple`, :c:func:`Py_BuildValue`, :c:func:`PyObject_CallFunction`, |
| 2019 | etc.) without ``PY_SSIZE_T_CLEAN`` defined raises ``DeprecationWarning`` now. |
| 2020 | It will be removed in 3.10 or 4.0. Read :ref:`arg-parsing` for detail. |
| 2021 | (Contributed by Inada Naoki in :issue:`36381`.) |
| 2022 | |
Eddie Elizondo | 364f0b0 | 2019-03-27 07:52:18 -0400 | [diff] [blame] | 2023 | * Instances of heap-allocated types (such as those created with |
| 2024 | :c:func:`PyType_FromSpec`) hold a reference to their type object. |
| 2025 | Increasing the reference count of these type objects has been moved from |
| 2026 | :c:func:`PyType_GenericAlloc` to the more low-level functions, |
| 2027 | :c:func:`PyObject_Init` and :c:func:`PyObject_INIT`. |
| 2028 | This makes types created through :c:func:`PyType_FromSpec` behave like |
| 2029 | other classes in managed code. |
| 2030 | |
| 2031 | Statically allocated types are not affected. |
| 2032 | |
| 2033 | For the vast majority of cases, there should be no side effect. |
| 2034 | However, types that manually increase the reference count after allocating |
| 2035 | an instance (perhaps to work around the bug) may now become immortal. |
| 2036 | To avoid this, these classes need to call Py_DECREF on the type object |
| 2037 | during instance deallocation. |
| 2038 | |
| 2039 | To correctly port these types into 3.8, please apply the following |
| 2040 | changes: |
| 2041 | |
| 2042 | * Remove :c:macro:`Py_INCREF` on the type object after allocating an |
| 2043 | instance - if any. |
| 2044 | This may happen after calling :c:func:`PyObject_New`, |
| 2045 | :c:func:`PyObject_NewVar`, :c:func:`PyObject_GC_New`, |
| 2046 | :c:func:`PyObject_GC_NewVar`, or any other custom allocator that uses |
| 2047 | :c:func:`PyObject_Init` or :c:func:`PyObject_INIT`. |
| 2048 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 2049 | Example: |
| 2050 | |
| 2051 | .. code-block:: c |
Eddie Elizondo | 364f0b0 | 2019-03-27 07:52:18 -0400 | [diff] [blame] | 2052 | |
| 2053 | static foo_struct * |
| 2054 | foo_new(PyObject *type) { |
| 2055 | foo_struct *foo = PyObject_GC_New(foo_struct, (PyTypeObject *) type); |
| 2056 | if (foo == NULL) |
| 2057 | return NULL; |
| 2058 | #if PY_VERSION_HEX < 0x03080000 |
| 2059 | // Workaround for Python issue 35810; no longer necessary in Python 3.8 |
| 2060 | PY_INCREF(type) |
| 2061 | #endif |
| 2062 | return foo; |
| 2063 | } |
| 2064 | |
| 2065 | * Ensure that all custom ``tp_dealloc`` functions of heap-allocated types |
| 2066 | decrease the type's reference count. |
| 2067 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 2068 | Example: |
| 2069 | |
| 2070 | .. code-block:: c |
Eddie Elizondo | 364f0b0 | 2019-03-27 07:52:18 -0400 | [diff] [blame] | 2071 | |
| 2072 | static void |
| 2073 | foo_dealloc(foo_struct *instance) { |
| 2074 | PyObject *type = Py_TYPE(instance); |
| 2075 | PyObject_GC_Del(instance); |
| 2076 | #if PY_VERSION_HEX >= 0x03080000 |
| 2077 | // This was not needed before Python 3.8 (Python issue 35810) |
| 2078 | Py_DECREF(type); |
| 2079 | #endif |
| 2080 | } |
| 2081 | |
| 2082 | (Contributed by Eddie Elizondo in :issue:`35810`.) |
| 2083 | |
Zackery Spytz | 3c8724f | 2019-05-28 09:16:33 -0600 | [diff] [blame] | 2084 | * The :c:macro:`Py_DEPRECATED()` macro has been implemented for MSVC. |
| 2085 | The macro now must be placed before the symbol name. |
| 2086 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 2087 | Example: |
| 2088 | |
| 2089 | .. code-block:: c |
Zackery Spytz | 3c8724f | 2019-05-28 09:16:33 -0600 | [diff] [blame] | 2090 | |
| 2091 | Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void); |
| 2092 | |
| 2093 | (Contributed by Zackery Spytz in :issue:`33407`.) |
| 2094 | |
Antoine Pitrou | ada319b | 2019-05-29 22:12:38 +0200 | [diff] [blame] | 2095 | * The interpreter does not pretend to support binary compatibility of |
Xtreak | 0d70227 | 2019-06-03 04:42:33 +0530 | [diff] [blame] | 2096 | extension types across feature releases, anymore. A :c:type:`PyTypeObject` |
Antoine Pitrou | ada319b | 2019-05-29 22:12:38 +0200 | [diff] [blame] | 2097 | exported by a third-party extension module is supposed to have all the |
| 2098 | slots expected in the current Python version, including |
| 2099 | :c:member:`~PyTypeObject.tp_finalize` (:const:`Py_TPFLAGS_HAVE_FINALIZE` |
| 2100 | is not checked anymore before reading :c:member:`~PyTypeObject.tp_finalize`). |
| 2101 | |
| 2102 | (Contributed by Antoine Pitrou in :issue:`32388`.) |
| 2103 | |
Pablo Galindo | 545a3b8 | 2019-05-31 19:33:41 +0100 | [diff] [blame] | 2104 | * The :c:func:`PyCode_New` has a new parameter in the second position (*posonlyargcount*) |
| 2105 | to support :pep:`570`, indicating the number of positional-only arguments. |
| 2106 | |
Ivan Levkivskyi | 47c2de7 | 2019-06-19 01:17:47 +0100 | [diff] [blame] | 2107 | * The functions :c:func:`PyNode_AddChild` and :c:func:`PyParser_AddToken` now accept |
| 2108 | two additional ``int`` arguments *end_lineno* and *end_col_offset*. |
Eddie Elizondo | 364f0b0 | 2019-03-27 07:52:18 -0400 | [diff] [blame] | 2109 | |
Steve Dower | f569092 | 2019-06-21 14:28:46 -0700 | [diff] [blame] | 2110 | * The :file:`libpython38.a` file to allow MinGW tools to link directly against |
| 2111 | :file:`python38.dll` is no longer included in the regular Windows distribution. |
| 2112 | If you require this file, it may be generated with the ``gendef`` and |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 2113 | ``dlltool`` tools, which are part of the MinGW binutils package: |
| 2114 | |
| 2115 | .. code-block:: shell |
Steve Dower | f569092 | 2019-06-21 14:28:46 -0700 | [diff] [blame] | 2116 | |
Baljak | 2545fa8 | 2020-02-05 01:10:16 +0100 | [diff] [blame] | 2117 | gendef - python38.dll > tmp.def |
Steve Dower | f569092 | 2019-06-21 14:28:46 -0700 | [diff] [blame] | 2118 | dlltool --dllname python38.dll --def tmp.def --output-lib libpython38.a |
| 2119 | |
| 2120 | The location of an installed :file:`pythonXY.dll` will depend on the |
| 2121 | installation options and the version and language of Windows. See |
| 2122 | :ref:`using-on-windows` for more information. The resulting library should be |
| 2123 | placed in the same directory as :file:`pythonXY.lib`, which is generally the |
| 2124 | :file:`libs` directory under your Python installation. |
| 2125 | |
Serhiy Storchaka | 298439c | 2019-10-14 16:10:40 +0300 | [diff] [blame] | 2126 | (Contributed by Steve Dower in :issue:`37351`.) |
Steve Dower | f569092 | 2019-06-21 14:28:46 -0700 | [diff] [blame] | 2127 | |
| 2128 | |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 2129 | CPython bytecode changes |
| 2130 | ------------------------ |
| 2131 | |
| 2132 | * The interpreter loop has been simplified by moving the logic of unrolling |
| 2133 | the stack of blocks into the compiler. The compiler emits now explicit |
Serhiy Storchaka | 3f819ca | 2018-10-31 02:26:06 +0200 | [diff] [blame] | 2134 | instructions for adjusting the stack of values and calling the |
| 2135 | cleaning-up code for :keyword:`break`, :keyword:`continue` and |
| 2136 | :keyword:`return`. |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 2137 | |
| 2138 | Removed opcodes :opcode:`BREAK_LOOP`, :opcode:`CONTINUE_LOOP`, |
| 2139 | :opcode:`SETUP_LOOP` and :opcode:`SETUP_EXCEPT`. Added new opcodes |
| 2140 | :opcode:`ROT_FOUR`, :opcode:`BEGIN_FINALLY`, :opcode:`CALL_FINALLY` and |
| 2141 | :opcode:`POP_FINALLY`. Changed the behavior of :opcode:`END_FINALLY` |
| 2142 | and :opcode:`WITH_CLEANUP_START`. |
| 2143 | |
| 2144 | (Contributed by Mark Shannon, Antoine Pitrou and Serhiy Storchaka in |
| 2145 | :issue:`17611`.) |
Serhiy Storchaka | 702f8f3 | 2018-03-23 14:34:35 +0200 | [diff] [blame] | 2146 | |
| 2147 | * Added new opcode :opcode:`END_ASYNC_FOR` for handling exceptions raised |
| 2148 | when awaiting a next item in an :keyword:`async for` loop. |
| 2149 | (Contributed by Serhiy Storchaka in :issue:`33041`.) |
Raymond Hettinger | f75d59e | 2019-02-02 22:54:56 -0800 | [diff] [blame] | 2150 | |
Pablo Galindo | b51b713 | 2019-06-25 02:41:58 +0100 | [diff] [blame] | 2151 | * The :opcode:`MAP_ADD` now expects the value as the first element in the |
| 2152 | stack and the key as the second element. This change was made so the key |
| 2153 | is always evaluated before the value in dictionary comprehensions, as |
Pablo Galindo | de9b606 | 2019-06-25 11:55:23 +0100 | [diff] [blame] | 2154 | proposed by :pep:`572`. (Contributed by Jörn Heissler in :issue:`35224`.) |
Pablo Galindo | b51b713 | 2019-06-25 02:41:58 +0100 | [diff] [blame] | 2155 | |
Raymond Hettinger | f75d59e | 2019-02-02 22:54:56 -0800 | [diff] [blame] | 2156 | |
| 2157 | Demos and Tools |
| 2158 | --------------- |
| 2159 | |
Raymond Hettinger | 1cdadf4 | 2019-11-03 21:47:01 -0800 | [diff] [blame] | 2160 | Added a benchmark script for timing various ways to access variables: |
| 2161 | ``Tools/scripts/var_access_benchmark.py``. |
| 2162 | (Contributed by Raymond Hettinger in :issue:`35884`.) |
| 2163 | |
| 2164 | Here's a summary of performance improvements since Python 3.3: |
| 2165 | |
| 2166 | .. code-block:: none |
| 2167 | |
| 2168 | Python version 3.3 3.4 3.5 3.6 3.7 3.8 |
| 2169 | -------------- --- --- --- --- --- --- |
| 2170 | |
| 2171 | Variable and attribute read access: |
| 2172 | read_local 4.0 7.1 7.1 5.4 5.1 3.9 |
| 2173 | read_nonlocal 5.3 7.1 8.1 5.8 5.4 4.4 |
| 2174 | read_global 13.3 15.5 19.0 14.3 13.6 7.6 |
| 2175 | read_builtin 20.0 21.1 21.6 18.5 19.0 7.5 |
| 2176 | read_classvar_from_class 20.5 25.6 26.5 20.7 19.5 18.4 |
| 2177 | read_classvar_from_instance 18.5 22.8 23.5 18.8 17.1 16.4 |
| 2178 | read_instancevar 26.8 32.4 33.1 28.0 26.3 25.4 |
| 2179 | read_instancevar_slots 23.7 27.8 31.3 20.8 20.8 20.2 |
| 2180 | read_namedtuple 68.5 73.8 57.5 45.0 46.8 18.4 |
| 2181 | read_boundmethod 29.8 37.6 37.9 29.6 26.9 27.7 |
| 2182 | |
| 2183 | Variable and attribute write access: |
| 2184 | write_local 4.6 8.7 9.3 5.5 5.3 4.3 |
| 2185 | write_nonlocal 7.3 10.5 11.1 5.6 5.5 4.7 |
| 2186 | write_global 15.9 19.7 21.2 18.0 18.0 15.8 |
| 2187 | write_classvar 81.9 92.9 96.0 104.6 102.1 39.2 |
| 2188 | write_instancevar 36.4 44.6 45.8 40.0 38.9 35.5 |
| 2189 | write_instancevar_slots 28.7 35.6 36.1 27.3 26.6 25.7 |
| 2190 | |
| 2191 | Data structure read access: |
| 2192 | read_list 19.2 24.2 24.5 20.8 20.8 19.0 |
| 2193 | read_deque 19.9 24.7 25.5 20.2 20.6 19.8 |
| 2194 | read_dict 19.7 24.3 25.7 22.3 23.0 21.0 |
| 2195 | read_strdict 17.9 22.6 24.3 19.5 21.2 18.9 |
| 2196 | |
| 2197 | Data structure write access: |
| 2198 | write_list 21.2 27.1 28.5 22.5 21.6 20.0 |
| 2199 | write_deque 23.8 28.7 30.1 22.7 21.8 23.5 |
| 2200 | write_dict 25.9 31.4 33.3 29.3 29.2 24.7 |
| 2201 | write_strdict 22.9 28.4 29.9 27.5 25.2 23.1 |
| 2202 | |
| 2203 | Stack (or queue) operations: |
| 2204 | list_append_pop 144.2 93.4 112.7 75.4 74.2 50.8 |
| 2205 | deque_append_pop 30.4 43.5 57.0 49.4 49.2 42.5 |
| 2206 | deque_append_popleft 30.8 43.7 57.3 49.7 49.7 42.8 |
| 2207 | |
| 2208 | Timing loop: |
| 2209 | loop_overhead 0.3 0.5 0.6 0.4 0.3 0.3 |
| 2210 | |
| 2211 | (Measured from the macOS 64-bit builds found at python.org) |
Kyle Stanley | f501db2 | 2019-12-16 16:50:34 -0500 | [diff] [blame] | 2212 | |
| 2213 | Notable changes in Python 3.8.1 |
| 2214 | =============================== |
| 2215 | |
| 2216 | Due to significant security concerns, the *reuse_address* parameter of |
| 2217 | :meth:`asyncio.loop.create_datagram_endpoint` is no longer supported. This is |
| 2218 | because of the behavior of the socket option ``SO_REUSEADDR`` in UDP. For more |
| 2219 | details, see the documentation for ``loop.create_datagram_endpoint()``. |
| 2220 | (Contributed by Kyle Stanley, Antoine Pitrou, and Yury Selivanov in |
| 2221 | :issue:`37228`.) |