blob: 3239ce537a5dcb733ff4f6794265bbe7ef44b69f [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
8.. Rules for maintenance:
9
10 * Anyone can add text to this document. Do not spend very much time
11 on the wording of your changes, because your text will probably
12 get rewritten to some degree.
13
14 * The maintainer will go through Misc/NEWS periodically and add
15 changes; it's therefore more important to add your changes to
16 Misc/NEWS than to this file.
17
18 * This is not a complete list of every single change; completeness
19 is the purpose of Misc/NEWS. Some changes I consider too small
20 or esoteric to include. If such a change is added to the text,
21 I'll just remove it. (This is another reason you shouldn't spend
22 too much time on writing your addition.)
23
24 * If you want to draw your new text to the attention of the
25 maintainer, add 'XXX' to the beginning of the paragraph or
26 section.
27
28 * It's OK to just add a fragmentary note about a change. For
29 example: "XXX Describe the transmogrify() function added to the
30 socket module." The maintainer will research the change and
31 write the necessary text.
32
33 * You can comment out your additions if you like, but it's not
34 necessary (especially when a final release is some months away).
35
36 * Credit the author of a patch or bugfix. Just the name is
37 sufficient; the e-mail address isn't necessary.
38
39 * It's helpful to add the bug/patch number as a comment:
40
41 XXX Describe the transmogrify() function added to the socket
42 module.
43 (Contributed by P.Y. Developer in :issue:`12345`.)
44
45 This saves the maintainer the effort of going through the Mercurial log
46 when researching a change.
47
48This article explains the new features in Python 3.5, compared to 3.4.
49
50For 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.
Victor Stinner01adf062014-03-18 00:53:32 +010074
75New library modules:
76
Brett Cannoncc4dfc12015-03-13 10:40:49 -040077* :mod:`zipapp`: :ref:`Improving Python ZIP Application Support
78 <whatsnew-zipapp>` (:pep:`441`).
Victor Stinner01adf062014-03-18 00:53:32 +010079
80New built-in features:
81
Victor Stinner93692bb2015-03-30 15:04:45 +020082* ``bytes % args``, ``bytearray % args``: :pep:`461` - Adding ``%`` formatting
83 to bytes and bytearray
Gregory P. Smith8cb65692015-04-25 23:22:26 +000084* ``b'\xf0\x9f\x90\x8d'.hex()``, ``bytearray(b'\xf0\x9f\x90\x8d').hex()``,
85 ``memoryview(b'\xf0\x9f\x90\x8d').hex()``: :issue:`9951` - A ``hex`` method
86 has been added to bytes, bytearray, and memoryview.
Yury Selivanove13f8f32015-07-03 00:23:30 -040087* Generators have new ``gi_yieldfrom`` attribute, which returns the
88 object being iterated by ``yield from`` expressions. (Contributed
89 by Benno Leslie and Yury Selivanov in :issue:`24450`.)
Yury Selivanovf488fb42015-07-03 01:04:23 -040090* New :exc:`RecursionError` exception. (Contributed by Georg Brandl
91 in :issue:`19235`.)
Victor Stinner01adf062014-03-18 00:53:32 +010092
93Implementation improvements:
94
Victor Stinner71430292014-03-18 01:18:21 +010095* When the ``LC_TYPE`` locale is the POSIX locale (``C`` locale),
96 :py:data:`sys.stdin` and :py:data:`sys.stdout` are now using the
97 ``surrogateescape`` error handler, instead of the ``strict`` error handler
98 (:issue:`19977`).
Victor Stinner01adf062014-03-18 00:53:32 +010099
Brett Cannonf299abd2015-04-13 14:21:02 -0400100* :pep:`488`, the elimination of ``.pyo`` files.
Nick Coghland5cacbb2015-05-23 22:24:10 +1000101* :pep:`489`, multi-phase initialization of extension modules.
Brett Cannonf299abd2015-04-13 14:21:02 -0400102
Victor Stinner01adf062014-03-18 00:53:32 +0100103Significantly Improved Library Modules:
104
Yury Selivanov58444362015-05-30 10:49:09 -0400105* :class:`collections.OrderedDict` is now implemented in C, which improves
106 its performance between 4x to 100x times. Contributed by Eric Snow in
107 :issue:`16991`.
108
Gregory P. Smithad577b92015-05-22 16:18:14 -0700109* You may now pass bytes to the :mod:`tempfile` module's APIs and it will
110 return the temporary pathname as bytes instead of str. It also accepts
111 a value of ``None`` on parameters where only str was accepted in the past to
112 do the right thing based on the types of the other inputs. Two functions,
113 :func:`gettempdirb` and :func:`gettempprefixb`, have been added to go along
114 with this. This behavior matches that of the :mod:`os` APIs.
Victor Stinner01adf062014-03-18 00:53:32 +0100115
116Security improvements:
117
118* None yet.
119
120Please read on for a comprehensive list of user-facing changes.
121
122
123.. PEP-sized items next.
124
125.. _pep-4XX:
126
127.. PEP 4XX: Virtual Environments
128.. =============================
129
130
131.. (Implemented by Foo Bar.)
132
133.. .. seealso::
134
135 :pep:`4XX` - Python Virtual Environments
136 PEP written by Carl Meyer
137
138
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400139PEP 492 - Coroutines with async and await syntax
140------------------------------------------------
141
142The PEP added dedicated syntax for declaring :term:`coroutines <coroutine>`,
143:keyword:`await` expressions, new asynchronous :keyword:`async for`
144and :keyword:`async with` statements.
145
146Example::
147
148 async def read_data(db):
149 async with db.transaction():
150 data = await db.fetch('SELECT ...')
151
152PEP written and implemented by Yury Selivanov.
153
154.. seealso::
155
156 :pep:`492` -- Coroutines with async and await syntax
157
158
Benjamin Peterson3d4a4572015-05-31 00:22:42 -0500159PEP 461 - Formatting support for bytes and bytearray
160----------------------------------------------------
Victor Stinner93692bb2015-03-30 15:04:45 +0200161
162This PEP proposes adding % formatting operations similar to Python 2's ``str``
163type to :class:`bytes` and :class:`bytearray`.
164
165Examples::
166
167 >>> b'Hello %s!' % b'World'
168 b'Hello World!'
169 >>> b'x=%i y=%f' % (1, 2.5)
170 b'x=1 y=2.500000'
171
172Unicode is not allowed for ``%s``, but it is accepted by ``%a`` (equivalent of
173``repr(obj).encode('ascii', 'backslashreplace')``)::
174
175 >>> b'Hello %s!' % 'World'
176 Traceback (most recent call last):
177 File "<stdin>", line 1, in <module>
178 TypeError: %b requires bytes, or an object that implements __bytes__, not 'str'
179 >>> b'price: %a' % '10€'
180 b"price: '10\\u20ac'"
181
182.. seealso::
183
184 :pep:`461` -- Adding % formatting to bytes and bytearray
185
186
187PEP 465 - A dedicated infix operator for matrix multiplication
188--------------------------------------------------------------
189
190This PEP proposes a new binary operator to be used for matrix multiplication,
R David Murrayef2a3972015-04-01 09:15:02 -0400191called ``@``. (Mnemonic: ``@`` is ``*`` for mATrices.)
Victor Stinner93692bb2015-03-30 15:04:45 +0200192
193.. seealso::
194
195 :pep:`465` -- A dedicated infix operator for matrix multiplication
196
Victor Stinner6036e442015-03-08 01:58:04 +0100197
198PEP 471 - os.scandir() function -- a better and faster directory iterator
199-------------------------------------------------------------------------
200
Victor Stinner37f20342015-03-10 13:29:41 +0100201:pep:`471` adds a new directory iteration function, :func:`os.scandir`,
202to the standard library. Additionally, :func:`os.walk` is now
203implemented using :func:`os.scandir`, which speeds it up by 3-5 times
204on POSIX systems and by 7-20 times on Windows systems.
205
206PEP and implementation written by Ben Hoyt with the help of Victor Stinner.
Victor Stinner6036e442015-03-08 01:58:04 +0100207
208.. seealso::
209
210 :pep:`471` -- os.scandir() function -- a better and faster directory
Victor Stinner37f20342015-03-10 13:29:41 +0100211 iterator
Victor Stinner6036e442015-03-08 01:58:04 +0100212
213
Charles-François Natali6e6c59b2015-02-07 13:27:50 +0000214PEP 475: Retry system calls failing with EINTR
215----------------------------------------------
216
Victor Stinnerf70e1ca2015-03-30 21:16:11 +0200217:pep:`475` adds support for automatic retry of system calls failing with
218:py:data:`~errno.EINTR`: this means that user code doesn't have to deal with
219EINTR or :exc:`InterruptedError` manually, and should make it more robust
220against asynchronous signal reception.
Charles-François Natali6e6c59b2015-02-07 13:27:50 +0000221
222.. seealso::
223
224 :pep:`475` -- Retry system calls failing with EINTR
Victor Stinner01adf062014-03-18 00:53:32 +0100225
226
Yury Selivanov8d006e72015-05-22 11:30:45 -0400227PEP 479: Change StopIteration handling inside generators
228--------------------------------------------------------
229
230:pep:`479` changes the behavior of generators: when a :exc:`StopIteration`
231exception is raised inside a generator, it is replaced with a
232:exc:`RuntimeError`. To enable the feature a ``__future__`` import should
233be used::
234
235 from __future__ import generator_stop
236
237Without a ``__future__`` import, a :exc:`PendingDeprecationWarning` will be
238raised.
239
240PEP written by Chris Angelico and Guido van Rossum. Implemented by
241Chris Angelico, Yury Selivanov and Nick Coghlan.
242
243.. seealso::
244
245 :pep:`479` -- Change StopIteration handling inside generators
246
247
Steve Dower76998fe2015-02-26 14:25:33 -0800248PEP 486: Make the Python Launcher aware of virtual environments
249---------------------------------------------------------------
250
251:pep:`486` makes the Windows launcher (see :pep:`397`) aware of an active
252virtual environment. When the default interpreter would be used and the
253``VIRTUAL_ENV`` environment variable is set, the interpreter in the virtual
254environment will be used.
255
256.. seealso::
257
258 :pep:`486` -- Make the Python Launcher aware of virtual environments
259
Brett Cannonf299abd2015-04-13 14:21:02 -0400260
261PEP 488: Elimination of PYO files
262---------------------------------
263
264:pep:`488` does away with the concept of ``.pyo`` files. This means that
Benjamin Petersone3283232015-05-26 21:40:28 -0500265``.pyc`` files represent both unoptimized and optimized bytecode. To prevent the
266need to constantly regenerate bytecode files, ``.pyc`` files now have an
267optional ``opt-`` tag in their name when the bytecode is optimized. This has the
268side-effect of no more bytecode file name clashes when running under either
269``-O`` or ``-OO``. Consequently, bytecode files generated from ``-O``, and
270``-OO`` may now exist simultaneously. :func:`importlib.util.cache_from_source`
271has an updated API to help with this change.
Brett Cannonf299abd2015-04-13 14:21:02 -0400272
273.. seealso::
274
275 :pep:`488` -- Elimination of PYO files
276
277
Nick Coghland5cacbb2015-05-23 22:24:10 +1000278PEP 489: Multi-phase extension module initialization
279----------------------------------------------------
280
281:pep:`489` updates extension module initialization to take advantage of the
282two step module loading mechanism introduced by :pep:`451` in Python 3.4.
283
284This change brings the import semantics of extension modules that opt-in to
285using the new mechanism much closer to those of Python source and bytecode
Nick Coghlan2ab5b092015-07-03 19:49:15 +1000286modules, including the ability to use any valid identifier as a module name,
Nick Coghland5cacbb2015-05-23 22:24:10 +1000287rather than being restricted to ASCII.
288
289.. seealso::
290
291 :pep:`488` -- Multi-phase extension module initialization
292
Tal Einatd5519ed2015-05-31 22:05:00 +0300293PEP 485: A function for testing approximate equality
294----------------------------------------------------
295
296:pep:`485` adds the :func:`math.isclose` and :func:`cmath.isclose`
297functions which tell whether two values are approximately equal or
298"close" to each other. Whether or not two values are considered
299close is determined according to given absolute and relative tolerances.
300
301.. seealso::
302
303 :pep:`485` -- A function for testing approximate equality
304
Victor Stinner01adf062014-03-18 00:53:32 +0100305Other Language Changes
306======================
307
308Some smaller changes made to the core Python language are:
309
Serhiy Storchaka07985ef2015-01-25 22:56:57 +0200310* Added the ``'namereplace'`` error handlers. The ``'backslashreplace'``
311 error handlers now works with decoding and translating.
312 (Contributed by Serhiy Storchaka in :issue:`19676` and :issue:`22286`.)
Victor Stinner01adf062014-03-18 00:53:32 +0100313
Serhiy Storchaka1dd49822015-03-20 16:54:57 +0200314* The :option:`-b` option now affects comparisons of :class:`bytes` with
315 :class:`int`. (Contributed by Serhiy Storchaka in :issue:`23681`)
Victor Stinner01adf062014-03-18 00:53:32 +0100316
Serhiy Storchakaad8a1c32015-05-12 23:16:55 +0300317* New Kazakh :ref:`codec <standard-encodings>` ``kz1048``. (Contributed by
318 Serhiy Storchaka in :issue:`22682`.)
319
Raymond Hettingereac503a2015-05-13 01:09:59 -0700320* Property docstrings are now writable. This is especially useful for
321 :func:`collections.namedtuple` docstrings.
322 (Contributed by Berker Peksag in :issue:`24064`.)
323
Serhiy Storchakaf0eeedf2015-05-12 23:24:19 +0300324* New Tajik :ref:`codec <standard-encodings>` ``koi8_t``. (Contributed by
325 Serhiy Storchaka in :issue:`22681`.)
326
Victor Stinner01adf062014-03-18 00:53:32 +0100327
328New Modules
329===========
330
Brett Cannoncc4dfc12015-03-13 10:40:49 -0400331.. _whatsnew-zipapp:
Victor Stinner01adf062014-03-18 00:53:32 +0100332
Brett Cannoncc4dfc12015-03-13 10:40:49 -0400333zipapp
334------
335
336The new :mod:`zipapp` module (specified in :pep:`441`) provides an API and
337command line tool for creating executable Python Zip Applications, which
338were introduced in Python 2.6 in :issue:`1739468` but which were not well
339publicised, either at the time or since.
340
341With the new module, bundling your application is as simple as putting all
342the files, including a ``__main__.py`` file, into a directory ``myapp``
343and running::
344
345 $ python -m zipapp myapp
346 $ python myapp.pyz
Victor Stinner01adf062014-03-18 00:53:32 +0100347
348
349Improved Modules
350================
351
Berker Peksag8089cd62015-02-14 01:39:17 +0200352argparse
353--------
354
355* :class:`~argparse.ArgumentParser` now allows to disable
356 :ref:`abbreviated usage <prefix-matching>` of long options by setting
357 :ref:`allow_abbrev` to ``False``.
358 (Contributed by Jonathan Paugh, Steven Bethard, paul j3 and Daniel Eriksson.)
359
Berker Peksagbf5e9602015-02-06 10:21:37 +0200360cgi
361---
362
Berker Peksagbd09d7b2015-02-11 15:32:34 +0200363* :class:`~cgi.FieldStorage` now supports the context management protocol.
Berker Peksagbf5e9602015-02-06 10:21:37 +0200364 (Contributed by Berker Peksag in :issue:`20289`.)
365
Tal Einatd5519ed2015-05-31 22:05:00 +0300366cmath
367-----
368
369* :func:`cmath.isclose` function added.
370 (Contributed by Chris Barker and Tal Einat in :issue:`24270`.)
371
372
R David Murrayc31e6222014-09-29 11:25:00 -0400373code
374----
375
376* The :func:`code.InteractiveInterpreter.showtraceback` method now prints
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200377 the full chained traceback, just like the interactive interpreter.
Berker Peksag088ca8b2015-02-06 10:17:49 +0200378 (Contributed by Claudiu Popa in :issue:`17442`.)
R David Murrayc31e6222014-09-29 11:25:00 -0400379
Raymond Hettingereac503a2015-05-13 01:09:59 -0700380collections
381-----------
382
383* You can now update docstrings produced by :func:`collections.namedtuple`::
384
385 Point = namedtuple('Point', ['x', 'y'])
386 Point.__doc__ = 'ordered pair'
387 Point.x.__doc__ = 'abscissa'
388 Point.y.__doc__ = 'ordinate'
389
390 (Contributed by Berker Peksag in :issue:`24064`.)
391
Brett Cannonf1a8df02014-09-12 10:39:48 -0400392compileall
393----------
394
395* :func:`compileall.compile_dir` and :mod:`compileall`'s command-line interface
396 can now do parallel bytecode compilation.
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200397 (Contributed by Claudiu Popa in :issue:`16104`.)
Brett Cannonf1a8df02014-09-12 10:39:48 -0400398
Berker Peksagbb44fe02014-11-28 23:28:06 +0200399contextlib
400----------
401
402* The new :func:`contextlib.redirect_stderr` context manager(similar to
403 :func:`contextlib.redirect_stdout`) makes it easier for utility scripts to
404 handle inflexible APIs that write their output to :data:`sys.stderr` and
405 don't provide any options to redirect it.
406 (Contributed by Berker Peksag in :issue:`22389`.)
407
Steve Dowerd2bc3892015-04-15 18:06:05 -0400408curses
409------
410* The new :func:`curses.update_lines_cols` function updates the variables
411 :envvar:`curses.LINES` and :envvar:`curses.COLS`.
412
Berker Peksag102029d2015-03-15 01:18:47 +0200413difflib
414-------
415
416* The charset of the HTML document generated by :meth:`difflib.HtmlDiff.make_file`
417 can now be customized by using *charset* keyword-only parameter. The default
418 charset of HTML document changed from ``'ISO-8859-1'`` to ``'utf-8'``.
419 (Contributed by Berker Peksag in :issue:`2052`.)
420
Greg Ward4d9d2562015-04-20 20:21:21 -0400421* It's now possible to compare lists of byte strings with
422 :func:`difflib.diff_bytes` (fixes a regression from Python 2).
423
Berker Peksag618e3152015-01-27 02:59:09 +0200424distutils
425---------
426
427* The ``build`` and ``build_ext`` commands now accept a ``-j``
428 option to enable parallel building of extension modules.
429 (Contributed by Antoine Pitrou in :issue:`5309`.)
430
Serhiy Storchakab9cec6a2015-05-16 22:13:27 +0300431* Added support for the LZMA compression.
432 (Contributed by Serhiy Storchaka in :issue:`16314`.)
433
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200434doctest
435-------
Giampaolo Rodola'e09fb712014-04-04 15:34:17 +0200436
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200437* :func:`doctest.DocTestSuite` returns an empty :class:`unittest.TestSuite` if
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200438 *module* contains no docstrings instead of raising :exc:`ValueError`.
439 (Contributed by Glenn Jones in :issue:`15916`.)
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200440
R David Murrayb744f3a2015-05-16 15:41:07 -0400441email
442-----
443
R David Murrayfdb23c22015-05-17 14:24:33 -0400444* A new policy option :attr:`~email.policy.Policy.mangle_from_` controls
445 whether or not lines that start with "From " in email bodies are prefixed with
446 a '>' character by generators. The default is ``True`` for
447 :attr:`~email.policy.compat32` and ``False`` for all other policies.
448 (Contributed by Milan Oberkirch in :issue:`20098`.)
449
R David Murrayb744f3a2015-05-16 15:41:07 -0400450* A new method :meth:`~email.message.Message.get_content_disposition` provides
451 easy access to a canonical value for the :mailheader:`Content-Disposition`
452 header (``None`` if there is no such header). (Contributed by Abhilash Raj
453 in :issue:`21083`.)
454
R David Murray224ef3e2015-05-17 11:29:21 -0400455* A new policy option :attr:`~email.policy.EmailPolicy.utf8` can be set
456 ``True`` to encode email headers using the utf8 charset instead of using
457 encoded words. This allows ``Messages`` to be formatted according to
458 :rfc:`6532` and used with an SMTP server that supports the :rfc:`6531`
459 ``SMTPUTF8`` extension. (Contributed by R. David Murray in :issue:`24211`.)
460
Serhiy Storchakac2edcdd2014-09-11 12:17:37 +0300461glob
462----
463
464* :func:`~glob.iglob` and :func:`~glob.glob` now support recursive search in
465 subdirectories using the "``**``" pattern.
466 (Contributed by Serhiy Storchaka in :issue:`13968`.)
467
Guido van Rossum7ca13532015-05-23 15:27:51 -0700468idlelib and IDLE
Terry Jan Reedy44825cf2015-05-23 18:19:42 -0400469----------------
470
471Since idlelib implements the IDLE shell and editor and is not intended for
472import by other programs, it gets improvements with every release. See
473:file:`Lib/idlelib/NEWS.txt` for a cumulative list of changes since 3.4.0,
474as well as changes made in future 3.5.x releases. This file is also available
475from the IDLE Help -> About Idle dialog.
476
Serhiy Storchaka38684c32014-09-09 19:07:49 +0300477imaplib
478-------
479
480* :class:`IMAP4` now supports the context management protocol. When used in a
481 :keyword:`with` statement, the IMAP4 ``LOGOUT`` command will be called
482 automatically at the end of the block. (Contributed by Tarek Ziadé and
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200483 Serhiy Storchaka in :issue:`4972`.)
Serhiy Storchaka38684c32014-09-09 19:07:49 +0300484
R David Murraya6429db2015-05-10 19:17:23 -0400485* :mod:`imaplib` now supports :rfc:`5161`: the :meth:`~imaplib.IMAP4.enable`
486 extension), and :rfc:`6855`: utf-8 support (internationalized email, via the
487 ``UTF8=ACCEPT`` argument to :meth:`~imaplib.IMAP4.enable`). A new attribute,
488 :attr:`~imaplib.IMAP4.utf8_enabled`, tracks whether or not :rfc:`6855`
489 support is enabled. Milan Oberkirch, R. David Murray, and Maciej Szulik in
490 :issue:`21800`.)
491
492* :mod:`imaplib` now automatically encodes non-ASCII string usernames and
493 passwords using ``UTF8``, as recommended by the RFCs. (Contributed by Milan
494 Oberkirch in :issue:`21800`.)
495
R David Murray2f608202014-06-26 12:27:57 -0400496imghdr
497------
498
499* :func:`~imghdr.what` now recognizes the `OpenEXR <http://www.openexr.com>`_
Berker Peksag088ca8b2015-02-06 10:17:49 +0200500 format. (Contributed by Martin Vignali and Claudiu Popa in :issue:`20295`.)
R David Murray2f608202014-06-26 12:27:57 -0400501
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200502importlib
503---------
504
505* :class:`importlib.util.LazyLoader` allows for the lazy loading of modules in
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200506 applications where startup time is paramount.
507 (Contributed by Brett Cannon in :issue:`17621`.)
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200508
509* :func:`importlib.abc.InspectLoader.source_to_code` is now a
510 static method to make it easier to work with source code in a string.
511 With a module object that you want to initialize you can then use
512 ``exec(code, module.__dict__)`` to execute the code in the module.
513
Brett Cannon2a17bde2014-05-30 14:55:29 -0400514* :func:`importlib.util.module_from_spec` is now the preferred way to create a
515 new module. Compared to :class:`types.ModuleType`, this new function will set
516 the various import-controlled attributes based on the passed-in spec object.
517
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200518inspect
519-------
Victor Stinner01adf062014-03-18 00:53:32 +0100520
Yury Selivanova5d63dd2014-03-27 11:31:43 -0400521* :class:`inspect.Signature` and :class:`inspect.Parameter` are now
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200522 picklable and hashable. (Contributed by Yury Selivanov in :issue:`20726`
523 and :issue:`20334`.)
Yury Selivanova5d63dd2014-03-27 11:31:43 -0400524
Yury Selivanovb907a512015-05-16 13:45:09 -0400525* New method :meth:`inspect.BoundArguments.apply_defaults`. (Contributed
526 by Yury Selivanov in :issue:`24190`.)
527
Yury Selivanovda396452014-03-27 12:09:24 -0400528* New class method :meth:`inspect.Signature.from_callable`, which makes
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200529 subclassing of :class:`~inspect.Signature` easier. (Contributed
530 by Yury Selivanov and Eric Snow in :issue:`17373`.)
Yury Selivanovda396452014-03-27 12:09:24 -0400531
Yury Selivanovbcd4fc12015-05-20 14:30:08 -0400532* New argument ``follow_wrapped`` for :func:`inspect.signature`.
533 (Contributed by Yury Selivanov in :issue:`20691`.)
534
Yury Selivanova74b5e52015-06-30 18:19:01 -0400535* New :func:`~inspect.iscoroutine` and :func:`~inspect.iscoroutinefunction`
536 functions. (Contributed by Yury Selivanov in :issue:`24017`.)
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400537
Yury Selivanov5376ba92015-06-22 12:19:30 -0400538* New :func:`~inspect.getcoroutinelocals` and :func:`~inspect.getcoroutinestate`
539 functions. (Contributed by Yury Selivanov in :issue:`24400`.)
540
Antoine Pitrou0dfce562014-05-15 22:55:40 +0200541ipaddress
542---------
543
544* :class:`ipaddress.IPv4Network` and :class:`ipaddress.IPv6Network` now
545 accept an ``(address, netmask)`` tuple argument, so as to easily construct
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200546 network objects from existing addresses. (Contributed by Peter Moody
547 and Antoine Pitrou in :issue:`16531`.)
Antoine Pitrou0dfce562014-05-15 22:55:40 +0200548
Berker Peksag39e4c4d2014-11-10 09:56:54 +0200549json
550----
551
552* The output of :mod:`json.tool` command line interface is now in the same
553 order as the input. Use the :option:`--sort-keys` option to sort the output
554 of dictionaries alphabetically by key. (Contributed by Berker Peksag in
555 :issue:`21650`.)
556
Serhiy Storchaka47efb4a2015-01-26 13:16:30 +0200557* JSON decoder now raises :exc:`json.JSONDecodeError` instead of
558 :exc:`ValueError`. (Contributed by Serhiy Storchaka in :issue:`19361`.)
559
Tal Einatf67b0a32015-05-31 22:18:31 +0300560math
561----
562
563* :data:`math.inf` and :data:`math.nan` constants added. (Contributed by Mark
564 Dickinson in :issue:`23185`.)
565* :func:`math.isclose` function added.
566 (Contributed by Chris Barker and Tal Einat in :issue:`24270`.)
567
Zachary Ware63f277b2014-06-19 09:46:37 -0500568os
569--
570
Victor Stinner37f20342015-03-10 13:29:41 +0100571* New :func:`os.scandir` function that exposes file information from
572 the operating system when listing a directory. :func:`os.scandir`
573 returns an iterator of :class:`os.DirEntry` objects corresponding to
574 the entries in the directory given by *path*. (Contributed by Ben
575 Hoyt with the help of Victor Stinner in :issue:`22524`.)
Victor Stinner6036e442015-03-08 01:58:04 +0100576
Victor Stinnere1d24f72014-07-24 12:44:07 +0200577* :class:`os.stat_result` now has a :attr:`~os.stat_result.st_file_attributes`
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200578 attribute on Windows. (Contributed by Ben Hoyt in :issue:`21719`.)
Zachary Ware63f277b2014-06-19 09:46:37 -0500579
Serhiy Storchaka38220932015-03-31 15:31:53 +0300580os.path
581-------
582
583* New :func:`~os.path.commonpath` function that extracts common path prefix.
584 Unlike the :func:`~os.path.commonprefix` function, it always returns a valid
585 patch. (Contributed by Rafik Draoui and Serhiy Storchaka in :issue:`10395`.)
586
Serhiy Storchaka58e41342015-03-31 14:07:24 +0300587pickle
588------
589
590* Serializing more "lookupable" objects (such as unbound methods or nested
591 classes) now are supported with pickle protocols < 4.
592 (Contributed by Serhiy Storchaka in :issue:`23611`.)
593
R David Murrayb8cd3e42015-05-16 15:05:53 -0400594poplib
595------
596
597* A new command :meth:`~poplib.POP3.utf8` enables :rfc:`6856`
598 (internationalized email) support if the POP server supports it. (Contributed
599 by Milan OberKirch in :issue:`21804`.)
600
Serhiy Storchaka9baa5b22014-09-29 22:49:23 +0300601re
602--
603
604* Number of capturing groups in regular expression is no longer limited by 100.
605 (Contributed by Serhiy Storchaka in :issue:`22437`.)
606
Serhiy Storchaka7438e4b2014-10-10 11:06:31 +0300607* Now unmatched groups are replaced with empty strings in :func:`re.sub`
608 and :func:`re.subn`. (Contributed by Serhiy Storchaka in :issue:`1519638`.)
609
R David Murray6ffface2014-06-11 14:40:13 -0400610shutil
611------
612
613* :func:`~shutil.move` now accepts a *copy_function* argument, allowing,
614 for example, :func:`~shutil.copy` to be used instead of the default
615 :func:`~shutil.copy2` if there is a need to ignore metadata. (Contributed by
616 Claudiu Popa in :issue:`19840`.)
617
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200618signal
619------
Brett Cannona04dbe42014-04-04 13:53:38 -0400620
Victor Stinnerbbe38032015-04-01 16:32:32 +0200621* On Windows, :func:`signal.set_wakeup_fd` now also supports socket handles.
622 (Contributed by Victor Stinner in :issue:`22018`.)
623
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200624* Different constants of :mod:`signal` module are now enumeration values using
625 the :mod:`enum` module. This allows meaningful names to be printed during
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200626 debugging, instead of integer “magic numbers”. (Contributed by Giampaolo
627 Rodola' in :issue:`21076`.)
R David Murray1976d9b2014-04-14 20:28:36 -0400628
R David Murray554bcbf2014-06-11 11:18:08 -0400629smtpd
630-----
631
632* Both :class:`~smtpd.SMTPServer` and :class:`smtpd.SMTPChannel` now accept a
633 *decode_data* keyword to determine if the DATA portion of the SMTP
634 transaction is decoded using the ``utf-8`` codec or is instead provided to
635 :meth:`~smtpd.SMTPServer.process_message` as a byte string. The default
636 is ``True`` for backward compatibility reasons, but will change to ``False``
R David Murraya33df312015-05-11 12:11:40 -0400637 in Python 3.6. If *decode_data* is set to ``False``, the
638 :meth:`~smtpd.SMTPServer.process_message` method must be prepared to accept
639 keyword arguments. (Contributed by Maciej Szulik in :issue:`19662`.)
640
641* :class:`~smtpd.SMTPServer` now advertises the ``8BITMIME`` extension
642 (:rfc:`6152`) if if *decode_data* has been set ``True``. If the client
643 specifies ``BODY=8BITMIME`` on the ``MAIL`` command, it is passed to
644 :meth:`~smtpd.SMTPServer.process_message` via the ``mail_options`` keyword.
645 (Contributed by Milan Oberkirch and R. David Murray in :issue:`21795`.)
646
647* :class:`~smtpd.SMTPServer` now supports the ``SMTPUTF8`` extension
648 (:rfc:`6531`: Internationalized Email). If the client specified ``SMTPUTF8
649 BODY=8BITMIME`` on the ``MAIL`` command, they are passed to
650 :meth:`~smtpd.SMTPServer.process_message` via the ``mail_options`` keyword.
651 It is the responsibility of the :meth:`~smtpd.SMTPServer.process_message`
652 method to correctly handle the ``SMTPUTF8`` data. (Contributed by Milan
653 Oberkirch in :issue:`21725`.)
R David Murray554bcbf2014-06-11 11:18:08 -0400654
R David Murray6fe56a32014-06-11 13:48:58 -0400655* It is now possible to provide, directly or via name resolution, IPv6
656 addresses in the :class:`~smtpd.SMTPServer` constructor, and have it
657 successfully connect. (Contributed by Milan Oberkirch in :issue:`14758`.)
658
R David Murray76e13c12014-07-03 14:47:46 -0400659smtplib
660-------
661
662* A new :meth:`~smtplib.SMTP.auth` method provides a convenient way to
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200663 implement custom authentication mechanisms.
664 (Contributed by Milan Oberkirch in :issue:`15014`.)
R David Murray76e13c12014-07-03 14:47:46 -0400665
R David Murray0c49b892015-04-16 17:14:42 -0400666* Additional debuglevel (2) shows timestamps for debug messages in
667 :class:`smtplib.SMTP`. (Contributed by Gavin Chappell and Maciej Szulik in
668 :issue:`16914`.)
669
R David Murray83084442015-05-17 19:27:22 -0400670* :mod:`smtplib` now supports :rfc:`6531` (SMTPUTF8) in both the
671 :meth:`~smtplib.SMTP.sendmail` and :meth:`~smtplib.SMTP.send_message`
672 commands. (Contributed by Milan Oberkirch and R. David Murray in
673 :issue:`22027`.)
R David Murraycee7cf62015-05-16 13:58:14 -0400674
R David Murray4487dd02014-10-09 16:59:30 -0400675sndhdr
676------
677
678* :func:`~sndhdr.what` and :func:`~sndhdr.whathdr` now return
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200679 :func:`~collections.namedtuple`.
680 (Contributed by Claudiu Popa in :issue:`18615`.)
R David Murray4487dd02014-10-09 16:59:30 -0400681
Giampaolo Rodola'915d1412014-06-11 03:54:30 +0200682socket
683------
684
685* New :meth:`socket.socket.sendfile` method allows to send a file over a socket
686 by using high-performance :func:`os.sendfile` function on UNIX resulting in
687 uploads being from 2x to 3x faster than when using plain
688 :meth:`socket.socket.send`.
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200689 (Contributed by Giampaolo Rodola' in :issue:`17552`.)
Giampaolo Rodola'915d1412014-06-11 03:54:30 +0200690
Gregory P. Smith6e730002015-04-14 16:14:25 -0700691subprocess
692----------
693
694* The new :func:`subprocess.run` function runs subprocesses and returns a
695 :class:`subprocess.CompletedProcess` object. It Provides a more consistent
696 API than :func:`~subprocess.call`, :func:`~subprocess.check_call` and
697 :func:`~subprocess.check_output`.
698
Yury Selivanov4640b302015-05-31 17:21:38 -0400699sys
700---
701
702* New :func:`~sys.set_coroutine_wrapper` and :func:`~sys.get_coroutine_wrapper`
703 functions. (Contributed by Yury Selivanov in :issue:`24017`.)
704
Eric V. Smith7a803892015-04-15 10:27:58 -0400705sysconfig
706---------
707
708* The user scripts directory on Windows is now versioned.
709 (Contributed by Paul Moore in :issue:`23437`.)
710
711tarfile
712-------
713
714* The :func:`tarfile.open` function now supports ``'x'`` (exclusive creation)
715 mode. (Contributed by Berker Peksag in :issue:`21717`.)
716
717* The :meth:`~tarfile.TarFile.extractall` and :meth:`~tarfile.TarFile.extract`
718 methods now take a keyword parameter *numeric_only*. If set to ``True``,
719 the extracted files and directories will be owned by the numeric uid and gid
720 from the tarfile. If set to ``False`` (the default, and the behavior in
721 versions prior to 3.5), they will be owned bythe named user and group in the
722 tarfile. (Contributed by Michael Vogt and Eric Smith in :issue:`23193`.)
723
Victor Stinnerae586492014-09-02 23:18:25 +0200724time
725----
726
Berker Peksag882c95c2014-10-09 11:46:56 +0300727* The :func:`time.monotonic` function is now always available. (Contributed by
728 Victor Stinner in :issue:`22043`.)
Victor Stinnerae586492014-09-02 23:18:25 +0200729
Zachary Ware7dc9dea2015-05-22 11:36:53 -0500730tkinter
731-------
732
Nick Coghland5cacbb2015-05-23 22:24:10 +1000733* The :mod:`tkinter._fix` module used for setting up the Tcl/Tk environment
Berker Peksag1a90b172015-05-24 00:26:05 +0300734 on Windows has been replaced by a private function in the :mod:`_tkinter`
Zachary Ware7dc9dea2015-05-22 11:36:53 -0500735 module which makes no permanent changes to environment variables.
736 (Contributed by Zachary Ware in :issue:`20035`.)
737
Yury Selivanovf3e40fa2015-05-21 11:50:30 -0400738types
739-----
740
741* New :func:`~types.coroutine` function. (Contributed by Yury Selivanov
742 in :issue:`24017`.)
743
Yury Selivanov5376ba92015-06-22 12:19:30 -0400744* New :class:`~types.CoroutineType`. (Contributed by Yury Selivanov
745 in :issue:`24400`.)
746
Berker Peksagbd09d7b2015-02-11 15:32:34 +0200747urllib
748------
Nick Coghlanc216c482014-11-12 23:33:50 +1000749
R David Murray4c7f9952015-04-16 16:36:18 -0400750* A new :class:`~urllib.request.HTTPPasswordMgrWithPriorAuth` allows HTTP Basic
751 Authentication credentials to be managed so as to eliminate unnecessary
752 ``401`` response handling, or to unconditionally send credentials
753 on the first request in order to communicate with servers that return a
754 ``404`` response instead of a ``401`` if the ``Authorization`` header is not
755 sent. (Contributed by Matej Cepl in :issue:`19494` and Akshit Khurana in
756 :issue:`7159`.)
Nick Coghlanc216c482014-11-12 23:33:50 +1000757
R David Murrayc17686f2015-05-17 20:44:50 -0400758* A new :func:`~urllib.parse.urlencode` parameter *quote_via* provides a way to
759 control the encoding of query parts if needed. (Contributed by Samwyse and
760 Arnon Yaari in :issue:`13866`.)
761
Benjamin Peterson48013832015-06-27 15:45:56 -0500762unicodedata
763-----------
764
765* The :mod:`unicodedata` module now uses data from `Unicode 8.0.0
Nick Coghlan2ab5b092015-07-03 19:49:15 +1000766 <http://unicode.org/versions/Unicode8.0.0/>`_.
Benjamin Peterson48013832015-06-27 15:45:56 -0500767
768
Berker Peksag3e887222014-07-02 08:37:22 +0300769wsgiref
770-------
771
772* *headers* parameter of :class:`wsgiref.headers.Headers` is now optional.
773 (Contributed by Pablo Torres Navarrete and SilentGhost in :issue:`5800`.)
774
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200775xmlrpc
776------
777
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200778* :class:`xmlrpc.client.ServerProxy` is now a :term:`context manager`.
779 (Contributed by Claudiu Popa in :issue:`20627`.)
Brett Cannon6eaac132014-05-09 12:28:22 -0400780
Serhiy Storchaka61de0872015-04-02 21:00:13 +0300781xml.sax
782-------
783
784* SAX parsers now support a character stream of
785 :class:`~xml.sax.xmlreader.InputSource` object.
786 (Contributed by Serhiy Storchaka in :issue:`2175`.)
787
Victor Stinner95bb7142015-03-12 15:32:03 +0100788faulthandler
789------------
790
791* :func:`~faulthandler.enable`, :func:`~faulthandler.register`,
792 :func:`~faulthandler.dump_traceback` and
793 :func:`~faulthandler.dump_traceback_later` functions now accept file
794 descriptors. (Contributed by Wei Wu in :issue:`23566`.)
795
Serhiy Storchaka77d89972015-03-23 01:09:35 +0200796zipfile
797-------
798
799* Added support for writing ZIP files to unseekable streams.
800 (Contributed by Serhiy Storchaka in :issue:`23252`.)
801
Serhiy Storchaka764fc9b2015-03-25 10:09:41 +0200802* The :func:`zipfile.ZipFile.open` function now supports ``'x'`` (exclusive
803 creation) mode. (Contributed by Serhiy Storchaka in :issue:`21717`.)
804
Victor Stinner01adf062014-03-18 00:53:32 +0100805
806Optimizations
807=============
808
Antoine Pitroub9d9ce72014-05-15 22:47:33 +0200809The following performance enhancements have been added:
Victor Stinner01adf062014-03-18 00:53:32 +0100810
Victor Stinner37f20342015-03-10 13:29:41 +0100811* :func:`os.walk` has been sped up by 3-5x on POSIX systems and 7-20x
812 on Windows. This was done using the new :func:`os.scandir` function,
813 which exposes file information from the underlying ``readdir`` and
814 ``FindFirstFile``/``FindNextFile`` system calls. (Contributed by
815 Ben Hoyt with help from Victor Stinner in :issue:`23605`.)
816
Brett Cannonf299abd2015-04-13 14:21:02 -0400817* Construction of ``bytes(int)`` (filled by zero bytes) is faster and uses less
Victor Stinner2bc4d952014-06-02 22:22:42 +0200818 memory for large objects. ``calloc()`` is used instead of ``malloc()`` to
Victor Stinnerdb067af2014-05-02 22:31:14 +0200819 allocate memory for these objects.
Victor Stinner01adf062014-03-18 00:53:32 +0100820
Antoine Pitrou0dfce562014-05-15 22:55:40 +0200821* Some operations on :class:`~ipaddress.IPv4Network` and
822 :class:`~ipaddress.IPv6Network` have been massively sped up, such as
823 :meth:`~ipaddress.IPv4Network.subnets`, :meth:`~ipaddress.IPv4Network.supernet`,
824 :func:`~ipaddress.summarize_address_range`, :func:`~ipaddress.collapse_addresses`.
825 The speed up can range from 3x to 15x.
826 (:issue:`21486`, :issue:`21487`, :issue:`20826`)
827
Serhiy Storchaka87d0b452015-02-03 11:30:10 +0200828* Many operations on :class:`io.BytesIO` are now 50% to 100% faster.
Berker Peksag9121fe82015-02-15 00:45:57 +0200829 (Contributed by Serhiy Storchaka in :issue:`15381` and David Wilson in
830 :issue:`22003`.)
Serhiy Storchaka87d0b452015-02-03 11:30:10 +0200831
Serhiy Storchakac1efe5f2015-02-11 15:54:54 +0200832* :func:`marshal.dumps` is now faster (65%-85% with versions 3--4, 20-25% with
833 versions 0--2 on typical data, and up to 5x in best cases).
834 (Contributed by Serhiy Storchaka in :issue:`20416` and :issue:`23344`.)
Serhiy Storchakace921c622015-02-11 15:53:31 +0200835
Serhiy Storchaka0d4df752015-05-12 23:12:45 +0300836* The UTF-32 encoder is now 3x to 7x faster. (Contributed by Serhiy Storchaka
837 in :issue:`15027`.)
838
Victor Stinner01adf062014-03-18 00:53:32 +0100839
840Build and C API Changes
841=======================
842
843Changes to Python's build process and to the C API include:
844
Victor Stinnerdb067af2014-05-02 22:31:14 +0200845* New ``calloc`` functions:
846
847 * :c:func:`PyMem_RawCalloc`
848 * :c:func:`PyMem_Calloc`
849 * :c:func:`PyObject_Calloc`
850 * :c:func:`_PyObject_GC_Calloc`
Victor Stinner01adf062014-03-18 00:53:32 +0100851
852
853Deprecated
854==========
855
Yury Selivanov8fa6d4f2015-05-28 17:09:14 -0400856New Keywords
857------------
858
859``async`` and ``await`` are not recommended to be used as variable, class or
860function names. Introduced by :pep:`492` in Python 3.5, they will become
861proper keywords in Python 3.7.
862
863
Victor Stinner01adf062014-03-18 00:53:32 +0100864Unsupported Operating Systems
865-----------------------------
866
Zachary Ware38019d12015-04-13 15:51:59 -0500867* Windows XP - Per :PEP:`11`, Microsoft support of Windows XP has ended.
Victor Stinner01adf062014-03-18 00:53:32 +0100868
869
870Deprecated Python modules, functions and methods
871------------------------------------------------
872
Brett Cannona77d0c32014-03-21 10:52:33 -0400873* The :mod:`formatter` module has now graduated to full deprecation and is still
874 slated for removal in Python 3.6.
Victor Stinner01adf062014-03-18 00:53:32 +0100875
R David Murray554bcbf2014-06-11 11:18:08 -0400876* :mod:`smtpd` has in the past always decoded the DATA portion of email
877 messages using the ``utf-8`` codec. This can now be controlled by the new
878 *decode_data* keyword to :class:`~smtpd.SMTPServer`. The default value is
879 ``True``, but this default is deprecated. Specify the *decode_data* keyword
880 with an appropriate value to avoid the deprecation warning.
881
R David Murray1813c172015-03-29 17:09:21 -0400882* Directly assigning values to the :attr:`~http.cookies.Morsel.key`,
883 :attr:`~http.cookies.Morsel.value` and
884 :attr:`~http.cookies.Morsel.coded_value` of :class:`~http.cookies.Morsel`
885 objects is deprecated. Use the :func:`~http.cookies.Morsel.set` method
886 instead. In addition, the undocumented *LegalChars* parameter of
887 :func:`~http.cookies.Morsel.set` is deprecated, and is now ignored.
Serhiy Storchaka9c1a9b22015-03-18 10:59:57 +0200888
Serhiy Storchakab876df42015-03-24 22:30:46 +0200889* Passing a format string as keyword argument *format_string* to the
890 :meth:`~string.Formatter.format` method of the :class:`string.Formatter`
891 class has been deprecated.
892
Berker Peksag2f3742b2015-05-13 12:32:20 +0300893* :func:`platform.dist` and :func:`platform.linux_distribution` functions are
894 now deprecated and will be removed in Python 3.7. Linux distributions use
895 too many different ways of describing themselves, so the functionality is
896 left to a package.
897 (Contributed by Vajrasky Kok and Berker Peksag in :issue:`1322`.)
Victor Stinner01adf062014-03-18 00:53:32 +0100898
Benjamin Petersonb1cc37c2015-05-20 22:09:43 -0500899* The previously undocumented ``from_function`` and ``from_builtin`` methods of
900 :class:`inspect.Signature` are deprecated. Use new
Yury Selivanov57c74fc2015-05-20 23:07:02 -0400901 :meth:`inspect.Signature.from_callable` instead. (Contributed by Yury
902 Selivanov in :issue:`24248`.)
903
Yury Selivanov945fff42015-05-22 16:28:05 -0400904* :func:`inspect.getargspec` is deprecated and scheduled to be removed in
905 Python 3.6. (See :issue:`20438` for details.)
906
907* :func:`~inspect.getfullargspec`, :func:`~inspect.getargvalues`,
908 :func:`~inspect.getcallargs`, :func:`~inspect.getargvalues`,
909 :func:`~inspect.formatargspec`, and :func:`~inspect.formatargvalues` are
910 deprecated in favor of :func:`inspect.signature` API. (See :issue:`20438`
911 for details.)
912
913
Victor Stinner01adf062014-03-18 00:53:32 +0100914Deprecated functions and types of the C API
915-------------------------------------------
916
917* None yet.
918
919
920Deprecated features
921-------------------
922
923* None yet.
924
925
R David Murraydf75fee2014-10-03 13:02:47 -0400926Removed
927=======
928
Berker Peksag8f791d32014-11-01 10:45:57 +0200929API and Feature Removals
930------------------------
931
932The following obsolete and previously deprecated APIs and features have been
933removed:
934
R David Murraydf75fee2014-10-03 13:02:47 -0400935* The ``__version__`` attribute has been dropped from the email package. The
936 email code hasn't been shipped separately from the stdlib for a long time,
937 and the ``__version__`` string was not updated in the last few releases.
938
Berker Peksag8f791d32014-11-01 10:45:57 +0200939* The internal ``Netrc`` class in the :mod:`ftplib` module was deprecated in
Serhiy Storchakac1ded292014-11-02 19:22:02 +0200940 3.4, and has now been removed.
941 (Contributed by Matt Chaput in :issue:`6623`.)
R David Murraydf75fee2014-10-03 13:02:47 -0400942
Brett Cannonf299abd2015-04-13 14:21:02 -0400943* The concept of ``.pyo`` files has been removed.
944
R David Murraye81a7732015-04-12 18:47:56 -0400945* The JoinableQueue class in the provisional asyncio module was deprecated
946 in 3.4.4 and is now removed (:issue:`23464`).
947
948
Victor Stinner01adf062014-03-18 00:53:32 +0100949Porting to Python 3.5
950=====================
951
952This section lists previously described changes and other bugfixes
953that may require changes to your code.
954
Victor Stinnerdb067af2014-05-02 22:31:14 +0200955Changes in the Python API
956-------------------------
957
Victor Stinnerf70e1ca2015-03-30 21:16:11 +0200958* :pep:`475`: Examples of functions which are now retried when interrupted
959 instead of raising :exc:`InterruptedError` if the signal handler does not
960 raise an exception:
Victor Stinnera766ddf2015-03-26 23:50:57 +0100961
Victor Stinner45ca48b2015-03-31 12:10:33 +0200962 - :func:`open`, :func:`os.open`, :func:`io.open`
Victor Stinneracd8e7c2015-04-02 13:56:29 +0200963 - functions of the :mod:`faulthandler` module
964 - :mod:`os` functions:
965
966 * :func:`os.fchdir`
967 * :func:`os.fchmod`
968 * :func:`os.fchown`
969 * :func:`os.fdatasync`
970 * :func:`os.fstat`
971 * :func:`os.fstatvfs`
972 * :func:`os.fsync`
973 * :func:`os.ftruncate`
974 * :func:`os.mkfifo`
975 * :func:`os.mknod`
976 * :func:`os.posix_fadvise`
977 * :func:`os.posix_fallocate`
978 * :func:`os.pread`
979 * :func:`os.pwrite`
980 * :func:`os.read`
981 * :func:`os.readv`
982 * :func:`os.sendfile`
983 * :func:`os.wait3`
984 * :func:`os.wait4`
985 * :func:`os.wait`
986 * :func:`os.waitid`
987 * :func:`os.waitpid`
988 * :func:`os.write`
989 * :func:`os.writev`
990 * special cases: :func:`os.close` and :func:`os.dup2` now ignore
991 :py:data:`~errno.EINTR` error, the syscall is not retried (see the PEP
992 for the rationale)
993
Victor Stinner4448c082015-03-31 11:48:34 +0200994 - :func:`select.select`, :func:`select.poll.poll`, :func:`select.epoll.poll`,
Victor Stinner45ca48b2015-03-31 12:10:33 +0200995 :func:`select.kqueue.control`, :func:`select.devpoll.poll`
Victor Stinner708d9ba2015-04-02 11:49:42 +0200996 - :func:`socket.socket` methods:
997
998 * :meth:`~socket.socket.accept`
Victor Stinner81c41db2015-04-02 11:50:57 +0200999 * :meth:`~socket.socket.connect` (except for non-blocking sockets)
Victor Stinner708d9ba2015-04-02 11:49:42 +02001000 * :meth:`~socket.socket.recv`
1001 * :meth:`~socket.socket.recvfrom`
1002 * :meth:`~socket.socket.recvmsg`
1003 * :meth:`~socket.socket.send`
1004 * :meth:`~socket.socket.sendall`
1005 * :meth:`~socket.socket.sendmsg`
1006 * :meth:`~socket.socket.sendto`
1007
Victor Stinnereb011cb2015-03-31 12:19:15 +02001008 - :func:`signal.sigtimedwait`, :func:`signal.sigwaitinfo`
Victor Stinnera766ddf2015-03-26 23:50:57 +01001009 - :func:`time.sleep`
1010
Benjamin Petersonee6bdc02014-03-20 18:00:35 -05001011* Before Python 3.5, a :class:`datetime.time` object was considered to be false
1012 if it represented midnight in UTC. This behavior was considered obscure and
1013 error-prone and has been removed in Python 3.5. See :issue:`13936` for full
1014 details.
Antoine Pitrou92c4d452014-04-29 10:05:59 +02001015
1016* :meth:`ssl.SSLSocket.send()` now raises either :exc:`ssl.SSLWantReadError`
1017 or :exc:`ssl.SSLWantWriteError` on a non-blocking socket if the operation
1018 would block. Previously, it would return 0. See :issue:`20951`.
Victor Stinnerdb067af2014-05-02 22:31:14 +02001019
Victor Stinner40ee3012014-06-16 15:59:28 +02001020* The ``__name__`` attribute of generator is now set from the function name,
1021 instead of being set from the code name. Use ``gen.gi_code.co_name`` to
1022 retrieve the code name. Generators also have a new ``__qualname__``
1023 attribute, the qualified name, which is now used for the representation
1024 of a generator (``repr(gen)``). See :issue:`21205`.
1025
Ezio Melotti045160b2014-08-02 18:54:30 +03001026* The deprecated "strict" mode and argument of :class:`~html.parser.HTMLParser`,
1027 :meth:`HTMLParser.error`, and the :exc:`HTMLParserError` exception have been
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001028 removed. (Contributed by Ezio Melotti in :issue:`15114`.)
Ezio Melotti045160b2014-08-02 18:54:30 +03001029 The *convert_charrefs* argument of :class:`~html.parser.HTMLParser` is
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001030 now ``True`` by default. (Contributed by Berker Peksag in :issue:`21047`.)
Ezio Melotti045160b2014-08-02 18:54:30 +03001031
R David Murray861470c2014-10-05 11:47:01 -04001032* Although it is not formally part of the API, it is worth noting for porting
1033 purposes (ie: fixing tests) that error messages that were previously of the
1034 form "'sometype' does not support the buffer protocol" are now of the form "a
Serhiy Storchakac1ded292014-11-02 19:22:02 +02001035 bytes-like object is required, not 'sometype'". (Contributed by Ezio Melotti
1036 in :issue:`16518`.)
R David Murray861470c2014-10-05 11:47:01 -04001037
Brett Cannonb6e25562014-11-21 12:19:28 -05001038* If the current directory is set to a directory that no longer exists then
1039 :exc:`FileNotFoundError` will no longer be raised and instead
1040 :meth:`~importlib.machinery.FileFinder.find_spec` will return ``None``
1041 **without** caching ``None`` in :data:`sys.path_importer_cache` which is
1042 different than the typical case (:issue:`22834`).
1043
Berker Peksag088ca8b2015-02-06 10:17:49 +02001044* HTTP status code and messages from :mod:`http.client` and :mod:`http.server`
1045 were refactored into a common :class:`~http.HTTPStatus` enum. The values in
1046 :mod:`http.client` and :mod:`http.server` remain available for backwards
1047 compatibility. (Contributed by Demian Brecht in :issue:`21793`.)
Serhiy Storchakae4db7692014-12-23 16:28:28 +02001048
Brett Cannon02d84542015-01-09 11:39:21 -05001049* When an import loader defines :meth:`~importlib.machinery.Loader.exec_module`
1050 it is now expected to also define
1051 :meth:`~importlib.machinery.Loader.create_module` (raises a
1052 :exc:`DeprecationWarning` now, will be an error in Python 3.6). If the loader
1053 inherits from :class:`importlib.abc.Loader` then there is nothing to do, else
1054 simply define :meth:`~importlib.machinery.Loader.create_module` to return
1055 ``None`` (:issue:`23014`).
1056
Serhiy Storchaka83e80272015-02-03 11:04:19 +02001057* :func:`re.split` always ignored empty pattern matches, so the ``'x*'``
1058 pattern worked the same as ``'x+'``, and the ``'\b'`` pattern never worked.
1059 Now :func:`re.split` raises a warning if the pattern could match
1060 an empty string. For compatibility use patterns that never match an empty
1061 string (e.g. ``'x+'`` instead of ``'x*'``). Patterns that could only match
1062 an empty string (such as ``'\b'``) now raise an error.
1063
R David Murray1813c172015-03-29 17:09:21 -04001064* The :class:`~http.cookies.Morsel` dict-like interface has been made self
1065 consistent: morsel comparison now takes the :attr:`~http.cookies.Morsel.key`
1066 and :attr:`~http.cookies.Morsel.value` into account,
1067 :meth:`~http.cookies.Morsel.copy` now results in a
R David Murrayba6ea9b2015-03-30 11:48:50 -04001068 :class:`~http.cookies.Morsel` instance rather than a :class:`dict`, and
1069 :meth:`~http.cookies.Morsel.update` will now raise an exception if any of the
R David Murray1813c172015-03-29 17:09:21 -04001070 keys in the update dictionary are invalid. In addition, the undocumented
1071 *LegalChars* parameter of :func:`~http.cookies.Morsel.set` is deprecated and
1072 is now ignored. (:issue:`2211`)
1073
Brett Cannonf299abd2015-04-13 14:21:02 -04001074* :pep:`488` has removed ``.pyo`` files from Python and introduced the optional
1075 ``opt-`` tag in ``.pyc`` file names. The
1076 :func:`importlib.util.cache_from_source` has gained an *optimization*
1077 parameter to help control the ``opt-`` tag. Because of this, the
1078 *debug_override* parameter of the function is now deprecated. `.pyo` files
1079 are also no longer supported as a file argument to the Python interpreter and
1080 thus serve no purpose when distributed on their own (i.e. sourcless code
1081 distribution). Due to the fact that the magic number for bytecode has changed
1082 in Python 3.5, all old `.pyo` files from previous versions of Python are
1083 invalid regardless of this PEP.
1084
Ned Deilycec3f562015-06-10 15:43:05 -07001085* The :mod:`socket` module now exports the CAN_RAW_FD_FRAMES constant on linux
1086 3.6 and greater.
Larry Hastingsa6cc5512015-04-13 17:48:40 -04001087
R David Murray2b781292015-04-16 12:15:09 -04001088* The `pygettext.py` Tool now uses the standard +NNNN format for timezones in
1089 the POT-Creation-Date header.
1090
R David Murray0c49b892015-04-16 17:14:42 -04001091* The :mod:`smtplib` module now uses :data:`sys.stderr` instead of previous
1092 module level :data:`stderr` variable for debug output. If your (test)
1093 program depends on patching the module level variable to capture the debug
1094 output, you will need to update it to capture sys.stderr instead.
1095
Serhiy Storchakad4ea03c2015-05-31 09:15:51 +03001096* The :meth:`str.startswith` and :meth:`str.endswith` methods no longer return
1097 ``True`` when finding the empty string and the indexes are completely out of
1098 range. See :issue:`24284`.
1099
Victor Stinnerdb067af2014-05-02 22:31:14 +02001100Changes in the C API
1101--------------------
1102
Stefan Krahf5324d72015-01-29 14:29:51 +01001103* The undocumented :c:member:`~PyMemoryViewObject.format` member of the
1104 (non-public) :c:type:`PyMemoryViewObject` structure has been removed.
1105
1106 All extensions relying on the relevant parts in ``memoryobject.h``
1107 must be rebuilt.
1108
Victor Stinnerd8f0d922014-06-02 21:57:10 +02001109* The :c:type:`PyMemAllocator` structure was renamed to
1110 :c:type:`PyMemAllocatorEx` and a new ``calloc`` field was added.
Serhiy Storchakadf4518c2014-11-18 23:34:33 +02001111
1112* Removed non-documented macro :c:macro:`PyObject_REPR` which leaked references.
1113 Use format character ``%R`` in :c:func:`PyUnicode_FromFormat`-like functions
1114 to format the :func:`repr` of the object.
Serhiy Storchaka490055a2015-03-01 10:03:02 +02001115
1116* Because the lack of the :attr:`__module__` attribute breaks pickling and
1117 introspection, a deprecation warning now is raised for builtin type without
1118 the :attr:`__module__` attribute. Would be an AttributeError in future.
1119 (:issue:`20204`)
Yury Selivanov50960882015-05-12 00:15:05 -04001120
Yury Selivanov5376ba92015-06-22 12:19:30 -04001121* As part of :pep:`492` implementation, ``tp_reserved`` slot of
Yury Selivanovf3e40fa2015-05-21 11:50:30 -04001122 :c:type:`PyTypeObject` was replaced with a
Yury Selivanov27947d52015-06-23 15:09:58 -04001123 :c:member:`tp_as_async` slot. Refer to :ref:`coro-objects` for
Yury Selivanov5376ba92015-06-22 12:19:30 -04001124 new types, structures and functions.