blob: 5c001594dc830b7db048ce981f01288e45411e37 [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 Coghlan6ea41862017-06-11 13:16:15 +100073.. _whatsnew37-pep538:
74
75PEP 538: Legacy C Locale Coercion
76---------------------------------
77
78An ongoing challenge within the Python 3 series has been determining a sensible
79default strategy for handling the "7-bit ASCII" text encoding assumption
80currently implied by the use of the default C locale on non-Windows platforms.
81
82:pep:`538` updates the default interpreter command line interface to
83automatically coerce that locale to an available UTF-8 based locale as
84described in the documentation of the new :envvar:`PYTHONCOERCECLOCALE`
85environment variable. Automatically setting ``LC_CTYPE`` this way means that
86both the core interpreter and locale-aware C extensions (such as
87:mod:`readline`) will assume the use of UTF-8 as the default text encoding,
88rather than ASCII.
89
90The platform support definition in :pep:`11` has also been updated to limit
91full text handling support to suitably configured non-ASCII based locales.
92
93As part of this change, the default error handler for ``stdin`` and ``stdout``
94is now ``surrogateescape`` (rather than ``strict``) when using any of the
95defined coercion target locales (currently ``C.UTF-8``, ``C.utf8``, and
96``UTF-8``). The default error handler for ``stderr`` continues to be
97``backslashreplace``, regardless of locale.
98
Nick Coghlaneb817952017-06-18 12:29:42 +100099Locale coercion is silent by default, but to assist in debugging potentially
100locale related integration problems, explicit warnings (emitted directly on
101``stderr`` can be requested by setting ``PYTHONCOERCECLOCALE=warn``. This
102setting will also cause the Python runtime to emit a warning if the legacy C
103locale remains active when the core interpreter is initialized.
Nick Coghlan6ea41862017-06-11 13:16:15 +1000104
105.. seealso::
106
107 :pep:`538` -- Coercing the legacy C locale to a UTF-8 based locale
108 PEP written and implemented by Nick Coghlan.
Ned Deily4829bc62016-09-12 17:29:04 -0400109
Barry Warsaw36c1d1f2017-10-05 12:11:18 -0400110.. _whatsnew37-pep553:
111
112PEP 553: Built-in breakpoint()
113------------------------------
114
115:pep:`553` describes a new built-in called ``breakpoint()`` which makes it
116easy and consistent to enter the Python debugger. Built-in ``breakpoint()``
117calls ``sys.breakpointhook()``. By default, this latter imports ``pdb`` and
118then calls ``pdb.set_trace()``, but by binding ``sys.breakpointhook()`` to the
119function of your choosing, ``breakpoint()`` can enter any debugger. Or, the
120environment variable :envvar:`PYTHONBREAKPOINT` can be set to the callable of
121your debugger of choice. Set ``PYTHONBREAKPOINT=0`` to completely disable
122built-in ``breakpoint()``.
123
124.. seealso::
125
126 :pep:`553` -- Built-in breakpoint()
127 PEP written and implemented by Barry Warsaw
128
Ned Deily4829bc62016-09-12 17:29:04 -0400129
Masayuki Yamamoto731e1892017-10-06 19:41:34 +0900130.. _whatsnew37-pep539:
131
132PEP 539: A New C-API for Thread-Local Storage in CPython
133--------------------------------------------------------
134
135While Python provides a C API for thread-local storage support; the existing
136:ref:`Thread Local Storage (TLS) API <thread-local-storage-api>` has used
137:c:type:`int` to represent TLS keys across all platforms. This has not
138generally been a problem for officially-support platforms, but that is neither
139POSIX-compliant, nor portable in any practical sense.
140
141:pep:`539` changes this by providing a new :ref:`Thread Specific Storage (TSS)
142API <thread-specific-storage-api>` to CPython which supersedes use of the
143existing TLS API within the CPython interpreter, while deprecating the existing
144API. The TSS API uses a new type :c:type:`Py_tss_t` instead of :c:type:`int`
145to represent TSS keys--an opaque type the definition of which may depend on
146the underlying TLS implementation. Therefore, this will allow to build CPython
147on platforms where the native TLS key is defined in a way that cannot be safely
148cast to :c:type:`int`.
149
150Note that on platforms where the native TLS key is defined in a way that cannot
151be safely cast to :c:type:`int`, all functions of the existing TLS API will be
152no-op and immediately return failure. This indicates clearly that the old API
153is not supported on platforms where it cannot be used reliably, and that no
154effort will be made to add such support.
155
156.. seealso::
157
158 :pep:`539` -- A New C-API for Thread-Local Storage in CPython
159 PEP written by Erik M. Bray; implementation by Masayuki Yamamoto.
160
161
Victor Stinnerc29b5852017-11-02 07:28:27 -0700162PEP 564: Add new time functions with nanosecond resolution
163----------------------------------------------------------
164
165Add six new "nanosecond" variants of existing functions to the :mod:`time`
166module:
167
168* :func:`time.clock_gettime_ns`
169* :func:`time.clock_settime_ns`
170* :func:`time.monotonic_ns`
171* :func:`time.perf_counter_ns`
172* :func:`time.process_time_ns`
173* :func:`time.time_ns`
174
175While similar to the existing functions without the ``_ns`` suffix, they
176provide nanosecond resolution: they return a number of nanoseconds as a Python
177``int``.
178
179The ``time.time_ns()`` resolution is 3 times better than the ``time.time()``
180resolution on Linux and Windows.
181
182.. seealso::
183
184 :pep:`564` -- Add new time functions with nanosecond resolution
185 PEP written and implemented by Victor Stinner
186
187
Victor Stinnerccb04422017-11-16 03:20:31 -0800188New Developer Mode: -X dev
189--------------------------
190
191Add a new "developer mode": ``-X dev`` command line option to enable debug
192checks at runtime.
193
194In short, ``python3 -X dev ...`` behaves as ``PYTHONMALLOC=debug python3 -W
195default -X faulthandler ...``, except that the PYTHONMALLOC environment
196variable is not set in practice.
197
198See :option:`-X` ``dev`` for the details.
199
200
Ned Deily4829bc62016-09-12 17:29:04 -0400201Other Language Changes
202======================
203
Serhiy Storchaka5bb8b912016-12-16 19:19:02 +0200204* More than 255 arguments can now be passed to a function, and a function can
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800205 now have more than 255 parameters. (Contributed by Serhiy Storchaka in
206 :issue:`12844` and :issue:`18896`.)
Ned Deily4829bc62016-09-12 17:29:04 -0400207
Serhiy Storchakadd1da7f2016-12-19 18:51:37 +0200208* :meth:`bytes.fromhex` and :meth:`bytearray.fromhex` now ignore all ASCII
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800209 whitespace, not only spaces. (Contributed by Robert Xiao in :issue:`28927`.)
Serhiy Storchakadd1da7f2016-12-19 18:51:37 +0200210
Matthias Bussonnier1bc15642017-02-22 07:06:50 -0800211* :exc:`ImportError` now displays module name and module ``__file__`` path when
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800212 ``from ... import ...`` fails. (Contributed by Matthias Bussonnier in :issue:`29546`.)
Matthias Bussonnier1bc15642017-02-22 07:06:50 -0800213
Serhiy Storchakaf93234b2017-05-09 22:31:05 +0300214* Circular imports involving absolute imports with binding a submodule to
215 a name are now supported.
216 (Contributed by Serhiy Storchaka in :issue:`30024`.)
217
Serhiy Storchaka7e19dbc2017-05-13 12:40:52 +0300218* ``object.__format__(x, '')`` is now equivalent to ``str(x)`` rather than
219 ``format(str(self), '')``.
220 (Contributed by Serhiy Storchaka in :issue:`28974`.)
221
Ned Deily4829bc62016-09-12 17:29:04 -0400222
223New Modules
224===========
225
226* None yet.
227
228
229Improved Modules
230================
231
Pierre Quentelcc3fa202017-05-08 14:08:34 +0200232
R. David Murray0f6b9d22017-09-06 20:25:40 -0400233argparse
234--------
235
236The :meth:`~argparse.ArgumentParser.parse_intermixed_args` supports letting
237the user intermix options and positional arguments on the command line,
238as is possible in many unix commands. It supports most but not all
239argparse features. (Contributed by paul.j3 in :issue:`14191`.)
240
241
Xiang Zhang13f1f422017-05-03 11:16:21 +0800242binascii
243--------
244
245The :func:`~binascii.b2a_uu` function now accepts an optional *backtick*
246keyword argument. When it's true, zeros are represented by ``'`'``
247instead of spaces. (Contributed by Xiang Zhang in :issue:`30103`.)
248
Oz N Tiram8b7a4cc2017-06-06 11:35:59 +0200249
250calendar
251--------
252
Walter Dörwaldf5c58c72017-06-26 18:31:52 +0200253The class :class:`~calendar.HTMLCalendar` has new class attributes which ease
254the customisation of the CSS classes in the produced HTML calendar.
Oz N Tiram8b7a4cc2017-06-06 11:35:59 +0200255(Contributed by Oz Tiram in :issue:`30095`.)
256
257cgi
258---
259
260:func:`~cgi.parse_multipart` returns the same results as
261:class:`~FieldStorage` : for non-file fields, the value associated to a key
262is a list of strings, not bytes.
263(Contributed by Pierre Quentel in :issue:`29979`.)
264
Jelle Zijlstra2e624692017-04-30 18:25:58 -0700265contextlib
266----------
267
268:func:`contextlib.asynccontextmanager` has been added. (Contributed by
269Jelle Zijlstra in :issue:`29679`.)
270
Sanyam Khurana7973e272017-11-08 16:20:56 +0530271cProfile
272--------
273
274cProfile command line now accepts `-m module_name` as an alternative to
275script path. (Contributed by Sanyam Khurana in :issue:`21862`.)
276
Serhiy Storchakaeab3ff72017-10-24 19:36:17 +0300277crypt
278-----
279
280Added support for the Blowfish method.
281(Contributed by Serhiy Storchaka in :issue:`31664`.)
282
Serhiy Storchakacede8c92017-11-16 13:22:51 +0200283The :func:`~crypt.mksalt` function now allows to specify the number of rounds
284for hashing. (Contributed by Serhiy Storchaka in :issue:`31702`.)
285
Serhiy Storchaka1efbf922017-06-11 14:09:39 +0300286dis
287---
288
289The :func:`~dis.dis` function now is able to
290disassemble nested code objects (the code of comprehensions, generator
291expressions and nested functions, and the code used for building nested
292classes). (Contributed by Serhiy Storchaka in :issue:`11822`.)
293
Ryan Gonzalezf9f87f02017-04-14 04:00:25 -0500294distutils
295---------
296
297README.rst is now included in the list of distutils standard READMEs and
298therefore included in source distributions.
299(Contributed by Ryan Gonzalez in :issue:`11913`.)
300
Berker Peksagdcaed6b2017-11-23 21:34:20 +0300301:class:`distutils.core.setup` now raises a :exc:`TypeError` if
302``classifiers``, ``keywords`` and ``platforms`` fields are not specified
303as a list. However, to minimize backwards incompatibility concerns,
304``keywords`` and ``platforms`` fields still accept a comma separated string.
305(Contributed by Berker Peksag in :issue:`19610`.)
306
Nir Sofferad455cd2017-11-06 23:16:37 +0200307http.client
308-----------
309
310Add Configurable *blocksize* to ``HTTPConnection`` and
311``HTTPSConnection`` for improved upload throughput.
312(Contributed by Nir Soffer in :issue:`31945`.)
313
Pierre Quentel351adda2017-04-02 12:26:12 +0200314http.server
315-----------
316
317:class:`~http.server.SimpleHTTPRequestHandler` supports the HTTP
318If-Modified-Since header. The server returns the 304 response status if the
319target file was not modified after the time specified in the header.
320(Contributed by Pierre Quentel in :issue:`29654`.)
321
Stéphane Wirtela17a2f52017-05-24 09:29:06 +0200322Add the parameter ``directory`` to the :class:`~http.server.SimpleHTTPRequestHandler`
323and the ``--directory`` to the command line of the module :mod:`~http.server`.
324With this parameter, the server serves the specified directory, by default it uses the current working directory.
325(Contributed by Stéphane Wirtel and Julien Palard in :issue:`28707`.)
326
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800327locale
328------
329
330Added another argument *monetary* in :meth:`format_string` of :mod:`locale`.
331If *monetary* is true, the conversion uses monetary thousands separator and
332grouping strings. (Contributed by Garvit in :issue:`10379`.)
333
Mark Dickinsona0ce3752017-04-05 18:34:27 +0100334math
335----
336
337New :func:`~math.remainder` function, implementing the IEEE 754-style remainder
338operation. (Contributed by Mark Dickinson in :issue:`29962`.)
339
Serhiy Storchaka8f6b3442017-03-07 14:33:21 +0200340os
341--
342
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800343Added support for :class:`bytes` paths in :func:`~os.fwalk`. (Contributed by
344Serhiy Storchaka in :issue:`28682`.)
Serhiy Storchaka8f6b3442017-03-07 14:33:21 +0200345
Serhiy Storchakaea720fe2017-03-30 09:12:31 +0300346Added support for :ref:`file descriptors <path_fd>` in :func:`~os.scandir`
347on Unix. (Contributed by Serhiy Storchaka in :issue:`25996`.)
348
Antoine Pitrouf7ecfac2017-05-28 11:35:14 +0200349New function :func:`os.register_at_fork` allows registering Python callbacks
350to be executed on a process fork. (Contributed by Antoine Pitrou in
351:issue:`16500`.)
352
Barry Warsaw35425d62017-09-22 12:29:42 -0400353pdb
354---
355
Berker Peksag12d60562017-11-04 15:17:56 +0300356:func:`~pdb.set_trace` now takes an optional *header* keyword-only
Barry Warsaw35425d62017-09-22 12:29:42 -0400357argument. If given, this is printed to the console just before debugging
Berker Peksag12d60562017-11-04 15:17:56 +0300358begins. (Contributed by Barry Warsaw in :issue:`31389`.)
Barry Warsaw35425d62017-09-22 12:29:42 -0400359
Serhiy Storchaka3557b052017-10-24 23:31:42 +0300360re
361--
362
363The flags :const:`re.ASCII`, :const:`re.LOCALE` and :const:`re.UNICODE`
364can be set within the scope of a group.
365(Contributed by Serhiy Storchaka in :issue:`31690`.)
366
Barry Warsaw973b9012017-09-04 17:29:27 -0400367string
368------
369
370:class:`string.Template` now lets you to optionally modify the regular
371expression pattern for braced placeholders and non-braced placeholders
372separately. (Contributed by Barry Warsaw in :issue:`1198569`.)
373
Victor Stinnera64ce972017-11-02 04:19:19 -0700374time
375----
376
Victor Stinnerc29b5852017-11-02 07:28:27 -0700377The :pep:`564` added six new functions with nanosecond resolution:
378
379* :func:`time.clock_gettime_ns`
380* :func:`time.clock_settime_ns`
381* :func:`time.monotonic_ns`
382* :func:`time.perf_counter_ns`
383* :func:`time.process_time_ns`
384* :func:`time.time_ns`
385
Victor Stinnera64ce972017-11-02 04:19:19 -0700386Add new clock identifiers:
387
388* :data:`time.CLOCK_BOOTTIME` (Linux): Identical to
389 :data:`time.CLOCK_MONOTONIC`, except it also includes any time that the
390 system is suspended.
391* :data:`time.CLOCK_PROF` (FreeBSD, NetBSD and OpenBSD): High-resolution
392 per-process timer from the CPU.
393* :data:`time.CLOCK_UPTIME` (FreeBSD, OpenBSD): Time whose absolute value is
394 the time the system has been running and not suspended, providing accurate
395 uptime measurement, both absolute and interval.
396
Antoine Pitrou4bd41c92017-11-15 22:52:21 +0100397Added functions :func:`time.thread_time` and :func:`time.thread_time_ns`
398to get per-thread CPU time measurements.
399(Contributed by Antoine Pitrou in :issue:`32025`.)
400
Jonas Haag4d193bc2017-11-28 20:40:44 +0100401
402unittest
403--------
404Added new command-line option ``-k`` to filter tests to run with a substring or
405Unix shell-like pattern. For example, ``python -m unittest -k foo`` runs the
406tests ``foo_tests.SomeTest.test_something``, ``bar_tests.SomeTest.test_foo``,
407but not ``bar_tests.FooTest.test_something``.
408
409
Serhiy Storchakad9c956f2017-01-11 20:13:03 +0200410unittest.mock
411-------------
412
413The :const:`~unittest.mock.sentinel` attributes now preserve their identity
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800414when they are :mod:`copied <copy>` or :mod:`pickled <pickle>`. (Contributed by
415Serhiy Storchaka in :issue:`20804`.)
Serhiy Storchakad9c956f2017-01-11 20:13:03 +0200416
Mario Corchero552be9d2017-10-17 12:35:11 +0100417New function :const:`~unittest.mock.seal` will disable the creation of mock
418children by preventing to get or set any new attribute on the sealed mock.
419The sealing process is performed recursively. (Contributed by Mario Corchero
420in :issue:`30541`.)
421
Xiang Zhang267b9d22017-02-28 17:12:52 +0800422xmlrpc.server
423-------------
424
425:meth:`register_function` of :class:`xmlrpc.server.SimpleXMLRPCDispatcher` and
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800426its subclasses can be used as a decorator. (Contributed by Xiang Zhang in
427:issue:`7769`.)
Xiang Zhang267b9d22017-02-28 17:12:52 +0800428
Benjamin Peterson279a9622017-06-22 22:31:08 -0700429unicodedata
430-----------
431
432The internal :mod:`unicodedata` database has been upgraded to use `Unicode 10
433<http://www.unicode.org/versions/Unicode10.0.0/>`_. (Contributed by Benjamin
434Peterson.)
435
Ratnadeep Debnath21024f02017-02-25 14:30:28 +0530436urllib.parse
437------------
438
Daniel Himmelsteindadca482017-08-10 21:45:12 -0400439:func:`urllib.parse.quote` has been updated from RFC 2396 to RFC 3986,
Ratnadeep Debnath21024f02017-02-25 14:30:28 +0530440adding `~` to the set of characters that is never quoted by default.
441(Contributed by Christian Theune and Ratnadeep Debnath in :issue:`16285`.)
442
Xiang Zhang13f1f422017-05-03 11:16:21 +0800443uu
444--
445
446Function :func:`~uu.encode` now accepts an optional *backtick*
447keyword argument. When it's true, zeros are represented by ``'`'``
448instead of spaces. (Contributed by Xiang Zhang in :issue:`30103`.)
449
scoder101a5e82017-09-30 15:35:21 +0200450xml.etree
451---------
452
453:ref:`ElementPath <elementtree-xpath>` predicates in the :meth:`find`
454methods can now compare text of the current node with ``[. = "text"]``,
455not only text in children. Predicates also allow adding spaces for
456better readability. (Contributed by Stefan Behnel in :issue:`31648`.)
457
Paul Moore0780bf72017-08-26 18:04:12 +0100458zipapp
459------
460
461Function :func:`zipapp.create_archive` now accepts an optional *filter*
Zhiming Wangd87b1052017-09-29 13:31:52 -0400462argument to allow the user to select which files should be included in the
463archive, and an optional *compressed* argument to generate a compressed
Paul Moore0780bf72017-08-26 18:04:12 +0100464archive.
465
Zhiming Wangd87b1052017-09-29 13:31:52 -0400466A command line option ``--compress`` has also been added to support
467compression.
468
Ned Deily4829bc62016-09-12 17:29:04 -0400469
470Optimizations
471=============
472
Yury Selivanovf2392132016-12-13 19:03:51 -0500473* Added two new opcodes: ``LOAD_METHOD`` and ``CALL_METHOD`` to avoid
474 instantiation of bound method objects for method calls, which results
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800475 in method calls being faster up to 20%. (Contributed by Yury Selivanov and
476 INADA Naoki in :issue:`26110`.)
Yury Selivanovf2392132016-12-13 19:03:51 -0500477
Serhiy Storchaka0a58f722017-03-30 09:11:10 +0300478* Searching some unlucky Unicode characters (like Ukrainian capital "Є")
Cody Scott72fa3012017-11-09 13:58:59 -0500479 in a string was up to 25 times slower than searching other characters.
480 Now it is slower only by 3 times in the worst case.
Serhiy Storchaka0a58f722017-03-30 09:11:10 +0300481 (Contributed by Serhiy Storchaka in :issue:`24821`.)
482
Serhiy Storchaka97553fd2017-03-11 23:37:16 +0200483* Fast implementation from standard C library is now used for functions
Paul Romano992f6132017-09-15 12:00:57 -0500484 :func:`~math.erf` and :func:`~math.erfc` in the :mod:`math` module.
485 (Contributed by Serhiy Storchaka in :issue:`26121`.)
Serhiy Storchaka97553fd2017-03-11 23:37:16 +0200486
Serhiy Storchakaea720fe2017-03-30 09:12:31 +0300487* The :func:`os.fwalk` function has been sped up by 2 times. This was done
488 using the :func:`os.scandir` function.
489 (Contributed by Serhiy Storchaka in :issue:`25996`.)
490
Serhiy Storchakad4d79bc2017-11-04 14:16:35 +0200491* The :func:`shutil.rmtree` function has been sped up to 20--40%.
492 This was done using the :func:`os.scandir` function.
493 (Contributed by Serhiy Storchaka in :issue:`28564`.)
494
Serhiy Storchaka6d336a02017-05-09 23:37:14 +0300495* Optimized case-insensitive matching and searching of :mod:`regular
496 expressions <re>`. Searching some patterns can now be up to 20 times faster.
497 (Contributed by Serhiy Storchaka in :issue:`30285`.)
498
INADA Naokic1c47c12017-10-05 17:19:26 +0900499* :func:`re.compile` now converts ``flags`` parameter to int object if
500 it is ``RegexFlag``. It is now as fast as Python 3.5, and faster than
Cody Scott72fa3012017-11-09 13:58:59 -0500501 Python 3.6 by about 10% depending on the pattern.
INADA Naokic1c47c12017-10-05 17:19:26 +0900502 (Contributed by INADA Naoki in :issue:`31671`.)
503
Giampaolo Rodolafbfaa6f2017-06-09 22:20:41 +0200504* :meth:`selectors.EpollSelector.modify`, :meth:`selectors.PollSelector.modify`
505 and :meth:`selectors.DevpollSelector.modify` may be around 10% faster under
506 heavy loads. (Contributed by Giampaolo Rodola' in :issue:`30014`)
Ned Deily4829bc62016-09-12 17:29:04 -0400507
508Build and C API Changes
509=======================
510
Zachary Waref40d4dd2016-09-17 01:25:24 -0500511* A full copy of libffi is no longer bundled for use when building the
512 :mod:`_ctypes <ctypes>` module on non-OSX UNIX platforms. An installed copy
513 of libffi is now required when building ``_ctypes`` on such platforms.
514 Contributed by Zachary Ware in :issue:`27979`.
Ned Deily4829bc62016-09-12 17:29:04 -0400515
Serhiy Storchaka007d7ff2016-11-22 07:58:08 +0200516* The fields :c:member:`name` and :c:member:`doc` of structures
517 :c:type:`PyMemberDef`, :c:type:`PyGetSetDef`,
518 :c:type:`PyStructSequence_Field`, :c:type:`PyStructSequence_Desc`,
519 and :c:type:`wrapperbase` are now of type ``const char *`` rather of
520 ``char *``. (Contributed by Serhiy Storchaka in :issue:`28761`.)
521
Serhiy Storchaka2a404b62017-01-22 23:07:07 +0200522* The result of :c:func:`PyUnicode_AsUTF8AndSize` and :c:func:`PyUnicode_AsUTF8`
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800523 is now of type ``const char *`` rather of ``char *``. (Contributed by Serhiy
524 Storchaka in :issue:`28769`.)
Serhiy Storchaka2a404b62017-01-22 23:07:07 +0200525
Oren Milman0ccc0f62017-10-08 11:17:46 +0300526* The result of :c:func:`PyMapping_Keys`, :c:func:`PyMapping_Values` and
527 :c:func:`PyMapping_Items` is now always a list, rather than a list or a
528 tuple. (Contributed by Oren Milman in :issue:`28280`.)
529
Serhiy Storchaka6e08baf2017-01-25 13:27:44 +0200530* Added functions :c:func:`PySlice_Unpack` and :c:func:`PySlice_AdjustIndices`.
531 (Contributed by Serhiy Storchaka in :issue:`27867`.)
532
Antoine Pitrouf7ecfac2017-05-28 11:35:14 +0200533* :c:func:`PyOS_AfterFork` is deprecated in favour of the new functions
534 :c:func:`PyOS_BeforeFork`, :c:func:`PyOS_AfterFork_Parent` and
535 :c:func:`PyOS_AfterFork_Child`. (Contributed by Antoine Pitrou in
536 :issue:`16500`.)
537
Zachary Warecb8c0482017-06-15 22:34:59 -0500538* The Windows build process no longer depends on Subversion to pull in external
539 sources, a Python script is used to download zipfiles from GitHub instead.
540 If Python 3.6 is not found on the system (via ``py -3.6``), NuGet is used to
541 download a copy of 32-bit Python for this purpose. (Contributed by Zachary
542 Ware in :issue:`30450`.)
543
xdegaye56d1f5c2017-10-26 15:09:06 +0200544* The ``PyExc_RecursionErrorInst`` singleton that was part of the public API
545 has been removed as its members being never cleared may cause a segfault
546 during finalization of the interpreter. Contributed by Xavier de Gaye in
547 :issue:`22898` and :issue:`30697`.
548
Antoine Pitroua6a4dc82017-09-07 18:56:24 +0200549* Support for building ``--without-threads`` is removed.
550 (Contributed by Antoine Pitrou in :issue:`31370`.).
551
Ned Deily4829bc62016-09-12 17:29:04 -0400552
Nick Coghlan5a851672017-09-08 10:14:16 +1000553Other CPython Implementation Changes
554====================================
555
556* Trace hooks may now opt out of receiving ``line`` events from the interpreter
557 by setting the new ``f_trace_lines`` attribute to :const:`False` on the frame
558 being traced. (Contributed by Nick Coghlan in :issue:`31344`.)
559
560* Trace hooks may now opt in to receiving ``opcode`` events from the interpreter
561 by setting the new ``f_trace_opcodes`` attribute to :const:`True` on the frame
562 being traced. (Contributed by Nick Coghlan in :issue:`31344`.)
563
564
Ned Deily4829bc62016-09-12 17:29:04 -0400565Deprecated
566==========
567
Serhiy Storchaka6e08baf2017-01-25 13:27:44 +0200568- Function :c:func:`PySlice_GetIndicesEx` is deprecated and replaced with
569 a macro if ``Py_LIMITED_API`` is not set or set to the value between
570 ``0x03050400`` and ``0x03060000`` (not including) or ``0x03060100`` or
571 higher. (Contributed by Serhiy Storchaka in :issue:`27867`.)
Ned Deily4829bc62016-09-12 17:29:04 -0400572
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800573- Deprecated :meth:`format` from :mod:`locale`, use the :meth:`format_string`
574 instead. (Contributed by Garvit in :issue:`10379`.)
575
Matthias Bussonnier1d4601c2017-02-15 18:00:32 -0800576- Methods
577 :meth:`MetaPathFinder.find_module() <importlib.abc.MetaPathFinder.find_module>`
578 (replaced by
579 :meth:`MetaPathFinder.find_spec() <importlib.abc.MetaPathFinder.find_spec>`
580 ) and
581 :meth:`PathEntryFinder.find_loader() <importlib.abc.PathEntryFinder.find_loader>`
582 (replaced by
583 :meth:`PathEntryFinder.find_spec() <importlib.abc.PathEntryFinder.find_spec>`)
584 both deprecated in Python 3.4 now emit :exc:`DeprecationWarning`. (Contributed
585 by Matthias Bussonnier in :issue:`29576`)
586
Serhiy Storchakaf6595982017-03-12 13:15:01 +0200587- Using non-integer value for selecting a plural form in :mod:`gettext` is
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800588 now deprecated. It never correctly worked. (Contributed by Serhiy Storchaka
589 in :issue:`28692`.)
Serhiy Storchakaf6595982017-03-12 13:15:01 +0200590
Victor Stinner89a1c932017-05-15 11:01:21 +0200591- The :mod:`macpath` is now deprecated and will be removed in Python 3.8.
592
Ned Deily4829bc62016-09-12 17:29:04 -0400593
Serhiy Storchakaaefa7eb2017-03-23 15:48:39 +0200594Changes in the C API
595--------------------
596
597- The type of results of :c:func:`PyThread_start_new_thread` and
598 :c:func:`PyThread_get_thread_ident`, and the *id* parameter of
599 :c:func:`PyThreadState_SetAsyncExc` changed from :c:type:`long` to
600 :c:type:`unsigned long`.
601 (Contributed by Serhiy Storchaka in :issue:`6532`.)
602
Serhiy Storchakae613e6a2017-06-27 16:03:14 +0300603- :c:func:`PyUnicode_AsWideCharString` now raises a :exc:`ValueError` if the
604 second argument is *NULL* and the :c:type:`wchar_t*` string contains null
605 characters. (Contributed by Serhiy Storchaka in :issue:`30708`.)
606
Serhiy Storchakaaefa7eb2017-03-23 15:48:39 +0200607
Steve (Gadget) Barnes5b8f9722017-06-28 20:14:52 +0100608Windows Only
609------------
610- The python launcher, (py.exe), can accept 32 & 64 bit specifiers **without**
611 having to specify a minor version as well. So ``py -3-32`` and ``py -3-64``
612 become valid as well as ``py -3.7-32``, also the -*m*-64 and -*m.n*-64 forms
613 are now accepted to force 64 bit python even if 32 bit would have otherwise
614 been used. If the specified version is not available py.exe will error exit.
615 (Contributed by Steve Barnes in :issue:`30291`.)
616
617- The launcher can be run as "py -0" to produce a list of the installed pythons,
618 *with default marked with an asterix*. Running "py -0p" will include the paths.
619 If py is run with a version specifier that cannot be matched it will also print
620 the *short form* list of available specifiers.
621 (Contributed by Steve Barnes in :issue:`30362`.)
622
Ned Deily4829bc62016-09-12 17:29:04 -0400623Removed
624=======
625
Serhiy Storchakaff3dbe92016-12-06 19:25:19 +0200626API and Feature Removals
627------------------------
628
Victor Stinner01b5aab2017-10-24 02:02:00 -0700629* The ``os.stat_float_times()`` function has been removed. It was introduced in
630 Python 2.3 for backward compatibility with Python 2.2, and was deprecated
631 since Python 3.1.
632
Serhiy Storchakaff3dbe92016-12-06 19:25:19 +0200633* Unknown escapes consisting of ``'\'`` and an ASCII letter in replacement
Serhiy Storchakab2d61792017-01-13 21:14:40 +0200634 templates for :func:`re.sub` were deprecated in Python 3.5, and will now
635 cause an error.
Ned Deily4829bc62016-09-12 17:29:04 -0400636
Serhiy Storchaka4f76fb12017-01-13 13:25:24 +0200637* Removed support of the *exclude* argument in :meth:`tarfile.TarFile.add`.
Serhiy Storchakab2d61792017-01-13 21:14:40 +0200638 It was deprecated in Python 2.7 and 3.2. Use the *filter* argument instead.
Serhiy Storchaka4f76fb12017-01-13 13:25:24 +0200639
Serhiy Storchaka9ed707e2017-01-13 20:55:05 +0200640* The ``splitunc()`` function in the :mod:`ntpath` module was deprecated in
641 Python 3.1, and has now been removed. Use the :func:`~os.path.splitdrive`
642 function instead.
643
Raymond Hettinger8b57d732017-09-10 10:23:36 -0700644* :func:`collections.namedtuple` no longer supports the *verbose* parameter
645 or ``_source`` attribute which showed the generated source code for the
646 named tuple class. This was part of an optimization designed to speed-up
647 class creation. (Contributed by Jelle Zijlstra with further improvements
648 by INADA Naoki, Serhiy Storchaka, and Raymond Hettinger in :issue:`28638`.)
649
Serhiy Storchaka2e564242017-03-06 17:01:06 +0200650* Functions :func:`bool`, :func:`float`, :func:`list` and :func:`tuple` no
651 longer take keyword arguments. The first argument of :func:`int` can now
Daniel Porteous77f68e32017-06-21 10:21:48 +1000652 be passed only as positional argument.
Serhiy Storchaka2e564242017-03-06 17:01:06 +0200653
Serhiy Storchakaedef3582017-05-15 13:21:31 +0300654* Removed previously deprecated in Python 2.4 classes ``Plist``, ``Dict`` and
655 ``_InternalDict`` in the :mod:`plistlib` module. Dict values in the result
656 of functions :func:`~plistlib.readPlist` and
657 :func:`~plistlib.readPlistFromBytes` are now normal dicts. You no longer
658 can use attribute access to access items of these dictionaries.
659
Ned Deily4829bc62016-09-12 17:29:04 -0400660
661Porting to Python 3.7
662=====================
663
664This section lists previously described changes and other bugfixes
665that may require changes to your code.
666
667
Serhiy Storchaka9165f772017-11-15 08:49:40 +0200668Changes in Python behavior
669--------------------------
670
671* Due to an oversight, earlier Python versions erroneously accepted the
672 following syntax::
673
674 f(1 for x in [1],)
675
Serhiy Storchakaddbce132017-11-15 17:39:37 +0200676 class C(1 for x in [1]):
677 pass
678
Serhiy Storchaka9165f772017-11-15 08:49:40 +0200679 Python 3.7 now correctly raises a :exc:`SyntaxError`, as a generator
680 expression always needs to be directly inside a set of parentheses
Serhiy Storchakaddbce132017-11-15 17:39:37 +0200681 and cannot have a comma on either side, and the duplication of the
682 parentheses can be omitted only on calls.
683 (Contributed by Serhiy Storchaka in :issue:`32012` and :issue:`32023`.)
Serhiy Storchaka9165f772017-11-15 08:49:40 +0200684
685
Serhiy Storchaka009b0a12017-01-13 09:10:51 +0200686Changes in the Python API
687-------------------------
688
Victor Stinnerac577d72017-11-28 21:33:20 +0100689* The ``asyncio.windows_utils.socketpair()`` function has been
690 removed: use directly :func:`socket.socketpair` which is available on all
691 platforms since Python 3.5 (before, it wasn't available on Windows).
692 ``asyncio.windows_utils.socketpair()`` was just an alias to
693 ``socket.socketpair`` on Python 3.5 and newer.
694
Victor Stinner4271dfd2017-11-28 15:19:56 +0100695* :mod:`asyncio`: The module doesn't export :mod:`selectors` and
696 :mod:`_overlapped` modules as ``asyncio.selectors`` and
697 ``asyncio._overlapped``. Replace ``from asyncio import selectors`` with
698 ``import selectors`` for example.
699
Sanyam Khuranab9c3da52017-06-13 22:41:14 +0530700* :meth:`pkgutil.walk_packages` now raises ValueError if *path* is a string.
701 Previously an empty list was returned. (Contributed by Sanyam Khurana in
702 :issue:`24744`.)
703
Serhiy Storchaka009b0a12017-01-13 09:10:51 +0200704* A format string argument for :meth:`string.Formatter.format`
705 is now :ref:`positional-only <positional-only_parameter>`.
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800706 Passing it as a keyword argument was deprecated in Python 3.5. (Contributed
707 by Serhiy Storchaka in :issue:`29193`.)
Serhiy Storchakacc283372017-01-13 09:23:15 +0200708
709* Attributes :attr:`~http.cookies.Morsel.key`,
710 :attr:`~http.cookies.Morsel.value` and
711 :attr:`~http.cookies.Morsel.coded_value` of class
712 :class:`http.cookies.Morsel` are now read-only.
Serhiy Storchakab2d61792017-01-13 21:14:40 +0200713 Assigning to them was deprecated in Python 3.5.
Serhiy Storchakacc283372017-01-13 09:23:15 +0200714 Use the :meth:`~http.cookies.Morsel.set` method for setting them.
715 (Contributed by Serhiy Storchaka in :issue:`29192`.)
INADA Naoki015bce62017-01-16 17:23:30 +0900716
INADA Naokicb41b272017-02-23 00:31:59 +0900717* ``Module``, ``FunctionDef``, ``AsyncFunctionDef``, and
718 ``ClassDef`` AST nodes now have a new ``docstring`` field.
719 The first statement in their body is not considered as a docstring
720 anymore. ``co_firstlineno`` and ``co_lnotab`` of code object for class
Garvit Khatri1cf93a72017-03-28 23:43:38 +0800721 and module are affected by this change. (Contributed by INADA Naoki and
722 Eugene Toder in :issue:`29463`.)
INADA Naoki015bce62017-01-16 17:23:30 +0900723
Serhiy Storchakae304e332017-03-24 13:27:42 +0200724* The *mode* argument of :func:`os.makedirs` no longer affects the file
725 permission bits of newly-created intermediate-level directories.
726 To set their file permission bits you can set the umask before invoking
727 ``makedirs()``.
728 (Contributed by Serhiy Storchaka in :issue:`19930`.)
729
Victor Stinnerf87b85f2017-06-23 15:11:12 +0200730* The :attr:`struct.Struct.format` type is now :class:`str` instead of
731 :class:`bytes`. (Contributed by Victor Stinner in :issue:`21071`.)
732
Segev Finer9f3bdcb2017-06-28 23:51:00 +0300733* Due to internal changes in :mod:`socket` you won't be able to
734 :func:`socket.fromshare` a socket :func:`~socket.socket.share`-ed in older
735 Python versions.
736
Utkarsh Upadhyay8e453182017-07-28 14:42:56 +0200737* ``repr`` for :class:`datetime.timedelta` has changed to include keyword arguments
738 in the output. (Contributed by Utkarsh Upadhyay in :issue:`30302`.)
739
Serhiy Storchakad4d79bc2017-11-04 14:16:35 +0200740* Because :func:`shutil.rmtree` is now implemented using the :func:`os.scandir`
741 function, the user specified handler *onerror* is now called with the first
742 argument ``os.scandir`` instead of ``os.listdir`` when listing the direcory
743 is failed.
744
Serhiy Storchaka05cb7282017-11-16 12:38:26 +0200745* Support of nested sets and set operations in regular expressions as in
746 `Unicode Technical Standard #18`_ might be added in the future. This would
747 change the syntax, so to facilitate this change a :exc:`FutureWarning` will
748 be raised in ambiguous cases for the time being.
749 That include sets starting with a literal ``'['`` or containing literal
750 character sequences ``'--'``, ``'&&'``, ``'~~'``, and ``'||'``. To
751 avoid a warning escape them with a backslash.
752 (Contributed by Serhiy Storchaka in :issue:`30349`.)
753
Jesse-Bakker706e10b2017-11-30 00:05:07 +0100754* :class:`tracemalloc.Traceback` frames are now sorted from oldest to most
755 recent to be more consistent with :mod:`traceback`.
756 (Contributed by Jesse Bakker in :issue:`32121`.)
757
Serhiy Storchaka05cb7282017-11-16 12:38:26 +0200758.. _Unicode Technical Standard #18: https://unicode.org/reports/tr18/
759
Serhiy Storchakae304e332017-03-24 13:27:42 +0200760
Serhiy Storchaka4d3f0842017-10-08 12:53:34 +0300761Changes in the C API
762--------------------
763
764* The function :c:func:`PySlice_GetIndicesEx` is considered not safe for
765 resizable sequences. If the slice indices are not instances of :class:`int`,
766 but objects that implement the :meth:`!__index__` method, the sequence can be
767 resized after passing its length to :c:func:`!PySlice_GetIndicesEx`. This
768 can lead to returning indices out of the length of the sequence. For
769 avoiding possible problems use new functions :c:func:`PySlice_Unpack` and
770 :c:func:`PySlice_AdjustIndices`.
771 (Contributed by Serhiy Storchaka in :issue:`27867`.)
772
773
INADA Naoki015bce62017-01-16 17:23:30 +0900774CPython bytecode changes
775------------------------
776
Martin Panter91a88662017-01-24 00:30:06 +0000777* Added two new opcodes: :opcode:`LOAD_METHOD` and :opcode:`CALL_METHOD`.
INADA Naoki015bce62017-01-16 17:23:30 +0900778 (Contributed by Yury Selivanov and INADA Naoki in :issue:`26110`.)
Julien Palard809d1732017-10-24 11:22:22 +0200779
780
Nick Coghlan1b461312017-11-05 14:58:45 +1000781Other CPython implementation changes
782------------------------------------
783
784* In preparation for potential future changes to the public CPython runtime
785 initialization API (see :pep:`432` for details), CPython's internal startup
786 and configuration management logic has been significantly refactored. While
787 these updates are intended to be entirely transparent to both embedding
788 applications and users of the regular CPython CLI, they're being mentioned
789 here as the refactoring changes the internal order of various operations
790 during interpreter startup, and hence may uncover previously latent defects,
791 either in embedding applications, or in CPython itself.
792 (Contributed by Nick Coghlan and Eric Snow as part of :issue:`22257`.)
793
794
Julien Palard809d1732017-10-24 11:22:22 +0200795Documentation
796=============
797
798.. _whatsnew37-pep545:
799
800PEP 545: Python Documentation Translations
801------------------------------------------
802
803:pep:`545` describes the process to translate Python documentation,
804and two translations have been added:
805
Berker Peksag28ab3ce2017-11-08 16:36:58 +0300806- Japanese: https://docs.python.org/ja/ and associated GitHub
Julien Palard809d1732017-10-24 11:22:22 +0200807 repository: https://github.com/python/python-docs-ja
808
Berker Peksag28ab3ce2017-11-08 16:36:58 +0300809- French: https://docs.python.org/fr/ and associated GitHub
Julien Palard809d1732017-10-24 11:22:22 +0200810 repository: https://github.com/python/python-docs-fr
811
812(Contributed by Julien Palard, Inada Naoki, and Victor Stinner in
Berker Peksag28ab3ce2017-11-08 16:36:58 +0300813:issue:`26546`.)