blob: 1360af79d0731e576d13c539e0c16514b214676a [file] [log] [blame]
Yury Selivanovd1da5072015-05-27 22:09:10 -04001****************************
2 What's New In Python 3.6
3****************************
4
Yury Selivanovf5df7302016-11-07 16:40:20 -05005:Editors: Elvis Pranskevichus <elvis@magic.io>, Yury Selivanov <yury@magic.io>
Yury Selivanovd1da5072015-05-27 22:09:10 -04006
7.. Rules for maintenance:
8
9 * Anyone can add text to this document. Do not spend very much time
10 on the wording of your changes, because your text will probably
11 get rewritten to some degree.
12
13 * The maintainer will go through Misc/NEWS periodically and add
14 changes; it's therefore more important to add your changes to
15 Misc/NEWS than to this file.
16
17 * This is not a complete list of every single change; completeness
18 is the purpose of Misc/NEWS. Some changes I consider too small
19 or esoteric to include. If such a change is added to the text,
20 I'll just remove it. (This is another reason you shouldn't spend
21 too much time on writing your addition.)
22
23 * If you want to draw your new text to the attention of the
24 maintainer, add 'XXX' to the beginning of the paragraph or
25 section.
26
27 * It's OK to just add a fragmentary note about a change. For
28 example: "XXX Describe the transmogrify() function added to the
29 socket module." The maintainer will research the change and
30 write the necessary text.
31
32 * You can comment out your additions if you like, but it's not
33 necessary (especially when a final release is some months away).
34
35 * Credit the author of a patch or bugfix. Just the name is
36 sufficient; the e-mail address isn't necessary.
37
38 * It's helpful to add the bug/patch number as a comment:
39
40 XXX Describe the transmogrify() function added to the socket
41 module.
42 (Contributed by P.Y. Developer in :issue:`12345`.)
43
44 This saves the maintainer the effort of going through the Mercurial log
45 when researching a change.
46
Yury Selivanovf5df7302016-11-07 16:40:20 -050047This article explains the new features in Python 3.6, compared to 3.5.
Ned Deily5c4568a2016-12-22 18:38:47 -050048Python 3.6 was released on December 23, 2016.  See the
49`changelog <https://docs.python.org/3.6/whatsnew/changelog.html>`_ for a full
50list of changes.
Yury Selivanovf5df7302016-11-07 16:40:20 -050051
52.. seealso::
53
54 :pep:`494` - Python 3.6 Release Schedule
Yury Selivanovd1da5072015-05-27 22:09:10 -040055
56
57Summary -- Release highlights
58=============================
59
Paul Moore835416c2016-05-22 12:28:41 +010060New syntax features:
61
Yury Selivanovf5df7302016-11-07 16:40:20 -050062* :ref:`PEP 498 <whatsnew36-pep498>`, formatted string literals.
Guido van Rossum52a7e372016-09-09 09:59:34 -070063
Yury Selivanovf5df7302016-11-07 16:40:20 -050064* :ref:`PEP 515 <whatsnew36-pep515>`, underscores in numeric literals.
Yury Selivanovd1da5072015-05-27 22:09:10 -040065
Yury Selivanovf5df7302016-11-07 16:40:20 -050066* :ref:`PEP 526 <whatsnew36-pep526>`, syntax for variable annotations.
Guido van Rossum52a7e372016-09-09 09:59:34 -070067
Yury Selivanovf5df7302016-11-07 16:40:20 -050068* :ref:`PEP 525 <whatsnew36-pep525>`, asynchronous generators.
Guido van Rossum52a7e372016-09-09 09:59:34 -070069
Yury Selivanovf5df7302016-11-07 16:40:20 -050070* :ref:`PEP 530 <whatsnew36-pep530>`: asynchronous comprehensions.
Guido van Rossum52a7e372016-09-09 09:59:34 -070071
Guido van Rossum52a7e372016-09-09 09:59:34 -070072
Yury Selivanovf5df7302016-11-07 16:40:20 -050073New library modules:
74
75* :mod:`secrets`: :ref:`PEP 506 -- Adding A Secrets Module To The Standard Library <whatsnew36-pep506>`.
76
77
78CPython implementation improvements:
79
80* The :ref:`dict <typesmapping>` type has been reimplemented to use
Victor Stinner83201932016-12-15 16:20:53 +010081 a :ref:`more compact representation <whatsnew36-compactdict>`
Raymond Hettinger51447db2016-12-29 23:49:20 -070082 based on `a proposal by Raymond Hettinger
83 <https://mail.python.org/pipermail/python-dev/2012-December/123028.html>`_
84 and similar to the `PyPy dict implementation`_. This resulted in dictionaries
Yury Selivanovf5df7302016-11-07 16:40:20 -050085 using 20% to 25% less memory when compared to Python 3.5.
86
87* Customization of class creation has been simplified with the
88 :ref:`new protocol <whatsnew36-pep487>`.
89
Yury Selivanov249ba5d2016-11-10 15:39:27 -050090* The class attribute definition order is
Yury Selivanovf5df7302016-11-07 16:40:20 -050091 :ref:`now preserved <whatsnew36-pep520>`.
92
Yury Selivanovc48ec272016-11-10 13:27:22 -050093* The order of elements in ``**kwargs`` now
94 :ref:`corresponds to the order <whatsnew36-pep468>` in which keyword
95 arguments were passed to the function.
Yury Selivanovf5df7302016-11-07 16:40:20 -050096
Yury Selivanovc48ec272016-11-10 13:27:22 -050097* DTrace and SystemTap :ref:`probing support <whatsnew36-tracing>` has
98 been added.
99
100* The new :ref:`PYTHONMALLOC <whatsnew36-pythonmalloc>` environment variable
101 can now be used to debug the interpreter memory allocation and access
102 errors.
Yury Selivanovf5df7302016-11-07 16:40:20 -0500103
104
105Significant improvements in the standard library:
106
Yury Selivanovc48ec272016-11-10 13:27:22 -0500107* The :mod:`asyncio` module has received new features, significant
108 usability and performance improvements, and a fair amount of bug fixes.
109 Starting with Python 3.6 the ``asyncio`` module is no longer provisional
110 and its API is considered stable.
111
Yury Selivanovf5df7302016-11-07 16:40:20 -0500112* A new :ref:`file system path protocol <whatsnew36-pep519>` has been
113 implemented to support :term:`path-like objects <path-like object>`.
114 All standard library functions operating on paths have been updated to
115 work with the new protocol.
116
Yury Selivanovc48ec272016-11-10 13:27:22 -0500117* The :mod:`datetime` module has gained support for
118 :ref:`Local Time Disambiguation <whatsnew36-pep495>`.
119
120* The :mod:`typing` module received a number of
Ned Deily67c1cb22017-01-20 10:13:23 -0500121 :ref:`improvements <whatsnew36-typing>`.
Yury Selivanovc48ec272016-11-10 13:27:22 -0500122
123* The :mod:`tracemalloc` module has been significantly reworked
Yury Selivanov249ba5d2016-11-10 15:39:27 -0500124 and is now used to provide better output for :exc:`ResourceWarning`
Yury Selivanovc48ec272016-11-10 13:27:22 -0500125 as well as provide better diagnostics for memory allocation errors.
126 See the :ref:`PYTHONMALLOC section <whatsnew36-pythonmalloc>` for more
127 information.
Yury Selivanovf5df7302016-11-07 16:40:20 -0500128
Brett Cannon68ed9782016-08-26 14:45:15 -0700129
Victor Stinnere66987e2016-09-06 16:33:52 -0700130Security improvements:
131
Yury Selivanovc48ec272016-11-10 13:27:22 -0500132* The new :mod:`secrets` module has been added to simplify the generation of
133 cryptographically strong pseudo-random numbers suitable for
134 managing secrets such as account authentication, tokens, and similar.
135
Yury Selivanovf5df7302016-11-07 16:40:20 -0500136* On Linux, :func:`os.urandom` now blocks until the system urandom entropy
137 pool is initialized to increase the security. See the :pep:`524` for the
Victor Stinnere66987e2016-09-06 16:33:52 -0700138 rationale.
139
Yury Selivanovf5df7302016-11-07 16:40:20 -0500140* The :mod:`hashlib` and :mod:`ssl` modules now support OpenSSL 1.1.0.
Christian Heimesc4d2e502016-09-12 01:14:35 +0200141
Yury Selivanovf5df7302016-11-07 16:40:20 -0500142* The default settings and feature set of the :mod:`ssl` module have been
143 improved.
Christian Heimesc4d2e502016-09-12 01:14:35 +0200144
Yury Selivanovf5df7302016-11-07 16:40:20 -0500145* The :mod:`hashlib` module received support for the BLAKE2, SHA-3 and SHAKE
146 hash algorithms and the :func:`~hashlib.scrypt` key derivation function.
147
Christian Heimesc4d2e502016-09-12 01:14:35 +0200148
Paul Moore835416c2016-05-22 12:28:41 +0100149Windows improvements:
150
Dmitry Shachnev495e5672018-05-31 01:52:43 +0300151* :ref:`PEP 528 <whatsnew36-pep528>` and :ref:`PEP 529 <whatsnew36-pep529>`,
Yury Selivanovf5df7302016-11-07 16:40:20 -0500152 Windows filesystem and console encoding changed to UTF-8.
Steve Dower39294992016-08-30 21:22:36 -0700153
Paul Moore835416c2016-05-22 12:28:41 +0100154* The ``py.exe`` launcher, when used interactively, no longer prefers
155 Python 2 over Python 3 when the user doesn't specify a version (via
156 command line arguments or a config file). Handling of shebang lines
157 remains unchanged - "python" refers to Python 2 in that case.
158
Steve Dower19ab0fd2016-09-06 20:40:11 -0700159* ``python.exe`` and ``pythonw.exe`` have been marked as long-path aware,
Zachary Ware0425fc02016-11-28 00:19:07 -0600160 which means that the 260 character path limit may no longer apply.
Steve Dower19ab0fd2016-09-06 20:40:11 -0700161 See :ref:`removing the MAX_PATH limitation <max-path>` for details.
162
Steve Dowered51b262016-09-17 12:54:06 -0700163* A ``._pth`` file can be added to force isolated mode and fully specify
Steve Dower3cdd7f52016-09-09 15:22:13 -0700164 all search paths to avoid registry and environment lookup. See
165 :ref:`the documentation <finding_modules>` for more information.
Steve Dowerd8fdffe2016-09-09 15:09:30 -0700166
Steve Dower3cdd7f52016-09-09 15:22:13 -0700167* A ``python36.zip`` file now works as a landmark to infer
168 :envvar:`PYTHONHOME`. See :ref:`the documentation <finding_modules>` for
169 more information.
Steve Dowerd8fdffe2016-09-09 15:09:30 -0700170
Eric Snow68f4dd82016-09-09 11:22:14 -0700171
Yury Selivanovf5df7302016-11-07 16:40:20 -0500172.. _PyPy dict implementation: https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html
173
174
Victor Stinner34be8072016-03-14 12:04:26 +0100175New Features
176============
177
Yury Selivanovf5df7302016-11-07 16:40:20 -0500178.. _whatsnew36-pep498:
179
180PEP 498: Formatted string literals
181----------------------------------
182
183:pep:`498` introduces a new kind of string literals: *f-strings*, or
Yury Selivanovc48ec272016-11-10 13:27:22 -0500184:ref:`formatted string literals <f-strings>`.
Yury Selivanovf5df7302016-11-07 16:40:20 -0500185
186Formatted string literals are prefixed with ``'f'`` and are similar to
187the format strings accepted by :meth:`str.format`. They contain replacement
188fields surrounded by curly braces. The replacement fields are expressions,
189which are evaluated at run time, and then formatted using the
190:func:`format` protocol::
191
192 >>> name = "Fred"
193 >>> f"He said his name is {name}."
194 'He said his name is Fred.'
Yury Selivanovc48ec272016-11-10 13:27:22 -0500195 >>> width = 10
196 >>> precision = 4
197 >>> value = decimal.Decimal("12.34567")
198 >>> f"result: {value:{width}.{precision}}" # nested fields
199 'result: 12.35'
Yury Selivanovf5df7302016-11-07 16:40:20 -0500200
201.. seealso::
202
203 :pep:`498` -- Literal String Interpolation.
204 PEP written and implemented by Eric V. Smith.
205
206 :ref:`Feature documentation <f-strings>`.
207
208
209.. _whatsnew36-pep526:
210
211PEP 526: Syntax for variable annotations
212----------------------------------------
213
214:pep:`484` introduced the standard for type annotations of function
215parameters, a.k.a. type hints. This PEP adds syntax to Python for annotating
216the types of variables including class variables and instance variables::
217
218 primes: List[int] = []
219
220 captain: str # Note: no initial value!
221
222 class Starship:
223 stats: Dict[str, int] = {}
224
225Just as for function annotations, the Python interpreter does not attach any
226particular meaning to variable annotations and only stores them in the
227``__annotations__`` attribute of a class or module.
228
229In contrast to variable declarations in statically typed languages,
230the goal of annotation syntax is to provide an easy way to specify structured
231type metadata for third party tools and libraries via the abstract syntax tree
232and the ``__annotations__`` attribute.
233
234.. seealso::
235
236 :pep:`526` -- Syntax for variable annotations.
237 PEP written by Ryan Gonzalez, Philip House, Ivan Levkivskyi, Lisa Roach,
238 and Guido van Rossum. Implemented by Ivan Levkivskyi.
239
240 Tools that use or will use the new syntax:
Sanyam Khurana1b4587a2017-12-06 22:09:33 +0530241 `mypy <http://www.mypy-lang.org/>`_,
242 `pytype <https://github.com/google/pytype>`_, PyCharm, etc.
Yury Selivanovf5df7302016-11-07 16:40:20 -0500243
244
245.. _whatsnew36-pep515:
Brett Cannona721aba2016-09-09 14:57:09 -0700246
247PEP 515: Underscores in Numeric Literals
Berker Peksag3e492642016-10-08 16:15:15 +0300248----------------------------------------
Brett Cannona721aba2016-09-09 14:57:09 -0700249
Yury Selivanovf5df7302016-11-07 16:40:20 -0500250:pep:`515` adds the ability to use underscores in numeric literals for
251improved readability. For example::
252
253 >>> 1_000_000_000_000_000
254 1000000000000000
255 >>> 0x_FF_FF_FF_FF
256 4294967295
Brett Cannona721aba2016-09-09 14:57:09 -0700257
258Single underscores are allowed between digits and after any base
Yury Selivanovf5df7302016-11-07 16:40:20 -0500259specifier. Leading, trailing, or multiple underscores in a row are not
260allowed.
Brett Cannona721aba2016-09-09 14:57:09 -0700261
Yury Selivanovc48ec272016-11-10 13:27:22 -0500262The :ref:`string formatting <formatspec>` language also now has support
263for the ``'_'`` option to signal the use of an underscore for a thousands
264separator for floating point presentation types and for integer
265presentation type ``'d'``. For integer presentation types ``'b'``,
266``'o'``, ``'x'``, and ``'X'``, underscores will be inserted every 4
267digits::
268
269 >>> '{:_}'.format(1000000)
270 '1_000_000'
271 >>> '{:_x}'.format(0xFFFFFFFF)
272 'ffff_ffff'
273
Brett Cannona721aba2016-09-09 14:57:09 -0700274.. seealso::
275
Ned Deily8761e592016-09-16 15:46:55 -0400276 :pep:`515` -- Underscores in Numeric Literals
Berker Peksagb5d67b72016-09-13 05:52:32 +0300277 PEP written by Georg Brandl and Serhiy Storchaka.
Brett Cannona721aba2016-09-09 14:57:09 -0700278
279
Yury Selivanovf5df7302016-11-07 16:40:20 -0500280.. _whatsnew36-pep525:
Brett Cannon3cebf932016-09-05 15:33:46 -0700281
Yury Selivanovf5df7302016-11-07 16:40:20 -0500282PEP 525: Asynchronous Generators
283--------------------------------
Brett Cannon3cebf932016-09-05 15:33:46 -0700284
Yury Selivanovf5df7302016-11-07 16:40:20 -0500285:pep:`492` introduced support for native coroutines and ``async`` / ``await``
286syntax to Python 3.5. A notable limitation of the Python 3.5 implementation
287is that it was not possible to use ``await`` and ``yield`` in the same
288function body. In Python 3.6 this restriction has been lifted, making it
289possible to define *asynchronous generators*::
Brett Cannon3cebf932016-09-05 15:33:46 -0700290
Yury Selivanovf5df7302016-11-07 16:40:20 -0500291 async def ticker(delay, to):
Yury Selivanov6bf87d32016-11-14 14:49:18 -0500292 """Yield numbers from 0 to *to* every *delay* seconds."""
Yury Selivanovf5df7302016-11-07 16:40:20 -0500293 for i in range(to):
294 yield i
295 await asyncio.sleep(delay)
Brett Cannon3cebf932016-09-05 15:33:46 -0700296
Yury Selivanovf5df7302016-11-07 16:40:20 -0500297The new syntax allows for faster and more concise code.
Brett Cannon3cebf932016-09-05 15:33:46 -0700298
299.. seealso::
300
Yury Selivanovf5df7302016-11-07 16:40:20 -0500301 :pep:`525` -- Asynchronous Generators
302 PEP written and implemented by Yury Selivanov.
Brett Cannon3cebf932016-09-05 15:33:46 -0700303
304
Yury Selivanovf5df7302016-11-07 16:40:20 -0500305.. _whatsnew36-pep530:
306
307PEP 530: Asynchronous Comprehensions
308------------------------------------
309
310:pep:`530` adds support for using ``async for`` in list, set, dict
311comprehensions and generator expressions::
312
313 result = [i async for i in aiter() if i % 2]
314
315Additionally, ``await`` expressions are supported in all kinds
316of comprehensions::
317
Yury Selivanovc48ec272016-11-10 13:27:22 -0500318 result = [await fun() for fun in funcs if await condition()]
Yury Selivanovf5df7302016-11-07 16:40:20 -0500319
320.. seealso::
321
322 :pep:`530` -- Asynchronous Comprehensions
323 PEP written and implemented by Yury Selivanov.
324
325
326.. _whatsnew36-pep487:
327
328PEP 487: Simpler customization of class creation
329------------------------------------------------
330
331It is now possible to customize subclass creation without using a metaclass.
332The new ``__init_subclass__`` classmethod will be called on the base class
333whenever a new subclass is created::
334
Yury Selivanovc48ec272016-11-10 13:27:22 -0500335 class PluginBase:
336 subclasses = []
Yury Selivanovf5df7302016-11-07 16:40:20 -0500337
Yury Selivanovc48ec272016-11-10 13:27:22 -0500338 def __init_subclass__(cls, **kwargs):
339 super().__init_subclass__(**kwargs)
340 cls.subclasses.append(cls)
Yury Selivanovf5df7302016-11-07 16:40:20 -0500341
Yury Selivanovc48ec272016-11-10 13:27:22 -0500342 class Plugin1(PluginBase):
343 pass
344
345 class Plugin2(PluginBase):
346 pass
Yury Selivanovf5df7302016-11-07 16:40:20 -0500347
Nick Coghlan19d24672016-12-05 16:47:55 +1000348In order to allow zero-argument :func:`super` calls to work correctly from
349:meth:`~object.__init_subclass__` implementations, custom metaclasses must
350ensure that the new ``__classcell__`` namespace entry is propagated to
351``type.__new__`` (as described in :ref:`class-object-creation`).
352
Yury Selivanovf5df7302016-11-07 16:40:20 -0500353.. seealso::
354
355 :pep:`487` -- Simpler customization of class creation
356 PEP written and implemented by Martin Teichmann.
357
358 :ref:`Feature documentation <class-customization>`
359
360
361.. _whatsnew36-pep487-descriptors:
362
363PEP 487: Descriptor Protocol Enhancements
364-----------------------------------------
365
Martin Panter59b0eb52016-12-18 01:26:53 +0000366:pep:`487` extends the descriptor protocol to include the new optional
Yury Selivanovc48ec272016-11-10 13:27:22 -0500367:meth:`~object.__set_name__` method. Whenever a new class is defined, the new
368method will be called on all descriptors included in the definition, providing
Yury Selivanovf5df7302016-11-07 16:40:20 -0500369them with a reference to the class being defined and the name given to the
Yury Selivanovc48ec272016-11-10 13:27:22 -0500370descriptor within the class namespace. In other words, instances of
371descriptors can now know the attribute name of the descriptor in the
372owner class::
373
374 class IntField:
375 def __get__(self, instance, owner):
376 return instance.__dict__[self.name]
377
378 def __set__(self, instance, value):
379 if not isinstance(value, int):
380 raise ValueError(f'expecting integer in {self.name}')
381 instance.__dict__[self.name] = value
382
383 # this is the new initializer:
384 def __set_name__(self, owner, name):
385 self.name = name
386
387 class Model:
388 int_field = IntField()
389
Yury Selivanovf5df7302016-11-07 16:40:20 -0500390
391.. seealso::
392
393 :pep:`487` -- Simpler customization of class creation
394 PEP written and implemented by Martin Teichmann.
395
396 :ref:`Feature documentation <descriptors>`
397
398
Yury Selivanovf5df7302016-11-07 16:40:20 -0500399.. _whatsnew36-pep519:
Brett Cannon68ed9782016-08-26 14:45:15 -0700400
401PEP 519: Adding a file system path protocol
Berker Peksagb5d67b72016-09-13 05:52:32 +0300402-------------------------------------------
Brett Cannon68ed9782016-08-26 14:45:15 -0700403
404File system paths have historically been represented as :class:`str`
405or :class:`bytes` objects. This has led to people who write code which
406operate on file system paths to assume that such objects are only one
407of those two types (an :class:`int` representing a file descriptor
408does not count as that is not a file path). Unfortunately that
409assumption prevents alternative object representations of file system
410paths like :mod:`pathlib` from working with pre-existing code,
411including Python's standard library.
412
413To fix this situation, a new interface represented by
414:class:`os.PathLike` has been defined. By implementing the
415:meth:`~os.PathLike.__fspath__` method, an object signals that it
416represents a path. An object can then provide a low-level
417representation of a file system path as a :class:`str` or
418:class:`bytes` object. This means an object is considered
419:term:`path-like <path-like object>` if it implements
420:class:`os.PathLike` or is a :class:`str` or :class:`bytes` object
421which represents a file system path. Code can use :func:`os.fspath`,
422:func:`os.fsdecode`, or :func:`os.fsencode` to explicitly get a
423:class:`str` and/or :class:`bytes` representation of a path-like
424object.
425
426The built-in :func:`open` function has been updated to accept
Martin Pantera2f7ee82016-11-21 13:38:59 +0000427:class:`os.PathLike` objects, as have all relevant functions in the
428:mod:`os` and :mod:`os.path` modules, and most other functions and
Yury Selivanovc48ec272016-11-10 13:27:22 -0500429classes in the standard library. The :class:`os.DirEntry` class
Brett Cannon68ed9782016-08-26 14:45:15 -0700430and relevant classes in :mod:`pathlib` have also been updated to
Brett Cannona5711202016-09-06 19:36:01 -0700431implement :class:`os.PathLike`.
432
Martin Pantera2f7ee82016-11-21 13:38:59 +0000433The hope is that updating the fundamental functions for operating
Brett Cannona5711202016-09-06 19:36:01 -0700434on file system paths will lead to third-party code to implicitly
435support all :term:`path-like objects <path-like object>` without any
Martin Pantera2f7ee82016-11-21 13:38:59 +0000436code changes, or at least very minimal ones (e.g. calling
Brett Cannona5711202016-09-06 19:36:01 -0700437:func:`os.fspath` at the beginning of code before operating on a
438path-like object).
Brett Cannon68ed9782016-08-26 14:45:15 -0700439
440Here are some examples of how the new interface allows for
441:class:`pathlib.Path` to be used more easily and transparently with
442pre-existing code::
443
444 >>> import pathlib
445 >>> with open(pathlib.Path("README")) as f:
446 ... contents = f.read()
447 ...
448 >>> import os.path
449 >>> os.path.splitext(pathlib.Path("some_file.txt"))
450 ('some_file', '.txt')
451 >>> os.path.join("/a/b", pathlib.Path("c"))
452 '/a/b/c'
453 >>> import os
454 >>> os.fspath(pathlib.Path("some_file.txt"))
455 'some_file.txt'
456
457(Implemented by Brett Cannon, Ethan Furman, Dusty Phillips, and Jelle Zijlstra.)
458
459.. seealso::
460
Berker Peksagb5d67b72016-09-13 05:52:32 +0300461 :pep:`519` -- Adding a file system path protocol
Brett Cannon68ed9782016-08-26 14:45:15 -0700462 PEP written by Brett Cannon and Koos Zevenhoven.
463
464
Yury Selivanovc48ec272016-11-10 13:27:22 -0500465.. _whatsnew36-pep495:
466
467PEP 495: Local Time Disambiguation
468----------------------------------
469
470In most world locations, there have been and will be times when local clocks
471are moved back. In those times, intervals are introduced in which local
472clocks show the same time twice in the same day. In these situations, the
473information displayed on a local clock (or stored in a Python datetime
474instance) is insufficient to identify a particular moment in time.
475
476:pep:`495` adds the new *fold* attribute to instances of
477:class:`datetime.datetime` and :class:`datetime.time` classes to differentiate
478between two moments in time for which local times are the same::
479
480 >>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc)
481 >>> for i in range(4):
482 ... u = u0 + i*HOUR
483 ... t = u.astimezone(Eastern)
484 ... print(u.time(), 'UTC =', t.time(), t.tzname(), t.fold)
485 ...
486 04:00:00 UTC = 00:00:00 EDT 0
487 05:00:00 UTC = 01:00:00 EDT 0
488 06:00:00 UTC = 01:00:00 EST 1
489 07:00:00 UTC = 02:00:00 EST 0
490
491The values of the :attr:`fold <datetime.datetime.fold>` attribute have the
Yury Selivanov6bf87d32016-11-14 14:49:18 -0500492value ``0`` for all instances except those that represent the second
Yury Selivanovc48ec272016-11-10 13:27:22 -0500493(chronologically) moment in time in an ambiguous case.
494
495.. seealso::
496
497 :pep:`495` -- Local Time Disambiguation
498 PEP written by Alexander Belopolsky and Tim Peters, implementation
499 by Alexander Belopolsky.
500
501
Yury Selivanovf5df7302016-11-07 16:40:20 -0500502.. _whatsnew36-pep529:
Steve Dowercc16be82016-09-08 10:35:16 -0700503
504PEP 529: Change Windows filesystem encoding to UTF-8
Berker Peksagb5d67b72016-09-13 05:52:32 +0300505----------------------------------------------------
Steve Dowercc16be82016-09-08 10:35:16 -0700506
507Representing filesystem paths is best performed with str (Unicode) rather than
508bytes. However, there are some situations where using bytes is sufficient and
509correct.
510
511Prior to Python 3.6, data loss could result when using bytes paths on Windows.
512With this change, using bytes to represent paths is now supported on Windows,
513provided those bytes are encoded with the encoding returned by
514:func:`sys.getfilesystemencoding()`, which now defaults to ``'utf-8'``.
515
516Applications that do not use str to represent paths should use
517:func:`os.fsencode()` and :func:`os.fsdecode()` to ensure their bytes are
518correctly encoded. To revert to the previous behaviour, set
519:envvar:`PYTHONLEGACYWINDOWSFSENCODING` or call
520:func:`sys._enablelegacywindowsfsencoding`.
521
522See :pep:`529` for more information and discussion of code modifications that
523may be required.
524
Ned Deily8761e592016-09-16 15:46:55 -0400525
Yury Selivanovf5df7302016-11-07 16:40:20 -0500526.. _whatsnew36-pep528:
Steve Dower39294992016-08-30 21:22:36 -0700527
528PEP 528: Change Windows console encoding to UTF-8
529-------------------------------------------------
530
531The default console on Windows will now accept all Unicode characters and
532provide correctly read str objects to Python code. ``sys.stdin``,
533``sys.stdout`` and ``sys.stderr`` now default to utf-8 encoding.
534
535This change only applies when using an interactive console, and not when
536redirecting files or pipes. To revert to the previous behaviour for interactive
Berker Peksag87fa8a72017-05-16 12:36:45 +0300537console use, set :envvar:`PYTHONLEGACYWINDOWSSTDIO`.
Steve Dower39294992016-08-30 21:22:36 -0700538
539.. seealso::
540
541 :pep:`528` -- Change Windows console encoding to UTF-8
542 PEP written and implemented by Steve Dower.
Nick Coghland78448e2016-07-30 16:26:03 +1000543
Yury Selivanovf5df7302016-11-07 16:40:20 -0500544
545.. _whatsnew36-pep520:
546
547PEP 520: Preserving Class Attribute Definition Order
548----------------------------------------------------
549
550Attributes in a class definition body have a natural ordering: the same
551order in which the names appear in the source. This order is now
Yury Selivanovc48ec272016-11-10 13:27:22 -0500552preserved in the new class's :attr:`~object.__dict__` attribute.
Yury Selivanovf5df7302016-11-07 16:40:20 -0500553
554Also, the effective default class *execution* namespace (returned from
Yury Selivanovc48ec272016-11-10 13:27:22 -0500555:ref:`type.__prepare__() <prepare>`) is now an insertion-order-preserving
556mapping.
Yury Selivanovf5df7302016-11-07 16:40:20 -0500557
558.. seealso::
559
560 :pep:`520` -- Preserving Class Attribute Definition Order
561 PEP written and implemented by Eric Snow.
562
563
564.. _whatsnew36-pep468:
565
566PEP 468: Preserving Keyword Argument Order
567------------------------------------------
568
569``**kwargs`` in a function signature is now guaranteed to be an
570insertion-order-preserving mapping.
571
572.. seealso::
573
574 :pep:`468` -- Preserving Keyword Argument Order
575 PEP written and implemented by Eric Snow.
576
577
578.. _whatsnew36-compactdict:
579
580New :ref:`dict <typesmapping>` implementation
581---------------------------------------------
582
583The :ref:`dict <typesmapping>` type now uses a "compact" representation
Raymond Hettinger51447db2016-12-29 23:49:20 -0700584based on `a proposal by Raymond Hettinger
585<https://mail.python.org/pipermail/python-dev/2012-December/123028.html>`_
586which was `first implemented by PyPy
587<https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html>`_.
Yury Selivanovf5df7302016-11-07 16:40:20 -0500588The memory usage of the new :func:`dict` is between 20% and 25% smaller
589compared to Python 3.5.
Yury Selivanovc48ec272016-11-10 13:27:22 -0500590
591The order-preserving aspect of this new implementation is considered an
592implementation detail and should not be relied upon (this may change in
593the future, but it is desired to have this new dict implementation in
594the language for a few releases before changing the language spec to mandate
Yury Selivanovf5df7302016-11-07 16:40:20 -0500595order-preserving semantics for all current and future Python
596implementations; this also helps preserve backwards-compatibility
597with older versions of the language where random iteration order is
598still in effect, e.g. Python 3.5).
Yury Selivanovc48ec272016-11-10 13:27:22 -0500599
Yury Selivanovf5df7302016-11-07 16:40:20 -0500600(Contributed by INADA Naoki in :issue:`27350`. Idea
601`originally suggested by Raymond Hettinger
602<https://mail.python.org/pipermail/python-dev/2012-December/123028.html>`_.)
603
604
605.. _whatsnew36-pep523:
606
607PEP 523: Adding a frame evaluation API to CPython
608-------------------------------------------------
609
610While Python provides extensive support to customize how code
611executes, one place it has not done so is in the evaluation of frame
Yury Selivanovc48ec272016-11-10 13:27:22 -0500612objects. If you wanted some way to intercept frame evaluation in
Yury Selivanovf5df7302016-11-07 16:40:20 -0500613Python there really wasn't any way without directly manipulating
614function pointers for defined functions.
615
616:pep:`523` changes this by providing an API to make frame
617evaluation pluggable at the C level. This will allow for tools such
618as debuggers and JITs to intercept frame evaluation before the
619execution of Python code begins. This enables the use of alternative
620evaluation implementations for Python code, tracking frame
621evaluation, etc.
622
623This API is not part of the limited C API and is marked as private to
624signal that usage of this API is expected to be limited and only
625applicable to very select, low-level use-cases. Semantics of the
626API will change with Python as necessary.
627
628.. seealso::
629
630 :pep:`523` -- Adding a frame evaluation API to CPython
631 PEP written by Brett Cannon and Dino Viehland.
632
633
Yury Selivanovc48ec272016-11-10 13:27:22 -0500634.. _whatsnew36-pythonmalloc:
Yury Selivanovf5df7302016-11-07 16:40:20 -0500635
Victor Stinner34be8072016-03-14 12:04:26 +0100636PYTHONMALLOC environment variable
Berker Peksagb5d67b72016-09-13 05:52:32 +0300637---------------------------------
Victor Stinner34be8072016-03-14 12:04:26 +0100638
Martin Panterdf1d31c2016-06-20 08:00:45 +0000639The new :envvar:`PYTHONMALLOC` environment variable allows setting the Python
Martin Pantera2f7ee82016-11-21 13:38:59 +0000640memory allocators and installing debug hooks.
Victor Stinner34be8072016-03-14 12:04:26 +0100641
642It is now possible to install debug hooks on Python memory allocators on Python
643compiled in release mode using ``PYTHONMALLOC=debug``. Effects of debug hooks:
644
645* Newly allocated memory is filled with the byte ``0xCB``
646* Freed memory is filled with the byte ``0xDB``
Martin Pantera2f7ee82016-11-21 13:38:59 +0000647* Detect violations of the Python memory allocator API. For example,
Victor Stinner34be8072016-03-14 12:04:26 +0100648 :c:func:`PyObject_Free` called on a memory block allocated by
649 :c:func:`PyMem_Malloc`.
Martin Pantera2f7ee82016-11-21 13:38:59 +0000650* Detect writes before the start of a buffer (buffer underflows)
651* Detect writes after the end of a buffer (buffer overflows)
Victor Stinnerc4aec362016-03-14 22:26:53 +0100652* Check that the :term:`GIL <global interpreter lock>` is held when allocator
Victor Stinnerc2fc5682016-03-18 11:04:31 +0100653 functions of :c:data:`PYMEM_DOMAIN_OBJ` (ex: :c:func:`PyObject_Malloc`) and
654 :c:data:`PYMEM_DOMAIN_MEM` (ex: :c:func:`PyMem_Malloc`) domains are called.
655
Victor Stinner9b46a572016-03-18 15:10:43 +0100656Checking if the GIL is held is also a new feature of Python 3.6.
Victor Stinner34be8072016-03-14 12:04:26 +0100657
658See the :c:func:`PyMem_SetupDebugHooks` function for debug hooks on Python
659memory allocators.
660
661It is now also possible to force the usage of the :c:func:`malloc` allocator of
662the C library for all Python memory allocations using ``PYTHONMALLOC=malloc``.
Martin Pantera2f7ee82016-11-21 13:38:59 +0000663This is helpful when using external memory debuggers like Valgrind on
664a Python compiled in release mode.
Victor Stinner34be8072016-03-14 12:04:26 +0100665
Victor Stinner0611c262016-03-15 22:22:13 +0100666On error, the debug hooks on Python memory allocators now use the
667:mod:`tracemalloc` module to get the traceback where a memory block was
668allocated.
669
670Example of fatal error on buffer overflow using
671``python3.6 -X tracemalloc=5`` (store 5 frames in traces)::
672
673 Debug memory block at address p=0x7fbcd41666f8: API 'o'
674 4 bytes originally requested
675 The 7 pad bytes at p-7 are FORBIDDENBYTE, as expected.
676 The 8 pad bytes at tail=0x7fbcd41666fc are not all FORBIDDENBYTE (0xfb):
677 at tail+0: 0x02 *** OUCH
678 at tail+1: 0xfb
679 at tail+2: 0xfb
680 at tail+3: 0xfb
681 at tail+4: 0xfb
682 at tail+5: 0xfb
683 at tail+6: 0xfb
684 at tail+7: 0xfb
685 The block was made by call #1233329 to debug malloc/realloc.
686 Data at p: 1a 2b 30 00
687
688 Memory block allocated at (most recent call first):
689 File "test/test_bytes.py", line 323
690 File "unittest/case.py", line 600
691 File "unittest/case.py", line 648
692 File "unittest/suite.py", line 122
693 File "unittest/suite.py", line 84
694
695 Fatal Python error: bad trailing pad byte
696
697 Current thread 0x00007fbcdbd32700 (most recent call first):
698 File "test/test_bytes.py", line 323 in test_hex
699 File "unittest/case.py", line 600 in run
700 File "unittest/case.py", line 648 in __call__
701 File "unittest/suite.py", line 122 in run
702 File "unittest/suite.py", line 84 in __call__
703 File "unittest/suite.py", line 122 in run
704 File "unittest/suite.py", line 84 in __call__
705 ...
706
707(Contributed by Victor Stinner in :issue:`26516` and :issue:`26564`.)
Victor Stinner34be8072016-03-14 12:04:26 +0100708
709
Yury Selivanovf5df7302016-11-07 16:40:20 -0500710.. _whatsnew36-tracing:
711
Łukasz Langaa785c872016-09-09 17:37:37 -0700712DTrace and SystemTap probing support
713------------------------------------
714
715Python can now be built ``--with-dtrace`` which enables static markers
716for the following events in the interpreter:
717
718* function call/return
719
720* garbage collection started/finished
721
722* line of code executed.
723
724This can be used to instrument running interpreters in production,
725without the need to recompile specific debug builds or providing
726application-specific profiling/debugging code.
727
Benjamin Peterson47503c52016-09-10 17:38:51 -0700728More details in :ref:`instrumentation`.
Łukasz Langaa785c872016-09-09 17:37:37 -0700729
730The current implementation is tested on Linux and macOS. Additional
731markers may be added in the future.
732
733(Contributed by Łukasz Langa in :issue:`21590`, based on patches by
734Jesús Cea Avión, David Malcolm, and Nikhil Benesch.)
735
736
Yury Selivanovd1da5072015-05-27 22:09:10 -0400737Other Language Changes
738======================
739
Nick Coghlan02d03df2016-08-16 10:58:14 +1000740Some smaller changes made to the core Python language are:
741
Yury Selivanovf5df7302016-11-07 16:40:20 -0500742* A ``global`` or ``nonlocal`` statement must now textually appear
743 before the first use of the affected name in the same scope.
744 Previously this was a ``SyntaxWarning``.
Victor Stinner742da042016-09-07 17:40:12 -0700745
Yury Selivanov6bf87d32016-11-14 14:49:18 -0500746* It is now possible to set a :ref:`special method <specialnames>` to
747 ``None`` to indicate that the corresponding operation is not available.
748 For example, if a class sets :meth:`__iter__` to ``None``, the class
749 is not iterable.
750 (Contributed by Andrew Barnert and Ivan Levkivskyi in :issue:`25958`.)
751
Nick Coghlan02d03df2016-08-16 10:58:14 +1000752* Long sequences of repeated traceback lines are now abbreviated as
753 ``"[Previous line repeated {count} more times]"`` (see
Yury Selivanovc48ec272016-11-10 13:27:22 -0500754 :ref:`whatsnew36-traceback` for an example).
Nick Coghlan02d03df2016-08-16 10:58:14 +1000755 (Contributed by Emanuel Barry in :issue:`26823`.)
Yury Selivanovd1da5072015-05-27 22:09:10 -0400756
Eric Snow46f97b82016-09-07 16:56:15 -0700757* Import now raises the new exception :exc:`ModuleNotFoundError`
758 (subclass of :exc:`ImportError`) when it cannot find a module. Code
Martin Pantera2f7ee82016-11-21 13:38:59 +0000759 that currently checks for ImportError (in try-except) will still work.
Yury Selivanovc48ec272016-11-10 13:27:22 -0500760 (Contributed by Eric Snow in :issue:`15767`.)
761
762* Class methods relying on zero-argument ``super()`` will now work correctly
763 when called from metaclass methods during class creation.
764 (Contributed by Martin Teichmann in :issue:`23722`.)
Eric Snow46f97b82016-09-07 16:56:15 -0700765
Yury Selivanovd1da5072015-05-27 22:09:10 -0400766
767New Modules
768===========
769
Yury Selivanovc48ec272016-11-10 13:27:22 -0500770.. _whatsnew36-pep506:
771
Yury Selivanovf5df7302016-11-07 16:40:20 -0500772secrets
773-------
774
Yury Selivanovc48ec272016-11-10 13:27:22 -0500775The main purpose of the new :mod:`secrets` module is to provide an obvious way
776to reliably generate cryptographically strong pseudo-random values suitable
777for managing secrets, such as account authentication, tokens, and similar.
778
779.. warning::
780
781 Note that the pseudo-random generators in the :mod:`random` module
782 should *NOT* be used for security purposes. Use :mod:`secrets`
783 on Python 3.6+ and :func:`os.urandom()` on Python 3.5 and earlier.
784
785.. seealso::
786
787 :pep:`506` -- Adding A Secrets Module To The Standard Library
788 PEP written and implemented by Steven D'Aprano.
Yury Selivanovd1da5072015-05-27 22:09:10 -0400789
790
791Improved Modules
792================
793
Yury Selivanovc48ec272016-11-10 13:27:22 -0500794array
795-----
796
797Exhausted iterators of :class:`array.array` will now stay exhausted even
798if the iterated array is extended. This is consistent with the behavior
799of other mutable sequences.
800
801Contributed by Serhiy Storchaka in :issue:`26492`.
802
803ast
804---
805
806The new :class:`ast.Constant` AST node has been added. It can be used
807by external AST optimizers for the purposes of constant folding.
808
809Contributed by Victor Stinner in :issue:`26146`.
810
811
Yury Selivanovb4a0d522016-05-16 16:25:16 -0400812asyncio
813-------
814
Martin Pantera2f7ee82016-11-21 13:38:59 +0000815Starting with Python 3.6 the ``asyncio`` module is no longer provisional and its
Yury Selivanovc48ec272016-11-10 13:27:22 -0500816API is considered stable.
Yury Selivanovb4a0d522016-05-16 16:25:16 -0400817
Yury Selivanovc48ec272016-11-10 13:27:22 -0500818Notable changes in the :mod:`asyncio` module since Python 3.5.0
819(all backported to 3.5.x due to the provisional status):
820
821* The :func:`~asyncio.get_event_loop` function has been changed to
Mandeep Singhe55de2d2018-05-30 00:07:08 +0530822 always return the currently running loop when called from coroutines
Yury Selivanovc48ec272016-11-10 13:27:22 -0500823 and callbacks.
824 (Contributed by Yury Selivanov in :issue:`28613`.)
Yury Selivanovb4a0d522016-05-16 16:25:16 -0400825
826* The :func:`~asyncio.ensure_future` function and all functions that
827 use it, such as :meth:`loop.run_until_complete() <asyncio.BaseEventLoop.run_until_complete>`,
828 now accept all kinds of :term:`awaitable objects <awaitable>`.
829 (Contributed by Yury Selivanov.)
830
831* New :func:`~asyncio.run_coroutine_threadsafe` function to submit
832 coroutines to event loops from other threads.
833 (Contributed by Vincent Michel.)
834
835* New :meth:`Transport.is_closing() <asyncio.BaseTransport.is_closing>`
836 method to check if the transport is closing or closed.
837 (Contributed by Yury Selivanov.)
838
839* The :meth:`loop.create_server() <asyncio.BaseEventLoop.create_server>`
840 method can now accept a list of hosts.
841 (Contributed by Yann Sionneau.)
842
843* New :meth:`loop.create_future() <asyncio.BaseEventLoop.create_future>`
844 method to create Future objects. This allows alternative event
845 loop implementations, such as
846 `uvloop <https://github.com/MagicStack/uvloop>`_, to provide a faster
847 :class:`asyncio.Future` implementation.
Yury Selivanovc48ec272016-11-10 13:27:22 -0500848 (Contributed by Yury Selivanov in :issue:`27041`.)
Yury Selivanovb4a0d522016-05-16 16:25:16 -0400849
850* New :meth:`loop.get_exception_handler() <asyncio.BaseEventLoop.get_exception_handler>`
851 method to get the current exception handler.
Yury Selivanovc48ec272016-11-10 13:27:22 -0500852 (Contributed by Yury Selivanov in :issue:`27040`.)
Yury Selivanovb4a0d522016-05-16 16:25:16 -0400853
Yury Selivanovb4a0d522016-05-16 16:25:16 -0400854* New :meth:`StreamReader.readuntil() <asyncio.StreamReader.readuntil>`
855 method to read data from the stream until a separator bytes
856 sequence appears.
857 (Contributed by Mark Korenberg.)
858
Yury Selivanovc48ec272016-11-10 13:27:22 -0500859* The performance of :meth:`StreamReader.readexactly() <asyncio.StreamReader.readexactly>`
860 has been improved.
861 (Contributed by Mark Korenberg in :issue:`28370`.)
862
Yury Selivanovb4a0d522016-05-16 16:25:16 -0400863* The :meth:`loop.getaddrinfo() <asyncio.BaseEventLoop.getaddrinfo>`
864 method is optimized to avoid calling the system ``getaddrinfo``
865 function if the address is already resolved.
866 (Contributed by A. Jesse Jiryu Davis.)
867
Yury Selivanov12174702016-12-15 17:56:43 -0500868* The :meth:`loop.stop() <asyncio.BaseEventLoop.stop>`
Yury Selivanovc48ec272016-11-10 13:27:22 -0500869 method has been changed to stop the loop immediately after
870 the current iteration. Any new callbacks scheduled as a result
871 of the last iteration will be discarded.
872 (Contributed by Guido van Rossum in :issue:`25593`.)
873
874* :meth:`Future.set_exception <asyncio.futures.Future.set_exception>`
875 will now raise :exc:`TypeError` when passed an instance of
Martin Pantera2f7ee82016-11-21 13:38:59 +0000876 the :exc:`StopIteration` exception.
Yury Selivanovc48ec272016-11-10 13:27:22 -0500877 (Contributed by Chris Angelico in :issue:`26221`.)
878
Yury Selivanov12174702016-12-15 17:56:43 -0500879* New :meth:`loop.connect_accepted_socket() <asyncio.BaseEventLoop.connect_accepted_socket>`
Yury Selivanovc48ec272016-11-10 13:27:22 -0500880 method to be used by servers that accept connections outside of asyncio,
881 but that use asyncio to handle them.
882 (Contributed by Jim Fulton in :issue:`27392`.)
883
Yury Selivanov3432f2f2016-12-12 16:44:58 -0500884* ``TCP_NODELAY`` flag is now set for all TCP transports by default.
885 (Contributed by Yury Selivanov in :issue:`27456`.)
886
Yury Selivanov12174702016-12-15 17:56:43 -0500887* New :meth:`loop.shutdown_asyncgens() <asyncio.AbstractEventLoop.shutdown_asyncgens>`
888 to properly close pending asynchronous generators before closing the
889 loop.
890 (Contributed by Yury Selivanov in :issue:`28003`.)
891
892* :class:`Future <asyncio.Future>` and :class:`Task <asyncio.Task>`
893 classes now have an optimized C implementation which makes asyncio
894 code up to 30% faster.
895 (Contributed by Yury Selivanov and INADA Naoki in :issue:`26081`
896 and :issue:`28544`.)
897
Yury Selivanovc48ec272016-11-10 13:27:22 -0500898
Yury Selivanovc48ec272016-11-10 13:27:22 -0500899binascii
900--------
901
902The :func:`~binascii.b2a_base64` function now accepts an optional *newline*
903keyword argument to control whether the newline character is appended to the
904return value.
905(Contributed by Victor Stinner in :issue:`25357`.)
906
907
908cmath
909-----
910
Serhiy Storchakadbaf7462017-05-04 12:25:09 +0300911The new :const:`cmath.tau` (*τ*) constant has been added.
Yury Selivanovc48ec272016-11-10 13:27:22 -0500912(Contributed by Lisa Roach in :issue:`12345`, see :pep:`628` for details.)
913
914New constants: :const:`cmath.inf` and :const:`cmath.nan` to
915match :const:`math.inf` and :const:`math.nan`, and also :const:`cmath.infj`
916and :const:`cmath.nanj` to match the format used by complex repr.
917(Contributed by Mark Dickinson in :issue:`23229`.)
918
919
920collections
921-----------
922
Yury Selivanov6bf87d32016-11-14 14:49:18 -0500923The new :class:`~collections.abc.Collection` abstract base class has been
Yury Selivanovc48ec272016-11-10 13:27:22 -0500924added to represent sized iterable container classes.
Yury Selivanov6bf87d32016-11-14 14:49:18 -0500925(Contributed by Ivan Levkivskyi, docs by Neil Girdhar in :issue:`27598`.)
926
927The new :class:`~collections.abc.Reversible` abstract base class represents
Martin Pantera2f7ee82016-11-21 13:38:59 +0000928iterable classes that also provide the :meth:`__reversed__` method.
Yury Selivanov6bf87d32016-11-14 14:49:18 -0500929(Contributed by Ivan Levkivskyi in :issue:`25987`.)
Yury Selivanovc48ec272016-11-10 13:27:22 -0500930
Yury Selivanov22214ab2016-11-16 18:25:04 -0500931The new :class:`~collections.abc.AsyncGenerator` abstract base class represents
932asynchronous generators.
933(Contributed by Yury Selivanov in :issue:`28720`.)
934
Yury Selivanovc48ec272016-11-10 13:27:22 -0500935The :func:`~collections.namedtuple` function now accepts an optional
936keyword argument *module*, which, when specified, is used for
937the ``__module__`` attribute of the returned named tuple class.
938(Contributed by Raymond Hettinger in :issue:`17941`.)
939
940The *verbose* and *rename* arguments for
941:func:`~collections.namedtuple` are now keyword-only.
942(Contributed by Raymond Hettinger in :issue:`25628`.)
943
944Recursive :class:`collections.deque` instances can now be pickled.
945(Contributed by Serhiy Storchaka in :issue:`26482`.)
946
947
948concurrent.futures
949------------------
950
Martin Pantera2f7ee82016-11-21 13:38:59 +0000951The :class:`ThreadPoolExecutor <concurrent.futures.ThreadPoolExecutor>`
Yury Selivanovc48ec272016-11-10 13:27:22 -0500952class constructor now accepts an optional *thread_name_prefix* argument
953to make it possible to customize the names of the threads created by the
954pool.
955(Contributed by Gregory P. Smith in :issue:`27664`.)
956
Yury Selivanovb4a0d522016-05-16 16:25:16 -0400957
Brett Cannon9e080e02016-04-08 12:15:27 -0700958contextlib
959----------
960
961The :class:`contextlib.AbstractContextManager` class has been added to
Yury Selivanovc48ec272016-11-10 13:27:22 -0500962provide an abstract base class for context managers. It provides a
Brett Cannon9e080e02016-04-08 12:15:27 -0700963sensible default implementation for `__enter__()` which returns
Yury Selivanovc48ec272016-11-10 13:27:22 -0500964``self`` and leaves `__exit__()` an abstract method. A matching
Brett Cannon9e080e02016-04-08 12:15:27 -0700965class has been added to the :mod:`typing` module as
966:class:`typing.ContextManager`.
967(Contributed by Brett Cannon in :issue:`25609`.)
968
969
Berker Peksagb6c95722015-10-08 13:58:49 +0300970datetime
971--------
972
Yury Selivanovc48ec272016-11-10 13:27:22 -0500973The :class:`~datetime.datetime` and :class:`~datetime.time` classes have
974the new :attr:`~time.fold` attribute used to disambiguate local time
975when necessary. Many functions in the :mod:`datetime` have been
976updated to support local time disambiguation.
977See :ref:`Local Time Disambiguation <whatsnew36-pep495>` section for more
978information.
979(Contributed by Alexander Belopolsky in :issue:`24773`.)
980
Martin Panterfad4b602015-11-14 01:29:17 +0000981The :meth:`datetime.strftime() <datetime.datetime.strftime>` and
Yury Selivanovc48ec272016-11-10 13:27:22 -0500982:meth:`date.strftime() <datetime.date.strftime>` methods now support
983ISO 8601 date directives ``%G``, ``%u`` and ``%V``.
Berker Peksagb6c95722015-10-08 13:58:49 +0300984(Contributed by Ashley Anderson in :issue:`12006`.)
985
Yury Selivanovc48ec272016-11-10 13:27:22 -0500986The :func:`datetime.isoformat() <datetime.datetime.isoformat>` function
987now accepts an optional *timespec* argument that specifies the number
988of additional components of the time value to include.
989(Contributed by Alessandro Cucci and Alexander Belopolsky in :issue:`19475`.)
Berker Peksagb6c95722015-10-08 13:58:49 +0300990
Yury Selivanovc48ec272016-11-10 13:27:22 -0500991The :meth:`datetime.combine() <datetime.datetime.combine>` now
992accepts an optional *tzinfo* argument.
993(Contributed by Alexander Belopolsky in :issue:`27661`.)
994
995
996decimal
997-------
998
999New :meth:`Decimal.as_integer_ratio() <decimal.Decimal.as_integer_ratio>`
1000method that returns a pair ``(n, d)`` of integers that represent the given
1001:class:`~decimal.Decimal` instance as a fraction, in lowest terms and
1002with a positive denominator::
1003
1004 >>> Decimal('-3.14').as_integer_ratio()
1005 (-157, 50)
1006
1007(Contributed by Stefan Krah amd Mark Dickinson in :issue:`25928`.)
1008
1009
Yury Selivanovc48ec272016-11-10 13:27:22 -05001010
1011distutils
1012---------
Jason R. Coombsc758d512016-08-21 16:09:27 -04001013
1014The ``default_format`` attribute has been removed from
1015:class:`distutils.command.sdist.sdist` and the ``formats``
1016attribute defaults to ``['gztar']``. Although not anticipated,
Martin Pantera2f7ee82016-11-21 13:38:59 +00001017any code relying on the presence of ``default_format`` may
Jason R. Coombsc758d512016-08-21 16:09:27 -04001018need to be adapted. See :issue:`27819` for more details.
1019
1020
R David Murray56b1f1b2016-09-07 16:48:35 -04001021email
1022-----
1023
R David Murray8e7cdb22016-09-07 21:21:58 -04001024The new email API, enabled via the *policy* keyword to various constructors, is
1025no longer provisional. The :mod:`email` documentation has been reorganized and
1026rewritten to focus on the new API, while retaining the old documentation for
1027the legacy API. (Contributed by R. David Murray in :issue:`24277`.)
1028
R David Murray56b1f1b2016-09-07 16:48:35 -04001029The :mod:`email.mime` classes now all accept an optional *policy* keyword.
1030(Contributed by Berker Peksag in :issue:`27331`.)
1031
R David Murray301edfa2016-09-08 17:57:06 -04001032The :class:`~email.generator.DecodedGenerator` now supports the *policy*
1033keyword.
1034
R David Murray06ed2182016-09-09 18:39:18 -04001035There is a new :mod:`~email.policy` attribute,
1036:attr:`~email.policy.Policy.message_factory`, that controls what class is used
1037by default when the parser creates new message objects. For the
1038:attr:`email.policy.compat32` policy this is :class:`~email.message.Message`,
1039for the new policies it is :class:`~email.message.EmailMessage`.
1040(Contributed by R. David Murray in :issue:`20476`.)
1041
R David Murray56b1f1b2016-09-07 16:48:35 -04001042
Steve Dower6cebd482016-09-06 19:55:55 -07001043encodings
1044---------
1045
Martin Pantera2f7ee82016-11-21 13:38:59 +00001046On Windows, added the ``'oem'`` encoding to use ``CP_OEMCP``, and the ``'ansi'``
Steve Dower6cebd482016-09-06 19:55:55 -07001047alias for the existing ``'mbcs'`` encoding, which uses the ``CP_ACP`` code page.
Yury Selivanovc48ec272016-11-10 13:27:22 -05001048(Contributed by Steve Dower in :issue:`27959`.)
1049
1050
1051enum
1052----
1053
1054Two new enumeration base classes have been added to the :mod:`enum` module:
1055:class:`~enum.Flag` and :class:`~enum.IntFlags`. Both are used to define
1056constants that can be combined using the bitwise operators.
1057(Contributed by Ethan Furman in :issue:`23591`.)
1058
1059Many standard library modules have been updated to use the
1060:class:`~enum.IntFlags` class for their constants.
1061
1062The new :class:`enum.auto` value can be used to assign values to enum
1063members automatically::
1064
1065 >>> from enum import Enum, auto
1066 >>> class Color(Enum):
1067 ... red = auto()
1068 ... blue = auto()
1069 ... green = auto()
1070 ...
1071 >>> list(Color)
1072 [<Color.red: 1>, <Color.blue: 2>, <Color.green: 3>]
Steve Dower6cebd482016-09-06 19:55:55 -07001073
R David Murray301edfa2016-09-08 17:57:06 -04001074
Victor Stinner404cdc52016-03-23 10:39:17 +01001075faulthandler
1076------------
1077
Serhiy Storchakab6a9c972016-04-17 09:39:28 +03001078On Windows, the :mod:`faulthandler` module now installs a handler for Windows
Victor Stinner404cdc52016-03-23 10:39:17 +01001079exceptions: see :func:`faulthandler.enable`. (Contributed by Victor Stinner in
1080:issue:`23848`.)
1081
1082
Yury Selivanovc48ec272016-11-10 13:27:22 -05001083fileinput
1084---------
1085
1086:func:`~fileinput.hook_encoded` now supports the *errors* argument.
1087(Contributed by Joseph Hackman in :issue:`25788`.)
1088
1089
Christian Heimesc4d2e502016-09-12 01:14:35 +02001090hashlib
1091-------
1092
Yury Selivanovc48ec272016-11-10 13:27:22 -05001093:mod:`hashlib` supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2.
Christian Heimesc4d2e502016-09-12 01:14:35 +02001094(Contributed by Christian Heimes in :issue:`26470`.)
1095
1096BLAKE2 hash functions were added to the module. :func:`~hashlib.blake2b`
1097and :func:`~hashlib.blake2s` are always available and support the full
1098feature set of BLAKE2.
1099(Contributed by Christian Heimes in :issue:`26798` based on code by
1100Dmitry Chestnykh and Samuel Neves. Documentation written by Dmitry Chestnykh.)
1101
1102The SHA-3 hash functions :func:`~hashlib.sha3_224`, :func:`~hashlib.sha3_256`,
1103:func:`~hashlib.sha3_384`, :func:`~hashlib.sha3_512`, and SHAKE hash functions
1104:func:`~hashlib.shake_128` and :func:`~hashlib.shake_256` were added.
1105(Contributed by Christian Heimes in :issue:`16113`. Keccak Code Package
1106by Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche, and
1107Ronny Van Keer.)
1108
1109The password-based key derivation function :func:`~hashlib.scrypt` is now
1110available with OpenSSL 1.1.0 and newer.
1111(Contributed by Christian Heimes in :issue:`27928`.)
1112
Martin Panter3c0d0ba2016-08-24 06:33:33 +00001113http.client
1114-----------
1115
1116:meth:`HTTPConnection.request() <http.client.HTTPConnection.request>` and
1117:meth:`~http.client.HTTPConnection.endheaders` both now support
1118chunked encoding request bodies.
1119(Contributed by Demian Brecht and Rolf Krahl in :issue:`12319`.)
1120
1121
Terry Jan Reedyd9792a02016-06-13 00:41:53 -04001122idlelib and IDLE
1123----------------
1124
Yury Selivanovc48ec272016-11-10 13:27:22 -05001125The idlelib package is being modernized and refactored to make IDLE look and
1126work better and to make the code easier to understand, test, and improve. Part
1127of making IDLE look better, especially on Linux and Mac, is using ttk widgets,
1128mostly in the dialogs. As a result, IDLE no longer runs with tcl/tk 8.4. It
1129now requires tcl/tk 8.5 or 8.6. We recommend running the latest release of
1130either.
Terry Jan Reedyd9792a02016-06-13 00:41:53 -04001131
Yury Selivanovc48ec272016-11-10 13:27:22 -05001132'Modernizing' includes renaming and consolidation of idlelib modules. The
1133renaming of files with partial uppercase names is similar to the renaming of,
1134for instance, Tkinter and TkFont to tkinter and tkinter.font in 3.0. As a
1135result, imports of idlelib files that worked in 3.5 will usually not work in
11363.6. At least a module name change will be needed (see idlelib/README.txt),
1137sometimes more. (Name changes contributed by Al Swiegart and Terry Reedy in
1138:issue:`24225`. Most idlelib patches since have been and will be part of the
1139process.)
Terry Jan Reedyd9792a02016-06-13 00:41:53 -04001140
Yury Selivanovc48ec272016-11-10 13:27:22 -05001141In compensation, the eventual result with be that some idlelib classes will be
1142easier to use, with better APIs and docstrings explaining them. Additional
1143useful information will be added to idlelib when available.
Terry Jan Reedyd9792a02016-06-13 00:41:53 -04001144
Terry Jan Reedye226eb72018-06-10 14:03:40 -04001145New in 3.6.2:
1146
1147Multiple fixes for autocompletion. (Contributed by Louie Lu in :issue:`15786`.)
1148
1149New in 3.6.3:
1150
1151Module Browser (on the File menu, formerly called Class Browser),
1152now displays nested functions and classes in addition to top-level
1153functions and classes.
1154(Contributed by Guilherme Polo, Cheryl Sabella, and Terry Jan Reedy
1155in :issue:`1612262`.)
1156
1157The IDLE features formerly implemented as extensions have been reimplemented
1158as normal features. Their settings have been moved from the Extensions tab
1159to other dialog tabs.
1160(Contributed by Charles Wohlganger and Terry Jan Reedy in :issue:`27099`.)
1161
1162The Settings dialog (Options, Configure IDLE) has been partly rewritten
1163to improve both appearance and function.
1164(Contributed by Cheryl Sabella and Terry Jan Reedy in multiple issues.)
1165
1166New in 3.6.4:
1167
1168The font sample now includes a selection of non-Latin characters so that
1169users can better see the effect of selecting a particular font.
1170(Contributed by Terry Jan Reedy in :issue:`13802`.)
1171The sample can be edited to include other characters.
1172(Contributed by Serhiy Storchaka in :issue:`31860`.)
1173
1174New in 3.6.6:
1175
1176Editor code context option revised. Box displays all context lines up to
1177maxlines. Clicking on a context line jumps the editor to that line. Context
1178colors for custom themes is added to Highlights tab of Settings dialog.
1179(Contributed by Cheryl Sabella and Terry Jan Reedy in :issue:`33642`,
Terry Jan Reedy820c53a2018-06-10 14:57:38 -04001180:issue:`33768`, and :issue:`33679`)
Terry Jan Reedye226eb72018-06-10 14:03:40 -04001181
Terry Jan Reedy800415e2018-06-11 14:14:32 -04001182On Windows, a new API call tells Windows that tk scales for DPI. On Windows
11838.1+ or 10, with DPI compatibility properties of the Python binary
1184unchanged, and a monitor resolution greater than 96 DPI, this should
1185make text and lines sharper. It should otherwise have no effect.
1186(Contributed by Terry Jan Reedy in :issue:`33656`).
1187
Terry Jan Reedyd9792a02016-06-13 00:41:53 -04001188
Brett Cannon696c35e2016-06-25 10:58:17 -07001189importlib
1190---------
1191
Yury Selivanovc48ec272016-11-10 13:27:22 -05001192Import now raises the new exception :exc:`ModuleNotFoundError`
1193(subclass of :exc:`ImportError`) when it cannot find a module. Code
1194that current checks for ``ImportError`` (in try-except) will still work.
1195(Contributed by Eric Snow in :issue:`15767`.)
1196
Brett Cannon696c35e2016-06-25 10:58:17 -07001197:class:`importlib.util.LazyLoader` now calls
1198:meth:`~importlib.abc.Loader.create_module` on the wrapped loader, removing the
1199restriction that :class:`importlib.machinery.BuiltinImporter` and
1200:class:`importlib.machinery.ExtensionFileLoader` couldn't be used with
1201:class:`importlib.util.LazyLoader`.
1202
Brett Cannon035a1002016-09-07 18:39:18 -07001203:func:`importlib.util.cache_from_source`,
1204:func:`importlib.util.source_from_cache`, and
1205:func:`importlib.util.spec_from_file_location` now accept a
1206:term:`path-like object`.
1207
Brett Cannon696c35e2016-06-25 10:58:17 -07001208
Yury Selivanovc48ec272016-11-10 13:27:22 -05001209inspect
1210-------
1211
1212The :func:`inspect.signature() <inspect.signature>` function now reports the
1213implicit ``.0`` parameters generated by the compiler for comprehension and
1214generator expression scopes as if they were positional-only parameters called
1215``implicit0``. (Contributed by Jelle Zijlstra in :issue:`19611`.)
1216
Nick Coghlan3c35fdb2016-12-02 20:29:57 +10001217To reduce code churn when upgrading from Python 2.7 and the legacy
1218:func:`inspect.getargspec` API, the previously documented deprecation of
1219:func:`inspect.getfullargspec` has been reversed. While this function is
1220convenient for single/source Python 2/3 code bases, the richer
1221:func:`inspect.signature` interface remains the recommended approach for new
1222code. (Contributed by Nick Coghlan in :issue:`27172`)
1223
Yury Selivanovc48ec272016-11-10 13:27:22 -05001224
Nick Coghlanb1615622016-09-10 20:16:18 +10001225json
1226----
1227
1228:func:`json.load` and :func:`json.loads` now support binary input. Encoded
1229JSON should be represented using either UTF-8, UTF-16, or UTF-32.
1230(Contributed by Serhiy Storchaka in :issue:`17909`.)
1231
1232
Yury Selivanovc48ec272016-11-10 13:27:22 -05001233logging
1234-------
1235
1236The new :meth:`WatchedFileHandler.reopenIfNeeded() <logging.handlers.WatchedFileHandler.reopenIfNeeded>`
1237method has been added to add the ability to check if the log file needs to
1238be reopened.
1239(Contributed by Marian Horban in :issue:`24884`.)
1240
1241
1242math
1243----
1244
Serhiy Storchakadbaf7462017-05-04 12:25:09 +03001245The tau (*τ*) constant has been added to the :mod:`math` and :mod:`cmath`
Yury Selivanovc48ec272016-11-10 13:27:22 -05001246modules.
1247(Contributed by Lisa Roach in :issue:`12345`, see :pep:`628` for details.)
1248
1249
1250multiprocessing
1251---------------
1252
1253:ref:`Proxy Objects <multiprocessing-proxy_objects>` returned by
1254:func:`multiprocessing.Manager` can now be nested.
1255(Contributed by Davin Potts in :issue:`6766`.)
1256
1257
Serhiy Storchakaffe96ae2016-02-11 13:21:30 +02001258os
1259--
1260
Martin Pantera2f7ee82016-11-21 13:38:59 +00001261See the summary of :ref:`PEP 519 <whatsnew36-pep519>` for details on how the
Yury Selivanovc48ec272016-11-10 13:27:22 -05001262:mod:`os` and :mod:`os.path` modules now support
1263:term:`path-like objects <path-like object>`.
1264
Serhiy Storchaka3c38e062016-11-20 08:23:07 +02001265:func:`~os.scandir` now supports :class:`bytes` paths on Windows.
1266
Serhiy Storchakaffe96ae2016-02-11 13:21:30 +02001267A new :meth:`~os.scandir.close` method allows explicitly closing a
1268:func:`~os.scandir` iterator. The :func:`~os.scandir` iterator now
1269supports the :term:`context manager` protocol. If a :func:`scandir`
1270iterator is neither exhausted nor explicitly closed a :exc:`ResourceWarning`
1271will be emitted in its destructor.
1272(Contributed by Serhiy Storchaka in :issue:`25994`.)
1273
Yury Selivanovf5df7302016-11-07 16:40:20 -05001274On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
1275is initialized to increase the security. See the :pep:`524` for the rationale.
1276
Victor Stinner9b1f4742016-09-06 16:18:52 -07001277The Linux ``getrandom()`` syscall (get random bytes) is now exposed as the new
1278:func:`os.getrandom` function.
1279(Contributed by Victor Stinner, part of the :pep:`524`)
1280
Yury Selivanovc48ec272016-11-10 13:27:22 -05001281
1282pathlib
1283-------
1284
1285:mod:`pathlib` now supports :term:`path-like objects <path-like object>`.
1286(Contributed by Brett Cannon in :issue:`27186`.)
1287
Martin Pantera2f7ee82016-11-21 13:38:59 +00001288See the summary of :ref:`PEP 519 <whatsnew36-pep519>` for details.
Yury Selivanovc48ec272016-11-10 13:27:22 -05001289
1290
1291pdb
1292---
1293
1294The :class:`~pdb.Pdb` class constructor has a new optional *readrc* argument
1295to control whether ``.pdbrc`` files should be read.
Brett Cannon035a1002016-09-07 18:39:18 -07001296
1297
Serhiy Storchaka0d554d72015-10-10 22:42:18 +03001298pickle
1299------
1300
Martin Pantera2f7ee82016-11-21 13:38:59 +00001301Objects that need ``__new__`` called with keyword arguments can now be pickled
Serhiy Storchaka0d554d72015-10-10 22:42:18 +03001302using :ref:`pickle protocols <pickle-protocols>` older than protocol version 4.
1303Protocol version 4 already supports this case. (Contributed by Serhiy
1304Storchaka in :issue:`24164`.)
1305
1306
Yury Selivanovc48ec272016-11-10 13:27:22 -05001307pickletools
1308-----------
1309
Martin Pantera2f7ee82016-11-21 13:38:59 +00001310:func:`pickletools.dis()` now outputs the implicit memo index for the
Yury Selivanovc48ec272016-11-10 13:27:22 -05001311``MEMOIZE`` opcode.
1312(Contributed by Serhiy Storchaka in :issue:`25382`.)
1313
1314
1315pydoc
1316-----
1317
1318The :mod:`pydoc` module has learned to respect the ``MANPAGER``
1319environment variable.
1320(Contributed by Matthias Klose in :issue:`8637`.)
1321
1322:func:`help` and :mod:`pydoc` can now list named tuple fields in the
1323order they were defined rather than alphabetically.
1324(Contributed by Raymond Hettinger in :issue:`24879`.)
1325
1326
1327random
1328-------
1329
1330The new :func:`~random.choices` function returns a list of elements of
1331specified size from the given population with optional weights.
1332(Contributed by Raymond Hettinger in :issue:`18844`.)
1333
1334
Serhiy Storchakabe9a4e52016-09-10 00:57:55 +03001335re
1336--
1337
1338Added support of modifier spans in regular expressions. Examples:
1339``'(?i:p)ython'`` matches ``'python'`` and ``'Python'``, but not ``'PYTHON'``;
1340``'(?i)g(?-i:v)r'`` matches ``'GvR'`` and ``'gvr'``, but not ``'GVR'``.
1341(Contributed by Serhiy Storchaka in :issue:`433028`.)
1342
Eric V. Smithb5690862016-09-11 09:50:47 -04001343Match object groups can be accessed by ``__getitem__``, which is
1344equivalent to ``group()``. So ``mo['name']`` is now equivalent to
1345``mo.group('name')``. (Contributed by Eric Smith in :issue:`24454`.)
1346
Martin Pantera2f7ee82016-11-21 13:38:59 +00001347:class:`~re.Match` objects now support
Yury Selivanovc48ec272016-11-10 13:27:22 -05001348:meth:`index-like objects <object.__index__>` as group
1349indices.
1350(Contributed by Jeroen Demeyer and Xiang Zhang in :issue:`27177`.)
1351
Serhiy Storchakabe9a4e52016-09-10 00:57:55 +03001352
Martin Panterf0dbf7a2016-05-15 01:26:25 +00001353readline
1354--------
1355
1356Added :func:`~readline.set_auto_history` to enable or disable
1357automatic addition of input to the history list. (Contributed by
1358Tyler Crompton in :issue:`26870`.)
1359
1360
Martin Panterfad4b602015-11-14 01:29:17 +00001361rlcompleter
1362-----------
Serhiy Storchakaab824222015-09-27 13:43:50 +03001363
1364Private and special attribute names now are omitted unless the prefix starts
Martin Panterfad4b602015-11-14 01:29:17 +00001365with underscores. A space or a colon is added after some completed keywords.
Serhiy Storchakaab824222015-09-27 13:43:50 +03001366(Contributed by Serhiy Storchaka in :issue:`25011` and :issue:`25209`.)
1367
1368
Yury Selivanovc48ec272016-11-10 13:27:22 -05001369shlex
1370-----
1371
1372The :class:`~shlex.shlex` has much
1373:ref:`improved shell compatibility <improved-shell-compatibility>`
1374through the new *punctuation_chars* argument to control which characters
1375are treated as punctuation.
1376(Contributed by Vinay Sajip in :issue:`1521950`.)
1377
1378
Brett Cannon5f0507d2016-04-08 15:04:28 -07001379site
1380----
1381
1382When specifying paths to add to :attr:`sys.path` in a `.pth` file,
1383you may now specify file paths on top of directories (e.g. zip files).
1384(Contributed by Wolfgang Langner in :issue:`26587`).
1385
1386
Berker Peksage0b70cd2016-06-14 15:25:36 +03001387sqlite3
1388-------
1389
Berker Peksagb84fd042016-09-07 01:07:06 +03001390:attr:`sqlite3.Cursor.lastrowid` now supports the ``REPLACE`` statement.
1391(Contributed by Alex LordThorsen in :issue:`16864`.)
Berker Peksage0b70cd2016-06-14 15:25:36 +03001392
1393
Steve Dowerea93ac02016-06-17 12:52:18 -07001394socket
1395------
1396
Yury Selivanovc48ec272016-11-10 13:27:22 -05001397The :func:`~socket.socket.ioctl` function now supports the
1398:data:`~socket.SIO_LOOPBACK_FAST_PATH` control code.
Steve Dowerea93ac02016-06-17 12:52:18 -07001399(Contributed by Daniel Stokes in :issue:`26536`.)
1400
R David Murraybdfa0eb2016-08-23 21:12:40 -04001401The :meth:`~socket.socket.getsockopt` constants ``SO_DOMAIN``,
1402``SO_PROTOCOL``, ``SO_PEERSEC``, and ``SO_PASSSEC`` are now supported.
1403(Contributed by Christian Heimes in :issue:`26907`.)
1404
Yury Selivanovc48ec272016-11-10 13:27:22 -05001405The :meth:`~socket.socket.setsockopt` now supports the
1406``setsockopt(level, optname, None, optlen: int)`` form.
Martin Pantera2f7ee82016-11-21 13:38:59 +00001407(Contributed by Christian Heimes in :issue:`27744`.)
Yury Selivanovc48ec272016-11-10 13:27:22 -05001408
Christian Heimesc4d2e502016-09-12 01:14:35 +02001409The socket module now supports the address family
1410:data:`~socket.AF_ALG` to interface with Linux Kernel crypto API. ``ALG_*``,
1411``SOL_ALG`` and :meth:`~socket.socket.sendmsg_afalg` were added.
1412(Contributed by Christian Heimes in :issue:`27744` with support from
1413Victor Stinner.)
Steve Dowerea93ac02016-06-17 12:52:18 -07001414
Victor Stinner01f5ae72017-01-23 12:30:00 +01001415New Linux constants ``TCP_USER_TIMEOUT`` and ``TCP_CONGESTION`` were added.
1416(Contributed by Omar Sandoval, issue:`26273`).
1417
Yury Selivanovc48ec272016-11-10 13:27:22 -05001418
Martin Panter0cab9c12016-04-13 00:36:52 +00001419socketserver
1420------------
1421
1422Servers based on the :mod:`socketserver` module, including those
1423defined in :mod:`http.server`, :mod:`xmlrpc.server` and
1424:mod:`wsgiref.simple_server`, now support the :term:`context manager`
1425protocol.
1426(Contributed by Aviv Palivoda in :issue:`26404`.)
1427
Martin Panter34eeed42016-06-29 10:12:22 +00001428The :attr:`~socketserver.StreamRequestHandler.wfile` attribute of
1429:class:`~socketserver.StreamRequestHandler` classes now implements
1430the :class:`io.BufferedIOBase` writable interface. In particular,
1431calling :meth:`~io.BufferedIOBase.write` is now guaranteed to send the
1432data in full. (Contributed by Martin Panter in :issue:`26721`.)
1433
Yury Selivanovc48ec272016-11-10 13:27:22 -05001434
Christian Heimesc4d2e502016-09-12 01:14:35 +02001435ssl
1436---
1437
Yury Selivanovc48ec272016-11-10 13:27:22 -05001438:mod:`ssl` supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2.
Christian Heimesc4d2e502016-09-12 01:14:35 +02001439(Contributed by Christian Heimes in :issue:`26470`.)
1440
14413DES has been removed from the default cipher suites and ChaCha20 Poly1305
Yury Selivanovc48ec272016-11-10 13:27:22 -05001442cipher suites have been added.
Christian Heimesc4d2e502016-09-12 01:14:35 +02001443(Contributed by Christian Heimes in :issue:`27850` and :issue:`27766`.)
1444
1445:class:`~ssl.SSLContext` has better default configuration for options
1446and ciphers.
1447(Contributed by Christian Heimes in :issue:`28043`.)
1448
1449SSL session can be copied from one client-side connection to another
Yury Selivanovc48ec272016-11-10 13:27:22 -05001450with the new :class:`~ssl.SSLSession` class. TLS session resumption can
1451speed up the initial handshake, reduce latency and improve performance
Christian Heimesc4d2e502016-09-12 01:14:35 +02001452(Contributed by Christian Heimes in :issue:`19500` based on a draft by
1453Alex Warhawk.)
1454
Yury Selivanovc48ec272016-11-10 13:27:22 -05001455The new :meth:`~ssl.SSLContext.get_ciphers` method can be used to
1456get a list of enabled ciphers in order of cipher priority.
1457
Christian Heimesc4d2e502016-09-12 01:14:35 +02001458All constants and flags have been converted to :class:`~enum.IntEnum` and
1459:class:`~enum.IntFlags`.
1460(Contributed by Christian Heimes in :issue:`28025`.)
1461
1462Server and client-side specific TLS protocols for :class:`~ssl.SSLContext`
1463were added.
1464(Contributed by Christian Heimes in :issue:`28085`.)
1465
Yury Selivanovc48ec272016-11-10 13:27:22 -05001466
1467statistics
1468----------
1469
1470A new :func:`~statistics.harmonic_mean` function has been added.
1471(Contributed by Steven D'Aprano in :issue:`27181`.)
1472
1473
1474struct
1475------
1476
1477:mod:`struct` now supports IEEE 754 half-precision floats via the ``'e'``
1478format specifier.
1479(Contributed by Eli Stevens, Mark Dickinson in :issue:`11734`.)
1480
1481
Victor Stinner5a48e212016-05-20 12:11:15 +02001482subprocess
1483----------
1484
1485:class:`subprocess.Popen` destructor now emits a :exc:`ResourceWarning` warning
1486if the child process is still running. Use the context manager protocol (``with
Martin Pantera2f7ee82016-11-21 13:38:59 +00001487proc: ...``) or explicitly call the :meth:`~subprocess.Popen.wait` method to
1488read the exit status of the child process. (Contributed by Victor Stinner in
1489:issue:`26741`.)
Victor Stinner5a48e212016-05-20 12:11:15 +02001490
Steve Dower050acae2016-09-06 20:16:17 -07001491The :class:`subprocess.Popen` constructor and all functions that pass arguments
1492through to it now accept *encoding* and *errors* arguments. Specifying either
1493of these will enable text mode for the *stdin*, *stdout* and *stderr* streams.
Yury Selivanovc48ec272016-11-10 13:27:22 -05001494(Contributed by Steve Dower in :issue:`6135`.)
1495
1496
1497sys
1498---
1499
1500The new :func:`~sys.getfilesystemencodeerrors` function returns the name of
1501the error mode used to convert between Unicode filenames and bytes filenames.
1502(Contributed by Steve Dower in :issue:`27781`.)
1503
1504On Windows the return value of the :func:`~sys.getwindowsversion` function
1505now includes the *platform_version* field which contains the accurate major
1506version, minor version and build number of the current operating system,
1507rather than the version that is being emulated for the process
1508(Contributed by Steve Dower in :issue:`27932`.)
1509
Victor Stinner5a48e212016-05-20 12:11:15 +02001510
R David Murray4f098062015-11-28 12:24:52 -05001511telnetlib
1512---------
1513
1514:class:`~telnetlib.Telnet` is now a context manager (contributed by
1515Stéphane Wirtel in :issue:`25485`).
1516
1517
Yury Selivanovc48ec272016-11-10 13:27:22 -05001518time
1519----
1520
1521The :class:`~time.struct_time` attributes :attr:`tm_gmtoff` and
1522:attr:`tm_zone` are now available on all platforms.
1523
1524
1525timeit
1526------
1527
1528The new :meth:`Timer.autorange() <timeit.Timer.autorange>` convenience
1529method has been added to call :meth:`Timer.timeit() <timeit.Timer.timeit>`
1530repeatedly so that the total run time is greater or equal to 200 milliseconds.
1531(Contributed by Steven D'Aprano in :issue:`6422`.)
1532
1533:mod:`timeit` now warns when there is substantial (4x) variance
1534between best and worst times.
1535(Contributed by Serhiy Storchaka in :issue:`23552`.)
1536
1537
Serhiy Storchaka81221742016-06-26 09:46:57 +03001538tkinter
1539-------
1540
1541Added methods :meth:`~tkinter.Variable.trace_add`,
1542:meth:`~tkinter.Variable.trace_remove` and :meth:`~tkinter.Variable.trace_info`
1543in the :class:`tkinter.Variable` class. They replace old methods
1544:meth:`~tkinter.Variable.trace_variable`, :meth:`~tkinter.Variable.trace`,
1545:meth:`~tkinter.Variable.trace_vdelete` and
1546:meth:`~tkinter.Variable.trace_vinfo` that use obsolete Tcl commands and might
1547not work in future versions of Tcl.
1548(Contributed by Serhiy Storchaka in :issue:`22115`).
1549
1550
Yury Selivanovc48ec272016-11-10 13:27:22 -05001551.. _whatsnew36-traceback:
Nick Coghlan02d03df2016-08-16 10:58:14 +10001552
Nick Coghland0034232016-08-15 13:11:34 +10001553traceback
1554---------
1555
Nick Coghlan02d03df2016-08-16 10:58:14 +10001556Both the traceback module and the interpreter's builtin exception display now
1557abbreviate long sequences of repeated lines in tracebacks as shown in the
1558following example::
1559
1560 >>> def f(): f()
1561 ...
1562 >>> f()
1563 Traceback (most recent call last):
1564 File "<stdin>", line 1, in <module>
1565 File "<stdin>", line 1, in f
1566 File "<stdin>", line 1, in f
1567 File "<stdin>", line 1, in f
1568 [Previous line repeated 995 more times]
1569 RecursionError: maximum recursion depth exceeded
1570
Nick Coghland0034232016-08-15 13:11:34 +10001571(Contributed by Emanuel Barry in :issue:`26823`.)
1572
1573
Yury Selivanovc48ec272016-11-10 13:27:22 -05001574tracemalloc
1575-----------
1576
1577The :mod:`tracemalloc` module now supports tracing memory allocations in
1578multiple different address spaces.
1579
1580The new :class:`~tracemalloc.DomainFilter` filter class has been added
1581to filter block traces by their address space (domain).
1582
1583(Contributed by Victor Stinner in :issue:`26588`.)
1584
1585
1586.. _whatsnew36-typing:
1587
Brett Cannon9e080e02016-04-08 12:15:27 -07001588typing
1589------
1590
Ned Deily67c1cb22017-01-20 10:13:23 -05001591Since the :mod:`typing` module is :term:`provisional <provisional api>`,
1592all changes introduced in Python 3.6 have also been
Yury Selivanovc48ec272016-11-10 13:27:22 -05001593backported to Python 3.5.x.
1594
Yury Selivanov6bf87d32016-11-14 14:49:18 -05001595The :mod:`typing` module has a much improved support for generic type
1596aliases. For example ``Dict[str, Tuple[S, T]]`` is now a valid
1597type annotation.
1598(Contributed by Guido van Rossum in `Github #195
1599<https://github.com/python/typing/pull/195>`_.)
1600
Brett Cannon9e080e02016-04-08 12:15:27 -07001601The :class:`typing.ContextManager` class has been added for
1602representing :class:`contextlib.AbstractContextManager`.
1603(Contributed by Brett Cannon in :issue:`25609`.)
1604
Yury Selivanovc48ec272016-11-10 13:27:22 -05001605The :class:`typing.Collection` class has been added for
1606representing :class:`collections.abc.Collection`.
1607(Contributed by Ivan Levkivskyi in :issue:`27598`.)
1608
1609The :const:`typing.ClassVar` type construct has been added to
1610mark class variables. As introduced in :pep:`526`, a variable annotation
1611wrapped in ClassVar indicates that a given attribute is intended to be used as
1612a class variable and should not be set on instances of that class.
1613(Contributed by Ivan Levkivskyi in `Github #280
Sanyam Khurana338cd832018-01-20 05:55:37 +05301614<https://github.com/python/typing/pull/280>`_.)
Yury Selivanovc48ec272016-11-10 13:27:22 -05001615
1616A new :const:`~typing.TYPE_CHECKING` constant that is assumed to be
1617``True`` by the static type chekers, but is ``False`` at runtime.
1618(Contributed by Guido van Rossum in `Github #230
1619<https://github.com/python/typing/issues/230>`_.)
1620
1621A new :func:`~typing.NewType` helper function has been added to create
1622lightweight distinct types for annotations::
1623
1624 from typing import NewType
1625
1626 UserId = NewType('UserId', int)
1627 some_id = UserId(524313)
1628
1629The static type checker will treat the new type as if it were a subclass
1630of the original type. (Contributed by Ivan Levkivskyi in `Github #189
1631<https://github.com/python/typing/issues/189>`_.)
1632
Brett Cannon9e080e02016-04-08 12:15:27 -07001633
Benjamin Peterson67752312016-09-14 23:53:47 -07001634unicodedata
1635-----------
1636
Yury Selivanovc48ec272016-11-10 13:27:22 -05001637The :mod:`unicodedata` module now uses data from `Unicode 9.0.0
1638<http://unicode.org/versions/Unicode9.0.0/>`_.
1639(Contributed by Benjamin Peterson.)
Benjamin Peterson67752312016-09-14 23:53:47 -07001640
1641
Victor Stinner2c2a4e62016-03-11 22:17:48 +01001642unittest.mock
1643-------------
1644
1645The :class:`~unittest.mock.Mock` class has the following improvements:
1646
1647* Two new methods, :meth:`Mock.assert_called()
1648 <unittest.mock.Mock.assert_called>` and :meth:`Mock.assert_called_once()
1649 <unittest.mock.Mock.assert_called_once>` to check if the mock object
1650 was called.
1651 (Contributed by Amit Saha in :issue:`26323`.)
1652
Yury Selivanovc48ec272016-11-10 13:27:22 -05001653* The :meth:`Mock.reset_mock() <unittest.mock.Mock.reset_mock>` method
1654 now has two optional keyword only arguments: *return_value* and
1655 *side_effect*.
1656 (Contributed by Kushal Das in :issue:`21271`.)
1657
Victor Stinner2c2a4e62016-03-11 22:17:48 +01001658
Martin Panter3c0d0ba2016-08-24 06:33:33 +00001659urllib.request
1660--------------
1661
Martin Panteref91bb22016-08-27 01:39:26 +00001662If a HTTP request has a file or iterable body (other than a
Yury Selivanovc48ec272016-11-10 13:27:22 -05001663bytes object) but no ``Content-Length`` header, rather than
Martin Panter3c0d0ba2016-08-24 06:33:33 +00001664throwing an error, :class:`~urllib.request.AbstractHTTPHandler` now
1665falls back to use chunked transfer encoding.
1666(Contributed by Demian Brecht and Rolf Krahl in :issue:`12319`.)
1667
1668
Berker Peksag960e8482015-10-08 12:27:06 +03001669urllib.robotparser
1670------------------
1671
Martin Panterfad4b602015-11-14 01:29:17 +00001672:class:`~urllib.robotparser.RobotFileParser` now supports the ``Crawl-delay`` and
Berker Peksag960e8482015-10-08 12:27:06 +03001673``Request-rate`` extensions.
1674(Contributed by Nikolay Bogoychev in :issue:`16099`.)
1675
1676
Yury Selivanovc48ec272016-11-10 13:27:22 -05001677venv
1678----
1679
1680:mod:`venv` accepts a new parameter ``--prompt``. This parameter provides an
1681alternative prefix for the virtual environment. (Proposed by Łukasz Balcerzak
1682and ported to 3.6 by Stéphane Wirtel in :issue:`22829`.)
1683
1684
Victor Stinner914cde82016-03-19 01:03:51 +01001685warnings
1686--------
1687
1688A new optional *source* parameter has been added to the
1689:func:`warnings.warn_explicit` function: the destroyed object which emitted a
1690:exc:`ResourceWarning`. A *source* attribute has also been added to
1691:class:`warnings.WarningMessage` (contributed by Victor Stinner in
1692:issue:`26568` and :issue:`26567`).
1693
Martin Pantera2f7ee82016-11-21 13:38:59 +00001694When a :exc:`ResourceWarning` warning is logged, the :mod:`tracemalloc` module is now
1695used to try to retrieve the traceback where the destroyed object was allocated.
Victor Stinner914cde82016-03-19 01:03:51 +01001696
1697Example with the script ``example.py``::
1698
Victor Stinneree803a82016-03-19 10:33:25 +01001699 import warnings
Victor Stinner914cde82016-03-19 01:03:51 +01001700
Victor Stinneree803a82016-03-19 10:33:25 +01001701 def func():
1702 return open(__file__)
1703
1704 f = func()
1705 f = None
Victor Stinner914cde82016-03-19 01:03:51 +01001706
1707Output of the command ``python3.6 -Wd -X tracemalloc=5 example.py``::
1708
Victor Stinneree803a82016-03-19 10:33:25 +01001709 example.py:7: ResourceWarning: unclosed file <_io.TextIOWrapper name='example.py' mode='r' encoding='UTF-8'>
Victor Stinner914cde82016-03-19 01:03:51 +01001710 f = None
1711 Object allocated at (most recent call first):
Victor Stinneree803a82016-03-19 10:33:25 +01001712 File "example.py", lineno 4
1713 return open(__file__)
1714 File "example.py", lineno 6
1715 f = func()
Victor Stinner914cde82016-03-19 01:03:51 +01001716
Martin Pantera2f7ee82016-11-21 13:38:59 +00001717The "Object allocated at" traceback is new and is only displayed if
Victor Stinneree803a82016-03-19 10:33:25 +01001718:mod:`tracemalloc` is tracing Python memory allocations and if the
Martin Pantera2f7ee82016-11-21 13:38:59 +00001719:mod:`warnings` module was already imported.
Victor Stinner914cde82016-03-19 01:03:51 +01001720
1721
Steve Dower80ac11d2016-05-24 15:42:04 -07001722winreg
1723------
1724
Steve Dower4d4bc422016-05-25 11:26:07 -07001725Added the 64-bit integer type :data:`REG_QWORD <winreg.REG_QWORD>`.
Steve Dower80ac11d2016-05-24 15:42:04 -07001726(Contributed by Clement Rouault in :issue:`23026`.)
1727
1728
Zachary Warec4018812016-09-06 16:32:43 -05001729winsound
1730--------
1731
1732Allowed keyword arguments to be passed to :func:`Beep <winsound.Beep>`,
1733:func:`MessageBeep <winsound.MessageBeep>`, and :func:`PlaySound
1734<winsound.PlaySound>` (:issue:`27982`).
1735
1736
Serhiy Storchaka352601c2016-09-11 11:23:38 +03001737xmlrpc.client
1738-------------
1739
Yury Selivanovc48ec272016-11-10 13:27:22 -05001740The :mod:`xmlrpc.client` module now supports unmarshalling
Martin Pantera2f7ee82016-11-21 13:38:59 +00001741additional data types used by the Apache XML-RPC implementation
Yury Selivanovc48ec272016-11-10 13:27:22 -05001742for numerics and ``None``.
Serhiy Storchaka352601c2016-09-11 11:23:38 +03001743(Contributed by Serhiy Storchaka in :issue:`26885`.)
1744
1745
Serhiy Storchaka503f9082016-02-08 00:02:25 +02001746zipfile
1747-------
1748
1749A new :meth:`ZipInfo.from_file() <zipfile.ZipInfo.from_file>` class method
Martin Panter288ed032016-02-10 05:45:55 +00001750allows making a :class:`~zipfile.ZipInfo` instance from a filesystem file.
Serhiy Storchaka503f9082016-02-08 00:02:25 +02001751A new :meth:`ZipInfo.is_dir() <zipfile.ZipInfo.is_dir>` method can be used
1752to check if the :class:`~zipfile.ZipInfo` instance represents a directory.
1753(Contributed by Thomas Kluyver in :issue:`26039`.)
1754
Serhiy Storchaka18ee29d2016-05-13 13:52:49 +03001755The :meth:`ZipFile.open() <zipfile.ZipFile.open>` method can now be used to
1756write data into a ZIP file, as well as for extracting data.
1757(Contributed by Thomas Kluyver in :issue:`26039`.)
1758
Serhiy Storchaka503f9082016-02-08 00:02:25 +02001759
Martin Panter1fe0d132016-02-10 10:06:36 +00001760zlib
1761----
1762
Yury Selivanovc48ec272016-11-10 13:27:22 -05001763The :func:`~zlib.compress` and :func:`~zlib.decompress` functions now accept
1764keyword arguments.
1765(Contributed by Aviv Palivoda in :issue:`26243` and
1766Xiang Zhang in :issue:`16764` respectively.)
Serhiy Storchakab2752102016-04-27 23:13:46 +03001767
1768
Yury Selivanovd1da5072015-05-27 22:09:10 -04001769Optimizations
1770=============
1771
Martin Pantera2f7ee82016-11-21 13:38:59 +00001772* The Python interpreter now uses a 16-bit wordcode instead of bytecode which
Yury Selivanovc48ec272016-11-10 13:27:22 -05001773 made a number of opcode optimizations possible.
1774 (Contributed by Demur Rumed with input and reviews from
1775 Serhiy Storchaka and Victor Stinner in :issue:`26647` and :issue:`28050`.)
1776
Yury Selivanov12174702016-12-15 17:56:43 -05001777* The :class:`asyncio.Future` class now has an optimized C implementation.
1778 (Contributed by Yury Selivanov and INADA Naoki in :issue:`26081`.)
Yury Selivanovc48ec272016-11-10 13:27:22 -05001779
Yury Selivanov12174702016-12-15 17:56:43 -05001780* The :class:`asyncio.Task` class now has an optimized
Yury Selivanovc48ec272016-11-10 13:27:22 -05001781 C implementation. (Contributed by Yury Selivanov in :issue:`28544`.)
1782
Yury Selivanov6bf87d32016-11-14 14:49:18 -05001783* Various implementation improvements in the :mod:`typing` module
1784 (such as caching of generic types) allow up to 30 times performance
1785 improvements and reduced memory footprint.
1786
Martin Panterfad4b602015-11-14 01:29:17 +00001787* The ASCII decoder is now up to 60 times as fast for error handlers
Victor Stinnerebcf9ed2015-10-14 10:10:00 +02001788 ``surrogateescape``, ``ignore`` and ``replace`` (Contributed
1789 by Victor Stinner in :issue:`24870`).
Yury Selivanovd1da5072015-05-27 22:09:10 -04001790
Terry Jan Reedy6dc9ce12015-10-20 01:07:53 -04001791* The ASCII and the Latin1 encoders are now up to 3 times as fast for the
Yury Selivanov6bf87d32016-11-14 14:49:18 -05001792 error handler ``surrogateescape``
1793 (Contributed by Victor Stinner in :issue:`25227`).
Victor Stinnerc3713e92015-09-29 12:32:13 +02001794
Martin Panterfad4b602015-11-14 01:29:17 +00001795* The UTF-8 encoder is now up to 75 times as fast for error handlers
Victor Stinnerebcf9ed2015-10-14 10:10:00 +02001796 ``ignore``, ``replace``, ``surrogateescape``, ``surrogatepass`` (Contributed
1797 by Victor Stinner in :issue:`25267`).
Victor Stinner01ada392015-10-01 21:54:51 +02001798
Martin Panterfad4b602015-11-14 01:29:17 +00001799* The UTF-8 decoder is now up to 15 times as fast for error handlers
Victor Stinnerebcf9ed2015-10-14 10:10:00 +02001800 ``ignore``, ``replace`` and ``surrogateescape`` (Contributed
1801 by Victor Stinner in :issue:`25301`).
1802
1803* ``bytes % args`` is now up to 2 times faster. (Contributed by Victor Stinner
1804 in :issue:`25349`).
1805
1806* ``bytearray % args`` is now between 2.5 and 5 times faster. (Contributed by
1807 Victor Stinner in :issue:`25399`).
Victor Stinner1d65d912015-10-05 13:43:50 +02001808
Victor Stinner2bf89932015-10-14 11:25:33 +02001809* Optimize :meth:`bytes.fromhex` and :meth:`bytearray.fromhex`: they are now
1810 between 2x and 3.5x faster. (Contributed by Victor Stinner in :issue:`25401`).
1811
Victor Stinnerfac39562016-03-21 10:38:58 +01001812* Optimize ``bytes.replace(b'', b'.')`` and ``bytearray.replace(b'', b'.')``:
1813 up to 80% faster. (Contributed by Josh Snider in :issue:`26574`).
1814
Victor Stinner8153ac82016-04-24 22:33:26 +02001815* Allocator functions of the :c:func:`PyMem_Malloc` domain
1816 (:c:data:`PYMEM_DOMAIN_MEM`) now use the :ref:`pymalloc memory allocator
1817 <pymalloc>` instead of :c:func:`malloc` function of the C library. The
1818 pymalloc allocator is optimized for objects smaller or equal to 512 bytes
1819 with a short lifetime, and use :c:func:`malloc` for larger memory blocks.
1820 (Contributed by Victor Stinner in :issue:`26249`).
1821
Victor Stinner19ed27e2016-05-20 11:42:37 +02001822* :func:`pickle.load` and :func:`pickle.loads` are now up to 10% faster when
1823 deserializing many small objects (Contributed by Victor Stinner in
1824 :issue:`27056`).
Yury Selivanovd1da5072015-05-27 22:09:10 -04001825
Martin Pantera2f7ee82016-11-21 13:38:59 +00001826* Passing :term:`keyword arguments <keyword argument>` to a function has an
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001827 overhead in comparison with passing :term:`positional arguments
1828 <positional argument>`. Now in extension functions implemented with using
1829 Argument Clinic this overhead is significantly decreased.
1830 (Contributed by Serhiy Storchaka in :issue:`27574`).
1831
Serhiy Storchaka28ab6342016-09-06 22:33:41 +03001832* Optimized :func:`~glob.glob` and :func:`~glob.iglob` functions in the
1833 :mod:`glob` module; they are now about 3--6 times faster.
1834 (Contributed by Serhiy Storchaka in :issue:`25596`).
1835
Serhiy Storchaka680cb152016-09-07 10:58:05 +03001836* Optimized globbing in :mod:`pathlib` by using :func:`os.scandir`;
1837 it is now about 1.5--4 times faster.
1838 (Contributed by Serhiy Storchaka in :issue:`26032`).
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001839
Yury Selivanovc48ec272016-11-10 13:27:22 -05001840* :class:`xml.etree.ElementTree` parsing, iteration and deepcopy performance
1841 has been significantly improved.
1842 (Contributed by Serhiy Storchaka in :issue:`25638`, :issue:`25873`,
1843 and :issue:`25869`.)
1844
1845* Creation of :class:`fractions.Fraction` instances from floats and
1846 decimals is now 2 to 3 times faster.
1847 (Contributed by Serhiy Storchaka in :issue:`25971`.)
1848
Yury Selivanovf5df7302016-11-07 16:40:20 -05001849
Yury Selivanovd1da5072015-05-27 22:09:10 -04001850Build and C API Changes
1851=======================
1852
Yury Selivanovc48ec272016-11-10 13:27:22 -05001853* Python now requires some C99 support in the toolchain to build.
1854 Most notably, Python now uses standard integer types and macros in
1855 place of custom macros like ``PY_LONG_LONG``.
1856 For more information, see :pep:`7` and :issue:`17884`.
Benjamin Petersoncfbd48b2016-09-08 10:27:20 -07001857
Xavier de Gaye032c0fb2016-09-13 18:04:15 +02001858* Cross-compiling CPython with the Android NDK and the Android API level set to
Xtreakc151f782018-06-16 10:38:31 +05301859 21 (Android 5.0 Lollipop) or greater runs successfully. While Android is not
Xavier de Gaye032c0fb2016-09-13 18:04:15 +02001860 yet a supported platform, the Python test suite runs on the Android emulator
1861 with only about 16 tests failures. See the Android meta-issue :issue:`26865`.
1862
Gregory P. Smith2863c382016-11-21 00:12:40 -08001863* The ``--enable-optimizations`` configure flag has been added. Turning it on
Brett Cannon1d8f7552016-11-03 16:20:00 -07001864 will activate expensive optimizations like PGO.
Martin Panterced4b902017-01-11 11:56:22 +00001865 (Original patch by Alecsandru Patrascu of Intel in :issue:`26359`.)
Brett Cannon63d98bc2016-09-06 17:12:40 -07001866
Yury Selivanovc48ec272016-11-10 13:27:22 -05001867* The :term:`GIL <global interpreter lock>` must now be held when allocator
1868 functions of :c:data:`PYMEM_DOMAIN_OBJ` (ex: :c:func:`PyObject_Malloc`) and
1869 :c:data:`PYMEM_DOMAIN_MEM` (ex: :c:func:`PyMem_Malloc`) domains are called.
1870
Martin Panterb4ce1fc2015-11-30 03:18:29 +00001871* New :c:func:`Py_FinalizeEx` API which indicates if flushing buffered data
Yury Selivanovc48ec272016-11-10 13:27:22 -05001872 failed.
1873 (Contributed by Martin Panter in :issue:`5319`.)
Yury Selivanovd1da5072015-05-27 22:09:10 -04001874
Serhiy Storchakaf41b82f2016-06-09 16:30:29 +03001875* :c:func:`PyArg_ParseTupleAndKeywords` now supports :ref:`positional-only
1876 parameters <positional-only_parameter>`. Positional-only parameters are
1877 defined by empty names.
Berker Peksage807e892016-07-01 12:12:19 +03001878 (Contributed by Serhiy Storchaka in :issue:`26282`).
Serhiy Storchakaf41b82f2016-06-09 16:30:29 +03001879
Nick Coghland0034232016-08-15 13:11:34 +10001880* ``PyTraceback_Print`` method now abbreviates long sequences of repeated lines
1881 as ``"[Previous line repeated {count} more times]"``.
1882 (Contributed by Emanuel Barry in :issue:`26823`.)
1883
Yury Selivanovc48ec272016-11-10 13:27:22 -05001884* The new :c:func:`PyErr_SetImportErrorSubclass` function allows for
1885 specifying a subclass of :exc:`ImportError` to raise.
1886 (Contributed by Eric Snow in :issue:`15767`.)
1887
1888* The new :c:func:`PyErr_ResourceWarning` function can be used to generate
Martin Pantera2f7ee82016-11-21 13:38:59 +00001889 a :exc:`ResourceWarning` providing the source of the resource allocation.
Yury Selivanovc48ec272016-11-10 13:27:22 -05001890 (Contributed by Victor Stinner in :issue:`26567`.)
1891
1892* The new :c:func:`PyOS_FSPath` function returns the file system
1893 representation of a :term:`path-like object`.
1894 (Contributed by Brett Cannon in :issue:`27186`.)
1895
1896* The :c:func:`PyUnicode_FSConverter` and :c:func:`PyUnicode_FSDecoder`
1897 functions will now accept :term:`path-like objects <path-like object>`.
1898
1899
INADA Naokif5763432016-11-24 17:20:40 +09001900Other Improvements
1901==================
1902
1903* When :option:`--version` (short form: :option:`-V`) is supplied twice,
1904 Python prints :data:`sys.version` for detailed information.
1905
1906 .. code-block:: shell-session
1907
1908 $ ./python -VV
1909 Python 3.6.0b4+ (3.6:223967b49e49+, Nov 21 2016, 20:55:04)
1910 [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
1911
Yury Selivanovd1da5072015-05-27 22:09:10 -04001912
1913Deprecated
1914==========
1915
Yury Selivanov7a219112015-05-28 17:10:29 -04001916New Keywords
1917------------
1918
Yury Selivanov62f27b52015-08-03 14:57:21 -04001919``async`` and ``await`` are not recommended to be used as variable, class,
1920function or module names. Introduced by :pep:`492` in Python 3.5, they will
Yury Selivanovc48ec272016-11-10 13:27:22 -05001921become proper keywords in Python 3.7. Starting in Python 3.6, the use of
1922``async`` or ``await`` as names will generate a :exc:`DeprecationWarning`.
Christian Heimesc4d2e502016-09-12 01:14:35 +02001923
Serhiy Storchakad73c3182016-08-06 23:22:08 +03001924
Martin Panter7e3a91a2016-02-10 04:40:48 +00001925Deprecated Python behavior
1926--------------------------
1927
Yury Selivanovc48ec272016-11-10 13:27:22 -05001928Raising the :exc:`StopIteration` exception inside a generator will now
1929generate a :exc:`DeprecationWarning`, and will trigger a :exc:`RuntimeError`
1930in Python 3.7. See :ref:`whatsnew-pep-479` for details.
1931
1932The :meth:`__aiter__` method is now expected to return an asynchronous
1933iterator directly instead of returning an awaitable as previously.
1934Doing the former will trigger a :exc:`DeprecationWarning`. Backward
1935compatibility will be removed in Python 3.7.
1936(Contributed by Yury Selivanov in :issue:`27243`.)
1937
1938A backslash-character pair that is not a valid escape sequence now generates
1939a :exc:`DeprecationWarning`. Although this will eventually become a
1940:exc:`SyntaxError`, that will not be for several Python releases.
1941(Contributed by Emanuel Barry in :issue:`27364`.)
1942
1943When performing a relative import, falling back on ``__name__`` and
1944``__path__`` from the calling module when ``__spec__`` or
1945``__package__`` are not defined now raises an :exc:`ImportWarning`.
1946(Contributed by Rose Ames in :issue:`25791`.)
1947
1948
1949Deprecated Python modules, functions and methods
1950------------------------------------------------
1951
1952asynchat
1953~~~~~~~~
1954
1955The :mod:`asynchat` has been deprecated in favor of :mod:`asyncio`.
1956(Contributed by Mariatta in :issue:`25002`.)
1957
1958
1959asyncore
1960~~~~~~~~
1961
1962The :mod:`asyncore` has been deprecated in favor of :mod:`asyncio`.
1963(Contributed by Mariatta in :issue:`25002`.)
1964
1965
1966dbm
1967~~~
1968
1969Unlike other :mod:`dbm` implementations, the :mod:`dbm.dumb` module
1970creates databases with the ``'rw'`` mode and allows modifying the database
1971opened with the ``'r'`` mode. This behavior is now deprecated and will
1972be removed in 3.8.
1973(Contributed by Serhiy Storchaka in :issue:`21708`.)
1974
1975
1976distutils
1977~~~~~~~~~
1978
1979The undocumented ``extra_path`` argument to the
1980:class:`~distutils.Distribution` constructor is now considered deprecated
1981and will raise a warning if set. Support for this parameter will be
1982removed in a future Python release. See :issue:`27919` for details.
1983
1984
1985grp
1986~~~
1987
1988The support of non-integer arguments in :func:`~grp.getgrgid` has been
1989deprecated.
1990(Contributed by Serhiy Storchaka in :issue:`26129`.)
1991
1992
1993importlib
1994~~~~~~~~~
1995
1996The :meth:`importlib.machinery.SourceFileLoader.load_module` and
1997:meth:`importlib.machinery.SourcelessFileLoader.load_module` methods
1998are now deprecated. They were the only remaining implementations of
1999:meth:`importlib.abc.Loader.load_module` in :mod:`importlib` that had not
2000been deprecated in previous versions of Python in favour of
2001:meth:`importlib.abc.Loader.exec_module`.
2002
Steve Dower20367422016-12-07 13:02:27 -08002003The :class:`importlib.machinery.WindowsRegistryFinder` class is now
2004deprecated. As of 3.6.0, it is still added to :attr:`sys.meta_path` by
2005default (on Windows), but this may change in future releases.
2006
Yury Selivanovc48ec272016-11-10 13:27:22 -05002007os
2008~~
2009
2010Undocumented support of general :term:`bytes-like objects <bytes-like object>`
2011as paths in :mod:`os` functions, :func:`compile` and similar functions is
2012now deprecated.
2013(Contributed by Serhiy Storchaka in :issue:`25791` and :issue:`26754`.)
2014
2015re
2016~~
2017
2018Support for inline flags ``(?letters)`` in the middle of the regular
2019expression has been deprecated and will be removed in a future Python
2020version. Flags at the start of a regular expression are still allowed.
2021(Contributed by Serhiy Storchaka in :issue:`22493`.)
2022
2023ssl
2024~~~
2025
2026OpenSSL 0.9.8, 1.0.0 and 1.0.1 are deprecated and no longer supported.
2027In the future the :mod:`ssl` module will require at least OpenSSL 1.0.2 or
20281.1.0.
2029
2030SSL-related arguments like ``certfile``, ``keyfile`` and ``check_hostname``
2031in :mod:`ftplib`, :mod:`http.client`, :mod:`imaplib`, :mod:`poplib`,
2032and :mod:`smtplib` have been deprecated in favor of ``context``.
2033(Contributed by Christian Heimes in :issue:`28022`.)
2034
2035A couple of protocols and functions of the :mod:`ssl` module are now
2036deprecated. Some features will no longer be available in future versions
2037of OpenSSL. Other features are deprecated in favor of a different API.
2038(Contributed by Christian Heimes in :issue:`28022` and :issue:`26470`.)
2039
2040tkinter
2041~~~~~~~
2042
2043The :mod:`tkinter.tix` module is now deprecated. :mod:`tkinter` users
2044should use :mod:`tkinter.ttk` instead.
2045
2046venv
2047~~~~
2048
2049The ``pyvenv`` script has been deprecated in favour of ``python3 -m venv``.
2050This prevents confusion as to what Python interpreter ``pyvenv`` is
2051connected to and thus what Python interpreter will be used by the virtual
2052environment. (Contributed by Brett Cannon in :issue:`25154`.)
2053
2054
2055Deprecated functions and types of the C API
2056-------------------------------------------
2057
2058Undocumented functions :c:func:`PyUnicode_AsEncodedObject`,
2059:c:func:`PyUnicode_AsDecodedObject`, :c:func:`PyUnicode_AsEncodedUnicode`
2060and :c:func:`PyUnicode_AsDecodedUnicode` are deprecated now.
Martin Pantera2f7ee82016-11-21 13:38:59 +00002061Use the :ref:`generic codec based API <codec-registry>` instead.
Yury Selivanovc48ec272016-11-10 13:27:22 -05002062
2063
2064Deprecated Build Options
2065------------------------
2066
2067The ``--with-system-ffi`` configure flag is now on by default on non-macOS
2068UNIX platforms. It may be disabled by using ``--without-system-ffi``, but
2069using the flag is deprecated and will not be accepted in Python 3.7.
2070macOS is unaffected by this change. Note that many OS distributors already
2071use the ``--with-system-ffi`` flag when building their system Python.
Martin Panter7e3a91a2016-02-10 04:40:48 +00002072
2073
Yury Selivanovd1da5072015-05-27 22:09:10 -04002074Removed
2075=======
2076
2077API and Feature Removals
2078------------------------
2079
Yury Selivanovc48ec272016-11-10 13:27:22 -05002080* Unknown escapes consisting of ``'\'`` and an ASCII letter in
Serhiy Storchaka53c53ea2016-12-06 19:15:29 +02002081 regular expressions will now cause an error. In replacement templates for
2082 :func:`re.sub` they are still allowed, but deprecated.
2083 The :const:`re.LOCALE` flag can now only be used with binary patterns.
Yury Selivanovc48ec272016-11-10 13:27:22 -05002084
Yury Selivanov56613162015-07-23 17:51:34 +03002085* ``inspect.getmoduleinfo()`` was removed (was deprecated since CPython 3.3).
Yury Selivanov6dfbc5d2015-07-23 17:49:00 +03002086 :func:`inspect.getmodulename` should be used for obtaining the module
2087 name for a given path.
Yury Selivanovc48ec272016-11-10 13:27:22 -05002088 (Contributed by Yury Selivanov in :issue:`13248`.)
Yury Selivanov6dfbc5d2015-07-23 17:49:00 +03002089
Senthil Kumaran613065b2016-01-17 20:12:16 -08002090* ``traceback.Ignore`` class and ``traceback.usage``, ``traceback.modname``,
2091 ``traceback.fullmodname``, ``traceback.find_lines_from_code``,
2092 ``traceback.find_lines``, ``traceback.find_strings``,
2093 ``traceback.find_executable_lines`` methods were removed from the
2094 :mod:`traceback` module. They were undocumented methods deprecated since
2095 Python 3.2 and equivalent functionality is available from private methods.
2096
Serhiy Storchaka2e208b72016-05-16 22:35:46 +03002097* The ``tk_menuBar()`` and ``tk_bindForTraversal()`` dummy methods in
2098 :mod:`tkinter` widget classes were removed (corresponding Tk commands
2099 were obsolete since Tk 4.0).
2100
Serhiy Storchakae670be22016-06-11 19:32:44 +03002101* The :meth:`~zipfile.ZipFile.open` method of the :class:`zipfile.ZipFile`
2102 class no longer supports the ``'U'`` mode (was deprecated since Python 3.4).
2103 Use :class:`io.TextIOWrapper` for reading compressed text files in
2104 :term:`universal newlines` mode.
2105
Zachary Ware20737cc2016-09-08 11:38:46 -07002106* The undocumented ``IN``, ``CDROM``, ``DLFCN``, ``TYPES``, ``CDIO``, and
2107 ``STROPTS`` modules have been removed. They had been available in the
2108 platform specific ``Lib/plat-*/`` directories, but were chronically out of
2109 date, inconsistently available across platforms, and unmaintained. The
2110 script that created these modules is still available in the source
2111 distribution at :source:`Tools/scripts/h2py.py`.
2112
Yury Selivanovc48ec272016-11-10 13:27:22 -05002113* The deprecated ``asynchat.fifo`` class has been removed.
2114
Yury Selivanovd1da5072015-05-27 22:09:10 -04002115
2116Porting to Python 3.6
2117=====================
2118
2119This section lists previously described changes and other bugfixes
2120that may require changes to your code.
2121
Serhiy Storchaka7e160ce2016-07-03 21:03:53 +03002122Changes in 'python' Command Behavior
2123------------------------------------
2124
2125* The output of a special Python build with defined ``COUNT_ALLOCS``,
2126 ``SHOW_ALLOC_COUNT`` or ``SHOW_TRACK_COUNT`` macros is now off by
2127 default. It can be re-enabled using the ``-X showalloccount`` option.
2128 It now outputs to ``stderr`` instead of ``stdout``.
2129 (Contributed by Serhiy Storchaka in :issue:`23034`.)
2130
2131
Yury Selivanovd1da5072015-05-27 22:09:10 -04002132Changes in the Python API
2133-------------------------
2134
Yury Selivanovc48ec272016-11-10 13:27:22 -05002135* :func:`open() <open>` will no longer allow combining the ``'U'`` mode flag
2136 with ``'+'``.
2137 (Contributed by Jeff Balogh and John O'Connor in :issue:`2091`.)
2138
Martin Pantera2f7ee82016-11-21 13:38:59 +00002139* :mod:`sqlite3` no longer implicitly commits an open transaction before DDL
Berker Peksagab994ed2016-09-11 12:57:15 +03002140 statements.
2141
Victor Stinnere66987e2016-09-06 16:33:52 -07002142* On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool
2143 is initialized to increase the security.
2144
Brett Cannon696c35e2016-06-25 10:58:17 -07002145* When :meth:`importlib.abc.Loader.exec_module` is defined,
2146 :meth:`importlib.abc.Loader.create_module` must also be defined.
2147
Eric Snow46f97b82016-09-07 16:56:15 -07002148* :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg**
2149 argument is not set. Previously only ``NULL`` was returned.
2150
Victor Stinnerf3914eb2016-01-20 12:16:21 +01002151* The format of the ``co_lnotab`` attribute of code objects changed to support
Martin Pantera2f7ee82016-11-21 13:38:59 +00002152 a negative line number delta. By default, Python does not emit bytecode with
2153 a negative line number delta. Functions using ``frame.f_lineno``,
Victor Stinnerf3914eb2016-01-20 12:16:21 +01002154 ``PyFrame_GetLineNumber()`` or ``PyCode_Addr2Line()`` are not affected.
Martin Pantera2f7ee82016-11-21 13:38:59 +00002155 Functions directly decoding ``co_lnotab`` should be updated to use a signed
2156 8-bit integer type for the line number delta, but this is only required to
2157 support applications using a negative line number delta. See
Victor Stinnerf3914eb2016-01-20 12:16:21 +01002158 ``Objects/lnotab_notes.txt`` for the ``co_lnotab`` format and how to decode
2159 it, and see the :pep:`511` for the rationale.
2160
Brett Cannon1e3c3e92015-12-27 13:17:04 -08002161* The functions in the :mod:`compileall` module now return booleans instead
2162 of ``1`` or ``0`` to represent success or failure, respectively. Thanks to
2163 booleans being a subclass of integers, this should only be an issue if you
2164 were doing identity checks for ``1`` or ``0``. See :issue:`25768`.
2165
Robert Collinsdfa95c92015-08-10 09:53:30 +12002166* Reading the :attr:`~urllib.parse.SplitResult.port` attribute of
2167 :func:`urllib.parse.urlsplit` and :func:`~urllib.parse.urlparse` results
2168 now raises :exc:`ValueError` for out-of-range values, rather than
2169 returning :const:`None`. See :issue:`20059`.
Yury Selivanovd1da5072015-05-27 22:09:10 -04002170
Brett Cannonc0d91af2015-10-16 12:21:37 -07002171* The :mod:`imp` module now raises a :exc:`DeprecationWarning` instead of
2172 :exc:`PendingDeprecationWarning`.
2173
Martin Panter28a465c2015-11-14 12:52:08 +00002174* The following modules have had missing APIs added to their :attr:`__all__`
Martin Panter0d3535a2016-06-06 02:09:08 +00002175 attributes to match the documented APIs:
2176 :mod:`calendar`, :mod:`cgi`, :mod:`csv`,
Martin Panterdcfebb32016-04-01 06:55:55 +00002177 :mod:`~xml.etree.ElementTree`, :mod:`enum`,
Martin Panter0d3535a2016-06-06 02:09:08 +00002178 :mod:`fileinput`, :mod:`ftplib`, :mod:`logging`, :mod:`mailbox`,
2179 :mod:`mimetypes`, :mod:`optparse`, :mod:`plistlib`, :mod:`smtpd`,
2180 :mod:`subprocess`, :mod:`tarfile`, :mod:`threading` and
Martin Panter28a465c2015-11-14 12:52:08 +00002181 :mod:`wave`. This means they will export new symbols when ``import *``
Yury Selivanovc48ec272016-11-10 13:27:22 -05002182 is used.
2183 (Contributed by Joel Taddei and Jacek Kołodziej in :issue:`23883`.)
Martin Panter28a465c2015-11-14 12:52:08 +00002184
Brett Cannon849113a2016-01-22 15:25:50 -08002185* When performing a relative import, if ``__package__`` does not compare equal
2186 to ``__spec__.parent`` then :exc:`ImportWarning` is raised.
2187 (Contributed by Brett Cannon in :issue:`25791`.)
Brett Cannon63b85052016-01-15 13:33:03 -08002188
Brett Cannon9fa81262016-01-22 16:39:02 -08002189* When a relative import is performed and no parent package is known, then
2190 :exc:`ImportError` will be raised. Previously, :exc:`SystemError` could be
Martin Panterd9108d12016-02-21 08:49:56 +00002191 raised. (Contributed by Brett Cannon in :issue:`18018`.)
2192
2193* Servers based on the :mod:`socketserver` module, including those
2194 defined in :mod:`http.server`, :mod:`xmlrpc.server` and
2195 :mod:`wsgiref.simple_server`, now only catch exceptions derived
2196 from :exc:`Exception`. Therefore if a request handler raises
2197 an exception like :exc:`SystemExit` or :exc:`KeyboardInterrupt`,
2198 :meth:`~socketserver.BaseServer.handle_error` is no longer called, and
2199 the exception will stop a single-threaded server. (Contributed by
2200 Martin Panter in :issue:`23430`.)
Brett Cannon9fa81262016-01-22 16:39:02 -08002201
Berker Peksag3c3d7f42016-03-19 11:44:17 +02002202* :func:`spwd.getspnam` now raises a :exc:`PermissionError` instead of
2203 :exc:`KeyError` if the user doesn't have privileges.
Yury Selivanovd1da5072015-05-27 22:09:10 -04002204
Martin Panter50ab1a32016-04-11 00:38:12 +00002205* The :meth:`socket.socket.close` method now raises an exception if
Yury Selivanovc48ec272016-11-10 13:27:22 -05002206 an error (e.g. ``EBADF``) was reported by the underlying system call.
2207 (Contributed by Martin Panter in :issue:`26685`.)
Martin Panter50ab1a32016-04-11 00:38:12 +00002208
Martin Pantera2f7ee82016-11-21 13:38:59 +00002209* The *decode_data* argument for the :class:`smtpd.SMTPChannel` and
Serhiy Storchaka8c740c42016-05-29 23:43:24 +03002210 :class:`smtpd.SMTPServer` constructors is now ``False`` by default.
2211 This means that the argument passed to
2212 :meth:`~smtpd.SMTPServer.process_message` is now a bytes object by
2213 default, and ``process_message()`` will be passed keyword arguments.
2214 Code that has already been updated in accordance with the deprecation
2215 warning generated by 3.5 will not be affected.
2216
Yury Selivanovc48ec272016-11-10 13:27:22 -05002217* All optional arguments of the :func:`~json.dump`, :func:`~json.dumps`,
Serhiy Storchakaaacd53f2016-06-22 00:03:20 +03002218 :func:`~json.load` and :func:`~json.loads` functions and
2219 :class:`~json.JSONEncoder` and :class:`~json.JSONDecoder` class
2220 constructors in the :mod:`json` module are now :ref:`keyword-only
2221 <keyword-only_parameter>`.
2222 (Contributed by Serhiy Storchaka in :issue:`18726`.)
2223
Yury Selivanovc48ec272016-11-10 13:27:22 -05002224* Subclasses of :class:`type` which don't override ``type.__new__`` may no
2225 longer use the one-argument form to get the type of an object.
2226
Nick Coghlan607e1c42016-07-31 12:42:49 +10002227* As part of :pep:`487`, the handling of keyword arguments passed to
2228 :class:`type` (other than the metaclass hint, ``metaclass``) is now
2229 consistently delegated to :meth:`object.__init_subclass__`. This means that
2230 :meth:`type.__new__` and :meth:`type.__init__` both now accept arbitrary
2231 keyword arguments, but :meth:`object.__init_subclass__` (which is called from
2232 :meth:`type.__new__`) will reject them by default. Custom metaclasses
2233 accepting additional keyword arguments will need to adjust their calls to
2234 :meth:`type.__new__` (whether direct or via :class:`super`) accordingly.
2235
Jason R. Coombsc758d512016-08-21 16:09:27 -04002236* In :class:`distutils.command.sdist.sdist`, the ``default_format``
2237 attribute has been removed and is no longer honored. Instead, the
2238 gzipped tarfile format is the default on all platforms and no
2239 platform-specific selection is made.
2240 In environments where distributions are
2241 built on Windows and zip distributions are required, configure
Serhiy Storchaka46936d52018-04-08 19:18:04 +03002242 the project with a ``setup.cfg`` file containing the following:
2243
2244 .. code-block:: ini
Jason R. Coombsc758d512016-08-21 16:09:27 -04002245
2246 [sdist]
2247 formats=zip
2248
2249 This behavior has also been backported to earlier Python versions
2250 by Setuptools 26.0.0.
Serhiy Storchakaaacd53f2016-06-22 00:03:20 +03002251
Martin Panteref91bb22016-08-27 01:39:26 +00002252* In the :mod:`urllib.request` module and the
2253 :meth:`http.client.HTTPConnection.request` method, if no Content-Length
2254 header field has been specified and the request body is a file object,
2255 it is now sent with HTTP 1.1 chunked encoding. If a file object has to
2256 be sent to a HTTP 1.0 server, the Content-Length value now has to be
Yury Selivanovc48ec272016-11-10 13:27:22 -05002257 specified by the caller.
2258 (Contributed by Demian Brecht and Rolf Krahl with tweaks from
2259 Martin Panter in :issue:`12319`.)
2260
2261* The :class:`~csv.DictReader` now returns rows of type
2262 :class:`~collections.OrderedDict`.
2263 (Contributed by Steve Holden in :issue:`27842`.)
2264
2265* The :const:`crypt.METHOD_CRYPT` will no longer be added to ``crypt.methods``
2266 if unsupported by the platform.
2267 (Contributed by Victor Stinner in :issue:`25287`.)
2268
2269* The *verbose* and *rename* arguments for
2270 :func:`~collections.namedtuple` are now keyword-only.
2271 (Contributed by Raymond Hettinger in :issue:`25628`.)
2272
Yury Selivanovc48ec272016-11-10 13:27:22 -05002273* On Linux, :func:`ctypes.util.find_library` now looks in
2274 ``LD_LIBRARY_PATH`` for shared libraries.
2275 (Contributed by Vinay Sajip in :issue:`9998`.)
2276
Yury Selivanovc48ec272016-11-10 13:27:22 -05002277* The :class:`imaplib.IMAP4` class now handles flags containing the
2278 ``']'`` character in messages sent from the server to improve
2279 real-world compatibility.
2280 (Contributed by Lita Cho in :issue:`21815`.)
2281
2282* The :func:`mmap.write() <mmap.write>` function now returns the number
2283 of bytes written like other write methods.
2284 (Contributed by Jakub Stasiak in :issue:`26335`.)
2285
2286* The :func:`pkgutil.iter_modules` and :func:`pkgutil.walk_packages`
2287 functions now return :class:`~pkgutil.ModuleInfo` named tuples.
2288 (Contributed by Ramchandra Apte in :issue:`17211`.)
2289
2290* :func:`re.sub` now raises an error for invalid numerical group
Martin Pantera2f7ee82016-11-21 13:38:59 +00002291 references in replacement templates even if the pattern is not
2292 found in the string. The error message for invalid group references
Yury Selivanovc48ec272016-11-10 13:27:22 -05002293 now includes the group index and the position of the reference.
2294 (Contributed by SilentGhost, Serhiy Storchaka in :issue:`25953`.)
2295
2296* :class:`zipfile.ZipFile` will now raise :exc:`NotImplementedError` for
2297 unrecognized compression values. Previously a plain :exc:`RuntimeError`
Martin Pantera2f7ee82016-11-21 13:38:59 +00002298 was raised. Additionally, calling :class:`~zipfile.ZipFile` methods
2299 on a closed ZipFile or calling the :meth:`~zipfile.ZipFile.write` method
Yury Selivanovc48ec272016-11-10 13:27:22 -05002300 on a ZipFile created with mode ``'r'`` will raise a :exc:`ValueError`.
2301 Previously, a :exc:`RuntimeError` was raised in those scenarios.
2302
Nick Coghlan19d24672016-12-05 16:47:55 +10002303* when custom metaclasses are combined with zero-argument :func:`super` or
2304 direct references from methods to the implicit ``__class__`` closure
2305 variable, the implicit ``__classcell__`` namespace entry must now be passed
2306 up to ``type.__new__`` for initialisation. Failing to do so will result in
Serhiy Storchaka8ae8e6a2018-05-20 08:13:52 +03002307 a :exc:`DeprecationWarning` in Python 3.6 and a :exc:`RuntimeError` in
2308 Python 3.8.
Martin Panteref91bb22016-08-27 01:39:26 +00002309
Yury Selivanovd1da5072015-05-27 22:09:10 -04002310Changes in the C API
2311--------------------
2312
Martin Pantera2f7ee82016-11-21 13:38:59 +00002313* The :c:func:`PyMem_Malloc` allocator family now uses the :ref:`pymalloc allocator
2314 <pymalloc>` rather than the system :c:func:`malloc`. Applications calling
Victor Stinnerf5c4b992016-04-22 16:26:23 +02002315 :c:func:`PyMem_Malloc` without holding the GIL can now crash. Set the
2316 :envvar:`PYTHONMALLOC` environment variable to ``debug`` to validate the
2317 usage of memory allocators in your application. See :issue:`26249`.
2318
Martin Panterb4ce1fc2015-11-30 03:18:29 +00002319* :c:func:`Py_Exit` (and the main interpreter) now override the exit status
2320 with 120 if flushing buffered data failed. See :issue:`5319`.
Yury Selivanov27ec5bf2016-11-28 11:45:36 -05002321
2322
2323CPython bytecode changes
2324------------------------
2325
2326There have been several major changes to the :term:`bytecode` in Python 3.6.
2327
2328* The Python interpreter now uses a 16-bit wordcode instead of bytecode.
2329 (Contributed by Demur Rumed with input and reviews from
2330 Serhiy Storchaka and Victor Stinner in :issue:`26647` and :issue:`28050`.)
2331
2332* The new :opcode:`FORMAT_VALUE` and :opcode:`BUILD_STRING` opcodes as part
2333 of the :ref:`formatted string literal <whatsnew36-pep498>` implementation.
2334 (Contributed by Eric Smith in :issue:`25483` and
2335 Serhiy Storchaka in :issue:`27078`.)
2336
2337* The new :opcode:`BUILD_CONST_KEY_MAP` opcode to optimize the creation
2338 of dictionaries with constant keys.
2339 (Contributed by Serhiy Storchaka in :issue:`27140`.)
2340
2341* The function call opcodes have been heavily reworked for better performance
2342 and simpler implementation.
2343 The :opcode:`MAKE_FUNCTION`, :opcode:`CALL_FUNCTION`,
2344 :opcode:`CALL_FUNCTION_KW` and :opcode:`BUILD_MAP_UNPACK_WITH_CALL` opcodes
2345 have been modified, the new :opcode:`CALL_FUNCTION_EX` and
2346 :opcode:`BUILD_TUPLE_UNPACK_WITH_CALL` have been added, and
2347 ``CALL_FUNCTION_VAR``, ``CALL_FUNCTION_VAR_KW`` and ``MAKE_CLOSURE`` opcodes
2348 have been removed.
2349 (Contributed by Demur Rumed in :issue:`27095`, and Serhiy Storchaka in
2350 :issue:`27213`, :issue:`28257`.)
2351
2352* The new :opcode:`SETUP_ANNOTATIONS` and :opcode:`STORE_ANNOTATION` opcodes
2353 have been added to support the new :term:`variable annotation` syntax.
2354 (Contributed by Ivan Levkivskyi in :issue:`27985`.)
Ned Deily9d6171d2018-06-11 04:09:34 -04002355
2356
2357Notable changes in Python 3.6.2
2358===============================
2359
2360New ``make regen-all`` build target
2361-----------------------------------
2362
2363To simplify cross-compilation, and to ensure that CPython can reliably be
2364compiled without requiring an existing version of Python to already be
2365available, the autotools-based build system no longer attempts to implicitly
2366recompile generated files based on file modification times.
2367
2368Instead, a new ``make regen-all`` command has been added to force regeneration
2369of these files when desired (e.g. after an initial version of Python has
2370already been built based on the pregenerated versions).
2371
2372More selective regeneration targets are also defined - see
2373:source:`Makefile.pre.in` for details.
2374
2375(Contributed by Victor Stinner in :issue:`23404`.)
2376
2377.. versionadded:: 3.6.2
2378
2379
2380Removal of ``make touch`` build target
2381--------------------------------------
2382
2383The ``make touch`` build target previously used to request implicit regeneration
2384of generated files by updating their modification times has been removed.
2385
2386It has been replaced by the new ``make regen-all`` target.
2387
2388(Contributed by Victor Stinner in :issue:`23404`.)
2389
2390.. versionchanged:: 3.6.2
2391
2392
2393Notable changes in Python 3.6.4
2394===============================
2395
2396The ``PyExc_RecursionErrorInst`` singleton that was part of the public API
2397has been removed as its members being never cleared may cause a segfault
2398during finalization of the interpreter.
2399(Contributed by Xavier de Gaye in :issue:`22898` and :issue:`30697`.)
2400
2401
2402Notable changes in Python 3.6.5
2403===============================
2404
2405The :func:`locale.localeconv` function now sets temporarily the ``LC_CTYPE``
2406locale to the ``LC_NUMERIC`` locale in some cases.
2407(Contributed by Victor Stinner in :issue:`31900`.)