blob: e52e32c4736959b0720e48a19ac9d4ade86bcc07 [file] [log] [blame]
Ned Deily4829bc62016-09-12 17:29:04 -04001****************************
2 What's New In Python 3.7
3****************************
4
5:Release: |release|
6:Date: |today|
7
8.. Rules for maintenance:
9
10 * Anyone can add text to this document. Do not spend very much time
11 on the wording of your changes, because your text will probably
12 get rewritten to some degree.
13
14 * The maintainer will go through Misc/NEWS periodically and add
15 changes; it's therefore more important to add your changes to
16 Misc/NEWS than to this file.
17
18 * This is not a complete list of every single change; completeness
19 is the purpose of Misc/NEWS. Some changes I consider too small
20 or esoteric to include. If such a change is added to the text,
21 I'll just remove it. (This is another reason you shouldn't spend
22 too much time on writing your addition.)
23
24 * If you want to draw your new text to the attention of the
25 maintainer, add 'XXX' to the beginning of the paragraph or
26 section.
27
28 * It's OK to just add a fragmentary note about a change. For
29 example: "XXX Describe the transmogrify() function added to the
30 socket module." The maintainer will research the change and
31 write the necessary text.
32
33 * You can comment out your additions if you like, but it's not
34 necessary (especially when a final release is some months away).
35
36 * Credit the author of a patch or bugfix. Just the name is
37 sufficient; the e-mail address isn't necessary.
38
39 * It's helpful to add the bug/patch number as a comment:
40
41 XXX Describe the transmogrify() function added to the socket
42 module.
43 (Contributed by P.Y. Developer in :issue:`12345`.)
44
45 This saves the maintainer the effort of going through the Mercurial log
46 when researching a change.
47
48This article explains the new features in Python 3.7, compared to 3.6.
49
Steve Dower3e7d93d2016-09-22 17:11:53 -070050For full details, see the :ref:`changelog <changelog>`.
Ned Deily4829bc62016-09-12 17:29:04 -040051
52.. note::
53
54 Prerelease users should be aware that this document is currently in draft
55 form. It will be updated substantially as Python 3.7 moves towards release,
56 so it's worth checking back even after reading earlier versions.
57
58
59Summary -- Release highlights
60=============================
61
62.. This section singles out the most important changes in Python 3.7.
63 Brevity is key.
64
65
66.. PEP-sized items next.
67
68
69
70New Features
71============
72
Nick Coghlan9b997472018-01-08 12:45:02 +100073
Nick Coghlan6ea41862017-06-11 13:16:15 +100074.. _whatsnew37-pep538:
75
76PEP 538: Legacy C Locale Coercion
77---------------------------------
78
79An ongoing challenge within the Python 3 series has been determining a sensible
80default strategy for handling the "7-bit ASCII" text encoding assumption
81currently implied by the use of the default C locale on non-Windows platforms.
82
83:pep:`538` updates the default interpreter command line interface to
84automatically coerce that locale to an available UTF-8 based locale as
85described in the documentation of the new :envvar:`PYTHONCOERCECLOCALE`
86environment variable. Automatically setting ``LC_CTYPE`` this way means that
87both the core interpreter and locale-aware C extensions (such as
88:mod:`readline`) will assume the use of UTF-8 as the default text encoding,
89rather than ASCII.
90
91The platform support definition in :pep:`11` has also been updated to limit
92full text handling support to suitably configured non-ASCII based locales.
93
94As part of this change, the default error handler for ``stdin`` and ``stdout``
95is now ``surrogateescape`` (rather than ``strict``) when using any of the
96defined coercion target locales (currently ``C.UTF-8``, ``C.utf8``, and
97``UTF-8``). The default error handler for ``stderr`` continues to be
98``backslashreplace``, regardless of locale.
99
Nick Coghlaneb817952017-06-18 12:29:42 +1000100Locale coercion is silent by default, but to assist in debugging potentially
101locale related integration problems, explicit warnings (emitted directly on
102``stderr`` can be requested by setting ``PYTHONCOERCECLOCALE=warn``. This
103setting will also cause the Python runtime to emit a warning if the legacy C
104locale remains active when the core interpreter is initialized.
Nick Coghlan6ea41862017-06-11 13:16:15 +1000105
106.. seealso::
107
108 :pep:`538` -- Coercing the legacy C locale to a UTF-8 based locale
109 PEP written and implemented by Nick Coghlan.
Ned Deily4829bc62016-09-12 17:29:04 -0400110
Nick Coghlan9b997472018-01-08 12:45:02 +1000111
Barry Warsaw36c1d1f2017-10-05 12:11:18 -0400112.. _whatsnew37-pep553:
113
114PEP 553: Built-in breakpoint()
115------------------------------
116
117:pep:`553` describes a new built-in called ``breakpoint()`` which makes it
118easy and consistent to enter the Python debugger. Built-in ``breakpoint()``
119calls ``sys.breakpointhook()``. By default, this latter imports ``pdb`` and
120then calls ``pdb.set_trace()``, but by binding ``sys.breakpointhook()`` to the
121function of your choosing, ``breakpoint()`` can enter any debugger. Or, the
122environment variable :envvar:`PYTHONBREAKPOINT` can be set to the callable of
123your debugger of choice. Set ``PYTHONBREAKPOINT=0`` to completely disable
124built-in ``breakpoint()``.
125
126.. seealso::
127
128 :pep:`553` -- Built-in breakpoint()
129 PEP written and implemented by Barry Warsaw
130
Ned Deily4829bc62016-09-12 17:29:04 -0400131
Masayuki Yamamoto731e1892017-10-06 19:41:34 +0900132.. _whatsnew37-pep539:
133
134PEP 539: A New C-API for Thread-Local Storage in CPython
135--------------------------------------------------------
136
137While Python provides a C API for thread-local storage support; the existing
138:ref:`Thread Local Storage (TLS) API <thread-local-storage-api>` has used
139:c:type:`int` to represent TLS keys across all platforms. This has not
140generally been a problem for officially-support platforms, but that is neither
141POSIX-compliant, nor portable in any practical sense.
142
143:pep:`539` changes this by providing a new :ref:`Thread Specific Storage (TSS)
144API <thread-specific-storage-api>` to CPython which supersedes use of the
145existing TLS API within the CPython interpreter, while deprecating the existing
146API. The TSS API uses a new type :c:type:`Py_tss_t` instead of :c:type:`int`
147to represent TSS keys--an opaque type the definition of which may depend on
148the underlying TLS implementation. Therefore, this will allow to build CPython
149on platforms where the native TLS key is defined in a way that cannot be safely
150cast to :c:type:`int`.
151
152Note that on platforms where the native TLS key is defined in a way that cannot
153be safely cast to :c:type:`int`, all functions of the existing TLS API will be
154no-op and immediately return failure. This indicates clearly that the old API
155is not supported on platforms where it cannot be used reliably, and that no
156effort will be made to add such support.
157
158.. seealso::
159
160 :pep:`539` -- A New C-API for Thread-Local Storage in CPython
161 PEP written by Erik M. Bray; implementation by Masayuki Yamamoto.
162
163
Ivan Levkivskyi5364b5c2017-12-14 11:59:44 +0100164PEP 562: Customization of access to module attributes
165-----------------------------------------------------
166
167It is sometimes convenient to customize or otherwise have control over access
168to module attributes. A typical example is managing deprecation warnings.
169Typical workarounds are assigning ``__class__`` of a module object to
170a custom subclass of :class:`types.ModuleType` or replacing the ``sys.modules``
171item with a custom wrapper instance. This procedure is now simplified by
172recognizing ``__getattr__`` defined directly in a module that would act like
173a normal ``__getattr__`` method, except that it will be defined on module
174*instances*.
175
176.. seealso::
177
178 :pep:`562` -- Module ``__getattr__`` and ``__dir__``
179 PEP written and implemented by Ivan Levkivskyi
180
181
Victor Stinnerc29b5852017-11-02 07:28:27 -0700182PEP 564: Add new time functions with nanosecond resolution
183----------------------------------------------------------
184
185Add six new "nanosecond" variants of existing functions to the :mod:`time`
186module:
187
188* :func:`time.clock_gettime_ns`
189* :func:`time.clock_settime_ns`
190* :func:`time.monotonic_ns`
191* :func:`time.perf_counter_ns`
192* :func:`time.process_time_ns`
193* :func:`time.time_ns`
194
195While similar to the existing functions without the ``_ns`` suffix, they
196provide nanosecond resolution: they return a number of nanoseconds as a Python
197``int``.
198
199The ``time.time_ns()`` resolution is 3 times better than the ``time.time()``
200resolution on Linux and Windows.
201
202.. seealso::
203
204 :pep:`564` -- Add new time functions with nanosecond resolution
205 PEP written and implemented by Victor Stinner
206
207
Nick Coghlan9b997472018-01-08 12:45:02 +1000208.. _whatsnew37-pep565:
209
210PEP 565: Show DeprecationWarning in ``__main__``
211------------------------------------------------
212
213The default handling of :exc:`DeprecationWarning` has been changed such that
214these warnings are once more shown by default, but only when the code
215triggering them is running directly in the ``__main__`` module. As a result,
216developers of single file scripts and those using Python interactively should
217once again start seeing deprecation warnings for the APIs they use, but
218deprecation warnings triggered by imported application, library and framework
219modules will continue to be hidden by default.
220
221As a result of this change, the standard library now allows developers to choose
222between three different deprecation warning behaviours:
223
224* :exc:`FutureWarning`: always displayed by default, recommended for warnings
225 intended to be seen by application end users (e.g. for deprecated application
226 configuration settings).
227* :exc:`DeprecationWarning`: displayed by default only in ``__main__`` and when
228 running tests, recommended for warnings intended to be seen by other Python
229 developers where a version upgrade may result in changed behaviour or an
230 error.
231* :exc:`PendingDeprecationWarning`: displayed by default only when running
232 tests, intended for cases where a future version upgrade will change the
233 warning category to :exc:`DeprecationWarning` or :exc:`FutureWarning`.
234
235Previously both :exc:`DeprecationWarning` and :exc:`PendingDeprecationWarning`
236were only visible when running tests, which meant that developers primarily
237writing single file scripts or using Python interactively could be surprised
238by breaking changes in the APIs they used.
239
240.. seealso::
241
242 :pep:`565` -- Show DeprecationWarning in ``__main__``
243 PEP written and implemented by Nick Coghlan
244
245
Victor Stinner91106cd2017-12-13 12:29:09 +0100246PEP 540: Add a new UTF-8 mode
247-----------------------------
248
249Add a new UTF-8 mode to ignore the locale, use the UTF-8 encoding, and change
250:data:`sys.stdin` and :data:`sys.stdout` error handlers to ``surrogateescape``.
251This mode is enabled by default in the POSIX locale, but otherwise disabled by
252default.
253
254The new :option:`-X` ``utf8`` command line option and :envvar:`PYTHONUTF8`
255environment variable are added to control the UTF-8 mode.
256
257.. seealso::
258
259 :pep:`540` -- Add a new UTF-8 mode
260 PEP written and implemented by Victor Stinner
261
262
Victor Stinner5e3806f2017-11-30 11:40:24 +0100263New Development Mode: -X dev
264----------------------------
Victor Stinnerccb04422017-11-16 03:20:31 -0800265
Victor Stinner747f48e2017-12-12 22:59:48 +0100266Add a new "development mode": :option:`-X` ``dev`` command line option and
267:envvar:`PYTHONDEVMODE` environment variable to enable CPython's "development
268mode", introducing additional runtime checks which are too expensive to be
269enabled by default. See :option:`-X` ``dev`` documentation for the effects of
270the development mode.
Victor Stinnerccb04422017-11-16 03:20:31 -0800271
Benjamin Peterson42aa93b2017-12-09 10:26:52 -0800272Hash-based pycs
273---------------
274
275Python has traditionally checked the up-to-dateness of bytecode cache files
276(i.e., ``.pyc`` files) by comparing the source metadata (last-modified timestamp
277and size) with source metadata saved in the cache file header when it was
278generated. While effective, this invalidation method has its drawbacks. When
279filesystem timestamps are too coarse, Python can miss source updates, leading to
280user confusion. Additionally, having a timestamp in the cache file is
281problematic for `build reproduciblity <https://reproducible-builds.org/>`_ and
282content-based build systems.
283
284:pep:`552` extends the pyc format to allow the hash of the source file to be
285used for invalidation instead of the source timestamp. Such ``.pyc`` files are
286called "hash-based". By default, Python still uses timestamp-based invalidation
287and does not generate hash-based ``.pyc`` files at runtime. Hash-based ``.pyc``
288files may be generated with :mod:`py_compile` or :mod:`compileall`.
289
290Hash-based ``.pyc`` files come in two variants: checked and unchecked. Python
291validates checked hash-based ``.pyc`` files against the corresponding source
292files at runtime but doesn't do so for unchecked hash-based pycs. Unchecked
293hash-based ``.pyc`` files are a useful performance optimization for environments
294where a system external to Python (e.g., the build system) is responsible for
295keeping ``.pyc`` files up-to-date.
296
297See :ref:`pyc-invalidation` for more information.
298
Victor Stinnerccb04422017-11-16 03:20:31 -0800299
Ned Deily4829bc62016-09-12 17:29:04 -0400300Other Language Changes
301======================
302
Serhiy Storchaka5bb8b912016-12-16 19:19:02 +0200303* More than 255 arguments can now be passed to a function, and a function can
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800304 now have more than 255 parameters. (Contributed by Serhiy Storchaka in
305 :issue:`12844` and :issue:`18896`.)
Ned Deily4829bc62016-09-12 17:29:04 -0400306
Serhiy Storchakadd1da7f2016-12-19 18:51:37 +0200307* :meth:`bytes.fromhex` and :meth:`bytearray.fromhex` now ignore all ASCII
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800308 whitespace, not only spaces. (Contributed by Robert Xiao in :issue:`28927`.)
Serhiy Storchakadd1da7f2016-12-19 18:51:37 +0200309
Matthias Bussonnier1bc15642017-02-22 07:06:50 -0800310* :exc:`ImportError` now displays module name and module ``__file__`` path when
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800311 ``from ... import ...`` fails. (Contributed by Matthias Bussonnier in :issue:`29546`.)
Matthias Bussonnier1bc15642017-02-22 07:06:50 -0800312
Serhiy Storchakaf93234b2017-05-09 22:31:05 +0300313* Circular imports involving absolute imports with binding a submodule to
314 a name are now supported.
315 (Contributed by Serhiy Storchaka in :issue:`30024`.)
316
Serhiy Storchaka7e19dbc2017-05-13 12:40:52 +0300317* ``object.__format__(x, '')`` is now equivalent to ``str(x)`` rather than
318 ``format(str(self), '')``.
319 (Contributed by Serhiy Storchaka in :issue:`28974`.)
320
Ned Deily4829bc62016-09-12 17:29:04 -0400321
322New Modules
323===========
324
Barry Warsawdeae6b42017-12-30 15:18:06 -0500325importlib.resources
326-------------------
327
328This module provides several new APIs and one new ABC for access to, opening,
329and reading *resources* inside packages. Resources are roughly akin to files
330inside of packages, but they needn't be actual files on the physical file
Barry Warsaw6f6eb352018-01-24 15:36:21 -0500331system. Module loaders can provide a :meth:`get_resource_reader()` function
332which returns a :class:`importlib.abc.ResourceReader` instance to support this
333new API. Built-in file path loaders and zip file loaders both support this.
334(see the PyPI package
335`importlib_resources <http://importlib-resources.readthedocs.io/en/latest/>`_
336as a compatible back port for older Python versions).
Ned Deily4829bc62016-09-12 17:29:04 -0400337
338
339Improved Modules
340================
341
Pierre Quentelcc3fa202017-05-08 14:08:34 +0200342
R. David Murray0f6b9d22017-09-06 20:25:40 -0400343argparse
344--------
345
346The :meth:`~argparse.ArgumentParser.parse_intermixed_args` supports letting
347the user intermix options and positional arguments on the command line,
348as is possible in many unix commands. It supports most but not all
349argparse features. (Contributed by paul.j3 in :issue:`14191`.)
350
351
Xiang Zhang13f1f422017-05-03 11:16:21 +0800352binascii
353--------
354
355The :func:`~binascii.b2a_uu` function now accepts an optional *backtick*
356keyword argument. When it's true, zeros are represented by ``'`'``
357instead of spaces. (Contributed by Xiang Zhang in :issue:`30103`.)
358
Oz N Tiram8b7a4cc2017-06-06 11:35:59 +0200359
360calendar
361--------
362
Walter Dörwaldf5c58c72017-06-26 18:31:52 +0200363The class :class:`~calendar.HTMLCalendar` has new class attributes which ease
364the customisation of the CSS classes in the produced HTML calendar.
Oz N Tiram8b7a4cc2017-06-06 11:35:59 +0200365(Contributed by Oz Tiram in :issue:`30095`.)
366
367cgi
368---
369
370:func:`~cgi.parse_multipart` returns the same results as
371:class:`~FieldStorage` : for non-file fields, the value associated to a key
372is a list of strings, not bytes.
373(Contributed by Pierre Quentel in :issue:`29979`.)
374
Jelle Zijlstra2e624692017-04-30 18:25:58 -0700375contextlib
376----------
377
Jelle Zijlstra176baa32017-12-13 17:19:17 -0800378:func:`~contextlib.asynccontextmanager` and
379:class:`~contextlib.AbstractAsyncContextManager` have been added. (Contributed
380by Jelle Zijlstra in :issue:`29679` and :issue:`30241`.)
Jelle Zijlstra2e624692017-04-30 18:25:58 -0700381
Sanyam Khurana7973e272017-11-08 16:20:56 +0530382cProfile
383--------
384
385cProfile command line now accepts `-m module_name` as an alternative to
386script path. (Contributed by Sanyam Khurana in :issue:`21862`.)
387
Serhiy Storchakaeab3ff72017-10-24 19:36:17 +0300388crypt
389-----
390
391Added support for the Blowfish method.
392(Contributed by Serhiy Storchaka in :issue:`31664`.)
393
Serhiy Storchakacede8c92017-11-16 13:22:51 +0200394The :func:`~crypt.mksalt` function now allows to specify the number of rounds
395for hashing. (Contributed by Serhiy Storchaka in :issue:`31702`.)
396
Serhiy Storchaka1efbf922017-06-11 14:09:39 +0300397dis
398---
399
400The :func:`~dis.dis` function now is able to
401disassemble nested code objects (the code of comprehensions, generator
402expressions and nested functions, and the code used for building nested
403classes). (Contributed by Serhiy Storchaka in :issue:`11822`.)
404
Ryan Gonzalezf9f87f02017-04-14 04:00:25 -0500405distutils
406---------
407
408README.rst is now included in the list of distutils standard READMEs and
409therefore included in source distributions.
410(Contributed by Ryan Gonzalez in :issue:`11913`.)
411
Neil Schemenauer8837dd02017-12-04 18:58:12 -0800412:class:`distutils.core.setup` now warns if the ``classifiers``, ``keywords``
413and ``platforms`` fields are not specified as a list or a string.
Berker Peksagdcaed6b2017-11-23 21:34:20 +0300414(Contributed by Berker Peksag in :issue:`19610`.)
415
Nir Sofferad455cd2017-11-06 23:16:37 +0200416http.client
417-----------
418
419Add Configurable *blocksize* to ``HTTPConnection`` and
420``HTTPSConnection`` for improved upload throughput.
421(Contributed by Nir Soffer in :issue:`31945`.)
422
Pierre Quentel351adda2017-04-02 12:26:12 +0200423http.server
424-----------
425
426:class:`~http.server.SimpleHTTPRequestHandler` supports the HTTP
427If-Modified-Since header. The server returns the 304 response status if the
428target file was not modified after the time specified in the header.
429(Contributed by Pierre Quentel in :issue:`29654`.)
430
Stéphane Wirtela17a2f52017-05-24 09:29:06 +0200431Add the parameter ``directory`` to the :class:`~http.server.SimpleHTTPRequestHandler`
432and the ``--directory`` to the command line of the module :mod:`~http.server`.
433With this parameter, the server serves the specified directory, by default it uses the current working directory.
434(Contributed by Stéphane Wirtel and Julien Palard in :issue:`28707`.)
435
Brett Cannonbca42182018-01-12 15:08:59 -0800436importlib
437---------
438
439The :class:`importlib.abc.ResourceReader` ABC was introduced to
440support the loading of resource from packages.
441
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800442locale
443------
444
445Added another argument *monetary* in :meth:`format_string` of :mod:`locale`.
446If *monetary* is true, the conversion uses monetary thousands separator and
447grouping strings. (Contributed by Garvit in :issue:`10379`.)
448
Victor Stinner91106cd2017-12-13 12:29:09 +0100449The :func:`locale.getpreferredencoding` function now always returns ``'UTF-8'``
450on Android or in the UTF-8 mode (:option:`-X` ``utf8`` option), the locale and
451the *do_setlocale* argument are ignored.
452
Mark Dickinsona0ce3752017-04-05 18:34:27 +0100453math
454----
455
456New :func:`~math.remainder` function, implementing the IEEE 754-style remainder
457operation. (Contributed by Mark Dickinson in :issue:`29962`.)
458
Serhiy Storchaka8f6b3442017-03-07 14:33:21 +0200459os
460--
461
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800462Added support for :class:`bytes` paths in :func:`~os.fwalk`. (Contributed by
463Serhiy Storchaka in :issue:`28682`.)
Serhiy Storchaka8f6b3442017-03-07 14:33:21 +0200464
Serhiy Storchakaea720fe2017-03-30 09:12:31 +0300465Added support for :ref:`file descriptors <path_fd>` in :func:`~os.scandir`
466on Unix. (Contributed by Serhiy Storchaka in :issue:`25996`.)
467
Antoine Pitrouf7ecfac2017-05-28 11:35:14 +0200468New function :func:`os.register_at_fork` allows registering Python callbacks
469to be executed on a process fork. (Contributed by Antoine Pitrou in
470:issue:`16500`.)
471
Barry Warsaw35425d62017-09-22 12:29:42 -0400472pdb
473---
474
Berker Peksag12d60562017-11-04 15:17:56 +0300475:func:`~pdb.set_trace` now takes an optional *header* keyword-only
Barry Warsaw35425d62017-09-22 12:29:42 -0400476argument. If given, this is printed to the console just before debugging
Berker Peksag12d60562017-11-04 15:17:56 +0300477begins. (Contributed by Barry Warsaw in :issue:`31389`.)
Barry Warsaw35425d62017-09-22 12:29:42 -0400478
Mario Corchero9f1e5f12018-01-06 07:53:05 +0000479pdb command line now accepts `-m module_name` as an alternative to
480script file. (Contributed by Mario Corchero in :issue:`32206`.)
481
Brett Cannoncab0b2b2018-01-24 17:13:24 -0800482py_compile
483----------
484
485:func:`py_compile.compile` -- and by extension, :mod:`compileall` -- now
486respects the :envvar:`SOURCE_DATE_EPOCH` environment variable by
487unconditionally creating ``.pyc`` files for hash-based validation.
488This allows for guaranteeing
489`reproducible builds <https://reproducible-builds.org/>`_ of ``.pyc``
490files when they are created eagerly. (Contributed by Bernhard M. Wiedemann
491in :issue:`29708`.)
492
Mario Corchero9f1e5f12018-01-06 07:53:05 +0000493
Serhiy Storchaka3557b052017-10-24 23:31:42 +0300494re
495--
496
497The flags :const:`re.ASCII`, :const:`re.LOCALE` and :const:`re.UNICODE`
498can be set within the scope of a group.
499(Contributed by Serhiy Storchaka in :issue:`31690`.)
500
Serhiy Storchaka70d56fb2017-12-04 14:29:05 +0200501:func:`re.split` now supports splitting on a pattern like ``r'\b'``,
502``'^$'`` or ``(?=-)`` that matches an empty string.
503(Contributed by Serhiy Storchaka in :issue:`25054`.)
504
Barry Warsaw973b9012017-09-04 17:29:27 -0400505string
506------
507
508:class:`string.Template` now lets you to optionally modify the regular
509expression pattern for braced placeholders and non-braced placeholders
510separately. (Contributed by Barry Warsaw in :issue:`1198569`.)
511
Segev Finerb2a60832017-12-18 11:28:19 +0200512subprocess
513----------
514
515On Windows the default for *close_fds* was changed from :const:`False` to
516:const:`True` when redirecting the standard handles. It's now possible to set
517*close_fds* to :const:`True` when redirecting the standard handles. See
518:class:`subprocess.Popen`.
519
520This means that *close_fds* now defaults to :const:`True` on all supported
521platforms.
522
Victor Stinner5e3806f2017-11-30 11:40:24 +0100523sys
524---
525
526Added :attr:`sys.flags.dev_mode` flag for the new development mode.
527
Nathaniel J. Smithfc2f4072018-01-21 06:44:07 -0800528Deprecated :func:`sys.set_coroutine_wrapper` and
529:func:`sys.get_coroutine_wrapper`.
530
Victor Stinnera64ce972017-11-02 04:19:19 -0700531time
532----
533
Victor Stinnerc29b5852017-11-02 07:28:27 -0700534The :pep:`564` added six new functions with nanosecond resolution:
535
536* :func:`time.clock_gettime_ns`
537* :func:`time.clock_settime_ns`
538* :func:`time.monotonic_ns`
539* :func:`time.perf_counter_ns`
540* :func:`time.process_time_ns`
541* :func:`time.time_ns`
542
Victor Stinnera64ce972017-11-02 04:19:19 -0700543Add new clock identifiers:
544
545* :data:`time.CLOCK_BOOTTIME` (Linux): Identical to
546 :data:`time.CLOCK_MONOTONIC`, except it also includes any time that the
547 system is suspended.
548* :data:`time.CLOCK_PROF` (FreeBSD, NetBSD and OpenBSD): High-resolution
549 per-process timer from the CPU.
550* :data:`time.CLOCK_UPTIME` (FreeBSD, OpenBSD): Time whose absolute value is
551 the time the system has been running and not suspended, providing accurate
552 uptime measurement, both absolute and interval.
553
Antoine Pitrou4bd41c92017-11-15 22:52:21 +0100554Added functions :func:`time.thread_time` and :func:`time.thread_time_ns`
555to get per-thread CPU time measurements.
556(Contributed by Antoine Pitrou in :issue:`32025`.)
557
Brett Cannoncab0b2b2018-01-24 17:13:24 -0800558unicodedata
559-----------
560
561The internal :mod:`unicodedata` database has been upgraded to use `Unicode 10
562<http://www.unicode.org/versions/Unicode10.0.0/>`_. (Contributed by Benjamin
563Peterson.)
Jonas Haag4d193bc2017-11-28 20:40:44 +0100564
565unittest
566--------
567Added new command-line option ``-k`` to filter tests to run with a substring or
568Unix shell-like pattern. For example, ``python -m unittest -k foo`` runs the
569tests ``foo_tests.SomeTest.test_something``, ``bar_tests.SomeTest.test_foo``,
570but not ``bar_tests.FooTest.test_something``.
571
572
Serhiy Storchakad9c956f2017-01-11 20:13:03 +0200573unittest.mock
574-------------
575
576The :const:`~unittest.mock.sentinel` attributes now preserve their identity
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800577when they are :mod:`copied <copy>` or :mod:`pickled <pickle>`. (Contributed by
578Serhiy Storchaka in :issue:`20804`.)
Serhiy Storchakad9c956f2017-01-11 20:13:03 +0200579
Mario Corchero552be9d2017-10-17 12:35:11 +0100580New function :const:`~unittest.mock.seal` will disable the creation of mock
581children by preventing to get or set any new attribute on the sealed mock.
582The sealing process is performed recursively. (Contributed by Mario Corchero
583in :issue:`30541`.)
584
Ratnadeep Debnath21024f02017-02-25 14:30:28 +0530585urllib.parse
586------------
587
Daniel Himmelsteindadca482017-08-10 21:45:12 -0400588:func:`urllib.parse.quote` has been updated from RFC 2396 to RFC 3986,
Ratnadeep Debnath21024f02017-02-25 14:30:28 +0530589adding `~` to the set of characters that is never quoted by default.
590(Contributed by Christian Theune and Ratnadeep Debnath in :issue:`16285`.)
591
Xiang Zhang13f1f422017-05-03 11:16:21 +0800592uu
593--
594
595Function :func:`~uu.encode` now accepts an optional *backtick*
596keyword argument. When it's true, zeros are represented by ``'`'``
597instead of spaces. (Contributed by Xiang Zhang in :issue:`30103`.)
598
Victor Stinner747f48e2017-12-12 22:59:48 +0100599warnings
600--------
601
602The initialization of the default warnings filters has changed as follows:
603
604* warnings enabled via command line options (including those for :option:`-b`
605 and the new CPython-specific ``-X dev`` option) are always passed to the
606 warnings machinery via the ``sys.warnoptions`` attribute.
607* warnings filters enabled via the command line or the environment now have the
608 following precedence order:
609
610 * the ``BytesWarning`` filter for :option:`-b` (or ``-bb``)
611 * any filters specified with :option:`-W`
612 * any filters specified with :envvar:`PYTHONWARNINGS`
613 * any other CPython specific filters (e.g. the ``default`` filter added
614 for the new ``-X dev`` mode)
615 * any implicit filters defined directly by the warnings machinery
616* in CPython debug builds, all warnings are now displayed by default (the
617 implicit filter list is empty)
618
619(Contributed by Nick Coghlan and Victor Stinner in :issue:`20361`,
620:issue:`32043`, and :issue:`32230`)
621
scoder101a5e82017-09-30 15:35:21 +0200622xml.etree
623---------
624
625:ref:`ElementPath <elementtree-xpath>` predicates in the :meth:`find`
626methods can now compare text of the current node with ``[. = "text"]``,
627not only text in children. Predicates also allow adding spaces for
628better readability. (Contributed by Stefan Behnel in :issue:`31648`.)
629
Brett Cannoncab0b2b2018-01-24 17:13:24 -0800630xmlrpc.server
631-------------
632
633:meth:`register_function` of :class:`xmlrpc.server.SimpleXMLRPCDispatcher` and
634its subclasses can be used as a decorator. (Contributed by Xiang Zhang in
635:issue:`7769`.)
636
Paul Moore0780bf72017-08-26 18:04:12 +0100637zipapp
638------
639
640Function :func:`zipapp.create_archive` now accepts an optional *filter*
Zhiming Wangd87b1052017-09-29 13:31:52 -0400641argument to allow the user to select which files should be included in the
642archive, and an optional *compressed* argument to generate a compressed
Paul Moore0780bf72017-08-26 18:04:12 +0100643archive.
644
Zhiming Wangd87b1052017-09-29 13:31:52 -0400645A command line option ``--compress`` has also been added to support
646compression.
647
Ned Deily4829bc62016-09-12 17:29:04 -0400648
649Optimizations
650=============
651
Yury Selivanovf2392132016-12-13 19:03:51 -0500652* Added two new opcodes: ``LOAD_METHOD`` and ``CALL_METHOD`` to avoid
653 instantiation of bound method objects for method calls, which results
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800654 in method calls being faster up to 20%. (Contributed by Yury Selivanov and
655 INADA Naoki in :issue:`26110`.)
Yury Selivanovf2392132016-12-13 19:03:51 -0500656
Serhiy Storchaka0a58f722017-03-30 09:11:10 +0300657* Searching some unlucky Unicode characters (like Ukrainian capital "Є")
Cody Scott72fa3012017-11-09 13:58:59 -0500658 in a string was up to 25 times slower than searching other characters.
659 Now it is slower only by 3 times in the worst case.
Serhiy Storchaka0a58f722017-03-30 09:11:10 +0300660 (Contributed by Serhiy Storchaka in :issue:`24821`.)
661
Serhiy Storchaka97553fd2017-03-11 23:37:16 +0200662* Fast implementation from standard C library is now used for functions
Paul Romano992f6132017-09-15 12:00:57 -0500663 :func:`~math.erf` and :func:`~math.erfc` in the :mod:`math` module.
664 (Contributed by Serhiy Storchaka in :issue:`26121`.)
Serhiy Storchaka97553fd2017-03-11 23:37:16 +0200665
Serhiy Storchakaea720fe2017-03-30 09:12:31 +0300666* The :func:`os.fwalk` function has been sped up by 2 times. This was done
667 using the :func:`os.scandir` function.
668 (Contributed by Serhiy Storchaka in :issue:`25996`.)
669
Serhiy Storchakad4d79bc2017-11-04 14:16:35 +0200670* The :func:`shutil.rmtree` function has been sped up to 20--40%.
671 This was done using the :func:`os.scandir` function.
672 (Contributed by Serhiy Storchaka in :issue:`28564`.)
673
Serhiy Storchaka6d336a02017-05-09 23:37:14 +0300674* Optimized case-insensitive matching and searching of :mod:`regular
675 expressions <re>`. Searching some patterns can now be up to 20 times faster.
676 (Contributed by Serhiy Storchaka in :issue:`30285`.)
677
INADA Naokic1c47c12017-10-05 17:19:26 +0900678* :func:`re.compile` now converts ``flags`` parameter to int object if
679 it is ``RegexFlag``. It is now as fast as Python 3.5, and faster than
Cody Scott72fa3012017-11-09 13:58:59 -0500680 Python 3.6 by about 10% depending on the pattern.
INADA Naokic1c47c12017-10-05 17:19:26 +0900681 (Contributed by INADA Naoki in :issue:`31671`.)
682
Giampaolo Rodolafbfaa6f2017-06-09 22:20:41 +0200683* :meth:`selectors.EpollSelector.modify`, :meth:`selectors.PollSelector.modify`
684 and :meth:`selectors.DevpollSelector.modify` may be around 10% faster under
685 heavy loads. (Contributed by Giampaolo Rodola' in :issue:`30014`)
Ned Deily4829bc62016-09-12 17:29:04 -0400686
INADA Naoki7ea143a2017-12-14 16:47:20 +0900687* Constant folding is moved from peephole optimizer to new AST optimizer.
688 (Contributed by Eugene Toder and INADA Naoki in :issue:`29469`)
689
Ned Deily4829bc62016-09-12 17:29:04 -0400690Build and C API Changes
691=======================
692
Brett Cannoncab0b2b2018-01-24 17:13:24 -0800693* :mod:`py_compile` and :mod:`compileall` now support the
694 :envvar:`SOURCE_DATE_EPOCH` environment variable by unconditionally
695 building ``.pyc`` files for hash verification instead of potentially
696 timestamp-based ``.pyc`` files. See the notes for the `py_compile`_
697 improvement notes for more details.
698
Zachary Waref40d4dd2016-09-17 01:25:24 -0500699* A full copy of libffi is no longer bundled for use when building the
700 :mod:`_ctypes <ctypes>` module on non-OSX UNIX platforms. An installed copy
701 of libffi is now required when building ``_ctypes`` on such platforms.
Brett Cannoncab0b2b2018-01-24 17:13:24 -0800702 (Contributed by Zachary Ware in :issue:`27979`.)
Ned Deily4829bc62016-09-12 17:29:04 -0400703
Serhiy Storchaka007d7ff2016-11-22 07:58:08 +0200704* The fields :c:member:`name` and :c:member:`doc` of structures
705 :c:type:`PyMemberDef`, :c:type:`PyGetSetDef`,
706 :c:type:`PyStructSequence_Field`, :c:type:`PyStructSequence_Desc`,
707 and :c:type:`wrapperbase` are now of type ``const char *`` rather of
708 ``char *``. (Contributed by Serhiy Storchaka in :issue:`28761`.)
709
Serhiy Storchaka2a404b62017-01-22 23:07:07 +0200710* The result of :c:func:`PyUnicode_AsUTF8AndSize` and :c:func:`PyUnicode_AsUTF8`
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800711 is now of type ``const char *`` rather of ``char *``. (Contributed by Serhiy
712 Storchaka in :issue:`28769`.)
Serhiy Storchaka2a404b62017-01-22 23:07:07 +0200713
Oren Milman0ccc0f62017-10-08 11:17:46 +0300714* The result of :c:func:`PyMapping_Keys`, :c:func:`PyMapping_Values` and
715 :c:func:`PyMapping_Items` is now always a list, rather than a list or a
716 tuple. (Contributed by Oren Milman in :issue:`28280`.)
717
Serhiy Storchaka6e08baf2017-01-25 13:27:44 +0200718* Added functions :c:func:`PySlice_Unpack` and :c:func:`PySlice_AdjustIndices`.
719 (Contributed by Serhiy Storchaka in :issue:`27867`.)
720
Antoine Pitrouf7ecfac2017-05-28 11:35:14 +0200721* :c:func:`PyOS_AfterFork` is deprecated in favour of the new functions
722 :c:func:`PyOS_BeforeFork`, :c:func:`PyOS_AfterFork_Parent` and
723 :c:func:`PyOS_AfterFork_Child`. (Contributed by Antoine Pitrou in
724 :issue:`16500`.)
725
Zachary Warecb8c0482017-06-15 22:34:59 -0500726* The Windows build process no longer depends on Subversion to pull in external
727 sources, a Python script is used to download zipfiles from GitHub instead.
728 If Python 3.6 is not found on the system (via ``py -3.6``), NuGet is used to
729 download a copy of 32-bit Python for this purpose. (Contributed by Zachary
730 Ware in :issue:`30450`.)
731
xdegaye56d1f5c2017-10-26 15:09:06 +0200732* The ``PyExc_RecursionErrorInst`` singleton that was part of the public API
733 has been removed as its members being never cleared may cause a segfault
734 during finalization of the interpreter. Contributed by Xavier de Gaye in
735 :issue:`22898` and :issue:`30697`.
736
Antoine Pitroua6a4dc82017-09-07 18:56:24 +0200737* Support for building ``--without-threads`` is removed.
738 (Contributed by Antoine Pitrou in :issue:`31370`.).
739
Ned Deily4829bc62016-09-12 17:29:04 -0400740
Nick Coghlan5a851672017-09-08 10:14:16 +1000741Other CPython Implementation Changes
742====================================
743
744* Trace hooks may now opt out of receiving ``line`` events from the interpreter
745 by setting the new ``f_trace_lines`` attribute to :const:`False` on the frame
746 being traced. (Contributed by Nick Coghlan in :issue:`31344`.)
747
748* Trace hooks may now opt in to receiving ``opcode`` events from the interpreter
749 by setting the new ``f_trace_opcodes`` attribute to :const:`True` on the frame
750 being traced. (Contributed by Nick Coghlan in :issue:`31344`.)
751
752
Ned Deily4829bc62016-09-12 17:29:04 -0400753Deprecated
754==========
755
Serhiy Storchaka73a7e9b2017-12-01 06:54:17 +0200756* Yield expressions (both ``yield`` and ``yield from`` clauses) are now deprecated
757 in comprehensions and generator expressions (aside from the iterable expression
758 in the leftmost :keyword:`for` clause). This ensures that comprehensions
759 always immediately return a container of the appropriate type (rather than
760 potentially returning a :term:`generator iterator` object), while generator
761 expressions won't attempt to interleave their implicit output with the output
762 from any explicit yield expressions.
763
764 In Python 3.7, such expressions emit :exc:`DeprecationWarning` when compiled,
765 in Python 3.8+ they will emit :exc:`SyntaxError`. (Contributed by Serhiy
766 Storchaka in :issue:`10544`.)
767
Serhiy Storchaka6e08baf2017-01-25 13:27:44 +0200768- Function :c:func:`PySlice_GetIndicesEx` is deprecated and replaced with
769 a macro if ``Py_LIMITED_API`` is not set or set to the value between
770 ``0x03050400`` and ``0x03060000`` (not including) or ``0x03060100`` or
771 higher. (Contributed by Serhiy Storchaka in :issue:`27867`.)
Ned Deily4829bc62016-09-12 17:29:04 -0400772
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800773- Deprecated :meth:`format` from :mod:`locale`, use the :meth:`format_string`
774 instead. (Contributed by Garvit in :issue:`10379`.)
775
Matthias Bussonnier1d4601c2017-02-15 18:00:32 -0800776- Methods
777 :meth:`MetaPathFinder.find_module() <importlib.abc.MetaPathFinder.find_module>`
778 (replaced by
779 :meth:`MetaPathFinder.find_spec() <importlib.abc.MetaPathFinder.find_spec>`
780 ) and
781 :meth:`PathEntryFinder.find_loader() <importlib.abc.PathEntryFinder.find_loader>`
782 (replaced by
783 :meth:`PathEntryFinder.find_spec() <importlib.abc.PathEntryFinder.find_spec>`)
784 both deprecated in Python 3.4 now emit :exc:`DeprecationWarning`. (Contributed
785 by Matthias Bussonnier in :issue:`29576`)
786
Serhiy Storchakaf6595982017-03-12 13:15:01 +0200787- Using non-integer value for selecting a plural form in :mod:`gettext` is
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800788 now deprecated. It never correctly worked. (Contributed by Serhiy Storchaka
789 in :issue:`28692`.)
Serhiy Storchakaf6595982017-03-12 13:15:01 +0200790
Victor Stinner89a1c932017-05-15 11:01:21 +0200791- The :mod:`macpath` is now deprecated and will be removed in Python 3.8.
792
Brett Cannonbca42182018-01-12 15:08:59 -0800793- The :class:`importlib.abc.ResourceLoader` ABC has been deprecated in
794 favour of :class:`importlib.abc.ResourceReader`.
795
Ned Deily4829bc62016-09-12 17:29:04 -0400796
Serhiy Storchakaaefa7eb2017-03-23 15:48:39 +0200797Changes in the C API
798--------------------
799
800- The type of results of :c:func:`PyThread_start_new_thread` and
801 :c:func:`PyThread_get_thread_ident`, and the *id* parameter of
802 :c:func:`PyThreadState_SetAsyncExc` changed from :c:type:`long` to
803 :c:type:`unsigned long`.
804 (Contributed by Serhiy Storchaka in :issue:`6532`.)
805
Serhiy Storchakae613e6a2017-06-27 16:03:14 +0300806- :c:func:`PyUnicode_AsWideCharString` now raises a :exc:`ValueError` if the
807 second argument is *NULL* and the :c:type:`wchar_t*` string contains null
808 characters. (Contributed by Serhiy Storchaka in :issue:`30708`.)
809
Serhiy Storchakaaefa7eb2017-03-23 15:48:39 +0200810
Steve (Gadget) Barnes5b8f9722017-06-28 20:14:52 +0100811Windows Only
812------------
813- The python launcher, (py.exe), can accept 32 & 64 bit specifiers **without**
814 having to specify a minor version as well. So ``py -3-32`` and ``py -3-64``
815 become valid as well as ``py -3.7-32``, also the -*m*-64 and -*m.n*-64 forms
816 are now accepted to force 64 bit python even if 32 bit would have otherwise
817 been used. If the specified version is not available py.exe will error exit.
818 (Contributed by Steve Barnes in :issue:`30291`.)
819
Brett Cannonbca42182018-01-12 15:08:59 -0800820- The launcher can be run as ``py -0`` to produce a list of the installed pythons,
821 *with default marked with an asterisk*. Running ``py -0p`` will include the paths.
Steve (Gadget) Barnes5b8f9722017-06-28 20:14:52 +0100822 If py is run with a version specifier that cannot be matched it will also print
823 the *short form* list of available specifiers.
824 (Contributed by Steve Barnes in :issue:`30362`.)
825
Ned Deily4829bc62016-09-12 17:29:04 -0400826Removed
827=======
828
Victor Stinner13ff2452018-01-22 18:32:50 +0100829Platform Support Removals
830-------------------------
831
832* FreeBSD 9 and older are no longer supported.
833
Serhiy Storchakaff3dbe92016-12-06 19:25:19 +0200834API and Feature Removals
835------------------------
836
Victor Stinner01b5aab2017-10-24 02:02:00 -0700837* The ``os.stat_float_times()`` function has been removed. It was introduced in
838 Python 2.3 for backward compatibility with Python 2.2, and was deprecated
839 since Python 3.1.
840
Serhiy Storchakaff3dbe92016-12-06 19:25:19 +0200841* Unknown escapes consisting of ``'\'`` and an ASCII letter in replacement
Serhiy Storchakab2d61792017-01-13 21:14:40 +0200842 templates for :func:`re.sub` were deprecated in Python 3.5, and will now
843 cause an error.
Ned Deily4829bc62016-09-12 17:29:04 -0400844
Serhiy Storchaka4f76fb12017-01-13 13:25:24 +0200845* Removed support of the *exclude* argument in :meth:`tarfile.TarFile.add`.
Serhiy Storchakab2d61792017-01-13 21:14:40 +0200846 It was deprecated in Python 2.7 and 3.2. Use the *filter* argument instead.
Serhiy Storchaka4f76fb12017-01-13 13:25:24 +0200847
Serhiy Storchaka9ed707e2017-01-13 20:55:05 +0200848* The ``splitunc()`` function in the :mod:`ntpath` module was deprecated in
849 Python 3.1, and has now been removed. Use the :func:`~os.path.splitdrive`
850 function instead.
851
Raymond Hettinger8b57d732017-09-10 10:23:36 -0700852* :func:`collections.namedtuple` no longer supports the *verbose* parameter
853 or ``_source`` attribute which showed the generated source code for the
854 named tuple class. This was part of an optimization designed to speed-up
855 class creation. (Contributed by Jelle Zijlstra with further improvements
856 by INADA Naoki, Serhiy Storchaka, and Raymond Hettinger in :issue:`28638`.)
857
Serhiy Storchaka2e564242017-03-06 17:01:06 +0200858* Functions :func:`bool`, :func:`float`, :func:`list` and :func:`tuple` no
859 longer take keyword arguments. The first argument of :func:`int` can now
Daniel Porteous77f68e32017-06-21 10:21:48 +1000860 be passed only as positional argument.
Serhiy Storchaka2e564242017-03-06 17:01:06 +0200861
Serhiy Storchakaedef3582017-05-15 13:21:31 +0300862* Removed previously deprecated in Python 2.4 classes ``Plist``, ``Dict`` and
863 ``_InternalDict`` in the :mod:`plistlib` module. Dict values in the result
864 of functions :func:`~plistlib.readPlist` and
865 :func:`~plistlib.readPlistFromBytes` are now normal dicts. You no longer
866 can use attribute access to access items of these dictionaries.
867
Ned Deily4829bc62016-09-12 17:29:04 -0400868
869Porting to Python 3.7
870=====================
871
872This section lists previously described changes and other bugfixes
873that may require changes to your code.
874
875
Serhiy Storchaka9165f772017-11-15 08:49:40 +0200876Changes in Python behavior
877--------------------------
878
879* Due to an oversight, earlier Python versions erroneously accepted the
880 following syntax::
881
882 f(1 for x in [1],)
883
Serhiy Storchakaddbce132017-11-15 17:39:37 +0200884 class C(1 for x in [1]):
885 pass
886
Serhiy Storchaka9165f772017-11-15 08:49:40 +0200887 Python 3.7 now correctly raises a :exc:`SyntaxError`, as a generator
888 expression always needs to be directly inside a set of parentheses
Serhiy Storchakaddbce132017-11-15 17:39:37 +0200889 and cannot have a comma on either side, and the duplication of the
890 parentheses can be omitted only on calls.
891 (Contributed by Serhiy Storchaka in :issue:`32012` and :issue:`32023`.)
Serhiy Storchaka9165f772017-11-15 08:49:40 +0200892
893
Serhiy Storchaka009b0a12017-01-13 09:10:51 +0200894Changes in the Python API
895-------------------------
896
Victor Stinnercb064fc2018-01-15 15:58:02 +0100897* The :func:`locale.localeconv` function now sets temporarily the ``LC_CTYPE``
898 locale to the ``LC_NUMERIC`` locale in some cases.
899
Victor Stinnerac577d72017-11-28 21:33:20 +0100900* The ``asyncio.windows_utils.socketpair()`` function has been
901 removed: use directly :func:`socket.socketpair` which is available on all
902 platforms since Python 3.5 (before, it wasn't available on Windows).
903 ``asyncio.windows_utils.socketpair()`` was just an alias to
904 ``socket.socketpair`` on Python 3.5 and newer.
905
Victor Stinner4271dfd2017-11-28 15:19:56 +0100906* :mod:`asyncio`: The module doesn't export :mod:`selectors` and
907 :mod:`_overlapped` modules as ``asyncio.selectors`` and
908 ``asyncio._overlapped``. Replace ``from asyncio import selectors`` with
909 ``import selectors`` for example.
910
Sanyam Khuranab9c3da52017-06-13 22:41:14 +0530911* :meth:`pkgutil.walk_packages` now raises ValueError if *path* is a string.
912 Previously an empty list was returned. (Contributed by Sanyam Khurana in
913 :issue:`24744`.)
914
Serhiy Storchaka009b0a12017-01-13 09:10:51 +0200915* A format string argument for :meth:`string.Formatter.format`
916 is now :ref:`positional-only <positional-only_parameter>`.
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800917 Passing it as a keyword argument was deprecated in Python 3.5. (Contributed
918 by Serhiy Storchaka in :issue:`29193`.)
Serhiy Storchakacc283372017-01-13 09:23:15 +0200919
920* Attributes :attr:`~http.cookies.Morsel.key`,
921 :attr:`~http.cookies.Morsel.value` and
922 :attr:`~http.cookies.Morsel.coded_value` of class
923 :class:`http.cookies.Morsel` are now read-only.
Serhiy Storchakab2d61792017-01-13 21:14:40 +0200924 Assigning to them was deprecated in Python 3.5.
Serhiy Storchakacc283372017-01-13 09:23:15 +0200925 Use the :meth:`~http.cookies.Morsel.set` method for setting them.
926 (Contributed by Serhiy Storchaka in :issue:`29192`.)
INADA Naoki015bce62017-01-16 17:23:30 +0900927
INADA Naokicb41b272017-02-23 00:31:59 +0900928* ``Module``, ``FunctionDef``, ``AsyncFunctionDef``, and
929 ``ClassDef`` AST nodes now have a new ``docstring`` field.
930 The first statement in their body is not considered as a docstring
931 anymore. ``co_firstlineno`` and ``co_lnotab`` of code object for class
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800932 and module are affected by this change. (Contributed by INADA Naoki and
933 Eugene Toder in :issue:`29463`.)
INADA Naoki015bce62017-01-16 17:23:30 +0900934
Serhiy Storchakae304e332017-03-24 13:27:42 +0200935* The *mode* argument of :func:`os.makedirs` no longer affects the file
936 permission bits of newly-created intermediate-level directories.
937 To set their file permission bits you can set the umask before invoking
938 ``makedirs()``.
939 (Contributed by Serhiy Storchaka in :issue:`19930`.)
940
Victor Stinnerf87b85f2017-06-23 15:11:12 +0200941* The :attr:`struct.Struct.format` type is now :class:`str` instead of
942 :class:`bytes`. (Contributed by Victor Stinner in :issue:`21071`.)
943
Segev Finer9f3bdcb2017-06-28 23:51:00 +0300944* Due to internal changes in :mod:`socket` you won't be able to
945 :func:`socket.fromshare` a socket :func:`~socket.socket.share`-ed in older
946 Python versions.
947
Utkarsh Upadhyay8e453182017-07-28 14:42:56 +0200948* ``repr`` for :class:`datetime.timedelta` has changed to include keyword arguments
949 in the output. (Contributed by Utkarsh Upadhyay in :issue:`30302`.)
950
Serhiy Storchakad4d79bc2017-11-04 14:16:35 +0200951* Because :func:`shutil.rmtree` is now implemented using the :func:`os.scandir`
952 function, the user specified handler *onerror* is now called with the first
953 argument ``os.scandir`` instead of ``os.listdir`` when listing the direcory
954 is failed.
955
Serhiy Storchaka05cb7282017-11-16 12:38:26 +0200956* Support of nested sets and set operations in regular expressions as in
957 `Unicode Technical Standard #18`_ might be added in the future. This would
958 change the syntax, so to facilitate this change a :exc:`FutureWarning` will
959 be raised in ambiguous cases for the time being.
960 That include sets starting with a literal ``'['`` or containing literal
961 character sequences ``'--'``, ``'&&'``, ``'~~'``, and ``'||'``. To
962 avoid a warning escape them with a backslash.
963 (Contributed by Serhiy Storchaka in :issue:`30349`.)
964
Serhiy Storchaka70d56fb2017-12-04 14:29:05 +0200965* The result of splitting a string on a :mod:`regular expression <re>`
966 that could match an empty string has been changed. For example
967 splitting on ``r'\s*'`` will now split not only on whitespaces as it
Serhiy Storchakafbb490f2018-01-04 11:06:13 +0200968 did previously, but also on empty strings before all non-whitespace
969 characters and just before the end of the string.
970 The previous behavior can be restored by changing the pattern
Serhiy Storchaka70d56fb2017-12-04 14:29:05 +0200971 to ``r'\s+'``. A :exc:`FutureWarning` was emitted for such patterns since
972 Python 3.5.
973
974 For patterns that match both empty and non-empty strings, the result of
975 searching for all matches may also be changed in other cases. For example
976 in the string ``'a\n\n'``, the pattern ``r'(?m)^\s*?$'`` will not only
977 match empty strings at positions 2 and 3, but also the string ``'\n'`` at
978 positions 2--3. To match only blank lines, the pattern should be rewritten
979 as ``r'(?m)^[^\S\n]*$'``.
980
Serhiy Storchakafbb490f2018-01-04 11:06:13 +0200981 :func:`re.sub()` now replaces empty matches adjacent to a previous
982 non-empty match. For example ``re.sub('x*', '-', 'abxd')`` returns now
983 ``'-a-b--d-'`` instead of ``'-a-b--d-'`` (the first minus between 'b' and
984 'd' replaces 'x', and the second minus replaces an empty string between
985 'x' and 'd').
986
987 (Contributed by Serhiy Storchaka in :issue:`25054` and :issue:`32308`.)
Serhiy Storchaka70d56fb2017-12-04 14:29:05 +0200988
Jesse-Bakker706e10b2017-11-30 00:05:07 +0100989* :class:`tracemalloc.Traceback` frames are now sorted from oldest to most
990 recent to be more consistent with :mod:`traceback`.
991 (Contributed by Jesse Bakker in :issue:`32121`.)
992
Yury Selivanov98181422017-12-18 20:02:54 -0500993* On OSes that support :const:`socket.SOCK_NONBLOCK` or
994 :const:`socket.SOCK_CLOEXEC` bit flags, the
995 :attr:`socket.type <socket.socket.type>` no longer has them applied.
996 Therefore, checks like ``if sock.type == socket.SOCK_STREAM``
997 work as expected on all platforms.
998 (Contributed by Yury Selivanov in :issue:`32331`.)
999
Serhiy Storchaka05cb7282017-11-16 12:38:26 +02001000.. _Unicode Technical Standard #18: https://unicode.org/reports/tr18/
1001
Segev Finerb2a60832017-12-18 11:28:19 +02001002* On Windows the default for the *close_fds* argument of
1003 :class:`subprocess.Popen` was changed from :const:`False` to :const:`True`
1004 when redirecting the standard handles. If you previously depended on handles
1005 being inherited when using :class:`subprocess.Popen` with standard io
1006 redirection, you will have to pass ``close_fds=False`` to preserve the
1007 previous behaviour, or use
1008 :attr:`STARTUPINFO.lpAttributeList <subprocess.STARTUPINFO.lpAttributeList>`.
1009
Serhiy Storchakae304e332017-03-24 13:27:42 +02001010
Serhiy Storchaka4d3f0842017-10-08 12:53:34 +03001011Changes in the C API
1012--------------------
1013
1014* The function :c:func:`PySlice_GetIndicesEx` is considered not safe for
1015 resizable sequences. If the slice indices are not instances of :class:`int`,
1016 but objects that implement the :meth:`!__index__` method, the sequence can be
1017 resized after passing its length to :c:func:`!PySlice_GetIndicesEx`. This
1018 can lead to returning indices out of the length of the sequence. For
1019 avoiding possible problems use new functions :c:func:`PySlice_Unpack` and
1020 :c:func:`PySlice_AdjustIndices`.
1021 (Contributed by Serhiy Storchaka in :issue:`27867`.)
1022
1023
INADA Naoki015bce62017-01-16 17:23:30 +09001024CPython bytecode changes
1025------------------------
1026
Martin Panter91a88662017-01-24 00:30:06 +00001027* Added two new opcodes: :opcode:`LOAD_METHOD` and :opcode:`CALL_METHOD`.
INADA Naoki015bce62017-01-16 17:23:30 +09001028 (Contributed by Yury Selivanov and INADA Naoki in :issue:`26110`.)
Julien Palard809d1732017-10-24 11:22:22 +02001029
1030
Nick Coghlan1b461312017-11-05 14:58:45 +10001031Other CPython implementation changes
1032------------------------------------
1033
1034* In preparation for potential future changes to the public CPython runtime
1035 initialization API (see :pep:`432` for details), CPython's internal startup
1036 and configuration management logic has been significantly refactored. While
1037 these updates are intended to be entirely transparent to both embedding
1038 applications and users of the regular CPython CLI, they're being mentioned
1039 here as the refactoring changes the internal order of various operations
1040 during interpreter startup, and hence may uncover previously latent defects,
1041 either in embedding applications, or in CPython itself.
1042 (Contributed by Nick Coghlan and Eric Snow as part of :issue:`22257`.)
1043
Victor Stinner747f48e2017-12-12 22:59:48 +01001044* Due to changes in the way the default warnings filters are configured,
1045 setting ``Py_BytesWarningFlag`` to a value greater than one is no longer
1046 sufficient to both emit ``BytesWarning`` messages and have them converted
1047 to exceptions. Instead, the flag must be set (to cause the warnings to be
1048 emitted in the first place), and an explicit ``error::BytesWarning``
1049 warnings filter added to convert them to exceptions.
Nick Coghlan1b461312017-11-05 14:58:45 +10001050
Julien Palard809d1732017-10-24 11:22:22 +02001051Documentation
1052=============
1053
1054.. _whatsnew37-pep545:
1055
1056PEP 545: Python Documentation Translations
1057------------------------------------------
1058
1059:pep:`545` describes the process to translate Python documentation,
1060and two translations have been added:
1061
Berker Peksag28ab3ce2017-11-08 16:36:58 +03001062- Japanese: https://docs.python.org/ja/ and associated GitHub
Julien Palard809d1732017-10-24 11:22:22 +02001063 repository: https://github.com/python/python-docs-ja
1064
Berker Peksag28ab3ce2017-11-08 16:36:58 +03001065- French: https://docs.python.org/fr/ and associated GitHub
Julien Palard809d1732017-10-24 11:22:22 +02001066 repository: https://github.com/python/python-docs-fr
1067
1068(Contributed by Julien Palard, Inada Naoki, and Victor Stinner in
Berker Peksag28ab3ce2017-11-08 16:36:58 +03001069:issue:`26546`.)