blob: 07da4047a383a77118098daaf7a6a52821a480a3 [file] [log] [blame]
Ned Deily07a18922018-01-31 18:12:38 -05001****************************
2 What's New In Python 3.8
3****************************
4
Ned Deily07a18922018-01-31 18:12:38 -05005.. Rules for maintenance:
6
7 * Anyone can add text to this document. Do not spend very much time
8 on the wording of your changes, because your text will probably
9 get rewritten to some degree.
10
11 * The maintainer will go through Misc/NEWS periodically and add
12 changes; it's therefore more important to add your changes to
13 Misc/NEWS than to this file.
14
15 * This is not a complete list of every single change; completeness
16 is the purpose of Misc/NEWS. Some changes I consider too small
17 or esoteric to include. If such a change is added to the text,
18 I'll just remove it. (This is another reason you shouldn't spend
19 too much time on writing your addition.)
20
21 * If you want to draw your new text to the attention of the
22 maintainer, add 'XXX' to the beginning of the paragraph or
23 section.
24
25 * It's OK to just add a fragmentary note about a change. For
26 example: "XXX Describe the transmogrify() function added to the
27 socket module." The maintainer will research the change and
28 write the necessary text.
29
30 * You can comment out your additions if you like, but it's not
31 necessary (especially when a final release is some months away).
32
33 * Credit the author of a patch or bugfix. Just the name is
34 sufficient; the e-mail address isn't necessary.
35
36 * It's helpful to add the bug/patch number as a comment:
37
38 XXX Describe the transmogrify() function added to the socket
39 module.
40 (Contributed by P.Y. Developer in :issue:`12345`.)
41
42 This saves the maintainer the effort of going through the Mercurial log
43 when researching a change.
44
45This article explains the new features in Python 3.8, compared to 3.7.
46
Ned Deily45ab51c2018-02-28 13:58:38 -050047For full details, see the :ref:`changelog <changelog>`.
Ned Deily07a18922018-01-31 18:12:38 -050048
49.. note::
50
51 Prerelease users should be aware that this document is currently in draft
52 form. It will be updated substantially as Python 3.8 moves towards release,
53 so it's worth checking back even after reading earlier versions.
54
55
56Summary -- Release highlights
57=============================
58
59.. This section singles out the most important changes in Python 3.8.
60 Brevity is key.
61
62
63.. PEP-sized items next.
64
65
66
67New Features
68============
69
Guido van Rossum09d434c2019-04-24 11:30:17 -070070Assignment expressions
71----------------------
72
73There is new syntax (the "walrus operator", ``:=``) to assign values
74to variables as part of an expression. Example::
75
76 if (n := len(a)) > 10:
77 print(f"List is too long ({n} elements, expected <= 10)")
78
79See :pep:`572` for a full description.
80
81(Contributed by Emily Morehouse in :issue:`35224`.)
82
83.. TODO: Emily will sprint on docs at PyCon US 2019.
84
85
Guido van Rossum843bf422019-04-29 05:49:30 -070086Positional-only parameters
87--------------------------
88
89There is new syntax (``/``) to indicate that some function parameters
90must be specified positionally (i.e., cannot be used as keyword
91arguments). This is the same notation as shown by ``help()`` for
92functions implemented in C (produced by Larry Hastings' "Argument
93Clinic" tool). Example::
94
95 def pow(x, y, z=None, /):
96 r = x**y
97 if z is not None:
98 r %= z
99 return r
100
101Now ``pow(2, 10)`` and ``pow(2, 10, 17)`` are valid calls, but
102``pow(x=2, y=10)`` and ``pow(2, 10, z=17)`` are invalid.
103
104See :pep:`570` for a full description.
105
106(Contributed by Pablo Galindo in :issue:`36540`.)
107
108.. TODO: Pablo will sprint on docs at PyCon US 2019.
109
110
Nick Coghlan16eb3bc2018-06-20 21:25:01 +1000111Parallel filesystem cache for compiled bytecode files
112-----------------------------------------------------
113
114The new :envvar:`PYTHONPYCACHEPREFIX` setting (also available as
115:option:`-X` ``pycache_prefix``) configures the implicit bytecode
116cache to use a separate parallel filesystem tree, rather than
117the default ``__pycache__`` subdirectories within each source
118directory.
119
120The location of the cache is reported in :data:`sys.pycache_prefix`
121(:const:`None` indicates the default location in ``__pycache__``
122subdirectories).
123
124(Contributed by Carl Meyer in :issue:`33499`.)
Ned Deily07a18922018-01-31 18:12:38 -0500125
Victor Stinner40460692019-04-26 17:56:44 +0200126Debug build uses the same ABI as release build
127-----------------------------------------------
128
Paul Ganssle5c403b22019-04-27 14:14:35 -0400129Python now uses the same ABI whether it built in release or debug mode. On
130Unix, when Python is built in debug mode, it is now possible to load C
131extensions built in release mode and C extensions built using the stable ABI.
Victor Stinner40460692019-04-26 17:56:44 +0200132
Paul Ganssle5c403b22019-04-27 14:14:35 -0400133Release builds and debug builds are now ABI compatible: defining the
134``Py_DEBUG`` macro no longer implies the ``Py_TRACE_REFS`` macro, which
135introduces the only ABI incompatibility. The ``Py_TRACE_REFS`` macro, which
136adds the :func:`sys.getobjects` function and the :envvar:`PYTHONDUMPREFS`
137environment variable, can be set using the new ``./configure --with-trace-refs``
138build option.
Victor Stinner40460692019-04-26 17:56:44 +0200139(Contributed by Victor Stinner in :issue:`36465`.)
140
Victor Stinner4ebcd7e2019-05-11 04:10:03 +0200141On Unix, C extensions are no longer linked to libpython except on Android.
142It is now possible
Paul Ganssle5c403b22019-04-27 14:14:35 -0400143for a statically linked Python to load a C extension built using a shared
144library Python.
Victor Stinner40460692019-04-26 17:56:44 +0200145(Contributed by Victor Stinner in :issue:`21536`.)
146
147On Unix, when Python is built in debug mode, import now also looks for C
148extensions compiled in release mode and for C extensions compiled with the
149stable ABI.
150(Contributed by Victor Stinner in :issue:`36722`.)
151
Eric V. Smith9a4135e2019-05-08 16:28:48 -0400152f-strings now support = for quick and easy debugging
153-----------------------------------------------------
154
155Add ``=`` specifier to f-strings. ``f'{expr=}'`` expands
156to the text of the expression, an equal sign, then the repr of the
157evaluated expression. So::
158
159 x = 3
160 print(f'{x*9 + 15=}')
161
162Would print ``x*9 + 15=42``.
163
164(Contributed by Eric V. Smith and Larry Hastings in :issue:`36817`.)
165
Ned Deily07a18922018-01-31 18:12:38 -0500166
167Other Language Changes
168======================
169
Serhiy Storchakafe2bbb12018-03-18 09:56:52 +0200170* A :keyword:`continue` statement was illegal in the :keyword:`finally` clause
171 due to a problem with the implementation. In Python 3.8 this restriction
172 was lifted.
173 (Contributed by Serhiy Storchaka in :issue:`32489`.)
174
Serhiy Storchakab2e20252018-10-20 00:46:31 +0300175* The :class:`int` type now has a new :meth:`~int.as_integer_ratio` method
176 compatible with the existing :meth:`float.as_integer_ratio` method.
Lisa Roach5ac70432018-09-13 23:56:23 -0700177 (Contributed by Lisa Roach in :issue:`33073`.)
178
Serhiy Storchakaa445feb2018-02-10 00:08:17 +0200179* Added support of ``\N{name}`` escapes in :mod:`regular expressions <re>`.
180 (Contributed by Jonathan Eunice and Serhiy Storchaka in :issue:`30688`.)
Ned Deily07a18922018-01-31 18:12:38 -0500181
Rémi Lapeyre6531bf62018-11-06 01:38:54 +0100182* Dict and dictviews are now iterable in reversed insertion order using
183 :func:`reversed`. (Contributed by Rémi Lapeyre in :issue:`33462`.)
184
Benjamin Petersonc9a71dd2018-09-12 17:14:39 -0700185* The syntax allowed for keyword names in function calls was further
186 restricted. In particular, ``f((keyword)=arg)`` is no longer allowed. It was
187 never intended to permit more than a bare name on the left-hand side of a
188 keyword argument assignment term. See :issue:`34641`.
Ned Deily07a18922018-01-31 18:12:38 -0500189
jChapman8fabae32018-09-22 21:13:10 -0400190* Iterable unpacking is now allowed without parentheses in :keyword:`yield`
191 and :keyword:`return` statements.
192 (Contributed by David Cuthbert and Jordan Chapman in :issue:`32117`.)
193
Serhiy Storchaka65439122018-10-19 17:42:06 +0300194* A backslash-character pair that is not a valid escape sequence generates
195 a :exc:`DeprecationWarning` since Python 3.6. In Python 3.8 it generates
196 a :exc:`SyntaxWarning` instead.
197 (Contributed by Serhiy Storchaka in :issue:`32912`.)
198
Serhiy Storchaka62e44812019-02-16 08:12:19 +0200199* The compiler now produces a :exc:`SyntaxWarning` in some cases when a comma
200 is missed before tuple or list. For example::
201
202 data = [
203 (1, 2, 3) # oops, missing comma!
204 (4, 5, 6)
205 ]
206
207 (Contributed by Serhiy Storchaka in :issue:`15248`.)
208
Paul Ganssled9503c32019-02-08 11:02:00 -0500209* Arithmetic operations between subclasses of :class:`datetime.date` or
210 :class:`datetime.datetime` and :class:`datetime.timedelta` objects now return
211 an instance of the subclass, rather than the base class. This also affects
212 the return type of operations whose implementation (directly or indirectly)
213 uses :class:`datetime.timedelta` arithmetic, such as
214 :meth:`datetime.datetime.astimezone`.
215 (Contributed by Paul Ganssle in :issue:`32417`.)
216
Gregory P. Smith06babb22019-02-23 10:43:49 -0800217* When the Python interpreter is interrupted by Ctrl-C (SIGINT) and the
218 resulting :exc:`KeyboardInterrupt` exception is not caught, the Python process
219 now exits via a SIGINT signal or with the correct exit code such that the
220 calling process can detect that it died due to a Ctrl-C. Shells on POSIX
221 and Windows use this to properly terminate scripts in interactive sessions.
222 (Contributed by Google via Gregory P. Smith in :issue:`1054041`.)
223
Serhiy Storchaka65439122018-10-19 17:42:06 +0300224
Ned Deily07a18922018-01-31 18:12:38 -0500225New Modules
226===========
227
228* None yet.
229
230
231Improved Modules
232================
233
Raymond Hettinger0bb4bdf2019-01-31 00:59:50 -0800234
Victor Stinner6ea29c52018-09-25 08:27:08 -0700235asyncio
236-------
237
238On Windows, the default event loop is now :class:`~asyncio.ProactorEventLoop`.
239
Terry Jan Reedyfdcb5ae2018-09-25 12:45:27 -0400240
Raymond Hettinger482b6b52019-05-01 17:48:13 -0700241collections
242-----------
243
244The :meth:`_asdict()` method for :func:`collections.namedtuple` now returns
Daniel Porteous05222912019-05-02 04:20:59 -0400245a :class:`dict` instead of a :class:`collections.OrderedDict`. This works because
246regular dicts have guaranteed ordering since Python 3.7. If the extra
Raymond Hettinger482b6b52019-05-01 17:48:13 -0700247features of :class:`OrderedDict` are required, the suggested remediation is
248to cast the result to the desired type: ``OrderedDict(nt._asdict())``.
249(Contributed by Raymond Hettinger in :issue:`35864`.)
250
251
Steve Dower2438cdf2019-03-29 16:37:16 -0700252ctypes
253------
254
255On Windows, :class:`~ctypes.CDLL` and subclasses now accept a *winmode* parameter
256to specify flags for the underlying ``LoadLibraryEx`` call. The default flags are
257set to only load DLL dependencies from trusted locations, including the path
258where the DLL is stored (if a full or partial path is used to load the initial
259DLL) and paths added by :func:`~os.add_dll_directory`.
260
261
Paul Ganssle88c09372019-04-29 09:22:03 -0400262datetime
263--------
264
265Added new alternate constructors :meth:`datetime.date.fromisocalendar` and
266:meth:`datetime.datetime.fromisocalendar`, which construct :class:`date` and
267:class:`datetime` objects respectively from ISO year, week number and weekday;
268these are the inverse of each class's ``isocalendar`` method.
269(Contributed by Paul Ganssle in :issue:`36004`.)
270
271
Cheryl Sabella637a33b2018-11-07 09:12:20 -0500272gettext
273-------
274
275Added :func:`~gettext.pgettext` and its variants.
276(Contributed by Franz Glasner, Éric Araujo, and Cheryl Sabella in :issue:`2504`.)
277
Raymond Hettingerd1e768a2019-03-25 13:01:13 -0700278inspect
279-------
280
281The :func:`inspect.getdoc` function can now find docstrings for ``__slots__``
282if that attribute is a :class:`dict` where the values are docstrings.
283This provides documentation options similar to what we already have
284for :func:`property`, :func:`classmethod`, and :func:`staticmethod`::
285
286 class AudioClip:
287 __slots__ = {'bit_rate': 'expressed in kilohertz to one decimal place',
288 'duration': 'in seconds, rounded up to an integer'}
289 def __init__(self, bit_rate, duration):
290 self.bit_rate = round(bit_rate / 1000.0, 1)
291 self.duration = ceil(duration)
Pablo Galindo175421b2019-02-23 03:02:06 +0000292
293gc
294--
295
296:func:`~gc.get_objects` can now receive an optional *generation* parameter
297indicating a generation to get objects from. Contributed in
298:issue:`36016` by Pablo Galindo.
299
300
guoci0e7497c2018-11-07 04:50:23 -0500301gzip
302----
303
304Added the *mtime* parameter to :func:`gzip.compress` for reproducible output.
305(Contributed by Guo Ci Teo in :issue:`34898`.)
306
Zackery Spytzcf599f62019-05-13 01:50:52 -0600307A :exc:`~gzip.BadGzipFile` exception is now raised instead of :exc:`OSError`
308for certain types of invalid or corrupt gzip files.
309(Contributed by Filip Gruszczyński, Michele Orrù, and Zackery Spytz in
310:issue:`6584`.)
311
guoci0e7497c2018-11-07 04:50:23 -0500312
Terry Jan Reedyfdcb5ae2018-09-25 12:45:27 -0400313idlelib and IDLE
314----------------
315
316Output over N lines (50 by default) is squeezed down to a button.
317N can be changed in the PyShell section of the General page of the
318Settings dialog. Fewer, but possibly extra long, lines can be squeezed by
319right clicking on the output. Squeezed output can be expanded in place
320by double-clicking the button or into the clipboard or a separate window
321by right-clicking the button. (Contributed by Tal Einat in :issue:`1529353`.)
322
323The changes above have been backported to 3.7 maintenance releases.
324
325
HongWeipengf1944792018-11-07 18:09:32 +0800326json.tool
327---------
328
329Add option ``--json-lines`` to parse every input line as separate JSON object.
330(Contributed by Weipeng Hong in :issue:`31553`.)
331
Pablo Galindobc098512019-02-07 07:04:02 +0000332
333math
334----
335
Raymond Hettinger3ff59622019-02-16 11:00:42 -0800336Added new function :func:`math.dist` for computing Euclidean distance
337between two points. (Contributed by Raymond Hettinger in :issue:`33089`.)
338
339Expanded the :func:`math.hypot` function to handle multiple dimensions.
340Formerly, it only supported the 2-D case.
341(Contributed by Raymond Hettinger in :issue:`33089`.)
342
Pablo Galindobc098512019-02-07 07:04:02 +0000343Added new function, :func:`math.prod`, as analogous function to :func:`sum`
344that returns the product of a 'start' value (default: 1) times an iterable of
Raymond Hettinger3ff59622019-02-16 11:00:42 -0800345numbers. (Contributed by Pablo Galindo in :issue:`35606`)
Pablo Galindobc098512019-02-07 07:04:02 +0000346
Mark Dickinson73934b92019-05-18 12:29:50 +0100347Added new function :func:`math.isqrt` for computing integer square roots.
348(Contributed by Mark Dickinson in :issue:`36887`.)
349
Steve Dower2438cdf2019-03-29 16:37:16 -0700350os
351--
352
353Added new function :func:`~os.add_dll_directory` on Windows for providing
354additional search paths for native dependencies when importing extension
355modules or loading DLLs using :mod:`ctypes`.
356
Pablo Galindobc098512019-02-07 07:04:02 +0000357
Serhiy Storchaka0185f342018-09-18 11:28:51 +0300358os.path
359-------
360
361:mod:`os.path` functions that return a boolean result like
362:func:`~os.path.exists`, :func:`~os.path.lexists`, :func:`~os.path.isdir`,
363:func:`~os.path.isfile`, :func:`~os.path.islink`, and :func:`~os.path.ismount`
364now return ``False`` instead of raising :exc:`ValueError` or its subclasses
365:exc:`UnicodeEncodeError` and :exc:`UnicodeDecodeError` for paths that contain
366characters or bytes unrepresentable at the OS level.
367(Contributed by Serhiy Storchaka in :issue:`33721`.)
368
Steve Dower8ef864d2019-03-12 15:15:26 -0700369:func:`~os.path.expanduser` on Windows now prefers the :envvar:`USERPROFILE`
370environment variable and does not use :envvar:`HOME`, which is not normally set
371for regular user accounts.
372
Serhiy Storchakab232df92018-10-30 13:22:42 +0200373
374ncurses
375-------
376
377Added a new variable holding structured version information for the
378underlying ncurses library: :data:`~curses.ncurses_version`.
379(Contributed by Serhiy Storchaka in :issue:`31680`.)
380
381
Serhiy Storchaka0185f342018-09-18 11:28:51 +0300382pathlib
383-------
384
385:mod:`pathlib.Path` methods that return a boolean result like
386:meth:`~pathlib.Path.exists()`, :meth:`~pathlib.Path.is_dir()`,
387:meth:`~pathlib.Path.is_file()`, :meth:`~pathlib.Path.is_mount()`,
388:meth:`~pathlib.Path.is_symlink()`, :meth:`~pathlib.Path.is_block_device()`,
389:meth:`~pathlib.Path.is_char_device()`, :meth:`~pathlib.Path.is_fifo()`,
390:meth:`~pathlib.Path.is_socket()` now return ``False`` instead of raising
391:exc:`ValueError` or its subclass :exc:`UnicodeEncodeError` for paths that
392contain characters unrepresentable at the OS level.
393(Contributed by Serhiy Storchaka in :issue:`33721`.)
394
Joannah Nanjekye6b5b0132019-05-04 11:27:10 -0400395Added :meth:`pathlib.Path.link_to()` which creates a hard link pointing
396to a path.
397(Contributed by Joannah Nanjekye in :issue:`26978`)
398
jab9e00d9e2018-12-28 13:03:40 -0500399
Jon Janzenc981ad12019-05-15 22:14:38 +0200400plistlib
401--------
402
403Added new :class:`plistlib.UID` and enabled support for reading and writing
404NSKeyedArchiver-encoded binary plists.
405(Contributed by Jon Janzen in :issue:`26707`.)
406
407
Giampaolo Rodolaeb7e29f2019-04-09 00:34:02 +0200408socket
409------
410
411Added :meth:`~socket.create_server()` and :meth:`~socket.has_dualstack_ipv6()`
412convenience functions to automate the necessary tasks usually involved when
413creating a server socket, including accepting both IPv4 and IPv6 connections
414on the same socket. (Contributed by Giampaolo Rodola in :issue:`17561`.)
415
416
jab9e00d9e2018-12-28 13:03:40 -0500417shutil
418------
419
420:func:`shutil.copytree` now accepts a new ``dirs_exist_ok`` keyword argument.
421(Contributed by Josh Bronson in :issue:`20849`.)
422
CAM Gerlach89a89442019-04-06 23:47:49 -0500423:func:`shutil.make_archive` now defaults to the modern pax (POSIX.1-2001)
424format for new archives to improve portability and standards conformance,
425inherited from the corresponding change to the :mod:`tarfile` module.
426(Contributed by C.A.M. Gerlach in :issue:`30661`.)
427
jab9e00d9e2018-12-28 13:03:40 -0500428
Christian Heimes9fb051f2018-09-23 08:32:31 +0200429ssl
430---
431
432Added :attr:`SSLContext.post_handshake_auth` to enable and
433:meth:`ssl.SSLSocket.verify_client_post_handshake` to initiate TLS 1.3
434post-handshake authentication.
435(Contributed by Christian Heimes in :issue:`34670`.)
436
Raymond Hettinger47d99872019-02-21 15:06:29 -0800437
438statistics
439----------
440
441Added :func:`statistics.fmean` as a faster, floating point variant of
442:func:`statistics.mean()`. (Contributed by Raymond Hettinger and
443Steven D'Aprano in :issue:`35904`.)
444
Raymond Hettinger6463ba32019-04-07 09:20:03 -0700445Added :func:`statistics.geometric_mean()`
446(Contributed by Raymond Hettinger in :issue:`27181`.)
447
Raymond Hettingerfc06a192019-03-12 00:43:27 -0700448Added :func:`statistics.multimode` that returns a list of the most
449common values. (Contributed by Raymond Hettinger in :issue:`35892`.)
450
Raymond Hettinger9013ccf2019-04-23 00:06:35 -0700451Added :func:`statistics.quantiles` that divides data or a distribution
452in to equiprobable intervals (e.g. quartiles, deciles, or percentiles).
453(Contributed by Raymond Hettinger in :issue:`36546`.)
454
Raymond Hettinger11c79532019-02-23 14:44:07 -0800455Added :class:`statistics.NormalDist`, a tool for creating
456and manipulating normal distributions of a random variable.
457(Contributed by Raymond Hettinger in :issue:`36018`.)
458
459::
460
461 >>> temperature_feb = NormalDist.from_samples([4, 12, -3, 2, 7, 14])
Raymond Hettinger671d7822019-05-01 17:49:12 -0700462 >>> temperature_feb.mean
463 6.0
464 >>> temperature_feb.stdev
465 6.356099432828281
Raymond Hettinger11c79532019-02-23 14:44:07 -0800466
467 >>> temperature_feb.cdf(3) # Chance of being under 3 degrees
468 0.3184678262814532
469 >>> # Relative chance of being 7 degrees versus 10 degrees
470 >>> temperature_feb.pdf(7) / temperature_feb.pdf(10)
471 1.2039930378537762
472
Raymond Hettinger671d7822019-05-01 17:49:12 -0700473 >>> el_niño = NormalDist(4, 2.5)
474 >>> temperature_feb += el_niño # Add in a climate effect
Raymond Hettinger11c79532019-02-23 14:44:07 -0800475 >>> temperature_feb
476 NormalDist(mu=10.0, sigma=6.830080526611674)
477
478 >>> temperature_feb * (9/5) + 32 # Convert to Fahrenheit
479 NormalDist(mu=50.0, sigma=12.294144947901014)
480 >>> temperature_feb.samples(3) # Generate random samples
481 [7.672102882379219, 12.000027119750287, 4.647488369766392]
482
Raymond Hettinger47d99872019-02-21 15:06:29 -0800483
CAM Gerlache680c3d2019-03-21 09:44:51 -0500484tarfile
485-------
486
487The :mod:`tarfile` module now defaults to the modern pax (POSIX.1-2001)
488format for new archives, instead of the previous GNU-specific one.
489This improves cross-platform portability with a consistent encoding (UTF-8)
490in a standardized and extensible format, and offers several other benefits.
491(Contributed by C.A.M. Gerlach in :issue:`36268`.)
492
493
Tal Einatdfba1f62018-10-24 10:20:05 +0300494tokenize
495--------
496
497The :mod:`tokenize` module now implicitly emits a ``NEWLINE`` token when
498provided with input that does not have a trailing new line. This behavior
499now matches what the C tokenizer does internally.
500(Contributed by Ammar Askar in :issue:`33899`.)
501
Juliette Monselaf5658a2018-10-08 18:29:24 +0200502tkinter
503-------
504
505Added methods :meth:`~tkinter.Spinbox.selection_from`,
506:meth:`~tkinter.Spinbox.selection_present`,
507:meth:`~tkinter.Spinbox.selection_range` and
508:meth:`~tkinter.Spinbox.selection_to`
509in the :class:`tkinter.Spinbox` class.
510(Contributed by Juliette Monsel in :issue:`34829`.)
511
Juliette Monselbf034712018-10-12 18:44:10 +0200512Added method :meth:`~tkinter.Canvas.moveto`
513in the :class:`tkinter.Canvas` class.
514(Contributed by Juliette Monsel in :issue:`23831`.)
515
Zackery Spytz50866e92019-04-05 04:17:13 -0600516The :class:`tkinter.PhotoImage` class now has
517:meth:`~tkinter.PhotoImage.transparency_get` and
518:meth:`~tkinter.PhotoImage.transparency_set` methods. (Contributed by
519Zackery Spytz in :issue:`25451`.)
520
Joannah Nanjekye572168a2019-01-10 19:56:38 +0300521time
522----
523
524Added new clock :data:`~time.CLOCK_UPTIME_RAW` for macOS 10.12.
525(Contributed by Joannah Nanjekye in :issue:`35702`.)
526
Max Bélanger2810dd72018-11-04 15:58:24 -0800527unicodedata
528-----------
529
Benjamin Peterson3aca40d2019-05-08 20:59:35 -0700530* The :mod:`unicodedata` module has been upgraded to use the `Unicode 12.1.0
531 <http://blog.unicode.org/2019/05/unicode-12-1-en.html>`_ release.
Raymond Hettinger482b6b52019-05-01 17:48:13 -0700532
Max Bélanger2810dd72018-11-04 15:58:24 -0800533* New function :func:`~unicodedata.is_normalized` can be used to verify a string
534 is in a specific normal form. (Contributed by Max Belanger and David Euresti in
535 :issue:`32285`).
536
Raymond Hettinger482b6b52019-05-01 17:48:13 -0700537
Lisa Roach0f221d02018-11-08 18:34:33 -0800538unittest
539--------
540
541* Added :func:`~unittest.addModuleCleanup()` and
542 :meth:`~unittest.TestCase.addClassCleanup()` to unittest to support
543 cleanups for :func:`~unittest.setUpModule()` and
544 :meth:`~unittest.TestCase.setUpClass()`.
545 (Contributed by Lisa Roach in :issue:`24412`.)
546
Brett Cannond64ee1a2018-09-21 15:27:26 -0700547venv
548----
549
550* :mod:`venv` now includes an ``Activate.ps1`` script on all platforms for
551 activating virtual environments under PowerShell Core 6.1.
552 (Contributed by Brett Cannon in :issue:`32718`.)
553
Mark Dickinson7abb6c02019-04-26 15:56:15 +0900554weakref
555-------
556
557* The proxy objects returned by :func:`weakref.proxy` now support the matrix
558 multiplication operators ``@`` and ``@=`` in addition to the other
559 numeric operators. (Contributed by Mark Dickinson in :issue:`36669`.)
560
Christian Heimes17b1d5d2018-09-23 09:50:25 +0200561xml
562---
563
564* As mitigation against DTD and external entity retrieval, the
Andrés Delfinoca682612018-11-07 14:29:14 -0300565 :mod:`xml.dom.minidom` and :mod:`xml.sax` modules no longer process
Christian Heimes17b1d5d2018-09-23 09:50:25 +0200566 external entities by default.
567 (Contributed by Christian Heimes in :issue:`17239`.)
568
Stefan Behnel47541682019-05-03 20:58:16 +0200569* The ``.find*()`` methods in the :mod:`xml.etree.ElementTree` module
570 support wildcard searches like ``{*}tag`` which ignores the namespace
571 and ``{namespace}*`` which returns all tags in the given namespace.
572 (Contributed by Stefan Behnel in :issue:`28238`.)
573
Stefan Behnele1d5dd62019-05-01 22:34:13 +0200574* The :mod:`xml.etree.ElementTree` module provides a new function
575 :func:`–xml.etree.ElementTree.canonicalize()` that implements C14N 2.0.
576 (Contributed by Stefan Behnel in :issue:`13611`.)
577
Stefan Behnele9a465f2019-05-10 10:25:13 +0200578* The target object of :class:`xml.etree.ElementTree.XMLParser` can
579 receive namespace declaration events through the new callback methods
580 ``start_ns()`` and ``end_ns()``. Additionally, the
581 :class:`xml.etree.ElementTree.TreeBuilder` target can be configured
582 to process events about comments and processing instructions to include
583 them in the generated tree.
584 (Contributed by Stefan Behnel in :issue:`36676` and :issue:`36673`.)
Christian Heimes17b1d5d2018-09-23 09:50:25 +0200585
Ned Deily07a18922018-01-31 18:12:38 -0500586Optimizations
587=============
588
Victor Stinner9daecf32019-01-16 00:02:35 +0100589* The :mod:`subprocess` module can now use the :func:`os.posix_spawn` function
590 in some cases for better performance. Currently, it is only used on macOS
591 and Linux (using glibc 2.24 or newer) if all these conditions are met:
592
593 * *close_fds* is false;
Victor Stinnerf6243ac2019-01-23 19:00:39 +0100594 * *preexec_fn*, *pass_fds*, *cwd* and *start_new_session* parameters
595 are not set;
Victor Stinner8c349562019-01-16 23:38:06 +0100596 * the *executable* path contains a directory.
Victor Stinner9daecf32019-01-16 00:02:35 +0100597
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +0200598* :func:`shutil.copyfile`, :func:`shutil.copy`, :func:`shutil.copy2`,
599 :func:`shutil.copytree` and :func:`shutil.move` use platform-specific
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -0700600 "fast-copy" syscalls on Linux, macOS and Solaris in order to copy the file
601 more efficiently.
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +0200602 "fast-copy" means that the copying operation occurs within the kernel,
603 avoiding the use of userspace buffers in Python as in
604 "``outfd.write(infd.read())``".
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -0700605 On Windows :func:`shutil.copyfile` uses a bigger default buffer size (1 MiB
606 instead of 16 KiB) and a :func:`memoryview`-based variant of
607 :func:`shutil.copyfileobj` is used.
608 The speedup for copying a 512 MiB file within the same partition is about
609 +26% on Linux, +50% on macOS and +40% on Windows. Also, much less CPU cycles
610 are consumed.
611 See :ref:`shutil-platform-dependent-efficient-copy-operations` section.
Mariatta16501b72018-12-06 21:59:42 -0800612 (Contributed by Giampaolo Rodola' in :issue:`33671`.)
Giampaolo Rodola4a172cc2018-06-12 23:04:50 +0200613
Giampaolo Rodola19c46a42018-11-12 06:18:15 -0800614* :func:`shutil.copytree` uses :func:`os.scandir` function and all copy
615 functions depending from it use cached :func:`os.stat` values. The speedup
616 for copying a directory with 8000 files is around +9% on Linux, +20% on
617 Windows and +30% on a Windows SMB share. Also the number of :func:`os.stat`
618 syscalls is reduced by 38% making :func:`shutil.copytree` especially faster
619 on network filesystems. (Contributed by Giampaolo Rodola' in :issue:`33695`.)
620
Łukasz Langac51d8c92018-04-03 23:06:53 -0700621* The default protocol in the :mod:`pickle` module is now Protocol 4,
622 first introduced in Python 3.4. It offers better performance and smaller
623 size compared to Protocol 3 available since Python 3.0.
Ned Deily07a18922018-01-31 18:12:38 -0500624
INADA Naokid5c875b2018-07-11 17:42:49 +0900625* Removed one ``Py_ssize_t`` member from ``PyGC_Head``. All GC tracked
626 objects (e.g. tuple, list, dict) size is reduced 4 or 8 bytes.
627 (Contributed by Inada Naoki in :issue:`33597`)
628
Tal Einat54752532018-09-10 16:11:04 +0300629* :class:`uuid.UUID` now uses ``__slots__`` to reduce its memory footprint.
Tal Einat54752532018-09-10 16:11:04 +0300630
Raymond Hettinger63fa1cf2019-02-16 12:02:22 -0800631* Improved performance of :func:`operator.itemgetter` by 33%. Optimized
632 argument handling and added a fast path for the common case of a single
633 non-negative integer index into a tuple (which is the typical use case in
634 the standard library). (Contributed by Raymond Hettinger in
635 :issue:`35664`.)
636
637* Sped-up field lookups in :func:`collections.namedtuple`. They are now more
638 than two times faster, making them the fastest form of instance variable
639 lookup in Python. (Contributed by Raymond Hettinger, Pablo Galindo, and
Joe Jevnikf36f8922019-02-21 16:00:40 -0500640 Joe Jevnik, Serhiy Storchaka in :issue:`32492`.)
Raymond Hettinger63fa1cf2019-02-16 12:02:22 -0800641
Pablo Galindoc61e2292018-10-28 22:03:18 +0000642* The :class:`list` constructor does not overallocate the internal item buffer
643 if the input iterable has a known length (the input implements ``__len__``).
Raymond Hettingere1823182019-02-16 12:47:48 -0800644 This makes the created list 12% smaller on average. (Contributed by
645 Raymond Hettinger and Pablo Galindo in :issue:`33234`.)
Pablo Galindoc61e2292018-10-28 22:03:18 +0000646
Stefan Behneld8b9e1f2019-02-20 18:29:24 +0100647* Doubled the speed of class variable writes. When a non-dunder attribute
648 was updated, there was an unnecessary call to update slots.
649 (Contributed by Stefan Behnel, Pablo Galindo Salgado, Raymond Hettinger,
650 Neil Schemenauer, and Serhiy Storchaka in :issue:`36012`.)
651
Serhiy Storchaka31913912019-03-14 10:32:22 +0200652* Reduced an overhead of converting arguments passed to many builtin functions
653 and methods. This sped up calling some simple builtin functions and
654 methods up to 20--50%. (Contributed by Serhiy Storchaka in :issue:`23867`,
655 :issue:`35582` and :issue:`36127`.)
656
Serhiy Storchakaceeef102018-06-15 11:09:43 +0300657
Ned Deily07a18922018-01-31 18:12:38 -0500658Build and C API Changes
659=======================
660
Victor Stinnerbf4ac2d2019-01-22 17:39:03 +0100661* The :c:func:`PyByteArray_Init` and :c:func:`PyByteArray_Fini` functions have
662 been removed. They did nothing since Python 2.7.4 and Python 3.2.0, were
663 excluded from the limited API (stable ABI), and were not documented.
664
Serhiy Storchakaceeef102018-06-15 11:09:43 +0300665* The result of :c:func:`PyExceptionClass_Name` is now of type
666 ``const char *`` rather of ``char *``.
667 (Contributed by Serhiy Storchaka in :issue:`33818`.)
Ned Deily07a18922018-01-31 18:12:38 -0500668
Antoine Pitrou961d54c2018-07-16 19:03:03 +0200669* The duality of ``Modules/Setup.dist`` and ``Modules/Setup`` has been
670 removed. Previously, when updating the CPython source tree, one had
671 to manually copy ``Modules/Setup.dist`` (inside the source tree) to
672 ``Modules/Setup`` (inside the build tree) in order to reflect any changes
673 upstream. This was of a small benefit to packagers at the expense of
674 a frequent annoyance to developers following CPython development, as
675 forgetting to copy the file could produce build failures.
676
677 Now the build system always reads from ``Modules/Setup`` inside the source
678 tree. People who want to customize that file are encouraged to maintain
679 their changes in a git fork of CPython or as patch files, as they would do
680 for any other change to the source tree.
681
682 (Contributed by Antoine Pitrou in :issue:`32430`.)
683
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200684* Functions that convert Python number to C integer like
685 :c:func:`PyLong_AsLong` and argument parsing functions like
686 :c:func:`PyArg_ParseTuple` with integer converting format units like ``'i'``
687 will now use the :meth:`~object.__index__` special method instead of
688 :meth:`~object.__int__`, if available. The deprecation warning will be
689 emitted for objects with the ``__int__()`` method but without the
690 ``__index__()`` method (like :class:`~decimal.Decimal` and
691 :class:`~fractions.Fraction`). :c:func:`PyNumber_Check` will now return
692 ``1`` for objects implementing ``__index__()``.
693 (Contributed by Serhiy Storchaka in :issue:`36048`.)
694
Eddie Elizondo364f0b02019-03-27 07:52:18 -0400695* Heap-allocated type objects will now increase their reference count
696 in :c:func:`PyObject_Init` (and its parallel macro ``PyObject_INIT``)
697 instead of in :c:func:`PyType_GenericAlloc`. Types that modify instance
698 allocation or deallocation may need to be adjusted.
699 (Contributed by Eddie Elizondo in :issue:`35810`.)
700
Ned Deily07a18922018-01-31 18:12:38 -0500701
702Deprecated
703==========
704
Serhiy Storchaka02ec92f2018-07-24 12:03:34 +0300705* Deprecated methods ``getchildren()`` and ``getiterator()`` in
706 the :mod:`~xml.etree.ElementTree` module emit now a
707 :exc:`DeprecationWarning` instead of :exc:`PendingDeprecationWarning`.
708 They will be removed in Python 3.9.
709 (Contributed by Serhiy Storchaka in :issue:`29209`.)
Ned Deily07a18922018-01-31 18:12:38 -0500710
Elvis Pranskevichus22d25082018-07-30 11:42:43 +0100711* Passing an object that is not an instance of
712 :class:`concurrent.futures.ThreadPoolExecutor` to
Yury Selivanov7c7605f2018-09-11 09:54:40 -0700713 :meth:`asyncio.loop.set_default_executor()` is
Elvis Pranskevichus22d25082018-07-30 11:42:43 +0100714 deprecated and will be prohibited in Python 3.9.
715 (Contributed by Elvis Pranskevichus in :issue:`34075`.)
716
Berker Peksagef8861c2018-08-21 17:58:49 +0300717* The :meth:`__getitem__` methods of :class:`xml.dom.pulldom.DOMEventStream`,
718 :class:`wsgiref.util.FileWrapper` and :class:`fileinput.FileInput` have been
719 deprecated.
720
721 Implementations of these methods have been ignoring their *index* parameter,
722 and returning the next item instead.
723
724 (Contributed by Berker Peksag in :issue:`9372`.)
725
Raymond Hettingerf7b57df2019-03-18 09:53:56 -0700726* The :class:`typing.NamedTuple` class has deprecated the ``_field_types``
727 attribute in favor of the ``__annotations__`` attribute which has the same
728 information. (Contributed by Raymond Hettinger in :issue:`36320`.)
729
Serhiy Storchaka3f228112018-09-27 17:42:37 +0300730* :mod:`ast` classes ``Num``, ``Str``, ``Bytes``, ``NameConstant`` and
731 ``Ellipsis`` are considered deprecated and will be removed in future Python
732 versions. :class:`~ast.Constant` should be used instead.
733 (Contributed by Serhiy Storchaka in :issue:`32892`.)
734
Serhiy Storchakafec35c92018-10-27 08:00:41 +0300735* The following functions and methods are deprecated in the :mod:`gettext`
736 module: :func:`~gettext.lgettext`, :func:`~gettext.ldgettext`,
737 :func:`~gettext.lngettext` and :func:`~gettext.ldngettext`.
738 They return encoded bytes, and it's possible that you will get unexpected
739 Unicode-related exceptions if there are encoding problems with the
740 translated strings. It's much better to use alternatives which return
741 Unicode strings in Python 3. These functions have been broken for a long time.
742
743 Function :func:`~gettext.bind_textdomain_codeset`, methods
744 :meth:`~gettext.NullTranslations.output_charset` and
745 :meth:`~gettext.NullTranslations.set_output_charset`, and the *codeset*
746 parameter of functions :func:`~gettext.translation` and
747 :func:`~gettext.install` are also deprecated, since they are only used for
748 for the ``l*gettext()`` functions.
749
750 (Contributed by Serhiy Storchaka in :issue:`33710`.)
751
Dong-hee Na89669ff2019-01-17 21:14:45 +0900752* The :meth:`~threading.Thread.isAlive()` method of :class:`threading.Thread` has been deprecated.
753 (Contributed by Dong-hee Na in :issue:`35283`.)
Ned Deily07a18922018-01-31 18:12:38 -0500754
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200755* Many builtin and extension functions that take integer arguments will
756 now emit a deprecation warning for :class:`~decimal.Decimal`\ s,
757 :class:`~fractions.Fraction`\ s and any other objects that can be converted
758 to integers only with a loss (e.g. that have the :meth:`~object.__int__`
759 method but do not have the :meth:`~object.__index__` method). In future
760 version they will be errors.
761 (Contributed by Serhiy Storchaka in :issue:`36048`.)
762
Serhiy Storchaka42a139e2019-04-01 09:16:35 +0300763* Deprecated passing the following arguments as keyword arguments:
764
765 - *func* in :func:`functools.partialmethod`, :func:`weakref.finalize`,
766 :meth:`profile.Profile.runcall`, :meth:`cProfile.Profile.runcall`,
767 :meth:`bdb.Bdb.runcall`, :meth:`trace.Trace.runfunc` and
768 :func:`curses.wrapper`.
769 - *function* in :func:`unittest.addModuleCleanup` and
770 :meth:`unittest.TestCase.addCleanup`.
771 - *fn* in the :meth:`~concurrent.futures.Executor.submit` method of
772 :class:`concurrent.futures.ThreadPoolExecutor` and
773 :class:`concurrent.futures.ProcessPoolExecutor`.
774 - *callback* in :meth:`contextlib.ExitStack.callback`,
775 :meth:`contextlib.AsyncExitStack.callback` and
776 :meth:`contextlib.AsyncExitStack.push_async_callback`.
777 - *c* and *typeid* in the :meth:`~multiprocessing.managers.Server.create`
778 method of :class:`multiprocessing.managers.Server` and
779 :class:`multiprocessing.managers.SharedMemoryServer`.
780 - *obj* in :func:`weakref.finalize`.
781
782 In future releases of Python they will be :ref:`positional-only
783 <positional-only_parameter>`.
784 (Contributed by Serhiy Storchaka in :issue:`36492`.)
785
Serhiy Storchaka6a44f6e2019-02-25 17:57:58 +0200786
Victor Stinner73104fa2018-11-29 09:58:20 +0100787API and Feature Removals
788========================
789
790The following features and APIs have been removed from Python 3.8:
791
Victor Stinnerd7538dd2018-12-14 13:37:26 +0100792* The :mod:`macpath` module, deprecated in Python 3.7, has been removed.
793 (Contributed by Victor Stinner in :issue:`35471`.)
794
Victor Stinner73104fa2018-11-29 09:58:20 +0100795* The function :func:`platform.popen` has been removed, it was deprecated since
796 Python 3.3: use :func:`os.popen` instead.
Ned Deily07a18922018-01-31 18:12:38 -0500797
Matthias Bussonnierb6a09ae2019-05-13 12:23:07 -0700798* The function :func:`time.clock` has been removed, it was deprecated since Python
799 3.3: use :func:`time.perf_counter` or :func:`time.process_time` instead, depending
800 on your requirements, to have a well defined behavior.
801
Brett Cannona8c34242018-04-20 14:15:40 -0700802* The ``pyvenv`` script has been removed in favor of ``python3.8 -m venv``
803 to help eliminate confusion as to what Python interpreter the ``pyvenv``
804 script is tied to. (Contributed by Brett Cannon in :issue:`25427`.)
Ned Deily07a18922018-01-31 18:12:38 -0500805
INADA Naoki698865d2018-06-19 17:28:50 +0900806* ``parse_qs``, ``parse_qsl``, and ``escape`` are removed from :mod:`cgi`
807 module. They are deprecated from Python 3.2 or older.
808
INADA Naoki461a1c42018-06-28 17:10:36 +0900809* ``filemode`` function is removed from :mod:`tarfile` module.
810 It is not documented and deprecated since Python 3.3.
INADA Naoki698865d2018-06-19 17:28:50 +0900811
Serhiy Storchaka02ec92f2018-07-24 12:03:34 +0300812* The :class:`~xml.etree.ElementTree.XMLParser` constructor no longer accepts
813 the *html* argument. It never had effect and was deprecated in Python 3.4.
814 All other parameters are now :ref:`keyword-only <keyword-only_parameter>`.
815 (Contributed by Serhiy Storchaka in :issue:`29209`.)
816
817* Removed the ``doctype()`` method of :class:`~xml.etree.ElementTree.XMLParser`.
818 (Contributed by Serhiy Storchaka in :issue:`29209`.)
819
Inada Naoki6a16b182019-03-18 15:44:11 +0900820* "unicode_internal" codec is removed.
821 (Contributed by Inada Naoki in :issue:`36297`.)
822
Aviv Palivodae6576242019-05-09 21:05:45 +0300823* The ``Cache`` and ``Statement`` objects of the :mod:`sqlite3` module are not
824 exposed to the user.
825 (Contributed by Aviv Palivoda in :issue:`30262`.)
826
Ned Deily07a18922018-01-31 18:12:38 -0500827
828Porting to Python 3.8
829=====================
830
831This section lists previously described changes and other bugfixes
832that may require changes to your code.
833
834
Serhiy Storchaka07ca9af2018-02-04 10:53:48 +0200835Changes in Python behavior
836--------------------------
837
838* Yield expressions (both ``yield`` and ``yield from`` clauses) are now disallowed
839 in comprehensions and generator expressions (aside from the iterable expression
Serhiy Storchaka2b57c432018-12-19 08:09:46 +0200840 in the leftmost :keyword:`!for` clause).
Serhiy Storchaka07ca9af2018-02-04 10:53:48 +0200841 (Contributed by Serhiy Storchaka in :issue:`10544`.)
842
Serhiy Storchaka3bcbedc2019-01-18 07:47:48 +0200843* The compiler now produces a :exc:`SyntaxWarning` when identity checks
844 (``is`` and ``is not``) are used with certain types of literals
845 (e.g. strings, ints). These can often work by accident in CPython,
846 but are not guaranteed by the language spec. The warning advises users
847 to use equality tests (``==`` and ``!=``) instead.
848 (Contributed by Serhiy Storchaka in :issue:`34850`.)
849
Serhiy Storchaka7a0630c2019-04-08 14:34:04 +0300850* The CPython interpreter can swallow exceptions in some circumstances.
851 In Python 3.8 this happens in less cases. In particular, exceptions
852 raised when getting the attribute from the type dictionary are no longer
853 ignored. (Contributed by Serhiy Storchaka in :issue:`35459`.)
854
Serhiy Storchaka96aeaec2019-05-06 22:29:40 +0300855* Removed ``__str__`` implementations from builtin types :class:`bool`,
856 :class:`int`, :class:`float`, :class:`complex` and few classes from
857 the standard library. They now inherit ``__str__()`` from :class:`object`.
858 As result, defining the ``__repr__()`` method in the subclass of these
859 classes will affect they string representation.
860 (Contributed by Serhiy Storchaka in :issue:`36793`.)
861
Michael Felt9d949f72019-04-12 16:15:32 +0200862* On AIX, :attr:`sys.platform` doesn't contain the major version anymore.
863 It is always ``'aix'``, instead of ``'aix3'`` .. ``'aix7'``. Since
864 older Python versions include the version number, it is recommended to
865 always use the ``sys.platform.startswith('aix')``.
866 (Contributed by M. Felt in :issue:`36588`.)
Serhiy Storchaka07ca9af2018-02-04 10:53:48 +0200867
Joannah Nanjekyef781d202019-04-29 04:38:45 -0400868* :c:func:`PyEval_AcquireLock` and :c:func:`PyEval_AcquireThread` now
869 terminate the current thread if called while the interpreter is
870 finalizing, making them consistent with :c:func:`PyEval_RestoreThread`,
871 :c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`. If this
872 behaviour is not desired, guard the call by checking :c:func:`_Py_IsFinalizing`
873 or :c:func:`sys.is_finalizing`.
874
Serhiy Storchaka97f1ca12018-02-01 18:49:21 +0200875Changes in the Python API
876-------------------------
877
Victor Stinnerd7befad2019-04-25 14:30:16 +0200878* :class:`subprocess.Popen` can now use :func:`os.posix_spawn` in some cases
879 for better performance. On Windows Subsystem for Linux and QEMU User
880 Emulation, Popen constructor using :func:`os.posix_spawn` no longer raise an
881 exception on errors like missing program, but the child process fails with a
882 non-zero :attr:`~Popen.returncode`.
883
Victor Stinner74125a62019-04-15 18:23:20 +0200884* The :meth:`imap.IMAP4.logout` method no longer ignores silently arbitrary
885 exceptions.
886
Victor Stinner73104fa2018-11-29 09:58:20 +0100887* The function :func:`platform.popen` has been removed, it was deprecated since
888 Python 3.3: use :func:`os.popen` instead.
889
Raymond Hettingerfc06a192019-03-12 00:43:27 -0700890* The :func:`statistics.mode` function no longer raises an exception
891 when given multimodal data. Instead, it returns the first mode
892 encountered in the input data. (Contributed by Raymond Hettinger
893 in :issue:`35892`.)
894
Serhiy Storchaka97f1ca12018-02-01 18:49:21 +0200895* The :meth:`~tkinter.ttk.Treeview.selection` method of the
896 :class:`tkinter.ttk.Treeview` class no longer takes arguments. Using it with
897 arguments for changing the selection was deprecated in Python 3.6. Use
898 specialized methods like :meth:`~tkinter.ttk.Treeview.selection_set` for
899 changing the selection. (Contributed by Serhiy Storchaka in :issue:`31508`.)
Serhiy Storchaka6c85efa52018-02-05 22:47:31 +0200900
Diego Rojas06e1e682019-03-16 18:44:56 -0500901* The :meth:`writexml`, :meth:`toxml` and :meth:`toprettyxml` methods of the
902 :mod:`xml.dom.minidom` module, and :mod:`xml.etree` now preserve the attribute
903 order specified by the user.
904 (Contributed by Diego Rojas and Raymond Hettinger in :issue:`34160`.)
905
Serhiy Storchaka6c85efa52018-02-05 22:47:31 +0200906* A :mod:`dbm.dumb` database opened with flags ``'r'`` is now read-only.
907 :func:`dbm.dumb.open` with flags ``'r'`` and ``'w'`` no longer creates
908 a database if it does not exist.
909 (Contributed by Serhiy Storchaka in :issue:`32749`.)
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +0200910
Serhiy Storchaka02ec92f2018-07-24 12:03:34 +0300911* The ``doctype()`` method defined in a subclass of
912 :class:`~xml.etree.ElementTree.XMLParser` will no longer be called and will
913 cause emitting a :exc:`RuntimeWarning` instead of a :exc:`DeprecationWarning`.
914 Define the :meth:`doctype() <xml.etree.ElementTree.TreeBuilder.doctype>`
915 method on a target for handling an XML doctype declaration.
916 (Contributed by Serhiy Storchaka in :issue:`29209`.)
917
Serhiy Storchakaf5e7b192018-05-20 08:48:12 +0300918* A :exc:`RuntimeError` is now raised when the custom metaclass doesn't
919 provide the ``__classcell__`` entry in the namespace passed to
920 ``type.__new__``. A :exc:`DeprecationWarning` was emitted in Python
921 3.6--3.7. (Contributed by Serhiy Storchaka in :issue:`23722`.)
922
Scott Sandersoncebe80b2018-06-07 05:46:42 -0400923* The :class:`cProfile.Profile` class can now be used as a context
924 manager. (Contributed by Scott Sanderson in :issue:`29235`.)
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +0200925
Giampaolo Rodolac7f02a92018-06-19 08:27:29 -0700926* :func:`shutil.copyfile`, :func:`shutil.copy`, :func:`shutil.copy2`,
927 :func:`shutil.copytree` and :func:`shutil.move` use platform-specific
928 "fast-copy" syscalls (see
929 :ref:`shutil-platform-dependent-efficient-copy-operations` section).
930
931* :func:`shutil.copyfile` default buffer size on Windows was changed from
932 16 KiB to 1 MiB.
933
INADA Naokid5c875b2018-07-11 17:42:49 +0900934* ``PyGC_Head`` struct is changed completely. All code touched the
935 struct member should be rewritten. (See :issue:`33597`)
936
Eric Snowbe3b2952019-02-23 11:35:52 -0700937* The ``PyInterpreterState`` struct has been moved into the "internal"
938 header files (specifically Include/internal/pycore_pystate.h). An
939 opaque ``PyInterpreterState`` is still available as part of the public
940 API (and stable ABI). The docs indicate that none of the struct's
941 fields are public, so we hope no one has been using them. However,
942 if you do rely on one or more of those private fields and have no
943 alternative then please open a BPO issue. We'll work on helping
944 you adjust (possibly including adding accessor functions to the
945 public API). (See :issue:`35886`.)
946
Alex Grönholmcca4eec2018-08-09 00:06:47 +0300947* Asyncio tasks can now be named, either by passing the ``name`` keyword
948 argument to :func:`asyncio.create_task` or
Yury Selivanov7c7605f2018-09-11 09:54:40 -0700949 the :meth:`~asyncio.loop.create_task` event loop method, or by
Alex Grönholmcca4eec2018-08-09 00:06:47 +0300950 calling the :meth:`~asyncio.Task.set_name` method on the task object. The
951 task name is visible in the ``repr()`` output of :class:`asyncio.Task` and
952 can also be retrieved using the :meth:`~asyncio.Task.get_name` method.
953
Berker Peksage7d4b2f2018-08-22 21:21:05 +0300954* The :meth:`mmap.flush() <mmap.mmap.flush>` method now returns ``None`` on
955 success and raises an exception on error under all platforms. Previously,
956 its behavior was platform-depended: a nonzero value was returned on success;
957 zero was returned on error under Windows. A zero value was returned on
958 success; an exception was raised on error under Unix.
959 (Contributed by Berker Peksag in :issue:`2122`.)
960
Pablo Galindofa221d82018-09-08 00:16:17 +0100961* The function :func:`math.factorial` no longer accepts arguments that are not
962 int-like. (Contributed by Pablo Galindo in :issue:`33083`.)
963
Andrés Delfinoca682612018-11-07 14:29:14 -0300964* :mod:`xml.dom.minidom` and :mod:`xml.sax` modules no longer process
Christian Heimes17b1d5d2018-09-23 09:50:25 +0200965 external entities by default.
966 (Contributed by Christian Heimes in :issue:`17239`.)
INADA Naokid5c875b2018-07-11 17:42:49 +0900967
Xiang Zhang4fb0b8b2018-12-12 20:46:55 +0800968* Deleting a key from a read-only :mod:`dbm` database (:mod:`dbm.dumb`,
969 :mod:`dbm.gnu` or :mod:`dbm.ndbm`) raises :attr:`error` (:exc:`dbm.dumb.error`,
970 :exc:`dbm.gnu.error` or :exc:`dbm.ndbm.error`) instead of :exc:`KeyError`.
971 (Contributed by Xiang Zhang in :issue:`33106`.)
972
Steve Dower8ef864d2019-03-12 15:15:26 -0700973* :func:`~os.path.expanduser` on Windows now prefers the :envvar:`USERPROFILE`
974 environment variable and does not use :envvar:`HOME`, which is not normally
975 set for regular user accounts.
976
Steve Dower2438cdf2019-03-29 16:37:16 -0700977.. _bpo-36085-whatsnew:
978
979* DLL dependencies for extension modules and DLLs loaded with :mod:`ctypes` on
980 Windows are now resolved more securely. Only the system paths, the directory
981 containing the DLL or PYD file, and directories added with
982 :func:`~os.add_dll_directory` are searched for load-time dependencies.
983 Specifically, :envvar:`PATH` and the current working directory are no longer
984 used, and modifications to these will no longer have any effect on normal DLL
985 resolution. If your application relies on these mechanisms, you should check
986 for :func:`~os.add_dll_directory` and if it exists, use it to add your DLLs
Steve Dower79da3882019-03-30 20:58:17 -0700987 directory while loading your library. Note that Windows 7 users will need to
988 ensure that Windows Update KB2533625 has been installed (this is also verified
989 by the installer).
Steve Dower2438cdf2019-03-29 16:37:16 -0700990 (See :issue:`36085`.)
991
Pablo Galindof2cf1e32019-04-13 17:05:14 +0100992* The header files and functions related to pgen have been removed after its
993 replacement by a pure Python implementation. (Contributed by Pablo Galindo
994 in :issue:`36623`.)
995
Pablo Galindo5d23e282019-05-12 22:45:52 +0100996* :class:`types.CodeType` has a new parameter in the second position of the
997 constructor (*posonlyargcount*) to support positional-only arguments defined
998 in :pep:`570`.
999
Xiang Zhang4fb0b8b2018-12-12 20:46:55 +08001000
Inada Naokid3c72a22019-03-23 21:04:40 +09001001Changes in the C API
1002--------------------
1003
Victor Stinnerd5d9e812019-05-13 12:35:37 +02001004* The :c:func:`PyEval_ReInitThreads` function has been removed from the C API.
1005 It should not be called explicitly: use :c:func:`PyOS_AfterFork_Child`
1006 instead.
1007 (Contributed by Victor Stinner in :issue:`36728`.)
1008
xdegaye254b3092019-04-29 09:27:40 +02001009* On Unix, C extensions are no longer linked to libpython except on
1010 Android. When Python is embedded, ``libpython`` must not be loaded with
1011 ``RTLD_LOCAL``, but ``RTLD_GLOBAL`` instead. Previously, using
1012 ``RTLD_LOCAL``, it was already not possible to load C extensions which were
1013 not linked to ``libpython``, like C extensions of the standard library built
1014 by the ``*shared*`` section of ``Modules/Setup``.
Victor Stinner8c3ecc62019-04-25 20:13:10 +02001015
Inada Naokid3c72a22019-03-23 21:04:40 +09001016* Use of ``#`` variants of formats in parsing or building value (e.g.
1017 :c:func:`PyArg_ParseTuple`, :c:func:`Py_BuildValue`, :c:func:`PyObject_CallFunction`,
1018 etc.) without ``PY_SSIZE_T_CLEAN`` defined raises ``DeprecationWarning`` now.
1019 It will be removed in 3.10 or 4.0. Read :ref:`arg-parsing` for detail.
1020 (Contributed by Inada Naoki in :issue:`36381`.)
1021
Eddie Elizondo364f0b02019-03-27 07:52:18 -04001022* Instances of heap-allocated types (such as those created with
1023 :c:func:`PyType_FromSpec`) hold a reference to their type object.
1024 Increasing the reference count of these type objects has been moved from
1025 :c:func:`PyType_GenericAlloc` to the more low-level functions,
1026 :c:func:`PyObject_Init` and :c:func:`PyObject_INIT`.
1027 This makes types created through :c:func:`PyType_FromSpec` behave like
1028 other classes in managed code.
1029
1030 Statically allocated types are not affected.
1031
1032 For the vast majority of cases, there should be no side effect.
1033 However, types that manually increase the reference count after allocating
1034 an instance (perhaps to work around the bug) may now become immortal.
1035 To avoid this, these classes need to call Py_DECREF on the type object
1036 during instance deallocation.
1037
1038 To correctly port these types into 3.8, please apply the following
1039 changes:
1040
1041 * Remove :c:macro:`Py_INCREF` on the type object after allocating an
1042 instance - if any.
1043 This may happen after calling :c:func:`PyObject_New`,
1044 :c:func:`PyObject_NewVar`, :c:func:`PyObject_GC_New`,
1045 :c:func:`PyObject_GC_NewVar`, or any other custom allocator that uses
1046 :c:func:`PyObject_Init` or :c:func:`PyObject_INIT`.
1047
1048 Example::
1049
1050 static foo_struct *
1051 foo_new(PyObject *type) {
1052 foo_struct *foo = PyObject_GC_New(foo_struct, (PyTypeObject *) type);
1053 if (foo == NULL)
1054 return NULL;
1055 #if PY_VERSION_HEX < 0x03080000
1056 // Workaround for Python issue 35810; no longer necessary in Python 3.8
1057 PY_INCREF(type)
1058 #endif
1059 return foo;
1060 }
1061
1062 * Ensure that all custom ``tp_dealloc`` functions of heap-allocated types
1063 decrease the type's reference count.
1064
1065 Example::
1066
1067 static void
1068 foo_dealloc(foo_struct *instance) {
1069 PyObject *type = Py_TYPE(instance);
1070 PyObject_GC_Del(instance);
1071 #if PY_VERSION_HEX >= 0x03080000
1072 // This was not needed before Python 3.8 (Python issue 35810)
1073 Py_DECREF(type);
1074 #endif
1075 }
1076
1077 (Contributed by Eddie Elizondo in :issue:`35810`.)
1078
1079
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +02001080CPython bytecode changes
1081------------------------
1082
1083* The interpreter loop has been simplified by moving the logic of unrolling
1084 the stack of blocks into the compiler. The compiler emits now explicit
Serhiy Storchaka3f819ca2018-10-31 02:26:06 +02001085 instructions for adjusting the stack of values and calling the
1086 cleaning-up code for :keyword:`break`, :keyword:`continue` and
1087 :keyword:`return`.
Serhiy Storchaka520b7ae2018-02-22 23:33:30 +02001088
1089 Removed opcodes :opcode:`BREAK_LOOP`, :opcode:`CONTINUE_LOOP`,
1090 :opcode:`SETUP_LOOP` and :opcode:`SETUP_EXCEPT`. Added new opcodes
1091 :opcode:`ROT_FOUR`, :opcode:`BEGIN_FINALLY`, :opcode:`CALL_FINALLY` and
1092 :opcode:`POP_FINALLY`. Changed the behavior of :opcode:`END_FINALLY`
1093 and :opcode:`WITH_CLEANUP_START`.
1094
1095 (Contributed by Mark Shannon, Antoine Pitrou and Serhiy Storchaka in
1096 :issue:`17611`.)
Serhiy Storchaka702f8f32018-03-23 14:34:35 +02001097
1098* Added new opcode :opcode:`END_ASYNC_FOR` for handling exceptions raised
1099 when awaiting a next item in an :keyword:`async for` loop.
1100 (Contributed by Serhiy Storchaka in :issue:`33041`.)
Raymond Hettingerf75d59e2019-02-02 22:54:56 -08001101
1102
1103Demos and Tools
1104---------------
1105
1106* Added a benchmark script for timing various ways to access variables:
1107 ``Tools/scripts/var_access_benchmark.py``.
1108 (Contributed by Raymond Hettinger in :issue:`35884`.)