Zachary Ware | 569db2c | 2015-05-22 11:42:20 -0500 | [diff] [blame] | 1 | **************************** |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2 | What's New In Python 3.5 |
| 3 | **************************** |
| 4 | |
Yury Selivanov | 7b76bae | 2015-09-12 17:53:33 -0400 | [diff] [blame] | 5 | :Editors: Elvis Pranskevichus <elvis@magic.io>, Yury Selivanov <yury@magic.io> |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 6 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 7 | .. Rules for maintenance: |
| 8 | |
| 9 | * Anyone can add text to this document. Do not spend very much time |
| 10 | on the wording of your changes, because your text will probably |
| 11 | get rewritten to some degree. |
| 12 | |
| 13 | * The maintainer will go through Misc/NEWS periodically and add |
| 14 | changes; it's therefore more important to add your changes to |
| 15 | Misc/NEWS than to this file. |
| 16 | |
| 17 | * This is not a complete list of every single change; completeness |
| 18 | is the purpose of Misc/NEWS. Some changes I consider too small |
| 19 | or esoteric to include. If such a change is added to the text, |
| 20 | I'll just remove it. (This is another reason you shouldn't spend |
| 21 | too much time on writing your addition.) |
| 22 | |
| 23 | * If you want to draw your new text to the attention of the |
| 24 | maintainer, add 'XXX' to the beginning of the paragraph or |
| 25 | section. |
| 26 | |
| 27 | * It's OK to just add a fragmentary note about a change. For |
| 28 | example: "XXX Describe the transmogrify() function added to the |
| 29 | socket module." The maintainer will research the change and |
| 30 | write the necessary text. |
| 31 | |
| 32 | * You can comment out your additions if you like, but it's not |
| 33 | necessary (especially when a final release is some months away). |
| 34 | |
| 35 | * Credit the author of a patch or bugfix. Just the name is |
| 36 | sufficient; the e-mail address isn't necessary. |
| 37 | |
| 38 | * It's helpful to add the bug/patch number as a comment: |
| 39 | |
| 40 | XXX Describe the transmogrify() function added to the socket |
| 41 | module. |
| 42 | (Contributed by P.Y. Developer in :issue:`12345`.) |
| 43 | |
| 44 | This saves the maintainer the effort of going through the Mercurial log |
| 45 | when researching a change. |
| 46 | |
| 47 | This article explains the new features in Python 3.5, compared to 3.4. |
Yury Selivanov | 69a15f1 | 2015-09-13 11:52:07 -0400 | [diff] [blame] | 48 | Python 3.5 was released on September 13, 2015. See the |
Yury Selivanov | 801306b | 2015-09-13 11:40:00 -0400 | [diff] [blame] | 49 | `changelog <https://docs.python.org/3.5/whatsnew/changelog.html>`_ for a full |
| 50 | list of changes. |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 51 | |
| 52 | .. seealso:: |
| 53 | |
Berker Peksag | fa0423b | 2014-10-09 11:38:19 +0300 | [diff] [blame] | 54 | :pep:`478` - Python 3.5 Release Schedule |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 55 | |
| 56 | |
| 57 | Summary -- Release highlights |
| 58 | ============================= |
| 59 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 60 | New syntax features: |
| 61 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 62 | * :ref:`PEP 492 <whatsnew-pep-492>`, coroutines with async and await syntax. |
| 63 | * :ref:`PEP 465 <whatsnew-pep-465>`, a new matrix multiplication operator: ``a @ b``. |
| 64 | * :ref:`PEP 448 <whatsnew-pep-448>`, additional unpacking generalizations. |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 65 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 66 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 67 | New library modules: |
| 68 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 69 | * :mod:`typing`: :ref:`PEP 484 -- Type Hints <whatsnew-pep-484>`. |
| 70 | * :mod:`zipapp`: :ref:`PEP 441 Improving Python ZIP Application Support |
| 71 | <whatsnew-zipapp>`. |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 72 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 73 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 74 | New built-in features: |
| 75 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 76 | * ``bytes % args``, ``bytearray % args``: :ref:`PEP 461 <whatsnew-pep-461>` -- |
| 77 | Adding ``%`` formatting to bytes and bytearray. |
Yury Selivanov | 40301c0 | 2015-09-08 23:28:06 -0400 | [diff] [blame] | 78 | |
Yury Selivanov | 8e3b04c | 2015-09-16 12:18:29 -0400 | [diff] [blame] | 79 | * New :meth:`bytes.hex`, :meth:`bytearray.hex` and :meth:`memoryview.hex` |
| 80 | methods. (Contributed by Arnon Yaari in :issue:`9951`.) |
Yury Selivanov | 40301c0 | 2015-09-08 23:28:06 -0400 | [diff] [blame] | 81 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 82 | * :class:`memoryview` now supports tuple indexing (including multi-dimensional). |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 83 | (Contributed by Antoine Pitrou in :issue:`23632`.) |
| 84 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 85 | * Generators have a new ``gi_yieldfrom`` attribute, which returns the |
Yury Selivanov | e13f8f3 | 2015-07-03 00:23:30 -0400 | [diff] [blame] | 86 | object being iterated by ``yield from`` expressions. (Contributed |
| 87 | by Benno Leslie and Yury Selivanov in :issue:`24450`.) |
Yury Selivanov | 40301c0 | 2015-09-08 23:28:06 -0400 | [diff] [blame] | 88 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 89 | * A new :exc:`RecursionError` exception is now raised when maximum |
| 90 | recursion depth is reached. (Contributed by Georg Brandl |
Yury Selivanov | f488fb4 | 2015-07-03 01:04:23 -0400 | [diff] [blame] | 91 | in :issue:`19235`.) |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 92 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 93 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 94 | CPython implementation improvements: |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 95 | |
Victor Stinner | 7143029 | 2014-03-18 01:18:21 +0100 | [diff] [blame] | 96 | * When the ``LC_TYPE`` locale is the POSIX locale (``C`` locale), |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 97 | :py:data:`sys.stdin` and :py:data:`sys.stdout` now use the |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 98 | ``surrogateescape`` error handler, instead of the ``strict`` error handler. |
| 99 | (Contributed by Victor Stinner in :issue:`19977`.) |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 100 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 101 | * ``.pyo`` files are no longer used and have been replaced by a more flexible |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 102 | scheme that includes the optimization level explicitly in ``.pyc`` name. |
| 103 | (See :ref:`PEP 488 overview <whatsnew-pep-488>`.) |
Yury Selivanov | 40301c0 | 2015-09-08 23:28:06 -0400 | [diff] [blame] | 104 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 105 | * Builtin and extension modules are now initialized in a multi-phase process, |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 106 | which is similar to how Python modules are loaded. |
| 107 | (See :ref:`PEP 489 overview <whatsnew-pep-489>`.) |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 108 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 109 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 110 | Significant improvements in the standard library: |
Yury Selivanov | 5844436 | 2015-05-30 10:49:09 -0400 | [diff] [blame] | 111 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 112 | * :class:`collections.OrderedDict` is now |
| 113 | :ref:`implemented in C <whatsnew-ordereddict>`, which makes it |
| 114 | 4 to 100 times faster. |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 115 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 116 | * The :mod:`ssl` module gained |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 117 | :ref:`support for Memory BIO <whatsnew-sslmemorybio>`, which decouples SSL |
| 118 | protocol handling from network IO. |
Yury Selivanov | 7d6adab | 2015-08-05 19:01:51 -0400 | [diff] [blame] | 119 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 120 | * The new :func:`os.scandir` function provides a |
| 121 | :ref:`better and significantly faster way <whatsnew-pep-471>` |
| 122 | of directory traversal. |
| 123 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 124 | * :func:`functools.lru_cache` has been mostly |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 125 | :ref:`reimplemented in C <whatsnew-lrucache>`, yielding much better |
| 126 | performance. |
| 127 | |
| 128 | * The new :func:`subprocess.run` function provides a |
| 129 | :ref:`streamlined way to run subprocesses <whatsnew-subprocess>`. |
| 130 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 131 | * The :mod:`traceback` module has been significantly |
Yury Selivanov | fe369a6 | 2015-09-13 08:29:19 -0400 | [diff] [blame] | 132 | :ref:`enhanced <whatsnew-traceback>` for improved |
| 133 | performance and developer convenience. |
| 134 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 135 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 136 | Security improvements: |
| 137 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 138 | * SSLv3 is now disabled throughout the standard library. |
| 139 | It can still be enabled by instantiating a :class:`ssl.SSLContext` |
| 140 | manually. (See :issue:`22638` for more details; this change was |
| 141 | backported to CPython 3.4 and 2.7.) |
| 142 | |
| 143 | * HTTP cookie parsing is now stricter, in order to protect |
| 144 | against potential injection attacks. (Contributed by Antoine Pitrou |
| 145 | in :issue:`22796`.) |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 146 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 147 | |
Steve Dower | 313fbf4 | 2015-07-17 16:48:48 -0700 | [diff] [blame] | 148 | Windows improvements: |
| 149 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 150 | * A new installer for Windows has replaced the old MSI. |
| 151 | See :ref:`using-on-windows` for more information. |
Yury Selivanov | 40301c0 | 2015-09-08 23:28:06 -0400 | [diff] [blame] | 152 | |
Steve Dower | 313fbf4 | 2015-07-17 16:48:48 -0700 | [diff] [blame] | 153 | * Windows builds now use Microsoft Visual C++ 14.0, and extension modules |
| 154 | should use the same. |
| 155 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 156 | |
Yury Selivanov | 0ac5f28 | 2015-09-08 23:40:46 -0400 | [diff] [blame] | 157 | Please read on for a comprehensive list of user-facing changes, including many |
| 158 | other smaller improvements, CPython optimizations, deprecations, and potential |
| 159 | porting issues. |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 160 | |
| 161 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 162 | New Features |
| 163 | ============ |
| 164 | |
| 165 | .. _whatsnew-pep-492: |
| 166 | |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 167 | PEP 492 - Coroutines with async and await syntax |
| 168 | ------------------------------------------------ |
| 169 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 170 | :pep:`492` greatly improves support for asynchronous programming in Python |
| 171 | by adding :term:`awaitable objects <awaitable>`, |
| 172 | :term:`coroutine functions <coroutine function>`, |
| 173 | :term:`asynchronous iteration <asynchronous iterable>`, |
| 174 | and :term:`asynchronous context managers <asynchronous context manager>`. |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 175 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 176 | Coroutine functions are declared using the new :keyword:`async def` syntax:: |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 177 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 178 | >>> async def coro(): |
| 179 | ... return 'spam' |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 180 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 181 | Inside a coroutine function, the new :keyword:`await` expression can be used |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 182 | to suspend coroutine execution until the result is available. Any object |
| 183 | can be *awaited*, as long as it implements the :term:`awaitable` protocol by |
| 184 | defining the :meth:`__await__` method. |
| 185 | |
| 186 | PEP 492 also adds :keyword:`async for` statement for convenient iteration |
| 187 | over asynchronous iterables. |
| 188 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 189 | An example of a rudimentary HTTP client written using the new syntax:: |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 190 | |
| 191 | import asyncio |
| 192 | |
| 193 | async def http_get(domain): |
| 194 | reader, writer = await asyncio.open_connection(domain, 80) |
| 195 | |
| 196 | writer.write(b'\r\n'.join([ |
| 197 | b'GET / HTTP/1.1', |
| 198 | b'Host: %b' % domain.encode('latin-1'), |
| 199 | b'Connection: close', |
| 200 | b'', b'' |
| 201 | ])) |
| 202 | |
| 203 | async for line in reader: |
| 204 | print('>>>', line) |
| 205 | |
| 206 | writer.close() |
| 207 | |
| 208 | loop = asyncio.get_event_loop() |
| 209 | try: |
| 210 | loop.run_until_complete(http_get('example.com')) |
| 211 | finally: |
| 212 | loop.close() |
| 213 | |
| 214 | |
| 215 | Similarly to asynchronous iteration, there is a new syntax for asynchronous |
Yury Selivanov | 79cf1b0 | 2015-09-10 21:44:59 -0400 | [diff] [blame] | 216 | context managers. The following script:: |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 217 | |
Yury Selivanov | 79cf1b0 | 2015-09-10 21:44:59 -0400 | [diff] [blame] | 218 | import asyncio |
| 219 | |
| 220 | async def coro(name, lock): |
| 221 | print('coro {}: waiting for lock'.format(name)) |
| 222 | async with lock: |
| 223 | print('coro {}: holding the lock'.format(name)) |
| 224 | await asyncio.sleep(1) |
| 225 | print('coro {}: releasing the lock'.format(name)) |
| 226 | |
| 227 | loop = asyncio.get_event_loop() |
| 228 | lock = asyncio.Lock() |
| 229 | coros = asyncio.gather(coro(1, lock), coro(2, lock)) |
| 230 | try: |
| 231 | loop.run_until_complete(coros) |
| 232 | finally: |
| 233 | loop.close() |
| 234 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 235 | will output:: |
Yury Selivanov | 79cf1b0 | 2015-09-10 21:44:59 -0400 | [diff] [blame] | 236 | |
| 237 | coro 2: waiting for lock |
| 238 | coro 2: holding the lock |
| 239 | coro 1: waiting for lock |
| 240 | coro 2: releasing the lock |
| 241 | coro 1: holding the lock |
| 242 | coro 1: releasing the lock |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 243 | |
| 244 | Note that both :keyword:`async for` and :keyword:`async with` can only |
| 245 | be used inside a coroutine function declared with :keyword:`async def`. |
| 246 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 247 | Coroutine functions are intended to be run inside a compatible event loop, |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 248 | such as the :ref:`asyncio loop <asyncio-event-loop>`. |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 249 | |
Yury Selivanov | a6f6edb | 2016-06-09 15:08:31 -0400 | [diff] [blame] | 250 | |
| 251 | .. note:: |
| 252 | |
| 253 | .. versionchanged:: 3.5.2 |
| 254 | Starting with CPython 3.5.2, ``__aiter__`` can directly return |
| 255 | :term:`asynchronous iterators <asynchronous iterator>`. Returning |
| 256 | an :term:`awaitable` object will result in a |
| 257 | :exc:`PendingDeprecationWarning`. |
| 258 | |
| 259 | See more details in the :ref:`async-iterators` documentation |
| 260 | section. |
| 261 | |
| 262 | |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 263 | .. seealso:: |
| 264 | |
| 265 | :pep:`492` -- Coroutines with async and await syntax |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 266 | PEP written and implemented by Yury Selivanov. |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 267 | |
| 268 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 269 | .. _whatsnew-pep-465: |
| 270 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 271 | PEP 465 - A dedicated infix operator for matrix multiplication |
| 272 | -------------------------------------------------------------- |
Victor Stinner | 93692bb | 2015-03-30 15:04:45 +0200 | [diff] [blame] | 273 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 274 | :pep:`465` adds the ``@`` infix operator for matrix multiplication. |
| 275 | Currently, no builtin Python types implement the new operator, however, it |
| 276 | can be implemented by defining :meth:`__matmul__`, :meth:`__rmatmul__`, |
| 277 | and :meth:`__imatmul__` for regular, reflected, and in-place matrix |
| 278 | multiplication. The semantics of these methods is similar to that of |
| 279 | methods defining other infix arithmetic operators. |
| 280 | |
| 281 | Matrix multiplication is a notably common operation in many fields of |
| 282 | mathematics, science, engineering, and the addition of ``@`` allows writing |
| 283 | cleaner code:: |
| 284 | |
Yury Selivanov | 0ac5f28 | 2015-09-08 23:40:46 -0400 | [diff] [blame] | 285 | S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r) |
| 286 | |
| 287 | instead of:: |
| 288 | |
| 289 | S = dot((dot(H, beta) - r).T, |
| 290 | dot(inv(dot(dot(H, V), H.T)), dot(H, beta) - r)) |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 291 | |
Yury Selivanov | f97edf1 | 2015-10-31 13:33:49 -0400 | [diff] [blame] | 292 | NumPy 1.10 has support for the new operator:: |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 293 | |
| 294 | >>> import numpy |
| 295 | |
| 296 | >>> x = numpy.ones(3) |
| 297 | >>> x |
| 298 | array([ 1., 1., 1.]) |
| 299 | |
| 300 | >>> m = numpy.eye(3) |
| 301 | >>> m |
| 302 | array([[ 1., 0., 0.], |
| 303 | [ 0., 1., 0.], |
| 304 | [ 0., 0., 1.]]) |
| 305 | |
| 306 | >>> x @ m |
| 307 | array([ 1., 1., 1.]) |
| 308 | |
| 309 | |
| 310 | .. seealso:: |
| 311 | |
| 312 | :pep:`465` -- A dedicated infix operator for matrix multiplication |
| 313 | PEP written by Nathaniel J. Smith; implemented by Benjamin Peterson. |
| 314 | |
| 315 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 316 | .. _whatsnew-pep-448: |
| 317 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 318 | PEP 448 - Additional Unpacking Generalizations |
| 319 | ---------------------------------------------- |
| 320 | |
| 321 | :pep:`448` extends the allowed uses of the ``*`` iterable unpacking |
| 322 | operator and ``**`` dictionary unpacking operator. It is now possible |
Martin Panter | 0c0da48 | 2016-06-12 01:46:50 +0000 | [diff] [blame] | 323 | to use an arbitrary number of unpackings in :ref:`function calls <calls>`:: |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 324 | |
| 325 | >>> print(*[1], *[2], 3, *[4, 5]) |
| 326 | 1 2 3 4 5 |
| 327 | |
| 328 | >>> def fn(a, b, c, d): |
| 329 | ... print(a, b, c, d) |
| 330 | ... |
| 331 | |
| 332 | >>> fn(**{'a': 1, 'c': 3}, **{'b': 2, 'd': 4}) |
| 333 | 1 2 3 4 |
| 334 | |
| 335 | Similarly, tuple, list, set, and dictionary displays allow multiple |
Martin Panter | 0c0da48 | 2016-06-12 01:46:50 +0000 | [diff] [blame] | 336 | unpackings (see :ref:`exprlists` and :ref:`dict`):: |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 337 | |
| 338 | >>> *range(4), 4 |
| 339 | (0, 1, 2, 3, 4) |
Yury Selivanov | 79cf1b0 | 2015-09-10 21:44:59 -0400 | [diff] [blame] | 340 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 341 | >>> [*range(4), 4] |
| 342 | [0, 1, 2, 3, 4] |
Yury Selivanov | 79cf1b0 | 2015-09-10 21:44:59 -0400 | [diff] [blame] | 343 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 344 | >>> {*range(4), 4, *(5, 6, 7)} |
| 345 | {0, 1, 2, 3, 4, 5, 6, 7} |
Yury Selivanov | 79cf1b0 | 2015-09-10 21:44:59 -0400 | [diff] [blame] | 346 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 347 | >>> {'x': 1, **{'y': 2}} |
| 348 | {'x': 1, 'y': 2} |
| 349 | |
| 350 | .. seealso:: |
| 351 | |
| 352 | :pep:`448` -- Additional Unpacking Generalizations |
| 353 | PEP written by Joshua Landau; implemented by Neil Girdhar, |
| 354 | Thomas Wouters, and Joshua Landau. |
| 355 | |
| 356 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 357 | .. _whatsnew-pep-461: |
| 358 | |
Benjamin Peterson | 909acb8 | 2016-06-21 23:47:16 -0700 | [diff] [blame] | 359 | PEP 461 - percent formatting support for bytes and bytearray |
| 360 | ------------------------------------------------------------ |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 361 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 362 | :pep:`461` adds support for the ``%`` |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 363 | :ref:`interpolation operator <bytes-formatting>` to :class:`bytes` |
| 364 | and :class:`bytearray`. |
| 365 | |
| 366 | While interpolation is usually thought of as a string operation, there are |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 367 | cases where interpolation on ``bytes`` or ``bytearrays`` makes sense, and the |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 368 | work needed to make up for this missing functionality detracts from the |
| 369 | overall readability of the code. This issue is particularly important when |
| 370 | dealing with wire format protocols, which are often a mixture of binary |
| 371 | and ASCII compatible text. |
Victor Stinner | 93692bb | 2015-03-30 15:04:45 +0200 | [diff] [blame] | 372 | |
| 373 | Examples:: |
| 374 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 375 | >>> b'Hello %b!' % b'World' |
Victor Stinner | 93692bb | 2015-03-30 15:04:45 +0200 | [diff] [blame] | 376 | b'Hello World!' |
Yury Selivanov | 79cf1b0 | 2015-09-10 21:44:59 -0400 | [diff] [blame] | 377 | |
Victor Stinner | 93692bb | 2015-03-30 15:04:45 +0200 | [diff] [blame] | 378 | >>> b'x=%i y=%f' % (1, 2.5) |
| 379 | b'x=1 y=2.500000' |
| 380 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 381 | Unicode is not allowed for ``%b``, but it is accepted by ``%a`` (equivalent of |
Victor Stinner | 93692bb | 2015-03-30 15:04:45 +0200 | [diff] [blame] | 382 | ``repr(obj).encode('ascii', 'backslashreplace')``):: |
| 383 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 384 | >>> b'Hello %b!' % 'World' |
Victor Stinner | 93692bb | 2015-03-30 15:04:45 +0200 | [diff] [blame] | 385 | Traceback (most recent call last): |
| 386 | File "<stdin>", line 1, in <module> |
| 387 | TypeError: %b requires bytes, or an object that implements __bytes__, not 'str' |
Yury Selivanov | 79cf1b0 | 2015-09-10 21:44:59 -0400 | [diff] [blame] | 388 | |
Victor Stinner | 93692bb | 2015-03-30 15:04:45 +0200 | [diff] [blame] | 389 | >>> b'price: %a' % '10€' |
| 390 | b"price: '10\\u20ac'" |
| 391 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 392 | Note that ``%s`` and ``%r`` conversion types, although supported, should |
| 393 | only be used in codebases that need compatibility with Python 2. |
| 394 | |
Victor Stinner | 93692bb | 2015-03-30 15:04:45 +0200 | [diff] [blame] | 395 | .. seealso:: |
| 396 | |
| 397 | :pep:`461` -- Adding % formatting to bytes and bytearray |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 398 | PEP written by Ethan Furman; implemented by Neil Schemenauer and |
| 399 | Ethan Furman. |
Yury Selivanov | 216d999 | 2015-08-04 12:42:20 -0400 | [diff] [blame] | 400 | |
| 401 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 402 | .. _whatsnew-pep-484: |
| 403 | |
Yury Selivanov | 5df36af | 2015-08-04 12:46:57 -0400 | [diff] [blame] | 404 | PEP 484 - Type Hints |
| 405 | -------------------- |
| 406 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 407 | Function annotation syntax has been a Python feature since version 3.0 |
| 408 | (:pep:`3107`), however the semantics of annotations has been left undefined. |
| 409 | |
| 410 | Experience has shown that the majority of function annotation |
| 411 | uses were to provide type hints to function parameters and return values. It |
| 412 | became evident that it would be beneficial for Python users, if the |
| 413 | standard library included the base definitions and tools for type annotations. |
| 414 | |
| 415 | :pep:`484` introduces a :term:`provisional module <provisional api>` to |
| 416 | provide these standard definitions and tools, along with some conventions |
| 417 | for situations where annotations are not available. |
Yury Selivanov | 5df36af | 2015-08-04 12:46:57 -0400 | [diff] [blame] | 418 | |
| 419 | For example, here is a simple function whose argument and return type |
| 420 | are declared in the annotations:: |
| 421 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 422 | def greeting(name: str) -> str: |
| 423 | return 'Hello ' + name |
Yury Selivanov | 5df36af | 2015-08-04 12:46:57 -0400 | [diff] [blame] | 424 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 425 | While these annotations are available at runtime through the usual |
| 426 | :attr:`__annotations__` attribute, *no automatic type checking happens at |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 427 | runtime*. Instead, it is assumed that a separate off-line type checker |
| 428 | (e.g. `mypy <http://mypy-lang.org>`_) will be used for on-demand |
| 429 | source code analysis. |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 430 | |
Yury Selivanov | 5df36af | 2015-08-04 12:46:57 -0400 | [diff] [blame] | 431 | The type system supports unions, generic types, and a special type |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 432 | named :class:`~typing.Any` which is consistent with (i.e. assignable to |
| 433 | and from) all types. |
Yury Selivanov | 5df36af | 2015-08-04 12:46:57 -0400 | [diff] [blame] | 434 | |
| 435 | .. seealso:: |
| 436 | |
Yury Selivanov | 40c0ce4 | 2015-08-05 12:46:29 -0400 | [diff] [blame] | 437 | * :mod:`typing` module documentation |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 438 | * :pep:`484` -- Type Hints |
| 439 | PEP written by Guido van Rossum, Jukka Lehtosalo, and Łukasz Langa; |
| 440 | implemented by Guido van Rossum. |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 441 | * :pep:`483` -- The Theory of Type Hints |
| 442 | PEP written by Guido van Rossum |
Yury Selivanov | 5df36af | 2015-08-04 12:46:57 -0400 | [diff] [blame] | 443 | |
| 444 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 445 | .. _whatsnew-pep-471: |
| 446 | |
Victor Stinner | 6036e44 | 2015-03-08 01:58:04 +0100 | [diff] [blame] | 447 | PEP 471 - os.scandir() function -- a better and faster directory iterator |
| 448 | ------------------------------------------------------------------------- |
| 449 | |
Victor Stinner | 37f2034 | 2015-03-10 13:29:41 +0100 | [diff] [blame] | 450 | :pep:`471` adds a new directory iteration function, :func:`os.scandir`, |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 451 | to the standard library. Additionally, :func:`os.walk` is now |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 452 | implemented using ``scandir``, which makes it 3 to 5 times faster |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 453 | on POSIX systems and 7 to 20 times faster on Windows systems. This is |
| 454 | largely achieved by greatly reducing the number of calls to :func:`os.stat` |
| 455 | required to walk a directory tree. |
| 456 | |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 457 | Additionally, ``scandir`` returns an iterator, as opposed to returning |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 458 | a list of file names, which improves memory efficiency when iterating |
| 459 | over very large directories. |
Victor Stinner | 37f2034 | 2015-03-10 13:29:41 +0100 | [diff] [blame] | 460 | |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 461 | The following example shows a simple use of :func:`os.scandir` to display all |
| 462 | the files (excluding directories) in the given *path* that don't start with |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 463 | ``'.'``. The :meth:`entry.is_file() <os.DirEntry.is_file>` call will generally |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 464 | not make an additional system call:: |
| 465 | |
| 466 | for entry in os.scandir(path): |
| 467 | if not entry.name.startswith('.') and entry.is_file(): |
| 468 | print(entry.name) |
| 469 | |
Victor Stinner | 6036e44 | 2015-03-08 01:58:04 +0100 | [diff] [blame] | 470 | .. seealso:: |
| 471 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 472 | :pep:`471` -- os.scandir() function -- a better and faster directory iterator |
| 473 | PEP written and implemented by Ben Hoyt with the help of Victor Stinner. |
Victor Stinner | 6036e44 | 2015-03-08 01:58:04 +0100 | [diff] [blame] | 474 | |
| 475 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 476 | .. _whatsnew-pep-475: |
| 477 | |
Charles-François Natali | 6e6c59b | 2015-02-07 13:27:50 +0000 | [diff] [blame] | 478 | PEP 475: Retry system calls failing with EINTR |
| 479 | ---------------------------------------------- |
| 480 | |
Martin Panter | d2ad571 | 2015-11-02 04:20:33 +0000 | [diff] [blame] | 481 | An :py:data:`errno.EINTR` error code is returned whenever a system call, that |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 482 | is waiting for I/O, is interrupted by a signal. Previously, Python would |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 483 | raise :exc:`InterruptedError` in such cases. This meant that, when writing a |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 484 | Python application, the developer had two choices: |
Charles-François Natali | 6e6c59b | 2015-02-07 13:27:50 +0000 | [diff] [blame] | 485 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 486 | #. Ignore the ``InterruptedError``. |
| 487 | #. Handle the ``InterruptedError`` and attempt to restart the interrupted |
| 488 | system call at every call site. |
| 489 | |
| 490 | The first option makes an application fail intermittently. |
| 491 | The second option adds a large amount of boilerplate that makes the |
| 492 | code nearly unreadable. Compare:: |
| 493 | |
| 494 | print("Hello World") |
| 495 | |
| 496 | and:: |
| 497 | |
| 498 | while True: |
| 499 | try: |
| 500 | print("Hello World") |
| 501 | break |
| 502 | except InterruptedError: |
| 503 | continue |
| 504 | |
| 505 | :pep:`475` implements automatic retry of system calls on |
| 506 | ``EINTR``. This removes the burden of dealing with ``EINTR`` |
| 507 | or :exc:`InterruptedError` in user code in most situations and makes |
| 508 | Python programs, including the standard library, more robust. Note that |
| 509 | the system call is only retried if the signal handler does not raise an |
| 510 | exception. |
| 511 | |
| 512 | Below is a list of functions which are now retried when interrupted |
| 513 | by a signal: |
Victor Stinner | 6752d65 | 2015-07-29 01:11:10 +0200 | [diff] [blame] | 514 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 515 | * :func:`open` and :func:`io.open`; |
Victor Stinner | 6752d65 | 2015-07-29 01:11:10 +0200 | [diff] [blame] | 516 | |
Yury Selivanov | 0ac5f28 | 2015-09-08 23:40:46 -0400 | [diff] [blame] | 517 | * functions of the :mod:`faulthandler` module; |
Victor Stinner | 6752d65 | 2015-07-29 01:11:10 +0200 | [diff] [blame] | 518 | |
Yury Selivanov | 0ac5f28 | 2015-09-08 23:40:46 -0400 | [diff] [blame] | 519 | * :mod:`os` functions: :func:`~os.fchdir`, :func:`~os.fchmod`, |
| 520 | :func:`~os.fchown`, :func:`~os.fdatasync`, :func:`~os.fstat`, |
| 521 | :func:`~os.fstatvfs`, :func:`~os.fsync`, :func:`~os.ftruncate`, |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 522 | :func:`~os.mkfifo`, :func:`~os.mknod`, :func:`~os.open`, |
| 523 | :func:`~os.posix_fadvise`, :func:`~os.posix_fallocate`, :func:`~os.pread`, |
| 524 | :func:`~os.pwrite`, :func:`~os.read`, :func:`~os.readv`, :func:`~os.sendfile`, |
Yury Selivanov | 0ac5f28 | 2015-09-08 23:40:46 -0400 | [diff] [blame] | 525 | :func:`~os.wait3`, :func:`~os.wait4`, :func:`~os.wait`, |
| 526 | :func:`~os.waitid`, :func:`~os.waitpid`, :func:`~os.write`, |
| 527 | :func:`~os.writev`; |
Victor Stinner | 6752d65 | 2015-07-29 01:11:10 +0200 | [diff] [blame] | 528 | |
Yury Selivanov | 0ac5f28 | 2015-09-08 23:40:46 -0400 | [diff] [blame] | 529 | * special cases: :func:`os.close` and :func:`os.dup2` now ignore |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 530 | :py:data:`~errno.EINTR` errors; the syscall is not retried (see the PEP |
Yury Selivanov | 0ac5f28 | 2015-09-08 23:40:46 -0400 | [diff] [blame] | 531 | for the rationale); |
Victor Stinner | 6752d65 | 2015-07-29 01:11:10 +0200 | [diff] [blame] | 532 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 533 | * :mod:`select` functions: :func:`devpoll.poll() <select.devpoll.poll>`, |
| 534 | :func:`epoll.poll() <select.epoll.poll>`, |
| 535 | :func:`kqueue.control() <select.kqueue.control>`, |
| 536 | :func:`poll.poll() <select.poll.poll>`, :func:`~select.select`; |
Victor Stinner | 6752d65 | 2015-07-29 01:11:10 +0200 | [diff] [blame] | 537 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 538 | * methods of the :class:`~socket.socket` class: :meth:`~socket.socket.accept`, |
Yury Selivanov | 0ac5f28 | 2015-09-08 23:40:46 -0400 | [diff] [blame] | 539 | :meth:`~socket.socket.connect` (except for non-blocking sockets), |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 540 | :meth:`~socket.socket.recv`, :meth:`~socket.socket.recvfrom`, |
| 541 | :meth:`~socket.socket.recvmsg`, :meth:`~socket.socket.send`, |
| 542 | :meth:`~socket.socket.sendall`, :meth:`~socket.socket.sendmsg`, |
Yury Selivanov | 0ac5f28 | 2015-09-08 23:40:46 -0400 | [diff] [blame] | 543 | :meth:`~socket.socket.sendto`; |
Victor Stinner | 6752d65 | 2015-07-29 01:11:10 +0200 | [diff] [blame] | 544 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 545 | * :func:`signal.sigtimedwait` and :func:`signal.sigwaitinfo`; |
Yury Selivanov | 0ac5f28 | 2015-09-08 23:40:46 -0400 | [diff] [blame] | 546 | |
| 547 | * :func:`time.sleep`. |
Victor Stinner | 6752d65 | 2015-07-29 01:11:10 +0200 | [diff] [blame] | 548 | |
Charles-François Natali | 6e6c59b | 2015-02-07 13:27:50 +0000 | [diff] [blame] | 549 | .. seealso:: |
| 550 | |
| 551 | :pep:`475` -- Retry system calls failing with EINTR |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 552 | PEP and implementation written by Charles-François Natali and |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 553 | Victor Stinner, with the help of Antoine Pitrou (the French connection). |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 554 | |
| 555 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 556 | .. _whatsnew-pep-479: |
| 557 | |
Yury Selivanov | 8d006e7 | 2015-05-22 11:30:45 -0400 | [diff] [blame] | 558 | PEP 479: Change StopIteration handling inside generators |
| 559 | -------------------------------------------------------- |
| 560 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 561 | The interaction of generators and :exc:`StopIteration` in Python 3.4 and |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 562 | earlier was sometimes surprising, and could conceal obscure bugs. Previously, |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 563 | ``StopIteration`` raised accidentally inside a generator function was |
| 564 | interpreted as the end of the iteration by the loop construct driving the |
| 565 | generator. |
| 566 | |
| 567 | :pep:`479` changes the behavior of generators: when a ``StopIteration`` |
Yury Selivanov | 8d006e7 | 2015-05-22 11:30:45 -0400 | [diff] [blame] | 568 | exception is raised inside a generator, it is replaced with a |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 569 | :exc:`RuntimeError` before it exits the generator frame. The main goal of |
| 570 | this change is to ease debugging in the situation where an unguarded |
| 571 | :func:`next` call raises ``StopIteration`` and causes the iteration controlled |
| 572 | by the generator to terminate silently. This is particularly pernicious in |
| 573 | combination with the ``yield from`` construct. |
| 574 | |
| 575 | This is a backwards incompatible change, so to enable the new behavior, |
| 576 | a :term:`__future__` import is necessary:: |
Yury Selivanov | 8d006e7 | 2015-05-22 11:30:45 -0400 | [diff] [blame] | 577 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 578 | >>> from __future__ import generator_stop |
| 579 | |
| 580 | >>> def gen(): |
| 581 | ... next(iter([])) |
| 582 | ... yield |
| 583 | ... |
| 584 | >>> next(gen()) |
| 585 | Traceback (most recent call last): |
| 586 | File "<stdin>", line 2, in gen |
| 587 | StopIteration |
| 588 | |
| 589 | The above exception was the direct cause of the following exception: |
| 590 | |
| 591 | Traceback (most recent call last): |
| 592 | File "<stdin>", line 1, in <module> |
| 593 | RuntimeError: generator raised StopIteration |
Yury Selivanov | 8d006e7 | 2015-05-22 11:30:45 -0400 | [diff] [blame] | 594 | |
| 595 | Without a ``__future__`` import, a :exc:`PendingDeprecationWarning` will be |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 596 | raised whenever a ``StopIteration`` exception is raised inside a generator. |
Yury Selivanov | 8d006e7 | 2015-05-22 11:30:45 -0400 | [diff] [blame] | 597 | |
Yury Selivanov | 8d006e7 | 2015-05-22 11:30:45 -0400 | [diff] [blame] | 598 | .. seealso:: |
| 599 | |
| 600 | :pep:`479` -- Change StopIteration handling inside generators |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 601 | PEP written by Chris Angelico and Guido van Rossum. Implemented by |
| 602 | Chris Angelico, Yury Selivanov and Nick Coghlan. |
Yury Selivanov | 8d006e7 | 2015-05-22 11:30:45 -0400 | [diff] [blame] | 603 | |
| 604 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 605 | .. _whatsnew-pep-485: |
| 606 | |
| 607 | PEP 485: A function for testing approximate equality |
| 608 | ---------------------------------------------------- |
| 609 | |
| 610 | :pep:`485` adds the :func:`math.isclose` and :func:`cmath.isclose` |
| 611 | functions which tell whether two values are approximately equal or |
| 612 | "close" to each other. Whether or not two values are considered |
| 613 | close is determined according to given absolute and relative tolerances. |
| 614 | Relative tolerance is the maximum allowed difference between ``isclose`` |
| 615 | arguments, relative to the larger absolute value:: |
| 616 | |
| 617 | >>> import math |
| 618 | >>> a = 5.0 |
| 619 | >>> b = 4.99998 |
| 620 | >>> math.isclose(a, b, rel_tol=1e-5) |
| 621 | True |
| 622 | >>> math.isclose(a, b, rel_tol=1e-6) |
| 623 | False |
| 624 | |
| 625 | It is also possible to compare two values using absolute tolerance, which |
| 626 | must be a non-negative value:: |
| 627 | |
| 628 | >>> import math |
| 629 | >>> a = 5.0 |
| 630 | >>> b = 4.99998 |
| 631 | >>> math.isclose(a, b, abs_tol=0.00003) |
| 632 | True |
| 633 | >>> math.isclose(a, b, abs_tol=0.00001) |
| 634 | False |
| 635 | |
| 636 | .. seealso:: |
| 637 | |
| 638 | :pep:`485` -- A function for testing approximate equality |
| 639 | PEP written by Christopher Barker; implemented by Chris Barker and |
| 640 | Tal Einat. |
| 641 | |
| 642 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 643 | .. _whatsnew-pep-486: |
| 644 | |
Steve Dower | 76998fe | 2015-02-26 14:25:33 -0800 | [diff] [blame] | 645 | PEP 486: Make the Python Launcher aware of virtual environments |
| 646 | --------------------------------------------------------------- |
| 647 | |
| 648 | :pep:`486` makes the Windows launcher (see :pep:`397`) aware of an active |
| 649 | virtual environment. When the default interpreter would be used and the |
| 650 | ``VIRTUAL_ENV`` environment variable is set, the interpreter in the virtual |
| 651 | environment will be used. |
| 652 | |
| 653 | .. seealso:: |
| 654 | |
| 655 | :pep:`486` -- Make the Python Launcher aware of virtual environments |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 656 | PEP written and implemented by Paul Moore. |
Steve Dower | 76998fe | 2015-02-26 14:25:33 -0800 | [diff] [blame] | 657 | |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 658 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 659 | .. _whatsnew-pep-488: |
| 660 | |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 661 | PEP 488: Elimination of PYO files |
| 662 | --------------------------------- |
| 663 | |
| 664 | :pep:`488` does away with the concept of ``.pyo`` files. This means that |
Benjamin Peterson | e328323 | 2015-05-26 21:40:28 -0500 | [diff] [blame] | 665 | ``.pyc`` files represent both unoptimized and optimized bytecode. To prevent the |
| 666 | need to constantly regenerate bytecode files, ``.pyc`` files now have an |
| 667 | optional ``opt-`` tag in their name when the bytecode is optimized. This has the |
| 668 | side-effect of no more bytecode file name clashes when running under either |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 669 | :option:`-O` or :option:`-OO`. Consequently, bytecode files generated from |
| 670 | :option:`-O`, and :option:`-OO` may now exist simultaneously. |
| 671 | :func:`importlib.util.cache_from_source` has an updated API to help with |
| 672 | this change. |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 673 | |
| 674 | .. seealso:: |
| 675 | |
| 676 | :pep:`488` -- Elimination of PYO files |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 677 | PEP written and implemented by Brett Cannon. |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 678 | |
| 679 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 680 | .. _whatsnew-pep-489: |
| 681 | |
Nick Coghlan | d5cacbb | 2015-05-23 22:24:10 +1000 | [diff] [blame] | 682 | PEP 489: Multi-phase extension module initialization |
| 683 | ---------------------------------------------------- |
| 684 | |
| 685 | :pep:`489` updates extension module initialization to take advantage of the |
| 686 | two step module loading mechanism introduced by :pep:`451` in Python 3.4. |
| 687 | |
| 688 | This change brings the import semantics of extension modules that opt-in to |
| 689 | using the new mechanism much closer to those of Python source and bytecode |
Nick Coghlan | 2ab5b09 | 2015-07-03 19:49:15 +1000 | [diff] [blame] | 690 | modules, including the ability to use any valid identifier as a module name, |
Nick Coghlan | d5cacbb | 2015-05-23 22:24:10 +1000 | [diff] [blame] | 691 | rather than being restricted to ASCII. |
| 692 | |
| 693 | .. seealso:: |
| 694 | |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 695 | :pep:`489` -- Multi-phase extension module initialization |
| 696 | PEP written by Petr Viktorin, Stefan Behnel, and Nick Coghlan; |
Yury Selivanov | 1f4d470 | 2015-09-09 09:27:29 -0400 | [diff] [blame] | 697 | implemented by Petr Viktorin. |
Yury Selivanov | dfcfe13 | 2015-09-08 15:33:15 -0400 | [diff] [blame] | 698 | |
Nick Coghlan | d5cacbb | 2015-05-23 22:24:10 +1000 | [diff] [blame] | 699 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 700 | Other Language Changes |
| 701 | ====================== |
| 702 | |
| 703 | Some smaller changes made to the core Python language are: |
| 704 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 705 | * Added the ``"namereplace"`` error handlers. The ``"backslashreplace"`` |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 706 | error handlers now work with decoding and translating. |
Serhiy Storchaka | 07985ef | 2015-01-25 22:56:57 +0200 | [diff] [blame] | 707 | (Contributed by Serhiy Storchaka in :issue:`19676` and :issue:`22286`.) |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 708 | |
Serhiy Storchaka | 1dd4982 | 2015-03-20 16:54:57 +0200 | [diff] [blame] | 709 | * The :option:`-b` option now affects comparisons of :class:`bytes` with |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 710 | :class:`int`. (Contributed by Serhiy Storchaka in :issue:`23681`.) |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 711 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 712 | * New Kazakh ``kz1048`` and Tajik ``koi8_t`` :ref:`codecs <standard-encodings>`. |
| 713 | (Contributed by Serhiy Storchaka in :issue:`22682` and :issue:`22681`.) |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 714 | |
Raymond Hettinger | eac503a | 2015-05-13 01:09:59 -0700 | [diff] [blame] | 715 | * Property docstrings are now writable. This is especially useful for |
| 716 | :func:`collections.namedtuple` docstrings. |
| 717 | (Contributed by Berker Peksag in :issue:`24064`.) |
| 718 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 719 | * Circular imports involving relative imports are now supported. |
| 720 | (Contributed by Brett Cannon and Antoine Pitrou in :issue:`17636`.) |
| 721 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 722 | |
| 723 | New Modules |
| 724 | =========== |
| 725 | |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 726 | typing |
| 727 | ------ |
| 728 | |
| 729 | The new :mod:`typing` :term:`provisional <provisional api>` module |
| 730 | provides standard definitions and tools for function type annotations. |
| 731 | See :ref:`Type Hints <whatsnew-pep-484>` for more information. |
| 732 | |
Brett Cannon | cc4dfc1 | 2015-03-13 10:40:49 -0400 | [diff] [blame] | 733 | .. _whatsnew-zipapp: |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 734 | |
Brett Cannon | cc4dfc1 | 2015-03-13 10:40:49 -0400 | [diff] [blame] | 735 | zipapp |
| 736 | ------ |
| 737 | |
| 738 | The new :mod:`zipapp` module (specified in :pep:`441`) provides an API and |
| 739 | command line tool for creating executable Python Zip Applications, which |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 740 | were introduced in Python 2.6 in :issue:`1739468`, but which were not well |
| 741 | publicized, either at the time or since. |
Brett Cannon | cc4dfc1 | 2015-03-13 10:40:49 -0400 | [diff] [blame] | 742 | |
| 743 | With the new module, bundling your application is as simple as putting all |
| 744 | the files, including a ``__main__.py`` file, into a directory ``myapp`` |
Martin Panter | 1050d2d | 2016-07-26 11:18:21 +0200 | [diff] [blame] | 745 | and running: |
| 746 | |
| 747 | .. code-block:: shell-session |
Brett Cannon | cc4dfc1 | 2015-03-13 10:40:49 -0400 | [diff] [blame] | 748 | |
| 749 | $ python -m zipapp myapp |
| 750 | $ python myapp.pyz |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 751 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 752 | The module implementation has been contributed by Paul Moore in |
| 753 | :issue:`23491`. |
| 754 | |
| 755 | .. seealso:: |
| 756 | |
| 757 | :pep:`441` -- Improving Python ZIP Application Support |
| 758 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 759 | |
| 760 | Improved Modules |
| 761 | ================ |
| 762 | |
Berker Peksag | 8089cd6 | 2015-02-14 01:39:17 +0200 | [diff] [blame] | 763 | argparse |
| 764 | -------- |
| 765 | |
Martin Panter | c04fb56 | 2016-02-10 05:44:01 +0000 | [diff] [blame] | 766 | The :class:`~argparse.ArgumentParser` class now allows disabling |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 767 | :ref:`abbreviated usage <prefix-matching>` of long options by setting |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 768 | :ref:`allow_abbrev` to ``False``. (Contributed by Jonathan Paugh, |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 769 | Steven Bethard, paul j3 and Daniel Eriksson in :issue:`14910`.) |
| 770 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 771 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 772 | asyncio |
| 773 | ------- |
| 774 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 775 | Since the :mod:`asyncio` module is :term:`provisional <provisional api>`, |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 776 | all changes introduced in Python 3.5 have also been backported to Python 3.4.x. |
| 777 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 778 | Notable changes in the :mod:`asyncio` module since Python 3.4.0: |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 779 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 780 | * New debugging APIs: :meth:`loop.set_debug() <asyncio.BaseEventLoop.set_debug>` |
Yury Selivanov | 72dab13 | 2015-09-13 01:39:05 -0400 | [diff] [blame] | 781 | and :meth:`loop.get_debug() <asyncio.BaseEventLoop.get_debug>` methods. |
Yury Selivanov | 63ae9f3b | 2015-09-13 00:29:02 -0400 | [diff] [blame] | 782 | (Contributed by Victor Stinner.) |
| 783 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 784 | * The proactor event loop now supports SSL. |
| 785 | (Contributed by Antoine Pitrou and Victor Stinner in :issue:`22560`.) |
| 786 | |
Yury Selivanov | 72dab13 | 2015-09-13 01:39:05 -0400 | [diff] [blame] | 787 | * A new :meth:`loop.is_closed() <asyncio.BaseEventLoop.is_closed>` method to |
Yury Selivanov | 63ae9f3b | 2015-09-13 00:29:02 -0400 | [diff] [blame] | 788 | check if the event loop is closed. |
| 789 | (Contributed by Victor Stinner in :issue:`21326`.) |
| 790 | |
| 791 | * A new :meth:`loop.create_task() <asyncio.BaseEventLoop.create_task>` |
| 792 | to conveniently create and schedule a new :class:`~asyncio.Task` |
| 793 | for a coroutine. The ``create_task`` method is also used by all |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 794 | asyncio functions that wrap coroutines into tasks, such as |
| 795 | :func:`asyncio.wait`, :func:`asyncio.gather`, etc. |
Yury Selivanov | 63ae9f3b | 2015-09-13 00:29:02 -0400 | [diff] [blame] | 796 | (Contributed by Victor Stinner.) |
| 797 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 798 | * A new :meth:`transport.get_write_buffer_limits() <asyncio.WriteTransport.get_write_buffer_limits>` |
Yury Selivanov | 63ae9f3b | 2015-09-13 00:29:02 -0400 | [diff] [blame] | 799 | method to inquire for *high-* and *low-* water limits of the flow |
| 800 | control. |
| 801 | (Contributed by Victor Stinner.) |
| 802 | |
| 803 | * The :func:`~asyncio.async` function is deprecated in favor of |
| 804 | :func:`~asyncio.ensure_future`. |
| 805 | (Contributed by Yury Selivanov.) |
| 806 | |
Benjamin Peterson | c1db513 | 2016-09-09 12:46:42 -0700 | [diff] [blame] | 807 | * New :meth:`loop.set_task_factory() |
| 808 | <asyncio.AbstractEventLoop.set_task_factory>` and |
| 809 | :meth:`loop.get_task_factory() <asyncio.AbstractEventLoop.get_task_factory>` |
| 810 | methods to customize the task factory that :meth:`loop.create_task() |
| 811 | <asyncio.BaseEventLoop.create_task>` method uses. (Contributed by Yury |
| 812 | Selivanov.) |
Yury Selivanov | 63ae9f3b | 2015-09-13 00:29:02 -0400 | [diff] [blame] | 813 | |
Yury Selivanov | 72dab13 | 2015-09-13 01:39:05 -0400 | [diff] [blame] | 814 | * New :meth:`Queue.join() <asyncio.Queue.join>` and |
| 815 | :meth:`Queue.task_done() <asyncio.Queue.task_done>` queue methods. |
Yury Selivanov | 63ae9f3b | 2015-09-13 00:29:02 -0400 | [diff] [blame] | 816 | (Contributed by Victor Stinner.) |
| 817 | |
| 818 | * The ``JoinableQueue`` class was removed, in favor of the |
| 819 | :class:`asyncio.Queue` class. |
| 820 | (Contributed by Victor Stinner.) |
| 821 | |
Yury Selivanov | 43d71e2 | 2015-10-02 15:05:59 -0400 | [diff] [blame] | 822 | Updates in 3.5.1: |
| 823 | |
| 824 | * The :func:`~asyncio.ensure_future` function and all functions that |
| 825 | use it, such as :meth:`loop.run_until_complete() <asyncio.BaseEventLoop.run_until_complete>`, |
| 826 | now accept all kinds of :term:`awaitable objects <awaitable>`. |
| 827 | (Contributed by Yury Selivanov.) |
| 828 | |
Yury Selivanov | bf077ee | 2015-12-15 00:30:18 -0500 | [diff] [blame] | 829 | * New :func:`~asyncio.run_coroutine_threadsafe` function to submit |
| 830 | coroutines to event loops from other threads. |
| 831 | (Contributed by Vincent Michel.) |
| 832 | |
Yury Selivanov | 4a18b35 | 2015-12-15 00:38:28 -0500 | [diff] [blame] | 833 | * New :meth:`Transport.is_closing() <asyncio.BaseTransport.is_closing>` |
Yury Selivanov | bf077ee | 2015-12-15 00:30:18 -0500 | [diff] [blame] | 834 | method to check if the transport is closing or closed. |
| 835 | (Contributed by Yury Selivanov.) |
| 836 | |
| 837 | * The :meth:`loop.create_server() <asyncio.BaseEventLoop.create_server>` |
| 838 | method can now accept a list of hosts. |
| 839 | (Contributed by Yann Sionneau.) |
| 840 | |
Yury Selivanov | 950204d | 2016-05-16 16:23:00 -0400 | [diff] [blame] | 841 | Updates in 3.5.2: |
| 842 | |
| 843 | * New :meth:`loop.create_future() <asyncio.BaseEventLoop.create_future>` |
| 844 | method to create Future objects. This allows alternative event |
| 845 | loop implementations, such as |
| 846 | `uvloop <https://github.com/MagicStack/uvloop>`_, to provide a faster |
| 847 | :class:`asyncio.Future` implementation. |
| 848 | (Contributed by Yury Selivanov.) |
| 849 | |
| 850 | * New :meth:`loop.get_exception_handler() <asyncio.BaseEventLoop.get_exception_handler>` |
| 851 | method to get the current exception handler. |
| 852 | (Contributed by Yury Selivanov.) |
| 853 | |
Yury Selivanov | 950204d | 2016-05-16 16:23:00 -0400 | [diff] [blame] | 854 | * New :meth:`StreamReader.readuntil() <asyncio.StreamReader.readuntil>` |
| 855 | method to read data from the stream until a separator bytes |
| 856 | sequence appears. |
| 857 | (Contributed by Mark Korenberg.) |
| 858 | |
Yury Selivanov | af74512 | 2016-06-08 12:55:29 -0400 | [diff] [blame] | 859 | * The :meth:`loop.create_connection() <asyncio.BaseEventLoop.create_connection>` |
| 860 | and :meth:`loop.create_server() <asyncio.BaseEventLoop.create_server>` |
| 861 | methods are optimized to avoid calling the system ``getaddrinfo`` |
Yury Selivanov | 950204d | 2016-05-16 16:23:00 -0400 | [diff] [blame] | 862 | function if the address is already resolved. |
| 863 | (Contributed by A. Jesse Jiryu Davis.) |
| 864 | |
Yury Selivanov | af74512 | 2016-06-08 12:55:29 -0400 | [diff] [blame] | 865 | * The :meth:`loop.sock_connect(sock, address) <asyncio.BaseEventLoop.sock_connect>` |
| 866 | no longer requires the *address* to be resolved prior to the call. |
| 867 | (Contributed by A. Jesse Jiryu Davis.) |
| 868 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 869 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 870 | bz2 |
| 871 | --- |
| 872 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 873 | The :meth:`BZ2Decompressor.decompress <bz2.BZ2Decompressor.decompress>` |
| 874 | method now accepts an optional *max_length* argument to limit the maximum |
| 875 | size of decompressed data. (Contributed by Nikolaus Rath in :issue:`15955`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 876 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 877 | |
Berker Peksag | bf5e960 | 2015-02-06 10:21:37 +0200 | [diff] [blame] | 878 | cgi |
| 879 | --- |
| 880 | |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 881 | The :class:`~cgi.FieldStorage` class now supports the :term:`context manager` |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 882 | protocol. (Contributed by Berker Peksag in :issue:`20289`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 883 | |
Berker Peksag | bf5e960 | 2015-02-06 10:21:37 +0200 | [diff] [blame] | 884 | |
Tal Einat | d5519ed | 2015-05-31 22:05:00 +0300 | [diff] [blame] | 885 | cmath |
| 886 | ----- |
| 887 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 888 | A new function :func:`~cmath.isclose` provides a way to test for approximate |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 889 | equality. (Contributed by Chris Barker and Tal Einat in :issue:`24270`.) |
Tal Einat | d5519ed | 2015-05-31 22:05:00 +0300 | [diff] [blame] | 890 | |
| 891 | |
R David Murray | c31e622 | 2014-09-29 11:25:00 -0400 | [diff] [blame] | 892 | code |
| 893 | ---- |
| 894 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 895 | The :func:`InteractiveInterpreter.showtraceback() <code.InteractiveInterpreter.showtraceback>` |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 896 | method now prints the full chained traceback, just like the interactive |
| 897 | interpreter. (Contributed by Claudiu Popa in :issue:`17442`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 898 | |
R David Murray | c31e622 | 2014-09-29 11:25:00 -0400 | [diff] [blame] | 899 | |
Raymond Hettinger | eac503a | 2015-05-13 01:09:59 -0700 | [diff] [blame] | 900 | collections |
| 901 | ----------- |
| 902 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 903 | .. _whatsnew-ordereddict: |
| 904 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 905 | The :class:`~collections.OrderedDict` class is now implemented in C, which |
| 906 | makes it 4 to 100 times faster. (Contributed by Eric Snow in :issue:`16991`.) |
| 907 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 908 | :meth:`OrderedDict.items() <collections.OrderedDict.items>`, |
| 909 | :meth:`OrderedDict.keys() <collections.OrderedDict.keys>`, |
| 910 | :meth:`OrderedDict.values() <collections.OrderedDict.values>` views now support |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 911 | :func:`reversed` iteration. |
| 912 | (Contributed by Serhiy Storchaka in :issue:`19505`.) |
| 913 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 914 | The :class:`~collections.deque` class now defines |
| 915 | :meth:`~collections.deque.index`, :meth:`~collections.deque.insert`, and |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 916 | :meth:`~collections.deque.copy`, and supports the ``+`` and ``*`` operators. |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 917 | This allows deques to be recognized as a :class:`~collections.abc.MutableSequence` |
| 918 | and improves their substitutability for lists. |
Martin Panter | 0e5eba2 | 2015-10-31 12:18:10 +0000 | [diff] [blame] | 919 | (Contributed by Raymond Hettinger in :issue:`23704`.) |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 920 | |
| 921 | Docstrings produced by :func:`~collections.namedtuple` can now be updated:: |
Raymond Hettinger | eac503a | 2015-05-13 01:09:59 -0700 | [diff] [blame] | 922 | |
| 923 | Point = namedtuple('Point', ['x', 'y']) |
Raymond Hettinger | 850be0f | 2015-11-09 08:24:53 -0800 | [diff] [blame] | 924 | Point.__doc__ += ': Cartesian coodinate' |
Raymond Hettinger | eac503a | 2015-05-13 01:09:59 -0700 | [diff] [blame] | 925 | Point.x.__doc__ = 'abscissa' |
| 926 | Point.y.__doc__ = 'ordinate' |
| 927 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 928 | (Contributed by Berker Peksag in :issue:`24064`.) |
Raymond Hettinger | eac503a | 2015-05-13 01:09:59 -0700 | [diff] [blame] | 929 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 930 | The :class:`~collections.UserString` class now implements the |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 931 | :meth:`__getnewargs__`, :meth:`__rmod__`, :meth:`~str.casefold`, |
| 932 | :meth:`~str.format_map`, :meth:`~str.isprintable`, and :meth:`~str.maketrans` |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 933 | methods to match the corresponding methods of :class:`str`. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 934 | (Contributed by Joe Jevnik in :issue:`22189`.) |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 935 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 936 | |
| 937 | collections.abc |
| 938 | --------------- |
| 939 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 940 | The :meth:`Sequence.index() <collections.abc.Sequence.index>` method now |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 941 | accepts *start* and *stop* arguments to match the corresponding methods |
| 942 | of :class:`tuple`, :class:`list`, etc. |
| 943 | (Contributed by Devin Jeanpierre in :issue:`23086`.) |
| 944 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 945 | A new :class:`~collections.abc.Generator` abstract base class. (Contributed |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 946 | by Stefan Behnel in :issue:`24018`.) |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 947 | |
Martin Panter | 0e5eba2 | 2015-10-31 12:18:10 +0000 | [diff] [blame] | 948 | New :class:`~collections.abc.Awaitable`, :class:`~collections.abc.Coroutine`, |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 949 | :class:`~collections.abc.AsyncIterator`, and |
| 950 | :class:`~collections.abc.AsyncIterable` abstract base classes. |
| 951 | (Contributed by Yury Selivanov in :issue:`24184`.) |
| 952 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 953 | For earlier Python versions, a backport of the new ABCs is available in an |
Stéphane Wirtel | 19177fb | 2018-05-15 20:58:35 +0200 | [diff] [blame] | 954 | external `PyPI package <https://pypi.org/project/backports_abc>`_. |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 955 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 956 | |
Brett Cannon | f1a8df0 | 2014-09-12 10:39:48 -0400 | [diff] [blame] | 957 | compileall |
| 958 | ---------- |
| 959 | |
Martin Panter | c04fb56 | 2016-02-10 05:44:01 +0000 | [diff] [blame] | 960 | A new :mod:`compileall` option, :samp:`-j {N}`, allows running *N* workers |
Martin Panter | 96a4f07 | 2016-02-10 01:17:51 +0000 | [diff] [blame] | 961 | simultaneously to perform parallel bytecode compilation. |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 962 | The :func:`~compileall.compile_dir` function has a corresponding ``workers`` |
| 963 | parameter. (Contributed by Claudiu Popa in :issue:`16104`.) |
Brett Cannon | f1a8df0 | 2014-09-12 10:39:48 -0400 | [diff] [blame] | 964 | |
Martin Panter | c04fb56 | 2016-02-10 05:44:01 +0000 | [diff] [blame] | 965 | Another new option, ``-r``, allows controlling the maximum recursion |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 966 | level for subdirectories. (Contributed by Claudiu Popa in :issue:`19628`.) |
| 967 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 968 | The ``-q`` command line option can now be specified more than once, in |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 969 | which case all output, including errors, will be suppressed. The corresponding |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 970 | ``quiet`` parameter in :func:`~compileall.compile_dir`, |
| 971 | :func:`~compileall.compile_file`, and :func:`~compileall.compile_path` can now |
| 972 | accept an integer value indicating the level of output suppression. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 973 | (Contributed by Thomas Kluyver in :issue:`21338`.) |
| 974 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 975 | |
| 976 | concurrent.futures |
| 977 | ------------------ |
| 978 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 979 | The :meth:`Executor.map() <concurrent.futures.Executor.map>` method now accepts a |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 980 | *chunksize* argument to allow batching of tasks to improve performance when |
| 981 | :meth:`~concurrent.futures.ProcessPoolExecutor` is used. |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 982 | (Contributed by Dan O'Reilly in :issue:`11271`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 983 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 984 | The number of workers in the :class:`~concurrent.futures.ThreadPoolExecutor` |
| 985 | constructor is optional now. The default value is 5 times the number of CPUs. |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 986 | (Contributed by Claudiu Popa in :issue:`21527`.) |
| 987 | |
| 988 | |
| 989 | configparser |
| 990 | ------------ |
| 991 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 992 | :mod:`configparser` now provides a way to customize the conversion |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 993 | of values by specifying a dictionary of converters in the |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 994 | :class:`~configparser.ConfigParser` constructor, or by defining them |
| 995 | as methods in ``ConfigParser`` subclasses. Converters defined in |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 996 | a parser instance are inherited by its section proxies. |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 997 | |
| 998 | Example:: |
| 999 | |
| 1000 | >>> import configparser |
| 1001 | >>> conv = {} |
| 1002 | >>> conv['list'] = lambda v: [e.strip() for e in v.split() if e.strip()] |
| 1003 | >>> cfg = configparser.ConfigParser(converters=conv) |
| 1004 | >>> cfg.read_string(""" |
| 1005 | ... [s] |
| 1006 | ... list = a b c d e f g |
| 1007 | ... """) |
| 1008 | >>> cfg.get('s', 'list') |
| 1009 | 'a b c d e f g' |
| 1010 | >>> cfg.getlist('s', 'list') |
| 1011 | ['a', 'b', 'c', 'd', 'e', 'f', 'g'] |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1012 | >>> section = cfg['s'] |
| 1013 | >>> section.getlist('list') |
| 1014 | ['a', 'b', 'c', 'd', 'e', 'f', 'g'] |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1015 | |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1016 | (Contributed by Łukasz Langa in :issue:`18159`.) |
| 1017 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1018 | |
Berker Peksag | bb44fe0 | 2014-11-28 23:28:06 +0200 | [diff] [blame] | 1019 | contextlib |
| 1020 | ---------- |
| 1021 | |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 1022 | The new :func:`~contextlib.redirect_stderr` :term:`context manager` (similar to |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1023 | :func:`~contextlib.redirect_stdout`) makes it easier for utility scripts to |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1024 | handle inflexible APIs that write their output to :data:`sys.stderr` and |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1025 | don't provide any options to redirect it:: |
| 1026 | |
| 1027 | >>> import contextlib, io, logging |
| 1028 | >>> f = io.StringIO() |
| 1029 | >>> with contextlib.redirect_stderr(f): |
| 1030 | ... logging.warning('warning') |
| 1031 | ... |
| 1032 | >>> f.getvalue() |
| 1033 | 'WARNING:root:warning\n' |
| 1034 | |
| 1035 | (Contributed by Berker Peksag in :issue:`22389`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1036 | |
Berker Peksag | bb44fe0 | 2014-11-28 23:28:06 +0200 | [diff] [blame] | 1037 | |
Yury Selivanov | fe369a6 | 2015-09-13 08:29:19 -0400 | [diff] [blame] | 1038 | csv |
| 1039 | --- |
| 1040 | |
| 1041 | The :meth:`~csv.csvwriter.writerow` method now supports arbitrary iterables, |
| 1042 | not just sequences. (Contributed by Serhiy Storchaka in :issue:`23171`.) |
| 1043 | |
| 1044 | |
Steve Dower | d2bc389 | 2015-04-15 18:06:05 -0400 | [diff] [blame] | 1045 | curses |
| 1046 | ------ |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1047 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1048 | The new :func:`~curses.update_lines_cols` function updates the :envvar:`LINES` |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1049 | and :envvar:`COLS` environment variables. This is useful for detecting |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1050 | manual screen resizing. (Contributed by Arnon Yaari in :issue:`4254`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1051 | |
Steve Dower | d2bc389 | 2015-04-15 18:06:05 -0400 | [diff] [blame] | 1052 | |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1053 | dbm |
| 1054 | --- |
| 1055 | |
| 1056 | :func:`dumb.open <dbm.dumb.open>` always creates a new database when the flag |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1057 | has the value ``"n"``. (Contributed by Claudiu Popa in :issue:`18039`.) |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1058 | |
| 1059 | |
Berker Peksag | 102029d | 2015-03-15 01:18:47 +0200 | [diff] [blame] | 1060 | difflib |
| 1061 | ------- |
| 1062 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1063 | The charset of HTML documents generated by |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1064 | :meth:`HtmlDiff.make_file() <difflib.HtmlDiff.make_file>` |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1065 | can now be customized by using a new *charset* keyword-only argument. |
| 1066 | The default charset of HTML document changed from ``"ISO-8859-1"`` |
| 1067 | to ``"utf-8"``. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1068 | (Contributed by Berker Peksag in :issue:`2052`.) |
Berker Peksag | 102029d | 2015-03-15 01:18:47 +0200 | [diff] [blame] | 1069 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1070 | The :func:`~difflib.diff_bytes` function can now compare lists of byte |
| 1071 | strings. This fixes a regression from Python 2. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1072 | (Contributed by Terry J. Reedy and Greg Ward in :issue:`17445`.) |
| 1073 | |
Greg Ward | 4d9d256 | 2015-04-20 20:21:21 -0400 | [diff] [blame] | 1074 | |
Berker Peksag | 618e315 | 2015-01-27 02:59:09 +0200 | [diff] [blame] | 1075 | distutils |
| 1076 | --------- |
| 1077 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1078 | Both the ``build`` and ``build_ext`` commands now accept a ``-j`` option to |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1079 | enable parallel building of extension modules. |
| 1080 | (Contributed by Antoine Pitrou in :issue:`5309`.) |
Berker Peksag | 618e315 | 2015-01-27 02:59:09 +0200 | [diff] [blame] | 1081 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1082 | The :mod:`distutils` module now supports ``xz`` compression, and can be |
| 1083 | enabled by passing ``xztar`` as an argument to ``bdist --format``. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1084 | (Contributed by Serhiy Storchaka in :issue:`16314`.) |
| 1085 | |
Serhiy Storchaka | b9cec6a | 2015-05-16 22:13:27 +0300 | [diff] [blame] | 1086 | |
Antoine Pitrou | b9d9ce7 | 2014-05-15 22:47:33 +0200 | [diff] [blame] | 1087 | doctest |
| 1088 | ------- |
Giampaolo Rodola' | e09fb71 | 2014-04-04 15:34:17 +0200 | [diff] [blame] | 1089 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1090 | The :func:`~doctest.DocTestSuite` function returns an empty |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1091 | :class:`unittest.TestSuite` if *module* contains no docstrings, instead of |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1092 | raising :exc:`ValueError`. (Contributed by Glenn Jones in :issue:`15916`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1093 | |
Antoine Pitrou | b9d9ce7 | 2014-05-15 22:47:33 +0200 | [diff] [blame] | 1094 | |
R David Murray | b744f3a | 2015-05-16 15:41:07 -0400 | [diff] [blame] | 1095 | email |
| 1096 | ----- |
| 1097 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1098 | A new policy option :attr:`Policy.mangle_from_ <email.policy.Policy.mangle_from_>` |
| 1099 | controls whether or not lines that start with ``"From "`` in email bodies are |
| 1100 | prefixed with a ``">"`` character by generators. The default is ``True`` for |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1101 | :attr:`~email.policy.compat32` and ``False`` for all other policies. |
| 1102 | (Contributed by Milan Oberkirch in :issue:`20098`.) |
R David Murray | fdb23c2 | 2015-05-17 14:24:33 -0400 | [diff] [blame] | 1103 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1104 | A new |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1105 | :meth:`Message.get_content_disposition() <email.message.Message.get_content_disposition>` |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1106 | method provides easy access to a canonical value for the |
| 1107 | :mailheader:`Content-Disposition` header. |
| 1108 | (Contributed by Abhilash Raj in :issue:`21083`.) |
R David Murray | b744f3a | 2015-05-16 15:41:07 -0400 | [diff] [blame] | 1109 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1110 | A new policy option :attr:`EmailPolicy.utf8 <email.policy.EmailPolicy.utf8>` |
| 1111 | can be set to ``True`` to encode email headers using the UTF-8 charset instead |
| 1112 | of using encoded words. This allows ``Messages`` to be formatted according to |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1113 | :rfc:`6532` and used with an SMTP server that supports the :rfc:`6531` |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1114 | ``SMTPUTF8`` extension. (Contributed by R. David Murray in |
| 1115 | :issue:`24211`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1116 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1117 | The :class:`mime.text.MIMEText <email.mime.text.MIMEText>` constructor now |
| 1118 | accepts a :class:`charset.Charset <email.charset.Charset>` instance. |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1119 | (Contributed by Claude Paroz and Berker Peksag in :issue:`16324`.) |
| 1120 | |
R David Murray | 224ef3e | 2015-05-17 11:29:21 -0400 | [diff] [blame] | 1121 | |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 1122 | enum |
| 1123 | ---- |
| 1124 | |
| 1125 | The :class:`~enum.Enum` callable has a new parameter *start* to |
| 1126 | specify the initial number of enum values if only *names* are provided:: |
| 1127 | |
| 1128 | >>> Animal = enum.Enum('Animal', 'cat dog', start=10) |
| 1129 | >>> Animal.cat |
| 1130 | <Animal.cat: 10> |
| 1131 | >>> Animal.dog |
| 1132 | <Animal.dog: 11> |
| 1133 | |
| 1134 | (Contributed by Ethan Furman in :issue:`21706`.) |
| 1135 | |
| 1136 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1137 | faulthandler |
| 1138 | ------------ |
| 1139 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1140 | The :func:`~faulthandler.enable`, :func:`~faulthandler.register`, |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1141 | :func:`~faulthandler.dump_traceback` and |
| 1142 | :func:`~faulthandler.dump_traceback_later` functions now accept file |
| 1143 | descriptors in addition to file-like objects. |
| 1144 | (Contributed by Wei Wu in :issue:`23566`.) |
| 1145 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1146 | |
| 1147 | functools |
| 1148 | --------- |
| 1149 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 1150 | .. _whatsnew-lrucache: |
| 1151 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1152 | Most of the :func:`~functools.lru_cache` machinery is now implemented in C, making |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1153 | it significantly faster. (Contributed by Matt Joiner, Alexey Kachayev, and |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1154 | Serhiy Storchaka in :issue:`14373`.) |
| 1155 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1156 | |
Serhiy Storchaka | c2edcdd | 2014-09-11 12:17:37 +0300 | [diff] [blame] | 1157 | glob |
| 1158 | ---- |
| 1159 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1160 | The :func:`~glob.iglob` and :func:`~glob.glob` functions now support recursive |
| 1161 | search in subdirectories, using the ``"**"`` pattern. |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1162 | (Contributed by Serhiy Storchaka in :issue:`13968`.) |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1163 | |
Serhiy Storchaka | c2edcdd | 2014-09-11 12:17:37 +0300 | [diff] [blame] | 1164 | |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1165 | gzip |
| 1166 | ---- |
| 1167 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1168 | The *mode* argument of the :class:`~gzip.GzipFile` constructor now |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1169 | accepts ``"x"`` to request exclusive creation. |
| 1170 | (Contributed by Tim Heaney in :issue:`19222`.) |
| 1171 | |
| 1172 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1173 | heapq |
| 1174 | ----- |
| 1175 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1176 | Element comparison in :func:`~heapq.merge` can now be customized by |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1177 | passing a :term:`key function` in a new optional *key* keyword argument, |
| 1178 | and a new optional *reverse* keyword argument can be used to reverse element |
| 1179 | comparison:: |
| 1180 | |
| 1181 | >>> import heapq |
| 1182 | >>> a = ['9', '777', '55555'] |
| 1183 | >>> b = ['88', '6666'] |
| 1184 | >>> list(heapq.merge(a, b, key=len)) |
| 1185 | ['9', '88', '777', '6666', '55555'] |
| 1186 | >>> list(heapq.merge(reversed(a), reversed(b), key=len, reverse=True)) |
| 1187 | ['55555', '6666', '777', '88', '9'] |
| 1188 | |
| 1189 | (Contributed by Raymond Hettinger in :issue:`13742`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1190 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1191 | |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 1192 | http |
| 1193 | ---- |
| 1194 | |
| 1195 | A new :class:`HTTPStatus <http.HTTPStatus>` enum that defines a set of |
| 1196 | HTTP status codes, reason phrases and long descriptions written in English. |
| 1197 | (Contributed by Demian Brecht in :issue:`21793`.) |
| 1198 | |
| 1199 | |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1200 | http.client |
| 1201 | ----------- |
| 1202 | |
| 1203 | :meth:`HTTPConnection.getresponse() <http.client.HTTPConnection.getresponse>` |
| 1204 | now raises a :exc:`~http.client.RemoteDisconnected` exception when a |
| 1205 | remote server connection is closed unexpectedly. Additionally, if a |
| 1206 | :exc:`ConnectionError` (of which ``RemoteDisconnected`` |
| 1207 | is a subclass) is raised, the client socket is now closed automatically, |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1208 | and will reconnect on the next request:: |
| 1209 | |
| 1210 | import http.client |
| 1211 | conn = http.client.HTTPConnection('www.python.org') |
| 1212 | for retries in range(3): |
| 1213 | try: |
| 1214 | conn.request('GET', '/') |
| 1215 | resp = conn.getresponse() |
| 1216 | except http.client.RemoteDisconnected: |
| 1217 | pass |
| 1218 | |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1219 | (Contributed by Martin Panter in :issue:`3566`.) |
| 1220 | |
| 1221 | |
Guido van Rossum | 7ca1353 | 2015-05-23 15:27:51 -0700 | [diff] [blame] | 1222 | idlelib and IDLE |
Terry Jan Reedy | 44825cf | 2015-05-23 18:19:42 -0400 | [diff] [blame] | 1223 | ---------------- |
| 1224 | |
| 1225 | Since idlelib implements the IDLE shell and editor and is not intended for |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1226 | import by other programs, it gets improvements with every release. See |
Terry Jan Reedy | 44825cf | 2015-05-23 18:19:42 -0400 | [diff] [blame] | 1227 | :file:`Lib/idlelib/NEWS.txt` for a cumulative list of changes since 3.4.0, |
| 1228 | as well as changes made in future 3.5.x releases. This file is also available |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 1229 | from the IDLE :menuselection:`Help --> About IDLE` dialog. |
Terry Jan Reedy | 44825cf | 2015-05-23 18:19:42 -0400 | [diff] [blame] | 1230 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1231 | |
Serhiy Storchaka | 38684c3 | 2014-09-09 19:07:49 +0300 | [diff] [blame] | 1232 | imaplib |
| 1233 | ------- |
| 1234 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1235 | The :class:`~imaplib.IMAP4` class now supports the :term:`context manager` protocol. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1236 | When used in a :keyword:`with` statement, the IMAP4 ``LOGOUT`` |
| 1237 | command will be called automatically at the end of the block. |
| 1238 | (Contributed by Tarek Ziadé and Serhiy Storchaka in :issue:`4972`.) |
Serhiy Storchaka | 38684c3 | 2014-09-09 19:07:49 +0300 | [diff] [blame] | 1239 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1240 | The :mod:`imaplib` module now supports :rfc:`5161` (ENABLE Extension) |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1241 | and :rfc:`6855` (UTF-8 Support) via the :meth:`IMAP4.enable() <imaplib.IMAP4.enable>` |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1242 | method. A new :attr:`IMAP4.utf8_enabled <imaplib.IMAP4.utf8_enabled>` |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1243 | attribute tracks whether or not :rfc:`6855` support is enabled. |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1244 | (Contributed by Milan Oberkirch, R. David Murray, and Maciej Szulik in |
| 1245 | :issue:`21800`.) |
R David Murray | a6429db | 2015-05-10 19:17:23 -0400 | [diff] [blame] | 1246 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1247 | The :mod:`imaplib` module now automatically encodes non-ASCII string usernames |
| 1248 | and passwords using UTF-8, as recommended by the RFCs. (Contributed by Milan |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1249 | Oberkirch in :issue:`21800`.) |
| 1250 | |
R David Murray | a6429db | 2015-05-10 19:17:23 -0400 | [diff] [blame] | 1251 | |
R David Murray | 2f60820 | 2014-06-26 12:27:57 -0400 | [diff] [blame] | 1252 | imghdr |
| 1253 | ------ |
| 1254 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1255 | The :func:`~imghdr.what` function now recognizes the |
| 1256 | `OpenEXR <http://www.openexr.com>`_ format |
| 1257 | (contributed by Martin Vignali and Claudiu Popa in :issue:`20295`), |
| 1258 | and the `WebP <https://en.wikipedia.org/wiki/WebP>`_ format |
| 1259 | (contributed by Fabrice Aneche and Claudiu Popa in :issue:`20197`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1260 | |
R David Murray | 2f60820 | 2014-06-26 12:27:57 -0400 | [diff] [blame] | 1261 | |
Antoine Pitrou | b9d9ce7 | 2014-05-15 22:47:33 +0200 | [diff] [blame] | 1262 | importlib |
| 1263 | --------- |
| 1264 | |
Yury Selivanov | 3b76552 | 2015-09-10 19:02:24 -0400 | [diff] [blame] | 1265 | The :class:`util.LazyLoader <importlib.util.LazyLoader>` class allows for |
| 1266 | lazy loading of modules in applications where startup time is important. |
| 1267 | (Contributed by Brett Cannon in :issue:`17621`.) |
Antoine Pitrou | b9d9ce7 | 2014-05-15 22:47:33 +0200 | [diff] [blame] | 1268 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1269 | The :func:`abc.InspectLoader.source_to_code() <importlib.abc.InspectLoader.source_to_code>` |
Yury Selivanov | 3b76552 | 2015-09-10 19:02:24 -0400 | [diff] [blame] | 1270 | method is now a static method. This makes it easier to initialize a module |
| 1271 | object with code compiled from a string by running |
| 1272 | ``exec(code, module.__dict__)``. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1273 | (Contributed by Brett Cannon in :issue:`21156`.) |
Antoine Pitrou | b9d9ce7 | 2014-05-15 22:47:33 +0200 | [diff] [blame] | 1274 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1275 | The new :func:`util.module_from_spec() <importlib.util.module_from_spec>` |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1276 | function is now the preferred way to create a new module. As opposed to |
| 1277 | creating a :class:`types.ModuleType` instance directly, this new function |
| 1278 | will set the various import-controlled attributes based on the passed-in |
| 1279 | spec object. (Contributed by Brett Cannon in :issue:`20383`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1280 | |
Brett Cannon | 2a17bde | 2014-05-30 14:55:29 -0400 | [diff] [blame] | 1281 | |
Antoine Pitrou | b9d9ce7 | 2014-05-15 22:47:33 +0200 | [diff] [blame] | 1282 | inspect |
| 1283 | ------- |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 1284 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1285 | Both the :class:`~inspect.Signature` and :class:`~inspect.Parameter` classes are |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1286 | now picklable and hashable. (Contributed by Yury Selivanov in :issue:`20726` |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1287 | and :issue:`20334`.) |
Yury Selivanov | a5d63dd | 2014-03-27 11:31:43 -0400 | [diff] [blame] | 1288 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1289 | A new |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1290 | :meth:`BoundArguments.apply_defaults() <inspect.BoundArguments.apply_defaults>` |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1291 | method provides a way to set default values for missing arguments:: |
| 1292 | |
| 1293 | >>> def foo(a, b='ham', *args): pass |
| 1294 | >>> ba = inspect.signature(foo).bind('spam') |
| 1295 | >>> ba.apply_defaults() |
| 1296 | >>> ba.arguments |
| 1297 | OrderedDict([('a', 'spam'), ('b', 'ham'), ('args', ())]) |
| 1298 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1299 | (Contributed by Yury Selivanov in :issue:`24190`.) |
Yury Selivanov | b907a51 | 2015-05-16 13:45:09 -0400 | [diff] [blame] | 1300 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1301 | A new class method |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1302 | :meth:`Signature.from_callable() <inspect.Signature.from_callable>` makes |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1303 | subclassing of :class:`~inspect.Signature` easier. (Contributed |
| 1304 | by Yury Selivanov and Eric Snow in :issue:`17373`.) |
Yury Selivanov | da39645 | 2014-03-27 12:09:24 -0400 | [diff] [blame] | 1305 | |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 1306 | The :func:`~inspect.signature` function now accepts a *follow_wrapped* |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1307 | optional keyword argument, which, when set to ``False``, disables automatic |
| 1308 | following of ``__wrapped__`` links. |
| 1309 | (Contributed by Yury Selivanov in :issue:`20691`.) |
Yury Selivanov | bcd4fc1 | 2015-05-20 14:30:08 -0400 | [diff] [blame] | 1310 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1311 | A set of new functions to inspect |
| 1312 | :term:`coroutine functions <coroutine function>` and |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1313 | :term:`coroutine objects <coroutine>` has been added: |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1314 | :func:`~inspect.iscoroutine`, :func:`~inspect.iscoroutinefunction`, |
| 1315 | :func:`~inspect.isawaitable`, :func:`~inspect.getcoroutinelocals`, |
| 1316 | and :func:`~inspect.getcoroutinestate`. |
| 1317 | (Contributed by Yury Selivanov in :issue:`24017` and :issue:`24400`.) |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 1318 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1319 | The :func:`~inspect.stack`, :func:`~inspect.trace`, |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1320 | :func:`~inspect.getouterframes`, and :func:`~inspect.getinnerframes` |
| 1321 | functions now return a list of named tuples. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1322 | (Contributed by Daniel Shahaf in :issue:`16808`.) |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 1323 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1324 | |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 1325 | io |
| 1326 | -- |
| 1327 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1328 | A new :meth:`BufferedIOBase.readinto1() <io.BufferedIOBase.readinto1>` |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 1329 | method, that uses at most one call to the underlying raw stream's |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1330 | :meth:`RawIOBase.read() <io.RawIOBase.read>` or |
| 1331 | :meth:`RawIOBase.readinto() <io.RawIOBase.readinto>` methods. |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 1332 | (Contributed by Nikolaus Rath in :issue:`20578`.) |
| 1333 | |
| 1334 | |
Antoine Pitrou | 0dfce56 | 2014-05-15 22:55:40 +0200 | [diff] [blame] | 1335 | ipaddress |
| 1336 | --------- |
| 1337 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1338 | Both the :class:`~ipaddress.IPv4Network` and :class:`~ipaddress.IPv6Network` classes |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1339 | now accept an ``(address, netmask)`` tuple argument, so as to easily construct |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1340 | network objects from existing addresses:: |
| 1341 | |
| 1342 | >>> import ipaddress |
| 1343 | >>> ipaddress.IPv4Network(('127.0.0.0', 8)) |
| 1344 | IPv4Network('127.0.0.0/8') |
| 1345 | >>> ipaddress.IPv4Network(('127.0.0.0', '255.0.0.0')) |
| 1346 | IPv4Network('127.0.0.0/8') |
| 1347 | |
| 1348 | (Contributed by Peter Moody and Antoine Pitrou in :issue:`16531`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1349 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1350 | A new :attr:`~ipaddress.IPv4Network.reverse_pointer` attribute for the |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 1351 | :class:`~ipaddress.IPv4Network` and :class:`~ipaddress.IPv6Network` classes |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1352 | returns the name of the reverse DNS PTR record:: |
| 1353 | |
| 1354 | >>> import ipaddress |
| 1355 | >>> addr = ipaddress.IPv4Address('127.0.0.1') |
| 1356 | >>> addr.reverse_pointer |
| 1357 | '1.0.0.127.in-addr.arpa' |
| 1358 | >>> addr6 = ipaddress.IPv6Address('::1') |
| 1359 | >>> addr6.reverse_pointer |
| 1360 | '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa' |
| 1361 | |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 1362 | (Contributed by Leon Weber in :issue:`20480`.) |
| 1363 | |
Antoine Pitrou | 0dfce56 | 2014-05-15 22:55:40 +0200 | [diff] [blame] | 1364 | |
Berker Peksag | 39e4c4d | 2014-11-10 09:56:54 +0200 | [diff] [blame] | 1365 | json |
| 1366 | ---- |
| 1367 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1368 | The :mod:`json.tool` command line interface now preserves the order of keys in |
| 1369 | JSON objects passed in input. The new ``--sort-keys`` option can be used |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1370 | to sort the keys alphabetically. (Contributed by Berker Peksag |
| 1371 | in :issue:`21650`.) |
Berker Peksag | 39e4c4d | 2014-11-10 09:56:54 +0200 | [diff] [blame] | 1372 | |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 1373 | JSON decoder now raises :exc:`~json.JSONDecodeError` instead of |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1374 | :exc:`ValueError` to provide better context information about the error. |
| 1375 | (Contributed by Serhiy Storchaka in :issue:`19361`.) |
| 1376 | |
| 1377 | |
| 1378 | linecache |
| 1379 | --------- |
| 1380 | |
| 1381 | A new :func:`~linecache.lazycache` function can be used to capture information |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1382 | about a non-file-based module to permit getting its lines later via |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1383 | :func:`~linecache.getline`. This avoids doing I/O until a line is actually |
| 1384 | needed, without having to carry the module globals around indefinitely. |
| 1385 | (Contributed by Robert Collins in :issue:`17911`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1386 | |
Serhiy Storchaka | 47efb4a | 2015-01-26 13:16:30 +0200 | [diff] [blame] | 1387 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1388 | locale |
| 1389 | ------ |
| 1390 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1391 | A new :func:`~locale.delocalize` function can be used to convert a string into |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1392 | a normalized number string, taking the ``LC_NUMERIC`` settings into account:: |
| 1393 | |
| 1394 | >>> import locale |
| 1395 | >>> locale.setlocale(locale.LC_NUMERIC, 'de_DE.UTF-8') |
| 1396 | 'de_DE.UTF-8' |
| 1397 | >>> locale.delocalize('1.234,56') |
| 1398 | '1234.56' |
| 1399 | >>> locale.setlocale(locale.LC_NUMERIC, 'en_US.UTF-8') |
| 1400 | 'en_US.UTF-8' |
| 1401 | >>> locale.delocalize('1,234.56') |
| 1402 | '1234.56' |
| 1403 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1404 | (Contributed by Cédric Krier in :issue:`13918`.) |
| 1405 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1406 | |
| 1407 | logging |
| 1408 | ------- |
| 1409 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1410 | All logging methods (:class:`~logging.Logger` :meth:`~logging.Logger.log`, |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1411 | :meth:`~logging.Logger.exception`, :meth:`~logging.Logger.critical`, |
| 1412 | :meth:`~logging.Logger.debug`, etc.), now accept exception instances |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 1413 | as an *exc_info* argument, in addition to boolean values and exception |
Yury Selivanov | 6d9dd75 | 2015-09-13 01:10:19 -0400 | [diff] [blame] | 1414 | tuples:: |
| 1415 | |
| 1416 | >>> import logging |
| 1417 | >>> try: |
| 1418 | ... 1/0 |
| 1419 | ... except ZeroDivisionError as ex: |
| 1420 | ... logging.error('exception', exc_info=ex) |
| 1421 | ERROR:root:exception |
| 1422 | |
| 1423 | (Contributed by Yury Selivanov in :issue:`20537`.) |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1424 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1425 | The :class:`handlers.HTTPHandler <logging.handlers.HTTPHandler>` class now |
| 1426 | accepts an optional :class:`ssl.SSLContext` instance to configure SSL |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1427 | settings used in an HTTP connection. |
| 1428 | (Contributed by Alex Gaynor in :issue:`22788`.) |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1429 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1430 | The :class:`handlers.QueueListener <logging.handlers.QueueListener>` class now |
| 1431 | takes a *respect_handler_level* keyword argument which, if set to ``True``, |
| 1432 | will pass messages to handlers taking handler levels into account. |
| 1433 | (Contributed by Vinay Sajip.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1434 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1435 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1436 | lzma |
| 1437 | ---- |
| 1438 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1439 | The :meth:`LZMADecompressor.decompress() <lzma.LZMADecompressor.decompress>` |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1440 | method now accepts an optional *max_length* argument to limit the maximum |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1441 | size of decompressed data. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1442 | (Contributed by Martin Panter in :issue:`15955`.) |
| 1443 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1444 | |
Tal Einat | f67b0a3 | 2015-05-31 22:18:31 +0300 | [diff] [blame] | 1445 | math |
| 1446 | ---- |
| 1447 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1448 | Two new constants have been added to the :mod:`math` module: :data:`~math.inf` |
| 1449 | and :data:`~math.nan`. (Contributed by Mark Dickinson in :issue:`23185`.) |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1450 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1451 | A new function :func:`~math.isclose` provides a way to test for approximate |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1452 | equality. (Contributed by Chris Barker and Tal Einat in :issue:`24270`.) |
Tal Einat | f67b0a3 | 2015-05-31 22:18:31 +0300 | [diff] [blame] | 1453 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1454 | A new :func:`~math.gcd` function has been added. The :func:`fractions.gcd` |
| 1455 | function is now deprecated. (Contributed by Mark Dickinson and Serhiy |
| 1456 | Storchaka in :issue:`22486`.) |
| 1457 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1458 | |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1459 | multiprocessing |
| 1460 | --------------- |
| 1461 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1462 | :func:`sharedctypes.synchronized() <multiprocessing.sharedctypes.synchronized>` |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1463 | objects now support the :term:`context manager` protocol. |
| 1464 | (Contributed by Charles-François Natali in :issue:`21565`.) |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1465 | |
| 1466 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1467 | operator |
| 1468 | -------- |
| 1469 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1470 | :func:`~operator.attrgetter`, :func:`~operator.itemgetter`, |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1471 | and :func:`~operator.methodcaller` objects now support pickling. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1472 | (Contributed by Josh Rosenberg and Serhiy Storchaka in :issue:`22955`.) |
| 1473 | |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 1474 | New :func:`~operator.matmul` and :func:`~operator.imatmul` functions |
| 1475 | to perform matrix multiplication. |
| 1476 | (Contributed by Benjamin Peterson in :issue:`21176`.) |
| 1477 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1478 | |
Zachary Ware | 63f277b | 2014-06-19 09:46:37 -0500 | [diff] [blame] | 1479 | os |
| 1480 | -- |
| 1481 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1482 | The new :func:`~os.scandir` function returning an iterator of |
| 1483 | :class:`~os.DirEntry` objects has been added. If possible, :func:`~os.scandir` |
| 1484 | extracts file attributes while scanning a directory, removing the need to |
| 1485 | perform subsequent system calls to determine file type or attributes, which may |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1486 | significantly improve performance. (Contributed by Ben Hoyt with the help |
| 1487 | of Victor Stinner in :issue:`22524`.) |
Victor Stinner | 6036e44 | 2015-03-08 01:58:04 +0100 | [diff] [blame] | 1488 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1489 | On Windows, a new |
| 1490 | :attr:`stat_result.st_file_attributes <os.stat_result.st_file_attributes>` |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1491 | attribute is now available. It corresponds to the ``dwFileAttributes`` member |
| 1492 | of the ``BY_HANDLE_FILE_INFORMATION`` structure returned by |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1493 | ``GetFileInformationByHandle()``. (Contributed by Ben Hoyt in :issue:`21719`.) |
Zachary Ware | 63f277b | 2014-06-19 09:46:37 -0500 | [diff] [blame] | 1494 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1495 | The :func:`~os.urandom` function now uses the ``getrandom()`` syscall on Linux 3.17 |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1496 | or newer, and ``getentropy()`` on OpenBSD 5.6 and newer, removing the need to |
| 1497 | use ``/dev/urandom`` and avoiding failures due to potential file descriptor |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1498 | exhaustion. (Contributed by Victor Stinner in :issue:`22181`.) |
Victor Stinner | ace8848 | 2015-07-29 02:28:32 +0200 | [diff] [blame] | 1499 | |
Martin Panter | c04fb56 | 2016-02-10 05:44:01 +0000 | [diff] [blame] | 1500 | New :func:`~os.get_blocking` and :func:`~os.set_blocking` functions allow |
| 1501 | getting and setting a file descriptor's blocking mode (:data:`~os.O_NONBLOCK`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1502 | (Contributed by Victor Stinner in :issue:`22054`.) |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1503 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1504 | The :func:`~os.truncate` and :func:`~os.ftruncate` functions are now supported |
| 1505 | on Windows. (Contributed by Steve Dower in :issue:`23668`.) |
Serhiy Storchaka | 3822093 | 2015-03-31 15:31:53 +0300 | [diff] [blame] | 1506 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1507 | There is a new :func:`os.path.commonpath` function returning the longest |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1508 | common sub-path of each passed pathname. Unlike the |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1509 | :func:`os.path.commonprefix` function, it always returns a valid |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1510 | path:: |
| 1511 | |
| 1512 | >>> os.path.commonprefix(['/usr/lib', '/usr/local/lib']) |
| 1513 | '/usr/l' |
| 1514 | |
| 1515 | >>> os.path.commonpath(['/usr/lib', '/usr/local/lib']) |
| 1516 | '/usr' |
| 1517 | |
| 1518 | (Contributed by Rafik Draoui and Serhiy Storchaka in :issue:`10395`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1519 | |
Serhiy Storchaka | 3822093 | 2015-03-31 15:31:53 +0300 | [diff] [blame] | 1520 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1521 | pathlib |
| 1522 | ------- |
| 1523 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1524 | The new :meth:`Path.samefile() <pathlib.Path.samefile>` method can be used |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1525 | to check whether the path points to the same file as another path, which can |
| 1526 | be either another :class:`~pathlib.Path` object, or a string:: |
Yury Selivanov | 6d9dd75 | 2015-09-13 01:10:19 -0400 | [diff] [blame] | 1527 | |
| 1528 | >>> import pathlib |
| 1529 | >>> p1 = pathlib.Path('/etc/hosts') |
| 1530 | >>> p2 = pathlib.Path('/etc/../etc/hosts') |
| 1531 | >>> p1.samefile(p2) |
| 1532 | True |
| 1533 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1534 | (Contributed by Vajrasky Kok and Antoine Pitrou in :issue:`19775`.) |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1535 | |
Berker Peksag | ad56c92 | 2015-10-19 00:56:39 +0300 | [diff] [blame] | 1536 | The :meth:`Path.mkdir() <pathlib.Path.mkdir>` method now accepts a new optional |
Berker Peksag | 5783ee1 | 2015-10-18 20:22:15 +0300 | [diff] [blame] | 1537 | *exist_ok* argument to match ``mkdir -p`` and :func:`os.makedirs` |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1538 | functionality. (Contributed by Berker Peksag in :issue:`21539`.) |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1539 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1540 | There is a new :meth:`Path.expanduser() <pathlib.Path.expanduser>` method to |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1541 | expand ``~`` and ``~user`` prefixes. (Contributed by Serhiy Storchaka and |
| 1542 | Claudiu Popa in :issue:`19776`.) |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1543 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1544 | A new :meth:`Path.home() <pathlib.Path.home>` class method can be used to get |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1545 | a :class:`~pathlib.Path` instance representing the user’s home |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1546 | directory. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1547 | (Contributed by Victor Salgado and Mayank Tripathi in :issue:`19777`.) |
| 1548 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1549 | New :meth:`Path.write_text() <pathlib.Path.write_text>`, |
| 1550 | :meth:`Path.read_text() <pathlib.Path.read_text>`, |
| 1551 | :meth:`Path.write_bytes() <pathlib.Path.write_bytes>`, |
| 1552 | :meth:`Path.read_bytes() <pathlib.Path.read_bytes>` methods to simplify |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 1553 | read/write operations on files. |
Yury Selivanov | 6d9dd75 | 2015-09-13 01:10:19 -0400 | [diff] [blame] | 1554 | |
| 1555 | The following code snippet will create or rewrite existing file |
| 1556 | ``~/spam42``:: |
| 1557 | |
| 1558 | >>> import pathlib |
| 1559 | >>> p = pathlib.Path('~/spam42') |
| 1560 | >>> p.expanduser().write_text('ham') |
| 1561 | 3 |
| 1562 | |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 1563 | (Contributed by Christopher Welborn in :issue:`20218`.) |
| 1564 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1565 | |
Serhiy Storchaka | 58e4134 | 2015-03-31 14:07:24 +0300 | [diff] [blame] | 1566 | pickle |
| 1567 | ------ |
| 1568 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1569 | Nested objects, such as unbound methods or nested classes, can now be pickled |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1570 | using :ref:`pickle protocols <pickle-protocols>` older than protocol version 4. |
| 1571 | Protocol version 4 already supports these cases. (Contributed by Serhiy |
| 1572 | Storchaka in :issue:`23611`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1573 | |
Serhiy Storchaka | 58e4134 | 2015-03-31 14:07:24 +0300 | [diff] [blame] | 1574 | |
R David Murray | b8cd3e4 | 2015-05-16 15:05:53 -0400 | [diff] [blame] | 1575 | poplib |
| 1576 | ------ |
| 1577 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1578 | A new :meth:`POP3.utf8() <poplib.POP3.utf8>` command enables :rfc:`6856` |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1579 | (Internationalized Email) support, if a POP server supports it. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1580 | (Contributed by Milan OberKirch in :issue:`21804`.) |
| 1581 | |
R David Murray | b8cd3e4 | 2015-05-16 15:05:53 -0400 | [diff] [blame] | 1582 | |
Serhiy Storchaka | 9baa5b2 | 2014-09-29 22:49:23 +0300 | [diff] [blame] | 1583 | re |
| 1584 | -- |
| 1585 | |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1586 | References and conditional references to groups with fixed length are now |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1587 | allowed in lookbehind assertions:: |
| 1588 | |
| 1589 | >>> import re |
| 1590 | >>> pat = re.compile(r'(a|b).(?<=\1)c') |
| 1591 | >>> pat.match('aac') |
| 1592 | <_sre.SRE_Match object; span=(0, 3), match='aac'> |
| 1593 | >>> pat.match('bbc') |
| 1594 | <_sre.SRE_Match object; span=(0, 3), match='bbc'> |
| 1595 | |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1596 | (Contributed by Serhiy Storchaka in :issue:`9179`.) |
| 1597 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1598 | The number of capturing groups in regular expressions is no longer limited to |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1599 | 100. (Contributed by Serhiy Storchaka in :issue:`22437`.) |
Serhiy Storchaka | 9baa5b2 | 2014-09-29 22:49:23 +0300 | [diff] [blame] | 1600 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1601 | The :func:`~re.sub` and :func:`~re.subn` functions now replace unmatched |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1602 | groups with empty strings instead of raising an exception. |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1603 | (Contributed by Serhiy Storchaka in :issue:`1519638`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1604 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1605 | The :class:`re.error` exceptions have new attributes, |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 1606 | :attr:`~re.error.msg`, :attr:`~re.error.pattern`, |
| 1607 | :attr:`~re.error.pos`, :attr:`~re.error.lineno`, |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1608 | and :attr:`~re.error.colno`, that provide better context |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1609 | information about the error:: |
| 1610 | |
| 1611 | >>> re.compile(""" |
| 1612 | ... (?x) |
| 1613 | ... .++ |
| 1614 | ... """) |
| 1615 | Traceback (most recent call last): |
| 1616 | ... |
| 1617 | sre_constants.error: multiple repeat at position 16 (line 3, column 7) |
| 1618 | |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 1619 | (Contributed by Serhiy Storchaka in :issue:`22578`.) |
| 1620 | |
Serhiy Storchaka | 7438e4b | 2014-10-10 11:06:31 +0300 | [diff] [blame] | 1621 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1622 | readline |
| 1623 | -------- |
| 1624 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1625 | A new :func:`~readline.append_history_file` function can be used to append |
| 1626 | the specified number of trailing elements in history to the given file. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1627 | (Contributed by Bruno Cauet in :issue:`22940`.) |
| 1628 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1629 | |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 1630 | selectors |
| 1631 | --------- |
| 1632 | |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 1633 | The new :class:`~selectors.DevpollSelector` supports efficient |
| 1634 | ``/dev/poll`` polling on Solaris. |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 1635 | (Contributed by Giampaolo Rodola' in :issue:`18931`.) |
| 1636 | |
| 1637 | |
R David Murray | 6ffface | 2014-06-11 14:40:13 -0400 | [diff] [blame] | 1638 | shutil |
| 1639 | ------ |
| 1640 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1641 | The :func:`~shutil.move` function now accepts a *copy_function* argument, |
| 1642 | allowing, for example, the :func:`~shutil.copy` function to be used instead of |
| 1643 | the default :func:`~shutil.copy2` if there is a need to ignore file metadata |
| 1644 | when moving. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1645 | (Contributed by Claudiu Popa in :issue:`19840`.) |
R David Murray | 6ffface | 2014-06-11 14:40:13 -0400 | [diff] [blame] | 1646 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1647 | The :func:`~shutil.make_archive` function now supports the *xztar* format. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1648 | (Contributed by Serhiy Storchaka in :issue:`5411`.) |
| 1649 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1650 | |
Antoine Pitrou | b9d9ce7 | 2014-05-15 22:47:33 +0200 | [diff] [blame] | 1651 | signal |
| 1652 | ------ |
Brett Cannon | a04dbe4 | 2014-04-04 13:53:38 -0400 | [diff] [blame] | 1653 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1654 | On Windows, the :func:`~signal.set_wakeup_fd` function now also supports |
| 1655 | socket handles. (Contributed by Victor Stinner in :issue:`22018`.) |
Victor Stinner | bbe3803 | 2015-04-01 16:32:32 +0200 | [diff] [blame] | 1656 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1657 | Various ``SIG*`` constants in the :mod:`signal` module have been converted into |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1658 | :mod:`Enums <enum>`. This allows meaningful names to be printed |
| 1659 | during debugging, instead of integer "magic numbers". |
| 1660 | (Contributed by Giampaolo Rodola' in :issue:`21076`.) |
| 1661 | |
R David Murray | 1976d9b | 2014-04-14 20:28:36 -0400 | [diff] [blame] | 1662 | |
R David Murray | 554bcbf | 2014-06-11 11:18:08 -0400 | [diff] [blame] | 1663 | smtpd |
| 1664 | ----- |
| 1665 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1666 | Both the :class:`~smtpd.SMTPServer` and :class:`~smtpd.SMTPChannel` classes now |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1667 | accept a *decode_data* keyword argument to determine if the ``DATA`` portion of |
| 1668 | the SMTP transaction is decoded using the ``"utf-8"`` codec or is instead |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1669 | provided to the |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1670 | :meth:`SMTPServer.process_message() <smtpd.SMTPServer.process_message>` |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1671 | method as a byte string. The default is ``True`` for backward compatibility |
| 1672 | reasons, but will change to ``False`` in Python 3.6. If *decode_data* is set |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1673 | to ``False``, the ``process_message`` method must be prepared to accept keyword |
| 1674 | arguments. |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1675 | (Contributed by Maciej Szulik in :issue:`19662`.) |
R David Murray | a33df31 | 2015-05-11 12:11:40 -0400 | [diff] [blame] | 1676 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1677 | The :class:`~smtpd.SMTPServer` class now advertises the ``8BITMIME`` extension |
| 1678 | (:rfc:`6152`) if *decode_data* has been set ``True``. If the client |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1679 | specifies ``BODY=8BITMIME`` on the ``MAIL`` command, it is passed to |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1680 | :meth:`SMTPServer.process_message() <smtpd.SMTPServer.process_message>` |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 1681 | via the *mail_options* keyword. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1682 | (Contributed by Milan Oberkirch and R. David Murray in :issue:`21795`.) |
R David Murray | a33df31 | 2015-05-11 12:11:40 -0400 | [diff] [blame] | 1683 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1684 | The :class:`~smtpd.SMTPServer` class now also supports the ``SMTPUTF8`` |
| 1685 | extension (:rfc:`6531`: Internationalized Email). If the client specified |
| 1686 | ``SMTPUTF8 BODY=8BITMIME`` on the ``MAIL`` command, they are passed to |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1687 | :meth:`SMTPServer.process_message() <smtpd.SMTPServer.process_message>` |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 1688 | via the *mail_options* keyword. It is the responsibility of the |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1689 | ``process_message`` method to correctly handle the ``SMTPUTF8`` data. |
| 1690 | (Contributed by Milan Oberkirch in :issue:`21725`.) |
R David Murray | 554bcbf | 2014-06-11 11:18:08 -0400 | [diff] [blame] | 1691 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1692 | It is now possible to provide, directly or via name resolution, IPv6 |
| 1693 | addresses in the :class:`~smtpd.SMTPServer` constructor, and have it |
| 1694 | successfully connect. (Contributed by Milan Oberkirch in :issue:`14758`.) |
| 1695 | |
R David Murray | 6fe56a3 | 2014-06-11 13:48:58 -0400 | [diff] [blame] | 1696 | |
R David Murray | 76e13c1 | 2014-07-03 14:47:46 -0400 | [diff] [blame] | 1697 | smtplib |
| 1698 | ------- |
| 1699 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1700 | A new :meth:`SMTP.auth() <smtplib.SMTP.auth>` method provides a convenient way to |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1701 | implement custom authentication mechanisms. (Contributed by Milan |
| 1702 | Oberkirch in :issue:`15014`.) |
R David Murray | 76e13c1 | 2014-07-03 14:47:46 -0400 | [diff] [blame] | 1703 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1704 | The :meth:`SMTP.set_debuglevel() <smtplib.SMTP.set_debuglevel>` method now |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1705 | accepts an additional debuglevel (2), which enables timestamps in debug |
| 1706 | messages. (Contributed by Gavin Chappell and Maciej Szulik in :issue:`16914`.) |
R David Murray | 0c49b89 | 2015-04-16 17:14:42 -0400 | [diff] [blame] | 1707 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1708 | Both the :meth:`SMTP.sendmail() <smtplib.SMTP.sendmail>` and |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1709 | :meth:`SMTP.send_message() <smtplib.SMTP.send_message>` methods now |
Martin Panter | a90a4a9 | 2016-05-30 04:04:50 +0000 | [diff] [blame] | 1710 | support :rfc:`6531` (SMTPUTF8). |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1711 | (Contributed by Milan Oberkirch and R. David Murray in :issue:`22027`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1712 | |
R David Murray | cee7cf6 | 2015-05-16 13:58:14 -0400 | [diff] [blame] | 1713 | |
R David Murray | 4487dd0 | 2014-10-09 16:59:30 -0400 | [diff] [blame] | 1714 | sndhdr |
| 1715 | ------ |
| 1716 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1717 | The :func:`~sndhdr.what` and :func:`~sndhdr.whathdr` functions now return |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1718 | a :func:`~collections.namedtuple`. (Contributed by Claudiu Popa in |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1719 | :issue:`18615`.) |
| 1720 | |
R David Murray | 4487dd0 | 2014-10-09 16:59:30 -0400 | [diff] [blame] | 1721 | |
Yury Selivanov | fe369a6 | 2015-09-13 08:29:19 -0400 | [diff] [blame] | 1722 | socket |
| 1723 | ------ |
| 1724 | |
| 1725 | Functions with timeouts now use a monotonic clock, instead of a system clock. |
| 1726 | (Contributed by Victor Stinner in :issue:`22043`.) |
| 1727 | |
Martin Panter | c04fb56 | 2016-02-10 05:44:01 +0000 | [diff] [blame] | 1728 | A new :meth:`socket.sendfile() <socket.socket.sendfile>` method allows |
| 1729 | sending a file over a socket by using the high-performance :func:`os.sendfile` |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1730 | function on UNIX, resulting in uploads being from 2 to 3 times faster than when |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1731 | using plain :meth:`socket.send() <socket.socket.send>`. |
Yury Selivanov | fe369a6 | 2015-09-13 08:29:19 -0400 | [diff] [blame] | 1732 | (Contributed by Giampaolo Rodola' in :issue:`17552`.) |
| 1733 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1734 | The :meth:`socket.sendall() <socket.socket.sendall>` method no longer resets the |
Yury Selivanov | fe369a6 | 2015-09-13 08:29:19 -0400 | [diff] [blame] | 1735 | socket timeout every time bytes are received or sent. The socket timeout is |
| 1736 | now the maximum total duration to send all data. |
| 1737 | (Contributed by Victor Stinner in :issue:`23853`.) |
| 1738 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1739 | The *backlog* argument of the :meth:`socket.listen() <socket.socket.listen>` |
Yury Selivanov | fe369a6 | 2015-09-13 08:29:19 -0400 | [diff] [blame] | 1740 | method is now optional. By default it is set to |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1741 | :data:`SOMAXCONN <socket.SOMAXCONN>` or to ``128``, whichever is less. |
Yury Selivanov | fe369a6 | 2015-09-13 08:29:19 -0400 | [diff] [blame] | 1742 | (Contributed by Charles-François Natali in :issue:`21455`.) |
| 1743 | |
| 1744 | |
Victor Stinner | 287452e | 2015-07-29 01:39:13 +0200 | [diff] [blame] | 1745 | ssl |
| 1746 | --- |
| 1747 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 1748 | .. _whatsnew-sslmemorybio: |
| 1749 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1750 | Memory BIO Support |
| 1751 | ~~~~~~~~~~~~~~~~~~ |
Yury Selivanov | 7d6adab | 2015-08-05 19:01:51 -0400 | [diff] [blame] | 1752 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1753 | (Contributed by Geert Jansen in :issue:`21965`.) |
Victor Stinner | 287452e | 2015-07-29 01:39:13 +0200 | [diff] [blame] | 1754 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1755 | The new :class:`~ssl.SSLObject` class has been added to provide SSL protocol |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1756 | support for cases when the network I/O capabilities of :class:`~ssl.SSLSocket` |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1757 | are not necessary or are suboptimal. ``SSLObject`` represents |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1758 | an SSL protocol instance, but does not implement any network I/O methods, and |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1759 | instead provides a memory buffer interface. The new :class:`~ssl.MemoryBIO` |
| 1760 | class can be used to pass data between Python and an SSL protocol instance. |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1761 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1762 | The memory BIO SSL support is primarily intended to be used in frameworks |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1763 | implementing asynchronous I/O for which :class:`~ssl.SSLSocket`'s readiness |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1764 | model ("select/poll") is inefficient. |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1765 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1766 | A new :meth:`SSLContext.wrap_bio() <ssl.SSLContext.wrap_bio>` method can be used |
| 1767 | to create a new ``SSLObject`` instance. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1768 | |
| 1769 | |
| 1770 | Application-Layer Protocol Negotiation Support |
| 1771 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1772 | |
| 1773 | (Contributed by Benjamin Peterson in :issue:`20188`.) |
| 1774 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1775 | Where OpenSSL support is present, the :mod:`ssl` module now implements |
| 1776 | the *Application-Layer Protocol Negotiation* TLS extension as described |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1777 | in :rfc:`7301`. |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1778 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1779 | The new :meth:`SSLContext.set_alpn_protocols() <ssl.SSLContext.set_alpn_protocols>` |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1780 | can be used to specify which protocols a socket should advertise during |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1781 | the TLS handshake. |
| 1782 | |
| 1783 | The new |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1784 | :meth:`SSLSocket.selected_alpn_protocol() <ssl.SSLSocket.selected_alpn_protocol>` |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1785 | returns the protocol that was selected during the TLS handshake. |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1786 | The :data:`~ssl.HAS_ALPN` flag indicates whether ALPN support is present. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1787 | |
| 1788 | |
| 1789 | Other Changes |
| 1790 | ~~~~~~~~~~~~~ |
| 1791 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1792 | There is a new :meth:`SSLSocket.version() <ssl.SSLSocket.version>` method to |
| 1793 | query the actual protocol version in use. |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1794 | (Contributed by Antoine Pitrou in :issue:`20421`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1795 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1796 | The :class:`~ssl.SSLSocket` class now implements |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1797 | a :meth:`SSLSocket.sendfile() <ssl.SSLSocket.sendfile>` method. |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 1798 | (Contributed by Giampaolo Rodola' in :issue:`17552`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1799 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1800 | The :meth:`SSLSocket.send() <ssl.SSLSocket.send>` method now raises either |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1801 | the :exc:`ssl.SSLWantReadError` or :exc:`ssl.SSLWantWriteError` exception on a |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1802 | non-blocking socket if the operation would block. Previously, it would return |
| 1803 | ``0``. (Contributed by Nikolaus Rath in :issue:`20951`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1804 | |
| 1805 | The :func:`~ssl.cert_time_to_seconds` function now interprets the input time |
| 1806 | as UTC and not as local time, per :rfc:`5280`. Additionally, the return |
| 1807 | value is always an :class:`int`. (Contributed by Akira Li in :issue:`19940`.) |
| 1808 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1809 | New :meth:`SSLObject.shared_ciphers() <ssl.SSLObject.shared_ciphers>` and |
| 1810 | :meth:`SSLSocket.shared_ciphers() <ssl.SSLSocket.shared_ciphers>` methods return |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1811 | the list of ciphers sent by the client during the handshake. |
| 1812 | (Contributed by Benjamin Peterson in :issue:`23186`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1813 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1814 | The :meth:`SSLSocket.do_handshake() <ssl.SSLSocket.do_handshake>`, |
| 1815 | :meth:`SSLSocket.read() <ssl.SSLSocket.read>`, |
| 1816 | :meth:`SSLSocket.shutdown() <ssl.SSLSocket.shutdown>`, and |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1817 | :meth:`SSLSocket.write() <ssl.SSLSocket.write>` methods of the :class:`~ssl.SSLSocket` |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1818 | class no longer reset the socket timeout every time bytes are received or sent. |
| 1819 | The socket timeout is now the maximum total duration of the method. |
| 1820 | (Contributed by Victor Stinner in :issue:`23853`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1821 | |
| 1822 | The :func:`~ssl.match_hostname` function now supports matching of IP addresses. |
| 1823 | (Contributed by Antoine Pitrou in :issue:`23239`.) |
| 1824 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1825 | |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 1826 | sqlite3 |
| 1827 | ------- |
| 1828 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1829 | The :class:`~sqlite3.Row` class now fully supports the sequence protocol, |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 1830 | in particular :func:`reversed` iteration and slice indexing. |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 1831 | (Contributed by Claudiu Popa in :issue:`10203`; by Lucas Sinclair, |
| 1832 | Jessica McKellar, and Serhiy Storchaka in :issue:`13583`.) |
| 1833 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1834 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 1835 | .. _whatsnew-subprocess: |
| 1836 | |
Gregory P. Smith | 6e73000 | 2015-04-14 16:14:25 -0700 | [diff] [blame] | 1837 | subprocess |
| 1838 | ---------- |
| 1839 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1840 | The new :func:`~subprocess.run` function has been added. |
Martin Panter | 0e5eba2 | 2015-10-31 12:18:10 +0000 | [diff] [blame] | 1841 | It runs the specified command and returns a |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1842 | :class:`~subprocess.CompletedProcess` object, which describes a finished |
| 1843 | process. The new API is more consistent and is the recommended approach |
| 1844 | to invoking subprocesses in Python code that does not need to maintain |
| 1845 | compatibility with earlier Python versions. |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1846 | (Contributed by Thomas Kluyver in :issue:`23342`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1847 | |
Yury Selivanov | 2395037 | 2015-09-12 23:46:39 -0400 | [diff] [blame] | 1848 | Examples:: |
| 1849 | |
| 1850 | >>> subprocess.run(["ls", "-l"]) # doesn't capture output |
| 1851 | CompletedProcess(args=['ls', '-l'], returncode=0) |
| 1852 | |
| 1853 | >>> subprocess.run("exit 1", shell=True, check=True) |
| 1854 | Traceback (most recent call last): |
| 1855 | ... |
| 1856 | subprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1 |
| 1857 | |
| 1858 | >>> subprocess.run(["ls", "-l", "/dev/null"], stdout=subprocess.PIPE) |
| 1859 | CompletedProcess(args=['ls', '-l', '/dev/null'], returncode=0, |
| 1860 | stdout=b'crw-rw-rw- 1 root root 1, 3 Jan 23 16:23 /dev/null\n') |
| 1861 | |
Gregory P. Smith | 6e73000 | 2015-04-14 16:14:25 -0700 | [diff] [blame] | 1862 | |
Yury Selivanov | 4640b30 | 2015-05-31 17:21:38 -0400 | [diff] [blame] | 1863 | sys |
| 1864 | --- |
| 1865 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1866 | A new :func:`~sys.set_coroutine_wrapper` function allows setting a global |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1867 | hook that will be called whenever a :term:`coroutine object <coroutine>` |
| 1868 | is created by an :keyword:`async def` function. A corresponding |
| 1869 | :func:`~sys.get_coroutine_wrapper` can be used to obtain a currently set |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 1870 | wrapper. Both functions are :term:`provisional <provisional api>`, |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1871 | and are intended for debugging purposes only. (Contributed by Yury Selivanov |
| 1872 | in :issue:`24017`.) |
Yury Selivanov | 4640b30 | 2015-05-31 17:21:38 -0400 | [diff] [blame] | 1873 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1874 | A new :func:`~sys.is_finalizing` function can be used to check if the Python |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1875 | interpreter is :term:`shutting down <interpreter shutdown>`. |
| 1876 | (Contributed by Antoine Pitrou in :issue:`22696`.) |
| 1877 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1878 | |
Eric V. Smith | 7a80389 | 2015-04-15 10:27:58 -0400 | [diff] [blame] | 1879 | sysconfig |
| 1880 | --------- |
| 1881 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1882 | The name of the user scripts directory on Windows now includes the first |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1883 | two components of the Python version. (Contributed by Paul Moore |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1884 | in :issue:`23437`.) |
| 1885 | |
Eric V. Smith | 7a80389 | 2015-04-15 10:27:58 -0400 | [diff] [blame] | 1886 | |
| 1887 | tarfile |
| 1888 | ------- |
| 1889 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1890 | The *mode* argument of the :func:`~tarfile.open` function now accepts ``"x"`` |
| 1891 | to request exclusive creation. (Contributed by Berker Peksag in :issue:`21717`.) |
Eric V. Smith | 7a80389 | 2015-04-15 10:27:58 -0400 | [diff] [blame] | 1892 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1893 | The :meth:`TarFile.extractall() <tarfile.TarFile.extractall>` and |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1894 | :meth:`TarFile.extract() <tarfile.TarFile.extract>` methods now take a keyword |
Martin Panter | efbf20f | 2016-11-13 23:25:06 +0000 | [diff] [blame] | 1895 | argument *numeric_owner*. If set to ``True``, the extracted files and |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1896 | directories will be owned by the numeric ``uid`` and ``gid`` from the tarfile. |
| 1897 | If set to ``False`` (the default, and the behavior in versions prior to 3.5), |
| 1898 | they will be owned by the named user and group in the tarfile. |
| 1899 | (Contributed by Michael Vogt and Eric Smith in :issue:`23193`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1900 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1901 | The :meth:`TarFile.list() <tarfile.TarFile.list>` now accepts an optional |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1902 | *members* keyword argument that can be set to a subset of the list returned |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1903 | by :meth:`TarFile.getmembers() <tarfile.TarFile.getmembers>`. |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1904 | (Contributed by Serhiy Storchaka in :issue:`21549`.) |
| 1905 | |
Eric V. Smith | 7a80389 | 2015-04-15 10:27:58 -0400 | [diff] [blame] | 1906 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1907 | threading |
| 1908 | --------- |
| 1909 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1910 | Both the :meth:`Lock.acquire() <threading.Lock.acquire>` and |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1911 | :meth:`RLock.acquire() <threading.RLock.acquire>` methods |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1912 | now use a monotonic clock for timeout management. |
| 1913 | (Contributed by Victor Stinner in :issue:`22043`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1914 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1915 | |
Victor Stinner | ae58649 | 2014-09-02 23:18:25 +0200 | [diff] [blame] | 1916 | time |
| 1917 | ---- |
| 1918 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1919 | The :func:`~time.monotonic` function is now always available. |
| 1920 | (Contributed by Victor Stinner in :issue:`22043`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1921 | |
Victor Stinner | ae58649 | 2014-09-02 23:18:25 +0200 | [diff] [blame] | 1922 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1923 | timeit |
| 1924 | ------ |
| 1925 | |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 1926 | A new command line option ``-u`` or :samp:`--unit={U}` can be used to specify the time |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 1927 | unit for the timer output. Supported options are ``usec``, ``msec``, |
| 1928 | or ``sec``. (Contributed by Julian Gindi in :issue:`18983`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1929 | |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 1930 | The :func:`~timeit.timeit` function has a new *globals* parameter for |
| 1931 | specifying the namespace in which the code will be running. |
| 1932 | (Contributed by Ben Roberts in :issue:`2527`.) |
| 1933 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1934 | |
Zachary Ware | 7dc9dea | 2015-05-22 11:36:53 -0500 | [diff] [blame] | 1935 | tkinter |
| 1936 | ------- |
| 1937 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1938 | The :mod:`tkinter._fix` module used for setting up the Tcl/Tk environment |
| 1939 | on Windows has been replaced by a private function in the :mod:`_tkinter` |
| 1940 | module which makes no permanent changes to environment variables. |
| 1941 | (Contributed by Zachary Ware in :issue:`20035`.) |
| 1942 | |
Zachary Ware | 7dc9dea | 2015-05-22 11:36:53 -0500 | [diff] [blame] | 1943 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 1944 | .. _whatsnew-traceback: |
| 1945 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1946 | traceback |
| 1947 | --------- |
| 1948 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1949 | New :func:`~traceback.walk_stack` and :func:`~traceback.walk_tb` |
| 1950 | functions to conveniently traverse frame and traceback objects. |
| 1951 | (Contributed by Robert Collins in :issue:`17911`.) |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1952 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1953 | New lightweight classes: :class:`~traceback.TracebackException`, |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 1954 | :class:`~traceback.StackSummary`, and :class:`~traceback.FrameSummary`. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1955 | (Contributed by Robert Collins in :issue:`17911`.) |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 1956 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1957 | Both the :func:`~traceback.print_tb` and :func:`~traceback.print_stack` functions |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 1958 | now support negative values for the *limit* argument. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1959 | (Contributed by Dmitry Kazakov in :issue:`22619`.) |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1960 | |
| 1961 | |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 1962 | types |
| 1963 | ----- |
| 1964 | |
Yury Selivanov | 1c73e69 | 2015-09-10 18:59:42 -0400 | [diff] [blame] | 1965 | A new :func:`~types.coroutine` function to transform |
| 1966 | :term:`generator <generator iterator>` and |
| 1967 | :class:`generator-like <collections.abc.Generator>` objects into |
| 1968 | :term:`awaitables <awaitable>`. |
| 1969 | (Contributed by Yury Selivanov in :issue:`24017`.) |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 1970 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1971 | A new type called :class:`~types.CoroutineType`, which is used for |
| 1972 | :term:`coroutine` objects created by :keyword:`async def` functions. |
Yury Selivanov | 1c73e69 | 2015-09-10 18:59:42 -0400 | [diff] [blame] | 1973 | (Contributed by Yury Selivanov in :issue:`24400`.) |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1974 | |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 1975 | |
Benjamin Peterson | 4801383 | 2015-06-27 15:45:56 -0500 | [diff] [blame] | 1976 | unicodedata |
| 1977 | ----------- |
| 1978 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1979 | The :mod:`unicodedata` module now uses data from `Unicode 8.0.0 |
| 1980 | <http://unicode.org/versions/Unicode8.0.0/>`_. |
| 1981 | |
Benjamin Peterson | 4801383 | 2015-06-27 15:45:56 -0500 | [diff] [blame] | 1982 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 1983 | unittest |
| 1984 | -------- |
| 1985 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 1986 | The :meth:`TestLoader.loadTestsFromModule() <unittest.TestLoader.loadTestsFromModule>` |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1987 | method now accepts a keyword-only argument *pattern* which is passed to |
| 1988 | ``load_tests`` as the third argument. Found packages are now checked for |
| 1989 | ``load_tests`` regardless of whether their path matches *pattern*, because it |
| 1990 | is impossible for a package name to match the default pattern. |
| 1991 | (Contributed by Robert Collins and Barry A. Warsaw in :issue:`16662`.) |
| 1992 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 1993 | Unittest discovery errors now are exposed in the |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 1994 | :data:`TestLoader.errors <unittest.TestLoader.errors>` attribute of the |
| 1995 | :class:`~unittest.TestLoader` instance. |
| 1996 | (Contributed by Robert Collins in :issue:`19746`.) |
| 1997 | |
Yury Selivanov | dddfffe | 2015-09-11 01:23:10 -0400 | [diff] [blame] | 1998 | A new command line option ``--locals`` to show local variables in |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 1999 | tracebacks. (Contributed by Robert Collins in :issue:`22936`.) |
| 2000 | |
Benjamin Peterson | 4801383 | 2015-06-27 15:45:56 -0500 | [diff] [blame] | 2001 | |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 2002 | unittest.mock |
| 2003 | ------------- |
| 2004 | |
Berker Peksag | 878bc87 | 2015-09-15 20:06:28 +0300 | [diff] [blame] | 2005 | The :class:`~unittest.mock.Mock` class has the following improvements: |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 2006 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2007 | * The class constructor has a new *unsafe* parameter, which causes mock |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 2008 | objects to raise :exc:`AttributeError` on attribute names starting |
| 2009 | with ``"assert"``. |
| 2010 | (Contributed by Kushal Das in :issue:`21238`.) |
| 2011 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 2012 | * A new :meth:`Mock.assert_not_called() <unittest.mock.Mock.assert_not_called>` |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 2013 | method to check if the mock object was called. |
| 2014 | (Contributed by Kushal Das in :issue:`21262`.) |
| 2015 | |
| 2016 | The :class:`~unittest.mock.MagicMock` class now supports :meth:`__truediv__`, |
| 2017 | :meth:`__divmod__` and :meth:`__matmul__` operators. |
| 2018 | (Contributed by Johannes Baiter in :issue:`20968`, and Håkan Lövdahl |
| 2019 | in :issue:`23581` and :issue:`23568`.) |
| 2020 | |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 2021 | It is no longer necessary to explicitly pass ``create=True`` to the |
| 2022 | :func:`~unittest.mock.patch` function when patching builtin names. |
| 2023 | (Contributed by Kushal Das in :issue:`17660`.) |
| 2024 | |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 2025 | |
Yury Selivanov | fe369a6 | 2015-09-13 08:29:19 -0400 | [diff] [blame] | 2026 | urllib |
| 2027 | ------ |
| 2028 | |
| 2029 | A new |
| 2030 | :class:`request.HTTPPasswordMgrWithPriorAuth <urllib.request.HTTPPasswordMgrWithPriorAuth>` |
| 2031 | class allows HTTP Basic Authentication credentials to be managed so as to |
| 2032 | eliminate unnecessary ``401`` response handling, or to unconditionally send |
| 2033 | credentials on the first request in order to communicate with servers that |
| 2034 | return a ``404`` response instead of a ``401`` if the ``Authorization`` header |
| 2035 | is not sent. (Contributed by Matej Cepl in :issue:`19494` and Akshit Khurana in |
| 2036 | :issue:`7159`.) |
| 2037 | |
| 2038 | A new *quote_via* argument for the |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 2039 | :func:`parse.urlencode() <urllib.parse.urlencode>` |
Yury Selivanov | fe369a6 | 2015-09-13 08:29:19 -0400 | [diff] [blame] | 2040 | function provides a way to control the encoding of query parts if needed. |
| 2041 | (Contributed by Samwyse and Arnon Yaari in :issue:`13866`.) |
| 2042 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 2043 | The :func:`request.urlopen() <urllib.request.urlopen>` function accepts an |
Yury Selivanov | fe369a6 | 2015-09-13 08:29:19 -0400 | [diff] [blame] | 2044 | :class:`ssl.SSLContext` object as a *context* argument, which will be used for |
| 2045 | the HTTPS connection. (Contributed by Alex Gaynor in :issue:`22366`.) |
| 2046 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 2047 | The :func:`parse.urljoin() <urllib.parse.urljoin>` was updated to use the |
Yury Selivanov | fe369a6 | 2015-09-13 08:29:19 -0400 | [diff] [blame] | 2048 | :rfc:`3986` semantics for the resolution of relative URLs, rather than |
| 2049 | :rfc:`1808` and :rfc:`2396`. |
| 2050 | (Contributed by Demian Brecht and Senthil Kumaran in :issue:`22118`.) |
| 2051 | |
| 2052 | |
Berker Peksag | 3e88722 | 2014-07-02 08:37:22 +0300 | [diff] [blame] | 2053 | wsgiref |
| 2054 | ------- |
| 2055 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2056 | The *headers* argument of the :class:`headers.Headers <wsgiref.headers.Headers>` |
| 2057 | class constructor is now optional. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 2058 | (Contributed by Pablo Torres Navarrete and SilentGhost in :issue:`5800`.) |
| 2059 | |
Berker Peksag | 3e88722 | 2014-07-02 08:37:22 +0300 | [diff] [blame] | 2060 | |
Antoine Pitrou | b9d9ce7 | 2014-05-15 22:47:33 +0200 | [diff] [blame] | 2061 | xmlrpc |
| 2062 | ------ |
| 2063 | |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 2064 | The :class:`client.ServerProxy <xmlrpc.client.ServerProxy>` class now supports |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2065 | the :term:`context manager` protocol. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 2066 | (Contributed by Claudiu Popa in :issue:`20627`.) |
Brett Cannon | 6eaac13 | 2014-05-09 12:28:22 -0400 | [diff] [blame] | 2067 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2068 | The :class:`client.ServerProxy <xmlrpc.client.ServerProxy>` constructor now accepts |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2069 | an optional :class:`ssl.SSLContext` instance. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 2070 | (Contributed by Alex Gaynor in :issue:`22960`.) |
| 2071 | |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 2072 | |
Serhiy Storchaka | 61de087 | 2015-04-02 21:00:13 +0300 | [diff] [blame] | 2073 | xml.sax |
| 2074 | ------- |
| 2075 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2076 | SAX parsers now support a character stream of the |
| 2077 | :class:`xmlreader.InputSource <xml.sax.xmlreader.InputSource>` object. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 2078 | (Contributed by Serhiy Storchaka in :issue:`2175`.) |
| 2079 | |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 2080 | :func:`~xml.sax.parseString` now accepts a :class:`str` instance. |
| 2081 | (Contributed by Serhiy Storchaka in :issue:`10590`.) |
| 2082 | |
Serhiy Storchaka | 61de087 | 2015-04-02 21:00:13 +0300 | [diff] [blame] | 2083 | |
Serhiy Storchaka | 77d8997 | 2015-03-23 01:09:35 +0200 | [diff] [blame] | 2084 | zipfile |
| 2085 | ------- |
| 2086 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 2087 | ZIP output can now be written to unseekable streams. |
| 2088 | (Contributed by Serhiy Storchaka in :issue:`23252`.) |
Serhiy Storchaka | 77d8997 | 2015-03-23 01:09:35 +0200 | [diff] [blame] | 2089 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 2090 | The *mode* argument of :meth:`ZipFile.open() <zipfile.ZipFile.open>` method now |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2091 | accepts ``"x"`` to request exclusive creation. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 2092 | (Contributed by Serhiy Storchaka in :issue:`21717`.) |
Serhiy Storchaka | 764fc9b | 2015-03-25 10:09:41 +0200 | [diff] [blame] | 2093 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2094 | |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 2095 | Other module-level changes |
| 2096 | ========================== |
| 2097 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2098 | Many functions in the :mod:`mmap`, :mod:`ossaudiodev`, :mod:`socket`, |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 2099 | :mod:`ssl`, and :mod:`codecs` modules now accept writable |
| 2100 | :term:`bytes-like objects <bytes-like object>`. |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 2101 | (Contributed by Serhiy Storchaka in :issue:`23001`.) |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 2102 | |
| 2103 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2104 | Optimizations |
| 2105 | ============= |
| 2106 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 2107 | The :func:`os.walk` function has been sped up by 3 to 5 times on POSIX systems, |
| 2108 | and by 7 to 20 times on Windows. This was done using the new :func:`os.scandir` |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2109 | function, which exposes file information from the underlying ``readdir`` or |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 2110 | ``FindFirstFile``/``FindNextFile`` system calls. (Contributed by |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2111 | Ben Hoyt with help from Victor Stinner in :issue:`23605`.) |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2112 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2113 | Construction of ``bytes(int)`` (filled by zero bytes) is faster and uses less |
| 2114 | memory for large objects. ``calloc()`` is used instead of ``malloc()`` to |
| 2115 | allocate memory for these objects. |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 2116 | (Contributed by Victor Stinner in :issue:`21233`.) |
Victor Stinner | 37f2034 | 2015-03-10 13:29:41 +0100 | [diff] [blame] | 2117 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2118 | Some operations on :mod:`ipaddress` :class:`~ipaddress.IPv4Network` and |
| 2119 | :class:`~ipaddress.IPv6Network` have been massively sped up, such as |
| 2120 | :meth:`~ipaddress.IPv4Network.subnets`, :meth:`~ipaddress.IPv4Network.supernet`, |
| 2121 | :func:`~ipaddress.summarize_address_range`, :func:`~ipaddress.collapse_addresses`. |
| 2122 | The speed up can range from 3 to 15 times. |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 2123 | (Contributed by Antoine Pitrou, Michel Albert, and Markus in |
| 2124 | :issue:`21486`, :issue:`21487`, :issue:`20826`, :issue:`23266`.) |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2125 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2126 | Pickling of :mod:`ipaddress` objects was optimized to produce significantly |
| 2127 | smaller output. (Contributed by Serhiy Storchaka in :issue:`23133`.) |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 2128 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2129 | Many operations on :class:`io.BytesIO` are now 50% to 100% faster. |
| 2130 | (Contributed by Serhiy Storchaka in :issue:`15381` and David Wilson in |
| 2131 | :issue:`22003`.) |
Antoine Pitrou | 0dfce56 | 2014-05-15 22:55:40 +0200 | [diff] [blame] | 2132 | |
Serhiy Storchaka | c7b1a0b | 2016-11-26 13:43:28 +0200 | [diff] [blame] | 2133 | The :func:`marshal.dumps` function is now faster: 65--85% with versions 3 |
| 2134 | and 4, 20--25% with versions 0 to 2 on typical data, and up to 5 times in |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2135 | best cases. |
| 2136 | (Contributed by Serhiy Storchaka in :issue:`20416` and :issue:`23344`.) |
Serhiy Storchaka | 87d0b45 | 2015-02-03 11:30:10 +0200 | [diff] [blame] | 2137 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2138 | The UTF-32 encoder is now 3 to 7 times faster. |
| 2139 | (Contributed by Serhiy Storchaka in :issue:`15027`.) |
Serhiy Storchaka | ce921c62 | 2015-02-11 15:53:31 +0200 | [diff] [blame] | 2140 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2141 | Regular expressions are now parsed up to 10% faster. |
| 2142 | (Contributed by Serhiy Storchaka in :issue:`19380`.) |
Serhiy Storchaka | 0d4df75 | 2015-05-12 23:12:45 +0300 | [diff] [blame] | 2143 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2144 | The :func:`json.dumps` function was optimized to run with |
| 2145 | ``ensure_ascii=False`` as fast as with ``ensure_ascii=True``. |
| 2146 | (Contributed by Naoki Inada in :issue:`23206`.) |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 2147 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2148 | The :c:func:`PyObject_IsInstance` and :c:func:`PyObject_IsSubclass` |
| 2149 | functions have been sped up in the common case that the second argument |
| 2150 | has :class:`type` as its metaclass. |
| 2151 | (Contributed Georg Brandl by in :issue:`22540`.) |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 2152 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2153 | Method caching was slightly improved, yielding up to 5% performance |
| 2154 | improvement in some benchmarks. |
| 2155 | (Contributed by Antoine Pitrou in :issue:`22847`.) |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 2156 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2157 | Objects from the :mod:`random` module now use 50% less memory on 64-bit |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2158 | builds. (Contributed by Serhiy Storchaka in :issue:`23488`.) |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 2159 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2160 | The :func:`property` getter calls are up to 25% faster. |
| 2161 | (Contributed by Joe Jevnik in :issue:`23910`.) |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 2162 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2163 | Instantiation of :class:`fractions.Fraction` is now up to 30% faster. |
| 2164 | (Contributed by Stefan Behnel in :issue:`22464`.) |
Yury Selivanov | 88d073d | 2015-09-09 22:46:40 -0400 | [diff] [blame] | 2165 | |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 2166 | String methods :meth:`~str.find`, :meth:`~str.rfind`, :meth:`~str.split`, |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2167 | :meth:`~str.partition` and the :keyword:`in` string operator are now significantly |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 2168 | faster for searching 1-character substrings. |
| 2169 | (Contributed by Serhiy Storchaka in :issue:`23573`.) |
| 2170 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2171 | |
| 2172 | Build and C API Changes |
| 2173 | ======================= |
| 2174 | |
Yury Selivanov | c973990 | 2015-09-10 18:26:44 -0400 | [diff] [blame] | 2175 | New ``calloc`` functions were added: |
Victor Stinner | db067af | 2014-05-02 22:31:14 +0200 | [diff] [blame] | 2176 | |
Yury Selivanov | a7672ba | 2015-09-13 01:40:36 -0400 | [diff] [blame] | 2177 | * :c:func:`PyMem_RawCalloc`, |
| 2178 | * :c:func:`PyMem_Calloc`, |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 2179 | * :c:func:`PyObject_Calloc`. |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 2180 | |
| 2181 | (Contributed by Victor Stinner in :issue:`21233`.) |
| 2182 | |
| 2183 | New encoding/decoding helper functions: |
| 2184 | |
Yury Selivanov | a7672ba | 2015-09-13 01:40:36 -0400 | [diff] [blame] | 2185 | * :c:func:`Py_DecodeLocale` (replaced ``_Py_char2wchar()``), |
| 2186 | * :c:func:`Py_EncodeLocale` (replaced ``_Py_wchar2char()``). |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 2187 | |
| 2188 | (Contributed by Victor Stinner in :issue:`18395`.) |
| 2189 | |
Yury Selivanov | dddfffe | 2015-09-11 01:23:10 -0400 | [diff] [blame] | 2190 | A new :c:func:`PyCodec_NameReplaceErrors` function to replace the unicode |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 2191 | encode error with ``\N{...}`` escapes. |
| 2192 | (Contributed by Serhiy Storchaka in :issue:`19676`.) |
| 2193 | |
Yury Selivanov | dddfffe | 2015-09-11 01:23:10 -0400 | [diff] [blame] | 2194 | A new :c:func:`PyErr_FormatV` function similar to :c:func:`PyErr_Format`, |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 2195 | but accepts a ``va_list`` argument. |
| 2196 | (Contributed by Antoine Pitrou in :issue:`18711`.) |
| 2197 | |
Yury Selivanov | dddfffe | 2015-09-11 01:23:10 -0400 | [diff] [blame] | 2198 | A new :c:data:`PyExc_RecursionError` exception. |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 2199 | (Contributed by Georg Brandl in :issue:`19235`.) |
| 2200 | |
| 2201 | New :c:func:`PyModule_FromDefAndSpec`, :c:func:`PyModule_FromDefAndSpec2`, |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 2202 | and :c:func:`PyModule_ExecDef` functions introduced by :pep:`489` -- |
| 2203 | multi-phase extension module initialization. |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 2204 | (Contributed by Petr Viktorin in :issue:`24268`.) |
| 2205 | |
| 2206 | New :c:func:`PyNumber_MatrixMultiply` and |
| 2207 | :c:func:`PyNumber_InPlaceMatrixMultiply` functions to perform matrix |
| 2208 | multiplication. |
| 2209 | (Contributed by Benjamin Peterson in :issue:`21176`. See also :pep:`465` |
| 2210 | for details.) |
| 2211 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2212 | The :c:member:`PyTypeObject.tp_finalize` slot is now part of the stable ABI. |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2213 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2214 | Windows builds now require Microsoft Visual C++ 14.0, which |
Georg Brandl | 5d94134 | 2016-02-26 19:37:12 +0100 | [diff] [blame] | 2215 | is available as part of `Visual Studio 2015 <https://www.visualstudio.com/>`_. |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2216 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2217 | Extension modules now include a platform information tag in their filename on |
Yury Selivanov | c973990 | 2015-09-10 18:26:44 -0400 | [diff] [blame] | 2218 | some platforms (the tag is optional, and CPython will import extensions without |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2219 | it, although if the tag is present and mismatched, the extension won't be |
Yury Selivanov | c973990 | 2015-09-10 18:26:44 -0400 | [diff] [blame] | 2220 | loaded): |
| 2221 | |
| 2222 | * On Linux, extension module filenames end with |
| 2223 | ``.cpython-<major><minor>m-<architecture>-<os>.pyd``: |
| 2224 | |
| 2225 | * ``<major>`` is the major number of the Python version; |
| 2226 | for Python 3.5 this is ``3``. |
| 2227 | |
| 2228 | * ``<minor>`` is the minor number of the Python version; |
| 2229 | for Python 3.5 this is ``5``. |
| 2230 | |
| 2231 | * ``<architecture>`` is the hardware architecture the extension module |
| 2232 | was built to run on. It's most commonly either ``i386`` for 32-bit Intel |
| 2233 | platforms or ``x86_64`` for 64-bit Intel (and AMD) platforms. |
| 2234 | |
| 2235 | * ``<os>`` is always ``linux-gnu``, except for extensions built to |
| 2236 | talk to the 32-bit ABI on 64-bit platforms, in which case it is |
| 2237 | ``linux-gnu32`` (and ``<architecture>`` will be ``x86_64``). |
| 2238 | |
| 2239 | * On Windows, extension module filenames end with |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 2240 | ``<debug>.cp<major><minor>-<platform>.pyd``: |
Yury Selivanov | c973990 | 2015-09-10 18:26:44 -0400 | [diff] [blame] | 2241 | |
| 2242 | * ``<major>`` is the major number of the Python version; |
| 2243 | for Python 3.5 this is ``3``. |
| 2244 | |
| 2245 | * ``<minor>`` is the minor number of the Python version; |
| 2246 | for Python 3.5 this is ``5``. |
| 2247 | |
| 2248 | * ``<platform>`` is the platform the extension module was built for, |
| 2249 | either ``win32`` for Win32, ``win_amd64`` for Win64, ``win_ia64`` for |
| 2250 | Windows Itanium 64, and ``win_arm`` for Windows on ARM. |
| 2251 | |
| 2252 | * If built in debug mode, ``<debug>`` will be ``_d``, |
| 2253 | otherwise it will be blank. |
| 2254 | |
| 2255 | * On OS X platforms, extension module filenames now end with ``-darwin.so``. |
| 2256 | |
| 2257 | * On all other platforms, extension module filenames are the same as they were |
| 2258 | with Python 3.4. |
| 2259 | |
Yury Selivanov | ce917c731 | 2015-09-10 17:35:38 -0400 | [diff] [blame] | 2260 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2261 | Deprecated |
| 2262 | ========== |
| 2263 | |
Yury Selivanov | 8fa6d4f | 2015-05-28 17:09:14 -0400 | [diff] [blame] | 2264 | New Keywords |
| 2265 | ------------ |
| 2266 | |
Yury Selivanov | 13b74ae | 2015-08-03 14:55:58 -0400 | [diff] [blame] | 2267 | ``async`` and ``await`` are not recommended to be used as variable, class, |
| 2268 | function or module names. Introduced by :pep:`492` in Python 3.5, they will |
| 2269 | become proper keywords in Python 3.7. |
Yury Selivanov | 8fa6d4f | 2015-05-28 17:09:14 -0400 | [diff] [blame] | 2270 | |
| 2271 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 2272 | Deprecated Python Behavior |
| 2273 | -------------------------- |
| 2274 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2275 | Raising the :exc:`StopIteration` exception inside a generator will now generate a silent |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 2276 | :exc:`PendingDeprecationWarning`, which will become a non-silent deprecation |
| 2277 | warning in Python 3.6 and will trigger a :exc:`RuntimeError` in Python 3.7. |
| 2278 | See :ref:`PEP 479: Change StopIteration handling inside generators <whatsnew-pep-479>` |
| 2279 | for details. |
| 2280 | |
| 2281 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2282 | Unsupported Operating Systems |
| 2283 | ----------------------------- |
| 2284 | |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 2285 | Windows XP is no longer supported by Microsoft, thus, per :PEP:`11`, CPython |
| 2286 | 3.5 is no longer officially supported on this OS. |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2287 | |
| 2288 | |
| 2289 | Deprecated Python modules, functions and methods |
| 2290 | ------------------------------------------------ |
| 2291 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2292 | The :mod:`formatter` module has now graduated to full deprecation and is still |
| 2293 | slated for removal in Python 3.6. |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2294 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2295 | The :func:`asyncio.async` function is deprecated in favor of |
| 2296 | :func:`~asyncio.ensure_future`. |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 2297 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2298 | The :mod:`smtpd` module has in the past always decoded the DATA portion of |
| 2299 | email messages using the ``utf-8`` codec. This can now be controlled by the |
| 2300 | new *decode_data* keyword to :class:`~smtpd.SMTPServer`. The default value is |
| 2301 | ``True``, but this default is deprecated. Specify the *decode_data* keyword |
| 2302 | with an appropriate value to avoid the deprecation warning. |
R David Murray | 554bcbf | 2014-06-11 11:18:08 -0400 | [diff] [blame] | 2303 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2304 | Directly assigning values to the :attr:`~http.cookies.Morsel.key`, |
| 2305 | :attr:`~http.cookies.Morsel.value` and |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 2306 | :attr:`~http.cookies.Morsel.coded_value` of :class:`http.cookies.Morsel` |
| 2307 | objects is deprecated. Use the :meth:`~http.cookies.Morsel.set` method |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2308 | instead. In addition, the undocumented *LegalChars* parameter of |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 2309 | :meth:`~http.cookies.Morsel.set` is deprecated, and is now ignored. |
Serhiy Storchaka | 9c1a9b2 | 2015-03-18 10:59:57 +0200 | [diff] [blame] | 2310 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2311 | Passing a format string as keyword argument *format_string* to the |
| 2312 | :meth:`~string.Formatter.format` method of the :class:`string.Formatter` |
| 2313 | class has been deprecated. |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 2314 | (Contributed by Serhiy Storchaka in :issue:`23671`.) |
Serhiy Storchaka | b876df4 | 2015-03-24 22:30:46 +0200 | [diff] [blame] | 2315 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2316 | The :func:`platform.dist` and :func:`platform.linux_distribution` functions |
Berker Peksag | 8d8221f | 2016-04-24 03:32:24 +0300 | [diff] [blame] | 2317 | are now deprecated. Linux distributions use too many different ways of |
| 2318 | describing themselves, so the functionality is left to a package. |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2319 | (Contributed by Vajrasky Kok and Berker Peksag in :issue:`1322`.) |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2320 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2321 | The previously undocumented ``from_function`` and ``from_builtin`` methods of |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 2322 | :class:`inspect.Signature` are deprecated. Use the new |
| 2323 | :meth:`Signature.from_callable() <inspect.Signature.from_callable>` |
| 2324 | method instead. (Contributed by Yury Selivanov in :issue:`24248`.) |
Yury Selivanov | 57c74fc | 2015-05-20 23:07:02 -0400 | [diff] [blame] | 2325 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2326 | The :func:`inspect.getargspec` function is deprecated and scheduled to be |
| 2327 | removed in Python 3.6. (See :issue:`20438` for details.) |
Yury Selivanov | 945fff4 | 2015-05-22 16:28:05 -0400 | [diff] [blame] | 2328 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2329 | The :mod:`inspect` :func:`~inspect.getfullargspec`, |
Matthias Bussonnier | 0899b98 | 2017-02-21 21:45:51 -0800 | [diff] [blame] | 2330 | :func:`~inspect.getcallargs`, and :func:`~inspect.formatargspec` functions are |
| 2331 | deprecated in favor of the :func:`inspect.signature` API. (Contributed by Yury |
| 2332 | Selivanov in :issue:`20438`.) |
| 2333 | |
| 2334 | :func:`~inspect.getargvalues` and :func:`~inspect.formatargvalues` functions |
| 2335 | were inadvertently marked as deprecated with the release of Python 3.5.0. |
Yury Selivanov | 945fff4 | 2015-05-22 16:28:05 -0400 | [diff] [blame] | 2336 | |
Serhiy Storchaka | 35a361f | 2015-09-13 12:07:54 +0300 | [diff] [blame] | 2337 | Use of :const:`re.LOCALE` flag with str patterns or :const:`re.ASCII` is now |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2338 | deprecated. (Contributed by Serhiy Storchaka in :issue:`22407`.) |
Yury Selivanov | 100fc3f | 2015-09-08 22:40:30 -0400 | [diff] [blame] | 2339 | |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 2340 | Use of unrecognized special sequences consisting of ``'\'`` and an ASCII letter |
| 2341 | in regular expression patterns and replacement patterns now raises a |
| 2342 | deprecation warning and will be forbidden in Python 3.6. |
| 2343 | (Contributed by Serhiy Storchaka in :issue:`23622`.) |
| 2344 | |
| 2345 | The undocumented and unofficial *use_load_tests* default argument of the |
| 2346 | :meth:`unittest.TestLoader.loadTestsFromModule` method now is |
| 2347 | deprecated and ignored. |
| 2348 | (Contributed by Robert Collins and Barry A. Warsaw in :issue:`16662`.) |
| 2349 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2350 | |
R David Murray | df75fee | 2014-10-03 13:02:47 -0400 | [diff] [blame] | 2351 | Removed |
| 2352 | ======= |
| 2353 | |
Berker Peksag | 8f791d3 | 2014-11-01 10:45:57 +0200 | [diff] [blame] | 2354 | API and Feature Removals |
| 2355 | ------------------------ |
| 2356 | |
| 2357 | The following obsolete and previously deprecated APIs and features have been |
| 2358 | removed: |
| 2359 | |
R David Murray | df75fee | 2014-10-03 13:02:47 -0400 | [diff] [blame] | 2360 | * The ``__version__`` attribute has been dropped from the email package. The |
| 2361 | email code hasn't been shipped separately from the stdlib for a long time, |
| 2362 | and the ``__version__`` string was not updated in the last few releases. |
| 2363 | |
Berker Peksag | 8f791d3 | 2014-11-01 10:45:57 +0200 | [diff] [blame] | 2364 | * The internal ``Netrc`` class in the :mod:`ftplib` module was deprecated in |
Serhiy Storchaka | c1ded29 | 2014-11-02 19:22:02 +0200 | [diff] [blame] | 2365 | 3.4, and has now been removed. |
| 2366 | (Contributed by Matt Chaput in :issue:`6623`.) |
R David Murray | df75fee | 2014-10-03 13:02:47 -0400 | [diff] [blame] | 2367 | |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 2368 | * The concept of ``.pyo`` files has been removed. |
| 2369 | |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 2370 | * The JoinableQueue class in the provisional :mod:`asyncio` module was |
| 2371 | deprecated in 3.4.4 and is now removed. |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 2372 | (Contributed by A. Jesse Jiryu Davis in :issue:`23464`.) |
R David Murray | e81a773 | 2015-04-12 18:47:56 -0400 | [diff] [blame] | 2373 | |
| 2374 | |
Victor Stinner | 01adf06 | 2014-03-18 00:53:32 +0100 | [diff] [blame] | 2375 | Porting to Python 3.5 |
| 2376 | ===================== |
| 2377 | |
| 2378 | This section lists previously described changes and other bugfixes |
| 2379 | that may require changes to your code. |
| 2380 | |
Yury Selivanov | 95fd26b | 2015-09-12 17:50:58 -0400 | [diff] [blame] | 2381 | |
| 2382 | Changes in Python behavior |
| 2383 | -------------------------- |
| 2384 | |
| 2385 | * Due to an oversight, earlier Python versions erroneously accepted the |
| 2386 | following syntax:: |
| 2387 | |
| 2388 | f(1 for x in [1], *args) |
| 2389 | f(1 for x in [1], **kwargs) |
| 2390 | |
| 2391 | Python 3.5 now correctly raises a :exc:`SyntaxError`, as generator |
| 2392 | expressions must be put in parentheses if not a sole argument to a function. |
| 2393 | |
| 2394 | |
Victor Stinner | db067af | 2014-05-02 22:31:14 +0200 | [diff] [blame] | 2395 | Changes in the Python API |
| 2396 | ------------------------- |
| 2397 | |
Victor Stinner | 6752d65 | 2015-07-29 01:11:10 +0200 | [diff] [blame] | 2398 | * :pep:`475`: System calls are now retried when interrupted by a signal instead |
| 2399 | of raising :exc:`InterruptedError` if the Python signal handler does not |
| 2400 | raise an exception. |
Victor Stinner | a766ddf | 2015-03-26 23:50:57 +0100 | [diff] [blame] | 2401 | |
Benjamin Peterson | ee6bdc0 | 2014-03-20 18:00:35 -0500 | [diff] [blame] | 2402 | * Before Python 3.5, a :class:`datetime.time` object was considered to be false |
| 2403 | if it represented midnight in UTC. This behavior was considered obscure and |
| 2404 | error-prone and has been removed in Python 3.5. See :issue:`13936` for full |
| 2405 | details. |
Antoine Pitrou | 92c4d45 | 2014-04-29 10:05:59 +0200 | [diff] [blame] | 2406 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2407 | * The :meth:`ssl.SSLSocket.send()` method now raises either |
| 2408 | :exc:`ssl.SSLWantReadError` or :exc:`ssl.SSLWantWriteError` |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 2409 | on a non-blocking socket if the operation would block. Previously, |
| 2410 | it would return ``0``. (Contributed by Nikolaus Rath in :issue:`20951`.) |
Victor Stinner | db067af | 2014-05-02 22:31:14 +0200 | [diff] [blame] | 2411 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2412 | * The ``__name__`` attribute of generators is now set from the function name, |
Victor Stinner | 40ee301 | 2014-06-16 15:59:28 +0200 | [diff] [blame] | 2413 | instead of being set from the code name. Use ``gen.gi_code.co_name`` to |
| 2414 | retrieve the code name. Generators also have a new ``__qualname__`` |
| 2415 | attribute, the qualified name, which is now used for the representation |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 2416 | of a generator (``repr(gen)``). |
| 2417 | (Contributed by Victor Stinner in :issue:`21205`.) |
Victor Stinner | 40ee301 | 2014-06-16 15:59:28 +0200 | [diff] [blame] | 2418 | |
Ezio Melotti | 045160b | 2014-08-02 18:54:30 +0300 | [diff] [blame] | 2419 | * The deprecated "strict" mode and argument of :class:`~html.parser.HTMLParser`, |
| 2420 | :meth:`HTMLParser.error`, and the :exc:`HTMLParserError` exception have been |
Serhiy Storchaka | c1ded29 | 2014-11-02 19:22:02 +0200 | [diff] [blame] | 2421 | removed. (Contributed by Ezio Melotti in :issue:`15114`.) |
Ezio Melotti | 045160b | 2014-08-02 18:54:30 +0300 | [diff] [blame] | 2422 | The *convert_charrefs* argument of :class:`~html.parser.HTMLParser` is |
Serhiy Storchaka | c1ded29 | 2014-11-02 19:22:02 +0200 | [diff] [blame] | 2423 | now ``True`` by default. (Contributed by Berker Peksag in :issue:`21047`.) |
Ezio Melotti | 045160b | 2014-08-02 18:54:30 +0300 | [diff] [blame] | 2424 | |
R David Murray | 861470c | 2014-10-05 11:47:01 -0400 | [diff] [blame] | 2425 | * Although it is not formally part of the API, it is worth noting for porting |
| 2426 | purposes (ie: fixing tests) that error messages that were previously of the |
| 2427 | form "'sometype' does not support the buffer protocol" are now of the form "a |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 2428 | :term:`bytes-like object` is required, not 'sometype'". |
| 2429 | (Contributed by Ezio Melotti in :issue:`16518`.) |
R David Murray | 861470c | 2014-10-05 11:47:01 -0400 | [diff] [blame] | 2430 | |
Brett Cannon | b6e2556 | 2014-11-21 12:19:28 -0500 | [diff] [blame] | 2431 | * If the current directory is set to a directory that no longer exists then |
| 2432 | :exc:`FileNotFoundError` will no longer be raised and instead |
| 2433 | :meth:`~importlib.machinery.FileFinder.find_spec` will return ``None`` |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2434 | **without** caching ``None`` in :data:`sys.path_importer_cache`, which is |
Brett Cannon | b6e2556 | 2014-11-21 12:19:28 -0500 | [diff] [blame] | 2435 | different than the typical case (:issue:`22834`). |
| 2436 | |
Berker Peksag | 088ca8b | 2015-02-06 10:17:49 +0200 | [diff] [blame] | 2437 | * HTTP status code and messages from :mod:`http.client` and :mod:`http.server` |
| 2438 | were refactored into a common :class:`~http.HTTPStatus` enum. The values in |
| 2439 | :mod:`http.client` and :mod:`http.server` remain available for backwards |
| 2440 | compatibility. (Contributed by Demian Brecht in :issue:`21793`.) |
Serhiy Storchaka | e4db769 | 2014-12-23 16:28:28 +0200 | [diff] [blame] | 2441 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 2442 | * When an import loader defines :meth:`importlib.machinery.Loader.exec_module` |
Brett Cannon | 02d8454 | 2015-01-09 11:39:21 -0500 | [diff] [blame] | 2443 | it is now expected to also define |
| 2444 | :meth:`~importlib.machinery.Loader.create_module` (raises a |
| 2445 | :exc:`DeprecationWarning` now, will be an error in Python 3.6). If the loader |
| 2446 | inherits from :class:`importlib.abc.Loader` then there is nothing to do, else |
| 2447 | simply define :meth:`~importlib.machinery.Loader.create_module` to return |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 2448 | ``None``. (Contributed by Brett Cannon in :issue:`23014`.) |
Brett Cannon | 02d8454 | 2015-01-09 11:39:21 -0500 | [diff] [blame] | 2449 | |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2450 | * The :func:`re.split` function always ignored empty pattern matches, so the |
| 2451 | ``"x*"`` pattern worked the same as ``"x+"``, and the ``"\b"`` pattern never |
| 2452 | worked. Now :func:`re.split` raises a warning if the pattern could match |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2453 | an empty string. For compatibility, use patterns that never match an empty |
Yury Selivanov | 5c3111e | 2015-09-10 18:04:35 -0400 | [diff] [blame] | 2454 | string (e.g. ``"x+"`` instead of ``"x*"``). Patterns that could only match |
| 2455 | an empty string (such as ``"\b"``) now raise an error. |
Yury Selivanov | 46a8b40 | 2015-09-12 15:52:04 -0400 | [diff] [blame] | 2456 | (Contributed by Serhiy Storchaka in :issue:`22818`.) |
Serhiy Storchaka | 83e8027 | 2015-02-03 11:04:19 +0200 | [diff] [blame] | 2457 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 2458 | * The :class:`http.cookies.Morsel` dict-like interface has been made self |
R David Murray | 1813c17 | 2015-03-29 17:09:21 -0400 | [diff] [blame] | 2459 | consistent: morsel comparison now takes the :attr:`~http.cookies.Morsel.key` |
| 2460 | and :attr:`~http.cookies.Morsel.value` into account, |
| 2461 | :meth:`~http.cookies.Morsel.copy` now results in a |
R David Murray | ba6ea9b | 2015-03-30 11:48:50 -0400 | [diff] [blame] | 2462 | :class:`~http.cookies.Morsel` instance rather than a :class:`dict`, and |
| 2463 | :meth:`~http.cookies.Morsel.update` will now raise an exception if any of the |
R David Murray | 1813c17 | 2015-03-29 17:09:21 -0400 | [diff] [blame] | 2464 | keys in the update dictionary are invalid. In addition, the undocumented |
| 2465 | *LegalChars* parameter of :func:`~http.cookies.Morsel.set` is deprecated and |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 2466 | is now ignored. (Contributed by Demian Brecht in :issue:`2211`.) |
R David Murray | 1813c17 | 2015-03-29 17:09:21 -0400 | [diff] [blame] | 2467 | |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 2468 | * :pep:`488` has removed ``.pyo`` files from Python and introduced the optional |
| 2469 | ``opt-`` tag in ``.pyc`` file names. The |
| 2470 | :func:`importlib.util.cache_from_source` has gained an *optimization* |
| 2471 | parameter to help control the ``opt-`` tag. Because of this, the |
| 2472 | *debug_override* parameter of the function is now deprecated. `.pyo` files |
| 2473 | are also no longer supported as a file argument to the Python interpreter and |
| 2474 | thus serve no purpose when distributed on their own (i.e. sourcless code |
| 2475 | distribution). Due to the fact that the magic number for bytecode has changed |
| 2476 | in Python 3.5, all old `.pyo` files from previous versions of Python are |
| 2477 | invalid regardless of this PEP. |
| 2478 | |
Yury Selivanov | 4dde587 | 2015-09-11 00:48:21 -0400 | [diff] [blame] | 2479 | * The :mod:`socket` module now exports the :data:`~socket.CAN_RAW_FD_FRAMES` |
| 2480 | constant on linux 3.6 and greater. |
Larry Hastings | a6cc551 | 2015-04-13 17:48:40 -0400 | [diff] [blame] | 2481 | |
Yury Selivanov | a33cb35 | 2015-09-13 11:21:25 -0400 | [diff] [blame] | 2482 | * The :func:`ssl.cert_time_to_seconds` function now interprets the input time |
Yury Selivanov | a88cd64 | 2015-09-10 21:26:54 -0400 | [diff] [blame] | 2483 | as UTC and not as local time, per :rfc:`5280`. Additionally, the return |
| 2484 | value is always an :class:`int`. (Contributed by Akira Li in :issue:`19940`.) |
| 2485 | |
Zachary Ware | 3d3aedc | 2015-07-07 00:07:25 -0500 | [diff] [blame] | 2486 | * The ``pygettext.py`` Tool now uses the standard +NNNN format for timezones in |
R David Murray | 2b78129 | 2015-04-16 12:15:09 -0400 | [diff] [blame] | 2487 | the POT-Creation-Date header. |
| 2488 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2489 | * The :mod:`smtplib` module now uses :data:`sys.stderr` instead of the previous |
| 2490 | module-level :data:`stderr` variable for debug output. If your (test) |
| 2491 | program depends on patching the module-level variable to capture the debug |
R David Murray | 0c49b89 | 2015-04-16 17:14:42 -0400 | [diff] [blame] | 2492 | output, you will need to update it to capture sys.stderr instead. |
| 2493 | |
Serhiy Storchaka | d4ea03c | 2015-05-31 09:15:51 +0300 | [diff] [blame] | 2494 | * The :meth:`str.startswith` and :meth:`str.endswith` methods no longer return |
| 2495 | ``True`` when finding the empty string and the indexes are completely out of |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 2496 | range. (Contributed by Serhiy Storchaka in :issue:`24284`.) |
Serhiy Storchaka | d4ea03c | 2015-05-31 09:15:51 +0300 | [diff] [blame] | 2497 | |
Berker Peksag | 4333d8b | 2015-07-30 18:06:09 +0300 | [diff] [blame] | 2498 | * The :func:`inspect.getdoc` function now returns documentation strings |
| 2499 | inherited from base classes. Documentation strings no longer need to be |
| 2500 | duplicated if the inherited documentation is appropriate. To suppress an |
| 2501 | inherited string, an empty string must be specified (or the documentation |
| 2502 | may be filled in). This change affects the output of the :mod:`pydoc` |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 2503 | module and the :func:`help` function. |
| 2504 | (Contributed by Serhiy Storchaka in :issue:`15582`.) |
Berker Peksag | 4333d8b | 2015-07-30 18:06:09 +0300 | [diff] [blame] | 2505 | |
Berker Peksag | 9b93c6b | 2015-09-22 13:08:16 +0300 | [diff] [blame] | 2506 | * Nested :func:`functools.partial` calls are now flattened. If you were |
| 2507 | relying on the previous behavior, you can now either add an attribute to a |
| 2508 | :func:`functools.partial` object or you can create a subclass of |
| 2509 | :func:`functools.partial`. |
| 2510 | (Contributed by Alexander Belopolsky in :issue:`7830`.) |
| 2511 | |
Victor Stinner | db067af | 2014-05-02 22:31:14 +0200 | [diff] [blame] | 2512 | Changes in the C API |
| 2513 | -------------------- |
| 2514 | |
Stefan Krah | f5324d7 | 2015-01-29 14:29:51 +0100 | [diff] [blame] | 2515 | * The undocumented :c:member:`~PyMemoryViewObject.format` member of the |
| 2516 | (non-public) :c:type:`PyMemoryViewObject` structure has been removed. |
Stefan Krah | f5324d7 | 2015-01-29 14:29:51 +0100 | [diff] [blame] | 2517 | All extensions relying on the relevant parts in ``memoryobject.h`` |
| 2518 | must be rebuilt. |
| 2519 | |
Victor Stinner | d8f0d92 | 2014-06-02 21:57:10 +0200 | [diff] [blame] | 2520 | * The :c:type:`PyMemAllocator` structure was renamed to |
| 2521 | :c:type:`PyMemAllocatorEx` and a new ``calloc`` field was added. |
Serhiy Storchaka | df4518c | 2014-11-18 23:34:33 +0200 | [diff] [blame] | 2522 | |
| 2523 | * Removed non-documented macro :c:macro:`PyObject_REPR` which leaked references. |
| 2524 | Use format character ``%R`` in :c:func:`PyUnicode_FromFormat`-like functions |
| 2525 | to format the :func:`repr` of the object. |
Yury Selivanov | 508a81e | 2015-09-10 23:37:06 -0400 | [diff] [blame] | 2526 | (Contributed by Serhiy Storchaka in :issue:`22453`.) |
Serhiy Storchaka | 490055a | 2015-03-01 10:03:02 +0200 | [diff] [blame] | 2527 | |
| 2528 | * Because the lack of the :attr:`__module__` attribute breaks pickling and |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2529 | introspection, a deprecation warning is now raised for builtin types without |
| 2530 | the :attr:`__module__` attribute. This would be an AttributeError in |
| 2531 | the future. |
Serhiy Storchaka | 1c30e7e | 2015-09-11 20:55:28 +0300 | [diff] [blame] | 2532 | (Contributed by Serhiy Storchaka in :issue:`20204`.) |
Yury Selivanov | 5096088 | 2015-05-12 00:15:05 -0400 | [diff] [blame] | 2533 | |
Martin Panter | 97ce0fa | 2015-11-14 01:14:54 +0000 | [diff] [blame] | 2534 | * As part of the :pep:`492` implementation, the ``tp_reserved`` slot of |
Yury Selivanov | f3e40fa | 2015-05-21 11:50:30 -0400 | [diff] [blame] | 2535 | :c:type:`PyTypeObject` was replaced with a |
Yury Selivanov | 27947d5 | 2015-06-23 15:09:58 -0400 | [diff] [blame] | 2536 | :c:member:`tp_as_async` slot. Refer to :ref:`coro-objects` for |
Yury Selivanov | 5376ba9 | 2015-06-22 12:19:30 -0400 | [diff] [blame] | 2537 | new types, structures and functions. |
Yury Selivanov | 336b37b | 2015-09-09 12:23:01 -0400 | [diff] [blame] | 2538 | |
Ned Deily | 9d6171d | 2018-06-11 04:09:34 -0400 | [diff] [blame] | 2539 | |
| 2540 | Notable changes in Python 3.5.4 |
| 2541 | =============================== |
| 2542 | |
| 2543 | New ``make regen-all`` build target |
| 2544 | ----------------------------------- |
| 2545 | |
| 2546 | To simplify cross-compilation, and to ensure that CPython can reliably be |
| 2547 | compiled without requiring an existing version of Python to already be |
| 2548 | available, the autotools-based build system no longer attempts to implicitly |
| 2549 | recompile generated files based on file modification times. |
| 2550 | |
| 2551 | Instead, a new ``make regen-all`` command has been added to force regeneration |
| 2552 | of these files when desired (e.g. after an initial version of Python has |
| 2553 | already been built based on the pregenerated versions). |
| 2554 | |
| 2555 | More selective regeneration targets are also defined - see |
| 2556 | :source:`Makefile.pre.in` for details. |
| 2557 | |
| 2558 | (Contributed by Victor Stinner in :issue:`23404`.) |
| 2559 | |
| 2560 | .. versionadded:: 3.5.4 |
| 2561 | |
| 2562 | |
| 2563 | Removal of ``make touch`` build target |
| 2564 | -------------------------------------- |
| 2565 | |
| 2566 | The ``make touch`` build target previously used to request implicit regeneration |
| 2567 | of generated files by updating their modification times has been removed. |
| 2568 | |
| 2569 | It has been replaced by the new ``make regen-all`` target. |
| 2570 | |
| 2571 | (Contributed by Victor Stinner in :issue:`23404`.) |
| 2572 | |
| 2573 | .. versionchanged:: 3.5.4 |
| 2574 | |