blob: ce1c44e80401a3c573a801ad12ace00a9f7abc97 [file] [log] [blame]
Yury Selivanovd1da5072015-05-27 22:09:10 -04001****************************
2 What's New In Python 3.6
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.6, compared to 3.5.
49
50For full details, see the :source:`Misc/NEWS` file.
51
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.6 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.6.
63 Brevity is key.
64
Paul Moore835416c2016-05-22 12:28:41 +010065New syntax features:
66
Martin Panterbc1ee462016-02-13 00:41:37 +000067* PEP 498: :ref:`Formatted string literals <whatsnew-fstrings>`
Yury Selivanovd1da5072015-05-27 22:09:10 -040068
Brett Cannon68ed9782016-08-26 14:45:15 -070069Standard library improvements:
70
Victor Stinnere66987e2016-09-06 16:33:52 -070071Security improvements:
72
73* On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
74 is initialized to increase the security. See the :pep:`524` for the
75 rationale.
76
Paul Moore835416c2016-05-22 12:28:41 +010077Windows improvements:
78
Steve Dowercc16be82016-09-08 10:35:16 -070079* PEP 529: :ref:`Change Windows filesystem encoding to UTF-8 <pep-529>`
80
Paul Moore835416c2016-05-22 12:28:41 +010081* The ``py.exe`` launcher, when used interactively, no longer prefers
82 Python 2 over Python 3 when the user doesn't specify a version (via
83 command line arguments or a config file). Handling of shebang lines
84 remains unchanged - "python" refers to Python 2 in that case.
85
Steve Dower19ab0fd2016-09-06 20:40:11 -070086* ``python.exe`` and ``pythonw.exe`` have been marked as long-path aware,
87 which means that when the 260 character path limit may no longer apply.
88 See :ref:`removing the MAX_PATH limitation <max-path>` for details.
89
Yury Selivanovd1da5072015-05-27 22:09:10 -040090.. PEP-sized items next.
91
92.. _pep-4XX:
93
94.. PEP 4XX: Virtual Environments
95.. =============================
96
97
98.. (Implemented by Foo Bar.)
99
100.. .. seealso::
101
102 :pep:`4XX` - Python Virtual Environments
103 PEP written by Carl Meyer
104
Eric Snow92a6c172016-09-05 14:50:11 -0700105.. XXX PEP 520: :ref:`Preserving Class Attribute Definition Order<whatsnew-deforder>`
Yury Selivanovd1da5072015-05-27 22:09:10 -0400106
Victor Stinner34be8072016-03-14 12:04:26 +0100107New Features
108============
109
Brett Cannon3cebf932016-09-05 15:33:46 -0700110.. _pep-523:
111
112PEP 523: Adding a frame evaluation API to CPython
113=================================================
114
115While Python provides extensive support to customize how code
116executes, one place it has not done so is in the evaluation of frame
117objects. If you wanted some way to intercept frame evaluation in
118Python there really wasn't any way without directly manipulating
119function pointers for defined functions.
120
121:pep:`523` changes this by providing an API to make frame
122evaluation pluggable at the C level. This will allow for tools such
123as debuggers and JITs to intercept frame evaluation before the
124execution of Python code begins. This enables the use of alternative
125evaluation implementations for Python code, tracking frame
126evaluation, etc.
127
128This API is not part of the limited C API and is marked as private to
129signal that usage of this API is expected to be limited and only
Brett Cannon5c4de282016-09-07 11:16:41 -0700130applicable to very select, low-level use-cases. Semantics of the
131API will change with Python as necessary.
Brett Cannon3cebf932016-09-05 15:33:46 -0700132
133.. seealso::
134
135 :pep:`523` - Adding a frame evaluation API to CPython
136 PEP written by Brett Cannon and Dino Viehland.
137
138
Brett Cannon68ed9782016-08-26 14:45:15 -0700139.. _pep-519:
140
141PEP 519: Adding a file system path protocol
142===========================================
143
144File system paths have historically been represented as :class:`str`
145or :class:`bytes` objects. This has led to people who write code which
146operate on file system paths to assume that such objects are only one
147of those two types (an :class:`int` representing a file descriptor
148does not count as that is not a file path). Unfortunately that
149assumption prevents alternative object representations of file system
150paths like :mod:`pathlib` from working with pre-existing code,
151including Python's standard library.
152
153To fix this situation, a new interface represented by
154:class:`os.PathLike` has been defined. By implementing the
155:meth:`~os.PathLike.__fspath__` method, an object signals that it
156represents a path. An object can then provide a low-level
157representation of a file system path as a :class:`str` or
158:class:`bytes` object. This means an object is considered
159:term:`path-like <path-like object>` if it implements
160:class:`os.PathLike` or is a :class:`str` or :class:`bytes` object
161which represents a file system path. Code can use :func:`os.fspath`,
162:func:`os.fsdecode`, or :func:`os.fsencode` to explicitly get a
163:class:`str` and/or :class:`bytes` representation of a path-like
164object.
165
166The built-in :func:`open` function has been updated to accept
167:class:`os.PathLike` objects as have all relevant functions in the
Brett Cannona5711202016-09-06 19:36:01 -0700168:mod:`os` and :mod:`os.path` modules. :c:func:`PyUnicode_FSConverter`
169and :c:func:`PyUnicode_FSConverter` have been changed to accept
170path-like objects. The :class:`os.DirEntry` class
Brett Cannon68ed9782016-08-26 14:45:15 -0700171and relevant classes in :mod:`pathlib` have also been updated to
Brett Cannona5711202016-09-06 19:36:01 -0700172implement :class:`os.PathLike`.
173
174The hope in is that updating the fundamental functions for operating
175on file system paths will lead to third-party code to implicitly
176support all :term:`path-like objects <path-like object>` without any
177code changes or at least very minimal ones (e.g. calling
178:func:`os.fspath` at the beginning of code before operating on a
179path-like object).
Brett Cannon68ed9782016-08-26 14:45:15 -0700180
181Here are some examples of how the new interface allows for
182:class:`pathlib.Path` to be used more easily and transparently with
183pre-existing code::
184
185 >>> import pathlib
186 >>> with open(pathlib.Path("README")) as f:
187 ... contents = f.read()
188 ...
189 >>> import os.path
190 >>> os.path.splitext(pathlib.Path("some_file.txt"))
191 ('some_file', '.txt')
192 >>> os.path.join("/a/b", pathlib.Path("c"))
193 '/a/b/c'
194 >>> import os
195 >>> os.fspath(pathlib.Path("some_file.txt"))
196 'some_file.txt'
197
198(Implemented by Brett Cannon, Ethan Furman, Dusty Phillips, and Jelle Zijlstra.)
199
200.. seealso::
201
202 :pep:`519` - Adding a file system path protocol
203 PEP written by Brett Cannon and Koos Zevenhoven.
204
205
Martin Panterbc1ee462016-02-13 00:41:37 +0000206.. _whatsnew-fstrings:
207
208PEP 498: Formatted string literals
209----------------------------------
210
211Formatted string literals are a new kind of string literal, prefixed
212with ``'f'``. They are similar to the format strings accepted by
213:meth:`str.format`. They contain replacement fields surrounded by
214curly braces. The replacement fields are expressions, which are
215evaluated at run time, and then formatted using the :func:`format` protocol.
216
217 >>> name = "Fred"
218 >>> f"He said his name is {name}."
219 'He said his name is Fred.'
220
221See :pep:`498` and the main documentation at :ref:`f-strings`.
222
Steve Dowercc16be82016-09-08 10:35:16 -0700223.. _pep-529:
224
225PEP 529: Change Windows filesystem encoding to UTF-8
226----------------------------------------------------
227
228Representing filesystem paths is best performed with str (Unicode) rather than
229bytes. However, there are some situations where using bytes is sufficient and
230correct.
231
232Prior to Python 3.6, data loss could result when using bytes paths on Windows.
233With this change, using bytes to represent paths is now supported on Windows,
234provided those bytes are encoded with the encoding returned by
235:func:`sys.getfilesystemencoding()`, which now defaults to ``'utf-8'``.
236
237Applications that do not use str to represent paths should use
238:func:`os.fsencode()` and :func:`os.fsdecode()` to ensure their bytes are
239correctly encoded. To revert to the previous behaviour, set
240:envvar:`PYTHONLEGACYWINDOWSFSENCODING` or call
241:func:`sys._enablelegacywindowsfsencoding`.
242
243See :pep:`529` for more information and discussion of code modifications that
244may be required.
245
246.. note::
247
248 This change is considered experimental for 3.6.0 beta releases. The default
249 encoding may change before the final release.
Martin Panterbc1ee462016-02-13 00:41:37 +0000250
Nick Coghland78448e2016-07-30 16:26:03 +1000251PEP 487: Simpler customization of class creation
252------------------------------------------------
253
254Upon subclassing a class, the ``__init_subclass__`` classmethod (if defined) is
255called on the base class. This makes it straightforward to write classes that
256customize initialization of future subclasses without introducing the
257complexity of a full custom metaclass.
258
259The descriptor protocol has also been expanded to include a new optional method,
260``__set_name__``. Whenever a new class is defined, the new method will be called
261on all descriptors included in the definition, providing them with a reference
262to the class being defined and the name given to the descriptor within the
263class namespace.
264
265Also see :pep:`487` and the updated class customization documentation at
266:ref:`class-customization` and :ref:`descriptors`.
267
268(Contributed by Martin Teichmann in :issue:`27366`)
269
270
Victor Stinner34be8072016-03-14 12:04:26 +0100271PYTHONMALLOC environment variable
272---------------------------------
273
Martin Panterdf1d31c2016-06-20 08:00:45 +0000274The new :envvar:`PYTHONMALLOC` environment variable allows setting the Python
Victor Stinner34be8072016-03-14 12:04:26 +0100275memory allocators and/or install debug hooks.
276
277It is now possible to install debug hooks on Python memory allocators on Python
278compiled in release mode using ``PYTHONMALLOC=debug``. Effects of debug hooks:
279
280* Newly allocated memory is filled with the byte ``0xCB``
281* Freed memory is filled with the byte ``0xDB``
282* Detect violations of Python memory allocator API. For example,
283 :c:func:`PyObject_Free` called on a memory block allocated by
284 :c:func:`PyMem_Malloc`.
285* Detect write before the start of the buffer (buffer underflow)
286* Detect write after the end of the buffer (buffer overflow)
Victor Stinnerc4aec362016-03-14 22:26:53 +0100287* Check that the :term:`GIL <global interpreter lock>` is held when allocator
Victor Stinnerc2fc5682016-03-18 11:04:31 +0100288 functions of :c:data:`PYMEM_DOMAIN_OBJ` (ex: :c:func:`PyObject_Malloc`) and
289 :c:data:`PYMEM_DOMAIN_MEM` (ex: :c:func:`PyMem_Malloc`) domains are called.
290
Victor Stinner9b46a572016-03-18 15:10:43 +0100291Checking if the GIL is held is also a new feature of Python 3.6.
Victor Stinner34be8072016-03-14 12:04:26 +0100292
293See the :c:func:`PyMem_SetupDebugHooks` function for debug hooks on Python
294memory allocators.
295
296It is now also possible to force the usage of the :c:func:`malloc` allocator of
297the C library for all Python memory allocations using ``PYTHONMALLOC=malloc``.
298It helps to use external memory debuggers like Valgrind on a Python compiled in
299release mode.
300
Victor Stinner0611c262016-03-15 22:22:13 +0100301On error, the debug hooks on Python memory allocators now use the
302:mod:`tracemalloc` module to get the traceback where a memory block was
303allocated.
304
305Example of fatal error on buffer overflow using
306``python3.6 -X tracemalloc=5`` (store 5 frames in traces)::
307
308 Debug memory block at address p=0x7fbcd41666f8: API 'o'
309 4 bytes originally requested
310 The 7 pad bytes at p-7 are FORBIDDENBYTE, as expected.
311 The 8 pad bytes at tail=0x7fbcd41666fc are not all FORBIDDENBYTE (0xfb):
312 at tail+0: 0x02 *** OUCH
313 at tail+1: 0xfb
314 at tail+2: 0xfb
315 at tail+3: 0xfb
316 at tail+4: 0xfb
317 at tail+5: 0xfb
318 at tail+6: 0xfb
319 at tail+7: 0xfb
320 The block was made by call #1233329 to debug malloc/realloc.
321 Data at p: 1a 2b 30 00
322
323 Memory block allocated at (most recent call first):
324 File "test/test_bytes.py", line 323
325 File "unittest/case.py", line 600
326 File "unittest/case.py", line 648
327 File "unittest/suite.py", line 122
328 File "unittest/suite.py", line 84
329
330 Fatal Python error: bad trailing pad byte
331
332 Current thread 0x00007fbcdbd32700 (most recent call first):
333 File "test/test_bytes.py", line 323 in test_hex
334 File "unittest/case.py", line 600 in run
335 File "unittest/case.py", line 648 in __call__
336 File "unittest/suite.py", line 122 in run
337 File "unittest/suite.py", line 84 in __call__
338 File "unittest/suite.py", line 122 in run
339 File "unittest/suite.py", line 84 in __call__
340 ...
341
342(Contributed by Victor Stinner in :issue:`26516` and :issue:`26564`.)
Victor Stinner34be8072016-03-14 12:04:26 +0100343
344
Eric Snow92a6c172016-09-05 14:50:11 -0700345.. _whatsnew-deforder:
346
347PEP 520: Preserving Class Attribute Definition Order
348----------------------------------------------------
349
350Attributes in a class definition body have a natural ordering: the same
351order in which the names appear in the source. This order is now
352preserved in the new class's ``__definition_order__`` attribute. It is
353a tuple of the attribute names, in the order in which they appear in
354the class definition body.
355
356For types that don't have a definition (e.g. builtins), or the attribute
357order could not be determined, ``__definition_order__`` is ``None``.
358
359Also, the effective default class *execution* namespace (returned from
360``type.__prepare__()``) is now an insertion-order-preserving mapping.
361For CPython, it is now ``collections.OrderedDict``. Note that the
362class namespace, ``cls.__dict__``, is unchanged.
363
364.. seealso::
365
366 :pep:`520` - Preserving Class Attribute Definition Order
367 PEP written and implemented by Eric Snow.
368
369
Yury Selivanovd1da5072015-05-27 22:09:10 -0400370Other Language Changes
371======================
372
Nick Coghlan02d03df2016-08-16 10:58:14 +1000373Some smaller changes made to the core Python language are:
374
Benjamin Petersone5e3edb2016-09-08 10:13:42 -0700375* :func:`dict` now uses a "compact" representation `pioneered by PyPy
376 <https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html>`_.
377 :pep:`PEP 468` (Preserving the order of ``**kwargs`` in a function.) is
378 implemented by this. (Contributed by INADA Naoki in :issue:`27350`.)
Victor Stinner742da042016-09-07 17:40:12 -0700379
Nick Coghlan02d03df2016-08-16 10:58:14 +1000380* Long sequences of repeated traceback lines are now abbreviated as
381 ``"[Previous line repeated {count} more times]"`` (see
382 :ref:`py36-traceback` for an example).
383 (Contributed by Emanuel Barry in :issue:`26823`.)
Yury Selivanovd1da5072015-05-27 22:09:10 -0400384
Eric Snow46f97b82016-09-07 16:56:15 -0700385* Import now raises the new exception :exc:`ModuleNotFoundError`
386 (subclass of :exc:`ImportError`) when it cannot find a module. Code
387 that current checks for ImportError (in try-except) will still work.
388
Yury Selivanovd1da5072015-05-27 22:09:10 -0400389
390New Modules
391===========
392
393* None yet.
394
395
396Improved Modules
397================
398
Victor Stinnere66987e2016-09-06 16:33:52 -0700399On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
400is initialized to increase the security. See the :pep:`524` for the rationale.
401
Yury Selivanovb4a0d522016-05-16 16:25:16 -0400402
403asyncio
404-------
405
406Since the :mod:`asyncio` module is :term:`provisional <provisional api>`,
407all changes introduced in Python 3.6 have also been backported to Python
4083.5.x.
409
410Notable changes in the :mod:`asyncio` module since Python 3.5.0:
411
412* The :func:`~asyncio.ensure_future` function and all functions that
413 use it, such as :meth:`loop.run_until_complete() <asyncio.BaseEventLoop.run_until_complete>`,
414 now accept all kinds of :term:`awaitable objects <awaitable>`.
415 (Contributed by Yury Selivanov.)
416
417* New :func:`~asyncio.run_coroutine_threadsafe` function to submit
418 coroutines to event loops from other threads.
419 (Contributed by Vincent Michel.)
420
421* New :meth:`Transport.is_closing() <asyncio.BaseTransport.is_closing>`
422 method to check if the transport is closing or closed.
423 (Contributed by Yury Selivanov.)
424
425* The :meth:`loop.create_server() <asyncio.BaseEventLoop.create_server>`
426 method can now accept a list of hosts.
427 (Contributed by Yann Sionneau.)
428
429* New :meth:`loop.create_future() <asyncio.BaseEventLoop.create_future>`
430 method to create Future objects. This allows alternative event
431 loop implementations, such as
432 `uvloop <https://github.com/MagicStack/uvloop>`_, to provide a faster
433 :class:`asyncio.Future` implementation.
434 (Contributed by Yury Selivanov.)
435
436* New :meth:`loop.get_exception_handler() <asyncio.BaseEventLoop.get_exception_handler>`
437 method to get the current exception handler.
438 (Contributed by Yury Selivanov.)
439
440* New :func:`~asyncio.timeout` context manager to simplify timeouts
441 handling code.
442 (Contributed by Andrew Svetlov.)
443
444* New :meth:`StreamReader.readuntil() <asyncio.StreamReader.readuntil>`
445 method to read data from the stream until a separator bytes
446 sequence appears.
447 (Contributed by Mark Korenberg.)
448
449* The :meth:`loop.getaddrinfo() <asyncio.BaseEventLoop.getaddrinfo>`
450 method is optimized to avoid calling the system ``getaddrinfo``
451 function if the address is already resolved.
452 (Contributed by A. Jesse Jiryu Davis.)
453
454
Brett Cannon9e080e02016-04-08 12:15:27 -0700455contextlib
456----------
457
458The :class:`contextlib.AbstractContextManager` class has been added to
459provide an abstract base class for context managers. It provides a
460sensible default implementation for `__enter__()` which returns
Martin Panter3872d622016-04-10 02:41:25 +0000461``self`` and leaves `__exit__()` an abstract method. A matching
Brett Cannon9e080e02016-04-08 12:15:27 -0700462class has been added to the :mod:`typing` module as
463:class:`typing.ContextManager`.
464(Contributed by Brett Cannon in :issue:`25609`.)
465
466
Vinay Sajipfd0f84b2016-08-06 10:43:44 +0100467venv
468----
469
470:mod:`venv` accepts a new parameter ``--prompt``. This parameter provides an
471alternative prefix for the virtual environment. (Proposed by Łukasz.Balcerzak
472and ported to 3.6 by Stéphane Wirtel in :issue:`22829`.)
473
474
Berker Peksagb6c95722015-10-08 13:58:49 +0300475datetime
476--------
477
Martin Panterfad4b602015-11-14 01:29:17 +0000478The :meth:`datetime.strftime() <datetime.datetime.strftime>` and
479:meth:`date.strftime() <datetime.date.strftime>` methods now support ISO 8601 date
Berker Peksagb6c95722015-10-08 13:58:49 +0300480directives ``%G``, ``%u`` and ``%V``.
481(Contributed by Ashley Anderson in :issue:`12006`.)
482
483
Jason R. Coombsc758d512016-08-21 16:09:27 -0400484distutils.command.sdist
485-----------------------
486
487The ``default_format`` attribute has been removed from
488:class:`distutils.command.sdist.sdist` and the ``formats``
489attribute defaults to ``['gztar']``. Although not anticipated,
490Any code relying on the presence of ``default_format`` may
491need to be adapted. See :issue:`27819` for more details.
492
493
R David Murray56b1f1b2016-09-07 16:48:35 -0400494email
495-----
496
R David Murray8e7cdb22016-09-07 21:21:58 -0400497The new email API, enabled via the *policy* keyword to various constructors, is
498no longer provisional. The :mod:`email` documentation has been reorganized and
499rewritten to focus on the new API, while retaining the old documentation for
500the legacy API. (Contributed by R. David Murray in :issue:`24277`.)
501
R David Murray56b1f1b2016-09-07 16:48:35 -0400502The :mod:`email.mime` classes now all accept an optional *policy* keyword.
503(Contributed by Berker Peksag in :issue:`27331`.)
504
505
Steve Dower6cebd482016-09-06 19:55:55 -0700506encodings
507---------
508
509On Windows, added the ``'oem'`` encoding to use ``CP_OEMCP`` and the ``'ansi'``
510alias for the existing ``'mbcs'`` encoding, which uses the ``CP_ACP`` code page.
511
Victor Stinner404cdc52016-03-23 10:39:17 +0100512faulthandler
513------------
514
Serhiy Storchakab6a9c972016-04-17 09:39:28 +0300515On Windows, the :mod:`faulthandler` module now installs a handler for Windows
Victor Stinner404cdc52016-03-23 10:39:17 +0100516exceptions: see :func:`faulthandler.enable`. (Contributed by Victor Stinner in
517:issue:`23848`.)
518
519
Martin Panter3c0d0ba2016-08-24 06:33:33 +0000520http.client
521-----------
522
523:meth:`HTTPConnection.request() <http.client.HTTPConnection.request>` and
524:meth:`~http.client.HTTPConnection.endheaders` both now support
525chunked encoding request bodies.
526(Contributed by Demian Brecht and Rolf Krahl in :issue:`12319`.)
527
528
Terry Jan Reedyd9792a02016-06-13 00:41:53 -0400529idlelib and IDLE
530----------------
531
532The idlelib package is being modernized and refactored to make IDLE look and work better and to make the code easier to understand, test, and improve. Part of making IDLE look better, especially on Linux and Mac, is using ttk widgets, mostly in the dialogs. As a result, IDLE no longer runs with tcl/tk 8.4. It now requires tcl/tk 8.5 or 8.6. We recommend running the latest release of either.
533
534'Modernizing' includes renaming and consolidation of idlelib modules. The renaming of files with partial uppercase names is similar to the renaming of, for instance, Tkinter and TkFont to tkinter and tkinter.font in 3.0. As a result, imports of idlelib files that worked in 3.5 will usually not work in 3.6. At least a module name change will be needed (see idlelib/README.txt), sometimes more. (Name changes contributed by Al Swiegart and Terry Reedy in :issue:`24225`. Most idlelib patches since have been and will be part of the process.)
535
Terry Jan Reedydffd42f2016-06-13 00:42:42 -0400536In compensation, the eventual result with be that some idlelib classes will be easier to use, with better APIs and docstrings explaining them. Additional useful information will be added to idlelib when available.
Terry Jan Reedyd9792a02016-06-13 00:41:53 -0400537
538
Brett Cannon696c35e2016-06-25 10:58:17 -0700539importlib
540---------
541
542:class:`importlib.util.LazyLoader` now calls
543:meth:`~importlib.abc.Loader.create_module` on the wrapped loader, removing the
544restriction that :class:`importlib.machinery.BuiltinImporter` and
545:class:`importlib.machinery.ExtensionFileLoader` couldn't be used with
546:class:`importlib.util.LazyLoader`.
547
Brett Cannon035a1002016-09-07 18:39:18 -0700548:func:`importlib.util.cache_from_source`,
549:func:`importlib.util.source_from_cache`, and
550:func:`importlib.util.spec_from_file_location` now accept a
551:term:`path-like object`.
552
Brett Cannon696c35e2016-06-25 10:58:17 -0700553
Serhiy Storchakaffe96ae2016-02-11 13:21:30 +0200554os
555--
556
557A new :meth:`~os.scandir.close` method allows explicitly closing a
558:func:`~os.scandir` iterator. The :func:`~os.scandir` iterator now
559supports the :term:`context manager` protocol. If a :func:`scandir`
560iterator is neither exhausted nor explicitly closed a :exc:`ResourceWarning`
561will be emitted in its destructor.
562(Contributed by Serhiy Storchaka in :issue:`25994`.)
563
Victor Stinner9b1f4742016-09-06 16:18:52 -0700564The Linux ``getrandom()`` syscall (get random bytes) is now exposed as the new
565:func:`os.getrandom` function.
566(Contributed by Victor Stinner, part of the :pep:`524`)
567
Brett Cannon035a1002016-09-07 18:39:18 -0700568See the summary for :ref:`PEP 519 <pep-519>` for details on how the
569:mod:`os` and :mod:`os.path` modules now support
570:term:`path-like objects <path-like object>`.
571
572
Serhiy Storchaka0d554d72015-10-10 22:42:18 +0300573pickle
574------
575
Martin Panterfad4b602015-11-14 01:29:17 +0000576Objects that need calling ``__new__`` with keyword arguments can now be pickled
Serhiy Storchaka0d554d72015-10-10 22:42:18 +0300577using :ref:`pickle protocols <pickle-protocols>` older than protocol version 4.
578Protocol version 4 already supports this case. (Contributed by Serhiy
579Storchaka in :issue:`24164`.)
580
581
Martin Panterf0dbf7a2016-05-15 01:26:25 +0000582readline
583--------
584
585Added :func:`~readline.set_auto_history` to enable or disable
586automatic addition of input to the history list. (Contributed by
587Tyler Crompton in :issue:`26870`.)
588
589
Martin Panterfad4b602015-11-14 01:29:17 +0000590rlcompleter
591-----------
Serhiy Storchakaab824222015-09-27 13:43:50 +0300592
593Private and special attribute names now are omitted unless the prefix starts
Martin Panterfad4b602015-11-14 01:29:17 +0000594with underscores. A space or a colon is added after some completed keywords.
Serhiy Storchakaab824222015-09-27 13:43:50 +0300595(Contributed by Serhiy Storchaka in :issue:`25011` and :issue:`25209`.)
596
Martin Panter6fe39262015-11-13 23:54:02 +0000597Names of most attributes listed by :func:`dir` are now completed.
598Previously, names of properties and slots which were not yet created on
599an instance were excluded. (Contributed by Martin Panter in :issue:`25590`.)
600
Serhiy Storchakaab824222015-09-27 13:43:50 +0300601
Brett Cannon5f0507d2016-04-08 15:04:28 -0700602site
603----
604
605When specifying paths to add to :attr:`sys.path` in a `.pth` file,
606you may now specify file paths on top of directories (e.g. zip files).
607(Contributed by Wolfgang Langner in :issue:`26587`).
608
609
Berker Peksage0b70cd2016-06-14 15:25:36 +0300610sqlite3
611-------
612
Berker Peksagb84fd042016-09-07 01:07:06 +0300613:attr:`sqlite3.Cursor.lastrowid` now supports the ``REPLACE`` statement.
614(Contributed by Alex LordThorsen in :issue:`16864`.)
Berker Peksage0b70cd2016-06-14 15:25:36 +0300615
616
Steve Dowerea93ac02016-06-17 12:52:18 -0700617socket
618------
619
620The :func:`~socket.socket.ioctl` function now supports the :data:`~socket.SIO_LOOPBACK_FAST_PATH`
621control code.
622(Contributed by Daniel Stokes in :issue:`26536`.)
623
R David Murraybdfa0eb2016-08-23 21:12:40 -0400624The :meth:`~socket.socket.getsockopt` constants ``SO_DOMAIN``,
625``SO_PROTOCOL``, ``SO_PEERSEC``, and ``SO_PASSSEC`` are now supported.
626(Contributed by Christian Heimes in :issue:`26907`.)
627
Steve Dowerea93ac02016-06-17 12:52:18 -0700628
Martin Panter0cab9c12016-04-13 00:36:52 +0000629socketserver
630------------
631
632Servers based on the :mod:`socketserver` module, including those
633defined in :mod:`http.server`, :mod:`xmlrpc.server` and
634:mod:`wsgiref.simple_server`, now support the :term:`context manager`
635protocol.
636(Contributed by Aviv Palivoda in :issue:`26404`.)
637
Martin Panter34eeed42016-06-29 10:12:22 +0000638The :attr:`~socketserver.StreamRequestHandler.wfile` attribute of
639:class:`~socketserver.StreamRequestHandler` classes now implements
640the :class:`io.BufferedIOBase` writable interface. In particular,
641calling :meth:`~io.BufferedIOBase.write` is now guaranteed to send the
642data in full. (Contributed by Martin Panter in :issue:`26721`.)
643
Martin Panter0cab9c12016-04-13 00:36:52 +0000644
Victor Stinner5a48e212016-05-20 12:11:15 +0200645subprocess
646----------
647
648:class:`subprocess.Popen` destructor now emits a :exc:`ResourceWarning` warning
649if the child process is still running. Use the context manager protocol (``with
650proc: ...``) or call explicitly the :meth:`~subprocess.Popen.wait` method to
651read the exit status of the child process (Contributed by Victor Stinner in
652:issue:`26741`).
653
Steve Dower050acae2016-09-06 20:16:17 -0700654The :class:`subprocess.Popen` constructor and all functions that pass arguments
655through to it now accept *encoding* and *errors* arguments. Specifying either
656of these will enable text mode for the *stdin*, *stdout* and *stderr* streams.
Victor Stinner5a48e212016-05-20 12:11:15 +0200657
R David Murray4f098062015-11-28 12:24:52 -0500658telnetlib
659---------
660
661:class:`~telnetlib.Telnet` is now a context manager (contributed by
662Stéphane Wirtel in :issue:`25485`).
663
664
Serhiy Storchaka81221742016-06-26 09:46:57 +0300665tkinter
666-------
667
668Added methods :meth:`~tkinter.Variable.trace_add`,
669:meth:`~tkinter.Variable.trace_remove` and :meth:`~tkinter.Variable.trace_info`
670in the :class:`tkinter.Variable` class. They replace old methods
671:meth:`~tkinter.Variable.trace_variable`, :meth:`~tkinter.Variable.trace`,
672:meth:`~tkinter.Variable.trace_vdelete` and
673:meth:`~tkinter.Variable.trace_vinfo` that use obsolete Tcl commands and might
674not work in future versions of Tcl.
675(Contributed by Serhiy Storchaka in :issue:`22115`).
676
677
Nick Coghlan02d03df2016-08-16 10:58:14 +1000678.. _py36-traceback:
679
Nick Coghland0034232016-08-15 13:11:34 +1000680traceback
681---------
682
Nick Coghlan02d03df2016-08-16 10:58:14 +1000683Both the traceback module and the interpreter's builtin exception display now
684abbreviate long sequences of repeated lines in tracebacks as shown in the
685following example::
686
687 >>> def f(): f()
688 ...
689 >>> f()
690 Traceback (most recent call last):
691 File "<stdin>", line 1, in <module>
692 File "<stdin>", line 1, in f
693 File "<stdin>", line 1, in f
694 File "<stdin>", line 1, in f
695 [Previous line repeated 995 more times]
696 RecursionError: maximum recursion depth exceeded
697
Nick Coghland0034232016-08-15 13:11:34 +1000698(Contributed by Emanuel Barry in :issue:`26823`.)
699
700
Brett Cannon9e080e02016-04-08 12:15:27 -0700701typing
702------
703
704The :class:`typing.ContextManager` class has been added for
705representing :class:`contextlib.AbstractContextManager`.
706(Contributed by Brett Cannon in :issue:`25609`.)
707
708
Victor Stinner2c2a4e62016-03-11 22:17:48 +0100709unittest.mock
710-------------
711
712The :class:`~unittest.mock.Mock` class has the following improvements:
713
714* Two new methods, :meth:`Mock.assert_called()
715 <unittest.mock.Mock.assert_called>` and :meth:`Mock.assert_called_once()
716 <unittest.mock.Mock.assert_called_once>` to check if the mock object
717 was called.
718 (Contributed by Amit Saha in :issue:`26323`.)
719
720
Martin Panter3c0d0ba2016-08-24 06:33:33 +0000721urllib.request
722--------------
723
Martin Panteref91bb22016-08-27 01:39:26 +0000724If a HTTP request has a file or iterable body (other than a
725bytes object) but no Content-Length header, rather than
Martin Panter3c0d0ba2016-08-24 06:33:33 +0000726throwing an error, :class:`~urllib.request.AbstractHTTPHandler` now
727falls back to use chunked transfer encoding.
728(Contributed by Demian Brecht and Rolf Krahl in :issue:`12319`.)
729
730
Berker Peksag960e8482015-10-08 12:27:06 +0300731urllib.robotparser
732------------------
733
Martin Panterfad4b602015-11-14 01:29:17 +0000734:class:`~urllib.robotparser.RobotFileParser` now supports the ``Crawl-delay`` and
Berker Peksag960e8482015-10-08 12:27:06 +0300735``Request-rate`` extensions.
736(Contributed by Nikolay Bogoychev in :issue:`16099`.)
737
738
Victor Stinner914cde82016-03-19 01:03:51 +0100739warnings
740--------
741
742A new optional *source* parameter has been added to the
743:func:`warnings.warn_explicit` function: the destroyed object which emitted a
744:exc:`ResourceWarning`. A *source* attribute has also been added to
745:class:`warnings.WarningMessage` (contributed by Victor Stinner in
746:issue:`26568` and :issue:`26567`).
747
748When a :exc:`ResourceWarning` warning is logged, the :mod:`tracemalloc` is now
749used to try to retrieve the traceback where the detroyed object was allocated.
750
751Example with the script ``example.py``::
752
Victor Stinneree803a82016-03-19 10:33:25 +0100753 import warnings
Victor Stinner914cde82016-03-19 01:03:51 +0100754
Victor Stinneree803a82016-03-19 10:33:25 +0100755 def func():
756 return open(__file__)
757
758 f = func()
759 f = None
Victor Stinner914cde82016-03-19 01:03:51 +0100760
761Output of the command ``python3.6 -Wd -X tracemalloc=5 example.py``::
762
Victor Stinneree803a82016-03-19 10:33:25 +0100763 example.py:7: ResourceWarning: unclosed file <_io.TextIOWrapper name='example.py' mode='r' encoding='UTF-8'>
Victor Stinner914cde82016-03-19 01:03:51 +0100764 f = None
765 Object allocated at (most recent call first):
Victor Stinneree803a82016-03-19 10:33:25 +0100766 File "example.py", lineno 4
767 return open(__file__)
768 File "example.py", lineno 6
769 f = func()
Victor Stinner914cde82016-03-19 01:03:51 +0100770
771The "Object allocated at" traceback is new and only displayed if
Victor Stinneree803a82016-03-19 10:33:25 +0100772:mod:`tracemalloc` is tracing Python memory allocations and if the
773:mod:`warnings` was already imported.
Victor Stinner914cde82016-03-19 01:03:51 +0100774
775
Steve Dower80ac11d2016-05-24 15:42:04 -0700776winreg
777------
778
Steve Dower4d4bc422016-05-25 11:26:07 -0700779Added the 64-bit integer type :data:`REG_QWORD <winreg.REG_QWORD>`.
Steve Dower80ac11d2016-05-24 15:42:04 -0700780(Contributed by Clement Rouault in :issue:`23026`.)
781
782
Zachary Warec4018812016-09-06 16:32:43 -0500783winsound
784--------
785
786Allowed keyword arguments to be passed to :func:`Beep <winsound.Beep>`,
787:func:`MessageBeep <winsound.MessageBeep>`, and :func:`PlaySound
788<winsound.PlaySound>` (:issue:`27982`).
789
790
Serhiy Storchaka503f9082016-02-08 00:02:25 +0200791zipfile
792-------
793
794A new :meth:`ZipInfo.from_file() <zipfile.ZipInfo.from_file>` class method
Martin Panter288ed032016-02-10 05:45:55 +0000795allows making a :class:`~zipfile.ZipInfo` instance from a filesystem file.
Serhiy Storchaka503f9082016-02-08 00:02:25 +0200796A new :meth:`ZipInfo.is_dir() <zipfile.ZipInfo.is_dir>` method can be used
797to check if the :class:`~zipfile.ZipInfo` instance represents a directory.
798(Contributed by Thomas Kluyver in :issue:`26039`.)
799
Serhiy Storchaka18ee29d2016-05-13 13:52:49 +0300800The :meth:`ZipFile.open() <zipfile.ZipFile.open>` method can now be used to
801write data into a ZIP file, as well as for extracting data.
802(Contributed by Thomas Kluyver in :issue:`26039`.)
803
Serhiy Storchaka503f9082016-02-08 00:02:25 +0200804
Martin Panter1fe0d132016-02-10 10:06:36 +0000805zlib
806----
807
808The :func:`~zlib.compress` function now accepts keyword arguments.
809(Contributed by Aviv Palivoda in :issue:`26243`.)
810
811
Serhiy Storchakab2752102016-04-27 23:13:46 +0300812fileinput
813---------
814
815:func:`~fileinput.hook_encoded` now supports the *errors* argument.
816(Contributed by Joseph Hackman in :issue:`25788`.)
817
818
Yury Selivanovd1da5072015-05-27 22:09:10 -0400819Optimizations
820=============
821
Martin Panterfad4b602015-11-14 01:29:17 +0000822* The ASCII decoder is now up to 60 times as fast for error handlers
Victor Stinnerebcf9ed2015-10-14 10:10:00 +0200823 ``surrogateescape``, ``ignore`` and ``replace`` (Contributed
824 by Victor Stinner in :issue:`24870`).
Yury Selivanovd1da5072015-05-27 22:09:10 -0400825
Terry Jan Reedy6dc9ce12015-10-20 01:07:53 -0400826* The ASCII and the Latin1 encoders are now up to 3 times as fast for the
Martin Panterfad4b602015-11-14 01:29:17 +0000827 error handler ``surrogateescape`` (Contributed by Victor Stinner in :issue:`25227`).
Victor Stinnerc3713e92015-09-29 12:32:13 +0200828
Martin Panterfad4b602015-11-14 01:29:17 +0000829* The UTF-8 encoder is now up to 75 times as fast for error handlers
Victor Stinnerebcf9ed2015-10-14 10:10:00 +0200830 ``ignore``, ``replace``, ``surrogateescape``, ``surrogatepass`` (Contributed
831 by Victor Stinner in :issue:`25267`).
Victor Stinner01ada392015-10-01 21:54:51 +0200832
Martin Panterfad4b602015-11-14 01:29:17 +0000833* The UTF-8 decoder is now up to 15 times as fast for error handlers
Victor Stinnerebcf9ed2015-10-14 10:10:00 +0200834 ``ignore``, ``replace`` and ``surrogateescape`` (Contributed
835 by Victor Stinner in :issue:`25301`).
836
837* ``bytes % args`` is now up to 2 times faster. (Contributed by Victor Stinner
838 in :issue:`25349`).
839
840* ``bytearray % args`` is now between 2.5 and 5 times faster. (Contributed by
841 Victor Stinner in :issue:`25399`).
Victor Stinner1d65d912015-10-05 13:43:50 +0200842
Victor Stinner2bf89932015-10-14 11:25:33 +0200843* Optimize :meth:`bytes.fromhex` and :meth:`bytearray.fromhex`: they are now
844 between 2x and 3.5x faster. (Contributed by Victor Stinner in :issue:`25401`).
845
Victor Stinnerfac39562016-03-21 10:38:58 +0100846* Optimize ``bytes.replace(b'', b'.')`` and ``bytearray.replace(b'', b'.')``:
847 up to 80% faster. (Contributed by Josh Snider in :issue:`26574`).
848
Victor Stinner8153ac82016-04-24 22:33:26 +0200849* Allocator functions of the :c:func:`PyMem_Malloc` domain
850 (:c:data:`PYMEM_DOMAIN_MEM`) now use the :ref:`pymalloc memory allocator
851 <pymalloc>` instead of :c:func:`malloc` function of the C library. The
852 pymalloc allocator is optimized for objects smaller or equal to 512 bytes
853 with a short lifetime, and use :c:func:`malloc` for larger memory blocks.
854 (Contributed by Victor Stinner in :issue:`26249`).
855
Victor Stinner19ed27e2016-05-20 11:42:37 +0200856* :func:`pickle.load` and :func:`pickle.loads` are now up to 10% faster when
857 deserializing many small objects (Contributed by Victor Stinner in
858 :issue:`27056`).
Yury Selivanovd1da5072015-05-27 22:09:10 -0400859
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300860- Passing :term:`keyword arguments <keyword argument>` to a function has an
861 overhead in comparison with passing :term:`positional arguments
862 <positional argument>`. Now in extension functions implemented with using
863 Argument Clinic this overhead is significantly decreased.
864 (Contributed by Serhiy Storchaka in :issue:`27574`).
865
Serhiy Storchaka28ab6342016-09-06 22:33:41 +0300866* Optimized :func:`~glob.glob` and :func:`~glob.iglob` functions in the
867 :mod:`glob` module; they are now about 3--6 times faster.
868 (Contributed by Serhiy Storchaka in :issue:`25596`).
869
Serhiy Storchaka680cb152016-09-07 10:58:05 +0300870* Optimized globbing in :mod:`pathlib` by using :func:`os.scandir`;
871 it is now about 1.5--4 times faster.
872 (Contributed by Serhiy Storchaka in :issue:`26032`).
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300873
Yury Selivanovd1da5072015-05-27 22:09:10 -0400874Build and C API Changes
875=======================
876
Benjamin Petersoncfbd48b2016-09-08 10:27:20 -0700877* Python now requires some C99 support in the toolchain to build. For more
878 information, see :pep:`7`.
879
Brett Cannon63d98bc2016-09-06 17:12:40 -0700880* The ``--with-optimizations`` configure flag has been added. Turning it on
881 will activate LTO and PGO build support (when available).
882 (Original patch by Alecsandru Patrascu of Intel in :issue:`26539`.)
883
Martin Panterb4ce1fc2015-11-30 03:18:29 +0000884* New :c:func:`Py_FinalizeEx` API which indicates if flushing buffered data
885 failed (:issue:`5319`).
Yury Selivanovd1da5072015-05-27 22:09:10 -0400886
Serhiy Storchakaf41b82f2016-06-09 16:30:29 +0300887* :c:func:`PyArg_ParseTupleAndKeywords` now supports :ref:`positional-only
888 parameters <positional-only_parameter>`. Positional-only parameters are
889 defined by empty names.
Berker Peksage807e892016-07-01 12:12:19 +0300890 (Contributed by Serhiy Storchaka in :issue:`26282`).
Serhiy Storchakaf41b82f2016-06-09 16:30:29 +0300891
Nick Coghland0034232016-08-15 13:11:34 +1000892* ``PyTraceback_Print`` method now abbreviates long sequences of repeated lines
893 as ``"[Previous line repeated {count} more times]"``.
894 (Contributed by Emanuel Barry in :issue:`26823`.)
895
Yury Selivanovd1da5072015-05-27 22:09:10 -0400896
897Deprecated
898==========
899
Yury Selivanov7a219112015-05-28 17:10:29 -0400900New Keywords
901------------
902
Yury Selivanov62f27b52015-08-03 14:57:21 -0400903``async`` and ``await`` are not recommended to be used as variable, class,
904function or module names. Introduced by :pep:`492` in Python 3.5, they will
905become proper keywords in Python 3.7.
Yury Selivanov7a219112015-05-28 17:10:29 -0400906
907
Yury Selivanovd1da5072015-05-27 22:09:10 -0400908Deprecated Python modules, functions and methods
909------------------------------------------------
910
Brett Cannon9e080e02016-04-08 12:15:27 -0700911* :meth:`importlib.machinery.SourceFileLoader.load_module` and
912 :meth:`importlib.machinery.SourcelessFileLoader.load_module` are now
913 deprecated. They were the only remaining implementations of
Brett Cannoneae30792015-12-28 17:55:27 -0800914 :meth:`importlib.abc.Loader.load_module` in :mod:`importlib` that had not
915 been deprecated in previous versions of Python in favour of
916 :meth:`importlib.abc.Loader.exec_module`.
Yury Selivanovd1da5072015-05-27 22:09:10 -0400917
918
919Deprecated functions and types of the C API
920-------------------------------------------
921
922* None yet.
923
924
925Deprecated features
926-------------------
927
Brett Cannon9b638682015-10-16 15:14:27 -0700928* The ``pyvenv`` script has been deprecated in favour of ``python3 -m venv``.
929 This prevents confusion as to what Python interpreter ``pyvenv`` is
930 connected to and thus what Python interpreter will be used by the virtual
Brett Cannon63b85052016-01-15 13:33:03 -0800931 environment. (Contributed by Brett Cannon in :issue:`25154`.)
932
933* When performing a relative import, falling back on ``__name__`` and
934 ``__path__`` from the calling module when ``__spec__`` or
935 ``__package__`` are not defined now raises an :exc:`ImportWarning`.
936 (Contributed by Rose Ames in :issue:`25791`.)
Yury Selivanovd1da5072015-05-27 22:09:10 -0400937
Serhiy Storchaka0122ae92016-07-06 12:21:58 +0300938* Unlike to other :mod:`dbm` implementations, the :mod:`dbm.dumb` module
939 creates database in ``'r'`` and ``'w'`` modes if it doesn't exist and
940 allows modifying database in ``'r'`` mode. This behavior is now deprecated
941 and will be removed in 3.8.
942 (Contributed by Serhiy Storchaka in :issue:`21708`.)
Yury Selivanovd1da5072015-05-27 22:09:10 -0400943
Serhiy Storchakad73c3182016-08-06 23:22:08 +0300944* Undocumented support of general :term:`bytes-like objects <bytes-like object>`
Serhiy Storchakafebc3322016-08-06 23:29:29 +0300945 as paths in :mod:`os` functions, :func:`compile` and similar functions is
946 now deprecated.
947 (Contributed by Serhiy Storchaka in :issue:`25791` and :issue:`26754`.)
Serhiy Storchakad73c3182016-08-06 23:22:08 +0300948
Jason R. Coombs5c071c12016-09-01 13:55:33 -0400949* The undocumented ``extra_path`` argument to a distutils Distribution
950 is now considered
951 deprecated, will raise a warning during install if set. Support for this
952 parameter will be dropped in a future Python release and likely earlier
953 through third party tools. See :issue:`27919` for details.
954
Serhiy Storchakad73c3182016-08-06 23:22:08 +0300955
Martin Panter7e3a91a2016-02-10 04:40:48 +0000956Deprecated Python behavior
957--------------------------
958
959* Raising the :exc:`StopIteration` exception inside a generator will now generate a
960 :exc:`DeprecationWarning`, and will trigger a :exc:`RuntimeError` in Python 3.7.
961 See :ref:`whatsnew-pep-479` for details.
962
963
Yury Selivanovd1da5072015-05-27 22:09:10 -0400964Removed
965=======
966
967API and Feature Removals
968------------------------
969
Yury Selivanov56613162015-07-23 17:51:34 +0300970* ``inspect.getmoduleinfo()`` was removed (was deprecated since CPython 3.3).
Yury Selivanov6dfbc5d2015-07-23 17:49:00 +0300971 :func:`inspect.getmodulename` should be used for obtaining the module
972 name for a given path.
973
Senthil Kumaran613065b2016-01-17 20:12:16 -0800974* ``traceback.Ignore`` class and ``traceback.usage``, ``traceback.modname``,
975 ``traceback.fullmodname``, ``traceback.find_lines_from_code``,
976 ``traceback.find_lines``, ``traceback.find_strings``,
977 ``traceback.find_executable_lines`` methods were removed from the
978 :mod:`traceback` module. They were undocumented methods deprecated since
979 Python 3.2 and equivalent functionality is available from private methods.
980
Serhiy Storchaka2e208b72016-05-16 22:35:46 +0300981* The ``tk_menuBar()`` and ``tk_bindForTraversal()`` dummy methods in
982 :mod:`tkinter` widget classes were removed (corresponding Tk commands
983 were obsolete since Tk 4.0).
984
Serhiy Storchakae670be22016-06-11 19:32:44 +0300985* The :meth:`~zipfile.ZipFile.open` method of the :class:`zipfile.ZipFile`
986 class no longer supports the ``'U'`` mode (was deprecated since Python 3.4).
987 Use :class:`io.TextIOWrapper` for reading compressed text files in
988 :term:`universal newlines` mode.
989
Yury Selivanovd1da5072015-05-27 22:09:10 -0400990
991Porting to Python 3.6
992=====================
993
994This section lists previously described changes and other bugfixes
995that may require changes to your code.
996
Serhiy Storchaka7e160ce2016-07-03 21:03:53 +0300997Changes in 'python' Command Behavior
998------------------------------------
999
1000* The output of a special Python build with defined ``COUNT_ALLOCS``,
1001 ``SHOW_ALLOC_COUNT`` or ``SHOW_TRACK_COUNT`` macros is now off by
1002 default. It can be re-enabled using the ``-X showalloccount`` option.
1003 It now outputs to ``stderr`` instead of ``stdout``.
1004 (Contributed by Serhiy Storchaka in :issue:`23034`.)
1005
1006
Yury Selivanovd1da5072015-05-27 22:09:10 -04001007Changes in the Python API
1008-------------------------
1009
Victor Stinnere66987e2016-09-06 16:33:52 -07001010* On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
1011 is initialized to increase the security.
1012
Brett Cannon696c35e2016-06-25 10:58:17 -07001013* When :meth:`importlib.abc.Loader.exec_module` is defined,
1014 :meth:`importlib.abc.Loader.create_module` must also be defined.
1015
Eric Snow46f97b82016-09-07 16:56:15 -07001016* :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg**
1017 argument is not set. Previously only ``NULL`` was returned.
1018
Victor Stinnerf3914eb2016-01-20 12:16:21 +01001019* The format of the ``co_lnotab`` attribute of code objects changed to support
1020 negative line number delta. By default, Python does not emit bytecode with
1021 negative line number delta. Functions using ``frame.f_lineno``,
1022 ``PyFrame_GetLineNumber()`` or ``PyCode_Addr2Line()`` are not affected.
1023 Functions decoding directly ``co_lnotab`` should be updated to use a signed
1024 8-bit integer type for the line number delta, but it's only required to
1025 support applications using negative line number delta. See
1026 ``Objects/lnotab_notes.txt`` for the ``co_lnotab`` format and how to decode
1027 it, and see the :pep:`511` for the rationale.
1028
Brett Cannon1e3c3e92015-12-27 13:17:04 -08001029* The functions in the :mod:`compileall` module now return booleans instead
1030 of ``1`` or ``0`` to represent success or failure, respectively. Thanks to
1031 booleans being a subclass of integers, this should only be an issue if you
1032 were doing identity checks for ``1`` or ``0``. See :issue:`25768`.
1033
Robert Collinsdfa95c92015-08-10 09:53:30 +12001034* Reading the :attr:`~urllib.parse.SplitResult.port` attribute of
1035 :func:`urllib.parse.urlsplit` and :func:`~urllib.parse.urlparse` results
1036 now raises :exc:`ValueError` for out-of-range values, rather than
1037 returning :const:`None`. See :issue:`20059`.
Yury Selivanovd1da5072015-05-27 22:09:10 -04001038
Brett Cannonc0d91af2015-10-16 12:21:37 -07001039* The :mod:`imp` module now raises a :exc:`DeprecationWarning` instead of
1040 :exc:`PendingDeprecationWarning`.
1041
Martin Panter28a465c2015-11-14 12:52:08 +00001042* The following modules have had missing APIs added to their :attr:`__all__`
Martin Panter0d3535a2016-06-06 02:09:08 +00001043 attributes to match the documented APIs:
1044 :mod:`calendar`, :mod:`cgi`, :mod:`csv`,
Martin Panterdcfebb32016-04-01 06:55:55 +00001045 :mod:`~xml.etree.ElementTree`, :mod:`enum`,
Martin Panter0d3535a2016-06-06 02:09:08 +00001046 :mod:`fileinput`, :mod:`ftplib`, :mod:`logging`, :mod:`mailbox`,
1047 :mod:`mimetypes`, :mod:`optparse`, :mod:`plistlib`, :mod:`smtpd`,
1048 :mod:`subprocess`, :mod:`tarfile`, :mod:`threading` and
Martin Panter28a465c2015-11-14 12:52:08 +00001049 :mod:`wave`. This means they will export new symbols when ``import *``
1050 is used. See :issue:`23883`.
1051
Brett Cannon849113a2016-01-22 15:25:50 -08001052* When performing a relative import, if ``__package__`` does not compare equal
1053 to ``__spec__.parent`` then :exc:`ImportWarning` is raised.
1054 (Contributed by Brett Cannon in :issue:`25791`.)
Brett Cannon63b85052016-01-15 13:33:03 -08001055
Brett Cannon9fa81262016-01-22 16:39:02 -08001056* When a relative import is performed and no parent package is known, then
1057 :exc:`ImportError` will be raised. Previously, :exc:`SystemError` could be
Martin Panterd9108d12016-02-21 08:49:56 +00001058 raised. (Contributed by Brett Cannon in :issue:`18018`.)
1059
1060* Servers based on the :mod:`socketserver` module, including those
1061 defined in :mod:`http.server`, :mod:`xmlrpc.server` and
1062 :mod:`wsgiref.simple_server`, now only catch exceptions derived
1063 from :exc:`Exception`. Therefore if a request handler raises
1064 an exception like :exc:`SystemExit` or :exc:`KeyboardInterrupt`,
1065 :meth:`~socketserver.BaseServer.handle_error` is no longer called, and
1066 the exception will stop a single-threaded server. (Contributed by
1067 Martin Panter in :issue:`23430`.)
Brett Cannon9fa81262016-01-22 16:39:02 -08001068
Berker Peksag3c3d7f42016-03-19 11:44:17 +02001069* :func:`spwd.getspnam` now raises a :exc:`PermissionError` instead of
1070 :exc:`KeyError` if the user doesn't have privileges.
Yury Selivanovd1da5072015-05-27 22:09:10 -04001071
Martin Panter50ab1a32016-04-11 00:38:12 +00001072* The :meth:`socket.socket.close` method now raises an exception if
1073 an error (e.g. EBADF) was reported by the underlying system call.
1074 See :issue:`26685`.
1075
Serhiy Storchaka8c740c42016-05-29 23:43:24 +03001076* The *decode_data* argument for :class:`smtpd.SMTPChannel` and
1077 :class:`smtpd.SMTPServer` constructors is now ``False`` by default.
1078 This means that the argument passed to
1079 :meth:`~smtpd.SMTPServer.process_message` is now a bytes object by
1080 default, and ``process_message()`` will be passed keyword arguments.
1081 Code that has already been updated in accordance with the deprecation
1082 warning generated by 3.5 will not be affected.
1083
Serhiy Storchakaaacd53f2016-06-22 00:03:20 +03001084* All optional parameters of the :func:`~json.dump`, :func:`~json.dumps`,
1085 :func:`~json.load` and :func:`~json.loads` functions and
1086 :class:`~json.JSONEncoder` and :class:`~json.JSONDecoder` class
1087 constructors in the :mod:`json` module are now :ref:`keyword-only
1088 <keyword-only_parameter>`.
1089 (Contributed by Serhiy Storchaka in :issue:`18726`.)
1090
Nick Coghlan607e1c42016-07-31 12:42:49 +10001091* As part of :pep:`487`, the handling of keyword arguments passed to
1092 :class:`type` (other than the metaclass hint, ``metaclass``) is now
1093 consistently delegated to :meth:`object.__init_subclass__`. This means that
1094 :meth:`type.__new__` and :meth:`type.__init__` both now accept arbitrary
1095 keyword arguments, but :meth:`object.__init_subclass__` (which is called from
1096 :meth:`type.__new__`) will reject them by default. Custom metaclasses
1097 accepting additional keyword arguments will need to adjust their calls to
1098 :meth:`type.__new__` (whether direct or via :class:`super`) accordingly.
1099
Jason R. Coombsc758d512016-08-21 16:09:27 -04001100* In :class:`distutils.command.sdist.sdist`, the ``default_format``
1101 attribute has been removed and is no longer honored. Instead, the
1102 gzipped tarfile format is the default on all platforms and no
1103 platform-specific selection is made.
1104 In environments where distributions are
1105 built on Windows and zip distributions are required, configure
1106 the project with a ``setup.cfg`` file containing the following::
1107
1108 [sdist]
1109 formats=zip
1110
1111 This behavior has also been backported to earlier Python versions
1112 by Setuptools 26.0.0.
Serhiy Storchakaaacd53f2016-06-22 00:03:20 +03001113
Martin Panteref91bb22016-08-27 01:39:26 +00001114* In the :mod:`urllib.request` module and the
1115 :meth:`http.client.HTTPConnection.request` method, if no Content-Length
1116 header field has been specified and the request body is a file object,
1117 it is now sent with HTTP 1.1 chunked encoding. If a file object has to
1118 be sent to a HTTP 1.0 server, the Content-Length value now has to be
1119 specified by the caller. See :issue:`12319`.
1120
Yury Selivanovd1da5072015-05-27 22:09:10 -04001121Changes in the C API
1122--------------------
1123
Victor Stinnerf5c4b992016-04-22 16:26:23 +02001124* :c:func:`PyMem_Malloc` allocator family now uses the :ref:`pymalloc allocator
1125 <pymalloc>` rather than system :c:func:`malloc`. Applications calling
1126 :c:func:`PyMem_Malloc` without holding the GIL can now crash. Set the
1127 :envvar:`PYTHONMALLOC` environment variable to ``debug`` to validate the
1128 usage of memory allocators in your application. See :issue:`26249`.
1129
Martin Panterb4ce1fc2015-11-30 03:18:29 +00001130* :c:func:`Py_Exit` (and the main interpreter) now override the exit status
1131 with 120 if flushing buffered data failed. See :issue:`5319`.