blob: c2e0251fb34abc249e1bf40f7722038607f68170 [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|
7
Yury Selivanovdfcfe132015-09-08 15:33:15 -04008:Author: Elvis Pranskevichus <elprans@gmail.com> (Editor)
9
Victor Stinner01adf062014-03-18 00:53:32 +010010.. Rules for maintenance:
11
12 * Anyone can add text to this document. Do not spend very much time
13 on the wording of your changes, because your text will probably
14 get rewritten to some degree.
15
16 * The maintainer will go through Misc/NEWS periodically and add
17 changes; it's therefore more important to add your changes to
18 Misc/NEWS than to this file.
19
20 * This is not a complete list of every single change; completeness
21 is the purpose of Misc/NEWS. Some changes I consider too small
22 or esoteric to include. If such a change is added to the text,
23 I'll just remove it. (This is another reason you shouldn't spend
24 too much time on writing your addition.)
25
26 * If you want to draw your new text to the attention of the
27 maintainer, add 'XXX' to the beginning of the paragraph or
28 section.
29
30 * It's OK to just add a fragmentary note about a change. For
31 example: "XXX Describe the transmogrify() function added to the
32 socket module." The maintainer will research the change and
33 write the necessary text.
34
35 * You can comment out your additions if you like, but it's not
36 necessary (especially when a final release is some months away).
37
38 * Credit the author of a patch or bugfix. Just the name is
39 sufficient; the e-mail address isn't necessary.
40
41 * It's helpful to add the bug/patch number as a comment:
42
43 XXX Describe the transmogrify() function added to the socket
44 module.
45 (Contributed by P.Y. Developer in :issue:`12345`.)
46
47 This saves the maintainer the effort of going through the Mercurial log
48 when researching a change.
49
50This article explains the new features in Python 3.5, compared to 3.4.
51
52For full details, see the :source:`Misc/NEWS` file.
53
Benjamin Peterson52d14932015-03-27 16:07:35 -040054.. note::
55
56 Prerelease users should be aware that this document is currently in draft
57 form. It will be updated substantially as Python 3.5 moves towards release,
58 so it's worth checking back even after reading earlier versions.
Victor Stinner01adf062014-03-18 00:53:32 +010059
60
61.. seealso::
62
Berker Peksagfa0423b2014-10-09 11:38:19 +030063 :pep:`478` - Python 3.5 Release Schedule
Victor Stinner01adf062014-03-18 00:53:32 +010064
65
66Summary -- Release highlights
67=============================
68
Victor Stinner93692bb2015-03-30 15:04:45 +020069.. This section singles out the most important changes in Python 3.5.
Victor Stinner01adf062014-03-18 00:53:32 +010070 Brevity is key.
71
72New syntax features:
73
Benjamin Peterson14ef1a12015-05-13 11:19:27 -040074* :pep:`465`, a new matrix multiplication operator: ``a @ b``.
75* :pep:`492`, coroutines with async and await syntax.
Yury Selivanova5a00622015-08-04 12:52:16 -040076* :pep:`448`, additional unpacking generalizations.
Victor Stinner01adf062014-03-18 00:53:32 +010077
78New library modules:
79
Brett Cannoncc4dfc12015-03-13 10:40:49 -040080* :mod:`zipapp`: :ref:`Improving Python ZIP Application Support
81 <whatsnew-zipapp>` (:pep:`441`).
Victor Stinner01adf062014-03-18 00:53:32 +010082
83New built-in features:
84
Victor Stinner93692bb2015-03-30 15:04:45 +020085* ``bytes % args``, ``bytearray % args``: :pep:`461` - Adding ``%`` formatting
86 to bytes and bytearray
Gregory P. Smith8cb65692015-04-25 23:22:26 +000087* ``b'\xf0\x9f\x90\x8d'.hex()``, ``bytearray(b'\xf0\x9f\x90\x8d').hex()``,
88 ``memoryview(b'\xf0\x9f\x90\x8d').hex()``: :issue:`9951` - A ``hex`` method
89 has been added to bytes, bytearray, and memoryview.
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 Selivanovf488fb42015-07-03 01:04:23 -040093* New :exc:`RecursionError` exception. (Contributed by Georg Brandl
94 in :issue:`19235`.)
Victor Stinner01adf062014-03-18 00:53:32 +010095
96Implementation improvements:
97
Victor Stinner71430292014-03-18 01:18:21 +010098* When the ``LC_TYPE`` locale is the POSIX locale (``C`` locale),
99 :py:data:`sys.stdin` and :py:data:`sys.stdout` are now using the
100 ``surrogateescape`` error handler, instead of the ``strict`` error handler
101 (:issue:`19977`).
Victor Stinner01adf062014-03-18 00:53:32 +0100102
Brett Cannonf299abd2015-04-13 14:21:02 -0400103* :pep:`488`, the elimination of ``.pyo`` files.
Nick Coghland5cacbb2015-05-23 22:24:10 +1000104* :pep:`489`, multi-phase initialization of extension modules.
Brett Cannonf299abd2015-04-13 14:21:02 -0400105
Victor Stinner01adf062014-03-18 00:53:32 +0100106Significantly Improved Library Modules:
107
Yury Selivanov58444362015-05-30 10:49:09 -0400108* :class:`collections.OrderedDict` is now implemented in C, which improves
109 its performance between 4x to 100x times. Contributed by Eric Snow in
110 :issue:`16991`.
111
Gregory P. Smithad577b92015-05-22 16:18:14 -0700112* You may now pass bytes to the :mod:`tempfile` module's APIs and it will
113 return the temporary pathname as bytes instead of str. It also accepts
114 a value of ``None`` on parameters where only str was accepted in the past to
115 do the right thing based on the types of the other inputs. Two functions,
116 :func:`gettempdirb` and :func:`gettempprefixb`, have been added to go along
117 with this. This behavior matches that of the :mod:`os` APIs.
Victor Stinner01adf062014-03-18 00:53:32 +0100118
Yury Selivanov7d6adab2015-08-05 19:01:51 -0400119* :mod:`ssl` module gained support for Memory BIO, which decouples SSL
120 protocol handling from network IO. (Contributed by Geert Jansen in
121 :issue:`21965`.)
122
Victor Stinner01adf062014-03-18 00:53:32 +0100123Security improvements:
124
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400125* SSLv3 is now disabled throughout the standard library.
126 It can still be enabled by instantiating a :class:`ssl.SSLContext`
127 manually. (See :issue:`22638` for more details; this change was
128 backported to CPython 3.4 and 2.7.)
129
130* HTTP cookie parsing is now stricter, in order to protect
131 against potential injection attacks. (Contributed by Antoine Pitrou
132 in :issue:`22796`.)
Victor Stinner01adf062014-03-18 00:53:32 +0100133
Steve Dower313fbf42015-07-17 16:48:48 -0700134Windows improvements:
135
136* A new installer for Windows has replaced the old MSI. See :ref:`using-on-windows`
137 for more information.
138* Windows builds now use Microsoft Visual C++ 14.0, and extension modules
139 should use the same.
140
141
Victor Stinner01adf062014-03-18 00:53:32 +0100142Please read on for a comprehensive list of user-facing changes.
143
144
145.. PEP-sized items next.
146
147.. _pep-4XX:
148
149.. PEP 4XX: Virtual Environments
150.. =============================
151
152
153.. (Implemented by Foo Bar.)
154
155.. .. seealso::
156
157 :pep:`4XX` - Python Virtual Environments
158 PEP written by Carl Meyer
159
160
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400161New Features
162============
163
164.. _whatsnew-pep-492:
165
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400166PEP 492 - Coroutines with async and await syntax
167------------------------------------------------
168
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400169:pep:`492` greatly improves support for asynchronous programming in Python
170by adding :term:`awaitable objects <awaitable>`,
171:term:`coroutine functions <coroutine function>`,
172:term:`asynchronous iteration <asynchronous iterable>`,
173and :term:`asynchronous context managers <asynchronous context manager>`.
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400174
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400175Coroutine functions are declared using the new :keyword:`async def` syntax::
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400176
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400177 >>> async def coro():
178 ... return 'spam'
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400179
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400180Inside a coroutine function, a new :keyword:`await` expression can be used
181to suspend coroutine execution until the result is available. Any object
182can be *awaited*, as long as it implements the :term:`awaitable` protocol by
183defining the :meth:`__await__` method.
184
185PEP 492 also adds :keyword:`async for` statement for convenient iteration
186over asynchronous iterables.
187
188An example of a simple HTTP client written using the new syntax::
189
190 import asyncio
191
192 async def http_get(domain):
193 reader, writer = await asyncio.open_connection(domain, 80)
194
195 writer.write(b'\r\n'.join([
196 b'GET / HTTP/1.1',
197 b'Host: %b' % domain.encode('latin-1'),
198 b'Connection: close',
199 b'', b''
200 ]))
201
202 async for line in reader:
203 print('>>>', line)
204
205 writer.close()
206
207 loop = asyncio.get_event_loop()
208 try:
209 loop.run_until_complete(http_get('example.com'))
210 finally:
211 loop.close()
212
213
214Similarly to asynchronous iteration, there is a new syntax for asynchronous
215context managers::
216
217 >>> import asyncio
218 >>> async def coro1(lock):
219 ... print('coro1: waiting for lock')
220 ... async with lock:
221 ... print('coro1: holding the lock')
222 ... await asyncio.sleep(1)
223 ... print('coro1: releasing the lock')
224 ...
225 >>> async def coro2(lock):
226 ... print('coro2: waiting for lock')
227 ... async with lock:
228 ... print('coro2: holding the lock')
229 ... await asyncio.sleep(1)
230 ... print('coro2: releasing the lock')
231 ...
232 >>> loop = asyncio.get_event_loop()
233 >>> lock = asyncio.Lock()
234 >>> coros = asyncio.gather(coro1(lock), coro2(lock), loop=loop)
235 >>> loop.run_until_complete(coros)
236 coro1: waiting for lock
237 coro1: holding the lock
238 coro2: waiting for lock
239 coro1: releasing the lock
240 coro2: holding the lock
241 coro2: releasing the lock
242 >>> loop.close()
243
244Note that both :keyword:`async for` and :keyword:`async with` can only
245be used inside a coroutine function declared with :keyword:`async def`.
246
247Coroutine functions are intended to be ran inside a compatible event loop,
248such as :class:`asyncio.Loop`.
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400249
250.. seealso::
251
252 :pep:`492` -- Coroutines with async and await syntax
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400253 PEP written and implemented by Yury Selivanov.
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400254
255
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400256PEP 465 - A dedicated infix operator for matrix multiplication
257--------------------------------------------------------------
Victor Stinner93692bb2015-03-30 15:04:45 +0200258
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400259:pep:`465` adds the ``@`` infix operator for matrix multiplication.
260Currently, no builtin Python types implement the new operator, however, it
261can be implemented by defining :meth:`__matmul__`, :meth:`__rmatmul__`,
262and :meth:`__imatmul__` for regular, reflected, and in-place matrix
263multiplication. The semantics of these methods is similar to that of
264methods defining other infix arithmetic operators.
265
266Matrix multiplication is a notably common operation in many fields of
267mathematics, science, engineering, and the addition of ``@`` allows writing
268cleaner code::
269
270 >>> S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r)
271
272An upcoming release of NumPy 1.10 will add support for the new operator::
273
274 >>> import numpy
275
276 >>> x = numpy.ones(3)
277 >>> x
278 array([ 1., 1., 1.])
279
280 >>> m = numpy.eye(3)
281 >>> m
282 array([[ 1., 0., 0.],
283 [ 0., 1., 0.],
284 [ 0., 0., 1.]])
285
286 >>> x @ m
287 array([ 1., 1., 1.])
288
289
290.. seealso::
291
292 :pep:`465` -- A dedicated infix operator for matrix multiplication
293 PEP written by Nathaniel J. Smith; implemented by Benjamin Peterson.
294
295
296PEP 448 - Additional Unpacking Generalizations
297----------------------------------------------
298
299:pep:`448` extends the allowed uses of the ``*`` iterable unpacking
300operator and ``**`` dictionary unpacking operator. It is now possible
301to use an arbitrary number of unpackings in function calls::
302
303 >>> print(*[1], *[2], 3, *[4, 5])
304 1 2 3 4 5
305
306 >>> def fn(a, b, c, d):
307 ... print(a, b, c, d)
308 ...
309
310 >>> fn(**{'a': 1, 'c': 3}, **{'b': 2, 'd': 4})
311 1 2 3 4
312
313Similarly, tuple, list, set, and dictionary displays allow multiple
314unpackings::
315
316 >>> *range(4), 4
317 (0, 1, 2, 3, 4)
318 >>> [*range(4), 4]
319 [0, 1, 2, 3, 4]
320 >>> {*range(4), 4, *(5, 6, 7)}
321 {0, 1, 2, 3, 4, 5, 6, 7}
322 >>> {'x': 1, **{'y': 2}}
323 {'x': 1, 'y': 2}
324
325.. seealso::
326
327 :pep:`448` -- Additional Unpacking Generalizations
328 PEP written by Joshua Landau; implemented by Neil Girdhar,
329 Thomas Wouters, and Joshua Landau.
330
331
332PEP 461 - % formatting support for bytes and bytearray
333------------------------------------------------------
334
335PEP 461 adds % formatting to :class:`bytes` and :class:`bytearray`, aiding in
336handling data that is a mixture of binary and ASCII compatible text. This
337feature also eases porting such code from Python 2.
Victor Stinner93692bb2015-03-30 15:04:45 +0200338
339Examples::
340
341 >>> b'Hello %s!' % b'World'
342 b'Hello World!'
343 >>> b'x=%i y=%f' % (1, 2.5)
344 b'x=1 y=2.500000'
345
346Unicode is not allowed for ``%s``, but it is accepted by ``%a`` (equivalent of
347``repr(obj).encode('ascii', 'backslashreplace')``)::
348
349 >>> b'Hello %s!' % 'World'
350 Traceback (most recent call last):
351 File "<stdin>", line 1, in <module>
352 TypeError: %b requires bytes, or an object that implements __bytes__, not 'str'
353 >>> b'price: %a' % '10€'
354 b"price: '10\\u20ac'"
355
356.. seealso::
357
358 :pep:`461` -- Adding % formatting to bytes and bytearray
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400359 PEP written by Ethan Furman; implemented by Neil Schemenauer and
360 Ethan Furman.
Yury Selivanov216d9992015-08-04 12:42:20 -0400361
362
Yury Selivanov5df36af2015-08-04 12:46:57 -0400363PEP 484 - Type Hints
364--------------------
365
366This PEP introduces a provisional module to provide these standard
367definitions and tools, along with some conventions for situations
368where annotations are not available.
369
370For example, here is a simple function whose argument and return type
371are declared in the annotations::
372
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400373 def greeting(name: str) -> str:
374 return 'Hello ' + name
Yury Selivanov5df36af2015-08-04 12:46:57 -0400375
376The type system supports unions, generic types, and a special type
377named ``Any`` which is consistent with (i.e. assignable to and from) all
378types.
379
380.. seealso::
381
Yury Selivanov40c0ce42015-08-05 12:46:29 -0400382 * :mod:`typing` module documentation
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400383 * :pep:`484` -- Type Hints
384 PEP written by Guido van Rossum, Jukka Lehtosalo, and Łukasz Langa;
385 implemented by Guido van Rossum.
Yury Selivanov5df36af2015-08-04 12:46:57 -0400386
387
Victor Stinner6036e442015-03-08 01:58:04 +0100388PEP 471 - os.scandir() function -- a better and faster directory iterator
389-------------------------------------------------------------------------
390
Victor Stinner37f20342015-03-10 13:29:41 +0100391:pep:`471` adds a new directory iteration function, :func:`os.scandir`,
392to the standard library. Additionally, :func:`os.walk` is now
393implemented using :func:`os.scandir`, which speeds it up by 3-5 times
394on POSIX systems and by 7-20 times on Windows systems.
395
Victor Stinner6036e442015-03-08 01:58:04 +0100396.. seealso::
397
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400398 :pep:`471` -- os.scandir() function -- a better and faster directory iterator
399 PEP written and implemented by Ben Hoyt with the help of Victor Stinner.
Victor Stinner6036e442015-03-08 01:58:04 +0100400
401
Charles-François Natali6e6c59b2015-02-07 13:27:50 +0000402PEP 475: Retry system calls failing with EINTR
403----------------------------------------------
404
Victor Stinnerf70e1ca2015-03-30 21:16:11 +0200405:pep:`475` adds support for automatic retry of system calls failing with
406:py:data:`~errno.EINTR`: this means that user code doesn't have to deal with
407EINTR or :exc:`InterruptedError` manually, and should make it more robust
408against asynchronous signal reception.
Charles-François Natali6e6c59b2015-02-07 13:27:50 +0000409
Victor Stinner6752d652015-07-29 01:11:10 +0200410Examples of functions which are now retried when interrupted by a signal
411instead of raising :exc:`InterruptedError` if the Python signal handler does
412not raise an exception:
413
414* :func:`open`, :func:`os.open`, :func:`io.open`
415* functions of the :mod:`faulthandler` module
416* :mod:`os` functions:
417
418 - :func:`os.fchdir`
419 - :func:`os.fchmod`
420 - :func:`os.fchown`
421 - :func:`os.fdatasync`
422 - :func:`os.fstat`
423 - :func:`os.fstatvfs`
424 - :func:`os.fsync`
425 - :func:`os.ftruncate`
426 - :func:`os.mkfifo`
427 - :func:`os.mknod`
428 - :func:`os.posix_fadvise`
429 - :func:`os.posix_fallocate`
430 - :func:`os.pread`
431 - :func:`os.pwrite`
432 - :func:`os.read`
433 - :func:`os.readv`
434 - :func:`os.sendfile`
435 - :func:`os.wait3`
436 - :func:`os.wait4`
437 - :func:`os.wait`
438 - :func:`os.waitid`
439 - :func:`os.waitpid`
440 - :func:`os.write`
441 - :func:`os.writev`
442 - special cases: :func:`os.close` and :func:`os.dup2` now ignore
443 :py:data:`~errno.EINTR` error, the syscall is not retried (see the PEP
444 for the rationale)
445
446* :mod:`select` functions:
447
448 - :func:`select.devpoll.poll`
449 - :func:`select.epoll.poll`
450 - :func:`select.kqueue.control`
451 - :func:`select.poll.poll`
452 - :func:`select.select`
453
454* :func:`socket.socket` methods:
455
456 - :meth:`~socket.socket.accept`
457 - :meth:`~socket.socket.connect` (except for non-blocking sockets)
458 - :meth:`~socket.socket.recv`
459 - :meth:`~socket.socket.recvfrom`
460 - :meth:`~socket.socket.recvmsg`
461 - :meth:`~socket.socket.send`
462 - :meth:`~socket.socket.sendall`
463 - :meth:`~socket.socket.sendmsg`
464 - :meth:`~socket.socket.sendto`
465
466* :func:`signal.sigtimedwait`, :func:`signal.sigwaitinfo`
467* :func:`time.sleep`
468
Charles-François Natali6e6c59b2015-02-07 13:27:50 +0000469.. seealso::
470
471 :pep:`475` -- Retry system calls failing with EINTR
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400472 PEP and implementation written by Charles-François Natali and
473 Victor Stinner, with the help of Antoine Pitrou (the french connection).
Victor Stinner01adf062014-03-18 00:53:32 +0100474
475
Yury Selivanov8d006e72015-05-22 11:30:45 -0400476PEP 479: Change StopIteration handling inside generators
477--------------------------------------------------------
478
479:pep:`479` changes the behavior of generators: when a :exc:`StopIteration`
480exception is raised inside a generator, it is replaced with a
481:exc:`RuntimeError`. To enable the feature a ``__future__`` import should
482be used::
483
484 from __future__ import generator_stop
485
486Without a ``__future__`` import, a :exc:`PendingDeprecationWarning` will be
487raised.
488
Yury Selivanov8d006e72015-05-22 11:30:45 -0400489.. seealso::
490
491 :pep:`479` -- Change StopIteration handling inside generators
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400492 PEP written by Chris Angelico and Guido van Rossum. Implemented by
493 Chris Angelico, Yury Selivanov and Nick Coghlan.
Yury Selivanov8d006e72015-05-22 11:30:45 -0400494
495
Steve Dower76998fe2015-02-26 14:25:33 -0800496PEP 486: Make the Python Launcher aware of virtual environments
497---------------------------------------------------------------
498
499:pep:`486` makes the Windows launcher (see :pep:`397`) aware of an active
500virtual environment. When the default interpreter would be used and the
501``VIRTUAL_ENV`` environment variable is set, the interpreter in the virtual
502environment will be used.
503
504.. seealso::
505
506 :pep:`486` -- Make the Python Launcher aware of virtual environments
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400507 PEP written and implemented by Paul Moore.
Steve Dower76998fe2015-02-26 14:25:33 -0800508
Brett Cannonf299abd2015-04-13 14:21:02 -0400509
510PEP 488: Elimination of PYO files
511---------------------------------
512
513:pep:`488` does away with the concept of ``.pyo`` files. This means that
Benjamin Petersone3283232015-05-26 21:40:28 -0500514``.pyc`` files represent both unoptimized and optimized bytecode. To prevent the
515need to constantly regenerate bytecode files, ``.pyc`` files now have an
516optional ``opt-`` tag in their name when the bytecode is optimized. This has the
517side-effect of no more bytecode file name clashes when running under either
518``-O`` or ``-OO``. Consequently, bytecode files generated from ``-O``, and
519``-OO`` may now exist simultaneously. :func:`importlib.util.cache_from_source`
520has an updated API to help with this change.
Brett Cannonf299abd2015-04-13 14:21:02 -0400521
522.. seealso::
523
524 :pep:`488` -- Elimination of PYO files
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400525 PEP written and implemented by Brett Cannon.
Brett Cannonf299abd2015-04-13 14:21:02 -0400526
527
Nick Coghland5cacbb2015-05-23 22:24:10 +1000528PEP 489: Multi-phase extension module initialization
529----------------------------------------------------
530
531:pep:`489` updates extension module initialization to take advantage of the
532two step module loading mechanism introduced by :pep:`451` in Python 3.4.
533
534This change brings the import semantics of extension modules that opt-in to
535using the new mechanism much closer to those of Python source and bytecode
Nick Coghlan2ab5b092015-07-03 19:49:15 +1000536modules, including the ability to use any valid identifier as a module name,
Nick Coghland5cacbb2015-05-23 22:24:10 +1000537rather than being restricted to ASCII.
538
539.. seealso::
540
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400541 :pep:`489` -- Multi-phase extension module initialization
542 PEP written by Petr Viktorin, Stefan Behnel, and Nick Coghlan;
543 implementation by Petr Viktorin.
544
Nick Coghland5cacbb2015-05-23 22:24:10 +1000545
Tal Einatd5519ed2015-05-31 22:05:00 +0300546PEP 485: A function for testing approximate equality
547----------------------------------------------------
548
549:pep:`485` adds the :func:`math.isclose` and :func:`cmath.isclose`
550functions which tell whether two values are approximately equal or
551"close" to each other. Whether or not two values are considered
552close is determined according to given absolute and relative tolerances.
553
554.. seealso::
555
556 :pep:`485` -- A function for testing approximate equality
Yury Selivanovdfcfe132015-09-08 15:33:15 -0400557 PEP written by Christopher Barker; implemented by Chris Barker and
558 Tal Einat.
559
Tal Einatd5519ed2015-05-31 22:05:00 +0300560
Victor Stinner01adf062014-03-18 00:53:32 +0100561Other Language Changes
562======================
563
564Some smaller changes made to the core Python language are:
565
Serhiy Storchaka07985ef2015-01-25 22:56:57 +0200566* Added the ``'namereplace'`` error handlers. The ``'backslashreplace'``
567 error handlers now works with decoding and translating.
568 (Contributed by Serhiy Storchaka in :issue:`19676` and :issue:`22286`.)
Victor Stinner01adf062014-03-18 00:53:32 +0100569
Serhiy Storchaka1dd49822015-03-20 16:54:57 +0200570* The :option:`-b` option now affects comparisons of :class:`bytes` with
571 :class:`int`. (Contributed by Serhiy Storchaka in :issue:`23681`)
Victor Stinner01adf062014-03-18 00:53:32 +0100572
Serhiy Storchakaad8a1c32015-05-12 23:16:55 +0300573* New Kazakh :ref:`codec <standard-encodings>` ``kz1048``. (Contributed by
574 Serhiy Storchaka in :issue:`22682`.)
575
Raymond Hettingereac503a2015-05-13 01:09:59 -0700576* Property docstrings are now writable. This is especially useful for
577 :func:`collections.namedtuple` docstrings.
578 (Contributed by Berker Peksag in :issue:`24064`.)
579
Serhiy Storchakaf0eeedf2015-05-12 23:24:19 +0300580* New Tajik :ref:`codec <standard-encodings>` ``koi8_t``. (Contributed by
581 Serhiy Storchaka in :issue:`22681`.)
582
Victor Stinner01adf062014-03-18 00:53:32 +0100583
584New Modules
585===========
586
Brett Cannoncc4dfc12015-03-13 10:40:49 -0400587.. _whatsnew-zipapp:
Victor Stinner01adf062014-03-18 00:53:32 +0100588
Brett Cannoncc4dfc12015-03-13 10:40:49 -0400589zipapp
590------
591
592The new :mod:`zipapp` module (specified in :pep:`441`) provides an API and
593command line tool for creating executable Python Zip Applications, which
594were introduced in Python 2.6 in :issue:`1739468` but which were not well
595publicised, either at the time or since.
596
597With the new module, bundling your application is as simple as putting all
598the files, including a ``__main__.py`` file, into a directory ``myapp``
599and running::
600
601 $ python -m zipapp myapp
602 $ python myapp.pyz
Victor Stinner01adf062014-03-18 00:53:32 +0100603
604
605Improved Modules
606================
607
Berker Peksag8089cd62015-02-14 01:39:17 +0200608argparse
609--------
610
611* :class:`~argparse.ArgumentParser` now allows to disable
612 :ref:`abbreviated usage <prefix-matching>` of long options by setting
613 :ref:`allow_abbrev` to ``False``.
614 (Contributed by Jonathan Paugh, Steven Bethard, paul j3 and Daniel Eriksson.)
615
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400616bz2
617---
618
619* New option *max_length* for :meth:`~bz2.BZ2Decompressor.decompress`
620 to limit the maximum size of decompressed data.
621 (Contributed by Nikolaus Rath in :issue:`15955`.)
622
Berker Peksagbf5e9602015-02-06 10:21:37 +0200623cgi
624---
625
Berker Peksagbd09d7b2015-02-11 15:32:34 +0200626* :class:`~cgi.FieldStorage` now supports the context management protocol.
Berker Peksagbf5e9602015-02-06 10:21:37 +0200627 (Contributed by Berker Peksag in :issue:`20289`.)
628
Tal Einatd5519ed2015-05-31 22:05:00 +0300629cmath
630-----
631
632* :func:`cmath.isclose` function added.
633 (Contributed by Chris Barker and Tal Einat in :issue:`24270`.)
634
635
R David Murrayc31e6222014-09-29 11:25:00 -0400636code
637----
638
639* The :func:`code.InteractiveInterpreter.showtraceback` method now prints
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200640 the full chained traceback, just like the interactive interpreter.
Berker Peksag088ca8b2015-02-06 10:17:49 +0200641 (Contributed by Claudiu Popa in :issue:`17442`.)
R David Murrayc31e6222014-09-29 11:25:00 -0400642
Raymond Hettingereac503a2015-05-13 01:09:59 -0700643collections
644-----------
645
646* You can now update docstrings produced by :func:`collections.namedtuple`::
647
648 Point = namedtuple('Point', ['x', 'y'])
649 Point.__doc__ = 'ordered pair'
650 Point.x.__doc__ = 'abscissa'
651 Point.y.__doc__ = 'ordinate'
652
653 (Contributed by Berker Peksag in :issue:`24064`.)
654
Brett Cannonf1a8df02014-09-12 10:39:48 -0400655compileall
656----------
657
658* :func:`compileall.compile_dir` and :mod:`compileall`'s command-line interface
659 can now do parallel bytecode compilation.
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200660 (Contributed by Claudiu Popa in :issue:`16104`.)
Brett Cannonf1a8df02014-09-12 10:39:48 -0400661
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400662* *quiet* parameter of :func:`compileall.compile_dir`,
663 :func:`compileall.compile_file`, and :func:`compileall.compile_path`
664 functions now has a multilevel value. New ``-qq`` command line option
665 is available for suppressing the output.
666 (Contributed by Thomas Kluyver in :issue:`21338`.)
667
668concurrent.futures
669------------------
670
671* :meth:`~concurrent.futures.Executor.map` now takes a *chunksize*
672 argument to allow batching of tasks in child processes and improve
673 performance of ProcessPoolExecutor.
674 (Contributed by Dan O'Reilly in :issue:`11271`.)
675
Berker Peksagbb44fe02014-11-28 23:28:06 +0200676contextlib
677----------
678
679* The new :func:`contextlib.redirect_stderr` context manager(similar to
680 :func:`contextlib.redirect_stdout`) makes it easier for utility scripts to
681 handle inflexible APIs that write their output to :data:`sys.stderr` and
682 don't provide any options to redirect it.
683 (Contributed by Berker Peksag in :issue:`22389`.)
684
Steve Dowerd2bc3892015-04-15 18:06:05 -0400685curses
686------
687* The new :func:`curses.update_lines_cols` function updates the variables
688 :envvar:`curses.LINES` and :envvar:`curses.COLS`.
689
Berker Peksag102029d2015-03-15 01:18:47 +0200690difflib
691-------
692
693* The charset of the HTML document generated by :meth:`difflib.HtmlDiff.make_file`
694 can now be customized by using *charset* keyword-only parameter. The default
695 charset of HTML document changed from ``'ISO-8859-1'`` to ``'utf-8'``.
696 (Contributed by Berker Peksag in :issue:`2052`.)
697
Greg Ward4d9d2562015-04-20 20:21:21 -0400698* It's now possible to compare lists of byte strings with
699 :func:`difflib.diff_bytes` (fixes a regression from Python 2).
700
Berker Peksag618e3152015-01-27 02:59:09 +0200701distutils
702---------
703
704* The ``build`` and ``build_ext`` commands now accept a ``-j``
705 option to enable parallel building of extension modules.
706 (Contributed by Antoine Pitrou in :issue:`5309`.)
707
Serhiy Storchakab9cec6a2015-05-16 22:13:27 +0300708* Added support for the LZMA compression.
709 (Contributed by Serhiy Storchaka in :issue:`16314`.)
710
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200711doctest
712-------
Giampaolo Rodola'e09fb712014-04-04 15:34:17 +0200713
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200714* :func:`doctest.DocTestSuite` returns an empty :class:`unittest.TestSuite` if
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200715 *module* contains no docstrings instead of raising :exc:`ValueError`.
716 (Contributed by Glenn Jones in :issue:`15916`.)
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200717
R David Murrayb744f3a2015-05-16 15:41:07 -0400718email
719-----
720
R David Murrayfdb23c22015-05-17 14:24:33 -0400721* A new policy option :attr:`~email.policy.Policy.mangle_from_` controls
722 whether or not lines that start with "From " in email bodies are prefixed with
723 a '>' character by generators. The default is ``True`` for
724 :attr:`~email.policy.compat32` and ``False`` for all other policies.
725 (Contributed by Milan Oberkirch in :issue:`20098`.)
726
R David Murrayb744f3a2015-05-16 15:41:07 -0400727* A new method :meth:`~email.message.Message.get_content_disposition` provides
728 easy access to a canonical value for the :mailheader:`Content-Disposition`
729 header (``None`` if there is no such header). (Contributed by Abhilash Raj
730 in :issue:`21083`.)
731
R David Murray224ef3e2015-05-17 11:29:21 -0400732* A new policy option :attr:`~email.policy.EmailPolicy.utf8` can be set
733 ``True`` to encode email headers using the utf8 charset instead of using
734 encoded words. This allows ``Messages`` to be formatted according to
735 :rfc:`6532` and used with an SMTP server that supports the :rfc:`6531`
736 ``SMTPUTF8`` extension. (Contributed by R. David Murray in :issue:`24211`.)
737
Serhiy Storchakac2edcdd2014-09-11 12:17:37 +0300738glob
739----
740
741* :func:`~glob.iglob` and :func:`~glob.glob` now support recursive search in
742 subdirectories using the "``**``" pattern.
743 (Contributed by Serhiy Storchaka in :issue:`13968`.)
744
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400745heapq
746-----
747
748* :func:`~heapq.merge` has two new optional parameters ``reverse`` and
749 ``key``. (Contributed by Raymond Hettinger in :issue:`13742`.)
750
Guido van Rossum7ca13532015-05-23 15:27:51 -0700751idlelib and IDLE
Terry Jan Reedy44825cf2015-05-23 18:19:42 -0400752----------------
753
754Since idlelib implements the IDLE shell and editor and is not intended for
755import by other programs, it gets improvements with every release. See
756:file:`Lib/idlelib/NEWS.txt` for a cumulative list of changes since 3.4.0,
757as well as changes made in future 3.5.x releases. This file is also available
758from the IDLE Help -> About Idle dialog.
759
Serhiy Storchaka38684c32014-09-09 19:07:49 +0300760imaplib
761-------
762
763* :class:`IMAP4` now supports the context management protocol. When used in a
764 :keyword:`with` statement, the IMAP4 ``LOGOUT`` command will be called
765 automatically at the end of the block. (Contributed by Tarek Ziadé and
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200766 Serhiy Storchaka in :issue:`4972`.)
Serhiy Storchaka38684c32014-09-09 19:07:49 +0300767
R David Murraya6429db2015-05-10 19:17:23 -0400768* :mod:`imaplib` now supports :rfc:`5161`: the :meth:`~imaplib.IMAP4.enable`
769 extension), and :rfc:`6855`: utf-8 support (internationalized email, via the
770 ``UTF8=ACCEPT`` argument to :meth:`~imaplib.IMAP4.enable`). A new attribute,
771 :attr:`~imaplib.IMAP4.utf8_enabled`, tracks whether or not :rfc:`6855`
772 support is enabled. Milan Oberkirch, R. David Murray, and Maciej Szulik in
773 :issue:`21800`.)
774
775* :mod:`imaplib` now automatically encodes non-ASCII string usernames and
776 passwords using ``UTF8``, as recommended by the RFCs. (Contributed by Milan
777 Oberkirch in :issue:`21800`.)
778
R David Murray2f608202014-06-26 12:27:57 -0400779imghdr
780------
781
782* :func:`~imghdr.what` now recognizes the `OpenEXR <http://www.openexr.com>`_
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400783 format (contributed by Martin Vignali and Claudiu Popa in :issue:`20295`),
784 and the `WebP <https://en.wikipedia.org/wiki/WebP>`_ format (contributed
785 by Fabrice Aneche and Claudiu Popa in :issue:`20197`.)
R David Murray2f608202014-06-26 12:27:57 -0400786
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200787importlib
788---------
789
790* :class:`importlib.util.LazyLoader` allows for the lazy loading of modules in
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200791 applications where startup time is paramount.
792 (Contributed by Brett Cannon in :issue:`17621`.)
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200793
794* :func:`importlib.abc.InspectLoader.source_to_code` is now a
795 static method to make it easier to work with source code in a string.
796 With a module object that you want to initialize you can then use
797 ``exec(code, module.__dict__)`` to execute the code in the module.
798
Brett Cannon2a17bde2014-05-30 14:55:29 -0400799* :func:`importlib.util.module_from_spec` is now the preferred way to create a
800 new module. Compared to :class:`types.ModuleType`, this new function will set
801 the various import-controlled attributes based on the passed-in spec object.
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400802 (Contributed by Brett Cannon in :issue:`20383`.)
Brett Cannon2a17bde2014-05-30 14:55:29 -0400803
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200804inspect
805-------
Victor Stinner01adf062014-03-18 00:53:32 +0100806
Yury Selivanova5d63dd2014-03-27 11:31:43 -0400807* :class:`inspect.Signature` and :class:`inspect.Parameter` are now
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200808 picklable and hashable. (Contributed by Yury Selivanov in :issue:`20726`
809 and :issue:`20334`.)
Yury Selivanova5d63dd2014-03-27 11:31:43 -0400810
Yury Selivanovb907a512015-05-16 13:45:09 -0400811* New method :meth:`inspect.BoundArguments.apply_defaults`. (Contributed
812 by Yury Selivanov in :issue:`24190`.)
813
Yury Selivanovda396452014-03-27 12:09:24 -0400814* New class method :meth:`inspect.Signature.from_callable`, which makes
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200815 subclassing of :class:`~inspect.Signature` easier. (Contributed
816 by Yury Selivanov and Eric Snow in :issue:`17373`.)
Yury Selivanovda396452014-03-27 12:09:24 -0400817
Yury Selivanovbcd4fc12015-05-20 14:30:08 -0400818* New argument ``follow_wrapped`` for :func:`inspect.signature`.
819 (Contributed by Yury Selivanov in :issue:`20691`.)
820
Yury Selivanovfdbeb2b2015-07-03 13:11:35 -0400821* New :func:`~inspect.iscoroutine`, :func:`~inspect.iscoroutinefunction`
822 and :func:`~inspect.isawaitable` functions. (Contributed by
823 Yury Selivanov in :issue:`24017`.)
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400824
Yury Selivanov5376ba92015-06-22 12:19:30 -0400825* New :func:`~inspect.getcoroutinelocals` and :func:`~inspect.getcoroutinestate`
826 functions. (Contributed by Yury Selivanov in :issue:`24400`.)
827
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400828* :func:`~inspect.stack`, :func:`~inspect.trace`, :func:`~inspect.getouterframes`,
829 and :func:`~inspect.getinnerframes` now return a list of named tuples.
830 (Contributed by Daniel Shahaf in :issue:`16808`.)
831
Antoine Pitrou0dfce562014-05-15 22:55:40 +0200832ipaddress
833---------
834
835* :class:`ipaddress.IPv4Network` and :class:`ipaddress.IPv6Network` now
836 accept an ``(address, netmask)`` tuple argument, so as to easily construct
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200837 network objects from existing addresses. (Contributed by Peter Moody
838 and Antoine Pitrou in :issue:`16531`.)
Antoine Pitrou0dfce562014-05-15 22:55:40 +0200839
Berker Peksag39e4c4d2014-11-10 09:56:54 +0200840json
841----
842
843* The output of :mod:`json.tool` command line interface is now in the same
844 order as the input. Use the :option:`--sort-keys` option to sort the output
845 of dictionaries alphabetically by key. (Contributed by Berker Peksag in
846 :issue:`21650`.)
847
Serhiy Storchaka47efb4a2015-01-26 13:16:30 +0200848* JSON decoder now raises :exc:`json.JSONDecodeError` instead of
849 :exc:`ValueError`. (Contributed by Serhiy Storchaka in :issue:`19361`.)
850
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400851locale
852------
853
854 * New :func:`~locale.delocalize` function to convert a string into a
855 normalized number string, following the ``LC_NUMERIC`` settings.
856 (Contributed by Cédric Krier in :issue:`13918`.)
857
858logging
859-------
860
861* All logging methods :meth:`~logging.Logger.log`, :meth:`~logging.Logger.exception`,
862 :meth:`~logging.Logger.critical`, :meth:`~logging.Logger.debug`, etc,
863 now accept exception instances for ``exc_info`` parameter, in addition
864 to boolean values and exception tuples.
865 (Contributed by Yury Selivanov in :issue:`20537`.)
866
867* :class:`~logging.handlers.HTTPHandler` now accepts optional
868 :class:`ssl.SSLContext` instance to configure the SSL settings used
869 for HTTP connection.
870 (Contributed by Alex Gaynor in :issue:`22788`.)
871
872lzma
873----
874
875* New option *max_length* for :meth:`~lzma.LZMADecompressor.decompress`
876 to limit the maximum size of decompressed data.
877 (Contributed by Martin Panter in :issue:`15955`.)
878
879
Tal Einatf67b0a32015-05-31 22:18:31 +0300880math
881----
882
883* :data:`math.inf` and :data:`math.nan` constants added. (Contributed by Mark
884 Dickinson in :issue:`23185`.)
885* :func:`math.isclose` function added.
886 (Contributed by Chris Barker and Tal Einat in :issue:`24270`.)
887
Zachary Ware63f277b2014-06-19 09:46:37 -0500888os
889--
890
Victor Stinner37f20342015-03-10 13:29:41 +0100891* New :func:`os.scandir` function that exposes file information from
892 the operating system when listing a directory. :func:`os.scandir`
893 returns an iterator of :class:`os.DirEntry` objects corresponding to
894 the entries in the directory given by *path*. (Contributed by Ben
895 Hoyt with the help of Victor Stinner in :issue:`22524`.)
Victor Stinner6036e442015-03-08 01:58:04 +0100896
Victor Stinnere1d24f72014-07-24 12:44:07 +0200897* :class:`os.stat_result` now has a :attr:`~os.stat_result.st_file_attributes`
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200898 attribute on Windows. (Contributed by Ben Hoyt in :issue:`21719`.)
Zachary Ware63f277b2014-06-19 09:46:37 -0500899
Victor Stinnerace88482015-07-29 02:28:32 +0200900* :func:`os.urandom`: On Linux 3.17 and newer, the ``getrandom()`` syscall is
901 now used when available. On OpenBSD 5.6 and newer, the C ``getentropy()``
902 function is now used. These functions avoid the usage of an internal file
903 descriptor.
904
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400905* New :func:`os.get_blocking` and :func:`os.set_blocking` functions to
906 get and set the blocking mode of file descriptors.
907 (Contributed by Victor Stinner in :issue:`22054`.)
908
Serhiy Storchaka38220932015-03-31 15:31:53 +0300909os.path
910-------
911
912* New :func:`~os.path.commonpath` function that extracts common path prefix.
913 Unlike the :func:`~os.path.commonprefix` function, it always returns a valid
Larry Hastingsd5b129c2015-08-24 12:49:22 -0700914 path. (Contributed by Rafik Draoui and Serhiy Storchaka in :issue:`10395`.)
Serhiy Storchaka38220932015-03-31 15:31:53 +0300915
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400916pathlib
917-------
918
919* New :meth:`~pathlib.Path.samefile` method to check if other path object
920 points to the same file. (Contributed by Vajrasky Kok and Antoine Pitrou
921 in :issue:`19775`.)
922
923* :meth:`~pathlib.Path.mkdir` has a new optional parameter ``exist_ok``
924 to mimic ``mkdir -p`` and :func:`os.makrdirs` functionality.
925 (Contributed by Berker Peksag in :issue:`21539`.)
926
927* New :meth:`~pathlib.Path.expanduser` to expand ``~`` and ``~user``
928 constructs.
929 (Contributed by Serhiy Storchaka and Claudiu Popa in :issue:`19776`.)
930
931* New class method :meth:`~pathlib.Path.home` to get an instance of
932 :class:`~pathlib.Path` object representing the user’s home directory.
933 (Contributed by Victor Salgado and Mayank Tripathi in :issue:`19777`.)
934
Serhiy Storchaka58e41342015-03-31 14:07:24 +0300935pickle
936------
937
938* Serializing more "lookupable" objects (such as unbound methods or nested
939 classes) now are supported with pickle protocols < 4.
940 (Contributed by Serhiy Storchaka in :issue:`23611`.)
941
R David Murrayb8cd3e42015-05-16 15:05:53 -0400942poplib
943------
944
945* A new command :meth:`~poplib.POP3.utf8` enables :rfc:`6856`
946 (internationalized email) support if the POP server supports it. (Contributed
947 by Milan OberKirch in :issue:`21804`.)
948
Serhiy Storchaka9baa5b22014-09-29 22:49:23 +0300949re
950--
951
952* Number of capturing groups in regular expression is no longer limited by 100.
953 (Contributed by Serhiy Storchaka in :issue:`22437`.)
954
Serhiy Storchaka7438e4b2014-10-10 11:06:31 +0300955* Now unmatched groups are replaced with empty strings in :func:`re.sub`
956 and :func:`re.subn`. (Contributed by Serhiy Storchaka in :issue:`1519638`.)
957
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400958readline
959--------
960
961* New :func:`~readline.append_history_file` function.
962 (Contributed by Bruno Cauet in :issue:`22940`.)
963
R David Murray6ffface2014-06-11 14:40:13 -0400964shutil
965------
966
967* :func:`~shutil.move` now accepts a *copy_function* argument, allowing,
968 for example, :func:`~shutil.copy` to be used instead of the default
969 :func:`~shutil.copy2` if there is a need to ignore metadata. (Contributed by
970 Claudiu Popa in :issue:`19840`.)
971
Yury Selivanov100fc3f2015-09-08 22:40:30 -0400972* :func:`~shutil.make_archive` now supports *xztar* format.
973 (Contributed by Serhiy Storchaka in :issue:`5411`.)
974
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200975signal
976------
Brett Cannona04dbe42014-04-04 13:53:38 -0400977
Victor Stinnerbbe38032015-04-01 16:32:32 +0200978* On Windows, :func:`signal.set_wakeup_fd` now also supports socket handles.
979 (Contributed by Victor Stinner in :issue:`22018`.)
980
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200981* Different constants of :mod:`signal` module are now enumeration values using
982 the :mod:`enum` module. This allows meaningful names to be printed during
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200983 debugging, instead of integer “magic numbers”. (Contributed by Giampaolo
984 Rodola' in :issue:`21076`.)
R David Murray1976d9b2014-04-14 20:28:36 -0400985
R David Murray554bcbf2014-06-11 11:18:08 -0400986smtpd
987-----
988
989* Both :class:`~smtpd.SMTPServer` and :class:`smtpd.SMTPChannel` now accept a
990 *decode_data* keyword to determine if the DATA portion of the SMTP
991 transaction is decoded using the ``utf-8`` codec or is instead provided to
992 :meth:`~smtpd.SMTPServer.process_message` as a byte string. The default
993 is ``True`` for backward compatibility reasons, but will change to ``False``
R David Murraya33df312015-05-11 12:11:40 -0400994 in Python 3.6. If *decode_data* is set to ``False``, the
995 :meth:`~smtpd.SMTPServer.process_message` method must be prepared to accept
996 keyword arguments. (Contributed by Maciej Szulik in :issue:`19662`.)
997
998* :class:`~smtpd.SMTPServer` now advertises the ``8BITMIME`` extension
999 (:rfc:`6152`) if if *decode_data* has been set ``True``. If the client
1000 specifies ``BODY=8BITMIME`` on the ``MAIL`` command, it is passed to
1001 :meth:`~smtpd.SMTPServer.process_message` via the ``mail_options`` keyword.
1002 (Contributed by Milan Oberkirch and R. David Murray in :issue:`21795`.)
1003
1004* :class:`~smtpd.SMTPServer` now supports the ``SMTPUTF8`` extension
1005 (:rfc:`6531`: Internationalized Email). If the client specified ``SMTPUTF8
1006 BODY=8BITMIME`` on the ``MAIL`` command, they are passed to
1007 :meth:`~smtpd.SMTPServer.process_message` via the ``mail_options`` keyword.
1008 It is the responsibility of the :meth:`~smtpd.SMTPServer.process_message`
1009 method to correctly handle the ``SMTPUTF8`` data. (Contributed by Milan
1010 Oberkirch in :issue:`21725`.)
R David Murray554bcbf2014-06-11 11:18:08 -04001011
R David Murray6fe56a32014-06-11 13:48:58 -04001012* It is now possible to provide, directly or via name resolution, IPv6
1013 addresses in the :class:`~smtpd.SMTPServer` constructor, and have it
1014 successfully connect. (Contributed by Milan Oberkirch in :issue:`14758`.)
1015
R David Murray76e13c12014-07-03 14:47:46 -04001016smtplib
1017-------
1018
1019* A new :meth:`~smtplib.SMTP.auth` method provides a convenient way to
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001020 implement custom authentication mechanisms.
1021 (Contributed by Milan Oberkirch in :issue:`15014`.)
R David Murray76e13c12014-07-03 14:47:46 -04001022
R David Murray0c49b892015-04-16 17:14:42 -04001023* Additional debuglevel (2) shows timestamps for debug messages in
1024 :class:`smtplib.SMTP`. (Contributed by Gavin Chappell and Maciej Szulik in
1025 :issue:`16914`.)
1026
R David Murray83084442015-05-17 19:27:22 -04001027* :mod:`smtplib` now supports :rfc:`6531` (SMTPUTF8) in both the
1028 :meth:`~smtplib.SMTP.sendmail` and :meth:`~smtplib.SMTP.send_message`
1029 commands. (Contributed by Milan Oberkirch and R. David Murray in
1030 :issue:`22027`.)
R David Murraycee7cf62015-05-16 13:58:14 -04001031
R David Murray4487dd02014-10-09 16:59:30 -04001032sndhdr
1033------
1034
1035* :func:`~sndhdr.what` and :func:`~sndhdr.whathdr` now return
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001036 :func:`~collections.namedtuple`.
1037 (Contributed by Claudiu Popa in :issue:`18615`.)
R David Murray4487dd02014-10-09 16:59:30 -04001038
Victor Stinner287452e2015-07-29 01:39:13 +02001039ssl
1040---
1041
Yury Selivanov7d6adab2015-08-05 19:01:51 -04001042* The :meth:`~ssl.SSLSocket.do_handshake`, :meth:`~ssl.SSLSocket.read`,
1043 :meth:`~ssl.SSLSocket.shutdown`, and :meth:`~ssl.SSLSocket.write` methods of
1044 :class:`ssl.SSLSocket` don't reset the socket timeout anymore each time bytes
1045 are received or sent. The socket timeout is now the maximum total duration of
1046 the method.
1047
1048* Memory BIO Support: new classes :class:`~ssl.SSLObject`,
1049 :class:`~ssl.MemoryBIO`, and new
1050 :meth:`SSLContext.wrap_bio <ssl.SSLContext.wrap_bio>` method.
1051 (Contributed by Geert Jansen in :issue:`21965`.)
Victor Stinner287452e2015-07-29 01:39:13 +02001052
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001053* New :meth:`~ssl.SSLSocket.version` to query the actual protocol version
1054 in use. (Contributed by Antoine Pitrou in :issue:`20421`.)
1055
1056* New :meth:`~ssl.SSLObject.shared_ciphers` and
1057 :meth:`~ssl.SSLSocket.shared_ciphers` methods to fetch the client's
1058 list of ciphers sent at handshake.
1059 (Contributed by Benjamin Peterson in :issue:`23186`.)
1060
Giampaolo Rodola'915d1412014-06-11 03:54:30 +02001061socket
1062------
1063
1064* New :meth:`socket.socket.sendfile` method allows to send a file over a socket
1065 by using high-performance :func:`os.sendfile` function on UNIX resulting in
1066 uploads being from 2x to 3x faster than when using plain
1067 :meth:`socket.socket.send`.
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001068 (Contributed by Giampaolo Rodola' in :issue:`17552`.)
Giampaolo Rodola'915d1412014-06-11 03:54:30 +02001069
Victor Stinner98810132015-07-29 01:41:25 +02001070* The :meth:`socket.socket.sendall` method don't reset the socket timeout
1071 anymore each time bytes are received or sent. The socket timeout is now the
1072 maximum total duration to send all data.
1073
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001074* Functions with timeouts now use a monotonic clock, instead of a
1075 system clock. (Contributed by Victor Stinner in :issue:`22043`.)
1076
Gregory P. Smith6e730002015-04-14 16:14:25 -07001077subprocess
1078----------
1079
1080* The new :func:`subprocess.run` function runs subprocesses and returns a
1081 :class:`subprocess.CompletedProcess` object. It Provides a more consistent
1082 API than :func:`~subprocess.call`, :func:`~subprocess.check_call` and
1083 :func:`~subprocess.check_output`.
1084
Yury Selivanov4640b302015-05-31 17:21:38 -04001085sys
1086---
1087
1088* New :func:`~sys.set_coroutine_wrapper` and :func:`~sys.get_coroutine_wrapper`
1089 functions. (Contributed by Yury Selivanov in :issue:`24017`.)
1090
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001091* New :func:`~sys.is_finalizing` to check for :term:`interpreter shutdown`.
1092 (Contributed by Antoine Pitrou in :issue:`22696`.)
1093
Eric V. Smith7a803892015-04-15 10:27:58 -04001094sysconfig
1095---------
1096
1097* The user scripts directory on Windows is now versioned.
1098 (Contributed by Paul Moore in :issue:`23437`.)
1099
1100tarfile
1101-------
1102
1103* The :func:`tarfile.open` function now supports ``'x'`` (exclusive creation)
1104 mode. (Contributed by Berker Peksag in :issue:`21717`.)
1105
1106* The :meth:`~tarfile.TarFile.extractall` and :meth:`~tarfile.TarFile.extract`
1107 methods now take a keyword parameter *numeric_only*. If set to ``True``,
1108 the extracted files and directories will be owned by the numeric uid and gid
1109 from the tarfile. If set to ``False`` (the default, and the behavior in
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001110 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 -04001111 tarfile. (Contributed by Michael Vogt and Eric Smith in :issue:`23193`.)
1112
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001113threading
1114---------
1115
1116* :meth:`~threading.Lock.acquire` and :meth:`~threading.RLock.acquire`
1117 now use a monotonic clock for managing timeouts.
1118 (Contributed by Victor Stinner in :issue:`22043`.)
1119
Victor Stinnerae586492014-09-02 23:18:25 +02001120time
1121----
1122
Berker Peksag882c95c2014-10-09 11:46:56 +03001123* The :func:`time.monotonic` function is now always available. (Contributed by
1124 Victor Stinner in :issue:`22043`.)
Victor Stinnerae586492014-09-02 23:18:25 +02001125
Zachary Ware7dc9dea2015-05-22 11:36:53 -05001126tkinter
1127-------
1128
Nick Coghland5cacbb2015-05-23 22:24:10 +10001129* The :mod:`tkinter._fix` module used for setting up the Tcl/Tk environment
Berker Peksag1a90b172015-05-24 00:26:05 +03001130 on Windows has been replaced by a private function in the :mod:`_tkinter`
Zachary Ware7dc9dea2015-05-22 11:36:53 -05001131 module which makes no permanent changes to environment variables.
1132 (Contributed by Zachary Ware in :issue:`20035`.)
1133
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001134traceback
1135---------
1136
1137* New :func:`~traceback.walk_stack` and :func:`~traceback.walk_tb`
1138 functions to conveniently traverse frame and traceback objects.
1139 (Contributed by Robert Collins in :issue:`17911`.)
1140
1141* New lightweight classes: :class:`~traceback.TracebackException`,
1142 :class:`~traceback.StackSummary`, and :class:`traceback.FrameSummary`.
1143 (Contributed by Robert Collins in :issue:`17911`.)
1144
Yury Selivanovf3e40fa2015-05-21 11:50:30 -04001145types
1146-----
1147
1148* New :func:`~types.coroutine` function. (Contributed by Yury Selivanov
1149 in :issue:`24017`.)
1150
Yury Selivanov5376ba92015-06-22 12:19:30 -04001151* New :class:`~types.CoroutineType`. (Contributed by Yury Selivanov
1152 in :issue:`24400`.)
1153
Berker Peksagbd09d7b2015-02-11 15:32:34 +02001154urllib
1155------
Nick Coghlanc216c482014-11-12 23:33:50 +10001156
R David Murray4c7f9952015-04-16 16:36:18 -04001157* A new :class:`~urllib.request.HTTPPasswordMgrWithPriorAuth` allows HTTP Basic
1158 Authentication credentials to be managed so as to eliminate unnecessary
1159 ``401`` response handling, or to unconditionally send credentials
1160 on the first request in order to communicate with servers that return a
1161 ``404`` response instead of a ``401`` if the ``Authorization`` header is not
1162 sent. (Contributed by Matej Cepl in :issue:`19494` and Akshit Khurana in
1163 :issue:`7159`.)
Nick Coghlanc216c482014-11-12 23:33:50 +10001164
R David Murrayc17686f2015-05-17 20:44:50 -04001165* A new :func:`~urllib.parse.urlencode` parameter *quote_via* provides a way to
1166 control the encoding of query parts if needed. (Contributed by Samwyse and
1167 Arnon Yaari in :issue:`13866`.)
1168
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001169* :func:`~urllib.request.urlopen` accepts an :class:`ssl.SSLContext`
1170 object as a *context* argument, which will be used for the HTTPS
1171 connection. (Contributed by Alex Gaynor in :issue:`22366`.)
1172
Benjamin Peterson48013832015-06-27 15:45:56 -05001173unicodedata
1174-----------
1175
1176* The :mod:`unicodedata` module now uses data from `Unicode 8.0.0
Nick Coghlan2ab5b092015-07-03 19:49:15 +10001177 <http://unicode.org/versions/Unicode8.0.0/>`_.
Benjamin Peterson48013832015-06-27 15:45:56 -05001178
1179
Berker Peksag3e887222014-07-02 08:37:22 +03001180wsgiref
1181-------
1182
1183* *headers* parameter of :class:`wsgiref.headers.Headers` is now optional.
1184 (Contributed by Pablo Torres Navarrete and SilentGhost in :issue:`5800`.)
1185
Antoine Pitroub9d9ce72014-05-15 22:47:33 +02001186xmlrpc
1187------
1188
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001189* :class:`xmlrpc.client.ServerProxy` is now a :term:`context manager`.
1190 (Contributed by Claudiu Popa in :issue:`20627`.)
Brett Cannon6eaac132014-05-09 12:28:22 -04001191
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001192* :class:`~xmlrpc.client.ServerProxy` constructor now accepts an optional
1193 :class:`ssl.SSLContext` instance.
1194 (Contributed by Alex Gaynor in :issue:`22960`.)
1195
Serhiy Storchaka61de0872015-04-02 21:00:13 +03001196xml.sax
1197-------
1198
1199* SAX parsers now support a character stream of
1200 :class:`~xml.sax.xmlreader.InputSource` object.
1201 (Contributed by Serhiy Storchaka in :issue:`2175`.)
1202
Victor Stinner95bb7142015-03-12 15:32:03 +01001203faulthandler
1204------------
1205
1206* :func:`~faulthandler.enable`, :func:`~faulthandler.register`,
1207 :func:`~faulthandler.dump_traceback` and
1208 :func:`~faulthandler.dump_traceback_later` functions now accept file
1209 descriptors. (Contributed by Wei Wu in :issue:`23566`.)
1210
Serhiy Storchaka77d89972015-03-23 01:09:35 +02001211zipfile
1212-------
1213
1214* Added support for writing ZIP files to unseekable streams.
1215 (Contributed by Serhiy Storchaka in :issue:`23252`.)
1216
Serhiy Storchaka764fc9b2015-03-25 10:09:41 +02001217* The :func:`zipfile.ZipFile.open` function now supports ``'x'`` (exclusive
1218 creation) mode. (Contributed by Serhiy Storchaka in :issue:`21717`.)
1219
Victor Stinner01adf062014-03-18 00:53:32 +01001220
1221Optimizations
1222=============
1223
Antoine Pitroub9d9ce72014-05-15 22:47:33 +02001224The following performance enhancements have been added:
Victor Stinner01adf062014-03-18 00:53:32 +01001225
Victor Stinner37f20342015-03-10 13:29:41 +01001226* :func:`os.walk` has been sped up by 3-5x on POSIX systems and 7-20x
1227 on Windows. This was done using the new :func:`os.scandir` function,
1228 which exposes file information from the underlying ``readdir`` and
1229 ``FindFirstFile``/``FindNextFile`` system calls. (Contributed by
1230 Ben Hoyt with help from Victor Stinner in :issue:`23605`.)
1231
Brett Cannonf299abd2015-04-13 14:21:02 -04001232* Construction of ``bytes(int)`` (filled by zero bytes) is faster and uses less
Victor Stinner2bc4d952014-06-02 22:22:42 +02001233 memory for large objects. ``calloc()`` is used instead of ``malloc()`` to
Victor Stinnerdb067af2014-05-02 22:31:14 +02001234 allocate memory for these objects.
Victor Stinner01adf062014-03-18 00:53:32 +01001235
Antoine Pitrou0dfce562014-05-15 22:55:40 +02001236* Some operations on :class:`~ipaddress.IPv4Network` and
1237 :class:`~ipaddress.IPv6Network` have been massively sped up, such as
1238 :meth:`~ipaddress.IPv4Network.subnets`, :meth:`~ipaddress.IPv4Network.supernet`,
1239 :func:`~ipaddress.summarize_address_range`, :func:`~ipaddress.collapse_addresses`.
1240 The speed up can range from 3x to 15x.
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001241 (See :issue:`21486`, :issue:`21487`, :issue:`20826`, :issue:`23266`.)
1242
1243* Pickling of :mod:`ipaddress` classes was optimized to produce significantly
1244 smaller output. (Contributed by Serhiy Storchaka in :issue:`23133`.)
Antoine Pitrou0dfce562014-05-15 22:55:40 +02001245
Serhiy Storchaka87d0b452015-02-03 11:30:10 +02001246* Many operations on :class:`io.BytesIO` are now 50% to 100% faster.
Berker Peksag9121fe82015-02-15 00:45:57 +02001247 (Contributed by Serhiy Storchaka in :issue:`15381` and David Wilson in
1248 :issue:`22003`.)
Serhiy Storchaka87d0b452015-02-03 11:30:10 +02001249
Serhiy Storchakac1efe5f2015-02-11 15:54:54 +02001250* :func:`marshal.dumps` is now faster (65%-85% with versions 3--4, 20-25% with
1251 versions 0--2 on typical data, and up to 5x in best cases).
1252 (Contributed by Serhiy Storchaka in :issue:`20416` and :issue:`23344`.)
Serhiy Storchakace921c622015-02-11 15:53:31 +02001253
Serhiy Storchaka0d4df752015-05-12 23:12:45 +03001254* The UTF-32 encoder is now 3x to 7x faster. (Contributed by Serhiy Storchaka
1255 in :issue:`15027`.)
1256
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001257* Regular expressions are now parsed up to 10% faster.
1258 (Contributed by Serhiy Storchaka in :issue:`19380`.)
1259
1260* :func:`json.dumps` was optimized to run with ``ensure_ascii=False``
1261 as fast as with ``ensure_ascii=True``.
1262 (Contributed by Naoki Inada in :issue:`23206`.)
1263
Victor Stinner01adf062014-03-18 00:53:32 +01001264
1265Build and C API Changes
1266=======================
1267
1268Changes to Python's build process and to the C API include:
1269
Victor Stinnerdb067af2014-05-02 22:31:14 +02001270* New ``calloc`` functions:
1271
1272 * :c:func:`PyMem_RawCalloc`
1273 * :c:func:`PyMem_Calloc`
1274 * :c:func:`PyObject_Calloc`
1275 * :c:func:`_PyObject_GC_Calloc`
Victor Stinner01adf062014-03-18 00:53:32 +01001276
Steve Dower313fbf42015-07-17 16:48:48 -07001277* Windows builds now require Microsoft Visual C++ 14.0, which
1278 is available as part of `Visual Studio 2015 <http://www.visualstudio.com>`_.
Victor Stinner01adf062014-03-18 00:53:32 +01001279
1280Deprecated
1281==========
1282
Yury Selivanov8fa6d4f2015-05-28 17:09:14 -04001283New Keywords
1284------------
1285
Yury Selivanov13b74ae2015-08-03 14:55:58 -04001286``async`` and ``await`` are not recommended to be used as variable, class,
1287function or module names. Introduced by :pep:`492` in Python 3.5, they will
1288become proper keywords in Python 3.7.
Yury Selivanov8fa6d4f2015-05-28 17:09:14 -04001289
1290
Victor Stinner01adf062014-03-18 00:53:32 +01001291Unsupported Operating Systems
1292-----------------------------
1293
Zachary Ware38019d12015-04-13 15:51:59 -05001294* Windows XP - Per :PEP:`11`, Microsoft support of Windows XP has ended.
Victor Stinner01adf062014-03-18 00:53:32 +01001295
1296
1297Deprecated Python modules, functions and methods
1298------------------------------------------------
1299
Brett Cannona77d0c32014-03-21 10:52:33 -04001300* The :mod:`formatter` module has now graduated to full deprecation and is still
1301 slated for removal in Python 3.6.
Victor Stinner01adf062014-03-18 00:53:32 +01001302
R David Murray554bcbf2014-06-11 11:18:08 -04001303* :mod:`smtpd` has in the past always decoded the DATA portion of email
1304 messages using the ``utf-8`` codec. This can now be controlled by the new
1305 *decode_data* keyword to :class:`~smtpd.SMTPServer`. The default value is
1306 ``True``, but this default is deprecated. Specify the *decode_data* keyword
1307 with an appropriate value to avoid the deprecation warning.
1308
R David Murray1813c172015-03-29 17:09:21 -04001309* Directly assigning values to the :attr:`~http.cookies.Morsel.key`,
1310 :attr:`~http.cookies.Morsel.value` and
1311 :attr:`~http.cookies.Morsel.coded_value` of :class:`~http.cookies.Morsel`
1312 objects is deprecated. Use the :func:`~http.cookies.Morsel.set` method
1313 instead. In addition, the undocumented *LegalChars* parameter of
1314 :func:`~http.cookies.Morsel.set` is deprecated, and is now ignored.
Serhiy Storchaka9c1a9b22015-03-18 10:59:57 +02001315
Serhiy Storchakab876df42015-03-24 22:30:46 +02001316* Passing a format string as keyword argument *format_string* to the
1317 :meth:`~string.Formatter.format` method of the :class:`string.Formatter`
1318 class has been deprecated.
1319
Berker Peksag2f3742b2015-05-13 12:32:20 +03001320* :func:`platform.dist` and :func:`platform.linux_distribution` functions are
1321 now deprecated and will be removed in Python 3.7. Linux distributions use
1322 too many different ways of describing themselves, so the functionality is
1323 left to a package.
1324 (Contributed by Vajrasky Kok and Berker Peksag in :issue:`1322`.)
Victor Stinner01adf062014-03-18 00:53:32 +01001325
Benjamin Petersonb1cc37c2015-05-20 22:09:43 -05001326* The previously undocumented ``from_function`` and ``from_builtin`` methods of
1327 :class:`inspect.Signature` are deprecated. Use new
Yury Selivanov57c74fc2015-05-20 23:07:02 -04001328 :meth:`inspect.Signature.from_callable` instead. (Contributed by Yury
1329 Selivanov in :issue:`24248`.)
1330
Yury Selivanov945fff42015-05-22 16:28:05 -04001331* :func:`inspect.getargspec` is deprecated and scheduled to be removed in
1332 Python 3.6. (See :issue:`20438` for details.)
1333
1334* :func:`~inspect.getfullargspec`, :func:`~inspect.getargvalues`,
1335 :func:`~inspect.getcallargs`, :func:`~inspect.getargvalues`,
1336 :func:`~inspect.formatargspec`, and :func:`~inspect.formatargvalues` are
1337 deprecated in favor of :func:`inspect.signature` API. (See :issue:`20438`
1338 for details.)
1339
Yury Selivanov100fc3f2015-09-08 22:40:30 -04001340* Use of ``re.LOCALE`` flag with str patterns or ``re.ASCII`` is now
1341 deprecated. (Contributed by Serhiy Storchaka in :issue:`22407`.)
1342
Yury Selivanov945fff42015-05-22 16:28:05 -04001343
Victor Stinner01adf062014-03-18 00:53:32 +01001344Deprecated functions and types of the C API
1345-------------------------------------------
1346
1347* None yet.
1348
1349
1350Deprecated features
1351-------------------
1352
1353* None yet.
1354
1355
R David Murraydf75fee2014-10-03 13:02:47 -04001356Removed
1357=======
1358
Berker Peksag8f791d32014-11-01 10:45:57 +02001359API and Feature Removals
1360------------------------
1361
1362The following obsolete and previously deprecated APIs and features have been
1363removed:
1364
R David Murraydf75fee2014-10-03 13:02:47 -04001365* The ``__version__`` attribute has been dropped from the email package. The
1366 email code hasn't been shipped separately from the stdlib for a long time,
1367 and the ``__version__`` string was not updated in the last few releases.
1368
Berker Peksag8f791d32014-11-01 10:45:57 +02001369* The internal ``Netrc`` class in the :mod:`ftplib` module was deprecated in
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001370 3.4, and has now been removed.
1371 (Contributed by Matt Chaput in :issue:`6623`.)
R David Murraydf75fee2014-10-03 13:02:47 -04001372
Brett Cannonf299abd2015-04-13 14:21:02 -04001373* The concept of ``.pyo`` files has been removed.
1374
R David Murraye81a7732015-04-12 18:47:56 -04001375* The JoinableQueue class in the provisional asyncio module was deprecated
1376 in 3.4.4 and is now removed (:issue:`23464`).
1377
1378
Victor Stinner01adf062014-03-18 00:53:32 +01001379Porting to Python 3.5
1380=====================
1381
1382This section lists previously described changes and other bugfixes
1383that may require changes to your code.
1384
Victor Stinnerdb067af2014-05-02 22:31:14 +02001385Changes in the Python API
1386-------------------------
1387
Victor Stinner6752d652015-07-29 01:11:10 +02001388* :pep:`475`: System calls are now retried when interrupted by a signal instead
1389 of raising :exc:`InterruptedError` if the Python signal handler does not
1390 raise an exception.
Victor Stinnera766ddf2015-03-26 23:50:57 +01001391
Benjamin Petersonee6bdc02014-03-20 18:00:35 -05001392* Before Python 3.5, a :class:`datetime.time` object was considered to be false
1393 if it represented midnight in UTC. This behavior was considered obscure and
1394 error-prone and has been removed in Python 3.5. See :issue:`13936` for full
1395 details.
Antoine Pitrou92c4d452014-04-29 10:05:59 +02001396
1397* :meth:`ssl.SSLSocket.send()` now raises either :exc:`ssl.SSLWantReadError`
1398 or :exc:`ssl.SSLWantWriteError` on a non-blocking socket if the operation
1399 would block. Previously, it would return 0. See :issue:`20951`.
Victor Stinnerdb067af2014-05-02 22:31:14 +02001400
Victor Stinner40ee3012014-06-16 15:59:28 +02001401* The ``__name__`` attribute of generator is now set from the function name,
1402 instead of being set from the code name. Use ``gen.gi_code.co_name`` to
1403 retrieve the code name. Generators also have a new ``__qualname__``
1404 attribute, the qualified name, which is now used for the representation
1405 of a generator (``repr(gen)``). See :issue:`21205`.
1406
Ezio Melotti045160b2014-08-02 18:54:30 +03001407* The deprecated "strict" mode and argument of :class:`~html.parser.HTMLParser`,
1408 :meth:`HTMLParser.error`, and the :exc:`HTMLParserError` exception have been
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001409 removed. (Contributed by Ezio Melotti in :issue:`15114`.)
Ezio Melotti045160b2014-08-02 18:54:30 +03001410 The *convert_charrefs* argument of :class:`~html.parser.HTMLParser` is
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001411 now ``True`` by default. (Contributed by Berker Peksag in :issue:`21047`.)
Ezio Melotti045160b2014-08-02 18:54:30 +03001412
R David Murray861470c2014-10-05 11:47:01 -04001413* Although it is not formally part of the API, it is worth noting for porting
1414 purposes (ie: fixing tests) that error messages that were previously of the
1415 form "'sometype' does not support the buffer protocol" are now of the form "a
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001416 bytes-like object is required, not 'sometype'". (Contributed by Ezio Melotti
1417 in :issue:`16518`.)
R David Murray861470c2014-10-05 11:47:01 -04001418
Brett Cannonb6e25562014-11-21 12:19:28 -05001419* If the current directory is set to a directory that no longer exists then
1420 :exc:`FileNotFoundError` will no longer be raised and instead
1421 :meth:`~importlib.machinery.FileFinder.find_spec` will return ``None``
1422 **without** caching ``None`` in :data:`sys.path_importer_cache` which is
1423 different than the typical case (:issue:`22834`).
1424
Berker Peksag088ca8b2015-02-06 10:17:49 +02001425* HTTP status code and messages from :mod:`http.client` and :mod:`http.server`
1426 were refactored into a common :class:`~http.HTTPStatus` enum. The values in
1427 :mod:`http.client` and :mod:`http.server` remain available for backwards
1428 compatibility. (Contributed by Demian Brecht in :issue:`21793`.)
Serhiy Storchakae4db7692014-12-23 16:28:28 +02001429
Brett Cannon02d84542015-01-09 11:39:21 -05001430* When an import loader defines :meth:`~importlib.machinery.Loader.exec_module`
1431 it is now expected to also define
1432 :meth:`~importlib.machinery.Loader.create_module` (raises a
1433 :exc:`DeprecationWarning` now, will be an error in Python 3.6). If the loader
1434 inherits from :class:`importlib.abc.Loader` then there is nothing to do, else
1435 simply define :meth:`~importlib.machinery.Loader.create_module` to return
1436 ``None`` (:issue:`23014`).
1437
Serhiy Storchaka83e80272015-02-03 11:04:19 +02001438* :func:`re.split` always ignored empty pattern matches, so the ``'x*'``
1439 pattern worked the same as ``'x+'``, and the ``'\b'`` pattern never worked.
1440 Now :func:`re.split` raises a warning if the pattern could match
1441 an empty string. For compatibility use patterns that never match an empty
1442 string (e.g. ``'x+'`` instead of ``'x*'``). Patterns that could only match
1443 an empty string (such as ``'\b'``) now raise an error.
1444
R David Murray1813c172015-03-29 17:09:21 -04001445* The :class:`~http.cookies.Morsel` dict-like interface has been made self
1446 consistent: morsel comparison now takes the :attr:`~http.cookies.Morsel.key`
1447 and :attr:`~http.cookies.Morsel.value` into account,
1448 :meth:`~http.cookies.Morsel.copy` now results in a
R David Murrayba6ea9b2015-03-30 11:48:50 -04001449 :class:`~http.cookies.Morsel` instance rather than a :class:`dict`, and
1450 :meth:`~http.cookies.Morsel.update` will now raise an exception if any of the
R David Murray1813c172015-03-29 17:09:21 -04001451 keys in the update dictionary are invalid. In addition, the undocumented
1452 *LegalChars* parameter of :func:`~http.cookies.Morsel.set` is deprecated and
1453 is now ignored. (:issue:`2211`)
1454
Brett Cannonf299abd2015-04-13 14:21:02 -04001455* :pep:`488` has removed ``.pyo`` files from Python and introduced the optional
1456 ``opt-`` tag in ``.pyc`` file names. The
1457 :func:`importlib.util.cache_from_source` has gained an *optimization*
1458 parameter to help control the ``opt-`` tag. Because of this, the
1459 *debug_override* parameter of the function is now deprecated. `.pyo` files
1460 are also no longer supported as a file argument to the Python interpreter and
1461 thus serve no purpose when distributed on their own (i.e. sourcless code
1462 distribution). Due to the fact that the magic number for bytecode has changed
1463 in Python 3.5, all old `.pyo` files from previous versions of Python are
1464 invalid regardless of this PEP.
1465
Ned Deilycec3f562015-06-10 15:43:05 -07001466* The :mod:`socket` module now exports the CAN_RAW_FD_FRAMES constant on linux
1467 3.6 and greater.
Larry Hastingsa6cc5512015-04-13 17:48:40 -04001468
Zachary Ware3d3aedc2015-07-07 00:07:25 -05001469* The ``pygettext.py`` Tool now uses the standard +NNNN format for timezones in
R David Murray2b781292015-04-16 12:15:09 -04001470 the POT-Creation-Date header.
1471
R David Murray0c49b892015-04-16 17:14:42 -04001472* The :mod:`smtplib` module now uses :data:`sys.stderr` instead of previous
1473 module level :data:`stderr` variable for debug output. If your (test)
1474 program depends on patching the module level variable to capture the debug
1475 output, you will need to update it to capture sys.stderr instead.
1476
Serhiy Storchakad4ea03c2015-05-31 09:15:51 +03001477* The :meth:`str.startswith` and :meth:`str.endswith` methods no longer return
1478 ``True`` when finding the empty string and the indexes are completely out of
1479 range. See :issue:`24284`.
1480
Berker Peksag4333d8b2015-07-30 18:06:09 +03001481* The :func:`inspect.getdoc` function now returns documentation strings
1482 inherited from base classes. Documentation strings no longer need to be
1483 duplicated if the inherited documentation is appropriate. To suppress an
1484 inherited string, an empty string must be specified (or the documentation
1485 may be filled in). This change affects the output of the :mod:`pydoc`
1486 module and the :func:`help` function. See :issue:`15582`.
1487
Victor Stinnerdb067af2014-05-02 22:31:14 +02001488Changes in the C API
1489--------------------
1490
Stefan Krahf5324d72015-01-29 14:29:51 +01001491* The undocumented :c:member:`~PyMemoryViewObject.format` member of the
1492 (non-public) :c:type:`PyMemoryViewObject` structure has been removed.
1493
1494 All extensions relying on the relevant parts in ``memoryobject.h``
1495 must be rebuilt.
1496
Victor Stinnerd8f0d922014-06-02 21:57:10 +02001497* The :c:type:`PyMemAllocator` structure was renamed to
1498 :c:type:`PyMemAllocatorEx` and a new ``calloc`` field was added.
Serhiy Storchakadf4518c2014-11-18 23:34:33 +02001499
1500* Removed non-documented macro :c:macro:`PyObject_REPR` which leaked references.
1501 Use format character ``%R`` in :c:func:`PyUnicode_FromFormat`-like functions
1502 to format the :func:`repr` of the object.
Serhiy Storchaka490055a2015-03-01 10:03:02 +02001503
1504* Because the lack of the :attr:`__module__` attribute breaks pickling and
1505 introspection, a deprecation warning now is raised for builtin type without
1506 the :attr:`__module__` attribute. Would be an AttributeError in future.
1507 (:issue:`20204`)
Yury Selivanov50960882015-05-12 00:15:05 -04001508
Yury Selivanov5376ba92015-06-22 12:19:30 -04001509* As part of :pep:`492` implementation, ``tp_reserved`` slot of
Yury Selivanovf3e40fa2015-05-21 11:50:30 -04001510 :c:type:`PyTypeObject` was replaced with a
Yury Selivanov27947d52015-06-23 15:09:58 -04001511 :c:member:`tp_as_async` slot. Refer to :ref:`coro-objects` for
Yury Selivanov5376ba92015-06-22 12:19:30 -04001512 new types, structures and functions.