blob: 96f86e6c6142da9781574c02ee95f2be6c939f79 [file] [log] [blame]
Zachary Ware569db2c2015-05-22 11:42:20 -05001****************************
Victor Stinner01adf062014-03-18 00:53:32 +01002 What's New In Python 3.5
3****************************
4
Yury Selivanov7b76bae2015-09-12 17:53:33 -04005:Editors: Elvis Pranskevichus <elvis@magic.io>, Yury Selivanov <yury@magic.io>
Yury Selivanovdfcfe132015-09-08 15:33:15 -04006
Victor Stinner01adf062014-03-18 00:53:32 +01007.. 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
47This article explains the new features in Python 3.5, compared to 3.4.
Yury Selivanov69a15f12015-09-13 11:52:07 -040048Python 3.5 was released on September 13, 2015.  See the
Yury Selivanov801306b2015-09-13 11:40:00 -040049`changelog <https://docs.python.org/3.5/whatsnew/changelog.html>`_ for a full
50list of changes.
Victor Stinner01adf062014-03-18 00:53:32 +010051
52.. seealso::
53
Berker Peksagfa0423b2014-10-09 11:38:19 +030054 :pep:`478` - Python 3.5 Release Schedule
Victor Stinner01adf062014-03-18 00:53:32 +010055
56
57Summary -- Release highlights
58=============================
59
Victor Stinner01adf062014-03-18 00:53:32 +010060New syntax features:
61
Yury Selivanova33cb352015-09-13 11:21:25 -040062* :ref:`PEP 492 <whatsnew-pep-492>`, coroutines with async and await syntax.
63* :ref:`PEP 465 <whatsnew-pep-465>`, a new matrix multiplication operator: ``a @ b``.
64* :ref:`PEP 448 <whatsnew-pep-448>`, additional unpacking generalizations.
Victor Stinner01adf062014-03-18 00:53:32 +010065
Yury Selivanov95fd26b2015-09-12 17:50:58 -040066
Victor Stinner01adf062014-03-18 00:53:32 +010067New library modules:
68
Yury Selivanova33cb352015-09-13 11:21:25 -040069* :mod:`typing`: :ref:`PEP 484 -- Type Hints <whatsnew-pep-484>`.
70* :mod:`zipapp`: :ref:`PEP 441 Improving Python ZIP Application Support
71 <whatsnew-zipapp>`.
Victor Stinner01adf062014-03-18 00:53:32 +010072
Yury Selivanov95fd26b2015-09-12 17:50:58 -040073
Victor Stinner01adf062014-03-18 00:53:32 +010074New built-in features:
75
Yury Selivanova33cb352015-09-13 11:21:25 -040076* ``bytes % args``, ``bytearray % args``: :ref:`PEP 461 <whatsnew-pep-461>` --
77 Adding ``%`` formatting to bytes and bytearray.
Yury Selivanov40301c02015-09-08 23:28:06 -040078
Yury Selivanov8e3b04c2015-09-16 12:18:29 -040079* New :meth:`bytes.hex`, :meth:`bytearray.hex` and :meth:`memoryview.hex`
80 methods. (Contributed by Arnon Yaari in :issue:`9951`.)
Yury Selivanov40301c02015-09-08 23:28:06 -040081
Yury Selivanova33cb352015-09-13 11:21:25 -040082* :class:`memoryview` now supports tuple indexing (including multi-dimensional).
Yury Selivanov4dde5872015-09-11 00:48:21 -040083 (Contributed by Antoine Pitrou in :issue:`23632`.)
84
Yury Selivanova33cb352015-09-13 11:21:25 -040085* Generators have a new ``gi_yieldfrom`` attribute, which returns the
Yury Selivanove13f8f32015-07-03 00:23:30 -040086 object being iterated by ``yield from`` expressions. (Contributed
87 by Benno Leslie and Yury Selivanov in :issue:`24450`.)
Yury Selivanov40301c02015-09-08 23:28:06 -040088
Yury Selivanova33cb352015-09-13 11:21:25 -040089* A new :exc:`RecursionError` exception is now raised when maximum
90 recursion depth is reached. (Contributed by Georg Brandl
Yury Selivanovf488fb42015-07-03 01:04:23 -040091 in :issue:`19235`.)
Victor Stinner01adf062014-03-18 00:53:32 +010092
Yury Selivanov95fd26b2015-09-12 17:50:58 -040093
Yury Selivanovce917c7312015-09-10 17:35:38 -040094CPython implementation improvements:
Victor Stinner01adf062014-03-18 00:53:32 +010095
Victor Stinner71430292014-03-18 01:18:21 +010096* When the ``LC_TYPE`` locale is the POSIX locale (``C`` locale),
Yury Selivanova33cb352015-09-13 11:21:25 -040097 :py:data:`sys.stdin` and :py:data:`sys.stdout` now use the
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +030098 ``surrogateescape`` error handler, instead of the ``strict`` error handler.
99 (Contributed by Victor Stinner in :issue:`19977`.)
Victor Stinner01adf062014-03-18 00:53:32 +0100100
Yury Selivanovce917c7312015-09-10 17:35:38 -0400101* ``.pyo`` files are no longer used and have been replaced by a more flexible
Yury Selivanova33cb352015-09-13 11:21:25 -0400102 scheme that includes the optimization level explicitly in ``.pyc`` name.
103 (See :ref:`PEP 488 overview <whatsnew-pep-488>`.)
Yury Selivanov40301c02015-09-08 23:28:06 -0400104
Yury Selivanovce917c7312015-09-10 17:35:38 -0400105* Builtin and extension modules are now initialized in a multi-phase process,
Yury Selivanova33cb352015-09-13 11:21:25 -0400106 which is similar to how Python modules are loaded.
107 (See :ref:`PEP 489 overview <whatsnew-pep-489>`.)
Brett Cannonf299abd2015-04-13 14:21:02 -0400108
Victor Stinner01adf062014-03-18 00:53:32 +0100109
Yury Selivanova33cb352015-09-13 11:21:25 -0400110Significant improvements in the standard library:
Yury Selivanov58444362015-05-30 10:49:09 -0400111
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400112* :class:`collections.OrderedDict` is now
113 :ref:`implemented in C <whatsnew-ordereddict>`, which makes it
114 4 to 100 times faster.
Victor Stinner01adf062014-03-18 00:53:32 +0100115
Martin Panter97ce0fa2015-11-14 01:14:54 +0000116* The :mod:`ssl` module gained
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400117 :ref:`support for Memory BIO <whatsnew-sslmemorybio>`, which decouples SSL
118 protocol handling from network IO.
Yury Selivanov7d6adab2015-08-05 19:01:51 -0400119
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400120* The new :func:`os.scandir` function provides a
121 :ref:`better and significantly faster way <whatsnew-pep-471>`
122 of directory traversal.
123
Yury Selivanova33cb352015-09-13 11:21:25 -0400124* :func:`functools.lru_cache` has been mostly
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400125 :ref:`reimplemented in C <whatsnew-lrucache>`, yielding much better
126 performance.
127
128* The new :func:`subprocess.run` function provides a
129 :ref:`streamlined way to run subprocesses <whatsnew-subprocess>`.
130
Yury Selivanova33cb352015-09-13 11:21:25 -0400131* The :mod:`traceback` module has been significantly
Yury Selivanovfe369a62015-09-13 08:29:19 -0400132 :ref:`enhanced <whatsnew-traceback>` for improved
133 performance and developer convenience.
134
Yury Selivanov336b37b2015-09-09 12:23:01 -0400135
Victor Stinner01adf062014-03-18 00:53:32 +0100136Security improvements:
137
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400138* SSLv3 is now disabled throughout the standard library.
139 It can still be enabled by instantiating a :class:`ssl.SSLContext`
140 manually. (See :issue:`22638` for more details; this change was
141 backported to CPython 3.4 and 2.7.)
142
143* HTTP cookie parsing is now stricter, in order to protect
144 against potential injection attacks. (Contributed by Antoine Pitrou
145 in :issue:`22796`.)
Victor Stinner01adf062014-03-18 00:53:32 +0100146
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400147
Steve Dower313fbf42015-07-17 16:48:48 -0700148Windows improvements:
149
Yury Selivanovce917c7312015-09-10 17:35:38 -0400150* A new installer for Windows has replaced the old MSI.
151 See :ref:`using-on-windows` for more information.
Yury Selivanov40301c02015-09-08 23:28:06 -0400152
Steve Dower313fbf42015-07-17 16:48:48 -0700153* Windows builds now use Microsoft Visual C++ 14.0, and extension modules
154 should use the same.
155
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400156
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400157Please read on for a comprehensive list of user-facing changes, including many
158other smaller improvements, CPython optimizations, deprecations, and potential
159porting issues.
Victor Stinner01adf062014-03-18 00:53:32 +0100160
161
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400162New Features
163============
164
165.. _whatsnew-pep-492:
166
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400167PEP 492 - Coroutines with async and await syntax
168------------------------------------------------
169
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400170:pep:`492` greatly improves support for asynchronous programming in Python
171by adding :term:`awaitable objects <awaitable>`,
172:term:`coroutine functions <coroutine function>`,
173:term:`asynchronous iteration <asynchronous iterable>`,
174and :term:`asynchronous context managers <asynchronous context manager>`.
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400175
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400176Coroutine functions are declared using the new :keyword:`async def` syntax::
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400177
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400178 >>> async def coro():
179 ... return 'spam'
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400180
Yury Selivanova88cd642015-09-10 21:26:54 -0400181Inside a coroutine function, the new :keyword:`await` expression can be used
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400182to suspend coroutine execution until the result is available. Any object
183can be *awaited*, as long as it implements the :term:`awaitable` protocol by
184defining the :meth:`__await__` method.
185
186PEP 492 also adds :keyword:`async for` statement for convenient iteration
187over asynchronous iterables.
188
Yury Selivanova33cb352015-09-13 11:21:25 -0400189An example of a rudimentary HTTP client written using the new syntax::
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400190
191 import asyncio
192
193 async def http_get(domain):
194 reader, writer = await asyncio.open_connection(domain, 80)
195
196 writer.write(b'\r\n'.join([
197 b'GET / HTTP/1.1',
198 b'Host: %b' % domain.encode('latin-1'),
199 b'Connection: close',
200 b'', b''
201 ]))
202
203 async for line in reader:
204 print('>>>', line)
205
206 writer.close()
207
208 loop = asyncio.get_event_loop()
209 try:
210 loop.run_until_complete(http_get('example.com'))
211 finally:
212 loop.close()
213
214
215Similarly to asynchronous iteration, there is a new syntax for asynchronous
Yury Selivanov79cf1b02015-09-10 21:44:59 -0400216context managers. The following script::
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400217
Yury Selivanov79cf1b02015-09-10 21:44:59 -0400218 import asyncio
219
220 async def coro(name, lock):
221 print('coro {}: waiting for lock'.format(name))
222 async with lock:
223 print('coro {}: holding the lock'.format(name))
224 await asyncio.sleep(1)
225 print('coro {}: releasing the lock'.format(name))
226
227 loop = asyncio.get_event_loop()
228 lock = asyncio.Lock()
229 coros = asyncio.gather(coro(1, lock), coro(2, lock))
230 try:
231 loop.run_until_complete(coros)
232 finally:
233 loop.close()
234
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400235will output::
Yury Selivanov79cf1b02015-09-10 21:44:59 -0400236
237 coro 2: waiting for lock
238 coro 2: holding the lock
239 coro 1: waiting for lock
240 coro 2: releasing the lock
241 coro 1: holding the lock
242 coro 1: releasing the lock
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400243
244Note that both :keyword:`async for` and :keyword:`async with` can only
245be used inside a coroutine function declared with :keyword:`async def`.
246
Yury Selivanova88cd642015-09-10 21:26:54 -0400247Coroutine functions are intended to be run inside a compatible event loop,
Yury Selivanova33cb352015-09-13 11:21:25 -0400248such as the :ref:`asyncio loop <asyncio-event-loop>`.
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400249
Yury Selivanova6f6edb2016-06-09 15:08:31 -0400250
251.. note::
252
253 .. versionchanged:: 3.5.2
254 Starting with CPython 3.5.2, ``__aiter__`` can directly return
255 :term:`asynchronous iterators <asynchronous iterator>`. Returning
256 an :term:`awaitable` object will result in a
257 :exc:`PendingDeprecationWarning`.
258
259 See more details in the :ref:`async-iterators` documentation
260 section.
261
262
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400263.. seealso::
264
265 :pep:`492` -- Coroutines with async and await syntax
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400266 PEP written and implemented by Yury Selivanov.
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400267
268
Yury Selivanovce917c7312015-09-10 17:35:38 -0400269.. _whatsnew-pep-465:
270
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400271PEP 465 - A dedicated infix operator for matrix multiplication
272--------------------------------------------------------------
Victor Stinner93692bb2015-03-30 15:04:45 +0200273
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400274:pep:`465` adds the ``@`` infix operator for matrix multiplication.
275Currently, no builtin Python types implement the new operator, however, it
276can be implemented by defining :meth:`__matmul__`, :meth:`__rmatmul__`,
277and :meth:`__imatmul__` for regular, reflected, and in-place matrix
278multiplication. The semantics of these methods is similar to that of
279methods defining other infix arithmetic operators.
280
281Matrix multiplication is a notably common operation in many fields of
282mathematics, science, engineering, and the addition of ``@`` allows writing
283cleaner code::
284
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400285 S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r)
286
287instead of::
288
289 S = dot((dot(H, beta) - r).T,
290 dot(inv(dot(dot(H, V), H.T)), dot(H, beta) - r))
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400291
Yury Selivanovf97edf12015-10-31 13:33:49 -0400292NumPy 1.10 has support for the new operator::
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400293
294 >>> import numpy
295
296 >>> x = numpy.ones(3)
297 >>> x
298 array([ 1., 1., 1.])
299
300 >>> m = numpy.eye(3)
301 >>> m
302 array([[ 1., 0., 0.],
303 [ 0., 1., 0.],
304 [ 0., 0., 1.]])
305
306 >>> x @ m
307 array([ 1., 1., 1.])
308
309
310.. seealso::
311
312 :pep:`465` -- A dedicated infix operator for matrix multiplication
313 PEP written by Nathaniel J. Smith; implemented by Benjamin Peterson.
314
315
Yury Selivanovce917c7312015-09-10 17:35:38 -0400316.. _whatsnew-pep-448:
317
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400318PEP 448 - Additional Unpacking Generalizations
319----------------------------------------------
320
321:pep:`448` extends the allowed uses of the ``*`` iterable unpacking
322operator and ``**`` dictionary unpacking operator. It is now possible
Martin Panter0c0da482016-06-12 01:46:50 +0000323to use an arbitrary number of unpackings in :ref:`function calls <calls>`::
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400324
325 >>> print(*[1], *[2], 3, *[4, 5])
326 1 2 3 4 5
327
328 >>> def fn(a, b, c, d):
329 ... print(a, b, c, d)
330 ...
331
332 >>> fn(**{'a': 1, 'c': 3}, **{'b': 2, 'd': 4})
333 1 2 3 4
334
335Similarly, tuple, list, set, and dictionary displays allow multiple
Martin Panter0c0da482016-06-12 01:46:50 +0000336unpackings (see :ref:`exprlists` and :ref:`dict`)::
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400337
338 >>> *range(4), 4
339 (0, 1, 2, 3, 4)
Yury Selivanov79cf1b02015-09-10 21:44:59 -0400340
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400341 >>> [*range(4), 4]
342 [0, 1, 2, 3, 4]
Yury Selivanov79cf1b02015-09-10 21:44:59 -0400343
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400344 >>> {*range(4), 4, *(5, 6, 7)}
345 {0, 1, 2, 3, 4, 5, 6, 7}
Yury Selivanov79cf1b02015-09-10 21:44:59 -0400346
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400347 >>> {'x': 1, **{'y': 2}}
348 {'x': 1, 'y': 2}
349
350.. seealso::
351
352 :pep:`448` -- Additional Unpacking Generalizations
353 PEP written by Joshua Landau; implemented by Neil Girdhar,
354 Thomas Wouters, and Joshua Landau.
355
356
Yury Selivanovce917c7312015-09-10 17:35:38 -0400357.. _whatsnew-pep-461:
358
Benjamin Peterson909acb82016-06-21 23:47:16 -0700359PEP 461 - percent formatting support for bytes and bytearray
360------------------------------------------------------------
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400361
Martin Panter97ce0fa2015-11-14 01:14:54 +0000362:pep:`461` adds support for the ``%``
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400363:ref:`interpolation operator <bytes-formatting>` to :class:`bytes`
364and :class:`bytearray`.
365
366While interpolation is usually thought of as a string operation, there are
Yury Selivanova33cb352015-09-13 11:21:25 -0400367cases where interpolation on ``bytes`` or ``bytearrays`` makes sense, and the
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400368work needed to make up for this missing functionality detracts from the
369overall readability of the code. This issue is particularly important when
370dealing with wire format protocols, which are often a mixture of binary
371and ASCII compatible text.
Victor Stinner93692bb2015-03-30 15:04:45 +0200372
373Examples::
374
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400375 >>> b'Hello %b!' % b'World'
Victor Stinner93692bb2015-03-30 15:04:45 +0200376 b'Hello World!'
Yury Selivanov79cf1b02015-09-10 21:44:59 -0400377
Victor Stinner93692bb2015-03-30 15:04:45 +0200378 >>> b'x=%i y=%f' % (1, 2.5)
379 b'x=1 y=2.500000'
380
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400381Unicode is not allowed for ``%b``, but it is accepted by ``%a`` (equivalent of
Victor Stinner93692bb2015-03-30 15:04:45 +0200382``repr(obj).encode('ascii', 'backslashreplace')``)::
383
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400384 >>> b'Hello %b!' % 'World'
Victor Stinner93692bb2015-03-30 15:04:45 +0200385 Traceback (most recent call last):
386 File "<stdin>", line 1, in <module>
387 TypeError: %b requires bytes, or an object that implements __bytes__, not 'str'
Yury Selivanov79cf1b02015-09-10 21:44:59 -0400388
Victor Stinner93692bb2015-03-30 15:04:45 +0200389 >>> b'price: %a' % '10€'
390 b"price: '10\\u20ac'"
391
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400392Note that ``%s`` and ``%r`` conversion types, although supported, should
393only be used in codebases that need compatibility with Python 2.
394
Victor Stinner93692bb2015-03-30 15:04:45 +0200395.. seealso::
396
397 :pep:`461` -- Adding % formatting to bytes and bytearray
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400398 PEP written by Ethan Furman; implemented by Neil Schemenauer and
399 Ethan Furman.
Yury Selivanov216d9992015-08-04 12:42:20 -0400400
401
Yury Selivanovce917c7312015-09-10 17:35:38 -0400402.. _whatsnew-pep-484:
403
Yury Selivanov5df36af2015-08-04 12:46:57 -0400404PEP 484 - Type Hints
405--------------------
406
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400407Function annotation syntax has been a Python feature since version 3.0
408(:pep:`3107`), however the semantics of annotations has been left undefined.
409
410Experience has shown that the majority of function annotation
411uses were to provide type hints to function parameters and return values. It
412became evident that it would be beneficial for Python users, if the
413standard library included the base definitions and tools for type annotations.
414
415:pep:`484` introduces a :term:`provisional module <provisional api>` to
416provide these standard definitions and tools, along with some conventions
417for situations where annotations are not available.
Yury Selivanov5df36af2015-08-04 12:46:57 -0400418
419For example, here is a simple function whose argument and return type
420are declared in the annotations::
421
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400422 def greeting(name: str) -> str:
423 return 'Hello ' + name
Yury Selivanov5df36af2015-08-04 12:46:57 -0400424
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400425While these annotations are available at runtime through the usual
426:attr:`__annotations__` attribute, *no automatic type checking happens at
Yury Selivanova33cb352015-09-13 11:21:25 -0400427runtime*. Instead, it is assumed that a separate off-line type checker
428(e.g. `mypy <http://mypy-lang.org>`_) will be used for on-demand
429source code analysis.
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400430
Yury Selivanov5df36af2015-08-04 12:46:57 -0400431The type system supports unions, generic types, and a special type
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400432named :class:`~typing.Any` which is consistent with (i.e. assignable to
433and from) all types.
Yury Selivanov5df36af2015-08-04 12:46:57 -0400434
435.. seealso::
436
Yury Selivanov40c0ce42015-08-05 12:46:29 -0400437 * :mod:`typing` module documentation
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400438 * :pep:`484` -- Type Hints
439 PEP written by Guido van Rossum, Jukka Lehtosalo, and Łukasz Langa;
440 implemented by Guido van Rossum.
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400441 * :pep:`483` -- The Theory of Type Hints
442 PEP written by Guido van Rossum
Yury Selivanov5df36af2015-08-04 12:46:57 -0400443
444
Yury Selivanovce917c7312015-09-10 17:35:38 -0400445.. _whatsnew-pep-471:
446
Victor Stinner6036e442015-03-08 01:58:04 +0100447PEP 471 - os.scandir() function -- a better and faster directory iterator
448-------------------------------------------------------------------------
449
Victor Stinner37f20342015-03-10 13:29:41 +0100450:pep:`471` adds a new directory iteration function, :func:`os.scandir`,
Yury Selivanovce917c7312015-09-10 17:35:38 -0400451to the standard library. Additionally, :func:`os.walk` is now
Yury Selivanov23950372015-09-12 23:46:39 -0400452implemented using ``scandir``, which makes it 3 to 5 times faster
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400453on POSIX systems and 7 to 20 times faster on Windows systems. This is
454largely achieved by greatly reducing the number of calls to :func:`os.stat`
455required to walk a directory tree.
456
Yury Selivanov23950372015-09-12 23:46:39 -0400457Additionally, ``scandir`` returns an iterator, as opposed to returning
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400458a list of file names, which improves memory efficiency when iterating
459over very large directories.
Victor Stinner37f20342015-03-10 13:29:41 +0100460
Yury Selivanov23950372015-09-12 23:46:39 -0400461The following example shows a simple use of :func:`os.scandir` to display all
462the files (excluding directories) in the given *path* that don't start with
Yury Selivanova33cb352015-09-13 11:21:25 -0400463``'.'``. The :meth:`entry.is_file() <os.DirEntry.is_file>` call will generally
Yury Selivanov23950372015-09-12 23:46:39 -0400464not make an additional system call::
465
466 for entry in os.scandir(path):
467 if not entry.name.startswith('.') and entry.is_file():
468 print(entry.name)
469
Victor Stinner6036e442015-03-08 01:58:04 +0100470.. seealso::
471
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400472 :pep:`471` -- os.scandir() function -- a better and faster directory iterator
473 PEP written and implemented by Ben Hoyt with the help of Victor Stinner.
Victor Stinner6036e442015-03-08 01:58:04 +0100474
475
Yury Selivanovce917c7312015-09-10 17:35:38 -0400476.. _whatsnew-pep-475:
477
Charles-François Natali6e6c59b2015-02-07 13:27:50 +0000478PEP 475: Retry system calls failing with EINTR
479----------------------------------------------
480
Martin Panterd2ad5712015-11-02 04:20:33 +0000481An :py:data:`errno.EINTR` error code is returned whenever a system call, that
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400482is waiting for I/O, is interrupted by a signal. Previously, Python would
Martin Panter97ce0fa2015-11-14 01:14:54 +0000483raise :exc:`InterruptedError` in such cases. This meant that, when writing a
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400484Python application, the developer had two choices:
Charles-François Natali6e6c59b2015-02-07 13:27:50 +0000485
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400486#. Ignore the ``InterruptedError``.
487#. Handle the ``InterruptedError`` and attempt to restart the interrupted
488 system call at every call site.
489
490The first option makes an application fail intermittently.
491The second option adds a large amount of boilerplate that makes the
492code nearly unreadable. Compare::
493
494 print("Hello World")
495
496and::
497
498 while True:
499 try:
500 print("Hello World")
501 break
502 except InterruptedError:
503 continue
504
505:pep:`475` implements automatic retry of system calls on
506``EINTR``. This removes the burden of dealing with ``EINTR``
507or :exc:`InterruptedError` in user code in most situations and makes
508Python programs, including the standard library, more robust. Note that
509the system call is only retried if the signal handler does not raise an
510exception.
511
512Below is a list of functions which are now retried when interrupted
513by a signal:
Victor Stinner6752d652015-07-29 01:11:10 +0200514
Yury Selivanova33cb352015-09-13 11:21:25 -0400515* :func:`open` and :func:`io.open`;
Victor Stinner6752d652015-07-29 01:11:10 +0200516
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400517* functions of the :mod:`faulthandler` module;
Victor Stinner6752d652015-07-29 01:11:10 +0200518
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400519* :mod:`os` functions: :func:`~os.fchdir`, :func:`~os.fchmod`,
520 :func:`~os.fchown`, :func:`~os.fdatasync`, :func:`~os.fstat`,
521 :func:`~os.fstatvfs`, :func:`~os.fsync`, :func:`~os.ftruncate`,
Yury Selivanova33cb352015-09-13 11:21:25 -0400522 :func:`~os.mkfifo`, :func:`~os.mknod`, :func:`~os.open`,
523 :func:`~os.posix_fadvise`, :func:`~os.posix_fallocate`, :func:`~os.pread`,
524 :func:`~os.pwrite`, :func:`~os.read`, :func:`~os.readv`, :func:`~os.sendfile`,
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400525 :func:`~os.wait3`, :func:`~os.wait4`, :func:`~os.wait`,
526 :func:`~os.waitid`, :func:`~os.waitpid`, :func:`~os.write`,
527 :func:`~os.writev`;
Victor Stinner6752d652015-07-29 01:11:10 +0200528
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400529* special cases: :func:`os.close` and :func:`os.dup2` now ignore
Martin Panter97ce0fa2015-11-14 01:14:54 +0000530 :py:data:`~errno.EINTR` errors; the syscall is not retried (see the PEP
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400531 for the rationale);
Victor Stinner6752d652015-07-29 01:11:10 +0200532
Yury Selivanova33cb352015-09-13 11:21:25 -0400533* :mod:`select` functions: :func:`devpoll.poll() <select.devpoll.poll>`,
534 :func:`epoll.poll() <select.epoll.poll>`,
535 :func:`kqueue.control() <select.kqueue.control>`,
536 :func:`poll.poll() <select.poll.poll>`, :func:`~select.select`;
Victor Stinner6752d652015-07-29 01:11:10 +0200537
Yury Selivanova33cb352015-09-13 11:21:25 -0400538* methods of the :class:`~socket.socket` class: :meth:`~socket.socket.accept`,
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400539 :meth:`~socket.socket.connect` (except for non-blocking sockets),
Yury Selivanov336b37b2015-09-09 12:23:01 -0400540 :meth:`~socket.socket.recv`, :meth:`~socket.socket.recvfrom`,
541 :meth:`~socket.socket.recvmsg`, :meth:`~socket.socket.send`,
542 :meth:`~socket.socket.sendall`, :meth:`~socket.socket.sendmsg`,
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400543 :meth:`~socket.socket.sendto`;
Victor Stinner6752d652015-07-29 01:11:10 +0200544
Yury Selivanova33cb352015-09-13 11:21:25 -0400545* :func:`signal.sigtimedwait` and :func:`signal.sigwaitinfo`;
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400546
547* :func:`time.sleep`.
Victor Stinner6752d652015-07-29 01:11:10 +0200548
Charles-François Natali6e6c59b2015-02-07 13:27:50 +0000549.. seealso::
550
551 :pep:`475` -- Retry system calls failing with EINTR
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400552 PEP and implementation written by Charles-François Natali and
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400553 Victor Stinner, with the help of Antoine Pitrou (the French connection).
Victor Stinner01adf062014-03-18 00:53:32 +0100554
555
Yury Selivanovce917c7312015-09-10 17:35:38 -0400556.. _whatsnew-pep-479:
557
Yury Selivanov8d006e72015-05-22 11:30:45 -0400558PEP 479: Change StopIteration handling inside generators
559--------------------------------------------------------
560
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400561The interaction of generators and :exc:`StopIteration` in Python 3.4 and
Yury Selivanova33cb352015-09-13 11:21:25 -0400562earlier was sometimes surprising, and could conceal obscure bugs. Previously,
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400563``StopIteration`` raised accidentally inside a generator function was
564interpreted as the end of the iteration by the loop construct driving the
565generator.
566
567:pep:`479` changes the behavior of generators: when a ``StopIteration``
Yury Selivanov8d006e72015-05-22 11:30:45 -0400568exception is raised inside a generator, it is replaced with a
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400569:exc:`RuntimeError` before it exits the generator frame. The main goal of
570this change is to ease debugging in the situation where an unguarded
571:func:`next` call raises ``StopIteration`` and causes the iteration controlled
572by the generator to terminate silently. This is particularly pernicious in
573combination with the ``yield from`` construct.
574
575This is a backwards incompatible change, so to enable the new behavior,
576a :term:`__future__` import is necessary::
Yury Selivanov8d006e72015-05-22 11:30:45 -0400577
Yury Selivanova33cb352015-09-13 11:21:25 -0400578 >>> from __future__ import generator_stop
579
580 >>> def gen():
581 ... next(iter([]))
582 ... yield
583 ...
584 >>> next(gen())
585 Traceback (most recent call last):
586 File "<stdin>", line 2, in gen
587 StopIteration
588
589 The above exception was the direct cause of the following exception:
590
591 Traceback (most recent call last):
592 File "<stdin>", line 1, in <module>
593 RuntimeError: generator raised StopIteration
Yury Selivanov8d006e72015-05-22 11:30:45 -0400594
595Without a ``__future__`` import, a :exc:`PendingDeprecationWarning` will be
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400596raised whenever a ``StopIteration`` exception is raised inside a generator.
Yury Selivanov8d006e72015-05-22 11:30:45 -0400597
Yury Selivanov8d006e72015-05-22 11:30:45 -0400598.. seealso::
599
600 :pep:`479` -- Change StopIteration handling inside generators
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400601 PEP written by Chris Angelico and Guido van Rossum. Implemented by
602 Chris Angelico, Yury Selivanov and Nick Coghlan.
Yury Selivanov8d006e72015-05-22 11:30:45 -0400603
604
Yury Selivanova33cb352015-09-13 11:21:25 -0400605.. _whatsnew-pep-485:
606
607PEP 485: A function for testing approximate equality
608----------------------------------------------------
609
610:pep:`485` adds the :func:`math.isclose` and :func:`cmath.isclose`
611functions which tell whether two values are approximately equal or
612"close" to each other. Whether or not two values are considered
613close is determined according to given absolute and relative tolerances.
614Relative tolerance is the maximum allowed difference between ``isclose``
615arguments, relative to the larger absolute value::
616
617 >>> import math
618 >>> a = 5.0
619 >>> b = 4.99998
620 >>> math.isclose(a, b, rel_tol=1e-5)
621 True
622 >>> math.isclose(a, b, rel_tol=1e-6)
623 False
624
625It is also possible to compare two values using absolute tolerance, which
626must be a non-negative value::
627
628 >>> import math
629 >>> a = 5.0
630 >>> b = 4.99998
631 >>> math.isclose(a, b, abs_tol=0.00003)
632 True
633 >>> math.isclose(a, b, abs_tol=0.00001)
634 False
635
636.. seealso::
637
638 :pep:`485` -- A function for testing approximate equality
639 PEP written by Christopher Barker; implemented by Chris Barker and
640 Tal Einat.
641
642
Yury Selivanovce917c7312015-09-10 17:35:38 -0400643.. _whatsnew-pep-486:
644
Steve Dower76998fe2015-02-26 14:25:33 -0800645PEP 486: Make the Python Launcher aware of virtual environments
646---------------------------------------------------------------
647
648:pep:`486` makes the Windows launcher (see :pep:`397`) aware of an active
649virtual environment. When the default interpreter would be used and the
650``VIRTUAL_ENV`` environment variable is set, the interpreter in the virtual
651environment will be used.
652
653.. seealso::
654
655 :pep:`486` -- Make the Python Launcher aware of virtual environments
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400656 PEP written and implemented by Paul Moore.
Steve Dower76998fe2015-02-26 14:25:33 -0800657
Brett Cannonf299abd2015-04-13 14:21:02 -0400658
Yury Selivanovce917c7312015-09-10 17:35:38 -0400659.. _whatsnew-pep-488:
660
Brett Cannonf299abd2015-04-13 14:21:02 -0400661PEP 488: Elimination of PYO files
662---------------------------------
663
664:pep:`488` does away with the concept of ``.pyo`` files. This means that
Benjamin Petersone3283232015-05-26 21:40:28 -0500665``.pyc`` files represent both unoptimized and optimized bytecode. To prevent the
666need to constantly regenerate bytecode files, ``.pyc`` files now have an
667optional ``opt-`` tag in their name when the bytecode is optimized. This has the
668side-effect of no more bytecode file name clashes when running under either
Yury Selivanovce917c7312015-09-10 17:35:38 -0400669:option:`-O` or :option:`-OO`. Consequently, bytecode files generated from
670:option:`-O`, and :option:`-OO` may now exist simultaneously.
671:func:`importlib.util.cache_from_source` has an updated API to help with
672this change.
Brett Cannonf299abd2015-04-13 14:21:02 -0400673
674.. seealso::
675
676 :pep:`488` -- Elimination of PYO files
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400677 PEP written and implemented by Brett Cannon.
Brett Cannonf299abd2015-04-13 14:21:02 -0400678
679
Yury Selivanovce917c7312015-09-10 17:35:38 -0400680.. _whatsnew-pep-489:
681
Nick Coghland5cacbb2015-05-23 22:24:10 +1000682PEP 489: Multi-phase extension module initialization
683----------------------------------------------------
684
685:pep:`489` updates extension module initialization to take advantage of the
686two step module loading mechanism introduced by :pep:`451` in Python 3.4.
687
688This change brings the import semantics of extension modules that opt-in to
689using the new mechanism much closer to those of Python source and bytecode
Nick Coghlan2ab5b092015-07-03 19:49:15 +1000690modules, including the ability to use any valid identifier as a module name,
Nick Coghland5cacbb2015-05-23 22:24:10 +1000691rather than being restricted to ASCII.
692
693.. seealso::
694
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400695 :pep:`489` -- Multi-phase extension module initialization
696 PEP written by Petr Viktorin, Stefan Behnel, and Nick Coghlan;
Yury Selivanov1f4d4702015-09-09 09:27:29 -0400697 implemented by Petr Viktorin.
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400698
Nick Coghland5cacbb2015-05-23 22:24:10 +1000699
Victor Stinner01adf062014-03-18 00:53:32 +0100700Other Language Changes
701======================
702
703Some smaller changes made to the core Python language are:
704
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400705* Added the ``"namereplace"`` error handlers. The ``"backslashreplace"``
Yury Selivanova33cb352015-09-13 11:21:25 -0400706 error handlers now work with decoding and translating.
Serhiy Storchaka07985ef2015-01-25 22:56:57 +0200707 (Contributed by Serhiy Storchaka in :issue:`19676` and :issue:`22286`.)
Victor Stinner01adf062014-03-18 00:53:32 +0100708
Serhiy Storchaka1dd49822015-03-20 16:54:57 +0200709* The :option:`-b` option now affects comparisons of :class:`bytes` with
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +0300710 :class:`int`. (Contributed by Serhiy Storchaka in :issue:`23681`.)
Victor Stinner01adf062014-03-18 00:53:32 +0100711
Yury Selivanova33cb352015-09-13 11:21:25 -0400712* New Kazakh ``kz1048`` and Tajik ``koi8_t`` :ref:`codecs <standard-encodings>`.
713 (Contributed by Serhiy Storchaka in :issue:`22682` and :issue:`22681`.)
Serhiy Storchaka35a361f2015-09-13 12:07:54 +0300714
Raymond Hettingereac503a2015-05-13 01:09:59 -0700715* Property docstrings are now writable. This is especially useful for
716 :func:`collections.namedtuple` docstrings.
717 (Contributed by Berker Peksag in :issue:`24064`.)
718
Yury Selivanov336b37b2015-09-09 12:23:01 -0400719* Circular imports involving relative imports are now supported.
720 (Contributed by Brett Cannon and Antoine Pitrou in :issue:`17636`.)
721
Victor Stinner01adf062014-03-18 00:53:32 +0100722
723New Modules
724===========
725
Yury Selivanov23950372015-09-12 23:46:39 -0400726typing
727------
728
729The new :mod:`typing` :term:`provisional <provisional api>` module
730provides standard definitions and tools for function type annotations.
731See :ref:`Type Hints <whatsnew-pep-484>` for more information.
732
Brett Cannoncc4dfc12015-03-13 10:40:49 -0400733.. _whatsnew-zipapp:
Victor Stinner01adf062014-03-18 00:53:32 +0100734
Brett Cannoncc4dfc12015-03-13 10:40:49 -0400735zipapp
736------
737
738The new :mod:`zipapp` module (specified in :pep:`441`) provides an API and
739command line tool for creating executable Python Zip Applications, which
Yury Selivanovce917c7312015-09-10 17:35:38 -0400740were introduced in Python 2.6 in :issue:`1739468`, but which were not well
741publicized, either at the time or since.
Brett Cannoncc4dfc12015-03-13 10:40:49 -0400742
743With the new module, bundling your application is as simple as putting all
744the files, including a ``__main__.py`` file, into a directory ``myapp``
Martin Panter1050d2d2016-07-26 11:18:21 +0200745and running:
746
747.. code-block:: shell-session
Brett Cannoncc4dfc12015-03-13 10:40:49 -0400748
749 $ python -m zipapp myapp
750 $ python myapp.pyz
Victor Stinner01adf062014-03-18 00:53:32 +0100751
Yury Selivanovce917c7312015-09-10 17:35:38 -0400752The module implementation has been contributed by Paul Moore in
753:issue:`23491`.
754
755.. seealso::
756
757 :pep:`441` -- Improving Python ZIP Application Support
758
Victor Stinner01adf062014-03-18 00:53:32 +0100759
760Improved Modules
761================
762
Berker Peksag8089cd62015-02-14 01:39:17 +0200763argparse
764--------
765
Martin Panterc04fb562016-02-10 05:44:01 +0000766The :class:`~argparse.ArgumentParser` class now allows disabling
Yury Selivanovce917c7312015-09-10 17:35:38 -0400767:ref:`abbreviated usage <prefix-matching>` of long options by setting
Yury Selivanova88cd642015-09-10 21:26:54 -0400768:ref:`allow_abbrev` to ``False``. (Contributed by Jonathan Paugh,
Yury Selivanovce917c7312015-09-10 17:35:38 -0400769Steven Bethard, paul j3 and Daniel Eriksson in :issue:`14910`.)
770
Yury Selivanov336b37b2015-09-09 12:23:01 -0400771
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400772asyncio
773-------
774
Martin Panter97ce0fa2015-11-14 01:14:54 +0000775Since the :mod:`asyncio` module is :term:`provisional <provisional api>`,
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400776all changes introduced in Python 3.5 have also been backported to Python 3.4.x.
777
Yury Selivanova33cb352015-09-13 11:21:25 -0400778Notable changes in the :mod:`asyncio` module since Python 3.4.0:
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400779
Yury Selivanova33cb352015-09-13 11:21:25 -0400780* New debugging APIs: :meth:`loop.set_debug() <asyncio.BaseEventLoop.set_debug>`
Yury Selivanov72dab132015-09-13 01:39:05 -0400781 and :meth:`loop.get_debug() <asyncio.BaseEventLoop.get_debug>` methods.
Yury Selivanov63ae9f3b2015-09-13 00:29:02 -0400782 (Contributed by Victor Stinner.)
783
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400784* The proactor event loop now supports SSL.
785 (Contributed by Antoine Pitrou and Victor Stinner in :issue:`22560`.)
786
Yury Selivanov72dab132015-09-13 01:39:05 -0400787* A new :meth:`loop.is_closed() <asyncio.BaseEventLoop.is_closed>` method to
Yury Selivanov63ae9f3b2015-09-13 00:29:02 -0400788 check if the event loop is closed.
789 (Contributed by Victor Stinner in :issue:`21326`.)
790
791* A new :meth:`loop.create_task() <asyncio.BaseEventLoop.create_task>`
792 to conveniently create and schedule a new :class:`~asyncio.Task`
793 for a coroutine. The ``create_task`` method is also used by all
Yury Selivanova33cb352015-09-13 11:21:25 -0400794 asyncio functions that wrap coroutines into tasks, such as
795 :func:`asyncio.wait`, :func:`asyncio.gather`, etc.
Yury Selivanov63ae9f3b2015-09-13 00:29:02 -0400796 (Contributed by Victor Stinner.)
797
Yury Selivanova33cb352015-09-13 11:21:25 -0400798* A new :meth:`transport.get_write_buffer_limits() <asyncio.WriteTransport.get_write_buffer_limits>`
Yury Selivanov63ae9f3b2015-09-13 00:29:02 -0400799 method to inquire for *high-* and *low-* water limits of the flow
800 control.
801 (Contributed by Victor Stinner.)
802
803* The :func:`~asyncio.async` function is deprecated in favor of
804 :func:`~asyncio.ensure_future`.
805 (Contributed by Yury Selivanov.)
806
Benjamin Petersonc1db5132016-09-09 12:46:42 -0700807* New :meth:`loop.set_task_factory()
808 <asyncio.AbstractEventLoop.set_task_factory>` and
809 :meth:`loop.get_task_factory() <asyncio.AbstractEventLoop.get_task_factory>`
810 methods to customize the task factory that :meth:`loop.create_task()
811 <asyncio.BaseEventLoop.create_task>` method uses. (Contributed by Yury
812 Selivanov.)
Yury Selivanov63ae9f3b2015-09-13 00:29:02 -0400813
Yury Selivanov72dab132015-09-13 01:39:05 -0400814* New :meth:`Queue.join() <asyncio.Queue.join>` and
815 :meth:`Queue.task_done() <asyncio.Queue.task_done>` queue methods.
Yury Selivanov63ae9f3b2015-09-13 00:29:02 -0400816 (Contributed by Victor Stinner.)
817
818* The ``JoinableQueue`` class was removed, in favor of the
819 :class:`asyncio.Queue` class.
820 (Contributed by Victor Stinner.)
821
Yury Selivanov43d71e22015-10-02 15:05:59 -0400822Updates in 3.5.1:
823
824* The :func:`~asyncio.ensure_future` function and all functions that
825 use it, such as :meth:`loop.run_until_complete() <asyncio.BaseEventLoop.run_until_complete>`,
826 now accept all kinds of :term:`awaitable objects <awaitable>`.
827 (Contributed by Yury Selivanov.)
828
Yury Selivanovbf077ee2015-12-15 00:30:18 -0500829* New :func:`~asyncio.run_coroutine_threadsafe` function to submit
830 coroutines to event loops from other threads.
831 (Contributed by Vincent Michel.)
832
Yury Selivanov4a18b352015-12-15 00:38:28 -0500833* New :meth:`Transport.is_closing() <asyncio.BaseTransport.is_closing>`
Yury Selivanovbf077ee2015-12-15 00:30:18 -0500834 method to check if the transport is closing or closed.
835 (Contributed by Yury Selivanov.)
836
837* The :meth:`loop.create_server() <asyncio.BaseEventLoop.create_server>`
838 method can now accept a list of hosts.
839 (Contributed by Yann Sionneau.)
840
Yury Selivanov950204d2016-05-16 16:23:00 -0400841Updates in 3.5.2:
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.
848 (Contributed by Yury Selivanov.)
849
850* New :meth:`loop.get_exception_handler() <asyncio.BaseEventLoop.get_exception_handler>`
851 method to get the current exception handler.
852 (Contributed by Yury Selivanov.)
853
Yury Selivanov950204d2016-05-16 16:23:00 -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 Selivanovaf745122016-06-08 12:55:29 -0400859* The :meth:`loop.create_connection() <asyncio.BaseEventLoop.create_connection>`
860 and :meth:`loop.create_server() <asyncio.BaseEventLoop.create_server>`
861 methods are optimized to avoid calling the system ``getaddrinfo``
Yury Selivanov950204d2016-05-16 16:23:00 -0400862 function if the address is already resolved.
863 (Contributed by A. Jesse Jiryu Davis.)
864
Yury Selivanovaf745122016-06-08 12:55:29 -0400865* The :meth:`loop.sock_connect(sock, address) <asyncio.BaseEventLoop.sock_connect>`
866 no longer requires the *address* to be resolved prior to the call.
867 (Contributed by A. Jesse Jiryu Davis.)
868
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400869
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400870bz2
871---
872
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400873The :meth:`BZ2Decompressor.decompress <bz2.BZ2Decompressor.decompress>`
874method now accepts an optional *max_length* argument to limit the maximum
875size of decompressed data. (Contributed by Nikolaus Rath in :issue:`15955`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -0400876
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400877
Berker Peksagbf5e9602015-02-06 10:21:37 +0200878cgi
879---
880
Serhiy Storchaka35a361f2015-09-13 12:07:54 +0300881The :class:`~cgi.FieldStorage` class now supports the :term:`context manager`
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400882protocol. (Contributed by Berker Peksag in :issue:`20289`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -0400883
Berker Peksagbf5e9602015-02-06 10:21:37 +0200884
Tal Einatd5519ed2015-05-31 22:05:00 +0300885cmath
886-----
887
Yury Selivanova88cd642015-09-10 21:26:54 -0400888A new function :func:`~cmath.isclose` provides a way to test for approximate
Yury Selivanova33cb352015-09-13 11:21:25 -0400889equality. (Contributed by Chris Barker and Tal Einat in :issue:`24270`.)
Tal Einatd5519ed2015-05-31 22:05:00 +0300890
891
R David Murrayc31e6222014-09-29 11:25:00 -0400892code
893----
894
Yury Selivanova33cb352015-09-13 11:21:25 -0400895The :func:`InteractiveInterpreter.showtraceback() <code.InteractiveInterpreter.showtraceback>`
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400896method now prints the full chained traceback, just like the interactive
897interpreter. (Contributed by Claudiu Popa in :issue:`17442`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -0400898
R David Murrayc31e6222014-09-29 11:25:00 -0400899
Raymond Hettingereac503a2015-05-13 01:09:59 -0700900collections
901-----------
902
Yury Selivanov95fd26b2015-09-12 17:50:58 -0400903.. _whatsnew-ordereddict:
904
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400905The :class:`~collections.OrderedDict` class is now implemented in C, which
906makes it 4 to 100 times faster. (Contributed by Eric Snow in :issue:`16991`.)
907
Yury Selivanova33cb352015-09-13 11:21:25 -0400908:meth:`OrderedDict.items() <collections.OrderedDict.items>`,
909:meth:`OrderedDict.keys() <collections.OrderedDict.keys>`,
910:meth:`OrderedDict.values() <collections.OrderedDict.values>` views now support
Yury Selivanov508a81e2015-09-10 23:37:06 -0400911:func:`reversed` iteration.
912(Contributed by Serhiy Storchaka in :issue:`19505`.)
913
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400914The :class:`~collections.deque` class now defines
915:meth:`~collections.deque.index`, :meth:`~collections.deque.insert`, and
Martin Panter97ce0fa2015-11-14 01:14:54 +0000916:meth:`~collections.deque.copy`, and supports the ``+`` and ``*`` operators.
Yury Selivanov508a81e2015-09-10 23:37:06 -0400917This allows deques to be recognized as a :class:`~collections.abc.MutableSequence`
918and improves their substitutability for lists.
Martin Panter0e5eba22015-10-31 12:18:10 +0000919(Contributed by Raymond Hettinger in :issue:`23704`.)
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400920
921Docstrings produced by :func:`~collections.namedtuple` can now be updated::
Raymond Hettingereac503a2015-05-13 01:09:59 -0700922
923 Point = namedtuple('Point', ['x', 'y'])
Raymond Hettinger850be0f2015-11-09 08:24:53 -0800924 Point.__doc__ += ': Cartesian coodinate'
Raymond Hettingereac503a2015-05-13 01:09:59 -0700925 Point.x.__doc__ = 'abscissa'
926 Point.y.__doc__ = 'ordinate'
927
Yury Selivanovce917c7312015-09-10 17:35:38 -0400928(Contributed by Berker Peksag in :issue:`24064`.)
Raymond Hettingereac503a2015-05-13 01:09:59 -0700929
Martin Panter97ce0fa2015-11-14 01:14:54 +0000930The :class:`~collections.UserString` class now implements the
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400931:meth:`__getnewargs__`, :meth:`__rmod__`, :meth:`~str.casefold`,
932:meth:`~str.format_map`, :meth:`~str.isprintable`, and :meth:`~str.maketrans`
Yury Selivanova33cb352015-09-13 11:21:25 -0400933methods to match the corresponding methods of :class:`str`.
Yury Selivanovce917c7312015-09-10 17:35:38 -0400934(Contributed by Joe Jevnik in :issue:`22189`.)
Yury Selivanov336b37b2015-09-09 12:23:01 -0400935
Yury Selivanov336b37b2015-09-09 12:23:01 -0400936
937collections.abc
938---------------
939
Yury Selivanova33cb352015-09-13 11:21:25 -0400940The :meth:`Sequence.index() <collections.abc.Sequence.index>` method now
Yury Selivanov46a8b402015-09-12 15:52:04 -0400941accepts *start* and *stop* arguments to match the corresponding methods
942of :class:`tuple`, :class:`list`, etc.
943(Contributed by Devin Jeanpierre in :issue:`23086`.)
944
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400945A new :class:`~collections.abc.Generator` abstract base class. (Contributed
Yury Selivanovce917c7312015-09-10 17:35:38 -0400946by Stefan Behnel in :issue:`24018`.)
Yury Selivanov336b37b2015-09-09 12:23:01 -0400947
Martin Panter0e5eba22015-10-31 12:18:10 +0000948New :class:`~collections.abc.Awaitable`, :class:`~collections.abc.Coroutine`,
Yury Selivanovce917c7312015-09-10 17:35:38 -0400949:class:`~collections.abc.AsyncIterator`, and
950:class:`~collections.abc.AsyncIterable` abstract base classes.
951(Contributed by Yury Selivanov in :issue:`24184`.)
952
Yury Selivanova33cb352015-09-13 11:21:25 -0400953For earlier Python versions, a backport of the new ABCs is available in an
Stéphane Wirtel19177fb2018-05-15 20:58:35 +0200954external `PyPI package <https://pypi.org/project/backports_abc>`_.
Yury Selivanova33cb352015-09-13 11:21:25 -0400955
Yury Selivanov336b37b2015-09-09 12:23:01 -0400956
Brett Cannonf1a8df02014-09-12 10:39:48 -0400957compileall
958----------
959
Martin Panterc04fb562016-02-10 05:44:01 +0000960A new :mod:`compileall` option, :samp:`-j {N}`, allows running *N* workers
Martin Panter96a4f072016-02-10 01:17:51 +0000961simultaneously to perform parallel bytecode compilation.
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400962The :func:`~compileall.compile_dir` function has a corresponding ``workers``
963parameter. (Contributed by Claudiu Popa in :issue:`16104`.)
Brett Cannonf1a8df02014-09-12 10:39:48 -0400964
Martin Panterc04fb562016-02-10 05:44:01 +0000965Another new option, ``-r``, allows controlling the maximum recursion
Yury Selivanov46a8b402015-09-12 15:52:04 -0400966level for subdirectories. (Contributed by Claudiu Popa in :issue:`19628`.)
967
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400968The ``-q`` command line option can now be specified more than once, in
Yury Selivanovce917c7312015-09-10 17:35:38 -0400969which case all output, including errors, will be suppressed. The corresponding
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400970``quiet`` parameter in :func:`~compileall.compile_dir`,
971:func:`~compileall.compile_file`, and :func:`~compileall.compile_path` can now
972accept an integer value indicating the level of output suppression.
Yury Selivanovce917c7312015-09-10 17:35:38 -0400973(Contributed by Thomas Kluyver in :issue:`21338`.)
974
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400975
976concurrent.futures
977------------------
978
Yury Selivanova33cb352015-09-13 11:21:25 -0400979The :meth:`Executor.map() <concurrent.futures.Executor.map>` method now accepts a
Yury Selivanova88cd642015-09-10 21:26:54 -0400980*chunksize* argument to allow batching of tasks to improve performance when
981:meth:`~concurrent.futures.ProcessPoolExecutor` is used.
Yury Selivanov5c3111e2015-09-10 18:04:35 -0400982(Contributed by Dan O'Reilly in :issue:`11271`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -0400983
Martin Panter97ce0fa2015-11-14 01:14:54 +0000984The number of workers in the :class:`~concurrent.futures.ThreadPoolExecutor`
985constructor is optional now. The default value is 5 times the number of CPUs.
Yury Selivanov46a8b402015-09-12 15:52:04 -0400986(Contributed by Claudiu Popa in :issue:`21527`.)
987
988
989configparser
990------------
991
Yury Selivanova33cb352015-09-13 11:21:25 -0400992:mod:`configparser` now provides a way to customize the conversion
Martin Panter97ce0fa2015-11-14 01:14:54 +0000993of values by specifying a dictionary of converters in the
Yury Selivanova33cb352015-09-13 11:21:25 -0400994:class:`~configparser.ConfigParser` constructor, or by defining them
995as methods in ``ConfigParser`` subclasses. Converters defined in
Martin Panter97ce0fa2015-11-14 01:14:54 +0000996a parser instance are inherited by its section proxies.
Yury Selivanov23950372015-09-12 23:46:39 -0400997
998Example::
999
1000 >>> import configparser
1001 >>> conv = {}
1002 >>> conv['list'] = lambda v: [e.strip() for e in v.split() if e.strip()]
1003 >>> cfg = configparser.ConfigParser(converters=conv)
1004 >>> cfg.read_string("""
1005 ... [s]
1006 ... list = a b c d e f g
1007 ... """)
1008 >>> cfg.get('s', 'list')
1009 'a b c d e f g'
1010 >>> cfg.getlist('s', 'list')
1011 ['a', 'b', 'c', 'd', 'e', 'f', 'g']
Yury Selivanova33cb352015-09-13 11:21:25 -04001012 >>> section = cfg['s']
1013 >>> section.getlist('list')
1014 ['a', 'b', 'c', 'd', 'e', 'f', 'g']
Yury Selivanov23950372015-09-12 23:46:39 -04001015
Yury Selivanov46a8b402015-09-12 15:52:04 -04001016(Contributed by Łukasz Langa in :issue:`18159`.)
1017
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001018
Berker Peksagbb44fe02014-11-28 23:28:06 +02001019contextlib
1020----------
1021
Serhiy Storchaka35a361f2015-09-13 12:07:54 +03001022The new :func:`~contextlib.redirect_stderr` :term:`context manager` (similar to
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001023:func:`~contextlib.redirect_stdout`) makes it easier for utility scripts to
Yury Selivanovce917c7312015-09-10 17:35:38 -04001024handle inflexible APIs that write their output to :data:`sys.stderr` and
Yury Selivanov23950372015-09-12 23:46:39 -04001025don't provide any options to redirect it::
1026
1027 >>> import contextlib, io, logging
1028 >>> f = io.StringIO()
1029 >>> with contextlib.redirect_stderr(f):
1030 ... logging.warning('warning')
1031 ...
1032 >>> f.getvalue()
1033 'WARNING:root:warning\n'
1034
1035(Contributed by Berker Peksag in :issue:`22389`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001036
Berker Peksagbb44fe02014-11-28 23:28:06 +02001037
Yury Selivanovfe369a62015-09-13 08:29:19 -04001038csv
1039---
1040
1041The :meth:`~csv.csvwriter.writerow` method now supports arbitrary iterables,
1042not just sequences. (Contributed by Serhiy Storchaka in :issue:`23171`.)
1043
1044
Steve Dowerd2bc3892015-04-15 18:06:05 -04001045curses
1046------
Yury Selivanovce917c7312015-09-10 17:35:38 -04001047
Martin Panter97ce0fa2015-11-14 01:14:54 +00001048The new :func:`~curses.update_lines_cols` function updates the :envvar:`LINES`
Yury Selivanova88cd642015-09-10 21:26:54 -04001049and :envvar:`COLS` environment variables. This is useful for detecting
Martin Panter97ce0fa2015-11-14 01:14:54 +00001050manual screen resizing. (Contributed by Arnon Yaari in :issue:`4254`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001051
Steve Dowerd2bc3892015-04-15 18:06:05 -04001052
Yury Selivanov46a8b402015-09-12 15:52:04 -04001053dbm
1054---
1055
1056:func:`dumb.open <dbm.dumb.open>` always creates a new database when the flag
Yury Selivanova33cb352015-09-13 11:21:25 -04001057has the value ``"n"``. (Contributed by Claudiu Popa in :issue:`18039`.)
Yury Selivanov46a8b402015-09-12 15:52:04 -04001058
1059
Berker Peksag102029d2015-03-15 01:18:47 +02001060difflib
1061-------
1062
Yury Selivanova88cd642015-09-10 21:26:54 -04001063The charset of HTML documents generated by
Yury Selivanova33cb352015-09-13 11:21:25 -04001064:meth:`HtmlDiff.make_file() <difflib.HtmlDiff.make_file>`
Yury Selivanova88cd642015-09-10 21:26:54 -04001065can now be customized by using a new *charset* keyword-only argument.
1066The default charset of HTML document changed from ``"ISO-8859-1"``
1067to ``"utf-8"``.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001068(Contributed by Berker Peksag in :issue:`2052`.)
Berker Peksag102029d2015-03-15 01:18:47 +02001069
Yury Selivanova88cd642015-09-10 21:26:54 -04001070The :func:`~difflib.diff_bytes` function can now compare lists of byte
1071strings. This fixes a regression from Python 2.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001072(Contributed by Terry J. Reedy and Greg Ward in :issue:`17445`.)
1073
Greg Ward4d9d2562015-04-20 20:21:21 -04001074
Berker Peksag618e3152015-01-27 02:59:09 +02001075distutils
1076---------
1077
Martin Panter97ce0fa2015-11-14 01:14:54 +00001078Both the ``build`` and ``build_ext`` commands now accept a ``-j`` option to
Yury Selivanovce917c7312015-09-10 17:35:38 -04001079enable parallel building of extension modules.
1080(Contributed by Antoine Pitrou in :issue:`5309`.)
Berker Peksag618e3152015-01-27 02:59:09 +02001081
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001082The :mod:`distutils` module now supports ``xz`` compression, and can be
1083enabled by passing ``xztar`` as an argument to ``bdist --format``.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001084(Contributed by Serhiy Storchaka in :issue:`16314`.)
1085
Serhiy Storchakab9cec6a2015-05-16 22:13:27 +03001086
Antoine Pitroub9d9ce72014-05-15 22:47:33 +02001087doctest
1088-------
Giampaolo Rodola'e09fb712014-04-04 15:34:17 +02001089
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001090The :func:`~doctest.DocTestSuite` function returns an empty
Martin Panter97ce0fa2015-11-14 01:14:54 +00001091:class:`unittest.TestSuite` if *module* contains no docstrings, instead of
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001092raising :exc:`ValueError`. (Contributed by Glenn Jones in :issue:`15916`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001093
Antoine Pitroub9d9ce72014-05-15 22:47:33 +02001094
R David Murrayb744f3a2015-05-16 15:41:07 -04001095email
1096-----
1097
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001098A new policy option :attr:`Policy.mangle_from_ <email.policy.Policy.mangle_from_>`
1099controls whether or not lines that start with ``"From "`` in email bodies are
1100prefixed with a ``">"`` character by generators. The default is ``True`` for
Yury Selivanovce917c7312015-09-10 17:35:38 -04001101:attr:`~email.policy.compat32` and ``False`` for all other policies.
1102(Contributed by Milan Oberkirch in :issue:`20098`.)
R David Murrayfdb23c22015-05-17 14:24:33 -04001103
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001104A new
Yury Selivanova33cb352015-09-13 11:21:25 -04001105:meth:`Message.get_content_disposition() <email.message.Message.get_content_disposition>`
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001106method provides easy access to a canonical value for the
1107:mailheader:`Content-Disposition` header.
1108(Contributed by Abhilash Raj in :issue:`21083`.)
R David Murrayb744f3a2015-05-16 15:41:07 -04001109
Yury Selivanova88cd642015-09-10 21:26:54 -04001110A new policy option :attr:`EmailPolicy.utf8 <email.policy.EmailPolicy.utf8>`
1111can be set to ``True`` to encode email headers using the UTF-8 charset instead
1112of using encoded words. This allows ``Messages`` to be formatted according to
Yury Selivanovce917c7312015-09-10 17:35:38 -04001113:rfc:`6532` and used with an SMTP server that supports the :rfc:`6531`
Yury Selivanova88cd642015-09-10 21:26:54 -04001114``SMTPUTF8`` extension. (Contributed by R. David Murray in
1115:issue:`24211`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001116
Yury Selivanova33cb352015-09-13 11:21:25 -04001117The :class:`mime.text.MIMEText <email.mime.text.MIMEText>` constructor now
1118accepts a :class:`charset.Charset <email.charset.Charset>` instance.
Yury Selivanov46a8b402015-09-12 15:52:04 -04001119(Contributed by Claude Paroz and Berker Peksag in :issue:`16324`.)
1120
R David Murray224ef3e2015-05-17 11:29:21 -04001121
Yury Selivanov4dde5872015-09-11 00:48:21 -04001122enum
1123----
1124
1125The :class:`~enum.Enum` callable has a new parameter *start* to
1126specify the initial number of enum values if only *names* are provided::
1127
1128 >>> Animal = enum.Enum('Animal', 'cat dog', start=10)
1129 >>> Animal.cat
1130 <Animal.cat: 10>
1131 >>> Animal.dog
1132 <Animal.dog: 11>
1133
1134(Contributed by Ethan Furman in :issue:`21706`.)
1135
1136
Yury Selivanov336b37b2015-09-09 12:23:01 -04001137faulthandler
1138------------
1139
Martin Panter97ce0fa2015-11-14 01:14:54 +00001140The :func:`~faulthandler.enable`, :func:`~faulthandler.register`,
Yury Selivanovce917c7312015-09-10 17:35:38 -04001141:func:`~faulthandler.dump_traceback` and
1142:func:`~faulthandler.dump_traceback_later` functions now accept file
1143descriptors in addition to file-like objects.
1144(Contributed by Wei Wu in :issue:`23566`.)
1145
Yury Selivanov336b37b2015-09-09 12:23:01 -04001146
1147functools
1148---------
1149
Yury Selivanov95fd26b2015-09-12 17:50:58 -04001150.. _whatsnew-lrucache:
1151
Martin Panter97ce0fa2015-11-14 01:14:54 +00001152Most of the :func:`~functools.lru_cache` machinery is now implemented in C, making
Yury Selivanova88cd642015-09-10 21:26:54 -04001153it significantly faster. (Contributed by Matt Joiner, Alexey Kachayev, and
Yury Selivanovce917c7312015-09-10 17:35:38 -04001154Serhiy Storchaka in :issue:`14373`.)
1155
Yury Selivanov336b37b2015-09-09 12:23:01 -04001156
Serhiy Storchakac2edcdd2014-09-11 12:17:37 +03001157glob
1158----
1159
Martin Panter97ce0fa2015-11-14 01:14:54 +00001160The :func:`~glob.iglob` and :func:`~glob.glob` functions now support recursive
1161search in subdirectories, using the ``"**"`` pattern.
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001162(Contributed by Serhiy Storchaka in :issue:`13968`.)
Yury Selivanov336b37b2015-09-09 12:23:01 -04001163
Serhiy Storchakac2edcdd2014-09-11 12:17:37 +03001164
Yury Selivanov46a8b402015-09-12 15:52:04 -04001165gzip
1166----
1167
Martin Panter97ce0fa2015-11-14 01:14:54 +00001168The *mode* argument of the :class:`~gzip.GzipFile` constructor now
Yury Selivanov46a8b402015-09-12 15:52:04 -04001169accepts ``"x"`` to request exclusive creation.
1170(Contributed by Tim Heaney in :issue:`19222`.)
1171
1172
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001173heapq
1174-----
1175
Yury Selivanovce917c7312015-09-10 17:35:38 -04001176Element comparison in :func:`~heapq.merge` can now be customized by
Yury Selivanov23950372015-09-12 23:46:39 -04001177passing a :term:`key function` in a new optional *key* keyword argument,
1178and a new optional *reverse* keyword argument can be used to reverse element
1179comparison::
1180
1181 >>> import heapq
1182 >>> a = ['9', '777', '55555']
1183 >>> b = ['88', '6666']
1184 >>> list(heapq.merge(a, b, key=len))
1185 ['9', '88', '777', '6666', '55555']
1186 >>> list(heapq.merge(reversed(a), reversed(b), key=len, reverse=True))
1187 ['55555', '6666', '777', '88', '9']
1188
1189(Contributed by Raymond Hettinger in :issue:`13742`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001190
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001191
Yury Selivanov4dde5872015-09-11 00:48:21 -04001192http
1193----
1194
1195A new :class:`HTTPStatus <http.HTTPStatus>` enum that defines a set of
1196HTTP status codes, reason phrases and long descriptions written in English.
1197(Contributed by Demian Brecht in :issue:`21793`.)
1198
1199
Yury Selivanov46a8b402015-09-12 15:52:04 -04001200http.client
1201-----------
1202
1203:meth:`HTTPConnection.getresponse() <http.client.HTTPConnection.getresponse>`
1204now raises a :exc:`~http.client.RemoteDisconnected` exception when a
1205remote server connection is closed unexpectedly. Additionally, if a
1206:exc:`ConnectionError` (of which ``RemoteDisconnected``
1207is a subclass) is raised, the client socket is now closed automatically,
Yury Selivanov23950372015-09-12 23:46:39 -04001208and will reconnect on the next request::
1209
1210 import http.client
1211 conn = http.client.HTTPConnection('www.python.org')
1212 for retries in range(3):
1213 try:
1214 conn.request('GET', '/')
1215 resp = conn.getresponse()
1216 except http.client.RemoteDisconnected:
1217 pass
1218
Yury Selivanov46a8b402015-09-12 15:52:04 -04001219(Contributed by Martin Panter in :issue:`3566`.)
1220
1221
Guido van Rossum7ca13532015-05-23 15:27:51 -07001222idlelib and IDLE
Terry Jan Reedy44825cf2015-05-23 18:19:42 -04001223----------------
1224
1225Since idlelib implements the IDLE shell and editor and is not intended for
Yury Selivanova88cd642015-09-10 21:26:54 -04001226import by other programs, it gets improvements with every release. See
Terry Jan Reedy44825cf2015-05-23 18:19:42 -04001227:file:`Lib/idlelib/NEWS.txt` for a cumulative list of changes since 3.4.0,
1228as well as changes made in future 3.5.x releases. This file is also available
Serhiy Storchaka35a361f2015-09-13 12:07:54 +03001229from the IDLE :menuselection:`Help --> About IDLE` dialog.
Terry Jan Reedy44825cf2015-05-23 18:19:42 -04001230
Yury Selivanovce917c7312015-09-10 17:35:38 -04001231
Serhiy Storchaka38684c32014-09-09 19:07:49 +03001232imaplib
1233-------
1234
Martin Panter97ce0fa2015-11-14 01:14:54 +00001235The :class:`~imaplib.IMAP4` class now supports the :term:`context manager` protocol.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001236When used in a :keyword:`with` statement, the IMAP4 ``LOGOUT``
1237command will be called automatically at the end of the block.
1238(Contributed by Tarek Ziadé and Serhiy Storchaka in :issue:`4972`.)
Serhiy Storchaka38684c32014-09-09 19:07:49 +03001239
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001240The :mod:`imaplib` module now supports :rfc:`5161` (ENABLE Extension)
Yury Selivanova33cb352015-09-13 11:21:25 -04001241and :rfc:`6855` (UTF-8 Support) via the :meth:`IMAP4.enable() <imaplib.IMAP4.enable>`
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001242method. A new :attr:`IMAP4.utf8_enabled <imaplib.IMAP4.utf8_enabled>`
Martin Panter97ce0fa2015-11-14 01:14:54 +00001243attribute tracks whether or not :rfc:`6855` support is enabled.
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001244(Contributed by Milan Oberkirch, R. David Murray, and Maciej Szulik in
1245:issue:`21800`.)
R David Murraya6429db2015-05-10 19:17:23 -04001246
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001247The :mod:`imaplib` module now automatically encodes non-ASCII string usernames
1248and passwords using UTF-8, as recommended by the RFCs. (Contributed by Milan
Yury Selivanovce917c7312015-09-10 17:35:38 -04001249Oberkirch in :issue:`21800`.)
1250
R David Murraya6429db2015-05-10 19:17:23 -04001251
R David Murray2f608202014-06-26 12:27:57 -04001252imghdr
1253------
1254
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001255The :func:`~imghdr.what` function now recognizes the
1256`OpenEXR <http://www.openexr.com>`_ format
1257(contributed by Martin Vignali and Claudiu Popa in :issue:`20295`),
1258and the `WebP <https://en.wikipedia.org/wiki/WebP>`_ format
1259(contributed by Fabrice Aneche and Claudiu Popa in :issue:`20197`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001260
R David Murray2f608202014-06-26 12:27:57 -04001261
Antoine Pitroub9d9ce72014-05-15 22:47:33 +02001262importlib
1263---------
1264
Yury Selivanov3b765522015-09-10 19:02:24 -04001265The :class:`util.LazyLoader <importlib.util.LazyLoader>` class allows for
1266lazy loading of modules in applications where startup time is important.
1267(Contributed by Brett Cannon in :issue:`17621`.)
Antoine Pitroub9d9ce72014-05-15 22:47:33 +02001268
Yury Selivanova33cb352015-09-13 11:21:25 -04001269The :func:`abc.InspectLoader.source_to_code() <importlib.abc.InspectLoader.source_to_code>`
Yury Selivanov3b765522015-09-10 19:02:24 -04001270method is now a static method. This makes it easier to initialize a module
1271object with code compiled from a string by running
1272``exec(code, module.__dict__)``.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001273(Contributed by Brett Cannon in :issue:`21156`.)
Antoine Pitroub9d9ce72014-05-15 22:47:33 +02001274
Yury Selivanova33cb352015-09-13 11:21:25 -04001275The new :func:`util.module_from_spec() <importlib.util.module_from_spec>`
Yury Selivanova88cd642015-09-10 21:26:54 -04001276function is now the preferred way to create a new module. As opposed to
1277creating a :class:`types.ModuleType` instance directly, this new function
1278will set the various import-controlled attributes based on the passed-in
1279spec object. (Contributed by Brett Cannon in :issue:`20383`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001280
Brett Cannon2a17bde2014-05-30 14:55:29 -04001281
Antoine Pitroub9d9ce72014-05-15 22:47:33 +02001282inspect
1283-------
Victor Stinner01adf062014-03-18 00:53:32 +01001284
Martin Panter97ce0fa2015-11-14 01:14:54 +00001285Both the :class:`~inspect.Signature` and :class:`~inspect.Parameter` classes are
Yury Selivanova88cd642015-09-10 21:26:54 -04001286now picklable and hashable. (Contributed by Yury Selivanov in :issue:`20726`
Yury Selivanovce917c7312015-09-10 17:35:38 -04001287and :issue:`20334`.)
Yury Selivanova5d63dd2014-03-27 11:31:43 -04001288
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001289A new
Yury Selivanova33cb352015-09-13 11:21:25 -04001290:meth:`BoundArguments.apply_defaults() <inspect.BoundArguments.apply_defaults>`
Yury Selivanov23950372015-09-12 23:46:39 -04001291method provides a way to set default values for missing arguments::
1292
1293 >>> def foo(a, b='ham', *args): pass
1294 >>> ba = inspect.signature(foo).bind('spam')
1295 >>> ba.apply_defaults()
1296 >>> ba.arguments
1297 OrderedDict([('a', 'spam'), ('b', 'ham'), ('args', ())])
1298
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001299(Contributed by Yury Selivanov in :issue:`24190`.)
Yury Selivanovb907a512015-05-16 13:45:09 -04001300
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001301A new class method
Yury Selivanova33cb352015-09-13 11:21:25 -04001302:meth:`Signature.from_callable() <inspect.Signature.from_callable>` makes
Yury Selivanovce917c7312015-09-10 17:35:38 -04001303subclassing of :class:`~inspect.Signature` easier. (Contributed
1304by Yury Selivanov and Eric Snow in :issue:`17373`.)
Yury Selivanovda396452014-03-27 12:09:24 -04001305
Serhiy Storchaka35a361f2015-09-13 12:07:54 +03001306The :func:`~inspect.signature` function now accepts a *follow_wrapped*
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001307optional keyword argument, which, when set to ``False``, disables automatic
1308following of ``__wrapped__`` links.
1309(Contributed by Yury Selivanov in :issue:`20691`.)
Yury Selivanovbcd4fc12015-05-20 14:30:08 -04001310
Yury Selivanovce917c7312015-09-10 17:35:38 -04001311A set of new functions to inspect
1312:term:`coroutine functions <coroutine function>` and
Yury Selivanova88cd642015-09-10 21:26:54 -04001313:term:`coroutine objects <coroutine>` has been added:
Yury Selivanovce917c7312015-09-10 17:35:38 -04001314:func:`~inspect.iscoroutine`, :func:`~inspect.iscoroutinefunction`,
1315:func:`~inspect.isawaitable`, :func:`~inspect.getcoroutinelocals`,
1316and :func:`~inspect.getcoroutinestate`.
1317(Contributed by Yury Selivanov in :issue:`24017` and :issue:`24400`.)
Yury Selivanovf3e40fa2015-05-21 11:50:30 -04001318
Martin Panter97ce0fa2015-11-14 01:14:54 +00001319The :func:`~inspect.stack`, :func:`~inspect.trace`,
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001320:func:`~inspect.getouterframes`, and :func:`~inspect.getinnerframes`
1321functions now return a list of named tuples.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001322(Contributed by Daniel Shahaf in :issue:`16808`.)
Yury Selivanov5376ba92015-06-22 12:19:30 -04001323
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001324
Yury Selivanov4dde5872015-09-11 00:48:21 -04001325io
1326--
1327
Yury Selivanova33cb352015-09-13 11:21:25 -04001328A new :meth:`BufferedIOBase.readinto1() <io.BufferedIOBase.readinto1>`
Yury Selivanov4dde5872015-09-11 00:48:21 -04001329method, that uses at most one call to the underlying raw stream's
Yury Selivanova33cb352015-09-13 11:21:25 -04001330:meth:`RawIOBase.read() <io.RawIOBase.read>` or
1331:meth:`RawIOBase.readinto() <io.RawIOBase.readinto>` methods.
Yury Selivanov4dde5872015-09-11 00:48:21 -04001332(Contributed by Nikolaus Rath in :issue:`20578`.)
1333
1334
Antoine Pitrou0dfce562014-05-15 22:55:40 +02001335ipaddress
1336---------
1337
Martin Panter97ce0fa2015-11-14 01:14:54 +00001338Both the :class:`~ipaddress.IPv4Network` and :class:`~ipaddress.IPv6Network` classes
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001339now accept an ``(address, netmask)`` tuple argument, so as to easily construct
Yury Selivanov23950372015-09-12 23:46:39 -04001340network objects from existing addresses::
1341
1342 >>> import ipaddress
1343 >>> ipaddress.IPv4Network(('127.0.0.0', 8))
1344 IPv4Network('127.0.0.0/8')
1345 >>> ipaddress.IPv4Network(('127.0.0.0', '255.0.0.0'))
1346 IPv4Network('127.0.0.0/8')
1347
1348(Contributed by Peter Moody and Antoine Pitrou in :issue:`16531`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001349
Martin Panter97ce0fa2015-11-14 01:14:54 +00001350A new :attr:`~ipaddress.IPv4Network.reverse_pointer` attribute for the
Yury Selivanov508a81e2015-09-10 23:37:06 -04001351:class:`~ipaddress.IPv4Network` and :class:`~ipaddress.IPv6Network` classes
Yury Selivanov23950372015-09-12 23:46:39 -04001352returns the name of the reverse DNS PTR record::
1353
1354 >>> import ipaddress
1355 >>> addr = ipaddress.IPv4Address('127.0.0.1')
1356 >>> addr.reverse_pointer
1357 '1.0.0.127.in-addr.arpa'
1358 >>> addr6 = ipaddress.IPv6Address('::1')
1359 >>> addr6.reverse_pointer
1360 '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa'
1361
Yury Selivanov508a81e2015-09-10 23:37:06 -04001362(Contributed by Leon Weber in :issue:`20480`.)
1363
Antoine Pitrou0dfce562014-05-15 22:55:40 +02001364
Berker Peksag39e4c4d2014-11-10 09:56:54 +02001365json
1366----
1367
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001368The :mod:`json.tool` command line interface now preserves the order of keys in
1369JSON objects passed in input. The new ``--sort-keys`` option can be used
Yury Selivanovce917c7312015-09-10 17:35:38 -04001370to sort the keys alphabetically. (Contributed by Berker Peksag
1371in :issue:`21650`.)
Berker Peksag39e4c4d2014-11-10 09:56:54 +02001372
Serhiy Storchaka35a361f2015-09-13 12:07:54 +03001373JSON decoder now raises :exc:`~json.JSONDecodeError` instead of
Yury Selivanov46a8b402015-09-12 15:52:04 -04001374:exc:`ValueError` to provide better context information about the error.
1375(Contributed by Serhiy Storchaka in :issue:`19361`.)
1376
1377
1378linecache
1379---------
1380
1381A new :func:`~linecache.lazycache` function can be used to capture information
Martin Panter97ce0fa2015-11-14 01:14:54 +00001382about a non-file-based module to permit getting its lines later via
Yury Selivanov46a8b402015-09-12 15:52:04 -04001383:func:`~linecache.getline`. This avoids doing I/O until a line is actually
1384needed, without having to carry the module globals around indefinitely.
1385(Contributed by Robert Collins in :issue:`17911`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001386
Serhiy Storchaka47efb4a2015-01-26 13:16:30 +02001387
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001388locale
1389------
1390
Yury Selivanovce917c7312015-09-10 17:35:38 -04001391A new :func:`~locale.delocalize` function can be used to convert a string into
Yury Selivanov23950372015-09-12 23:46:39 -04001392a normalized number string, taking the ``LC_NUMERIC`` settings into account::
1393
1394 >>> import locale
1395 >>> locale.setlocale(locale.LC_NUMERIC, 'de_DE.UTF-8')
1396 'de_DE.UTF-8'
1397 >>> locale.delocalize('1.234,56')
1398 '1234.56'
1399 >>> locale.setlocale(locale.LC_NUMERIC, 'en_US.UTF-8')
1400 'en_US.UTF-8'
1401 >>> locale.delocalize('1,234.56')
1402 '1234.56'
1403
Yury Selivanovce917c7312015-09-10 17:35:38 -04001404(Contributed by Cédric Krier in :issue:`13918`.)
1405
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001406
1407logging
1408-------
1409
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001410All logging methods (:class:`~logging.Logger` :meth:`~logging.Logger.log`,
Yury Selivanovce917c7312015-09-10 17:35:38 -04001411:meth:`~logging.Logger.exception`, :meth:`~logging.Logger.critical`,
1412:meth:`~logging.Logger.debug`, etc.), now accept exception instances
Serhiy Storchaka35a361f2015-09-13 12:07:54 +03001413as an *exc_info* argument, in addition to boolean values and exception
Yury Selivanov6d9dd752015-09-13 01:10:19 -04001414tuples::
1415
1416 >>> import logging
1417 >>> try:
1418 ... 1/0
1419 ... except ZeroDivisionError as ex:
1420 ... logging.error('exception', exc_info=ex)
1421 ERROR:root:exception
1422
1423(Contributed by Yury Selivanov in :issue:`20537`.)
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001424
Yury Selivanova88cd642015-09-10 21:26:54 -04001425The :class:`handlers.HTTPHandler <logging.handlers.HTTPHandler>` class now
1426accepts an optional :class:`ssl.SSLContext` instance to configure SSL
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001427settings used in an HTTP connection.
1428(Contributed by Alex Gaynor in :issue:`22788`.)
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001429
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001430The :class:`handlers.QueueListener <logging.handlers.QueueListener>` class now
1431takes a *respect_handler_level* keyword argument which, if set to ``True``,
1432will pass messages to handlers taking handler levels into account.
1433(Contributed by Vinay Sajip.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001434
Yury Selivanov336b37b2015-09-09 12:23:01 -04001435
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001436lzma
1437----
1438
Yury Selivanova33cb352015-09-13 11:21:25 -04001439The :meth:`LZMADecompressor.decompress() <lzma.LZMADecompressor.decompress>`
Yury Selivanova88cd642015-09-10 21:26:54 -04001440method now accepts an optional *max_length* argument to limit the maximum
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001441size of decompressed data.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001442(Contributed by Martin Panter in :issue:`15955`.)
1443
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001444
Tal Einatf67b0a32015-05-31 22:18:31 +03001445math
1446----
1447
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001448Two new constants have been added to the :mod:`math` module: :data:`~math.inf`
1449and :data:`~math.nan`. (Contributed by Mark Dickinson in :issue:`23185`.)
Yury Selivanov336b37b2015-09-09 12:23:01 -04001450
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001451A new function :func:`~math.isclose` provides a way to test for approximate
Yury Selivanovce917c7312015-09-10 17:35:38 -04001452equality. (Contributed by Chris Barker and Tal Einat in :issue:`24270`.)
Tal Einatf67b0a32015-05-31 22:18:31 +03001453
Yury Selivanovce917c7312015-09-10 17:35:38 -04001454A new :func:`~math.gcd` function has been added. The :func:`fractions.gcd`
1455function is now deprecated. (Contributed by Mark Dickinson and Serhiy
1456Storchaka in :issue:`22486`.)
1457
Yury Selivanov336b37b2015-09-09 12:23:01 -04001458
Yury Selivanov46a8b402015-09-12 15:52:04 -04001459multiprocessing
1460---------------
1461
Yury Selivanova33cb352015-09-13 11:21:25 -04001462:func:`sharedctypes.synchronized() <multiprocessing.sharedctypes.synchronized>`
Yury Selivanov23950372015-09-12 23:46:39 -04001463objects now support the :term:`context manager` protocol.
1464(Contributed by Charles-François Natali in :issue:`21565`.)
Yury Selivanov46a8b402015-09-12 15:52:04 -04001465
1466
Yury Selivanov336b37b2015-09-09 12:23:01 -04001467operator
1468--------
1469
Yury Selivanova88cd642015-09-10 21:26:54 -04001470:func:`~operator.attrgetter`, :func:`~operator.itemgetter`,
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001471and :func:`~operator.methodcaller` objects now support pickling.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001472(Contributed by Josh Rosenberg and Serhiy Storchaka in :issue:`22955`.)
1473
Yury Selivanov4dde5872015-09-11 00:48:21 -04001474New :func:`~operator.matmul` and :func:`~operator.imatmul` functions
1475to perform matrix multiplication.
1476(Contributed by Benjamin Peterson in :issue:`21176`.)
1477
Yury Selivanov336b37b2015-09-09 12:23:01 -04001478
Zachary Ware63f277b2014-06-19 09:46:37 -05001479os
1480--
1481
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001482The new :func:`~os.scandir` function returning an iterator of
1483:class:`~os.DirEntry` objects has been added. If possible, :func:`~os.scandir`
1484extracts file attributes while scanning a directory, removing the need to
1485perform subsequent system calls to determine file type or attributes, which may
Yury Selivanovce917c7312015-09-10 17:35:38 -04001486significantly improve performance. (Contributed by Ben Hoyt with the help
1487of Victor Stinner in :issue:`22524`.)
Victor Stinner6036e442015-03-08 01:58:04 +01001488
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001489On Windows, a new
1490:attr:`stat_result.st_file_attributes <os.stat_result.st_file_attributes>`
Yury Selivanova33cb352015-09-13 11:21:25 -04001491attribute is now available. It corresponds to the ``dwFileAttributes`` member
1492of the ``BY_HANDLE_FILE_INFORMATION`` structure returned by
Yury Selivanovce917c7312015-09-10 17:35:38 -04001493``GetFileInformationByHandle()``. (Contributed by Ben Hoyt in :issue:`21719`.)
Zachary Ware63f277b2014-06-19 09:46:37 -05001494
Martin Panter97ce0fa2015-11-14 01:14:54 +00001495The :func:`~os.urandom` function now uses the ``getrandom()`` syscall on Linux 3.17
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001496or newer, and ``getentropy()`` on OpenBSD 5.6 and newer, removing the need to
1497use ``/dev/urandom`` and avoiding failures due to potential file descriptor
Yury Selivanovce917c7312015-09-10 17:35:38 -04001498exhaustion. (Contributed by Victor Stinner in :issue:`22181`.)
Victor Stinnerace88482015-07-29 02:28:32 +02001499
Martin Panterc04fb562016-02-10 05:44:01 +00001500New :func:`~os.get_blocking` and :func:`~os.set_blocking` functions allow
1501getting and setting a file descriptor's blocking mode (:data:`~os.O_NONBLOCK`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001502(Contributed by Victor Stinner in :issue:`22054`.)
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001503
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001504The :func:`~os.truncate` and :func:`~os.ftruncate` functions are now supported
1505on Windows. (Contributed by Steve Dower in :issue:`23668`.)
Serhiy Storchaka38220932015-03-31 15:31:53 +03001506
Yury Selivanova88cd642015-09-10 21:26:54 -04001507There is a new :func:`os.path.commonpath` function returning the longest
Yury Selivanovce917c7312015-09-10 17:35:38 -04001508common sub-path of each passed pathname. Unlike the
Yury Selivanova88cd642015-09-10 21:26:54 -04001509:func:`os.path.commonprefix` function, it always returns a valid
Yury Selivanov23950372015-09-12 23:46:39 -04001510path::
1511
1512 >>> os.path.commonprefix(['/usr/lib', '/usr/local/lib'])
1513 '/usr/l'
1514
1515 >>> os.path.commonpath(['/usr/lib', '/usr/local/lib'])
1516 '/usr'
1517
1518(Contributed by Rafik Draoui and Serhiy Storchaka in :issue:`10395`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001519
Serhiy Storchaka38220932015-03-31 15:31:53 +03001520
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001521pathlib
1522-------
1523
Yury Selivanova33cb352015-09-13 11:21:25 -04001524The new :meth:`Path.samefile() <pathlib.Path.samefile>` method can be used
Martin Panter97ce0fa2015-11-14 01:14:54 +00001525to check whether the path points to the same file as another path, which can
1526be either another :class:`~pathlib.Path` object, or a string::
Yury Selivanov6d9dd752015-09-13 01:10:19 -04001527
1528 >>> import pathlib
1529 >>> p1 = pathlib.Path('/etc/hosts')
1530 >>> p2 = pathlib.Path('/etc/../etc/hosts')
1531 >>> p1.samefile(p2)
1532 True
1533
Yury Selivanovce917c7312015-09-10 17:35:38 -04001534(Contributed by Vajrasky Kok and Antoine Pitrou in :issue:`19775`.)
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001535
Berker Peksagad56c922015-10-19 00:56:39 +03001536The :meth:`Path.mkdir() <pathlib.Path.mkdir>` method now accepts a new optional
Berker Peksag5783ee12015-10-18 20:22:15 +03001537*exist_ok* argument to match ``mkdir -p`` and :func:`os.makedirs`
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001538functionality. (Contributed by Berker Peksag in :issue:`21539`.)
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001539
Yury Selivanova33cb352015-09-13 11:21:25 -04001540There is a new :meth:`Path.expanduser() <pathlib.Path.expanduser>` method to
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001541expand ``~`` and ``~user`` prefixes. (Contributed by Serhiy Storchaka and
1542Claudiu Popa in :issue:`19776`.)
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001543
Yury Selivanova33cb352015-09-13 11:21:25 -04001544A new :meth:`Path.home() <pathlib.Path.home>` class method can be used to get
Martin Panter97ce0fa2015-11-14 01:14:54 +00001545a :class:`~pathlib.Path` instance representing the user’s home
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001546directory.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001547(Contributed by Victor Salgado and Mayank Tripathi in :issue:`19777`.)
1548
Yury Selivanova33cb352015-09-13 11:21:25 -04001549New :meth:`Path.write_text() <pathlib.Path.write_text>`,
1550:meth:`Path.read_text() <pathlib.Path.read_text>`,
1551:meth:`Path.write_bytes() <pathlib.Path.write_bytes>`,
1552:meth:`Path.read_bytes() <pathlib.Path.read_bytes>` methods to simplify
Yury Selivanov4dde5872015-09-11 00:48:21 -04001553read/write operations on files.
Yury Selivanov6d9dd752015-09-13 01:10:19 -04001554
1555The following code snippet will create or rewrite existing file
1556``~/spam42``::
1557
1558 >>> import pathlib
1559 >>> p = pathlib.Path('~/spam42')
1560 >>> p.expanduser().write_text('ham')
1561 3
1562
Yury Selivanov4dde5872015-09-11 00:48:21 -04001563(Contributed by Christopher Welborn in :issue:`20218`.)
1564
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001565
Serhiy Storchaka58e41342015-03-31 14:07:24 +03001566pickle
1567------
1568
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001569Nested objects, such as unbound methods or nested classes, can now be pickled
Yury Selivanova88cd642015-09-10 21:26:54 -04001570using :ref:`pickle protocols <pickle-protocols>` older than protocol version 4.
1571Protocol version 4 already supports these cases. (Contributed by Serhiy
1572Storchaka in :issue:`23611`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001573
Serhiy Storchaka58e41342015-03-31 14:07:24 +03001574
R David Murrayb8cd3e42015-05-16 15:05:53 -04001575poplib
1576------
1577
Yury Selivanova33cb352015-09-13 11:21:25 -04001578A new :meth:`POP3.utf8() <poplib.POP3.utf8>` command enables :rfc:`6856`
Yury Selivanova88cd642015-09-10 21:26:54 -04001579(Internationalized Email) support, if a POP server supports it.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001580(Contributed by Milan OberKirch in :issue:`21804`.)
1581
R David Murrayb8cd3e42015-05-16 15:05:53 -04001582
Serhiy Storchaka9baa5b22014-09-29 22:49:23 +03001583re
1584--
1585
Yury Selivanov46a8b402015-09-12 15:52:04 -04001586References and conditional references to groups with fixed length are now
Yury Selivanov23950372015-09-12 23:46:39 -04001587allowed in lookbehind assertions::
1588
1589 >>> import re
1590 >>> pat = re.compile(r'(a|b).(?<=\1)c')
1591 >>> pat.match('aac')
1592 <_sre.SRE_Match object; span=(0, 3), match='aac'>
1593 >>> pat.match('bbc')
1594 <_sre.SRE_Match object; span=(0, 3), match='bbc'>
1595
Yury Selivanov46a8b402015-09-12 15:52:04 -04001596(Contributed by Serhiy Storchaka in :issue:`9179`.)
1597
Martin Panter97ce0fa2015-11-14 01:14:54 +00001598The number of capturing groups in regular expressions is no longer limited to
Yury Selivanovce917c7312015-09-10 17:35:38 -04001599100. (Contributed by Serhiy Storchaka in :issue:`22437`.)
Serhiy Storchaka9baa5b22014-09-29 22:49:23 +03001600
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001601The :func:`~re.sub` and :func:`~re.subn` functions now replace unmatched
Yury Selivanova88cd642015-09-10 21:26:54 -04001602groups with empty strings instead of raising an exception.
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001603(Contributed by Serhiy Storchaka in :issue:`1519638`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001604
Martin Panter97ce0fa2015-11-14 01:14:54 +00001605The :class:`re.error` exceptions have new attributes,
Yury Selivanov508a81e2015-09-10 23:37:06 -04001606:attr:`~re.error.msg`, :attr:`~re.error.pattern`,
1607:attr:`~re.error.pos`, :attr:`~re.error.lineno`,
Martin Panter97ce0fa2015-11-14 01:14:54 +00001608and :attr:`~re.error.colno`, that provide better context
Yury Selivanov23950372015-09-12 23:46:39 -04001609information about the error::
1610
1611 >>> re.compile("""
1612 ... (?x)
1613 ... .++
1614 ... """)
1615 Traceback (most recent call last):
1616 ...
1617 sre_constants.error: multiple repeat at position 16 (line 3, column 7)
1618
Yury Selivanov508a81e2015-09-10 23:37:06 -04001619(Contributed by Serhiy Storchaka in :issue:`22578`.)
1620
Serhiy Storchaka7438e4b2014-10-10 11:06:31 +03001621
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001622readline
1623--------
1624
Yury Selivanova88cd642015-09-10 21:26:54 -04001625A new :func:`~readline.append_history_file` function can be used to append
1626the specified number of trailing elements in history to the given file.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001627(Contributed by Bruno Cauet in :issue:`22940`.)
1628
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001629
Yury Selivanov508a81e2015-09-10 23:37:06 -04001630selectors
1631---------
1632
Yury Selivanov4dde5872015-09-11 00:48:21 -04001633The new :class:`~selectors.DevpollSelector` supports efficient
1634``/dev/poll`` polling on Solaris.
Yury Selivanov508a81e2015-09-10 23:37:06 -04001635(Contributed by Giampaolo Rodola' in :issue:`18931`.)
1636
1637
R David Murray6ffface2014-06-11 14:40:13 -04001638shutil
1639------
1640
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001641The :func:`~shutil.move` function now accepts a *copy_function* argument,
1642allowing, for example, the :func:`~shutil.copy` function to be used instead of
1643the default :func:`~shutil.copy2` if there is a need to ignore file metadata
1644when moving.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001645(Contributed by Claudiu Popa in :issue:`19840`.)
R David Murray6ffface2014-06-11 14:40:13 -04001646
Yury Selivanova88cd642015-09-10 21:26:54 -04001647The :func:`~shutil.make_archive` function now supports the *xztar* format.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001648(Contributed by Serhiy Storchaka in :issue:`5411`.)
1649
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001650
Antoine Pitroub9d9ce72014-05-15 22:47:33 +02001651signal
1652------
Brett Cannona04dbe42014-04-04 13:53:38 -04001653
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001654On Windows, the :func:`~signal.set_wakeup_fd` function now also supports
1655socket handles. (Contributed by Victor Stinner in :issue:`22018`.)
Victor Stinnerbbe38032015-04-01 16:32:32 +02001656
Yury Selivanova88cd642015-09-10 21:26:54 -04001657Various ``SIG*`` constants in the :mod:`signal` module have been converted into
Yury Selivanovce917c7312015-09-10 17:35:38 -04001658:mod:`Enums <enum>`. This allows meaningful names to be printed
1659during debugging, instead of integer "magic numbers".
1660(Contributed by Giampaolo Rodola' in :issue:`21076`.)
1661
R David Murray1976d9b2014-04-14 20:28:36 -04001662
R David Murray554bcbf2014-06-11 11:18:08 -04001663smtpd
1664-----
1665
Martin Panter97ce0fa2015-11-14 01:14:54 +00001666Both the :class:`~smtpd.SMTPServer` and :class:`~smtpd.SMTPChannel` classes now
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001667accept a *decode_data* keyword argument to determine if the ``DATA`` portion of
1668the SMTP transaction is decoded using the ``"utf-8"`` codec or is instead
Yury Selivanova88cd642015-09-10 21:26:54 -04001669provided to the
Yury Selivanova33cb352015-09-13 11:21:25 -04001670:meth:`SMTPServer.process_message() <smtpd.SMTPServer.process_message>`
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001671method as a byte string. The default is ``True`` for backward compatibility
1672reasons, but will change to ``False`` in Python 3.6. If *decode_data* is set
Yury Selivanova33cb352015-09-13 11:21:25 -04001673to ``False``, the ``process_message`` method must be prepared to accept keyword
1674arguments.
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001675(Contributed by Maciej Szulik in :issue:`19662`.)
R David Murraya33df312015-05-11 12:11:40 -04001676
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001677The :class:`~smtpd.SMTPServer` class now advertises the ``8BITMIME`` extension
1678(:rfc:`6152`) if *decode_data* has been set ``True``. If the client
Yury Selivanovce917c7312015-09-10 17:35:38 -04001679specifies ``BODY=8BITMIME`` on the ``MAIL`` command, it is passed to
Yury Selivanova33cb352015-09-13 11:21:25 -04001680:meth:`SMTPServer.process_message() <smtpd.SMTPServer.process_message>`
Serhiy Storchaka35a361f2015-09-13 12:07:54 +03001681via the *mail_options* keyword.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001682(Contributed by Milan Oberkirch and R. David Murray in :issue:`21795`.)
R David Murraya33df312015-05-11 12:11:40 -04001683
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001684The :class:`~smtpd.SMTPServer` class now also supports the ``SMTPUTF8``
1685extension (:rfc:`6531`: Internationalized Email). If the client specified
1686``SMTPUTF8 BODY=8BITMIME`` on the ``MAIL`` command, they are passed to
Yury Selivanova33cb352015-09-13 11:21:25 -04001687:meth:`SMTPServer.process_message() <smtpd.SMTPServer.process_message>`
Serhiy Storchaka35a361f2015-09-13 12:07:54 +03001688via the *mail_options* keyword. It is the responsibility of the
Yury Selivanova33cb352015-09-13 11:21:25 -04001689``process_message`` method to correctly handle the ``SMTPUTF8`` data.
1690(Contributed by Milan Oberkirch in :issue:`21725`.)
R David Murray554bcbf2014-06-11 11:18:08 -04001691
Yury Selivanovce917c7312015-09-10 17:35:38 -04001692It is now possible to provide, directly or via name resolution, IPv6
1693addresses in the :class:`~smtpd.SMTPServer` constructor, and have it
1694successfully connect. (Contributed by Milan Oberkirch in :issue:`14758`.)
1695
R David Murray6fe56a32014-06-11 13:48:58 -04001696
R David Murray76e13c12014-07-03 14:47:46 -04001697smtplib
1698-------
1699
Yury Selivanova33cb352015-09-13 11:21:25 -04001700A new :meth:`SMTP.auth() <smtplib.SMTP.auth>` method provides a convenient way to
Yury Selivanovce917c7312015-09-10 17:35:38 -04001701implement custom authentication mechanisms. (Contributed by Milan
1702Oberkirch in :issue:`15014`.)
R David Murray76e13c12014-07-03 14:47:46 -04001703
Yury Selivanova33cb352015-09-13 11:21:25 -04001704The :meth:`SMTP.set_debuglevel() <smtplib.SMTP.set_debuglevel>` method now
Yury Selivanova88cd642015-09-10 21:26:54 -04001705accepts an additional debuglevel (2), which enables timestamps in debug
1706messages. (Contributed by Gavin Chappell and Maciej Szulik in :issue:`16914`.)
R David Murray0c49b892015-04-16 17:14:42 -04001707
Martin Panter97ce0fa2015-11-14 01:14:54 +00001708Both the :meth:`SMTP.sendmail() <smtplib.SMTP.sendmail>` and
Yury Selivanova33cb352015-09-13 11:21:25 -04001709:meth:`SMTP.send_message() <smtplib.SMTP.send_message>` methods now
Martin Pantera90a4a92016-05-30 04:04:50 +00001710support :rfc:`6531` (SMTPUTF8).
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001711(Contributed by Milan Oberkirch and R. David Murray in :issue:`22027`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001712
R David Murraycee7cf62015-05-16 13:58:14 -04001713
R David Murray4487dd02014-10-09 16:59:30 -04001714sndhdr
1715------
1716
Martin Panter97ce0fa2015-11-14 01:14:54 +00001717The :func:`~sndhdr.what` and :func:`~sndhdr.whathdr` functions now return
Yury Selivanova88cd642015-09-10 21:26:54 -04001718a :func:`~collections.namedtuple`. (Contributed by Claudiu Popa in
Yury Selivanovce917c7312015-09-10 17:35:38 -04001719:issue:`18615`.)
1720
R David Murray4487dd02014-10-09 16:59:30 -04001721
Yury Selivanovfe369a62015-09-13 08:29:19 -04001722socket
1723------
1724
1725Functions with timeouts now use a monotonic clock, instead of a system clock.
1726(Contributed by Victor Stinner in :issue:`22043`.)
1727
Martin Panterc04fb562016-02-10 05:44:01 +00001728A new :meth:`socket.sendfile() <socket.socket.sendfile>` method allows
1729sending a file over a socket by using the high-performance :func:`os.sendfile`
Martin Panter97ce0fa2015-11-14 01:14:54 +00001730function on UNIX, resulting in uploads being from 2 to 3 times faster than when
Yury Selivanova33cb352015-09-13 11:21:25 -04001731using plain :meth:`socket.send() <socket.socket.send>`.
Yury Selivanovfe369a62015-09-13 08:29:19 -04001732(Contributed by Giampaolo Rodola' in :issue:`17552`.)
1733
Yury Selivanova33cb352015-09-13 11:21:25 -04001734The :meth:`socket.sendall() <socket.socket.sendall>` method no longer resets the
Yury Selivanovfe369a62015-09-13 08:29:19 -04001735socket timeout every time bytes are received or sent. The socket timeout is
1736now the maximum total duration to send all data.
1737(Contributed by Victor Stinner in :issue:`23853`.)
1738
Yury Selivanova33cb352015-09-13 11:21:25 -04001739The *backlog* argument of the :meth:`socket.listen() <socket.socket.listen>`
Yury Selivanovfe369a62015-09-13 08:29:19 -04001740method is now optional. By default it is set to
Martin Panter97ce0fa2015-11-14 01:14:54 +00001741:data:`SOMAXCONN <socket.SOMAXCONN>` or to ``128``, whichever is less.
Yury Selivanovfe369a62015-09-13 08:29:19 -04001742(Contributed by Charles-François Natali in :issue:`21455`.)
1743
1744
Victor Stinner287452e2015-07-29 01:39:13 +02001745ssl
1746---
1747
Yury Selivanov95fd26b2015-09-12 17:50:58 -04001748.. _whatsnew-sslmemorybio:
1749
Yury Selivanovce917c7312015-09-10 17:35:38 -04001750Memory BIO Support
1751~~~~~~~~~~~~~~~~~~
Yury Selivanov7d6adab2015-08-05 19:01:51 -04001752
Yury Selivanovce917c7312015-09-10 17:35:38 -04001753(Contributed by Geert Jansen in :issue:`21965`.)
Victor Stinner287452e2015-07-29 01:39:13 +02001754
Yury Selivanovce917c7312015-09-10 17:35:38 -04001755The new :class:`~ssl.SSLObject` class has been added to provide SSL protocol
Yury Selivanova88cd642015-09-10 21:26:54 -04001756support for cases when the network I/O capabilities of :class:`~ssl.SSLSocket`
Martin Panter97ce0fa2015-11-14 01:14:54 +00001757are not necessary or are suboptimal. ``SSLObject`` represents
Yury Selivanova88cd642015-09-10 21:26:54 -04001758an SSL protocol instance, but does not implement any network I/O methods, and
Yury Selivanovce917c7312015-09-10 17:35:38 -04001759instead provides a memory buffer interface. The new :class:`~ssl.MemoryBIO`
1760class can be used to pass data between Python and an SSL protocol instance.
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001761
Yury Selivanovce917c7312015-09-10 17:35:38 -04001762The memory BIO SSL support is primarily intended to be used in frameworks
Yury Selivanova88cd642015-09-10 21:26:54 -04001763implementing asynchronous I/O for which :class:`~ssl.SSLSocket`'s readiness
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001764model ("select/poll") is inefficient.
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001765
Yury Selivanova33cb352015-09-13 11:21:25 -04001766A new :meth:`SSLContext.wrap_bio() <ssl.SSLContext.wrap_bio>` method can be used
1767to create a new ``SSLObject`` instance.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001768
1769
1770Application-Layer Protocol Negotiation Support
1771~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1772
1773(Contributed by Benjamin Peterson in :issue:`20188`.)
1774
Martin Panter97ce0fa2015-11-14 01:14:54 +00001775Where OpenSSL support is present, the :mod:`ssl` module now implements
1776the *Application-Layer Protocol Negotiation* TLS extension as described
Yury Selivanovce917c7312015-09-10 17:35:38 -04001777in :rfc:`7301`.
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001778
Yury Selivanova33cb352015-09-13 11:21:25 -04001779The new :meth:`SSLContext.set_alpn_protocols() <ssl.SSLContext.set_alpn_protocols>`
Yury Selivanova88cd642015-09-10 21:26:54 -04001780can be used to specify which protocols a socket should advertise during
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001781the TLS handshake.
1782
1783The new
Yury Selivanova33cb352015-09-13 11:21:25 -04001784:meth:`SSLSocket.selected_alpn_protocol() <ssl.SSLSocket.selected_alpn_protocol>`
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001785returns the protocol that was selected during the TLS handshake.
Martin Panter97ce0fa2015-11-14 01:14:54 +00001786The :data:`~ssl.HAS_ALPN` flag indicates whether ALPN support is present.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001787
1788
1789Other Changes
1790~~~~~~~~~~~~~
1791
Yury Selivanova33cb352015-09-13 11:21:25 -04001792There is a new :meth:`SSLSocket.version() <ssl.SSLSocket.version>` method to
1793query the actual protocol version in use.
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001794(Contributed by Antoine Pitrou in :issue:`20421`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001795
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001796The :class:`~ssl.SSLSocket` class now implements
Yury Selivanova33cb352015-09-13 11:21:25 -04001797a :meth:`SSLSocket.sendfile() <ssl.SSLSocket.sendfile>` method.
Yury Selivanov508a81e2015-09-10 23:37:06 -04001798(Contributed by Giampaolo Rodola' in :issue:`17552`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001799
Yury Selivanova33cb352015-09-13 11:21:25 -04001800The :meth:`SSLSocket.send() <ssl.SSLSocket.send>` method now raises either
Martin Panter97ce0fa2015-11-14 01:14:54 +00001801the :exc:`ssl.SSLWantReadError` or :exc:`ssl.SSLWantWriteError` exception on a
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001802non-blocking socket if the operation would block. Previously, it would return
1803``0``. (Contributed by Nikolaus Rath in :issue:`20951`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001804
1805The :func:`~ssl.cert_time_to_seconds` function now interprets the input time
1806as UTC and not as local time, per :rfc:`5280`. Additionally, the return
1807value is always an :class:`int`. (Contributed by Akira Li in :issue:`19940`.)
1808
Yury Selivanova33cb352015-09-13 11:21:25 -04001809New :meth:`SSLObject.shared_ciphers() <ssl.SSLObject.shared_ciphers>` and
1810:meth:`SSLSocket.shared_ciphers() <ssl.SSLSocket.shared_ciphers>` methods return
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001811the list of ciphers sent by the client during the handshake.
1812(Contributed by Benjamin Peterson in :issue:`23186`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001813
Yury Selivanova33cb352015-09-13 11:21:25 -04001814The :meth:`SSLSocket.do_handshake() <ssl.SSLSocket.do_handshake>`,
1815:meth:`SSLSocket.read() <ssl.SSLSocket.read>`,
1816:meth:`SSLSocket.shutdown() <ssl.SSLSocket.shutdown>`, and
Martin Panter97ce0fa2015-11-14 01:14:54 +00001817:meth:`SSLSocket.write() <ssl.SSLSocket.write>` methods of the :class:`~ssl.SSLSocket`
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001818class no longer reset the socket timeout every time bytes are received or sent.
1819The socket timeout is now the maximum total duration of the method.
1820(Contributed by Victor Stinner in :issue:`23853`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001821
1822The :func:`~ssl.match_hostname` function now supports matching of IP addresses.
1823(Contributed by Antoine Pitrou in :issue:`23239`.)
1824
Yury Selivanov336b37b2015-09-09 12:23:01 -04001825
Yury Selivanov508a81e2015-09-10 23:37:06 -04001826sqlite3
1827-------
1828
Martin Panter97ce0fa2015-11-14 01:14:54 +00001829The :class:`~sqlite3.Row` class now fully supports the sequence protocol,
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +03001830in particular :func:`reversed` iteration and slice indexing.
Yury Selivanov508a81e2015-09-10 23:37:06 -04001831(Contributed by Claudiu Popa in :issue:`10203`; by Lucas Sinclair,
1832Jessica McKellar, and Serhiy Storchaka in :issue:`13583`.)
1833
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001834
Yury Selivanov95fd26b2015-09-12 17:50:58 -04001835.. _whatsnew-subprocess:
1836
Gregory P. Smith6e730002015-04-14 16:14:25 -07001837subprocess
1838----------
1839
Yury Selivanova88cd642015-09-10 21:26:54 -04001840The new :func:`~subprocess.run` function has been added.
Martin Panter0e5eba22015-10-31 12:18:10 +00001841It runs the specified command and returns a
Yury Selivanova88cd642015-09-10 21:26:54 -04001842:class:`~subprocess.CompletedProcess` object, which describes a finished
1843process. The new API is more consistent and is the recommended approach
1844to invoking subprocesses in Python code that does not need to maintain
1845compatibility with earlier Python versions.
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001846(Contributed by Thomas Kluyver in :issue:`23342`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001847
Yury Selivanov23950372015-09-12 23:46:39 -04001848Examples::
1849
1850 >>> subprocess.run(["ls", "-l"]) # doesn't capture output
1851 CompletedProcess(args=['ls', '-l'], returncode=0)
1852
1853 >>> subprocess.run("exit 1", shell=True, check=True)
1854 Traceback (most recent call last):
1855 ...
1856 subprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1
1857
1858 >>> subprocess.run(["ls", "-l", "/dev/null"], stdout=subprocess.PIPE)
1859 CompletedProcess(args=['ls', '-l', '/dev/null'], returncode=0,
1860 stdout=b'crw-rw-rw- 1 root root 1, 3 Jan 23 16:23 /dev/null\n')
1861
Gregory P. Smith6e730002015-04-14 16:14:25 -07001862
Yury Selivanov4640b302015-05-31 17:21:38 -04001863sys
1864---
1865
Yury Selivanovce917c7312015-09-10 17:35:38 -04001866A new :func:`~sys.set_coroutine_wrapper` function allows setting a global
Yury Selivanova88cd642015-09-10 21:26:54 -04001867hook that will be called whenever a :term:`coroutine object <coroutine>`
1868is created by an :keyword:`async def` function. A corresponding
1869:func:`~sys.get_coroutine_wrapper` can be used to obtain a currently set
Yury Selivanov95fd26b2015-09-12 17:50:58 -04001870wrapper. Both functions are :term:`provisional <provisional api>`,
Yury Selivanov46a8b402015-09-12 15:52:04 -04001871and are intended for debugging purposes only. (Contributed by Yury Selivanov
1872in :issue:`24017`.)
Yury Selivanov4640b302015-05-31 17:21:38 -04001873
Yury Selivanova88cd642015-09-10 21:26:54 -04001874A new :func:`~sys.is_finalizing` function can be used to check if the Python
Yury Selivanovce917c7312015-09-10 17:35:38 -04001875interpreter is :term:`shutting down <interpreter shutdown>`.
1876(Contributed by Antoine Pitrou in :issue:`22696`.)
1877
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001878
Eric V. Smith7a803892015-04-15 10:27:58 -04001879sysconfig
1880---------
1881
Yury Selivanovce917c7312015-09-10 17:35:38 -04001882The name of the user scripts directory on Windows now includes the first
Martin Panter97ce0fa2015-11-14 01:14:54 +00001883two components of the Python version. (Contributed by Paul Moore
Yury Selivanovce917c7312015-09-10 17:35:38 -04001884in :issue:`23437`.)
1885
Eric V. Smith7a803892015-04-15 10:27:58 -04001886
1887tarfile
1888-------
1889
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001890The *mode* argument of the :func:`~tarfile.open` function now accepts ``"x"``
1891to request exclusive creation. (Contributed by Berker Peksag in :issue:`21717`.)
Eric V. Smith7a803892015-04-15 10:27:58 -04001892
Martin Panter97ce0fa2015-11-14 01:14:54 +00001893The :meth:`TarFile.extractall() <tarfile.TarFile.extractall>` and
Yury Selivanova33cb352015-09-13 11:21:25 -04001894:meth:`TarFile.extract() <tarfile.TarFile.extract>` methods now take a keyword
Martin Panterefbf20f2016-11-13 23:25:06 +00001895argument *numeric_owner*. If set to ``True``, the extracted files and
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001896directories will be owned by the numeric ``uid`` and ``gid`` from the tarfile.
1897If set to ``False`` (the default, and the behavior in versions prior to 3.5),
1898they will be owned by the named user and group in the tarfile.
1899(Contributed by Michael Vogt and Eric Smith in :issue:`23193`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001900
Yury Selivanova33cb352015-09-13 11:21:25 -04001901The :meth:`TarFile.list() <tarfile.TarFile.list>` now accepts an optional
Yury Selivanov46a8b402015-09-12 15:52:04 -04001902*members* keyword argument that can be set to a subset of the list returned
Yury Selivanova33cb352015-09-13 11:21:25 -04001903by :meth:`TarFile.getmembers() <tarfile.TarFile.getmembers>`.
Yury Selivanov46a8b402015-09-12 15:52:04 -04001904(Contributed by Serhiy Storchaka in :issue:`21549`.)
1905
Eric V. Smith7a803892015-04-15 10:27:58 -04001906
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001907threading
1908---------
1909
Martin Panter97ce0fa2015-11-14 01:14:54 +00001910Both the :meth:`Lock.acquire() <threading.Lock.acquire>` and
Yury Selivanova33cb352015-09-13 11:21:25 -04001911:meth:`RLock.acquire() <threading.RLock.acquire>` methods
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001912now use a monotonic clock for timeout management.
1913(Contributed by Victor Stinner in :issue:`22043`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001914
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001915
Victor Stinnerae586492014-09-02 23:18:25 +02001916time
1917----
1918
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001919The :func:`~time.monotonic` function is now always available.
1920(Contributed by Victor Stinner in :issue:`22043`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001921
Victor Stinnerae586492014-09-02 23:18:25 +02001922
Yury Selivanov336b37b2015-09-09 12:23:01 -04001923timeit
1924------
1925
Serhiy Storchaka35a361f2015-09-13 12:07:54 +03001926A new command line option ``-u`` or :samp:`--unit={U}` can be used to specify the time
Yury Selivanova88cd642015-09-10 21:26:54 -04001927unit for the timer output. Supported options are ``usec``, ``msec``,
1928or ``sec``. (Contributed by Julian Gindi in :issue:`18983`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001929
Yury Selivanov508a81e2015-09-10 23:37:06 -04001930The :func:`~timeit.timeit` function has a new *globals* parameter for
1931specifying the namespace in which the code will be running.
1932(Contributed by Ben Roberts in :issue:`2527`.)
1933
Yury Selivanov336b37b2015-09-09 12:23:01 -04001934
Zachary Ware7dc9dea2015-05-22 11:36:53 -05001935tkinter
1936-------
1937
Yury Selivanovce917c7312015-09-10 17:35:38 -04001938The :mod:`tkinter._fix` module used for setting up the Tcl/Tk environment
1939on Windows has been replaced by a private function in the :mod:`_tkinter`
1940module which makes no permanent changes to environment variables.
1941(Contributed by Zachary Ware in :issue:`20035`.)
1942
Zachary Ware7dc9dea2015-05-22 11:36:53 -05001943
Yury Selivanov95fd26b2015-09-12 17:50:58 -04001944.. _whatsnew-traceback:
1945
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001946traceback
1947---------
1948
Yury Selivanovce917c7312015-09-10 17:35:38 -04001949New :func:`~traceback.walk_stack` and :func:`~traceback.walk_tb`
1950functions to conveniently traverse frame and traceback objects.
1951(Contributed by Robert Collins in :issue:`17911`.)
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001952
Yury Selivanovce917c7312015-09-10 17:35:38 -04001953New lightweight classes: :class:`~traceback.TracebackException`,
Serhiy Storchaka35a361f2015-09-13 12:07:54 +03001954:class:`~traceback.StackSummary`, and :class:`~traceback.FrameSummary`.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001955(Contributed by Robert Collins in :issue:`17911`.)
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001956
Martin Panter97ce0fa2015-11-14 01:14:54 +00001957Both the :func:`~traceback.print_tb` and :func:`~traceback.print_stack` functions
Yury Selivanov5c3111e2015-09-10 18:04:35 -04001958now support negative values for the *limit* argument.
Yury Selivanovce917c7312015-09-10 17:35:38 -04001959(Contributed by Dmitry Kazakov in :issue:`22619`.)
Yury Selivanov336b37b2015-09-09 12:23:01 -04001960
1961
Yury Selivanovf3e40fa2015-05-21 11:50:30 -04001962types
1963-----
1964
Yury Selivanov1c73e692015-09-10 18:59:42 -04001965A new :func:`~types.coroutine` function to transform
1966:term:`generator <generator iterator>` and
1967:class:`generator-like <collections.abc.Generator>` objects into
1968:term:`awaitables <awaitable>`.
1969(Contributed by Yury Selivanov in :issue:`24017`.)
Yury Selivanovf3e40fa2015-05-21 11:50:30 -04001970
Martin Panter97ce0fa2015-11-14 01:14:54 +00001971A new type called :class:`~types.CoroutineType`, which is used for
1972:term:`coroutine` objects created by :keyword:`async def` functions.
Yury Selivanov1c73e692015-09-10 18:59:42 -04001973(Contributed by Yury Selivanov in :issue:`24400`.)
Yury Selivanovce917c7312015-09-10 17:35:38 -04001974
Yury Selivanov5376ba92015-06-22 12:19:30 -04001975
Benjamin Peterson48013832015-06-27 15:45:56 -05001976unicodedata
1977-----------
1978
Yury Selivanovce917c7312015-09-10 17:35:38 -04001979The :mod:`unicodedata` module now uses data from `Unicode 8.0.0
1980<http://unicode.org/versions/Unicode8.0.0/>`_.
1981
Benjamin Peterson48013832015-06-27 15:45:56 -05001982
Yury Selivanov336b37b2015-09-09 12:23:01 -04001983unittest
1984--------
1985
Yury Selivanova33cb352015-09-13 11:21:25 -04001986The :meth:`TestLoader.loadTestsFromModule() <unittest.TestLoader.loadTestsFromModule>`
Yury Selivanov46a8b402015-09-12 15:52:04 -04001987method now accepts a keyword-only argument *pattern* which is passed to
1988``load_tests`` as the third argument. Found packages are now checked for
1989``load_tests`` regardless of whether their path matches *pattern*, because it
1990is impossible for a package name to match the default pattern.
1991(Contributed by Robert Collins and Barry A. Warsaw in :issue:`16662`.)
1992
Martin Panter97ce0fa2015-11-14 01:14:54 +00001993Unittest discovery errors now are exposed in the
Yury Selivanov46a8b402015-09-12 15:52:04 -04001994:data:`TestLoader.errors <unittest.TestLoader.errors>` attribute of the
1995:class:`~unittest.TestLoader` instance.
1996(Contributed by Robert Collins in :issue:`19746`.)
1997
Yury Selivanovdddfffe2015-09-11 01:23:10 -04001998A new command line option ``--locals`` to show local variables in
Yury Selivanovce917c7312015-09-10 17:35:38 -04001999tracebacks. (Contributed by Robert Collins in :issue:`22936`.)
2000
Benjamin Peterson48013832015-06-27 15:45:56 -05002001
Yury Selivanov508a81e2015-09-10 23:37:06 -04002002unittest.mock
2003-------------
2004
Berker Peksag878bc872015-09-15 20:06:28 +03002005The :class:`~unittest.mock.Mock` class has the following improvements:
Yury Selivanov508a81e2015-09-10 23:37:06 -04002006
Martin Panter97ce0fa2015-11-14 01:14:54 +00002007* The class constructor has a new *unsafe* parameter, which causes mock
Yury Selivanov508a81e2015-09-10 23:37:06 -04002008 objects to raise :exc:`AttributeError` on attribute names starting
2009 with ``"assert"``.
2010 (Contributed by Kushal Das in :issue:`21238`.)
2011
Yury Selivanova33cb352015-09-13 11:21:25 -04002012* A new :meth:`Mock.assert_not_called() <unittest.mock.Mock.assert_not_called>`
Yury Selivanov508a81e2015-09-10 23:37:06 -04002013 method to check if the mock object was called.
2014 (Contributed by Kushal Das in :issue:`21262`.)
2015
2016The :class:`~unittest.mock.MagicMock` class now supports :meth:`__truediv__`,
2017:meth:`__divmod__` and :meth:`__matmul__` operators.
2018(Contributed by Johannes Baiter in :issue:`20968`, and Håkan Lövdahl
2019in :issue:`23581` and :issue:`23568`.)
2020
Yury Selivanov46a8b402015-09-12 15:52:04 -04002021It is no longer necessary to explicitly pass ``create=True`` to the
2022:func:`~unittest.mock.patch` function when patching builtin names.
2023(Contributed by Kushal Das in :issue:`17660`.)
2024
Yury Selivanov508a81e2015-09-10 23:37:06 -04002025
Yury Selivanovfe369a62015-09-13 08:29:19 -04002026urllib
2027------
2028
2029A new
2030:class:`request.HTTPPasswordMgrWithPriorAuth <urllib.request.HTTPPasswordMgrWithPriorAuth>`
2031class allows HTTP Basic Authentication credentials to be managed so as to
2032eliminate unnecessary ``401`` response handling, or to unconditionally send
2033credentials on the first request in order to communicate with servers that
2034return a ``404`` response instead of a ``401`` if the ``Authorization`` header
2035is not sent. (Contributed by Matej Cepl in :issue:`19494` and Akshit Khurana in
2036:issue:`7159`.)
2037
2038A new *quote_via* argument for the
Yury Selivanova33cb352015-09-13 11:21:25 -04002039:func:`parse.urlencode() <urllib.parse.urlencode>`
Yury Selivanovfe369a62015-09-13 08:29:19 -04002040function provides a way to control the encoding of query parts if needed.
2041(Contributed by Samwyse and Arnon Yaari in :issue:`13866`.)
2042
Yury Selivanova33cb352015-09-13 11:21:25 -04002043The :func:`request.urlopen() <urllib.request.urlopen>` function accepts an
Yury Selivanovfe369a62015-09-13 08:29:19 -04002044:class:`ssl.SSLContext` object as a *context* argument, which will be used for
2045the HTTPS connection. (Contributed by Alex Gaynor in :issue:`22366`.)
2046
Yury Selivanova33cb352015-09-13 11:21:25 -04002047The :func:`parse.urljoin() <urllib.parse.urljoin>` was updated to use the
Yury Selivanovfe369a62015-09-13 08:29:19 -04002048:rfc:`3986` semantics for the resolution of relative URLs, rather than
2049:rfc:`1808` and :rfc:`2396`.
2050(Contributed by Demian Brecht and Senthil Kumaran in :issue:`22118`.)
2051
2052
Berker Peksag3e887222014-07-02 08:37:22 +03002053wsgiref
2054-------
2055
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002056The *headers* argument of the :class:`headers.Headers <wsgiref.headers.Headers>`
2057class constructor is now optional.
Yury Selivanovce917c7312015-09-10 17:35:38 -04002058(Contributed by Pablo Torres Navarrete and SilentGhost in :issue:`5800`.)
2059
Berker Peksag3e887222014-07-02 08:37:22 +03002060
Antoine Pitroub9d9ce72014-05-15 22:47:33 +02002061xmlrpc
2062------
2063
Serhiy Storchaka35a361f2015-09-13 12:07:54 +03002064The :class:`client.ServerProxy <xmlrpc.client.ServerProxy>` class now supports
Martin Panter97ce0fa2015-11-14 01:14:54 +00002065the :term:`context manager` protocol.
Yury Selivanovce917c7312015-09-10 17:35:38 -04002066(Contributed by Claudiu Popa in :issue:`20627`.)
Brett Cannon6eaac132014-05-09 12:28:22 -04002067
Martin Panter97ce0fa2015-11-14 01:14:54 +00002068The :class:`client.ServerProxy <xmlrpc.client.ServerProxy>` constructor now accepts
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002069an optional :class:`ssl.SSLContext` instance.
Yury Selivanovce917c7312015-09-10 17:35:38 -04002070(Contributed by Alex Gaynor in :issue:`22960`.)
2071
Yury Selivanov100fc3f2015-09-08 22:40:30 -04002072
Serhiy Storchaka61de0872015-04-02 21:00:13 +03002073xml.sax
2074-------
2075
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002076SAX parsers now support a character stream of the
2077:class:`xmlreader.InputSource <xml.sax.xmlreader.InputSource>` object.
Yury Selivanovce917c7312015-09-10 17:35:38 -04002078(Contributed by Serhiy Storchaka in :issue:`2175`.)
2079
Yury Selivanov46a8b402015-09-12 15:52:04 -04002080:func:`~xml.sax.parseString` now accepts a :class:`str` instance.
2081(Contributed by Serhiy Storchaka in :issue:`10590`.)
2082
Serhiy Storchaka61de0872015-04-02 21:00:13 +03002083
Serhiy Storchaka77d89972015-03-23 01:09:35 +02002084zipfile
2085-------
2086
Yury Selivanovce917c7312015-09-10 17:35:38 -04002087ZIP output can now be written to unseekable streams.
2088(Contributed by Serhiy Storchaka in :issue:`23252`.)
Serhiy Storchaka77d89972015-03-23 01:09:35 +02002089
Yury Selivanova33cb352015-09-13 11:21:25 -04002090The *mode* argument of :meth:`ZipFile.open() <zipfile.ZipFile.open>` method now
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002091accepts ``"x"`` to request exclusive creation.
Yury Selivanovce917c7312015-09-10 17:35:38 -04002092(Contributed by Serhiy Storchaka in :issue:`21717`.)
Serhiy Storchaka764fc9b2015-03-25 10:09:41 +02002093
Victor Stinner01adf062014-03-18 00:53:32 +01002094
Yury Selivanov336b37b2015-09-09 12:23:01 -04002095Other module-level changes
2096==========================
2097
Martin Panter97ce0fa2015-11-14 01:14:54 +00002098Many functions in the :mod:`mmap`, :mod:`ossaudiodev`, :mod:`socket`,
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +03002099:mod:`ssl`, and :mod:`codecs` modules now accept writable
2100:term:`bytes-like objects <bytes-like object>`.
Yury Selivanovce917c7312015-09-10 17:35:38 -04002101(Contributed by Serhiy Storchaka in :issue:`23001`.)
Yury Selivanov336b37b2015-09-09 12:23:01 -04002102
2103
Victor Stinner01adf062014-03-18 00:53:32 +01002104Optimizations
2105=============
2106
Yury Selivanova88cd642015-09-10 21:26:54 -04002107The :func:`os.walk` function has been sped up by 3 to 5 times on POSIX systems,
2108and by 7 to 20 times on Windows. This was done using the new :func:`os.scandir`
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002109function, which exposes file information from the underlying ``readdir`` or
Yury Selivanova88cd642015-09-10 21:26:54 -04002110``FindFirstFile``/``FindNextFile`` system calls. (Contributed by
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002111Ben Hoyt with help from Victor Stinner in :issue:`23605`.)
Victor Stinner01adf062014-03-18 00:53:32 +01002112
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002113Construction of ``bytes(int)`` (filled by zero bytes) is faster and uses less
2114memory for large objects. ``calloc()`` is used instead of ``malloc()`` to
2115allocate memory for these objects.
Yury Selivanova88cd642015-09-10 21:26:54 -04002116(Contributed by Victor Stinner in :issue:`21233`.)
Victor Stinner37f20342015-03-10 13:29:41 +01002117
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002118Some operations on :mod:`ipaddress` :class:`~ipaddress.IPv4Network` and
2119:class:`~ipaddress.IPv6Network` have been massively sped up, such as
2120:meth:`~ipaddress.IPv4Network.subnets`, :meth:`~ipaddress.IPv4Network.supernet`,
2121:func:`~ipaddress.summarize_address_range`, :func:`~ipaddress.collapse_addresses`.
2122The speed up can range from 3 to 15 times.
Yury Selivanova88cd642015-09-10 21:26:54 -04002123(Contributed by Antoine Pitrou, Michel Albert, and Markus in
2124:issue:`21486`, :issue:`21487`, :issue:`20826`, :issue:`23266`.)
Victor Stinner01adf062014-03-18 00:53:32 +01002125
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002126Pickling of :mod:`ipaddress` objects was optimized to produce significantly
2127smaller output. (Contributed by Serhiy Storchaka in :issue:`23133`.)
Yury Selivanov100fc3f2015-09-08 22:40:30 -04002128
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002129Many operations on :class:`io.BytesIO` are now 50% to 100% faster.
2130(Contributed by Serhiy Storchaka in :issue:`15381` and David Wilson in
2131:issue:`22003`.)
Antoine Pitrou0dfce562014-05-15 22:55:40 +02002132
Serhiy Storchakac7b1a0b2016-11-26 13:43:28 +02002133The :func:`marshal.dumps` function is now faster: 65--85% with versions 3
2134and 4, 20--25% with versions 0 to 2 on typical data, and up to 5 times in
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002135best cases.
2136(Contributed by Serhiy Storchaka in :issue:`20416` and :issue:`23344`.)
Serhiy Storchaka87d0b452015-02-03 11:30:10 +02002137
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002138The UTF-32 encoder is now 3 to 7 times faster.
2139(Contributed by Serhiy Storchaka in :issue:`15027`.)
Serhiy Storchakace921c622015-02-11 15:53:31 +02002140
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002141Regular expressions are now parsed up to 10% faster.
2142(Contributed by Serhiy Storchaka in :issue:`19380`.)
Serhiy Storchaka0d4df752015-05-12 23:12:45 +03002143
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002144The :func:`json.dumps` function was optimized to run with
2145``ensure_ascii=False`` as fast as with ``ensure_ascii=True``.
2146(Contributed by Naoki Inada in :issue:`23206`.)
Yury Selivanov100fc3f2015-09-08 22:40:30 -04002147
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002148The :c:func:`PyObject_IsInstance` and :c:func:`PyObject_IsSubclass`
2149functions have been sped up in the common case that the second argument
2150has :class:`type` as its metaclass.
2151(Contributed Georg Brandl by in :issue:`22540`.)
Yury Selivanov100fc3f2015-09-08 22:40:30 -04002152
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002153Method caching was slightly improved, yielding up to 5% performance
2154improvement in some benchmarks.
2155(Contributed by Antoine Pitrou in :issue:`22847`.)
Yury Selivanov336b37b2015-09-09 12:23:01 -04002156
Martin Panter97ce0fa2015-11-14 01:14:54 +00002157Objects from the :mod:`random` module now use 50% less memory on 64-bit
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002158builds. (Contributed by Serhiy Storchaka in :issue:`23488`.)
Yury Selivanov336b37b2015-09-09 12:23:01 -04002159
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002160The :func:`property` getter calls are up to 25% faster.
2161(Contributed by Joe Jevnik in :issue:`23910`.)
Yury Selivanov336b37b2015-09-09 12:23:01 -04002162
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002163Instantiation of :class:`fractions.Fraction` is now up to 30% faster.
2164(Contributed by Stefan Behnel in :issue:`22464`.)
Yury Selivanov88d073d2015-09-09 22:46:40 -04002165
Yury Selivanov508a81e2015-09-10 23:37:06 -04002166String methods :meth:`~str.find`, :meth:`~str.rfind`, :meth:`~str.split`,
Martin Panter97ce0fa2015-11-14 01:14:54 +00002167:meth:`~str.partition` and the :keyword:`in` string operator are now significantly
Yury Selivanov508a81e2015-09-10 23:37:06 -04002168faster for searching 1-character substrings.
2169(Contributed by Serhiy Storchaka in :issue:`23573`.)
2170
Victor Stinner01adf062014-03-18 00:53:32 +01002171
2172Build and C API Changes
2173=======================
2174
Yury Selivanovc9739902015-09-10 18:26:44 -04002175New ``calloc`` functions were added:
Victor Stinnerdb067af2014-05-02 22:31:14 +02002176
Yury Selivanova7672ba2015-09-13 01:40:36 -04002177* :c:func:`PyMem_RawCalloc`,
2178* :c:func:`PyMem_Calloc`,
Serhiy Storchaka9fab79b2016-09-11 11:03:14 +03002179* :c:func:`PyObject_Calloc`.
Yury Selivanov508a81e2015-09-10 23:37:06 -04002180
2181(Contributed by Victor Stinner in :issue:`21233`.)
2182
2183New encoding/decoding helper functions:
2184
Yury Selivanova7672ba2015-09-13 01:40:36 -04002185* :c:func:`Py_DecodeLocale` (replaced ``_Py_char2wchar()``),
2186* :c:func:`Py_EncodeLocale` (replaced ``_Py_wchar2char()``).
Yury Selivanov508a81e2015-09-10 23:37:06 -04002187
2188(Contributed by Victor Stinner in :issue:`18395`.)
2189
Yury Selivanovdddfffe2015-09-11 01:23:10 -04002190A new :c:func:`PyCodec_NameReplaceErrors` function to replace the unicode
Yury Selivanov4dde5872015-09-11 00:48:21 -04002191encode error with ``\N{...}`` escapes.
2192(Contributed by Serhiy Storchaka in :issue:`19676`.)
2193
Yury Selivanovdddfffe2015-09-11 01:23:10 -04002194A new :c:func:`PyErr_FormatV` function similar to :c:func:`PyErr_Format`,
Yury Selivanov4dde5872015-09-11 00:48:21 -04002195but accepts a ``va_list`` argument.
2196(Contributed by Antoine Pitrou in :issue:`18711`.)
2197
Yury Selivanovdddfffe2015-09-11 01:23:10 -04002198A new :c:data:`PyExc_RecursionError` exception.
Yury Selivanov4dde5872015-09-11 00:48:21 -04002199(Contributed by Georg Brandl in :issue:`19235`.)
2200
2201New :c:func:`PyModule_FromDefAndSpec`, :c:func:`PyModule_FromDefAndSpec2`,
Yury Selivanova33cb352015-09-13 11:21:25 -04002202and :c:func:`PyModule_ExecDef` functions introduced by :pep:`489` --
2203multi-phase extension module initialization.
Yury Selivanov4dde5872015-09-11 00:48:21 -04002204(Contributed by Petr Viktorin in :issue:`24268`.)
2205
2206New :c:func:`PyNumber_MatrixMultiply` and
2207:c:func:`PyNumber_InPlaceMatrixMultiply` functions to perform matrix
2208multiplication.
2209(Contributed by Benjamin Peterson in :issue:`21176`. See also :pep:`465`
2210for details.)
2211
Martin Panter97ce0fa2015-11-14 01:14:54 +00002212The :c:member:`PyTypeObject.tp_finalize` slot is now part of the stable ABI.
Victor Stinner01adf062014-03-18 00:53:32 +01002213
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002214Windows builds now require Microsoft Visual C++ 14.0, which
Georg Brandl5d941342016-02-26 19:37:12 +01002215is available as part of `Visual Studio 2015 <https://www.visualstudio.com/>`_.
Victor Stinner01adf062014-03-18 00:53:32 +01002216
Martin Panter97ce0fa2015-11-14 01:14:54 +00002217Extension modules now include a platform information tag in their filename on
Yury Selivanovc9739902015-09-10 18:26:44 -04002218some platforms (the tag is optional, and CPython will import extensions without
Martin Panter97ce0fa2015-11-14 01:14:54 +00002219it, although if the tag is present and mismatched, the extension won't be
Yury Selivanovc9739902015-09-10 18:26:44 -04002220loaded):
2221
2222* On Linux, extension module filenames end with
2223 ``.cpython-<major><minor>m-<architecture>-<os>.pyd``:
2224
2225 * ``<major>`` is the major number of the Python version;
2226 for Python 3.5 this is ``3``.
2227
2228 * ``<minor>`` is the minor number of the Python version;
2229 for Python 3.5 this is ``5``.
2230
2231 * ``<architecture>`` is the hardware architecture the extension module
2232 was built to run on. It's most commonly either ``i386`` for 32-bit Intel
2233 platforms or ``x86_64`` for 64-bit Intel (and AMD) platforms.
2234
2235 * ``<os>`` is always ``linux-gnu``, except for extensions built to
2236 talk to the 32-bit ABI on 64-bit platforms, in which case it is
2237 ``linux-gnu32`` (and ``<architecture>`` will be ``x86_64``).
2238
2239* On Windows, extension module filenames end with
Yury Selivanova88cd642015-09-10 21:26:54 -04002240 ``<debug>.cp<major><minor>-<platform>.pyd``:
Yury Selivanovc9739902015-09-10 18:26:44 -04002241
2242 * ``<major>`` is the major number of the Python version;
2243 for Python 3.5 this is ``3``.
2244
2245 * ``<minor>`` is the minor number of the Python version;
2246 for Python 3.5 this is ``5``.
2247
2248 * ``<platform>`` is the platform the extension module was built for,
2249 either ``win32`` for Win32, ``win_amd64`` for Win64, ``win_ia64`` for
2250 Windows Itanium 64, and ``win_arm`` for Windows on ARM.
2251
2252 * If built in debug mode, ``<debug>`` will be ``_d``,
2253 otherwise it will be blank.
2254
2255* On OS X platforms, extension module filenames now end with ``-darwin.so``.
2256
2257* On all other platforms, extension module filenames are the same as they were
2258 with Python 3.4.
2259
Yury Selivanovce917c7312015-09-10 17:35:38 -04002260
Victor Stinner01adf062014-03-18 00:53:32 +01002261Deprecated
2262==========
2263
Yury Selivanov8fa6d4f2015-05-28 17:09:14 -04002264New Keywords
2265------------
2266
Yury Selivanov13b74ae2015-08-03 14:55:58 -04002267``async`` and ``await`` are not recommended to be used as variable, class,
2268function or module names. Introduced by :pep:`492` in Python 3.5, they will
2269become proper keywords in Python 3.7.
Yury Selivanov8fa6d4f2015-05-28 17:09:14 -04002270
2271
Yury Selivanov95fd26b2015-09-12 17:50:58 -04002272Deprecated Python Behavior
2273--------------------------
2274
Martin Panter97ce0fa2015-11-14 01:14:54 +00002275Raising the :exc:`StopIteration` exception inside a generator will now generate a silent
Yury Selivanov95fd26b2015-09-12 17:50:58 -04002276:exc:`PendingDeprecationWarning`, which will become a non-silent deprecation
2277warning in Python 3.6 and will trigger a :exc:`RuntimeError` in Python 3.7.
2278See :ref:`PEP 479: Change StopIteration handling inside generators <whatsnew-pep-479>`
2279for details.
2280
2281
Victor Stinner01adf062014-03-18 00:53:32 +01002282Unsupported Operating Systems
2283-----------------------------
2284
Yury Selivanova88cd642015-09-10 21:26:54 -04002285Windows XP is no longer supported by Microsoft, thus, per :PEP:`11`, CPython
22863.5 is no longer officially supported on this OS.
Victor Stinner01adf062014-03-18 00:53:32 +01002287
2288
2289Deprecated Python modules, functions and methods
2290------------------------------------------------
2291
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002292The :mod:`formatter` module has now graduated to full deprecation and is still
2293slated for removal in Python 3.6.
Victor Stinner01adf062014-03-18 00:53:32 +01002294
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002295The :func:`asyncio.async` function is deprecated in favor of
2296:func:`~asyncio.ensure_future`.
Yury Selivanov336b37b2015-09-09 12:23:01 -04002297
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002298The :mod:`smtpd` module has in the past always decoded the DATA portion of
2299email messages using the ``utf-8`` codec. This can now be controlled by the
2300new *decode_data* keyword to :class:`~smtpd.SMTPServer`. The default value is
2301``True``, but this default is deprecated. Specify the *decode_data* keyword
2302with an appropriate value to avoid the deprecation warning.
R David Murray554bcbf2014-06-11 11:18:08 -04002303
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002304Directly assigning values to the :attr:`~http.cookies.Morsel.key`,
2305:attr:`~http.cookies.Morsel.value` and
Yury Selivanova33cb352015-09-13 11:21:25 -04002306:attr:`~http.cookies.Morsel.coded_value` of :class:`http.cookies.Morsel`
2307objects is deprecated. Use the :meth:`~http.cookies.Morsel.set` method
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002308instead. In addition, the undocumented *LegalChars* parameter of
Yury Selivanova33cb352015-09-13 11:21:25 -04002309:meth:`~http.cookies.Morsel.set` is deprecated, and is now ignored.
Serhiy Storchaka9c1a9b22015-03-18 10:59:57 +02002310
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002311Passing a format string as keyword argument *format_string* to the
2312:meth:`~string.Formatter.format` method of the :class:`string.Formatter`
2313class has been deprecated.
Yury Selivanov46a8b402015-09-12 15:52:04 -04002314(Contributed by Serhiy Storchaka in :issue:`23671`.)
Serhiy Storchakab876df42015-03-24 22:30:46 +02002315
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002316The :func:`platform.dist` and :func:`platform.linux_distribution` functions
Berker Peksag8d8221f2016-04-24 03:32:24 +03002317are now deprecated. Linux distributions use too many different ways of
2318describing themselves, so the functionality is left to a package.
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002319(Contributed by Vajrasky Kok and Berker Peksag in :issue:`1322`.)
Victor Stinner01adf062014-03-18 00:53:32 +01002320
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002321The previously undocumented ``from_function`` and ``from_builtin`` methods of
Yury Selivanova33cb352015-09-13 11:21:25 -04002322:class:`inspect.Signature` are deprecated. Use the new
2323:meth:`Signature.from_callable() <inspect.Signature.from_callable>`
2324method instead. (Contributed by Yury Selivanov in :issue:`24248`.)
Yury Selivanov57c74fc2015-05-20 23:07:02 -04002325
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002326The :func:`inspect.getargspec` function is deprecated and scheduled to be
2327removed in Python 3.6. (See :issue:`20438` for details.)
Yury Selivanov945fff42015-05-22 16:28:05 -04002328
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002329The :mod:`inspect` :func:`~inspect.getfullargspec`,
Matthias Bussonnier0899b982017-02-21 21:45:51 -08002330:func:`~inspect.getcallargs`, and :func:`~inspect.formatargspec` functions are
2331deprecated in favor of the :func:`inspect.signature` API. (Contributed by Yury
2332Selivanov in :issue:`20438`.)
2333
2334:func:`~inspect.getargvalues` and :func:`~inspect.formatargvalues` functions
2335were inadvertently marked as deprecated with the release of Python 3.5.0.
Yury Selivanov945fff42015-05-22 16:28:05 -04002336
Serhiy Storchaka35a361f2015-09-13 12:07:54 +03002337Use of :const:`re.LOCALE` flag with str patterns or :const:`re.ASCII` is now
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002338deprecated. (Contributed by Serhiy Storchaka in :issue:`22407`.)
Yury Selivanov100fc3f2015-09-08 22:40:30 -04002339
Yury Selivanov46a8b402015-09-12 15:52:04 -04002340Use of unrecognized special sequences consisting of ``'\'`` and an ASCII letter
2341in regular expression patterns and replacement patterns now raises a
2342deprecation warning and will be forbidden in Python 3.6.
2343(Contributed by Serhiy Storchaka in :issue:`23622`.)
2344
2345The undocumented and unofficial *use_load_tests* default argument of the
2346:meth:`unittest.TestLoader.loadTestsFromModule` method now is
2347deprecated and ignored.
2348(Contributed by Robert Collins and Barry A. Warsaw in :issue:`16662`.)
2349
Victor Stinner01adf062014-03-18 00:53:32 +01002350
R David Murraydf75fee2014-10-03 13:02:47 -04002351Removed
2352=======
2353
Berker Peksag8f791d32014-11-01 10:45:57 +02002354API and Feature Removals
2355------------------------
2356
2357The following obsolete and previously deprecated APIs and features have been
2358removed:
2359
R David Murraydf75fee2014-10-03 13:02:47 -04002360* The ``__version__`` attribute has been dropped from the email package. The
2361 email code hasn't been shipped separately from the stdlib for a long time,
2362 and the ``__version__`` string was not updated in the last few releases.
2363
Berker Peksag8f791d32014-11-01 10:45:57 +02002364* The internal ``Netrc`` class in the :mod:`ftplib` module was deprecated in
Serhiy Storchakac1ded292014-11-02 19:22:02 +02002365 3.4, and has now been removed.
2366 (Contributed by Matt Chaput in :issue:`6623`.)
R David Murraydf75fee2014-10-03 13:02:47 -04002367
Brett Cannonf299abd2015-04-13 14:21:02 -04002368* The concept of ``.pyo`` files has been removed.
2369
Yury Selivanov46a8b402015-09-12 15:52:04 -04002370* The JoinableQueue class in the provisional :mod:`asyncio` module was
2371 deprecated in 3.4.4 and is now removed.
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +03002372 (Contributed by A. Jesse Jiryu Davis in :issue:`23464`.)
R David Murraye81a7732015-04-12 18:47:56 -04002373
2374
Victor Stinner01adf062014-03-18 00:53:32 +01002375Porting to Python 3.5
2376=====================
2377
2378This section lists previously described changes and other bugfixes
2379that may require changes to your code.
2380
Yury Selivanov95fd26b2015-09-12 17:50:58 -04002381
2382Changes in Python behavior
2383--------------------------
2384
2385* Due to an oversight, earlier Python versions erroneously accepted the
2386 following syntax::
2387
2388 f(1 for x in [1], *args)
2389 f(1 for x in [1], **kwargs)
2390
2391 Python 3.5 now correctly raises a :exc:`SyntaxError`, as generator
2392 expressions must be put in parentheses if not a sole argument to a function.
2393
2394
Victor Stinnerdb067af2014-05-02 22:31:14 +02002395Changes in the Python API
2396-------------------------
2397
Victor Stinner6752d652015-07-29 01:11:10 +02002398* :pep:`475`: System calls are now retried when interrupted by a signal instead
2399 of raising :exc:`InterruptedError` if the Python signal handler does not
2400 raise an exception.
Victor Stinnera766ddf2015-03-26 23:50:57 +01002401
Benjamin Petersonee6bdc02014-03-20 18:00:35 -05002402* Before Python 3.5, a :class:`datetime.time` object was considered to be false
2403 if it represented midnight in UTC. This behavior was considered obscure and
2404 error-prone and has been removed in Python 3.5. See :issue:`13936` for full
2405 details.
Antoine Pitrou92c4d452014-04-29 10:05:59 +02002406
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002407* The :meth:`ssl.SSLSocket.send()` method now raises either
2408 :exc:`ssl.SSLWantReadError` or :exc:`ssl.SSLWantWriteError`
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +03002409 on a non-blocking socket if the operation would block. Previously,
2410 it would return ``0``. (Contributed by Nikolaus Rath in :issue:`20951`.)
Victor Stinnerdb067af2014-05-02 22:31:14 +02002411
Martin Panter97ce0fa2015-11-14 01:14:54 +00002412* The ``__name__`` attribute of generators is now set from the function name,
Victor Stinner40ee3012014-06-16 15:59:28 +02002413 instead of being set from the code name. Use ``gen.gi_code.co_name`` to
2414 retrieve the code name. Generators also have a new ``__qualname__``
2415 attribute, the qualified name, which is now used for the representation
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +03002416 of a generator (``repr(gen)``).
2417 (Contributed by Victor Stinner in :issue:`21205`.)
Victor Stinner40ee3012014-06-16 15:59:28 +02002418
Ezio Melotti045160b2014-08-02 18:54:30 +03002419* The deprecated "strict" mode and argument of :class:`~html.parser.HTMLParser`,
2420 :meth:`HTMLParser.error`, and the :exc:`HTMLParserError` exception have been
Serhiy Storchakac1ded292014-11-02 19:22:02 +02002421 removed. (Contributed by Ezio Melotti in :issue:`15114`.)
Ezio Melotti045160b2014-08-02 18:54:30 +03002422 The *convert_charrefs* argument of :class:`~html.parser.HTMLParser` is
Serhiy Storchakac1ded292014-11-02 19:22:02 +02002423 now ``True`` by default. (Contributed by Berker Peksag in :issue:`21047`.)
Ezio Melotti045160b2014-08-02 18:54:30 +03002424
R David Murray861470c2014-10-05 11:47:01 -04002425* Although it is not formally part of the API, it is worth noting for porting
2426 purposes (ie: fixing tests) that error messages that were previously of the
2427 form "'sometype' does not support the buffer protocol" are now of the form "a
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +03002428 :term:`bytes-like object` is required, not 'sometype'".
2429 (Contributed by Ezio Melotti in :issue:`16518`.)
R David Murray861470c2014-10-05 11:47:01 -04002430
Brett Cannonb6e25562014-11-21 12:19:28 -05002431* If the current directory is set to a directory that no longer exists then
2432 :exc:`FileNotFoundError` will no longer be raised and instead
2433 :meth:`~importlib.machinery.FileFinder.find_spec` will return ``None``
Martin Panter97ce0fa2015-11-14 01:14:54 +00002434 **without** caching ``None`` in :data:`sys.path_importer_cache`, which is
Brett Cannonb6e25562014-11-21 12:19:28 -05002435 different than the typical case (:issue:`22834`).
2436
Berker Peksag088ca8b2015-02-06 10:17:49 +02002437* HTTP status code and messages from :mod:`http.client` and :mod:`http.server`
2438 were refactored into a common :class:`~http.HTTPStatus` enum. The values in
2439 :mod:`http.client` and :mod:`http.server` remain available for backwards
2440 compatibility. (Contributed by Demian Brecht in :issue:`21793`.)
Serhiy Storchakae4db7692014-12-23 16:28:28 +02002441
Yury Selivanova33cb352015-09-13 11:21:25 -04002442* When an import loader defines :meth:`importlib.machinery.Loader.exec_module`
Brett Cannon02d84542015-01-09 11:39:21 -05002443 it is now expected to also define
2444 :meth:`~importlib.machinery.Loader.create_module` (raises a
2445 :exc:`DeprecationWarning` now, will be an error in Python 3.6). If the loader
2446 inherits from :class:`importlib.abc.Loader` then there is nothing to do, else
2447 simply define :meth:`~importlib.machinery.Loader.create_module` to return
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +03002448 ``None``. (Contributed by Brett Cannon in :issue:`23014`.)
Brett Cannon02d84542015-01-09 11:39:21 -05002449
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002450* The :func:`re.split` function always ignored empty pattern matches, so the
2451 ``"x*"`` pattern worked the same as ``"x+"``, and the ``"\b"`` pattern never
2452 worked. Now :func:`re.split` raises a warning if the pattern could match
Martin Panter97ce0fa2015-11-14 01:14:54 +00002453 an empty string. For compatibility, use patterns that never match an empty
Yury Selivanov5c3111e2015-09-10 18:04:35 -04002454 string (e.g. ``"x+"`` instead of ``"x*"``). Patterns that could only match
2455 an empty string (such as ``"\b"``) now raise an error.
Yury Selivanov46a8b402015-09-12 15:52:04 -04002456 (Contributed by Serhiy Storchaka in :issue:`22818`.)
Serhiy Storchaka83e80272015-02-03 11:04:19 +02002457
Yury Selivanova33cb352015-09-13 11:21:25 -04002458* The :class:`http.cookies.Morsel` dict-like interface has been made self
R David Murray1813c172015-03-29 17:09:21 -04002459 consistent: morsel comparison now takes the :attr:`~http.cookies.Morsel.key`
2460 and :attr:`~http.cookies.Morsel.value` into account,
2461 :meth:`~http.cookies.Morsel.copy` now results in a
R David Murrayba6ea9b2015-03-30 11:48:50 -04002462 :class:`~http.cookies.Morsel` instance rather than a :class:`dict`, and
2463 :meth:`~http.cookies.Morsel.update` will now raise an exception if any of the
R David Murray1813c172015-03-29 17:09:21 -04002464 keys in the update dictionary are invalid. In addition, the undocumented
2465 *LegalChars* parameter of :func:`~http.cookies.Morsel.set` is deprecated and
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +03002466 is now ignored. (Contributed by Demian Brecht in :issue:`2211`.)
R David Murray1813c172015-03-29 17:09:21 -04002467
Brett Cannonf299abd2015-04-13 14:21:02 -04002468* :pep:`488` has removed ``.pyo`` files from Python and introduced the optional
2469 ``opt-`` tag in ``.pyc`` file names. The
2470 :func:`importlib.util.cache_from_source` has gained an *optimization*
2471 parameter to help control the ``opt-`` tag. Because of this, the
2472 *debug_override* parameter of the function is now deprecated. `.pyo` files
2473 are also no longer supported as a file argument to the Python interpreter and
2474 thus serve no purpose when distributed on their own (i.e. sourcless code
2475 distribution). Due to the fact that the magic number for bytecode has changed
2476 in Python 3.5, all old `.pyo` files from previous versions of Python are
2477 invalid regardless of this PEP.
2478
Yury Selivanov4dde5872015-09-11 00:48:21 -04002479* The :mod:`socket` module now exports the :data:`~socket.CAN_RAW_FD_FRAMES`
2480 constant on linux 3.6 and greater.
Larry Hastingsa6cc5512015-04-13 17:48:40 -04002481
Yury Selivanova33cb352015-09-13 11:21:25 -04002482* The :func:`ssl.cert_time_to_seconds` function now interprets the input time
Yury Selivanova88cd642015-09-10 21:26:54 -04002483 as UTC and not as local time, per :rfc:`5280`. Additionally, the return
2484 value is always an :class:`int`. (Contributed by Akira Li in :issue:`19940`.)
2485
Zachary Ware3d3aedc2015-07-07 00:07:25 -05002486* The ``pygettext.py`` Tool now uses the standard +NNNN format for timezones in
R David Murray2b781292015-04-16 12:15:09 -04002487 the POT-Creation-Date header.
2488
Martin Panter97ce0fa2015-11-14 01:14:54 +00002489* The :mod:`smtplib` module now uses :data:`sys.stderr` instead of the previous
2490 module-level :data:`stderr` variable for debug output. If your (test)
2491 program depends on patching the module-level variable to capture the debug
R David Murray0c49b892015-04-16 17:14:42 -04002492 output, you will need to update it to capture sys.stderr instead.
2493
Serhiy Storchakad4ea03c2015-05-31 09:15:51 +03002494* The :meth:`str.startswith` and :meth:`str.endswith` methods no longer return
2495 ``True`` when finding the empty string and the indexes are completely out of
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +03002496 range. (Contributed by Serhiy Storchaka in :issue:`24284`.)
Serhiy Storchakad4ea03c2015-05-31 09:15:51 +03002497
Berker Peksag4333d8b2015-07-30 18:06:09 +03002498* The :func:`inspect.getdoc` function now returns documentation strings
2499 inherited from base classes. Documentation strings no longer need to be
2500 duplicated if the inherited documentation is appropriate. To suppress an
2501 inherited string, an empty string must be specified (or the documentation
2502 may be filled in). This change affects the output of the :mod:`pydoc`
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +03002503 module and the :func:`help` function.
2504 (Contributed by Serhiy Storchaka in :issue:`15582`.)
Berker Peksag4333d8b2015-07-30 18:06:09 +03002505
Berker Peksag9b93c6b2015-09-22 13:08:16 +03002506* Nested :func:`functools.partial` calls are now flattened. If you were
2507 relying on the previous behavior, you can now either add an attribute to a
2508 :func:`functools.partial` object or you can create a subclass of
2509 :func:`functools.partial`.
2510 (Contributed by Alexander Belopolsky in :issue:`7830`.)
2511
Victor Stinnerdb067af2014-05-02 22:31:14 +02002512Changes in the C API
2513--------------------
2514
Stefan Krahf5324d72015-01-29 14:29:51 +01002515* The undocumented :c:member:`~PyMemoryViewObject.format` member of the
2516 (non-public) :c:type:`PyMemoryViewObject` structure has been removed.
Stefan Krahf5324d72015-01-29 14:29:51 +01002517 All extensions relying on the relevant parts in ``memoryobject.h``
2518 must be rebuilt.
2519
Victor Stinnerd8f0d922014-06-02 21:57:10 +02002520* The :c:type:`PyMemAllocator` structure was renamed to
2521 :c:type:`PyMemAllocatorEx` and a new ``calloc`` field was added.
Serhiy Storchakadf4518c2014-11-18 23:34:33 +02002522
2523* Removed non-documented macro :c:macro:`PyObject_REPR` which leaked references.
2524 Use format character ``%R`` in :c:func:`PyUnicode_FromFormat`-like functions
2525 to format the :func:`repr` of the object.
Yury Selivanov508a81e2015-09-10 23:37:06 -04002526 (Contributed by Serhiy Storchaka in :issue:`22453`.)
Serhiy Storchaka490055a2015-03-01 10:03:02 +02002527
2528* Because the lack of the :attr:`__module__` attribute breaks pickling and
Martin Panter97ce0fa2015-11-14 01:14:54 +00002529 introspection, a deprecation warning is now raised for builtin types without
2530 the :attr:`__module__` attribute. This would be an AttributeError in
2531 the future.
Serhiy Storchaka1c30e7e2015-09-11 20:55:28 +03002532 (Contributed by Serhiy Storchaka in :issue:`20204`.)
Yury Selivanov50960882015-05-12 00:15:05 -04002533
Martin Panter97ce0fa2015-11-14 01:14:54 +00002534* As part of the :pep:`492` implementation, the ``tp_reserved`` slot of
Yury Selivanovf3e40fa2015-05-21 11:50:30 -04002535 :c:type:`PyTypeObject` was replaced with a
Yury Selivanov27947d52015-06-23 15:09:58 -04002536 :c:member:`tp_as_async` slot. Refer to :ref:`coro-objects` for
Yury Selivanov5376ba92015-06-22 12:19:30 -04002537 new types, structures and functions.
Yury Selivanov336b37b2015-09-09 12:23:01 -04002538
Ned Deily9d6171d2018-06-11 04:09:34 -04002539
2540Notable changes in Python 3.5.4
2541===============================
2542
2543New ``make regen-all`` build target
2544-----------------------------------
2545
2546To simplify cross-compilation, and to ensure that CPython can reliably be
2547compiled without requiring an existing version of Python to already be
2548available, the autotools-based build system no longer attempts to implicitly
2549recompile generated files based on file modification times.
2550
2551Instead, a new ``make regen-all`` command has been added to force regeneration
2552of these files when desired (e.g. after an initial version of Python has
2553already been built based on the pregenerated versions).
2554
2555More selective regeneration targets are also defined - see
2556:source:`Makefile.pre.in` for details.
2557
2558(Contributed by Victor Stinner in :issue:`23404`.)
2559
2560.. versionadded:: 3.5.4
2561
2562
2563Removal of ``make touch`` build target
2564--------------------------------------
2565
2566The ``make touch`` build target previously used to request implicit regeneration
2567of generated files by updating their modification times has been removed.
2568
2569It has been replaced by the new ``make regen-all`` target.
2570
2571(Contributed by Victor Stinner in :issue:`23404`.)
2572
2573.. versionchanged:: 3.5.4
2574