blob: 248cdf99a22426b37e835beb7348389eddc9a5cd [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
5:Release: |release|
6:Date: |today|
Yury Selivanov1f4d4702015-09-09 09:27:29 -04007:Editor: Elvis Pranskevichus <elprans@gmail.com>
Yury Selivanovdfcfe132015-09-08 15:33:15 -04008
Victor Stinner01adf062014-03-18 00:53:32 +01009.. Rules for maintenance:
10
11 * Anyone can add text to this document. Do not spend very much time
12 on the wording of your changes, because your text will probably
13 get rewritten to some degree.
14
15 * The maintainer will go through Misc/NEWS periodically and add
16 changes; it's therefore more important to add your changes to
17 Misc/NEWS than to this file.
18
19 * This is not a complete list of every single change; completeness
20 is the purpose of Misc/NEWS. Some changes I consider too small
21 or esoteric to include. If such a change is added to the text,
22 I'll just remove it. (This is another reason you shouldn't spend
23 too much time on writing your addition.)
24
25 * If you want to draw your new text to the attention of the
26 maintainer, add 'XXX' to the beginning of the paragraph or
27 section.
28
29 * It's OK to just add a fragmentary note about a change. For
30 example: "XXX Describe the transmogrify() function added to the
31 socket module." The maintainer will research the change and
32 write the necessary text.
33
34 * You can comment out your additions if you like, but it's not
35 necessary (especially when a final release is some months away).
36
37 * Credit the author of a patch or bugfix. Just the name is
38 sufficient; the e-mail address isn't necessary.
39
40 * It's helpful to add the bug/patch number as a comment:
41
42 XXX Describe the transmogrify() function added to the socket
43 module.
44 (Contributed by P.Y. Developer in :issue:`12345`.)
45
46 This saves the maintainer the effort of going through the Mercurial log
47 when researching a change.
48
49This article explains the new features in Python 3.5, compared to 3.4.
Victor Stinner01adf062014-03-18 00:53:32 +010050For full details, see the :source:`Misc/NEWS` file.
51
Benjamin Peterson52d14932015-03-27 16:07:35 -040052.. note::
53
54 Prerelease users should be aware that this document is currently in draft
55 form. It will be updated substantially as Python 3.5 moves towards release,
56 so it's worth checking back even after reading earlier versions.
Victor Stinner01adf062014-03-18 00:53:32 +010057
58
59.. seealso::
60
Berker Peksagfa0423b2014-10-09 11:38:19 +030061 :pep:`478` - Python 3.5 Release Schedule
Victor Stinner01adf062014-03-18 00:53:32 +010062
63
64Summary -- Release highlights
65=============================
66
Victor Stinner93692bb2015-03-30 15:04:45 +020067.. This section singles out the most important changes in Python 3.5.
Victor Stinner01adf062014-03-18 00:53:32 +010068 Brevity is key.
69
70New syntax features:
71
Benjamin Peterson14ef1a12015-05-13 11:19:27 -040072* :pep:`465`, a new matrix multiplication operator: ``a @ b``.
73* :pep:`492`, coroutines with async and await syntax.
Yury Selivanova5a00622015-08-04 12:52:16 -040074* :pep:`448`, additional unpacking generalizations.
Victor Stinner01adf062014-03-18 00:53:32 +010075
76New library modules:
77
Brett Cannoncc4dfc12015-03-13 10:40:49 -040078* :mod:`zipapp`: :ref:`Improving Python ZIP Application Support
79 <whatsnew-zipapp>` (:pep:`441`).
Victor Stinner01adf062014-03-18 00:53:32 +010080
81New built-in features:
82
Victor Stinner93692bb2015-03-30 15:04:45 +020083* ``bytes % args``, ``bytearray % args``: :pep:`461` - Adding ``%`` formatting
Yury Selivanov40301c02015-09-08 23:28:06 -040084 to bytes and bytearray.
85
Gregory P. Smith8cb65692015-04-25 23:22:26 +000086* ``b'\xf0\x9f\x90\x8d'.hex()``, ``bytearray(b'\xf0\x9f\x90\x8d').hex()``,
87 ``memoryview(b'\xf0\x9f\x90\x8d').hex()``: :issue:`9951` - A ``hex`` method
88 has been added to bytes, bytearray, and memoryview.
Yury Selivanov40301c02015-09-08 23:28:06 -040089
Yury Selivanove13f8f32015-07-03 00:23:30 -040090* Generators have new ``gi_yieldfrom`` attribute, which returns the
91 object being iterated by ``yield from`` expressions. (Contributed
92 by Benno Leslie and Yury Selivanov in :issue:`24450`.)
Yury Selivanov40301c02015-09-08 23:28:06 -040093
Yury Selivanovf488fb42015-07-03 01:04:23 -040094* New :exc:`RecursionError` exception. (Contributed by Georg Brandl
95 in :issue:`19235`.)
Victor Stinner01adf062014-03-18 00:53:32 +010096
97Implementation improvements:
98
Victor Stinner71430292014-03-18 01:18:21 +010099* When the ``LC_TYPE`` locale is the POSIX locale (``C`` locale),
100 :py:data:`sys.stdin` and :py:data:`sys.stdout` are now using the
101 ``surrogateescape`` error handler, instead of the ``strict`` error handler
102 (:issue:`19977`).
Victor Stinner01adf062014-03-18 00:53:32 +0100103
Brett Cannonf299abd2015-04-13 14:21:02 -0400104* :pep:`488`, the elimination of ``.pyo`` files.
Yury Selivanov40301c02015-09-08 23:28:06 -0400105
Nick Coghland5cacbb2015-05-23 22:24:10 +1000106* :pep:`489`, multi-phase initialization of extension modules.
Brett Cannonf299abd2015-04-13 14:21:02 -0400107
Victor Stinner01adf062014-03-18 00:53:32 +0100108Significantly Improved Library Modules:
109
Yury Selivanov58444362015-05-30 10:49:09 -0400110* :class:`collections.OrderedDict` is now implemented in C, which improves
111 its performance between 4x to 100x times. Contributed by Eric Snow in
112 :issue:`16991`.
113
Gregory P. Smithad577b92015-05-22 16:18:14 -0700114* You may now pass bytes to the :mod:`tempfile` module's APIs and it will
115 return the temporary pathname as bytes instead of str. It also accepts
116 a value of ``None`` on parameters where only str was accepted in the past to
117 do the right thing based on the types of the other inputs. Two functions,
118 :func:`gettempdirb` and :func:`gettempprefixb`, have been added to go along
119 with this. This behavior matches that of the :mod:`os` APIs.
Victor Stinner01adf062014-03-18 00:53:32 +0100120
Yury Selivanov7d6adab2015-08-05 19:01:51 -0400121* :mod:`ssl` module gained support for Memory BIO, which decouples SSL
122 protocol handling from network IO. (Contributed by Geert Jansen in
123 :issue:`21965`.)
124
Yury Selivanov40301c02015-09-08 23:28:06 -0400125* :mod:`traceback` has new lightweight and convenient to work with
126 classes :class:`~traceback.TracebackException`,
127 :class:`~traceback.StackSummary`, and :class:`traceback.FrameSummary`.
128 (Contributed by Robert Collins in :issue:`17911`.)
129
Victor Stinner01adf062014-03-18 00:53:32 +0100130Security improvements:
131
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400132* SSLv3 is now disabled throughout the standard library.
133 It can still be enabled by instantiating a :class:`ssl.SSLContext`
134 manually. (See :issue:`22638` for more details; this change was
135 backported to CPython 3.4 and 2.7.)
136
137* HTTP cookie parsing is now stricter, in order to protect
138 against potential injection attacks. (Contributed by Antoine Pitrou
139 in :issue:`22796`.)
Victor Stinner01adf062014-03-18 00:53:32 +0100140
Steve Dower313fbf42015-07-17 16:48:48 -0700141Windows improvements:
142
143* A new installer for Windows has replaced the old MSI. See :ref:`using-on-windows`
144 for more information.
Yury Selivanov40301c02015-09-08 23:28:06 -0400145
Steve Dower313fbf42015-07-17 16:48:48 -0700146* Windows builds now use Microsoft Visual C++ 14.0, and extension modules
147 should use the same.
148
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400149Please read on for a comprehensive list of user-facing changes, including many
150other smaller improvements, CPython optimizations, deprecations, and potential
151porting issues.
Victor Stinner01adf062014-03-18 00:53:32 +0100152
153
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400154New Features
155============
156
157.. _whatsnew-pep-492:
158
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400159PEP 492 - Coroutines with async and await syntax
160------------------------------------------------
161
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400162:pep:`492` greatly improves support for asynchronous programming in Python
163by adding :term:`awaitable objects <awaitable>`,
164:term:`coroutine functions <coroutine function>`,
165:term:`asynchronous iteration <asynchronous iterable>`,
166and :term:`asynchronous context managers <asynchronous context manager>`.
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400167
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400168Coroutine functions are declared using the new :keyword:`async def` syntax::
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400169
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400170 >>> async def coro():
171 ... return 'spam'
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400172
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400173Inside a coroutine function, a new :keyword:`await` expression can be used
174to suspend coroutine execution until the result is available. Any object
175can be *awaited*, as long as it implements the :term:`awaitable` protocol by
176defining the :meth:`__await__` method.
177
178PEP 492 also adds :keyword:`async for` statement for convenient iteration
179over asynchronous iterables.
180
181An example of a simple HTTP client written using the new syntax::
182
183 import asyncio
184
185 async def http_get(domain):
186 reader, writer = await asyncio.open_connection(domain, 80)
187
188 writer.write(b'\r\n'.join([
189 b'GET / HTTP/1.1',
190 b'Host: %b' % domain.encode('latin-1'),
191 b'Connection: close',
192 b'', b''
193 ]))
194
195 async for line in reader:
196 print('>>>', line)
197
198 writer.close()
199
200 loop = asyncio.get_event_loop()
201 try:
202 loop.run_until_complete(http_get('example.com'))
203 finally:
204 loop.close()
205
206
207Similarly to asynchronous iteration, there is a new syntax for asynchronous
208context managers::
209
210 >>> import asyncio
211 >>> async def coro1(lock):
212 ... print('coro1: waiting for lock')
213 ... async with lock:
214 ... print('coro1: holding the lock')
215 ... await asyncio.sleep(1)
216 ... print('coro1: releasing the lock')
217 ...
218 >>> async def coro2(lock):
219 ... print('coro2: waiting for lock')
220 ... async with lock:
221 ... print('coro2: holding the lock')
222 ... await asyncio.sleep(1)
223 ... print('coro2: releasing the lock')
224 ...
225 >>> loop = asyncio.get_event_loop()
226 >>> lock = asyncio.Lock()
227 >>> coros = asyncio.gather(coro1(lock), coro2(lock), loop=loop)
228 >>> loop.run_until_complete(coros)
229 coro1: waiting for lock
230 coro1: holding the lock
231 coro2: waiting for lock
232 coro1: releasing the lock
233 coro2: holding the lock
234 coro2: releasing the lock
235 >>> loop.close()
236
237Note that both :keyword:`async for` and :keyword:`async with` can only
238be used inside a coroutine function declared with :keyword:`async def`.
239
240Coroutine functions are intended to be ran inside a compatible event loop,
241such as :class:`asyncio.Loop`.
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400242
243.. seealso::
244
245 :pep:`492` -- Coroutines with async and await syntax
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400246 PEP written and implemented by Yury Selivanov.
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400247
248
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400249PEP 465 - A dedicated infix operator for matrix multiplication
250--------------------------------------------------------------
Victor Stinner93692bb2015-03-30 15:04:45 +0200251
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400252:pep:`465` adds the ``@`` infix operator for matrix multiplication.
253Currently, no builtin Python types implement the new operator, however, it
254can be implemented by defining :meth:`__matmul__`, :meth:`__rmatmul__`,
255and :meth:`__imatmul__` for regular, reflected, and in-place matrix
256multiplication. The semantics of these methods is similar to that of
257methods defining other infix arithmetic operators.
258
259Matrix multiplication is a notably common operation in many fields of
260mathematics, science, engineering, and the addition of ``@`` allows writing
261cleaner code::
262
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400263 S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r)
264
265instead of::
266
267 S = dot((dot(H, beta) - r).T,
268 dot(inv(dot(dot(H, V), H.T)), dot(H, beta) - r))
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400269
270An upcoming release of NumPy 1.10 will add support for the new operator::
271
272 >>> import numpy
273
274 >>> x = numpy.ones(3)
275 >>> x
276 array([ 1., 1., 1.])
277
278 >>> m = numpy.eye(3)
279 >>> m
280 array([[ 1., 0., 0.],
281 [ 0., 1., 0.],
282 [ 0., 0., 1.]])
283
284 >>> x @ m
285 array([ 1., 1., 1.])
286
287
288.. seealso::
289
290 :pep:`465` -- A dedicated infix operator for matrix multiplication
291 PEP written by Nathaniel J. Smith; implemented by Benjamin Peterson.
292
293
294PEP 448 - Additional Unpacking Generalizations
295----------------------------------------------
296
297:pep:`448` extends the allowed uses of the ``*`` iterable unpacking
298operator and ``**`` dictionary unpacking operator. It is now possible
299to use an arbitrary number of unpackings in function calls::
300
301 >>> print(*[1], *[2], 3, *[4, 5])
302 1 2 3 4 5
303
304 >>> def fn(a, b, c, d):
305 ... print(a, b, c, d)
306 ...
307
308 >>> fn(**{'a': 1, 'c': 3}, **{'b': 2, 'd': 4})
309 1 2 3 4
310
311Similarly, tuple, list, set, and dictionary displays allow multiple
312unpackings::
313
314 >>> *range(4), 4
315 (0, 1, 2, 3, 4)
316 >>> [*range(4), 4]
317 [0, 1, 2, 3, 4]
318 >>> {*range(4), 4, *(5, 6, 7)}
319 {0, 1, 2, 3, 4, 5, 6, 7}
320 >>> {'x': 1, **{'y': 2}}
321 {'x': 1, 'y': 2}
322
323.. seealso::
324
325 :pep:`448` -- Additional Unpacking Generalizations
326 PEP written by Joshua Landau; implemented by Neil Girdhar,
327 Thomas Wouters, and Joshua Landau.
328
329
330PEP 461 - % formatting support for bytes and bytearray
331------------------------------------------------------
332
333PEP 461 adds % formatting to :class:`bytes` and :class:`bytearray`, aiding in
334handling data that is a mixture of binary and ASCII compatible text. This
335feature also eases porting such code from Python 2.
Victor Stinner93692bb2015-03-30 15:04:45 +0200336
337Examples::
338
339 >>> b'Hello %s!' % b'World'
340 b'Hello World!'
341 >>> b'x=%i y=%f' % (1, 2.5)
342 b'x=1 y=2.500000'
343
344Unicode is not allowed for ``%s``, but it is accepted by ``%a`` (equivalent of
345``repr(obj).encode('ascii', 'backslashreplace')``)::
346
347 >>> b'Hello %s!' % 'World'
348 Traceback (most recent call last):
349 File "<stdin>", line 1, in <module>
350 TypeError: %b requires bytes, or an object that implements __bytes__, not 'str'
351 >>> b'price: %a' % '10€'
352 b"price: '10\\u20ac'"
353
354.. seealso::
355
356 :pep:`461` -- Adding % formatting to bytes and bytearray
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400357 PEP written by Ethan Furman; implemented by Neil Schemenauer and
358 Ethan Furman.
Yury Selivanov216d9992015-08-04 12:42:20 -0400359
360
Yury Selivanov5df36af2015-08-04 12:46:57 -0400361PEP 484 - Type Hints
362--------------------
363
364This PEP introduces a provisional module to provide these standard
365definitions and tools, along with some conventions for situations
366where annotations are not available.
367
368For example, here is a simple function whose argument and return type
369are declared in the annotations::
370
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400371 def greeting(name: str) -> str:
372 return 'Hello ' + name
Yury Selivanov5df36af2015-08-04 12:46:57 -0400373
374The type system supports unions, generic types, and a special type
375named ``Any`` which is consistent with (i.e. assignable to and from) all
376types.
377
378.. seealso::
379
Yury Selivanov40c0ce42015-08-05 12:46:29 -0400380 * :mod:`typing` module documentation
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400381 * :pep:`484` -- Type Hints
382 PEP written by Guido van Rossum, Jukka Lehtosalo, and Łukasz Langa;
383 implemented by Guido van Rossum.
Yury Selivanov5df36af2015-08-04 12:46:57 -0400384
385
Victor Stinner6036e442015-03-08 01:58:04 +0100386PEP 471 - os.scandir() function -- a better and faster directory iterator
387-------------------------------------------------------------------------
388
Victor Stinner37f20342015-03-10 13:29:41 +0100389:pep:`471` adds a new directory iteration function, :func:`os.scandir`,
390to the standard library. Additionally, :func:`os.walk` is now
391implemented using :func:`os.scandir`, which speeds it up by 3-5 times
392on POSIX systems and by 7-20 times on Windows systems.
393
Victor Stinner6036e442015-03-08 01:58:04 +0100394.. seealso::
395
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400396 :pep:`471` -- os.scandir() function -- a better and faster directory iterator
397 PEP written and implemented by Ben Hoyt with the help of Victor Stinner.
Victor Stinner6036e442015-03-08 01:58:04 +0100398
399
Charles-François Natali6e6c59b2015-02-07 13:27:50 +0000400PEP 475: Retry system calls failing with EINTR
401----------------------------------------------
402
Victor Stinnerf70e1ca2015-03-30 21:16:11 +0200403:pep:`475` adds support for automatic retry of system calls failing with
404:py:data:`~errno.EINTR`: this means that user code doesn't have to deal with
405EINTR or :exc:`InterruptedError` manually, and should make it more robust
406against asynchronous signal reception.
Charles-François Natali6e6c59b2015-02-07 13:27:50 +0000407
Victor Stinner6752d652015-07-29 01:11:10 +0200408Examples of functions which are now retried when interrupted by a signal
409instead of raising :exc:`InterruptedError` if the Python signal handler does
410not raise an exception:
411
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400412* :func:`open`, :func:`os.open`, :func:`io.open`;
Victor Stinner6752d652015-07-29 01:11:10 +0200413
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400414* functions of the :mod:`faulthandler` module;
Victor Stinner6752d652015-07-29 01:11:10 +0200415
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400416* :mod:`os` functions: :func:`~os.fchdir`, :func:`~os.fchmod`,
417 :func:`~os.fchown`, :func:`~os.fdatasync`, :func:`~os.fstat`,
418 :func:`~os.fstatvfs`, :func:`~os.fsync`, :func:`~os.ftruncate`,
419 :func:`~os.mkfifo`, :func:`~os.mknod`, :func:`~os.posix_fadvise`,
420 :func:`~os.posix_fallocate`, :func:`~os.pread`, :func:`~os.pwrite`,
421 :func:`~os.read`, :func:`~os.readv`, :func:`~os.sendfile`,
422 :func:`~os.wait3`, :func:`~os.wait4`, :func:`~os.wait`,
423 :func:`~os.waitid`, :func:`~os.waitpid`, :func:`~os.write`,
424 :func:`~os.writev`;
Victor Stinner6752d652015-07-29 01:11:10 +0200425
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400426* special cases: :func:`os.close` and :func:`os.dup2` now ignore
427 :py:data:`~errno.EINTR` error, the syscall is not retried (see the PEP
428 for the rationale);
Victor Stinner6752d652015-07-29 01:11:10 +0200429
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400430* :mod:`select` functions: :func:`~select.devpoll.poll`,
431 :func:`~select.epoll.poll`, :func:`~select.kqueue.control`,
432 :func:`~select.poll.poll`, :func:`~select.select`;
Victor Stinner6752d652015-07-29 01:11:10 +0200433
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400434* :func:`socket.socket` methods: :meth:`~socket.socket.accept`,
435 :meth:`~socket.socket.connect` (except for non-blocking sockets),
436 :meth:`~socket.socket.recv`, :meth:`~socket.socket.recvfrom`,
437 :meth:`~socket.socket.recvmsg`, :meth:`~socket.socket.send`,
438 :meth:`~socket.socket.sendall`, :meth:`~socket.socket.sendmsg`,
439 :meth:`~socket.socket.sendto`;
Victor Stinner6752d652015-07-29 01:11:10 +0200440
Yury Selivanov0ac5f282015-09-08 23:40:46 -0400441* :func:`signal.sigtimedwait`, :func:`signal.sigwaitinfo`;
442
443* :func:`time.sleep`.
Victor Stinner6752d652015-07-29 01:11:10 +0200444
Charles-François Natali6e6c59b2015-02-07 13:27:50 +0000445.. seealso::
446
447 :pep:`475` -- Retry system calls failing with EINTR
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400448 PEP and implementation written by Charles-François Natali and
449 Victor Stinner, with the help of Antoine Pitrou (the french connection).
Victor Stinner01adf062014-03-18 00:53:32 +0100450
451
Yury Selivanov8d006e72015-05-22 11:30:45 -0400452PEP 479: Change StopIteration handling inside generators
453--------------------------------------------------------
454
455:pep:`479` changes the behavior of generators: when a :exc:`StopIteration`
456exception is raised inside a generator, it is replaced with a
457:exc:`RuntimeError`. To enable the feature a ``__future__`` import should
458be used::
459
460 from __future__ import generator_stop
461
462Without a ``__future__`` import, a :exc:`PendingDeprecationWarning` will be
463raised.
464
Yury Selivanov8d006e72015-05-22 11:30:45 -0400465.. seealso::
466
467 :pep:`479` -- Change StopIteration handling inside generators
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400468 PEP written by Chris Angelico and Guido van Rossum. Implemented by
469 Chris Angelico, Yury Selivanov and Nick Coghlan.
Yury Selivanov8d006e72015-05-22 11:30:45 -0400470
471
Steve Dower76998fe2015-02-26 14:25:33 -0800472PEP 486: Make the Python Launcher aware of virtual environments
473---------------------------------------------------------------
474
475:pep:`486` makes the Windows launcher (see :pep:`397`) aware of an active
476virtual environment. When the default interpreter would be used and the
477``VIRTUAL_ENV`` environment variable is set, the interpreter in the virtual
478environment will be used.
479
480.. seealso::
481
482 :pep:`486` -- Make the Python Launcher aware of virtual environments
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400483 PEP written and implemented by Paul Moore.
Steve Dower76998fe2015-02-26 14:25:33 -0800484
Brett Cannonf299abd2015-04-13 14:21:02 -0400485
486PEP 488: Elimination of PYO files
487---------------------------------
488
489:pep:`488` does away with the concept of ``.pyo`` files. This means that
Benjamin Petersone3283232015-05-26 21:40:28 -0500490``.pyc`` files represent both unoptimized and optimized bytecode. To prevent the
491need to constantly regenerate bytecode files, ``.pyc`` files now have an
492optional ``opt-`` tag in their name when the bytecode is optimized. This has the
493side-effect of no more bytecode file name clashes when running under either
494``-O`` or ``-OO``. Consequently, bytecode files generated from ``-O``, and
495``-OO`` may now exist simultaneously. :func:`importlib.util.cache_from_source`
496has an updated API to help with this change.
Brett Cannonf299abd2015-04-13 14:21:02 -0400497
498.. seealso::
499
500 :pep:`488` -- Elimination of PYO files
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400501 PEP written and implemented by Brett Cannon.
Brett Cannonf299abd2015-04-13 14:21:02 -0400502
503
Nick Coghland5cacbb2015-05-23 22:24:10 +1000504PEP 489: Multi-phase extension module initialization
505----------------------------------------------------
506
507:pep:`489` updates extension module initialization to take advantage of the
508two step module loading mechanism introduced by :pep:`451` in Python 3.4.
509
510This change brings the import semantics of extension modules that opt-in to
511using the new mechanism much closer to those of Python source and bytecode
Nick Coghlan2ab5b092015-07-03 19:49:15 +1000512modules, including the ability to use any valid identifier as a module name,
Nick Coghland5cacbb2015-05-23 22:24:10 +1000513rather than being restricted to ASCII.
514
515.. seealso::
516
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400517 :pep:`489` -- Multi-phase extension module initialization
518 PEP written by Petr Viktorin, Stefan Behnel, and Nick Coghlan;
Yury Selivanov1f4d4702015-09-09 09:27:29 -0400519 implemented by Petr Viktorin.
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400520
Nick Coghland5cacbb2015-05-23 22:24:10 +1000521
Tal Einatd5519ed2015-05-31 22:05:00 +0300522PEP 485: A function for testing approximate equality
523----------------------------------------------------
524
525:pep:`485` adds the :func:`math.isclose` and :func:`cmath.isclose`
526functions which tell whether two values are approximately equal or
527"close" to each other. Whether or not two values are considered
528close is determined according to given absolute and relative tolerances.
529
530.. seealso::
531
532 :pep:`485` -- A function for testing approximate equality
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400533 PEP written by Christopher Barker; implemented by Chris Barker and
534 Tal Einat.
535
Tal Einatd5519ed2015-05-31 22:05:00 +0300536
Victor Stinner01adf062014-03-18 00:53:32 +0100537Other Language Changes
538======================
539
540Some smaller changes made to the core Python language are:
541
Serhiy Storchaka07985ef2015-01-25 22:56:57 +0200542* Added the ``'namereplace'`` error handlers. The ``'backslashreplace'``
543 error handlers now works with decoding and translating.
544 (Contributed by Serhiy Storchaka in :issue:`19676` and :issue:`22286`.)
Victor Stinner01adf062014-03-18 00:53:32 +0100545
Serhiy Storchaka1dd49822015-03-20 16:54:57 +0200546* The :option:`-b` option now affects comparisons of :class:`bytes` with
547 :class:`int`. (Contributed by Serhiy Storchaka in :issue:`23681`)
Victor Stinner01adf062014-03-18 00:53:32 +0100548
Serhiy Storchakaad8a1c32015-05-12 23:16:55 +0300549* New Kazakh :ref:`codec <standard-encodings>` ``kz1048``. (Contributed by
550 Serhiy Storchaka in :issue:`22682`.)
551
Raymond Hettingereac503a2015-05-13 01:09:59 -0700552* Property docstrings are now writable. This is especially useful for
553 :func:`collections.namedtuple` docstrings.
554 (Contributed by Berker Peksag in :issue:`24064`.)
555
Serhiy Storchakaf0eeedf2015-05-12 23:24:19 +0300556* New Tajik :ref:`codec <standard-encodings>` ``koi8_t``. (Contributed by
557 Serhiy Storchaka in :issue:`22681`.)
558
Victor Stinner01adf062014-03-18 00:53:32 +0100559
560New Modules
561===========
562
Brett Cannoncc4dfc12015-03-13 10:40:49 -0400563.. _whatsnew-zipapp:
Victor Stinner01adf062014-03-18 00:53:32 +0100564
Brett Cannoncc4dfc12015-03-13 10:40:49 -0400565zipapp
566------
567
568The new :mod:`zipapp` module (specified in :pep:`441`) provides an API and
569command line tool for creating executable Python Zip Applications, which
570were introduced in Python 2.6 in :issue:`1739468` but which were not well
571publicised, either at the time or since.
572
573With the new module, bundling your application is as simple as putting all
574the files, including a ``__main__.py`` file, into a directory ``myapp``
575and running::
576
577 $ python -m zipapp myapp
578 $ python myapp.pyz
Victor Stinner01adf062014-03-18 00:53:32 +0100579
580
581Improved Modules
582================
583
Berker Peksag8089cd62015-02-14 01:39:17 +0200584argparse
585--------
586
587* :class:`~argparse.ArgumentParser` now allows to disable
588 :ref:`abbreviated usage <prefix-matching>` of long options by setting
589 :ref:`allow_abbrev` to ``False``.
590 (Contributed by Jonathan Paugh, Steven Bethard, paul j3 and Daniel Eriksson.)
591
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400592bz2
593---
594
595* New option *max_length* for :meth:`~bz2.BZ2Decompressor.decompress`
596 to limit the maximum size of decompressed data.
597 (Contributed by Nikolaus Rath in :issue:`15955`.)
598
Berker Peksagbf5e9602015-02-06 10:21:37 +0200599cgi
600---
601
Berker Peksagbd09d7b2015-02-11 15:32:34 +0200602* :class:`~cgi.FieldStorage` now supports the context management protocol.
Berker Peksagbf5e9602015-02-06 10:21:37 +0200603 (Contributed by Berker Peksag in :issue:`20289`.)
604
Tal Einatd5519ed2015-05-31 22:05:00 +0300605cmath
606-----
607
608* :func:`cmath.isclose` function added.
609 (Contributed by Chris Barker and Tal Einat in :issue:`24270`.)
610
611
R David Murrayc31e6222014-09-29 11:25:00 -0400612code
613----
614
615* The :func:`code.InteractiveInterpreter.showtraceback` method now prints
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200616 the full chained traceback, just like the interactive interpreter.
Berker Peksag088ca8b2015-02-06 10:17:49 +0200617 (Contributed by Claudiu Popa in :issue:`17442`.)
R David Murrayc31e6222014-09-29 11:25:00 -0400618
Raymond Hettingereac503a2015-05-13 01:09:59 -0700619collections
620-----------
621
622* You can now update docstrings produced by :func:`collections.namedtuple`::
623
624 Point = namedtuple('Point', ['x', 'y'])
625 Point.__doc__ = 'ordered pair'
626 Point.x.__doc__ = 'abscissa'
627 Point.y.__doc__ = 'ordinate'
628
629 (Contributed by Berker Peksag in :issue:`24064`.)
630
Brett Cannonf1a8df02014-09-12 10:39:48 -0400631compileall
632----------
633
634* :func:`compileall.compile_dir` and :mod:`compileall`'s command-line interface
635 can now do parallel bytecode compilation.
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200636 (Contributed by Claudiu Popa in :issue:`16104`.)
Brett Cannonf1a8df02014-09-12 10:39:48 -0400637
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400638* *quiet* parameter of :func:`compileall.compile_dir`,
639 :func:`compileall.compile_file`, and :func:`compileall.compile_path`
640 functions now has a multilevel value. New ``-qq`` command line option
641 is available for suppressing the output.
642 (Contributed by Thomas Kluyver in :issue:`21338`.)
643
644concurrent.futures
645------------------
646
647* :meth:`~concurrent.futures.Executor.map` now takes a *chunksize*
648 argument to allow batching of tasks in child processes and improve
649 performance of ProcessPoolExecutor.
650 (Contributed by Dan O'Reilly in :issue:`11271`.)
651
Berker Peksagbb44fe02014-11-28 23:28:06 +0200652contextlib
653----------
654
655* The new :func:`contextlib.redirect_stderr` context manager(similar to
656 :func:`contextlib.redirect_stdout`) makes it easier for utility scripts to
657 handle inflexible APIs that write their output to :data:`sys.stderr` and
658 don't provide any options to redirect it.
659 (Contributed by Berker Peksag in :issue:`22389`.)
660
Steve Dowerd2bc3892015-04-15 18:06:05 -0400661curses
662------
663* The new :func:`curses.update_lines_cols` function updates the variables
664 :envvar:`curses.LINES` and :envvar:`curses.COLS`.
665
Berker Peksag102029d2015-03-15 01:18:47 +0200666difflib
667-------
668
669* The charset of the HTML document generated by :meth:`difflib.HtmlDiff.make_file`
670 can now be customized by using *charset* keyword-only parameter. The default
671 charset of HTML document changed from ``'ISO-8859-1'`` to ``'utf-8'``.
672 (Contributed by Berker Peksag in :issue:`2052`.)
673
Greg Ward4d9d2562015-04-20 20:21:21 -0400674* It's now possible to compare lists of byte strings with
675 :func:`difflib.diff_bytes` (fixes a regression from Python 2).
676
Berker Peksag618e3152015-01-27 02:59:09 +0200677distutils
678---------
679
680* The ``build`` and ``build_ext`` commands now accept a ``-j``
681 option to enable parallel building of extension modules.
682 (Contributed by Antoine Pitrou in :issue:`5309`.)
683
Serhiy Storchakab9cec6a2015-05-16 22:13:27 +0300684* Added support for the LZMA compression.
685 (Contributed by Serhiy Storchaka in :issue:`16314`.)
686
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200687doctest
688-------
Giampaolo Rodola'e09fb712014-04-04 15:34:17 +0200689
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200690* :func:`doctest.DocTestSuite` returns an empty :class:`unittest.TestSuite` if
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200691 *module* contains no docstrings instead of raising :exc:`ValueError`.
692 (Contributed by Glenn Jones in :issue:`15916`.)
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200693
R David Murrayb744f3a2015-05-16 15:41:07 -0400694email
695-----
696
R David Murrayfdb23c22015-05-17 14:24:33 -0400697* A new policy option :attr:`~email.policy.Policy.mangle_from_` controls
698 whether or not lines that start with "From " in email bodies are prefixed with
699 a '>' character by generators. The default is ``True`` for
700 :attr:`~email.policy.compat32` and ``False`` for all other policies.
701 (Contributed by Milan Oberkirch in :issue:`20098`.)
702
R David Murrayb744f3a2015-05-16 15:41:07 -0400703* A new method :meth:`~email.message.Message.get_content_disposition` provides
704 easy access to a canonical value for the :mailheader:`Content-Disposition`
705 header (``None`` if there is no such header). (Contributed by Abhilash Raj
706 in :issue:`21083`.)
707
R David Murray224ef3e2015-05-17 11:29:21 -0400708* A new policy option :attr:`~email.policy.EmailPolicy.utf8` can be set
709 ``True`` to encode email headers using the utf8 charset instead of using
710 encoded words. This allows ``Messages`` to be formatted according to
711 :rfc:`6532` and used with an SMTP server that supports the :rfc:`6531`
712 ``SMTPUTF8`` extension. (Contributed by R. David Murray in :issue:`24211`.)
713
Serhiy Storchakac2edcdd2014-09-11 12:17:37 +0300714glob
715----
716
717* :func:`~glob.iglob` and :func:`~glob.glob` now support recursive search in
718 subdirectories using the "``**``" pattern.
719 (Contributed by Serhiy Storchaka in :issue:`13968`.)
720
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400721heapq
722-----
723
724* :func:`~heapq.merge` has two new optional parameters ``reverse`` and
725 ``key``. (Contributed by Raymond Hettinger in :issue:`13742`.)
726
Guido van Rossum7ca13532015-05-23 15:27:51 -0700727idlelib and IDLE
Terry Jan Reedy44825cf2015-05-23 18:19:42 -0400728----------------
729
730Since idlelib implements the IDLE shell and editor and is not intended for
731import by other programs, it gets improvements with every release. See
732:file:`Lib/idlelib/NEWS.txt` for a cumulative list of changes since 3.4.0,
733as well as changes made in future 3.5.x releases. This file is also available
734from the IDLE Help -> About Idle dialog.
735
Serhiy Storchaka38684c32014-09-09 19:07:49 +0300736imaplib
737-------
738
739* :class:`IMAP4` now supports the context management protocol. When used in a
740 :keyword:`with` statement, the IMAP4 ``LOGOUT`` command will be called
741 automatically at the end of the block. (Contributed by Tarek Ziadé and
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200742 Serhiy Storchaka in :issue:`4972`.)
Serhiy Storchaka38684c32014-09-09 19:07:49 +0300743
R David Murraya6429db2015-05-10 19:17:23 -0400744* :mod:`imaplib` now supports :rfc:`5161`: the :meth:`~imaplib.IMAP4.enable`
745 extension), and :rfc:`6855`: utf-8 support (internationalized email, via the
746 ``UTF8=ACCEPT`` argument to :meth:`~imaplib.IMAP4.enable`). A new attribute,
747 :attr:`~imaplib.IMAP4.utf8_enabled`, tracks whether or not :rfc:`6855`
748 support is enabled. Milan Oberkirch, R. David Murray, and Maciej Szulik in
749 :issue:`21800`.)
750
751* :mod:`imaplib` now automatically encodes non-ASCII string usernames and
752 passwords using ``UTF8``, as recommended by the RFCs. (Contributed by Milan
753 Oberkirch in :issue:`21800`.)
754
R David Murray2f608202014-06-26 12:27:57 -0400755imghdr
756------
757
758* :func:`~imghdr.what` now recognizes the `OpenEXR <http://www.openexr.com>`_
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400759 format (contributed by Martin Vignali and Claudiu Popa in :issue:`20295`),
760 and the `WebP <https://en.wikipedia.org/wiki/WebP>`_ format (contributed
761 by Fabrice Aneche and Claudiu Popa in :issue:`20197`.)
R David Murray2f608202014-06-26 12:27:57 -0400762
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200763importlib
764---------
765
766* :class:`importlib.util.LazyLoader` allows for the lazy loading of modules in
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200767 applications where startup time is paramount.
768 (Contributed by Brett Cannon in :issue:`17621`.)
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200769
770* :func:`importlib.abc.InspectLoader.source_to_code` is now a
771 static method to make it easier to work with source code in a string.
772 With a module object that you want to initialize you can then use
773 ``exec(code, module.__dict__)`` to execute the code in the module.
774
Brett Cannon2a17bde2014-05-30 14:55:29 -0400775* :func:`importlib.util.module_from_spec` is now the preferred way to create a
776 new module. Compared to :class:`types.ModuleType`, this new function will set
777 the various import-controlled attributes based on the passed-in spec object.
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400778 (Contributed by Brett Cannon in :issue:`20383`.)
Brett Cannon2a17bde2014-05-30 14:55:29 -0400779
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200780inspect
781-------
Victor Stinner01adf062014-03-18 00:53:32 +0100782
Yury Selivanova5d63dd2014-03-27 11:31:43 -0400783* :class:`inspect.Signature` and :class:`inspect.Parameter` are now
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200784 picklable and hashable. (Contributed by Yury Selivanov in :issue:`20726`
785 and :issue:`20334`.)
Yury Selivanova5d63dd2014-03-27 11:31:43 -0400786
Yury Selivanovb907a512015-05-16 13:45:09 -0400787* New method :meth:`inspect.BoundArguments.apply_defaults`. (Contributed
788 by Yury Selivanov in :issue:`24190`.)
789
Yury Selivanovda396452014-03-27 12:09:24 -0400790* New class method :meth:`inspect.Signature.from_callable`, which makes
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200791 subclassing of :class:`~inspect.Signature` easier. (Contributed
792 by Yury Selivanov and Eric Snow in :issue:`17373`.)
Yury Selivanovda396452014-03-27 12:09:24 -0400793
Yury Selivanovbcd4fc12015-05-20 14:30:08 -0400794* New argument ``follow_wrapped`` for :func:`inspect.signature`.
795 (Contributed by Yury Selivanov in :issue:`20691`.)
796
Yury Selivanovfdbeb2b2015-07-03 13:11:35 -0400797* New :func:`~inspect.iscoroutine`, :func:`~inspect.iscoroutinefunction`
798 and :func:`~inspect.isawaitable` functions. (Contributed by
799 Yury Selivanov in :issue:`24017`.)
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400800
Yury Selivanov5376ba92015-06-22 12:19:30 -0400801* New :func:`~inspect.getcoroutinelocals` and :func:`~inspect.getcoroutinestate`
802 functions. (Contributed by Yury Selivanov in :issue:`24400`.)
803
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400804* :func:`~inspect.stack`, :func:`~inspect.trace`, :func:`~inspect.getouterframes`,
805 and :func:`~inspect.getinnerframes` now return a list of named tuples.
806 (Contributed by Daniel Shahaf in :issue:`16808`.)
807
Antoine Pitrou0dfce562014-05-15 22:55:40 +0200808ipaddress
809---------
810
811* :class:`ipaddress.IPv4Network` and :class:`ipaddress.IPv6Network` now
812 accept an ``(address, netmask)`` tuple argument, so as to easily construct
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200813 network objects from existing addresses. (Contributed by Peter Moody
814 and Antoine Pitrou in :issue:`16531`.)
Antoine Pitrou0dfce562014-05-15 22:55:40 +0200815
Berker Peksag39e4c4d2014-11-10 09:56:54 +0200816json
817----
818
819* The output of :mod:`json.tool` command line interface is now in the same
820 order as the input. Use the :option:`--sort-keys` option to sort the output
821 of dictionaries alphabetically by key. (Contributed by Berker Peksag in
822 :issue:`21650`.)
823
Serhiy Storchaka47efb4a2015-01-26 13:16:30 +0200824* JSON decoder now raises :exc:`json.JSONDecodeError` instead of
825 :exc:`ValueError`. (Contributed by Serhiy Storchaka in :issue:`19361`.)
826
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400827locale
828------
829
830 * New :func:`~locale.delocalize` function to convert a string into a
831 normalized number string, following the ``LC_NUMERIC`` settings.
832 (Contributed by Cédric Krier in :issue:`13918`.)
833
834logging
835-------
836
837* All logging methods :meth:`~logging.Logger.log`, :meth:`~logging.Logger.exception`,
838 :meth:`~logging.Logger.critical`, :meth:`~logging.Logger.debug`, etc,
839 now accept exception instances for ``exc_info`` parameter, in addition
840 to boolean values and exception tuples.
841 (Contributed by Yury Selivanov in :issue:`20537`.)
842
843* :class:`~logging.handlers.HTTPHandler` now accepts optional
844 :class:`ssl.SSLContext` instance to configure the SSL settings used
845 for HTTP connection.
846 (Contributed by Alex Gaynor in :issue:`22788`.)
847
848lzma
849----
850
851* New option *max_length* for :meth:`~lzma.LZMADecompressor.decompress`
852 to limit the maximum size of decompressed data.
853 (Contributed by Martin Panter in :issue:`15955`.)
854
855
Tal Einatf67b0a32015-05-31 22:18:31 +0300856math
857----
858
859* :data:`math.inf` and :data:`math.nan` constants added. (Contributed by Mark
860 Dickinson in :issue:`23185`.)
861* :func:`math.isclose` function added.
862 (Contributed by Chris Barker and Tal Einat in :issue:`24270`.)
863
Zachary Ware63f277b2014-06-19 09:46:37 -0500864os
865--
866
Victor Stinner37f20342015-03-10 13:29:41 +0100867* New :func:`os.scandir` function that exposes file information from
868 the operating system when listing a directory. :func:`os.scandir`
869 returns an iterator of :class:`os.DirEntry` objects corresponding to
870 the entries in the directory given by *path*. (Contributed by Ben
871 Hoyt with the help of Victor Stinner in :issue:`22524`.)
Victor Stinner6036e442015-03-08 01:58:04 +0100872
Victor Stinnere1d24f72014-07-24 12:44:07 +0200873* :class:`os.stat_result` now has a :attr:`~os.stat_result.st_file_attributes`
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200874 attribute on Windows. (Contributed by Ben Hoyt in :issue:`21719`.)
Zachary Ware63f277b2014-06-19 09:46:37 -0500875
Victor Stinnerace88482015-07-29 02:28:32 +0200876* :func:`os.urandom`: On Linux 3.17 and newer, the ``getrandom()`` syscall is
877 now used when available. On OpenBSD 5.6 and newer, the C ``getentropy()``
878 function is now used. These functions avoid the usage of an internal file
879 descriptor.
880
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400881* New :func:`os.get_blocking` and :func:`os.set_blocking` functions to
882 get and set the blocking mode of file descriptors.
883 (Contributed by Victor Stinner in :issue:`22054`.)
884
Serhiy Storchaka38220932015-03-31 15:31:53 +0300885os.path
886-------
887
888* New :func:`~os.path.commonpath` function that extracts common path prefix.
889 Unlike the :func:`~os.path.commonprefix` function, it always returns a valid
Larry Hastingsd5b129c2015-08-24 12:49:22 -0700890 path. (Contributed by Rafik Draoui and Serhiy Storchaka in :issue:`10395`.)
Serhiy Storchaka38220932015-03-31 15:31:53 +0300891
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400892pathlib
893-------
894
895* New :meth:`~pathlib.Path.samefile` method to check if other path object
896 points to the same file. (Contributed by Vajrasky Kok and Antoine Pitrou
897 in :issue:`19775`.)
898
899* :meth:`~pathlib.Path.mkdir` has a new optional parameter ``exist_ok``
900 to mimic ``mkdir -p`` and :func:`os.makrdirs` functionality.
901 (Contributed by Berker Peksag in :issue:`21539`.)
902
903* New :meth:`~pathlib.Path.expanduser` to expand ``~`` and ``~user``
904 constructs.
905 (Contributed by Serhiy Storchaka and Claudiu Popa in :issue:`19776`.)
906
907* New class method :meth:`~pathlib.Path.home` to get an instance of
908 :class:`~pathlib.Path` object representing the user’s home directory.
909 (Contributed by Victor Salgado and Mayank Tripathi in :issue:`19777`.)
910
Serhiy Storchaka58e41342015-03-31 14:07:24 +0300911pickle
912------
913
914* Serializing more "lookupable" objects (such as unbound methods or nested
915 classes) now are supported with pickle protocols < 4.
916 (Contributed by Serhiy Storchaka in :issue:`23611`.)
917
R David Murrayb8cd3e42015-05-16 15:05:53 -0400918poplib
919------
920
921* A new command :meth:`~poplib.POP3.utf8` enables :rfc:`6856`
922 (internationalized email) support if the POP server supports it. (Contributed
923 by Milan OberKirch in :issue:`21804`.)
924
Serhiy Storchaka9baa5b22014-09-29 22:49:23 +0300925re
926--
927
928* Number of capturing groups in regular expression is no longer limited by 100.
929 (Contributed by Serhiy Storchaka in :issue:`22437`.)
930
Serhiy Storchaka7438e4b2014-10-10 11:06:31 +0300931* Now unmatched groups are replaced with empty strings in :func:`re.sub`
932 and :func:`re.subn`. (Contributed by Serhiy Storchaka in :issue:`1519638`.)
933
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400934readline
935--------
936
937* New :func:`~readline.append_history_file` function.
938 (Contributed by Bruno Cauet in :issue:`22940`.)
939
R David Murray6ffface2014-06-11 14:40:13 -0400940shutil
941------
942
943* :func:`~shutil.move` now accepts a *copy_function* argument, allowing,
944 for example, :func:`~shutil.copy` to be used instead of the default
945 :func:`~shutil.copy2` if there is a need to ignore metadata. (Contributed by
946 Claudiu Popa in :issue:`19840`.)
947
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400948* :func:`~shutil.make_archive` now supports *xztar* format.
949 (Contributed by Serhiy Storchaka in :issue:`5411`.)
950
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200951signal
952------
Brett Cannona04dbe42014-04-04 13:53:38 -0400953
Victor Stinnerbbe38032015-04-01 16:32:32 +0200954* On Windows, :func:`signal.set_wakeup_fd` now also supports socket handles.
955 (Contributed by Victor Stinner in :issue:`22018`.)
956
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200957* Different constants of :mod:`signal` module are now enumeration values using
958 the :mod:`enum` module. This allows meaningful names to be printed during
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200959 debugging, instead of integer “magic numbers”. (Contributed by Giampaolo
960 Rodola' in :issue:`21076`.)
R David Murray1976d9b2014-04-14 20:28:36 -0400961
R David Murray554bcbf2014-06-11 11:18:08 -0400962smtpd
963-----
964
965* Both :class:`~smtpd.SMTPServer` and :class:`smtpd.SMTPChannel` now accept a
966 *decode_data* keyword to determine if the DATA portion of the SMTP
967 transaction is decoded using the ``utf-8`` codec or is instead provided to
968 :meth:`~smtpd.SMTPServer.process_message` as a byte string. The default
969 is ``True`` for backward compatibility reasons, but will change to ``False``
R David Murraya33df312015-05-11 12:11:40 -0400970 in Python 3.6. If *decode_data* is set to ``False``, the
971 :meth:`~smtpd.SMTPServer.process_message` method must be prepared to accept
972 keyword arguments. (Contributed by Maciej Szulik in :issue:`19662`.)
973
974* :class:`~smtpd.SMTPServer` now advertises the ``8BITMIME`` extension
975 (:rfc:`6152`) if if *decode_data* has been set ``True``. If the client
976 specifies ``BODY=8BITMIME`` on the ``MAIL`` command, it is passed to
977 :meth:`~smtpd.SMTPServer.process_message` via the ``mail_options`` keyword.
978 (Contributed by Milan Oberkirch and R. David Murray in :issue:`21795`.)
979
980* :class:`~smtpd.SMTPServer` now supports the ``SMTPUTF8`` extension
981 (:rfc:`6531`: Internationalized Email). If the client specified ``SMTPUTF8
982 BODY=8BITMIME`` on the ``MAIL`` command, they are passed to
983 :meth:`~smtpd.SMTPServer.process_message` via the ``mail_options`` keyword.
984 It is the responsibility of the :meth:`~smtpd.SMTPServer.process_message`
985 method to correctly handle the ``SMTPUTF8`` data. (Contributed by Milan
986 Oberkirch in :issue:`21725`.)
R David Murray554bcbf2014-06-11 11:18:08 -0400987
R David Murray6fe56a32014-06-11 13:48:58 -0400988* It is now possible to provide, directly or via name resolution, IPv6
989 addresses in the :class:`~smtpd.SMTPServer` constructor, and have it
990 successfully connect. (Contributed by Milan Oberkirch in :issue:`14758`.)
991
R David Murray76e13c12014-07-03 14:47:46 -0400992smtplib
993-------
994
995* A new :meth:`~smtplib.SMTP.auth` method provides a convenient way to
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200996 implement custom authentication mechanisms.
997 (Contributed by Milan Oberkirch in :issue:`15014`.)
R David Murray76e13c12014-07-03 14:47:46 -0400998
R David Murray0c49b892015-04-16 17:14:42 -0400999* Additional debuglevel (2) shows timestamps for debug messages in
1000 :class:`smtplib.SMTP`. (Contributed by Gavin Chappell and Maciej Szulik in
1001 :issue:`16914`.)
1002
R David Murray83084442015-05-17 19:27:22 -04001003* :mod:`smtplib` now supports :rfc:`6531` (SMTPUTF8) in both the
1004 :meth:`~smtplib.SMTP.sendmail` and :meth:`~smtplib.SMTP.send_message`
1005 commands. (Contributed by Milan Oberkirch and R. David Murray in
1006 :issue:`22027`.)
R David Murraycee7cf62015-05-16 13:58:14 -04001007
R David Murray4487dd02014-10-09 16:59:30 -04001008sndhdr
1009------
1010
1011* :func:`~sndhdr.what` and :func:`~sndhdr.whathdr` now return
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001012 :func:`~collections.namedtuple`.
1013 (Contributed by Claudiu Popa in :issue:`18615`.)
R David Murray4487dd02014-10-09 16:59:30 -04001014
Victor Stinner287452e2015-07-29 01:39:13 +02001015ssl
1016---
1017
Yury Selivanov7d6adab2015-08-05 19:01:51 -04001018* The :meth:`~ssl.SSLSocket.do_handshake`, :meth:`~ssl.SSLSocket.read`,
1019 :meth:`~ssl.SSLSocket.shutdown`, and :meth:`~ssl.SSLSocket.write` methods of
1020 :class:`ssl.SSLSocket` don't reset the socket timeout anymore each time bytes
1021 are received or sent. The socket timeout is now the maximum total duration of
1022 the method.
1023
1024* Memory BIO Support: new classes :class:`~ssl.SSLObject`,
1025 :class:`~ssl.MemoryBIO`, and new
1026 :meth:`SSLContext.wrap_bio <ssl.SSLContext.wrap_bio>` method.
1027 (Contributed by Geert Jansen in :issue:`21965`.)
Victor Stinner287452e2015-07-29 01:39:13 +02001028
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001029* New :meth:`~ssl.SSLSocket.version` to query the actual protocol version
1030 in use. (Contributed by Antoine Pitrou in :issue:`20421`.)
1031
1032* New :meth:`~ssl.SSLObject.shared_ciphers` and
1033 :meth:`~ssl.SSLSocket.shared_ciphers` methods to fetch the client's
1034 list of ciphers sent at handshake.
1035 (Contributed by Benjamin Peterson in :issue:`23186`.)
1036
Giampaolo Rodola'915d1412014-06-11 03:54:30 +02001037socket
1038------
1039
1040* New :meth:`socket.socket.sendfile` method allows to send a file over a socket
1041 by using high-performance :func:`os.sendfile` function on UNIX resulting in
1042 uploads being from 2x to 3x faster than when using plain
1043 :meth:`socket.socket.send`.
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001044 (Contributed by Giampaolo Rodola' in :issue:`17552`.)
Giampaolo Rodola'915d1412014-06-11 03:54:30 +02001045
Victor Stinner98810132015-07-29 01:41:25 +02001046* The :meth:`socket.socket.sendall` method don't reset the socket timeout
1047 anymore each time bytes are received or sent. The socket timeout is now the
1048 maximum total duration to send all data.
1049
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001050* Functions with timeouts now use a monotonic clock, instead of a
1051 system clock. (Contributed by Victor Stinner in :issue:`22043`.)
1052
Gregory P. Smith6e730002015-04-14 16:14:25 -07001053subprocess
1054----------
1055
1056* The new :func:`subprocess.run` function runs subprocesses and returns a
1057 :class:`subprocess.CompletedProcess` object. It Provides a more consistent
1058 API than :func:`~subprocess.call`, :func:`~subprocess.check_call` and
1059 :func:`~subprocess.check_output`.
1060
Yury Selivanov4640b302015-05-31 17:21:38 -04001061sys
1062---
1063
1064* New :func:`~sys.set_coroutine_wrapper` and :func:`~sys.get_coroutine_wrapper`
1065 functions. (Contributed by Yury Selivanov in :issue:`24017`.)
1066
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001067* New :func:`~sys.is_finalizing` to check for :term:`interpreter shutdown`.
1068 (Contributed by Antoine Pitrou in :issue:`22696`.)
1069
Eric V. Smith7a803892015-04-15 10:27:58 -04001070sysconfig
1071---------
1072
1073* The user scripts directory on Windows is now versioned.
1074 (Contributed by Paul Moore in :issue:`23437`.)
1075
1076tarfile
1077-------
1078
1079* The :func:`tarfile.open` function now supports ``'x'`` (exclusive creation)
1080 mode. (Contributed by Berker Peksag in :issue:`21717`.)
1081
1082* The :meth:`~tarfile.TarFile.extractall` and :meth:`~tarfile.TarFile.extract`
1083 methods now take a keyword parameter *numeric_only*. If set to ``True``,
1084 the extracted files and directories will be owned by the numeric uid and gid
1085 from the tarfile. If set to ``False`` (the default, and the behavior in
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001086 versions prior to 3.5), they will be owned by the named user and group in the
Eric V. Smith7a803892015-04-15 10:27:58 -04001087 tarfile. (Contributed by Michael Vogt and Eric Smith in :issue:`23193`.)
1088
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001089threading
1090---------
1091
1092* :meth:`~threading.Lock.acquire` and :meth:`~threading.RLock.acquire`
1093 now use a monotonic clock for managing timeouts.
1094 (Contributed by Victor Stinner in :issue:`22043`.)
1095
Victor Stinnerae586492014-09-02 23:18:25 +02001096time
1097----
1098
Berker Peksag882c95c2014-10-09 11:46:56 +03001099* The :func:`time.monotonic` function is now always available. (Contributed by
1100 Victor Stinner in :issue:`22043`.)
Victor Stinnerae586492014-09-02 23:18:25 +02001101
Zachary Ware7dc9dea2015-05-22 11:36:53 -05001102tkinter
1103-------
1104
Nick Coghland5cacbb2015-05-23 22:24:10 +10001105* The :mod:`tkinter._fix` module used for setting up the Tcl/Tk environment
Berker Peksag1a90b172015-05-24 00:26:05 +03001106 on Windows has been replaced by a private function in the :mod:`_tkinter`
Zachary Ware7dc9dea2015-05-22 11:36:53 -05001107 module which makes no permanent changes to environment variables.
1108 (Contributed by Zachary Ware in :issue:`20035`.)
1109
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001110traceback
1111---------
1112
1113* New :func:`~traceback.walk_stack` and :func:`~traceback.walk_tb`
1114 functions to conveniently traverse frame and traceback objects.
1115 (Contributed by Robert Collins in :issue:`17911`.)
1116
1117* New lightweight classes: :class:`~traceback.TracebackException`,
1118 :class:`~traceback.StackSummary`, and :class:`traceback.FrameSummary`.
1119 (Contributed by Robert Collins in :issue:`17911`.)
1120
Yury Selivanovf3e40fa2015-05-21 11:50:30 -04001121types
1122-----
1123
1124* New :func:`~types.coroutine` function. (Contributed by Yury Selivanov
1125 in :issue:`24017`.)
1126
Yury Selivanov5376ba92015-06-22 12:19:30 -04001127* New :class:`~types.CoroutineType`. (Contributed by Yury Selivanov
1128 in :issue:`24400`.)
1129
Berker Peksagbd09d7b2015-02-11 15:32:34 +02001130urllib
1131------
Nick Coghlanc216c482014-11-12 23:33:50 +10001132
R David Murray4c7f9952015-04-16 16:36:18 -04001133* A new :class:`~urllib.request.HTTPPasswordMgrWithPriorAuth` allows HTTP Basic
1134 Authentication credentials to be managed so as to eliminate unnecessary
1135 ``401`` response handling, or to unconditionally send credentials
1136 on the first request in order to communicate with servers that return a
1137 ``404`` response instead of a ``401`` if the ``Authorization`` header is not
1138 sent. (Contributed by Matej Cepl in :issue:`19494` and Akshit Khurana in
1139 :issue:`7159`.)
Nick Coghlanc216c482014-11-12 23:33:50 +10001140
R David Murrayc17686f2015-05-17 20:44:50 -04001141* A new :func:`~urllib.parse.urlencode` parameter *quote_via* provides a way to
1142 control the encoding of query parts if needed. (Contributed by Samwyse and
1143 Arnon Yaari in :issue:`13866`.)
1144
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001145* :func:`~urllib.request.urlopen` accepts an :class:`ssl.SSLContext`
1146 object as a *context* argument, which will be used for the HTTPS
1147 connection. (Contributed by Alex Gaynor in :issue:`22366`.)
1148
Benjamin Peterson48013832015-06-27 15:45:56 -05001149unicodedata
1150-----------
1151
1152* The :mod:`unicodedata` module now uses data from `Unicode 8.0.0
Nick Coghlan2ab5b092015-07-03 19:49:15 +10001153 <http://unicode.org/versions/Unicode8.0.0/>`_.
Benjamin Peterson48013832015-06-27 15:45:56 -05001154
1155
Berker Peksag3e887222014-07-02 08:37:22 +03001156wsgiref
1157-------
1158
1159* *headers* parameter of :class:`wsgiref.headers.Headers` is now optional.
1160 (Contributed by Pablo Torres Navarrete and SilentGhost in :issue:`5800`.)
1161
Antoine Pitroub9d9ce72014-05-15 22:47:33 +02001162xmlrpc
1163------
1164
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001165* :class:`xmlrpc.client.ServerProxy` is now a :term:`context manager`.
1166 (Contributed by Claudiu Popa in :issue:`20627`.)
Brett Cannon6eaac132014-05-09 12:28:22 -04001167
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001168* :class:`~xmlrpc.client.ServerProxy` constructor now accepts an optional
1169 :class:`ssl.SSLContext` instance.
1170 (Contributed by Alex Gaynor in :issue:`22960`.)
1171
Serhiy Storchaka61de0872015-04-02 21:00:13 +03001172xml.sax
1173-------
1174
1175* SAX parsers now support a character stream of
1176 :class:`~xml.sax.xmlreader.InputSource` object.
1177 (Contributed by Serhiy Storchaka in :issue:`2175`.)
1178
Victor Stinner95bb7142015-03-12 15:32:03 +01001179faulthandler
1180------------
1181
1182* :func:`~faulthandler.enable`, :func:`~faulthandler.register`,
1183 :func:`~faulthandler.dump_traceback` and
1184 :func:`~faulthandler.dump_traceback_later` functions now accept file
1185 descriptors. (Contributed by Wei Wu in :issue:`23566`.)
1186
Serhiy Storchaka77d89972015-03-23 01:09:35 +02001187zipfile
1188-------
1189
1190* Added support for writing ZIP files to unseekable streams.
1191 (Contributed by Serhiy Storchaka in :issue:`23252`.)
1192
Serhiy Storchaka764fc9b2015-03-25 10:09:41 +02001193* The :func:`zipfile.ZipFile.open` function now supports ``'x'`` (exclusive
1194 creation) mode. (Contributed by Serhiy Storchaka in :issue:`21717`.)
1195
Victor Stinner01adf062014-03-18 00:53:32 +01001196
1197Optimizations
1198=============
1199
Antoine Pitroub9d9ce72014-05-15 22:47:33 +02001200The following performance enhancements have been added:
Victor Stinner01adf062014-03-18 00:53:32 +01001201
Victor Stinner37f20342015-03-10 13:29:41 +01001202* :func:`os.walk` has been sped up by 3-5x on POSIX systems and 7-20x
1203 on Windows. This was done using the new :func:`os.scandir` function,
1204 which exposes file information from the underlying ``readdir`` and
1205 ``FindFirstFile``/``FindNextFile`` system calls. (Contributed by
1206 Ben Hoyt with help from Victor Stinner in :issue:`23605`.)
1207
Brett Cannonf299abd2015-04-13 14:21:02 -04001208* Construction of ``bytes(int)`` (filled by zero bytes) is faster and uses less
Victor Stinner2bc4d952014-06-02 22:22:42 +02001209 memory for large objects. ``calloc()`` is used instead of ``malloc()`` to
Victor Stinnerdb067af2014-05-02 22:31:14 +02001210 allocate memory for these objects.
Victor Stinner01adf062014-03-18 00:53:32 +01001211
Antoine Pitrou0dfce562014-05-15 22:55:40 +02001212* Some operations on :class:`~ipaddress.IPv4Network` and
1213 :class:`~ipaddress.IPv6Network` have been massively sped up, such as
1214 :meth:`~ipaddress.IPv4Network.subnets`, :meth:`~ipaddress.IPv4Network.supernet`,
1215 :func:`~ipaddress.summarize_address_range`, :func:`~ipaddress.collapse_addresses`.
1216 The speed up can range from 3x to 15x.
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001217 (See :issue:`21486`, :issue:`21487`, :issue:`20826`, :issue:`23266`.)
1218
1219* Pickling of :mod:`ipaddress` classes was optimized to produce significantly
1220 smaller output. (Contributed by Serhiy Storchaka in :issue:`23133`.)
Antoine Pitrou0dfce562014-05-15 22:55:40 +02001221
Serhiy Storchaka87d0b452015-02-03 11:30:10 +02001222* Many operations on :class:`io.BytesIO` are now 50% to 100% faster.
Berker Peksag9121fe82015-02-15 00:45:57 +02001223 (Contributed by Serhiy Storchaka in :issue:`15381` and David Wilson in
1224 :issue:`22003`.)
Serhiy Storchaka87d0b452015-02-03 11:30:10 +02001225
Serhiy Storchakac1efe5f2015-02-11 15:54:54 +02001226* :func:`marshal.dumps` is now faster (65%-85% with versions 3--4, 20-25% with
1227 versions 0--2 on typical data, and up to 5x in best cases).
1228 (Contributed by Serhiy Storchaka in :issue:`20416` and :issue:`23344`.)
Serhiy Storchakace921c622015-02-11 15:53:31 +02001229
Serhiy Storchaka0d4df752015-05-12 23:12:45 +03001230* The UTF-32 encoder is now 3x to 7x faster. (Contributed by Serhiy Storchaka
1231 in :issue:`15027`.)
1232
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001233* Regular expressions are now parsed up to 10% faster.
1234 (Contributed by Serhiy Storchaka in :issue:`19380`.)
1235
1236* :func:`json.dumps` was optimized to run with ``ensure_ascii=False``
1237 as fast as with ``ensure_ascii=True``.
1238 (Contributed by Naoki Inada in :issue:`23206`.)
1239
Victor Stinner01adf062014-03-18 00:53:32 +01001240
1241Build and C API Changes
1242=======================
1243
1244Changes to Python's build process and to the C API include:
1245
Victor Stinnerdb067af2014-05-02 22:31:14 +02001246* New ``calloc`` functions:
1247
1248 * :c:func:`PyMem_RawCalloc`
1249 * :c:func:`PyMem_Calloc`
1250 * :c:func:`PyObject_Calloc`
1251 * :c:func:`_PyObject_GC_Calloc`
Victor Stinner01adf062014-03-18 00:53:32 +01001252
Steve Dower313fbf42015-07-17 16:48:48 -07001253* Windows builds now require Microsoft Visual C++ 14.0, which
1254 is available as part of `Visual Studio 2015 <http://www.visualstudio.com>`_.
Victor Stinner01adf062014-03-18 00:53:32 +01001255
1256Deprecated
1257==========
1258
Yury Selivanov8fa6d4f2015-05-28 17:09:14 -04001259New Keywords
1260------------
1261
Yury Selivanov13b74ae2015-08-03 14:55:58 -04001262``async`` and ``await`` are not recommended to be used as variable, class,
1263function or module names. Introduced by :pep:`492` in Python 3.5, they will
1264become proper keywords in Python 3.7.
Yury Selivanov8fa6d4f2015-05-28 17:09:14 -04001265
1266
Victor Stinner01adf062014-03-18 00:53:32 +01001267Unsupported Operating Systems
1268-----------------------------
1269
Zachary Ware38019d12015-04-13 15:51:59 -05001270* Windows XP - Per :PEP:`11`, Microsoft support of Windows XP has ended.
Victor Stinner01adf062014-03-18 00:53:32 +01001271
1272
1273Deprecated Python modules, functions and methods
1274------------------------------------------------
1275
Brett Cannona77d0c32014-03-21 10:52:33 -04001276* The :mod:`formatter` module has now graduated to full deprecation and is still
1277 slated for removal in Python 3.6.
Victor Stinner01adf062014-03-18 00:53:32 +01001278
R David Murray554bcbf2014-06-11 11:18:08 -04001279* :mod:`smtpd` has in the past always decoded the DATA portion of email
1280 messages using the ``utf-8`` codec. This can now be controlled by the new
1281 *decode_data* keyword to :class:`~smtpd.SMTPServer`. The default value is
1282 ``True``, but this default is deprecated. Specify the *decode_data* keyword
1283 with an appropriate value to avoid the deprecation warning.
1284
R David Murray1813c172015-03-29 17:09:21 -04001285* Directly assigning values to the :attr:`~http.cookies.Morsel.key`,
1286 :attr:`~http.cookies.Morsel.value` and
1287 :attr:`~http.cookies.Morsel.coded_value` of :class:`~http.cookies.Morsel`
1288 objects is deprecated. Use the :func:`~http.cookies.Morsel.set` method
1289 instead. In addition, the undocumented *LegalChars* parameter of
1290 :func:`~http.cookies.Morsel.set` is deprecated, and is now ignored.
Serhiy Storchaka9c1a9b22015-03-18 10:59:57 +02001291
Serhiy Storchakab876df42015-03-24 22:30:46 +02001292* Passing a format string as keyword argument *format_string* to the
1293 :meth:`~string.Formatter.format` method of the :class:`string.Formatter`
1294 class has been deprecated.
1295
Berker Peksag2f3742b2015-05-13 12:32:20 +03001296* :func:`platform.dist` and :func:`platform.linux_distribution` functions are
1297 now deprecated and will be removed in Python 3.7. Linux distributions use
1298 too many different ways of describing themselves, so the functionality is
1299 left to a package.
1300 (Contributed by Vajrasky Kok and Berker Peksag in :issue:`1322`.)
Victor Stinner01adf062014-03-18 00:53:32 +01001301
Benjamin Petersonb1cc37c2015-05-20 22:09:43 -05001302* The previously undocumented ``from_function`` and ``from_builtin`` methods of
1303 :class:`inspect.Signature` are deprecated. Use new
Yury Selivanov57c74fc2015-05-20 23:07:02 -04001304 :meth:`inspect.Signature.from_callable` instead. (Contributed by Yury
1305 Selivanov in :issue:`24248`.)
1306
Yury Selivanov945fff42015-05-22 16:28:05 -04001307* :func:`inspect.getargspec` is deprecated and scheduled to be removed in
1308 Python 3.6. (See :issue:`20438` for details.)
1309
1310* :func:`~inspect.getfullargspec`, :func:`~inspect.getargvalues`,
1311 :func:`~inspect.getcallargs`, :func:`~inspect.getargvalues`,
1312 :func:`~inspect.formatargspec`, and :func:`~inspect.formatargvalues` are
1313 deprecated in favor of :func:`inspect.signature` API. (See :issue:`20438`
1314 for details.)
1315
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001316* Use of ``re.LOCALE`` flag with str patterns or ``re.ASCII`` is now
1317 deprecated. (Contributed by Serhiy Storchaka in :issue:`22407`.)
1318
Yury Selivanov945fff42015-05-22 16:28:05 -04001319
Victor Stinner01adf062014-03-18 00:53:32 +01001320Deprecated functions and types of the C API
1321-------------------------------------------
1322
1323* None yet.
1324
1325
1326Deprecated features
1327-------------------
1328
1329* None yet.
1330
1331
R David Murraydf75fee2014-10-03 13:02:47 -04001332Removed
1333=======
1334
Berker Peksag8f791d32014-11-01 10:45:57 +02001335API and Feature Removals
1336------------------------
1337
1338The following obsolete and previously deprecated APIs and features have been
1339removed:
1340
R David Murraydf75fee2014-10-03 13:02:47 -04001341* The ``__version__`` attribute has been dropped from the email package. The
1342 email code hasn't been shipped separately from the stdlib for a long time,
1343 and the ``__version__`` string was not updated in the last few releases.
1344
Berker Peksag8f791d32014-11-01 10:45:57 +02001345* The internal ``Netrc`` class in the :mod:`ftplib` module was deprecated in
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001346 3.4, and has now been removed.
1347 (Contributed by Matt Chaput in :issue:`6623`.)
R David Murraydf75fee2014-10-03 13:02:47 -04001348
Brett Cannonf299abd2015-04-13 14:21:02 -04001349* The concept of ``.pyo`` files has been removed.
1350
R David Murraye81a7732015-04-12 18:47:56 -04001351* The JoinableQueue class in the provisional asyncio module was deprecated
1352 in 3.4.4 and is now removed (:issue:`23464`).
1353
1354
Victor Stinner01adf062014-03-18 00:53:32 +01001355Porting to Python 3.5
1356=====================
1357
1358This section lists previously described changes and other bugfixes
1359that may require changes to your code.
1360
Victor Stinnerdb067af2014-05-02 22:31:14 +02001361Changes in the Python API
1362-------------------------
1363
Victor Stinner6752d652015-07-29 01:11:10 +02001364* :pep:`475`: System calls are now retried when interrupted by a signal instead
1365 of raising :exc:`InterruptedError` if the Python signal handler does not
1366 raise an exception.
Victor Stinnera766ddf2015-03-26 23:50:57 +01001367
Benjamin Petersonee6bdc02014-03-20 18:00:35 -05001368* Before Python 3.5, a :class:`datetime.time` object was considered to be false
1369 if it represented midnight in UTC. This behavior was considered obscure and
1370 error-prone and has been removed in Python 3.5. See :issue:`13936` for full
1371 details.
Antoine Pitrou92c4d452014-04-29 10:05:59 +02001372
1373* :meth:`ssl.SSLSocket.send()` now raises either :exc:`ssl.SSLWantReadError`
1374 or :exc:`ssl.SSLWantWriteError` on a non-blocking socket if the operation
1375 would block. Previously, it would return 0. See :issue:`20951`.
Victor Stinnerdb067af2014-05-02 22:31:14 +02001376
Victor Stinner40ee3012014-06-16 15:59:28 +02001377* The ``__name__`` attribute of generator is now set from the function name,
1378 instead of being set from the code name. Use ``gen.gi_code.co_name`` to
1379 retrieve the code name. Generators also have a new ``__qualname__``
1380 attribute, the qualified name, which is now used for the representation
1381 of a generator (``repr(gen)``). See :issue:`21205`.
1382
Ezio Melotti045160b2014-08-02 18:54:30 +03001383* The deprecated "strict" mode and argument of :class:`~html.parser.HTMLParser`,
1384 :meth:`HTMLParser.error`, and the :exc:`HTMLParserError` exception have been
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001385 removed. (Contributed by Ezio Melotti in :issue:`15114`.)
Ezio Melotti045160b2014-08-02 18:54:30 +03001386 The *convert_charrefs* argument of :class:`~html.parser.HTMLParser` is
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001387 now ``True`` by default. (Contributed by Berker Peksag in :issue:`21047`.)
Ezio Melotti045160b2014-08-02 18:54:30 +03001388
R David Murray861470c2014-10-05 11:47:01 -04001389* Although it is not formally part of the API, it is worth noting for porting
1390 purposes (ie: fixing tests) that error messages that were previously of the
1391 form "'sometype' does not support the buffer protocol" are now of the form "a
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001392 bytes-like object is required, not 'sometype'". (Contributed by Ezio Melotti
1393 in :issue:`16518`.)
R David Murray861470c2014-10-05 11:47:01 -04001394
Brett Cannonb6e25562014-11-21 12:19:28 -05001395* If the current directory is set to a directory that no longer exists then
1396 :exc:`FileNotFoundError` will no longer be raised and instead
1397 :meth:`~importlib.machinery.FileFinder.find_spec` will return ``None``
1398 **without** caching ``None`` in :data:`sys.path_importer_cache` which is
1399 different than the typical case (:issue:`22834`).
1400
Berker Peksag088ca8b2015-02-06 10:17:49 +02001401* HTTP status code and messages from :mod:`http.client` and :mod:`http.server`
1402 were refactored into a common :class:`~http.HTTPStatus` enum. The values in
1403 :mod:`http.client` and :mod:`http.server` remain available for backwards
1404 compatibility. (Contributed by Demian Brecht in :issue:`21793`.)
Serhiy Storchakae4db7692014-12-23 16:28:28 +02001405
Brett Cannon02d84542015-01-09 11:39:21 -05001406* When an import loader defines :meth:`~importlib.machinery.Loader.exec_module`
1407 it is now expected to also define
1408 :meth:`~importlib.machinery.Loader.create_module` (raises a
1409 :exc:`DeprecationWarning` now, will be an error in Python 3.6). If the loader
1410 inherits from :class:`importlib.abc.Loader` then there is nothing to do, else
1411 simply define :meth:`~importlib.machinery.Loader.create_module` to return
1412 ``None`` (:issue:`23014`).
1413
Serhiy Storchaka83e80272015-02-03 11:04:19 +02001414* :func:`re.split` always ignored empty pattern matches, so the ``'x*'``
1415 pattern worked the same as ``'x+'``, and the ``'\b'`` pattern never worked.
1416 Now :func:`re.split` raises a warning if the pattern could match
1417 an empty string. For compatibility use patterns that never match an empty
1418 string (e.g. ``'x+'`` instead of ``'x*'``). Patterns that could only match
1419 an empty string (such as ``'\b'``) now raise an error.
1420
R David Murray1813c172015-03-29 17:09:21 -04001421* The :class:`~http.cookies.Morsel` dict-like interface has been made self
1422 consistent: morsel comparison now takes the :attr:`~http.cookies.Morsel.key`
1423 and :attr:`~http.cookies.Morsel.value` into account,
1424 :meth:`~http.cookies.Morsel.copy` now results in a
R David Murrayba6ea9b2015-03-30 11:48:50 -04001425 :class:`~http.cookies.Morsel` instance rather than a :class:`dict`, and
1426 :meth:`~http.cookies.Morsel.update` will now raise an exception if any of the
R David Murray1813c172015-03-29 17:09:21 -04001427 keys in the update dictionary are invalid. In addition, the undocumented
1428 *LegalChars* parameter of :func:`~http.cookies.Morsel.set` is deprecated and
1429 is now ignored. (:issue:`2211`)
1430
Brett Cannonf299abd2015-04-13 14:21:02 -04001431* :pep:`488` has removed ``.pyo`` files from Python and introduced the optional
1432 ``opt-`` tag in ``.pyc`` file names. The
1433 :func:`importlib.util.cache_from_source` has gained an *optimization*
1434 parameter to help control the ``opt-`` tag. Because of this, the
1435 *debug_override* parameter of the function is now deprecated. `.pyo` files
1436 are also no longer supported as a file argument to the Python interpreter and
1437 thus serve no purpose when distributed on their own (i.e. sourcless code
1438 distribution). Due to the fact that the magic number for bytecode has changed
1439 in Python 3.5, all old `.pyo` files from previous versions of Python are
1440 invalid regardless of this PEP.
1441
Ned Deilycec3f562015-06-10 15:43:05 -07001442* The :mod:`socket` module now exports the CAN_RAW_FD_FRAMES constant on linux
1443 3.6 and greater.
Larry Hastingsa6cc5512015-04-13 17:48:40 -04001444
Zachary Ware3d3aedc2015-07-07 00:07:25 -05001445* The ``pygettext.py`` Tool now uses the standard +NNNN format for timezones in
R David Murray2b781292015-04-16 12:15:09 -04001446 the POT-Creation-Date header.
1447
R David Murray0c49b892015-04-16 17:14:42 -04001448* The :mod:`smtplib` module now uses :data:`sys.stderr` instead of previous
1449 module level :data:`stderr` variable for debug output. If your (test)
1450 program depends on patching the module level variable to capture the debug
1451 output, you will need to update it to capture sys.stderr instead.
1452
Serhiy Storchakad4ea03c2015-05-31 09:15:51 +03001453* The :meth:`str.startswith` and :meth:`str.endswith` methods no longer return
1454 ``True`` when finding the empty string and the indexes are completely out of
1455 range. See :issue:`24284`.
1456
Berker Peksag4333d8b2015-07-30 18:06:09 +03001457* The :func:`inspect.getdoc` function now returns documentation strings
1458 inherited from base classes. Documentation strings no longer need to be
1459 duplicated if the inherited documentation is appropriate. To suppress an
1460 inherited string, an empty string must be specified (or the documentation
1461 may be filled in). This change affects the output of the :mod:`pydoc`
1462 module and the :func:`help` function. See :issue:`15582`.
1463
Victor Stinnerdb067af2014-05-02 22:31:14 +02001464Changes in the C API
1465--------------------
1466
Stefan Krahf5324d72015-01-29 14:29:51 +01001467* The undocumented :c:member:`~PyMemoryViewObject.format` member of the
1468 (non-public) :c:type:`PyMemoryViewObject` structure has been removed.
1469
1470 All extensions relying on the relevant parts in ``memoryobject.h``
1471 must be rebuilt.
1472
Victor Stinnerd8f0d922014-06-02 21:57:10 +02001473* The :c:type:`PyMemAllocator` structure was renamed to
1474 :c:type:`PyMemAllocatorEx` and a new ``calloc`` field was added.
Serhiy Storchakadf4518c2014-11-18 23:34:33 +02001475
1476* Removed non-documented macro :c:macro:`PyObject_REPR` which leaked references.
1477 Use format character ``%R`` in :c:func:`PyUnicode_FromFormat`-like functions
1478 to format the :func:`repr` of the object.
Serhiy Storchaka490055a2015-03-01 10:03:02 +02001479
1480* Because the lack of the :attr:`__module__` attribute breaks pickling and
1481 introspection, a deprecation warning now is raised for builtin type without
1482 the :attr:`__module__` attribute. Would be an AttributeError in future.
1483 (:issue:`20204`)
Yury Selivanov50960882015-05-12 00:15:05 -04001484
Yury Selivanov5376ba92015-06-22 12:19:30 -04001485* As part of :pep:`492` implementation, ``tp_reserved`` slot of
Yury Selivanovf3e40fa2015-05-21 11:50:30 -04001486 :c:type:`PyTypeObject` was replaced with a
Yury Selivanov27947d52015-06-23 15:09:58 -04001487 :c:member:`tp_as_async` slot. Refer to :ref:`coro-objects` for
Yury Selivanov5376ba92015-06-22 12:19:30 -04001488 new types, structures and functions.