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