Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 1 | **************************** |
| 2 | What's New In Python 3.6 |
| 3 | **************************** |
| 4 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 5 | :Editors: Elvis Pranskevichus <elvis@magic.io>, Yury Selivanov <yury@magic.io> |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 6 | |
| 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 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 47 | This article explains the new features in Python 3.6, compared to 3.5. |
Ned Deily | 5c4568a | 2016-12-22 18:38:47 -0500 | [diff] [blame] | 48 | Python 3.6 was released on December 23, 2016. See the |
| 49 | `changelog <https://docs.python.org/3.6/whatsnew/changelog.html>`_ for a full |
| 50 | list of changes. |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 51 | |
| 52 | .. seealso:: |
| 53 | |
| 54 | :pep:`494` - Python 3.6 Release Schedule |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 55 | |
| 56 | |
| 57 | Summary -- Release highlights |
| 58 | ============================= |
| 59 | |
Paul Moore | 835416c | 2016-05-22 12:28:41 +0100 | [diff] [blame] | 60 | New syntax features: |
| 61 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 62 | * :ref:`PEP 498 <whatsnew36-pep498>`, formatted string literals. |
Guido van Rossum | 52a7e37 | 2016-09-09 09:59:34 -0700 | [diff] [blame] | 63 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 64 | * :ref:`PEP 515 <whatsnew36-pep515>`, underscores in numeric literals. |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 65 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 66 | * :ref:`PEP 526 <whatsnew36-pep526>`, syntax for variable annotations. |
Guido van Rossum | 52a7e37 | 2016-09-09 09:59:34 -0700 | [diff] [blame] | 67 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 68 | * :ref:`PEP 525 <whatsnew36-pep525>`, asynchronous generators. |
Guido van Rossum | 52a7e37 | 2016-09-09 09:59:34 -0700 | [diff] [blame] | 69 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 70 | * :ref:`PEP 530 <whatsnew36-pep530>`: asynchronous comprehensions. |
Guido van Rossum | 52a7e37 | 2016-09-09 09:59:34 -0700 | [diff] [blame] | 71 | |
Guido van Rossum | 52a7e37 | 2016-09-09 09:59:34 -0700 | [diff] [blame] | 72 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 73 | New library modules: |
| 74 | |
| 75 | * :mod:`secrets`: :ref:`PEP 506 -- Adding A Secrets Module To The Standard Library <whatsnew36-pep506>`. |
| 76 | |
| 77 | |
| 78 | CPython implementation improvements: |
| 79 | |
| 80 | * The :ref:`dict <typesmapping>` type has been reimplemented to use |
Victor Stinner | 8320193 | 2016-12-15 16:20:53 +0100 | [diff] [blame] | 81 | a :ref:`more compact representation <whatsnew36-compactdict>` |
Raymond Hettinger | 51447db | 2016-12-29 23:49:20 -0700 | [diff] [blame] | 82 | based on `a proposal by Raymond Hettinger |
| 83 | <https://mail.python.org/pipermail/python-dev/2012-December/123028.html>`_ |
| 84 | and similar to the `PyPy dict implementation`_. This resulted in dictionaries |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 85 | using 20% to 25% less memory when compared to Python 3.5. |
| 86 | |
| 87 | * Customization of class creation has been simplified with the |
| 88 | :ref:`new protocol <whatsnew36-pep487>`. |
| 89 | |
Yury Selivanov | 249ba5d | 2016-11-10 15:39:27 -0500 | [diff] [blame] | 90 | * The class attribute definition order is |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 91 | :ref:`now preserved <whatsnew36-pep520>`. |
| 92 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 93 | * The order of elements in ``**kwargs`` now |
| 94 | :ref:`corresponds to the order <whatsnew36-pep468>` in which keyword |
| 95 | arguments were passed to the function. |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 96 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 97 | * DTrace and SystemTap :ref:`probing support <whatsnew36-tracing>` has |
| 98 | been added. |
| 99 | |
| 100 | * The new :ref:`PYTHONMALLOC <whatsnew36-pythonmalloc>` environment variable |
| 101 | can now be used to debug the interpreter memory allocation and access |
| 102 | errors. |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 103 | |
| 104 | |
| 105 | Significant improvements in the standard library: |
| 106 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 107 | * The :mod:`asyncio` module has received new features, significant |
| 108 | usability and performance improvements, and a fair amount of bug fixes. |
| 109 | Starting with Python 3.6 the ``asyncio`` module is no longer provisional |
| 110 | and its API is considered stable. |
| 111 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 112 | * A new :ref:`file system path protocol <whatsnew36-pep519>` has been |
| 113 | implemented to support :term:`path-like objects <path-like object>`. |
| 114 | All standard library functions operating on paths have been updated to |
| 115 | work with the new protocol. |
| 116 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 117 | * The :mod:`datetime` module has gained support for |
| 118 | :ref:`Local Time Disambiguation <whatsnew36-pep495>`. |
| 119 | |
| 120 | * The :mod:`typing` module received a number of |
Ned Deily | 67c1cb2 | 2017-01-20 10:13:23 -0500 | [diff] [blame] | 121 | :ref:`improvements <whatsnew36-typing>`. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 122 | |
| 123 | * The :mod:`tracemalloc` module has been significantly reworked |
Yury Selivanov | 249ba5d | 2016-11-10 15:39:27 -0500 | [diff] [blame] | 124 | and is now used to provide better output for :exc:`ResourceWarning` |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 125 | as well as provide better diagnostics for memory allocation errors. |
| 126 | See the :ref:`PYTHONMALLOC section <whatsnew36-pythonmalloc>` for more |
| 127 | information. |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 128 | |
Brett Cannon | 68ed978 | 2016-08-26 14:45:15 -0700 | [diff] [blame] | 129 | |
Victor Stinner | e66987e | 2016-09-06 16:33:52 -0700 | [diff] [blame] | 130 | Security improvements: |
| 131 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 132 | * The new :mod:`secrets` module has been added to simplify the generation of |
| 133 | cryptographically strong pseudo-random numbers suitable for |
| 134 | managing secrets such as account authentication, tokens, and similar. |
| 135 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 136 | * On Linux, :func:`os.urandom` now blocks until the system urandom entropy |
| 137 | pool is initialized to increase the security. See the :pep:`524` for the |
Victor Stinner | e66987e | 2016-09-06 16:33:52 -0700 | [diff] [blame] | 138 | rationale. |
| 139 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 140 | * The :mod:`hashlib` and :mod:`ssl` modules now support OpenSSL 1.1.0. |
Christian Heimes | c4d2e50 | 2016-09-12 01:14:35 +0200 | [diff] [blame] | 141 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 142 | * The default settings and feature set of the :mod:`ssl` module have been |
| 143 | improved. |
Christian Heimes | c4d2e50 | 2016-09-12 01:14:35 +0200 | [diff] [blame] | 144 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 145 | * The :mod:`hashlib` module received support for the BLAKE2, SHA-3 and SHAKE |
| 146 | hash algorithms and the :func:`~hashlib.scrypt` key derivation function. |
| 147 | |
Christian Heimes | c4d2e50 | 2016-09-12 01:14:35 +0200 | [diff] [blame] | 148 | |
Paul Moore | 835416c | 2016-05-22 12:28:41 +0100 | [diff] [blame] | 149 | Windows improvements: |
| 150 | |
Dmitry Shachnev | 495e567 | 2018-05-31 01:52:43 +0300 | [diff] [blame] | 151 | * :ref:`PEP 528 <whatsnew36-pep528>` and :ref:`PEP 529 <whatsnew36-pep529>`, |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 152 | Windows filesystem and console encoding changed to UTF-8. |
Steve Dower | 3929499 | 2016-08-30 21:22:36 -0700 | [diff] [blame] | 153 | |
Paul Moore | 835416c | 2016-05-22 12:28:41 +0100 | [diff] [blame] | 154 | * The ``py.exe`` launcher, when used interactively, no longer prefers |
| 155 | Python 2 over Python 3 when the user doesn't specify a version (via |
| 156 | command line arguments or a config file). Handling of shebang lines |
| 157 | remains unchanged - "python" refers to Python 2 in that case. |
| 158 | |
Steve Dower | 19ab0fd | 2016-09-06 20:40:11 -0700 | [diff] [blame] | 159 | * ``python.exe`` and ``pythonw.exe`` have been marked as long-path aware, |
Zachary Ware | 0425fc0 | 2016-11-28 00:19:07 -0600 | [diff] [blame] | 160 | which means that the 260 character path limit may no longer apply. |
Steve Dower | 19ab0fd | 2016-09-06 20:40:11 -0700 | [diff] [blame] | 161 | See :ref:`removing the MAX_PATH limitation <max-path>` for details. |
| 162 | |
Steve Dower | ed51b26 | 2016-09-17 12:54:06 -0700 | [diff] [blame] | 163 | * A ``._pth`` file can be added to force isolated mode and fully specify |
Steve Dower | 3cdd7f5 | 2016-09-09 15:22:13 -0700 | [diff] [blame] | 164 | all search paths to avoid registry and environment lookup. See |
| 165 | :ref:`the documentation <finding_modules>` for more information. |
Steve Dower | d8fdffe | 2016-09-09 15:09:30 -0700 | [diff] [blame] | 166 | |
Steve Dower | 3cdd7f5 | 2016-09-09 15:22:13 -0700 | [diff] [blame] | 167 | * A ``python36.zip`` file now works as a landmark to infer |
| 168 | :envvar:`PYTHONHOME`. See :ref:`the documentation <finding_modules>` for |
| 169 | more information. |
Steve Dower | d8fdffe | 2016-09-09 15:09:30 -0700 | [diff] [blame] | 170 | |
Eric Snow | 68f4dd8 | 2016-09-09 11:22:14 -0700 | [diff] [blame] | 171 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 172 | .. _PyPy dict implementation: https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html |
| 173 | |
| 174 | |
Victor Stinner | 34be807 | 2016-03-14 12:04:26 +0100 | [diff] [blame] | 175 | New Features |
| 176 | ============ |
| 177 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 178 | .. _whatsnew36-pep498: |
| 179 | |
| 180 | PEP 498: Formatted string literals |
| 181 | ---------------------------------- |
| 182 | |
| 183 | :pep:`498` introduces a new kind of string literals: *f-strings*, or |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 184 | :ref:`formatted string literals <f-strings>`. |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 185 | |
| 186 | Formatted string literals are prefixed with ``'f'`` and are similar to |
| 187 | the format strings accepted by :meth:`str.format`. They contain replacement |
| 188 | fields surrounded by curly braces. The replacement fields are expressions, |
| 189 | which are evaluated at run time, and then formatted using the |
| 190 | :func:`format` protocol:: |
| 191 | |
| 192 | >>> name = "Fred" |
| 193 | >>> f"He said his name is {name}." |
| 194 | 'He said his name is Fred.' |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 195 | >>> width = 10 |
| 196 | >>> precision = 4 |
| 197 | >>> value = decimal.Decimal("12.34567") |
| 198 | >>> f"result: {value:{width}.{precision}}" # nested fields |
| 199 | 'result: 12.35' |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 200 | |
| 201 | .. seealso:: |
| 202 | |
| 203 | :pep:`498` -- Literal String Interpolation. |
| 204 | PEP written and implemented by Eric V. Smith. |
| 205 | |
| 206 | :ref:`Feature documentation <f-strings>`. |
| 207 | |
| 208 | |
| 209 | .. _whatsnew36-pep526: |
| 210 | |
| 211 | PEP 526: Syntax for variable annotations |
| 212 | ---------------------------------------- |
| 213 | |
| 214 | :pep:`484` introduced the standard for type annotations of function |
| 215 | parameters, a.k.a. type hints. This PEP adds syntax to Python for annotating |
| 216 | the types of variables including class variables and instance variables:: |
| 217 | |
| 218 | primes: List[int] = [] |
| 219 | |
| 220 | captain: str # Note: no initial value! |
| 221 | |
| 222 | class Starship: |
| 223 | stats: Dict[str, int] = {} |
| 224 | |
| 225 | Just as for function annotations, the Python interpreter does not attach any |
| 226 | particular meaning to variable annotations and only stores them in the |
| 227 | ``__annotations__`` attribute of a class or module. |
| 228 | |
| 229 | In contrast to variable declarations in statically typed languages, |
| 230 | the goal of annotation syntax is to provide an easy way to specify structured |
| 231 | type metadata for third party tools and libraries via the abstract syntax tree |
| 232 | and the ``__annotations__`` attribute. |
| 233 | |
| 234 | .. seealso:: |
| 235 | |
| 236 | :pep:`526` -- Syntax for variable annotations. |
| 237 | PEP written by Ryan Gonzalez, Philip House, Ivan Levkivskyi, Lisa Roach, |
| 238 | and Guido van Rossum. Implemented by Ivan Levkivskyi. |
| 239 | |
| 240 | Tools that use or will use the new syntax: |
Sanyam Khurana | 1b4587a | 2017-12-06 22:09:33 +0530 | [diff] [blame] | 241 | `mypy <http://www.mypy-lang.org/>`_, |
| 242 | `pytype <https://github.com/google/pytype>`_, PyCharm, etc. |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 243 | |
| 244 | |
| 245 | .. _whatsnew36-pep515: |
Brett Cannon | a721aba | 2016-09-09 14:57:09 -0700 | [diff] [blame] | 246 | |
| 247 | PEP 515: Underscores in Numeric Literals |
Berker Peksag | 3e49264 | 2016-10-08 16:15:15 +0300 | [diff] [blame] | 248 | ---------------------------------------- |
Brett Cannon | a721aba | 2016-09-09 14:57:09 -0700 | [diff] [blame] | 249 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 250 | :pep:`515` adds the ability to use underscores in numeric literals for |
| 251 | improved readability. For example:: |
| 252 | |
| 253 | >>> 1_000_000_000_000_000 |
| 254 | 1000000000000000 |
| 255 | >>> 0x_FF_FF_FF_FF |
| 256 | 4294967295 |
Brett Cannon | a721aba | 2016-09-09 14:57:09 -0700 | [diff] [blame] | 257 | |
| 258 | Single underscores are allowed between digits and after any base |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 259 | specifier. Leading, trailing, or multiple underscores in a row are not |
| 260 | allowed. |
Brett Cannon | a721aba | 2016-09-09 14:57:09 -0700 | [diff] [blame] | 261 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 262 | The :ref:`string formatting <formatspec>` language also now has support |
| 263 | for the ``'_'`` option to signal the use of an underscore for a thousands |
| 264 | separator for floating point presentation types and for integer |
| 265 | presentation type ``'d'``. For integer presentation types ``'b'``, |
| 266 | ``'o'``, ``'x'``, and ``'X'``, underscores will be inserted every 4 |
| 267 | digits:: |
| 268 | |
| 269 | >>> '{:_}'.format(1000000) |
| 270 | '1_000_000' |
| 271 | >>> '{:_x}'.format(0xFFFFFFFF) |
| 272 | 'ffff_ffff' |
| 273 | |
Brett Cannon | a721aba | 2016-09-09 14:57:09 -0700 | [diff] [blame] | 274 | .. seealso:: |
| 275 | |
Ned Deily | 8761e59 | 2016-09-16 15:46:55 -0400 | [diff] [blame] | 276 | :pep:`515` -- Underscores in Numeric Literals |
Berker Peksag | b5d67b7 | 2016-09-13 05:52:32 +0300 | [diff] [blame] | 277 | PEP written by Georg Brandl and Serhiy Storchaka. |
Brett Cannon | a721aba | 2016-09-09 14:57:09 -0700 | [diff] [blame] | 278 | |
| 279 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 280 | .. _whatsnew36-pep525: |
Brett Cannon | 3cebf93 | 2016-09-05 15:33:46 -0700 | [diff] [blame] | 281 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 282 | PEP 525: Asynchronous Generators |
| 283 | -------------------------------- |
Brett Cannon | 3cebf93 | 2016-09-05 15:33:46 -0700 | [diff] [blame] | 284 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 285 | :pep:`492` introduced support for native coroutines and ``async`` / ``await`` |
| 286 | syntax to Python 3.5. A notable limitation of the Python 3.5 implementation |
| 287 | is that it was not possible to use ``await`` and ``yield`` in the same |
| 288 | function body. In Python 3.6 this restriction has been lifted, making it |
| 289 | possible to define *asynchronous generators*:: |
Brett Cannon | 3cebf93 | 2016-09-05 15:33:46 -0700 | [diff] [blame] | 290 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 291 | async def ticker(delay, to): |
Yury Selivanov | 6bf87d3 | 2016-11-14 14:49:18 -0500 | [diff] [blame] | 292 | """Yield numbers from 0 to *to* every *delay* seconds.""" |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 293 | for i in range(to): |
| 294 | yield i |
| 295 | await asyncio.sleep(delay) |
Brett Cannon | 3cebf93 | 2016-09-05 15:33:46 -0700 | [diff] [blame] | 296 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 297 | The new syntax allows for faster and more concise code. |
Brett Cannon | 3cebf93 | 2016-09-05 15:33:46 -0700 | [diff] [blame] | 298 | |
| 299 | .. seealso:: |
| 300 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 301 | :pep:`525` -- Asynchronous Generators |
| 302 | PEP written and implemented by Yury Selivanov. |
Brett Cannon | 3cebf93 | 2016-09-05 15:33:46 -0700 | [diff] [blame] | 303 | |
| 304 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 305 | .. _whatsnew36-pep530: |
| 306 | |
| 307 | PEP 530: Asynchronous Comprehensions |
| 308 | ------------------------------------ |
| 309 | |
| 310 | :pep:`530` adds support for using ``async for`` in list, set, dict |
| 311 | comprehensions and generator expressions:: |
| 312 | |
| 313 | result = [i async for i in aiter() if i % 2] |
| 314 | |
| 315 | Additionally, ``await`` expressions are supported in all kinds |
| 316 | of comprehensions:: |
| 317 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 318 | result = [await fun() for fun in funcs if await condition()] |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 319 | |
| 320 | .. seealso:: |
| 321 | |
| 322 | :pep:`530` -- Asynchronous Comprehensions |
| 323 | PEP written and implemented by Yury Selivanov. |
| 324 | |
| 325 | |
| 326 | .. _whatsnew36-pep487: |
| 327 | |
| 328 | PEP 487: Simpler customization of class creation |
| 329 | ------------------------------------------------ |
| 330 | |
| 331 | It is now possible to customize subclass creation without using a metaclass. |
| 332 | The new ``__init_subclass__`` classmethod will be called on the base class |
| 333 | whenever a new subclass is created:: |
| 334 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 335 | class PluginBase: |
| 336 | subclasses = [] |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 337 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 338 | def __init_subclass__(cls, **kwargs): |
| 339 | super().__init_subclass__(**kwargs) |
| 340 | cls.subclasses.append(cls) |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 341 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 342 | class Plugin1(PluginBase): |
| 343 | pass |
| 344 | |
| 345 | class Plugin2(PluginBase): |
| 346 | pass |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 347 | |
Nick Coghlan | 19d2467 | 2016-12-05 16:47:55 +1000 | [diff] [blame] | 348 | In order to allow zero-argument :func:`super` calls to work correctly from |
| 349 | :meth:`~object.__init_subclass__` implementations, custom metaclasses must |
| 350 | ensure that the new ``__classcell__`` namespace entry is propagated to |
| 351 | ``type.__new__`` (as described in :ref:`class-object-creation`). |
| 352 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 353 | .. seealso:: |
| 354 | |
| 355 | :pep:`487` -- Simpler customization of class creation |
| 356 | PEP written and implemented by Martin Teichmann. |
| 357 | |
| 358 | :ref:`Feature documentation <class-customization>` |
| 359 | |
| 360 | |
| 361 | .. _whatsnew36-pep487-descriptors: |
| 362 | |
| 363 | PEP 487: Descriptor Protocol Enhancements |
| 364 | ----------------------------------------- |
| 365 | |
Martin Panter | 59b0eb5 | 2016-12-18 01:26:53 +0000 | [diff] [blame] | 366 | :pep:`487` extends the descriptor protocol to include the new optional |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 367 | :meth:`~object.__set_name__` method. Whenever a new class is defined, the new |
| 368 | method will be called on all descriptors included in the definition, providing |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 369 | them with a reference to the class being defined and the name given to the |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 370 | descriptor within the class namespace. In other words, instances of |
| 371 | descriptors can now know the attribute name of the descriptor in the |
| 372 | owner class:: |
| 373 | |
| 374 | class IntField: |
| 375 | def __get__(self, instance, owner): |
| 376 | return instance.__dict__[self.name] |
| 377 | |
| 378 | def __set__(self, instance, value): |
| 379 | if not isinstance(value, int): |
| 380 | raise ValueError(f'expecting integer in {self.name}') |
| 381 | instance.__dict__[self.name] = value |
| 382 | |
| 383 | # this is the new initializer: |
| 384 | def __set_name__(self, owner, name): |
| 385 | self.name = name |
| 386 | |
| 387 | class Model: |
| 388 | int_field = IntField() |
| 389 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 390 | |
| 391 | .. seealso:: |
| 392 | |
| 393 | :pep:`487` -- Simpler customization of class creation |
| 394 | PEP written and implemented by Martin Teichmann. |
| 395 | |
| 396 | :ref:`Feature documentation <descriptors>` |
| 397 | |
| 398 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 399 | .. _whatsnew36-pep519: |
Brett Cannon | 68ed978 | 2016-08-26 14:45:15 -0700 | [diff] [blame] | 400 | |
| 401 | PEP 519: Adding a file system path protocol |
Berker Peksag | b5d67b7 | 2016-09-13 05:52:32 +0300 | [diff] [blame] | 402 | ------------------------------------------- |
Brett Cannon | 68ed978 | 2016-08-26 14:45:15 -0700 | [diff] [blame] | 403 | |
| 404 | File system paths have historically been represented as :class:`str` |
| 405 | or :class:`bytes` objects. This has led to people who write code which |
| 406 | operate on file system paths to assume that such objects are only one |
| 407 | of those two types (an :class:`int` representing a file descriptor |
| 408 | does not count as that is not a file path). Unfortunately that |
| 409 | assumption prevents alternative object representations of file system |
| 410 | paths like :mod:`pathlib` from working with pre-existing code, |
| 411 | including Python's standard library. |
| 412 | |
| 413 | To fix this situation, a new interface represented by |
| 414 | :class:`os.PathLike` has been defined. By implementing the |
| 415 | :meth:`~os.PathLike.__fspath__` method, an object signals that it |
| 416 | represents a path. An object can then provide a low-level |
| 417 | representation of a file system path as a :class:`str` or |
| 418 | :class:`bytes` object. This means an object is considered |
| 419 | :term:`path-like <path-like object>` if it implements |
| 420 | :class:`os.PathLike` or is a :class:`str` or :class:`bytes` object |
| 421 | which represents a file system path. Code can use :func:`os.fspath`, |
| 422 | :func:`os.fsdecode`, or :func:`os.fsencode` to explicitly get a |
| 423 | :class:`str` and/or :class:`bytes` representation of a path-like |
| 424 | object. |
| 425 | |
| 426 | The built-in :func:`open` function has been updated to accept |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 427 | :class:`os.PathLike` objects, as have all relevant functions in the |
| 428 | :mod:`os` and :mod:`os.path` modules, and most other functions and |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 429 | classes in the standard library. The :class:`os.DirEntry` class |
Brett Cannon | 68ed978 | 2016-08-26 14:45:15 -0700 | [diff] [blame] | 430 | and relevant classes in :mod:`pathlib` have also been updated to |
Brett Cannon | a571120 | 2016-09-06 19:36:01 -0700 | [diff] [blame] | 431 | implement :class:`os.PathLike`. |
| 432 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 433 | The hope is that updating the fundamental functions for operating |
Brett Cannon | a571120 | 2016-09-06 19:36:01 -0700 | [diff] [blame] | 434 | on file system paths will lead to third-party code to implicitly |
| 435 | support all :term:`path-like objects <path-like object>` without any |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 436 | code changes, or at least very minimal ones (e.g. calling |
Brett Cannon | a571120 | 2016-09-06 19:36:01 -0700 | [diff] [blame] | 437 | :func:`os.fspath` at the beginning of code before operating on a |
| 438 | path-like object). |
Brett Cannon | 68ed978 | 2016-08-26 14:45:15 -0700 | [diff] [blame] | 439 | |
| 440 | Here are some examples of how the new interface allows for |
| 441 | :class:`pathlib.Path` to be used more easily and transparently with |
| 442 | pre-existing code:: |
| 443 | |
| 444 | >>> import pathlib |
| 445 | >>> with open(pathlib.Path("README")) as f: |
| 446 | ... contents = f.read() |
| 447 | ... |
| 448 | >>> import os.path |
| 449 | >>> os.path.splitext(pathlib.Path("some_file.txt")) |
| 450 | ('some_file', '.txt') |
| 451 | >>> os.path.join("/a/b", pathlib.Path("c")) |
| 452 | '/a/b/c' |
| 453 | >>> import os |
| 454 | >>> os.fspath(pathlib.Path("some_file.txt")) |
| 455 | 'some_file.txt' |
| 456 | |
| 457 | (Implemented by Brett Cannon, Ethan Furman, Dusty Phillips, and Jelle Zijlstra.) |
| 458 | |
| 459 | .. seealso:: |
| 460 | |
Berker Peksag | b5d67b7 | 2016-09-13 05:52:32 +0300 | [diff] [blame] | 461 | :pep:`519` -- Adding a file system path protocol |
Brett Cannon | 68ed978 | 2016-08-26 14:45:15 -0700 | [diff] [blame] | 462 | PEP written by Brett Cannon and Koos Zevenhoven. |
| 463 | |
| 464 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 465 | .. _whatsnew36-pep495: |
| 466 | |
| 467 | PEP 495: Local Time Disambiguation |
| 468 | ---------------------------------- |
| 469 | |
| 470 | In most world locations, there have been and will be times when local clocks |
| 471 | are moved back. In those times, intervals are introduced in which local |
| 472 | clocks show the same time twice in the same day. In these situations, the |
| 473 | information displayed on a local clock (or stored in a Python datetime |
| 474 | instance) is insufficient to identify a particular moment in time. |
| 475 | |
| 476 | :pep:`495` adds the new *fold* attribute to instances of |
| 477 | :class:`datetime.datetime` and :class:`datetime.time` classes to differentiate |
| 478 | between two moments in time for which local times are the same:: |
| 479 | |
| 480 | >>> u0 = datetime(2016, 11, 6, 4, tzinfo=timezone.utc) |
| 481 | >>> for i in range(4): |
| 482 | ... u = u0 + i*HOUR |
| 483 | ... t = u.astimezone(Eastern) |
| 484 | ... print(u.time(), 'UTC =', t.time(), t.tzname(), t.fold) |
| 485 | ... |
| 486 | 04:00:00 UTC = 00:00:00 EDT 0 |
| 487 | 05:00:00 UTC = 01:00:00 EDT 0 |
| 488 | 06:00:00 UTC = 01:00:00 EST 1 |
| 489 | 07:00:00 UTC = 02:00:00 EST 0 |
| 490 | |
| 491 | The values of the :attr:`fold <datetime.datetime.fold>` attribute have the |
Yury Selivanov | 6bf87d3 | 2016-11-14 14:49:18 -0500 | [diff] [blame] | 492 | value ``0`` for all instances except those that represent the second |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 493 | (chronologically) moment in time in an ambiguous case. |
| 494 | |
| 495 | .. seealso:: |
| 496 | |
| 497 | :pep:`495` -- Local Time Disambiguation |
| 498 | PEP written by Alexander Belopolsky and Tim Peters, implementation |
| 499 | by Alexander Belopolsky. |
| 500 | |
| 501 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 502 | .. _whatsnew36-pep529: |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 503 | |
| 504 | PEP 529: Change Windows filesystem encoding to UTF-8 |
Berker Peksag | b5d67b7 | 2016-09-13 05:52:32 +0300 | [diff] [blame] | 505 | ---------------------------------------------------- |
Steve Dower | cc16be8 | 2016-09-08 10:35:16 -0700 | [diff] [blame] | 506 | |
| 507 | Representing filesystem paths is best performed with str (Unicode) rather than |
| 508 | bytes. However, there are some situations where using bytes is sufficient and |
| 509 | correct. |
| 510 | |
| 511 | Prior to Python 3.6, data loss could result when using bytes paths on Windows. |
| 512 | With this change, using bytes to represent paths is now supported on Windows, |
| 513 | provided those bytes are encoded with the encoding returned by |
| 514 | :func:`sys.getfilesystemencoding()`, which now defaults to ``'utf-8'``. |
| 515 | |
| 516 | Applications that do not use str to represent paths should use |
| 517 | :func:`os.fsencode()` and :func:`os.fsdecode()` to ensure their bytes are |
| 518 | correctly encoded. To revert to the previous behaviour, set |
| 519 | :envvar:`PYTHONLEGACYWINDOWSFSENCODING` or call |
| 520 | :func:`sys._enablelegacywindowsfsencoding`. |
| 521 | |
| 522 | See :pep:`529` for more information and discussion of code modifications that |
| 523 | may be required. |
| 524 | |
Ned Deily | 8761e59 | 2016-09-16 15:46:55 -0400 | [diff] [blame] | 525 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 526 | .. _whatsnew36-pep528: |
Steve Dower | 3929499 | 2016-08-30 21:22:36 -0700 | [diff] [blame] | 527 | |
| 528 | PEP 528: Change Windows console encoding to UTF-8 |
| 529 | ------------------------------------------------- |
| 530 | |
| 531 | The default console on Windows will now accept all Unicode characters and |
| 532 | provide correctly read str objects to Python code. ``sys.stdin``, |
| 533 | ``sys.stdout`` and ``sys.stderr`` now default to utf-8 encoding. |
| 534 | |
| 535 | This change only applies when using an interactive console, and not when |
| 536 | redirecting files or pipes. To revert to the previous behaviour for interactive |
Berker Peksag | 87fa8a7 | 2017-05-16 12:36:45 +0300 | [diff] [blame] | 537 | console use, set :envvar:`PYTHONLEGACYWINDOWSSTDIO`. |
Steve Dower | 3929499 | 2016-08-30 21:22:36 -0700 | [diff] [blame] | 538 | |
| 539 | .. seealso:: |
| 540 | |
| 541 | :pep:`528` -- Change Windows console encoding to UTF-8 |
| 542 | PEP written and implemented by Steve Dower. |
Nick Coghlan | d78448e | 2016-07-30 16:26:03 +1000 | [diff] [blame] | 543 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 544 | |
| 545 | .. _whatsnew36-pep520: |
| 546 | |
| 547 | PEP 520: Preserving Class Attribute Definition Order |
| 548 | ---------------------------------------------------- |
| 549 | |
| 550 | Attributes in a class definition body have a natural ordering: the same |
| 551 | order in which the names appear in the source. This order is now |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 552 | preserved in the new class's :attr:`~object.__dict__` attribute. |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 553 | |
| 554 | Also, the effective default class *execution* namespace (returned from |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 555 | :ref:`type.__prepare__() <prepare>`) is now an insertion-order-preserving |
| 556 | mapping. |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 557 | |
| 558 | .. seealso:: |
| 559 | |
| 560 | :pep:`520` -- Preserving Class Attribute Definition Order |
| 561 | PEP written and implemented by Eric Snow. |
| 562 | |
| 563 | |
| 564 | .. _whatsnew36-pep468: |
| 565 | |
| 566 | PEP 468: Preserving Keyword Argument Order |
| 567 | ------------------------------------------ |
| 568 | |
| 569 | ``**kwargs`` in a function signature is now guaranteed to be an |
| 570 | insertion-order-preserving mapping. |
| 571 | |
| 572 | .. seealso:: |
| 573 | |
| 574 | :pep:`468` -- Preserving Keyword Argument Order |
| 575 | PEP written and implemented by Eric Snow. |
| 576 | |
| 577 | |
| 578 | .. _whatsnew36-compactdict: |
| 579 | |
| 580 | New :ref:`dict <typesmapping>` implementation |
| 581 | --------------------------------------------- |
| 582 | |
| 583 | The :ref:`dict <typesmapping>` type now uses a "compact" representation |
Raymond Hettinger | 51447db | 2016-12-29 23:49:20 -0700 | [diff] [blame] | 584 | based on `a proposal by Raymond Hettinger |
| 585 | <https://mail.python.org/pipermail/python-dev/2012-December/123028.html>`_ |
| 586 | which was `first implemented by PyPy |
| 587 | <https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html>`_. |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 588 | The memory usage of the new :func:`dict` is between 20% and 25% smaller |
| 589 | compared to Python 3.5. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 590 | |
| 591 | The order-preserving aspect of this new implementation is considered an |
| 592 | implementation detail and should not be relied upon (this may change in |
| 593 | the future, but it is desired to have this new dict implementation in |
| 594 | the language for a few releases before changing the language spec to mandate |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 595 | order-preserving semantics for all current and future Python |
| 596 | implementations; this also helps preserve backwards-compatibility |
| 597 | with older versions of the language where random iteration order is |
| 598 | still in effect, e.g. Python 3.5). |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 599 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 600 | (Contributed by INADA Naoki in :issue:`27350`. Idea |
| 601 | `originally suggested by Raymond Hettinger |
| 602 | <https://mail.python.org/pipermail/python-dev/2012-December/123028.html>`_.) |
| 603 | |
| 604 | |
| 605 | .. _whatsnew36-pep523: |
| 606 | |
| 607 | PEP 523: Adding a frame evaluation API to CPython |
| 608 | ------------------------------------------------- |
| 609 | |
| 610 | While Python provides extensive support to customize how code |
| 611 | executes, one place it has not done so is in the evaluation of frame |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 612 | objects. If you wanted some way to intercept frame evaluation in |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 613 | Python there really wasn't any way without directly manipulating |
| 614 | function pointers for defined functions. |
| 615 | |
| 616 | :pep:`523` changes this by providing an API to make frame |
| 617 | evaluation pluggable at the C level. This will allow for tools such |
| 618 | as debuggers and JITs to intercept frame evaluation before the |
| 619 | execution of Python code begins. This enables the use of alternative |
| 620 | evaluation implementations for Python code, tracking frame |
| 621 | evaluation, etc. |
| 622 | |
| 623 | This API is not part of the limited C API and is marked as private to |
| 624 | signal that usage of this API is expected to be limited and only |
| 625 | applicable to very select, low-level use-cases. Semantics of the |
| 626 | API will change with Python as necessary. |
| 627 | |
| 628 | .. seealso:: |
| 629 | |
| 630 | :pep:`523` -- Adding a frame evaluation API to CPython |
| 631 | PEP written by Brett Cannon and Dino Viehland. |
| 632 | |
| 633 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 634 | .. _whatsnew36-pythonmalloc: |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 635 | |
Victor Stinner | 34be807 | 2016-03-14 12:04:26 +0100 | [diff] [blame] | 636 | PYTHONMALLOC environment variable |
Berker Peksag | b5d67b7 | 2016-09-13 05:52:32 +0300 | [diff] [blame] | 637 | --------------------------------- |
Victor Stinner | 34be807 | 2016-03-14 12:04:26 +0100 | [diff] [blame] | 638 | |
Martin Panter | df1d31c | 2016-06-20 08:00:45 +0000 | [diff] [blame] | 639 | The new :envvar:`PYTHONMALLOC` environment variable allows setting the Python |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 640 | memory allocators and installing debug hooks. |
Victor Stinner | 34be807 | 2016-03-14 12:04:26 +0100 | [diff] [blame] | 641 | |
| 642 | It is now possible to install debug hooks on Python memory allocators on Python |
| 643 | compiled in release mode using ``PYTHONMALLOC=debug``. Effects of debug hooks: |
| 644 | |
| 645 | * Newly allocated memory is filled with the byte ``0xCB`` |
| 646 | * Freed memory is filled with the byte ``0xDB`` |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 647 | * Detect violations of the Python memory allocator API. For example, |
Victor Stinner | 34be807 | 2016-03-14 12:04:26 +0100 | [diff] [blame] | 648 | :c:func:`PyObject_Free` called on a memory block allocated by |
| 649 | :c:func:`PyMem_Malloc`. |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 650 | * Detect writes before the start of a buffer (buffer underflows) |
| 651 | * Detect writes after the end of a buffer (buffer overflows) |
Victor Stinner | c4aec36 | 2016-03-14 22:26:53 +0100 | [diff] [blame] | 652 | * Check that the :term:`GIL <global interpreter lock>` is held when allocator |
Victor Stinner | c2fc568 | 2016-03-18 11:04:31 +0100 | [diff] [blame] | 653 | functions of :c:data:`PYMEM_DOMAIN_OBJ` (ex: :c:func:`PyObject_Malloc`) and |
| 654 | :c:data:`PYMEM_DOMAIN_MEM` (ex: :c:func:`PyMem_Malloc`) domains are called. |
| 655 | |
Victor Stinner | 9b46a57 | 2016-03-18 15:10:43 +0100 | [diff] [blame] | 656 | Checking if the GIL is held is also a new feature of Python 3.6. |
Victor Stinner | 34be807 | 2016-03-14 12:04:26 +0100 | [diff] [blame] | 657 | |
| 658 | See the :c:func:`PyMem_SetupDebugHooks` function for debug hooks on Python |
| 659 | memory allocators. |
| 660 | |
| 661 | It is now also possible to force the usage of the :c:func:`malloc` allocator of |
| 662 | the C library for all Python memory allocations using ``PYTHONMALLOC=malloc``. |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 663 | This is helpful when using external memory debuggers like Valgrind on |
| 664 | a Python compiled in release mode. |
Victor Stinner | 34be807 | 2016-03-14 12:04:26 +0100 | [diff] [blame] | 665 | |
Victor Stinner | 0611c26 | 2016-03-15 22:22:13 +0100 | [diff] [blame] | 666 | On error, the debug hooks on Python memory allocators now use the |
| 667 | :mod:`tracemalloc` module to get the traceback where a memory block was |
| 668 | allocated. |
| 669 | |
| 670 | Example of fatal error on buffer overflow using |
| 671 | ``python3.6 -X tracemalloc=5`` (store 5 frames in traces):: |
| 672 | |
| 673 | Debug memory block at address p=0x7fbcd41666f8: API 'o' |
| 674 | 4 bytes originally requested |
| 675 | The 7 pad bytes at p-7 are FORBIDDENBYTE, as expected. |
| 676 | The 8 pad bytes at tail=0x7fbcd41666fc are not all FORBIDDENBYTE (0xfb): |
| 677 | at tail+0: 0x02 *** OUCH |
| 678 | at tail+1: 0xfb |
| 679 | at tail+2: 0xfb |
| 680 | at tail+3: 0xfb |
| 681 | at tail+4: 0xfb |
| 682 | at tail+5: 0xfb |
| 683 | at tail+6: 0xfb |
| 684 | at tail+7: 0xfb |
| 685 | The block was made by call #1233329 to debug malloc/realloc. |
| 686 | Data at p: 1a 2b 30 00 |
| 687 | |
| 688 | Memory block allocated at (most recent call first): |
| 689 | File "test/test_bytes.py", line 323 |
| 690 | File "unittest/case.py", line 600 |
| 691 | File "unittest/case.py", line 648 |
| 692 | File "unittest/suite.py", line 122 |
| 693 | File "unittest/suite.py", line 84 |
| 694 | |
| 695 | Fatal Python error: bad trailing pad byte |
| 696 | |
| 697 | Current thread 0x00007fbcdbd32700 (most recent call first): |
| 698 | File "test/test_bytes.py", line 323 in test_hex |
| 699 | File "unittest/case.py", line 600 in run |
| 700 | File "unittest/case.py", line 648 in __call__ |
| 701 | File "unittest/suite.py", line 122 in run |
| 702 | File "unittest/suite.py", line 84 in __call__ |
| 703 | File "unittest/suite.py", line 122 in run |
| 704 | File "unittest/suite.py", line 84 in __call__ |
| 705 | ... |
| 706 | |
| 707 | (Contributed by Victor Stinner in :issue:`26516` and :issue:`26564`.) |
Victor Stinner | 34be807 | 2016-03-14 12:04:26 +0100 | [diff] [blame] | 708 | |
| 709 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 710 | .. _whatsnew36-tracing: |
| 711 | |
Łukasz Langa | a785c87 | 2016-09-09 17:37:37 -0700 | [diff] [blame] | 712 | DTrace and SystemTap probing support |
| 713 | ------------------------------------ |
| 714 | |
| 715 | Python can now be built ``--with-dtrace`` which enables static markers |
| 716 | for the following events in the interpreter: |
| 717 | |
| 718 | * function call/return |
| 719 | |
| 720 | * garbage collection started/finished |
| 721 | |
| 722 | * line of code executed. |
| 723 | |
| 724 | This can be used to instrument running interpreters in production, |
| 725 | without the need to recompile specific debug builds or providing |
| 726 | application-specific profiling/debugging code. |
| 727 | |
Benjamin Peterson | 47503c5 | 2016-09-10 17:38:51 -0700 | [diff] [blame] | 728 | More details in :ref:`instrumentation`. |
Łukasz Langa | a785c87 | 2016-09-09 17:37:37 -0700 | [diff] [blame] | 729 | |
| 730 | The current implementation is tested on Linux and macOS. Additional |
| 731 | markers may be added in the future. |
| 732 | |
| 733 | (Contributed by Łukasz Langa in :issue:`21590`, based on patches by |
| 734 | Jesús Cea Avión, David Malcolm, and Nikhil Benesch.) |
| 735 | |
| 736 | |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 737 | Other Language Changes |
| 738 | ====================== |
| 739 | |
Nick Coghlan | 02d03df | 2016-08-16 10:58:14 +1000 | [diff] [blame] | 740 | Some smaller changes made to the core Python language are: |
| 741 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 742 | * A ``global`` or ``nonlocal`` statement must now textually appear |
| 743 | before the first use of the affected name in the same scope. |
| 744 | Previously this was a ``SyntaxWarning``. |
Victor Stinner | 742da04 | 2016-09-07 17:40:12 -0700 | [diff] [blame] | 745 | |
Yury Selivanov | 6bf87d3 | 2016-11-14 14:49:18 -0500 | [diff] [blame] | 746 | * It is now possible to set a :ref:`special method <specialnames>` to |
| 747 | ``None`` to indicate that the corresponding operation is not available. |
| 748 | For example, if a class sets :meth:`__iter__` to ``None``, the class |
| 749 | is not iterable. |
| 750 | (Contributed by Andrew Barnert and Ivan Levkivskyi in :issue:`25958`.) |
| 751 | |
Nick Coghlan | 02d03df | 2016-08-16 10:58:14 +1000 | [diff] [blame] | 752 | * Long sequences of repeated traceback lines are now abbreviated as |
| 753 | ``"[Previous line repeated {count} more times]"`` (see |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 754 | :ref:`whatsnew36-traceback` for an example). |
Nick Coghlan | 02d03df | 2016-08-16 10:58:14 +1000 | [diff] [blame] | 755 | (Contributed by Emanuel Barry in :issue:`26823`.) |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 756 | |
Eric Snow | 46f97b8 | 2016-09-07 16:56:15 -0700 | [diff] [blame] | 757 | * Import now raises the new exception :exc:`ModuleNotFoundError` |
| 758 | (subclass of :exc:`ImportError`) when it cannot find a module. Code |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 759 | that currently checks for ImportError (in try-except) will still work. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 760 | (Contributed by Eric Snow in :issue:`15767`.) |
| 761 | |
| 762 | * Class methods relying on zero-argument ``super()`` will now work correctly |
| 763 | when called from metaclass methods during class creation. |
| 764 | (Contributed by Martin Teichmann in :issue:`23722`.) |
Eric Snow | 46f97b8 | 2016-09-07 16:56:15 -0700 | [diff] [blame] | 765 | |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 766 | |
| 767 | New Modules |
| 768 | =========== |
| 769 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 770 | .. _whatsnew36-pep506: |
| 771 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 772 | secrets |
| 773 | ------- |
| 774 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 775 | The main purpose of the new :mod:`secrets` module is to provide an obvious way |
| 776 | to reliably generate cryptographically strong pseudo-random values suitable |
| 777 | for managing secrets, such as account authentication, tokens, and similar. |
| 778 | |
| 779 | .. warning:: |
| 780 | |
| 781 | Note that the pseudo-random generators in the :mod:`random` module |
| 782 | should *NOT* be used for security purposes. Use :mod:`secrets` |
| 783 | on Python 3.6+ and :func:`os.urandom()` on Python 3.5 and earlier. |
| 784 | |
| 785 | .. seealso:: |
| 786 | |
| 787 | :pep:`506` -- Adding A Secrets Module To The Standard Library |
| 788 | PEP written and implemented by Steven D'Aprano. |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 789 | |
| 790 | |
| 791 | Improved Modules |
| 792 | ================ |
| 793 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 794 | array |
| 795 | ----- |
| 796 | |
| 797 | Exhausted iterators of :class:`array.array` will now stay exhausted even |
| 798 | if the iterated array is extended. This is consistent with the behavior |
| 799 | of other mutable sequences. |
| 800 | |
| 801 | Contributed by Serhiy Storchaka in :issue:`26492`. |
| 802 | |
| 803 | ast |
| 804 | --- |
| 805 | |
| 806 | The new :class:`ast.Constant` AST node has been added. It can be used |
| 807 | by external AST optimizers for the purposes of constant folding. |
| 808 | |
| 809 | Contributed by Victor Stinner in :issue:`26146`. |
| 810 | |
| 811 | |
Yury Selivanov | b4a0d52 | 2016-05-16 16:25:16 -0400 | [diff] [blame] | 812 | asyncio |
| 813 | ------- |
| 814 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 815 | Starting with Python 3.6 the ``asyncio`` module is no longer provisional and its |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 816 | API is considered stable. |
Yury Selivanov | b4a0d52 | 2016-05-16 16:25:16 -0400 | [diff] [blame] | 817 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 818 | Notable changes in the :mod:`asyncio` module since Python 3.5.0 |
| 819 | (all backported to 3.5.x due to the provisional status): |
| 820 | |
| 821 | * The :func:`~asyncio.get_event_loop` function has been changed to |
Mandeep Singh | e55de2d | 2018-05-30 00:07:08 +0530 | [diff] [blame] | 822 | always return the currently running loop when called from coroutines |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 823 | and callbacks. |
| 824 | (Contributed by Yury Selivanov in :issue:`28613`.) |
Yury Selivanov | b4a0d52 | 2016-05-16 16:25:16 -0400 | [diff] [blame] | 825 | |
| 826 | * The :func:`~asyncio.ensure_future` function and all functions that |
| 827 | use it, such as :meth:`loop.run_until_complete() <asyncio.BaseEventLoop.run_until_complete>`, |
| 828 | now accept all kinds of :term:`awaitable objects <awaitable>`. |
| 829 | (Contributed by Yury Selivanov.) |
| 830 | |
| 831 | * New :func:`~asyncio.run_coroutine_threadsafe` function to submit |
| 832 | coroutines to event loops from other threads. |
| 833 | (Contributed by Vincent Michel.) |
| 834 | |
| 835 | * New :meth:`Transport.is_closing() <asyncio.BaseTransport.is_closing>` |
| 836 | method to check if the transport is closing or closed. |
| 837 | (Contributed by Yury Selivanov.) |
| 838 | |
| 839 | * The :meth:`loop.create_server() <asyncio.BaseEventLoop.create_server>` |
| 840 | method can now accept a list of hosts. |
| 841 | (Contributed by Yann Sionneau.) |
| 842 | |
| 843 | * New :meth:`loop.create_future() <asyncio.BaseEventLoop.create_future>` |
| 844 | method to create Future objects. This allows alternative event |
| 845 | loop implementations, such as |
| 846 | `uvloop <https://github.com/MagicStack/uvloop>`_, to provide a faster |
| 847 | :class:`asyncio.Future` implementation. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 848 | (Contributed by Yury Selivanov in :issue:`27041`.) |
Yury Selivanov | b4a0d52 | 2016-05-16 16:25:16 -0400 | [diff] [blame] | 849 | |
| 850 | * New :meth:`loop.get_exception_handler() <asyncio.BaseEventLoop.get_exception_handler>` |
| 851 | method to get the current exception handler. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 852 | (Contributed by Yury Selivanov in :issue:`27040`.) |
Yury Selivanov | b4a0d52 | 2016-05-16 16:25:16 -0400 | [diff] [blame] | 853 | |
Yury Selivanov | b4a0d52 | 2016-05-16 16:25:16 -0400 | [diff] [blame] | 854 | * New :meth:`StreamReader.readuntil() <asyncio.StreamReader.readuntil>` |
| 855 | method to read data from the stream until a separator bytes |
| 856 | sequence appears. |
| 857 | (Contributed by Mark Korenberg.) |
| 858 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 859 | * The performance of :meth:`StreamReader.readexactly() <asyncio.StreamReader.readexactly>` |
| 860 | has been improved. |
| 861 | (Contributed by Mark Korenberg in :issue:`28370`.) |
| 862 | |
Yury Selivanov | b4a0d52 | 2016-05-16 16:25:16 -0400 | [diff] [blame] | 863 | * The :meth:`loop.getaddrinfo() <asyncio.BaseEventLoop.getaddrinfo>` |
| 864 | method is optimized to avoid calling the system ``getaddrinfo`` |
| 865 | function if the address is already resolved. |
| 866 | (Contributed by A. Jesse Jiryu Davis.) |
| 867 | |
Yury Selivanov | 1217470 | 2016-12-15 17:56:43 -0500 | [diff] [blame] | 868 | * The :meth:`loop.stop() <asyncio.BaseEventLoop.stop>` |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 869 | method has been changed to stop the loop immediately after |
| 870 | the current iteration. Any new callbacks scheduled as a result |
| 871 | of the last iteration will be discarded. |
| 872 | (Contributed by Guido van Rossum in :issue:`25593`.) |
| 873 | |
| 874 | * :meth:`Future.set_exception <asyncio.futures.Future.set_exception>` |
| 875 | will now raise :exc:`TypeError` when passed an instance of |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 876 | the :exc:`StopIteration` exception. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 877 | (Contributed by Chris Angelico in :issue:`26221`.) |
| 878 | |
Yury Selivanov | 1217470 | 2016-12-15 17:56:43 -0500 | [diff] [blame] | 879 | * New :meth:`loop.connect_accepted_socket() <asyncio.BaseEventLoop.connect_accepted_socket>` |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 880 | method to be used by servers that accept connections outside of asyncio, |
| 881 | but that use asyncio to handle them. |
| 882 | (Contributed by Jim Fulton in :issue:`27392`.) |
| 883 | |
Yury Selivanov | 3432f2f | 2016-12-12 16:44:58 -0500 | [diff] [blame] | 884 | * ``TCP_NODELAY`` flag is now set for all TCP transports by default. |
| 885 | (Contributed by Yury Selivanov in :issue:`27456`.) |
| 886 | |
Yury Selivanov | 1217470 | 2016-12-15 17:56:43 -0500 | [diff] [blame] | 887 | * New :meth:`loop.shutdown_asyncgens() <asyncio.AbstractEventLoop.shutdown_asyncgens>` |
| 888 | to properly close pending asynchronous generators before closing the |
| 889 | loop. |
| 890 | (Contributed by Yury Selivanov in :issue:`28003`.) |
| 891 | |
| 892 | * :class:`Future <asyncio.Future>` and :class:`Task <asyncio.Task>` |
| 893 | classes now have an optimized C implementation which makes asyncio |
| 894 | code up to 30% faster. |
| 895 | (Contributed by Yury Selivanov and INADA Naoki in :issue:`26081` |
| 896 | and :issue:`28544`.) |
| 897 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 898 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 899 | binascii |
| 900 | -------- |
| 901 | |
| 902 | The :func:`~binascii.b2a_base64` function now accepts an optional *newline* |
| 903 | keyword argument to control whether the newline character is appended to the |
| 904 | return value. |
| 905 | (Contributed by Victor Stinner in :issue:`25357`.) |
| 906 | |
| 907 | |
| 908 | cmath |
| 909 | ----- |
| 910 | |
Serhiy Storchaka | dbaf746 | 2017-05-04 12:25:09 +0300 | [diff] [blame] | 911 | The new :const:`cmath.tau` (*τ*) constant has been added. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 912 | (Contributed by Lisa Roach in :issue:`12345`, see :pep:`628` for details.) |
| 913 | |
| 914 | New constants: :const:`cmath.inf` and :const:`cmath.nan` to |
| 915 | match :const:`math.inf` and :const:`math.nan`, and also :const:`cmath.infj` |
| 916 | and :const:`cmath.nanj` to match the format used by complex repr. |
| 917 | (Contributed by Mark Dickinson in :issue:`23229`.) |
| 918 | |
| 919 | |
| 920 | collections |
| 921 | ----------- |
| 922 | |
Yury Selivanov | 6bf87d3 | 2016-11-14 14:49:18 -0500 | [diff] [blame] | 923 | The new :class:`~collections.abc.Collection` abstract base class has been |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 924 | added to represent sized iterable container classes. |
Yury Selivanov | 6bf87d3 | 2016-11-14 14:49:18 -0500 | [diff] [blame] | 925 | (Contributed by Ivan Levkivskyi, docs by Neil Girdhar in :issue:`27598`.) |
| 926 | |
| 927 | The new :class:`~collections.abc.Reversible` abstract base class represents |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 928 | iterable classes that also provide the :meth:`__reversed__` method. |
Yury Selivanov | 6bf87d3 | 2016-11-14 14:49:18 -0500 | [diff] [blame] | 929 | (Contributed by Ivan Levkivskyi in :issue:`25987`.) |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 930 | |
Yury Selivanov | 22214ab | 2016-11-16 18:25:04 -0500 | [diff] [blame] | 931 | The new :class:`~collections.abc.AsyncGenerator` abstract base class represents |
| 932 | asynchronous generators. |
| 933 | (Contributed by Yury Selivanov in :issue:`28720`.) |
| 934 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 935 | The :func:`~collections.namedtuple` function now accepts an optional |
| 936 | keyword argument *module*, which, when specified, is used for |
| 937 | the ``__module__`` attribute of the returned named tuple class. |
| 938 | (Contributed by Raymond Hettinger in :issue:`17941`.) |
| 939 | |
| 940 | The *verbose* and *rename* arguments for |
| 941 | :func:`~collections.namedtuple` are now keyword-only. |
| 942 | (Contributed by Raymond Hettinger in :issue:`25628`.) |
| 943 | |
| 944 | Recursive :class:`collections.deque` instances can now be pickled. |
| 945 | (Contributed by Serhiy Storchaka in :issue:`26482`.) |
| 946 | |
| 947 | |
| 948 | concurrent.futures |
| 949 | ------------------ |
| 950 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 951 | The :class:`ThreadPoolExecutor <concurrent.futures.ThreadPoolExecutor>` |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 952 | class constructor now accepts an optional *thread_name_prefix* argument |
| 953 | to make it possible to customize the names of the threads created by the |
| 954 | pool. |
| 955 | (Contributed by Gregory P. Smith in :issue:`27664`.) |
| 956 | |
Yury Selivanov | b4a0d52 | 2016-05-16 16:25:16 -0400 | [diff] [blame] | 957 | |
Brett Cannon | 9e080e0 | 2016-04-08 12:15:27 -0700 | [diff] [blame] | 958 | contextlib |
| 959 | ---------- |
| 960 | |
| 961 | The :class:`contextlib.AbstractContextManager` class has been added to |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 962 | provide an abstract base class for context managers. It provides a |
Brett Cannon | 9e080e0 | 2016-04-08 12:15:27 -0700 | [diff] [blame] | 963 | sensible default implementation for `__enter__()` which returns |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 964 | ``self`` and leaves `__exit__()` an abstract method. A matching |
Brett Cannon | 9e080e0 | 2016-04-08 12:15:27 -0700 | [diff] [blame] | 965 | class has been added to the :mod:`typing` module as |
| 966 | :class:`typing.ContextManager`. |
| 967 | (Contributed by Brett Cannon in :issue:`25609`.) |
| 968 | |
| 969 | |
Berker Peksag | b6c9572 | 2015-10-08 13:58:49 +0300 | [diff] [blame] | 970 | datetime |
| 971 | -------- |
| 972 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 973 | The :class:`~datetime.datetime` and :class:`~datetime.time` classes have |
| 974 | the new :attr:`~time.fold` attribute used to disambiguate local time |
| 975 | when necessary. Many functions in the :mod:`datetime` have been |
| 976 | updated to support local time disambiguation. |
| 977 | See :ref:`Local Time Disambiguation <whatsnew36-pep495>` section for more |
| 978 | information. |
| 979 | (Contributed by Alexander Belopolsky in :issue:`24773`.) |
| 980 | |
Martin Panter | fad4b60 | 2015-11-14 01:29:17 +0000 | [diff] [blame] | 981 | The :meth:`datetime.strftime() <datetime.datetime.strftime>` and |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 982 | :meth:`date.strftime() <datetime.date.strftime>` methods now support |
| 983 | ISO 8601 date directives ``%G``, ``%u`` and ``%V``. |
Berker Peksag | b6c9572 | 2015-10-08 13:58:49 +0300 | [diff] [blame] | 984 | (Contributed by Ashley Anderson in :issue:`12006`.) |
| 985 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 986 | The :func:`datetime.isoformat() <datetime.datetime.isoformat>` function |
| 987 | now accepts an optional *timespec* argument that specifies the number |
| 988 | of additional components of the time value to include. |
| 989 | (Contributed by Alessandro Cucci and Alexander Belopolsky in :issue:`19475`.) |
Berker Peksag | b6c9572 | 2015-10-08 13:58:49 +0300 | [diff] [blame] | 990 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 991 | The :meth:`datetime.combine() <datetime.datetime.combine>` now |
| 992 | accepts an optional *tzinfo* argument. |
| 993 | (Contributed by Alexander Belopolsky in :issue:`27661`.) |
| 994 | |
| 995 | |
| 996 | decimal |
| 997 | ------- |
| 998 | |
| 999 | New :meth:`Decimal.as_integer_ratio() <decimal.Decimal.as_integer_ratio>` |
| 1000 | method that returns a pair ``(n, d)`` of integers that represent the given |
| 1001 | :class:`~decimal.Decimal` instance as a fraction, in lowest terms and |
| 1002 | with a positive denominator:: |
| 1003 | |
| 1004 | >>> Decimal('-3.14').as_integer_ratio() |
| 1005 | (-157, 50) |
| 1006 | |
| 1007 | (Contributed by Stefan Krah amd Mark Dickinson in :issue:`25928`.) |
| 1008 | |
| 1009 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1010 | |
| 1011 | distutils |
| 1012 | --------- |
Jason R. Coombs | c758d51 | 2016-08-21 16:09:27 -0400 | [diff] [blame] | 1013 | |
| 1014 | The ``default_format`` attribute has been removed from |
| 1015 | :class:`distutils.command.sdist.sdist` and the ``formats`` |
| 1016 | attribute defaults to ``['gztar']``. Although not anticipated, |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1017 | any code relying on the presence of ``default_format`` may |
Jason R. Coombs | c758d51 | 2016-08-21 16:09:27 -0400 | [diff] [blame] | 1018 | need to be adapted. See :issue:`27819` for more details. |
| 1019 | |
| 1020 | |
R David Murray | 56b1f1b | 2016-09-07 16:48:35 -0400 | [diff] [blame] | 1021 | email |
| 1022 | ----- |
| 1023 | |
R David Murray | 8e7cdb2 | 2016-09-07 21:21:58 -0400 | [diff] [blame] | 1024 | The new email API, enabled via the *policy* keyword to various constructors, is |
| 1025 | no longer provisional. The :mod:`email` documentation has been reorganized and |
| 1026 | rewritten to focus on the new API, while retaining the old documentation for |
| 1027 | the legacy API. (Contributed by R. David Murray in :issue:`24277`.) |
| 1028 | |
R David Murray | 56b1f1b | 2016-09-07 16:48:35 -0400 | [diff] [blame] | 1029 | The :mod:`email.mime` classes now all accept an optional *policy* keyword. |
| 1030 | (Contributed by Berker Peksag in :issue:`27331`.) |
| 1031 | |
R David Murray | 301edfa | 2016-09-08 17:57:06 -0400 | [diff] [blame] | 1032 | The :class:`~email.generator.DecodedGenerator` now supports the *policy* |
| 1033 | keyword. |
| 1034 | |
R David Murray | 06ed218 | 2016-09-09 18:39:18 -0400 | [diff] [blame] | 1035 | There is a new :mod:`~email.policy` attribute, |
| 1036 | :attr:`~email.policy.Policy.message_factory`, that controls what class is used |
| 1037 | by default when the parser creates new message objects. For the |
| 1038 | :attr:`email.policy.compat32` policy this is :class:`~email.message.Message`, |
| 1039 | for the new policies it is :class:`~email.message.EmailMessage`. |
| 1040 | (Contributed by R. David Murray in :issue:`20476`.) |
| 1041 | |
R David Murray | 56b1f1b | 2016-09-07 16:48:35 -0400 | [diff] [blame] | 1042 | |
Steve Dower | 6cebd48 | 2016-09-06 19:55:55 -0700 | [diff] [blame] | 1043 | encodings |
| 1044 | --------- |
| 1045 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1046 | On Windows, added the ``'oem'`` encoding to use ``CP_OEMCP``, and the ``'ansi'`` |
Steve Dower | 6cebd48 | 2016-09-06 19:55:55 -0700 | [diff] [blame] | 1047 | alias for the existing ``'mbcs'`` encoding, which uses the ``CP_ACP`` code page. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1048 | (Contributed by Steve Dower in :issue:`27959`.) |
| 1049 | |
| 1050 | |
| 1051 | enum |
| 1052 | ---- |
| 1053 | |
| 1054 | Two new enumeration base classes have been added to the :mod:`enum` module: |
| 1055 | :class:`~enum.Flag` and :class:`~enum.IntFlags`. Both are used to define |
| 1056 | constants that can be combined using the bitwise operators. |
| 1057 | (Contributed by Ethan Furman in :issue:`23591`.) |
| 1058 | |
| 1059 | Many standard library modules have been updated to use the |
| 1060 | :class:`~enum.IntFlags` class for their constants. |
| 1061 | |
| 1062 | The new :class:`enum.auto` value can be used to assign values to enum |
| 1063 | members automatically:: |
| 1064 | |
| 1065 | >>> from enum import Enum, auto |
| 1066 | >>> class Color(Enum): |
| 1067 | ... red = auto() |
| 1068 | ... blue = auto() |
| 1069 | ... green = auto() |
| 1070 | ... |
| 1071 | >>> list(Color) |
| 1072 | [<Color.red: 1>, <Color.blue: 2>, <Color.green: 3>] |
Steve Dower | 6cebd48 | 2016-09-06 19:55:55 -0700 | [diff] [blame] | 1073 | |
R David Murray | 301edfa | 2016-09-08 17:57:06 -0400 | [diff] [blame] | 1074 | |
Victor Stinner | 404cdc5 | 2016-03-23 10:39:17 +0100 | [diff] [blame] | 1075 | faulthandler |
| 1076 | ------------ |
| 1077 | |
Serhiy Storchaka | b6a9c97 | 2016-04-17 09:39:28 +0300 | [diff] [blame] | 1078 | On Windows, the :mod:`faulthandler` module now installs a handler for Windows |
Victor Stinner | 404cdc5 | 2016-03-23 10:39:17 +0100 | [diff] [blame] | 1079 | exceptions: see :func:`faulthandler.enable`. (Contributed by Victor Stinner in |
| 1080 | :issue:`23848`.) |
| 1081 | |
| 1082 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1083 | fileinput |
| 1084 | --------- |
| 1085 | |
| 1086 | :func:`~fileinput.hook_encoded` now supports the *errors* argument. |
| 1087 | (Contributed by Joseph Hackman in :issue:`25788`.) |
| 1088 | |
| 1089 | |
Christian Heimes | c4d2e50 | 2016-09-12 01:14:35 +0200 | [diff] [blame] | 1090 | hashlib |
| 1091 | ------- |
| 1092 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1093 | :mod:`hashlib` supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2. |
Christian Heimes | c4d2e50 | 2016-09-12 01:14:35 +0200 | [diff] [blame] | 1094 | (Contributed by Christian Heimes in :issue:`26470`.) |
| 1095 | |
| 1096 | BLAKE2 hash functions were added to the module. :func:`~hashlib.blake2b` |
| 1097 | and :func:`~hashlib.blake2s` are always available and support the full |
| 1098 | feature set of BLAKE2. |
| 1099 | (Contributed by Christian Heimes in :issue:`26798` based on code by |
| 1100 | Dmitry Chestnykh and Samuel Neves. Documentation written by Dmitry Chestnykh.) |
| 1101 | |
| 1102 | The SHA-3 hash functions :func:`~hashlib.sha3_224`, :func:`~hashlib.sha3_256`, |
| 1103 | :func:`~hashlib.sha3_384`, :func:`~hashlib.sha3_512`, and SHAKE hash functions |
| 1104 | :func:`~hashlib.shake_128` and :func:`~hashlib.shake_256` were added. |
| 1105 | (Contributed by Christian Heimes in :issue:`16113`. Keccak Code Package |
| 1106 | by Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche, and |
| 1107 | Ronny Van Keer.) |
| 1108 | |
| 1109 | The password-based key derivation function :func:`~hashlib.scrypt` is now |
| 1110 | available with OpenSSL 1.1.0 and newer. |
| 1111 | (Contributed by Christian Heimes in :issue:`27928`.) |
| 1112 | |
Martin Panter | 3c0d0ba | 2016-08-24 06:33:33 +0000 | [diff] [blame] | 1113 | http.client |
| 1114 | ----------- |
| 1115 | |
| 1116 | :meth:`HTTPConnection.request() <http.client.HTTPConnection.request>` and |
| 1117 | :meth:`~http.client.HTTPConnection.endheaders` both now support |
| 1118 | chunked encoding request bodies. |
| 1119 | (Contributed by Demian Brecht and Rolf Krahl in :issue:`12319`.) |
| 1120 | |
| 1121 | |
Terry Jan Reedy | d9792a0 | 2016-06-13 00:41:53 -0400 | [diff] [blame] | 1122 | idlelib and IDLE |
| 1123 | ---------------- |
| 1124 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1125 | The idlelib package is being modernized and refactored to make IDLE look and |
| 1126 | work better and to make the code easier to understand, test, and improve. Part |
| 1127 | of making IDLE look better, especially on Linux and Mac, is using ttk widgets, |
| 1128 | mostly in the dialogs. As a result, IDLE no longer runs with tcl/tk 8.4. It |
| 1129 | now requires tcl/tk 8.5 or 8.6. We recommend running the latest release of |
| 1130 | either. |
Terry Jan Reedy | d9792a0 | 2016-06-13 00:41:53 -0400 | [diff] [blame] | 1131 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1132 | 'Modernizing' includes renaming and consolidation of idlelib modules. The |
| 1133 | renaming of files with partial uppercase names is similar to the renaming of, |
| 1134 | for instance, Tkinter and TkFont to tkinter and tkinter.font in 3.0. As a |
| 1135 | result, imports of idlelib files that worked in 3.5 will usually not work in |
| 1136 | 3.6. At least a module name change will be needed (see idlelib/README.txt), |
| 1137 | sometimes more. (Name changes contributed by Al Swiegart and Terry Reedy in |
| 1138 | :issue:`24225`. Most idlelib patches since have been and will be part of the |
| 1139 | process.) |
Terry Jan Reedy | d9792a0 | 2016-06-13 00:41:53 -0400 | [diff] [blame] | 1140 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1141 | In compensation, the eventual result with be that some idlelib classes will be |
| 1142 | easier to use, with better APIs and docstrings explaining them. Additional |
| 1143 | useful information will be added to idlelib when available. |
Terry Jan Reedy | d9792a0 | 2016-06-13 00:41:53 -0400 | [diff] [blame] | 1144 | |
Terry Jan Reedy | e226eb7 | 2018-06-10 14:03:40 -0400 | [diff] [blame] | 1145 | New in 3.6.2: |
| 1146 | |
| 1147 | Multiple fixes for autocompletion. (Contributed by Louie Lu in :issue:`15786`.) |
| 1148 | |
| 1149 | New in 3.6.3: |
| 1150 | |
| 1151 | Module Browser (on the File menu, formerly called Class Browser), |
| 1152 | now displays nested functions and classes in addition to top-level |
| 1153 | functions and classes. |
| 1154 | (Contributed by Guilherme Polo, Cheryl Sabella, and Terry Jan Reedy |
| 1155 | in :issue:`1612262`.) |
| 1156 | |
| 1157 | The IDLE features formerly implemented as extensions have been reimplemented |
| 1158 | as normal features. Their settings have been moved from the Extensions tab |
| 1159 | to other dialog tabs. |
| 1160 | (Contributed by Charles Wohlganger and Terry Jan Reedy in :issue:`27099`.) |
| 1161 | |
| 1162 | The Settings dialog (Options, Configure IDLE) has been partly rewritten |
| 1163 | to improve both appearance and function. |
| 1164 | (Contributed by Cheryl Sabella and Terry Jan Reedy in multiple issues.) |
| 1165 | |
| 1166 | New in 3.6.4: |
| 1167 | |
| 1168 | The font sample now includes a selection of non-Latin characters so that |
| 1169 | users can better see the effect of selecting a particular font. |
| 1170 | (Contributed by Terry Jan Reedy in :issue:`13802`.) |
| 1171 | The sample can be edited to include other characters. |
| 1172 | (Contributed by Serhiy Storchaka in :issue:`31860`.) |
| 1173 | |
| 1174 | New in 3.6.6: |
| 1175 | |
| 1176 | Editor code context option revised. Box displays all context lines up to |
| 1177 | maxlines. Clicking on a context line jumps the editor to that line. Context |
| 1178 | colors for custom themes is added to Highlights tab of Settings dialog. |
| 1179 | (Contributed by Cheryl Sabella and Terry Jan Reedy in :issue:`33642`, |
Terry Jan Reedy | 820c53a | 2018-06-10 14:57:38 -0400 | [diff] [blame] | 1180 | :issue:`33768`, and :issue:`33679`) |
Terry Jan Reedy | e226eb7 | 2018-06-10 14:03:40 -0400 | [diff] [blame] | 1181 | |
Terry Jan Reedy | 800415e | 2018-06-11 14:14:32 -0400 | [diff] [blame] | 1182 | On Windows, a new API call tells Windows that tk scales for DPI. On Windows |
| 1183 | 8.1+ or 10, with DPI compatibility properties of the Python binary |
| 1184 | unchanged, and a monitor resolution greater than 96 DPI, this should |
| 1185 | make text and lines sharper. It should otherwise have no effect. |
| 1186 | (Contributed by Terry Jan Reedy in :issue:`33656`). |
| 1187 | |
Terry Jan Reedy | d9792a0 | 2016-06-13 00:41:53 -0400 | [diff] [blame] | 1188 | |
Brett Cannon | 696c35e | 2016-06-25 10:58:17 -0700 | [diff] [blame] | 1189 | importlib |
| 1190 | --------- |
| 1191 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1192 | Import now raises the new exception :exc:`ModuleNotFoundError` |
| 1193 | (subclass of :exc:`ImportError`) when it cannot find a module. Code |
| 1194 | that current checks for ``ImportError`` (in try-except) will still work. |
| 1195 | (Contributed by Eric Snow in :issue:`15767`.) |
| 1196 | |
Brett Cannon | 696c35e | 2016-06-25 10:58:17 -0700 | [diff] [blame] | 1197 | :class:`importlib.util.LazyLoader` now calls |
| 1198 | :meth:`~importlib.abc.Loader.create_module` on the wrapped loader, removing the |
| 1199 | restriction that :class:`importlib.machinery.BuiltinImporter` and |
| 1200 | :class:`importlib.machinery.ExtensionFileLoader` couldn't be used with |
| 1201 | :class:`importlib.util.LazyLoader`. |
| 1202 | |
Brett Cannon | 035a100 | 2016-09-07 18:39:18 -0700 | [diff] [blame] | 1203 | :func:`importlib.util.cache_from_source`, |
| 1204 | :func:`importlib.util.source_from_cache`, and |
| 1205 | :func:`importlib.util.spec_from_file_location` now accept a |
| 1206 | :term:`path-like object`. |
| 1207 | |
Brett Cannon | 696c35e | 2016-06-25 10:58:17 -0700 | [diff] [blame] | 1208 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1209 | inspect |
| 1210 | ------- |
| 1211 | |
| 1212 | The :func:`inspect.signature() <inspect.signature>` function now reports the |
| 1213 | implicit ``.0`` parameters generated by the compiler for comprehension and |
| 1214 | generator expression scopes as if they were positional-only parameters called |
| 1215 | ``implicit0``. (Contributed by Jelle Zijlstra in :issue:`19611`.) |
| 1216 | |
Nick Coghlan | 3c35fdb | 2016-12-02 20:29:57 +1000 | [diff] [blame] | 1217 | To reduce code churn when upgrading from Python 2.7 and the legacy |
| 1218 | :func:`inspect.getargspec` API, the previously documented deprecation of |
| 1219 | :func:`inspect.getfullargspec` has been reversed. While this function is |
| 1220 | convenient for single/source Python 2/3 code bases, the richer |
| 1221 | :func:`inspect.signature` interface remains the recommended approach for new |
| 1222 | code. (Contributed by Nick Coghlan in :issue:`27172`) |
| 1223 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1224 | |
Nick Coghlan | b161562 | 2016-09-10 20:16:18 +1000 | [diff] [blame] | 1225 | json |
| 1226 | ---- |
| 1227 | |
| 1228 | :func:`json.load` and :func:`json.loads` now support binary input. Encoded |
| 1229 | JSON should be represented using either UTF-8, UTF-16, or UTF-32. |
| 1230 | (Contributed by Serhiy Storchaka in :issue:`17909`.) |
| 1231 | |
| 1232 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1233 | logging |
| 1234 | ------- |
| 1235 | |
| 1236 | The new :meth:`WatchedFileHandler.reopenIfNeeded() <logging.handlers.WatchedFileHandler.reopenIfNeeded>` |
| 1237 | method has been added to add the ability to check if the log file needs to |
| 1238 | be reopened. |
| 1239 | (Contributed by Marian Horban in :issue:`24884`.) |
| 1240 | |
| 1241 | |
| 1242 | math |
| 1243 | ---- |
| 1244 | |
Serhiy Storchaka | dbaf746 | 2017-05-04 12:25:09 +0300 | [diff] [blame] | 1245 | The tau (*τ*) constant has been added to the :mod:`math` and :mod:`cmath` |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1246 | modules. |
| 1247 | (Contributed by Lisa Roach in :issue:`12345`, see :pep:`628` for details.) |
| 1248 | |
| 1249 | |
| 1250 | multiprocessing |
| 1251 | --------------- |
| 1252 | |
| 1253 | :ref:`Proxy Objects <multiprocessing-proxy_objects>` returned by |
| 1254 | :func:`multiprocessing.Manager` can now be nested. |
| 1255 | (Contributed by Davin Potts in :issue:`6766`.) |
| 1256 | |
| 1257 | |
Serhiy Storchaka | ffe96ae | 2016-02-11 13:21:30 +0200 | [diff] [blame] | 1258 | os |
| 1259 | -- |
| 1260 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1261 | See the summary of :ref:`PEP 519 <whatsnew36-pep519>` for details on how the |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1262 | :mod:`os` and :mod:`os.path` modules now support |
| 1263 | :term:`path-like objects <path-like object>`. |
| 1264 | |
Serhiy Storchaka | 3c38e06 | 2016-11-20 08:23:07 +0200 | [diff] [blame] | 1265 | :func:`~os.scandir` now supports :class:`bytes` paths on Windows. |
| 1266 | |
Serhiy Storchaka | ffe96ae | 2016-02-11 13:21:30 +0200 | [diff] [blame] | 1267 | A new :meth:`~os.scandir.close` method allows explicitly closing a |
| 1268 | :func:`~os.scandir` iterator. The :func:`~os.scandir` iterator now |
| 1269 | supports the :term:`context manager` protocol. If a :func:`scandir` |
| 1270 | iterator is neither exhausted nor explicitly closed a :exc:`ResourceWarning` |
| 1271 | will be emitted in its destructor. |
| 1272 | (Contributed by Serhiy Storchaka in :issue:`25994`.) |
| 1273 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 1274 | On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool |
| 1275 | is initialized to increase the security. See the :pep:`524` for the rationale. |
| 1276 | |
Victor Stinner | 9b1f474 | 2016-09-06 16:18:52 -0700 | [diff] [blame] | 1277 | The Linux ``getrandom()`` syscall (get random bytes) is now exposed as the new |
| 1278 | :func:`os.getrandom` function. |
| 1279 | (Contributed by Victor Stinner, part of the :pep:`524`) |
| 1280 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1281 | |
| 1282 | pathlib |
| 1283 | ------- |
| 1284 | |
| 1285 | :mod:`pathlib` now supports :term:`path-like objects <path-like object>`. |
| 1286 | (Contributed by Brett Cannon in :issue:`27186`.) |
| 1287 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1288 | See the summary of :ref:`PEP 519 <whatsnew36-pep519>` for details. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1289 | |
| 1290 | |
| 1291 | pdb |
| 1292 | --- |
| 1293 | |
| 1294 | The :class:`~pdb.Pdb` class constructor has a new optional *readrc* argument |
| 1295 | to control whether ``.pdbrc`` files should be read. |
Brett Cannon | 035a100 | 2016-09-07 18:39:18 -0700 | [diff] [blame] | 1296 | |
| 1297 | |
Serhiy Storchaka | 0d554d7 | 2015-10-10 22:42:18 +0300 | [diff] [blame] | 1298 | pickle |
| 1299 | ------ |
| 1300 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1301 | Objects that need ``__new__`` called with keyword arguments can now be pickled |
Serhiy Storchaka | 0d554d7 | 2015-10-10 22:42:18 +0300 | [diff] [blame] | 1302 | using :ref:`pickle protocols <pickle-protocols>` older than protocol version 4. |
| 1303 | Protocol version 4 already supports this case. (Contributed by Serhiy |
| 1304 | Storchaka in :issue:`24164`.) |
| 1305 | |
| 1306 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1307 | pickletools |
| 1308 | ----------- |
| 1309 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1310 | :func:`pickletools.dis()` now outputs the implicit memo index for the |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1311 | ``MEMOIZE`` opcode. |
| 1312 | (Contributed by Serhiy Storchaka in :issue:`25382`.) |
| 1313 | |
| 1314 | |
| 1315 | pydoc |
| 1316 | ----- |
| 1317 | |
| 1318 | The :mod:`pydoc` module has learned to respect the ``MANPAGER`` |
| 1319 | environment variable. |
| 1320 | (Contributed by Matthias Klose in :issue:`8637`.) |
| 1321 | |
| 1322 | :func:`help` and :mod:`pydoc` can now list named tuple fields in the |
| 1323 | order they were defined rather than alphabetically. |
| 1324 | (Contributed by Raymond Hettinger in :issue:`24879`.) |
| 1325 | |
| 1326 | |
| 1327 | random |
| 1328 | ------- |
| 1329 | |
| 1330 | The new :func:`~random.choices` function returns a list of elements of |
| 1331 | specified size from the given population with optional weights. |
| 1332 | (Contributed by Raymond Hettinger in :issue:`18844`.) |
| 1333 | |
| 1334 | |
Serhiy Storchaka | be9a4e5 | 2016-09-10 00:57:55 +0300 | [diff] [blame] | 1335 | re |
| 1336 | -- |
| 1337 | |
| 1338 | Added support of modifier spans in regular expressions. Examples: |
| 1339 | ``'(?i:p)ython'`` matches ``'python'`` and ``'Python'``, but not ``'PYTHON'``; |
| 1340 | ``'(?i)g(?-i:v)r'`` matches ``'GvR'`` and ``'gvr'``, but not ``'GVR'``. |
| 1341 | (Contributed by Serhiy Storchaka in :issue:`433028`.) |
| 1342 | |
Eric V. Smith | b569086 | 2016-09-11 09:50:47 -0400 | [diff] [blame] | 1343 | Match object groups can be accessed by ``__getitem__``, which is |
| 1344 | equivalent to ``group()``. So ``mo['name']`` is now equivalent to |
| 1345 | ``mo.group('name')``. (Contributed by Eric Smith in :issue:`24454`.) |
| 1346 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1347 | :class:`~re.Match` objects now support |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1348 | :meth:`index-like objects <object.__index__>` as group |
| 1349 | indices. |
| 1350 | (Contributed by Jeroen Demeyer and Xiang Zhang in :issue:`27177`.) |
| 1351 | |
Serhiy Storchaka | be9a4e5 | 2016-09-10 00:57:55 +0300 | [diff] [blame] | 1352 | |
Martin Panter | f0dbf7a | 2016-05-15 01:26:25 +0000 | [diff] [blame] | 1353 | readline |
| 1354 | -------- |
| 1355 | |
| 1356 | Added :func:`~readline.set_auto_history` to enable or disable |
| 1357 | automatic addition of input to the history list. (Contributed by |
| 1358 | Tyler Crompton in :issue:`26870`.) |
| 1359 | |
| 1360 | |
Martin Panter | fad4b60 | 2015-11-14 01:29:17 +0000 | [diff] [blame] | 1361 | rlcompleter |
| 1362 | ----------- |
Serhiy Storchaka | ab82422 | 2015-09-27 13:43:50 +0300 | [diff] [blame] | 1363 | |
| 1364 | Private and special attribute names now are omitted unless the prefix starts |
Martin Panter | fad4b60 | 2015-11-14 01:29:17 +0000 | [diff] [blame] | 1365 | with underscores. A space or a colon is added after some completed keywords. |
Serhiy Storchaka | ab82422 | 2015-09-27 13:43:50 +0300 | [diff] [blame] | 1366 | (Contributed by Serhiy Storchaka in :issue:`25011` and :issue:`25209`.) |
| 1367 | |
| 1368 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1369 | shlex |
| 1370 | ----- |
| 1371 | |
| 1372 | The :class:`~shlex.shlex` has much |
| 1373 | :ref:`improved shell compatibility <improved-shell-compatibility>` |
| 1374 | through the new *punctuation_chars* argument to control which characters |
| 1375 | are treated as punctuation. |
| 1376 | (Contributed by Vinay Sajip in :issue:`1521950`.) |
| 1377 | |
| 1378 | |
Brett Cannon | 5f0507d | 2016-04-08 15:04:28 -0700 | [diff] [blame] | 1379 | site |
| 1380 | ---- |
| 1381 | |
| 1382 | When specifying paths to add to :attr:`sys.path` in a `.pth` file, |
| 1383 | you may now specify file paths on top of directories (e.g. zip files). |
| 1384 | (Contributed by Wolfgang Langner in :issue:`26587`). |
| 1385 | |
| 1386 | |
Berker Peksag | e0b70cd | 2016-06-14 15:25:36 +0300 | [diff] [blame] | 1387 | sqlite3 |
| 1388 | ------- |
| 1389 | |
Berker Peksag | b84fd04 | 2016-09-07 01:07:06 +0300 | [diff] [blame] | 1390 | :attr:`sqlite3.Cursor.lastrowid` now supports the ``REPLACE`` statement. |
| 1391 | (Contributed by Alex LordThorsen in :issue:`16864`.) |
Berker Peksag | e0b70cd | 2016-06-14 15:25:36 +0300 | [diff] [blame] | 1392 | |
| 1393 | |
Steve Dower | ea93ac0 | 2016-06-17 12:52:18 -0700 | [diff] [blame] | 1394 | socket |
| 1395 | ------ |
| 1396 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1397 | The :func:`~socket.socket.ioctl` function now supports the |
| 1398 | :data:`~socket.SIO_LOOPBACK_FAST_PATH` control code. |
Steve Dower | ea93ac0 | 2016-06-17 12:52:18 -0700 | [diff] [blame] | 1399 | (Contributed by Daniel Stokes in :issue:`26536`.) |
| 1400 | |
R David Murray | bdfa0eb | 2016-08-23 21:12:40 -0400 | [diff] [blame] | 1401 | The :meth:`~socket.socket.getsockopt` constants ``SO_DOMAIN``, |
| 1402 | ``SO_PROTOCOL``, ``SO_PEERSEC``, and ``SO_PASSSEC`` are now supported. |
| 1403 | (Contributed by Christian Heimes in :issue:`26907`.) |
| 1404 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1405 | The :meth:`~socket.socket.setsockopt` now supports the |
| 1406 | ``setsockopt(level, optname, None, optlen: int)`` form. |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1407 | (Contributed by Christian Heimes in :issue:`27744`.) |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1408 | |
Christian Heimes | c4d2e50 | 2016-09-12 01:14:35 +0200 | [diff] [blame] | 1409 | The socket module now supports the address family |
| 1410 | :data:`~socket.AF_ALG` to interface with Linux Kernel crypto API. ``ALG_*``, |
| 1411 | ``SOL_ALG`` and :meth:`~socket.socket.sendmsg_afalg` were added. |
| 1412 | (Contributed by Christian Heimes in :issue:`27744` with support from |
| 1413 | Victor Stinner.) |
Steve Dower | ea93ac0 | 2016-06-17 12:52:18 -0700 | [diff] [blame] | 1414 | |
Victor Stinner | 01f5ae7 | 2017-01-23 12:30:00 +0100 | [diff] [blame] | 1415 | New Linux constants ``TCP_USER_TIMEOUT`` and ``TCP_CONGESTION`` were added. |
| 1416 | (Contributed by Omar Sandoval, issue:`26273`). |
| 1417 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1418 | |
Martin Panter | 0cab9c1 | 2016-04-13 00:36:52 +0000 | [diff] [blame] | 1419 | socketserver |
| 1420 | ------------ |
| 1421 | |
| 1422 | Servers based on the :mod:`socketserver` module, including those |
| 1423 | defined in :mod:`http.server`, :mod:`xmlrpc.server` and |
| 1424 | :mod:`wsgiref.simple_server`, now support the :term:`context manager` |
| 1425 | protocol. |
| 1426 | (Contributed by Aviv Palivoda in :issue:`26404`.) |
| 1427 | |
Martin Panter | 34eeed4 | 2016-06-29 10:12:22 +0000 | [diff] [blame] | 1428 | The :attr:`~socketserver.StreamRequestHandler.wfile` attribute of |
| 1429 | :class:`~socketserver.StreamRequestHandler` classes now implements |
| 1430 | the :class:`io.BufferedIOBase` writable interface. In particular, |
| 1431 | calling :meth:`~io.BufferedIOBase.write` is now guaranteed to send the |
| 1432 | data in full. (Contributed by Martin Panter in :issue:`26721`.) |
| 1433 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1434 | |
Christian Heimes | c4d2e50 | 2016-09-12 01:14:35 +0200 | [diff] [blame] | 1435 | ssl |
| 1436 | --- |
| 1437 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1438 | :mod:`ssl` supports OpenSSL 1.1.0. The minimum recommend version is 1.0.2. |
Christian Heimes | c4d2e50 | 2016-09-12 01:14:35 +0200 | [diff] [blame] | 1439 | (Contributed by Christian Heimes in :issue:`26470`.) |
| 1440 | |
| 1441 | 3DES has been removed from the default cipher suites and ChaCha20 Poly1305 |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1442 | cipher suites have been added. |
Christian Heimes | c4d2e50 | 2016-09-12 01:14:35 +0200 | [diff] [blame] | 1443 | (Contributed by Christian Heimes in :issue:`27850` and :issue:`27766`.) |
| 1444 | |
| 1445 | :class:`~ssl.SSLContext` has better default configuration for options |
| 1446 | and ciphers. |
| 1447 | (Contributed by Christian Heimes in :issue:`28043`.) |
| 1448 | |
| 1449 | SSL session can be copied from one client-side connection to another |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1450 | with the new :class:`~ssl.SSLSession` class. TLS session resumption can |
| 1451 | speed up the initial handshake, reduce latency and improve performance |
Christian Heimes | c4d2e50 | 2016-09-12 01:14:35 +0200 | [diff] [blame] | 1452 | (Contributed by Christian Heimes in :issue:`19500` based on a draft by |
| 1453 | Alex Warhawk.) |
| 1454 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1455 | The new :meth:`~ssl.SSLContext.get_ciphers` method can be used to |
| 1456 | get a list of enabled ciphers in order of cipher priority. |
| 1457 | |
Christian Heimes | c4d2e50 | 2016-09-12 01:14:35 +0200 | [diff] [blame] | 1458 | All constants and flags have been converted to :class:`~enum.IntEnum` and |
| 1459 | :class:`~enum.IntFlags`. |
| 1460 | (Contributed by Christian Heimes in :issue:`28025`.) |
| 1461 | |
| 1462 | Server and client-side specific TLS protocols for :class:`~ssl.SSLContext` |
| 1463 | were added. |
| 1464 | (Contributed by Christian Heimes in :issue:`28085`.) |
| 1465 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1466 | |
| 1467 | statistics |
| 1468 | ---------- |
| 1469 | |
| 1470 | A new :func:`~statistics.harmonic_mean` function has been added. |
| 1471 | (Contributed by Steven D'Aprano in :issue:`27181`.) |
| 1472 | |
| 1473 | |
| 1474 | struct |
| 1475 | ------ |
| 1476 | |
| 1477 | :mod:`struct` now supports IEEE 754 half-precision floats via the ``'e'`` |
| 1478 | format specifier. |
| 1479 | (Contributed by Eli Stevens, Mark Dickinson in :issue:`11734`.) |
| 1480 | |
| 1481 | |
Victor Stinner | 5a48e21 | 2016-05-20 12:11:15 +0200 | [diff] [blame] | 1482 | subprocess |
| 1483 | ---------- |
| 1484 | |
| 1485 | :class:`subprocess.Popen` destructor now emits a :exc:`ResourceWarning` warning |
| 1486 | if the child process is still running. Use the context manager protocol (``with |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1487 | proc: ...``) or explicitly call the :meth:`~subprocess.Popen.wait` method to |
| 1488 | read the exit status of the child process. (Contributed by Victor Stinner in |
| 1489 | :issue:`26741`.) |
Victor Stinner | 5a48e21 | 2016-05-20 12:11:15 +0200 | [diff] [blame] | 1490 | |
Steve Dower | 050acae | 2016-09-06 20:16:17 -0700 | [diff] [blame] | 1491 | The :class:`subprocess.Popen` constructor and all functions that pass arguments |
| 1492 | through to it now accept *encoding* and *errors* arguments. Specifying either |
| 1493 | of these will enable text mode for the *stdin*, *stdout* and *stderr* streams. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1494 | (Contributed by Steve Dower in :issue:`6135`.) |
| 1495 | |
| 1496 | |
| 1497 | sys |
| 1498 | --- |
| 1499 | |
| 1500 | The new :func:`~sys.getfilesystemencodeerrors` function returns the name of |
| 1501 | the error mode used to convert between Unicode filenames and bytes filenames. |
| 1502 | (Contributed by Steve Dower in :issue:`27781`.) |
| 1503 | |
| 1504 | On Windows the return value of the :func:`~sys.getwindowsversion` function |
| 1505 | now includes the *platform_version* field which contains the accurate major |
| 1506 | version, minor version and build number of the current operating system, |
| 1507 | rather than the version that is being emulated for the process |
| 1508 | (Contributed by Steve Dower in :issue:`27932`.) |
| 1509 | |
Victor Stinner | 5a48e21 | 2016-05-20 12:11:15 +0200 | [diff] [blame] | 1510 | |
R David Murray | 4f09806 | 2015-11-28 12:24:52 -0500 | [diff] [blame] | 1511 | telnetlib |
| 1512 | --------- |
| 1513 | |
| 1514 | :class:`~telnetlib.Telnet` is now a context manager (contributed by |
| 1515 | Stéphane Wirtel in :issue:`25485`). |
| 1516 | |
| 1517 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1518 | time |
| 1519 | ---- |
| 1520 | |
| 1521 | The :class:`~time.struct_time` attributes :attr:`tm_gmtoff` and |
| 1522 | :attr:`tm_zone` are now available on all platforms. |
| 1523 | |
| 1524 | |
| 1525 | timeit |
| 1526 | ------ |
| 1527 | |
| 1528 | The new :meth:`Timer.autorange() <timeit.Timer.autorange>` convenience |
| 1529 | method has been added to call :meth:`Timer.timeit() <timeit.Timer.timeit>` |
| 1530 | repeatedly so that the total run time is greater or equal to 200 milliseconds. |
| 1531 | (Contributed by Steven D'Aprano in :issue:`6422`.) |
| 1532 | |
| 1533 | :mod:`timeit` now warns when there is substantial (4x) variance |
| 1534 | between best and worst times. |
| 1535 | (Contributed by Serhiy Storchaka in :issue:`23552`.) |
| 1536 | |
| 1537 | |
Serhiy Storchaka | 8122174 | 2016-06-26 09:46:57 +0300 | [diff] [blame] | 1538 | tkinter |
| 1539 | ------- |
| 1540 | |
| 1541 | Added methods :meth:`~tkinter.Variable.trace_add`, |
| 1542 | :meth:`~tkinter.Variable.trace_remove` and :meth:`~tkinter.Variable.trace_info` |
| 1543 | in the :class:`tkinter.Variable` class. They replace old methods |
| 1544 | :meth:`~tkinter.Variable.trace_variable`, :meth:`~tkinter.Variable.trace`, |
| 1545 | :meth:`~tkinter.Variable.trace_vdelete` and |
| 1546 | :meth:`~tkinter.Variable.trace_vinfo` that use obsolete Tcl commands and might |
| 1547 | not work in future versions of Tcl. |
| 1548 | (Contributed by Serhiy Storchaka in :issue:`22115`). |
| 1549 | |
| 1550 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1551 | .. _whatsnew36-traceback: |
Nick Coghlan | 02d03df | 2016-08-16 10:58:14 +1000 | [diff] [blame] | 1552 | |
Nick Coghlan | d003423 | 2016-08-15 13:11:34 +1000 | [diff] [blame] | 1553 | traceback |
| 1554 | --------- |
| 1555 | |
Nick Coghlan | 02d03df | 2016-08-16 10:58:14 +1000 | [diff] [blame] | 1556 | Both the traceback module and the interpreter's builtin exception display now |
| 1557 | abbreviate long sequences of repeated lines in tracebacks as shown in the |
| 1558 | following example:: |
| 1559 | |
| 1560 | >>> def f(): f() |
| 1561 | ... |
| 1562 | >>> f() |
| 1563 | Traceback (most recent call last): |
| 1564 | File "<stdin>", line 1, in <module> |
| 1565 | File "<stdin>", line 1, in f |
| 1566 | File "<stdin>", line 1, in f |
| 1567 | File "<stdin>", line 1, in f |
| 1568 | [Previous line repeated 995 more times] |
| 1569 | RecursionError: maximum recursion depth exceeded |
| 1570 | |
Nick Coghlan | d003423 | 2016-08-15 13:11:34 +1000 | [diff] [blame] | 1571 | (Contributed by Emanuel Barry in :issue:`26823`.) |
| 1572 | |
| 1573 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1574 | tracemalloc |
| 1575 | ----------- |
| 1576 | |
| 1577 | The :mod:`tracemalloc` module now supports tracing memory allocations in |
| 1578 | multiple different address spaces. |
| 1579 | |
| 1580 | The new :class:`~tracemalloc.DomainFilter` filter class has been added |
| 1581 | to filter block traces by their address space (domain). |
| 1582 | |
| 1583 | (Contributed by Victor Stinner in :issue:`26588`.) |
| 1584 | |
| 1585 | |
| 1586 | .. _whatsnew36-typing: |
| 1587 | |
Brett Cannon | 9e080e0 | 2016-04-08 12:15:27 -0700 | [diff] [blame] | 1588 | typing |
| 1589 | ------ |
| 1590 | |
Ned Deily | 67c1cb2 | 2017-01-20 10:13:23 -0500 | [diff] [blame] | 1591 | Since the :mod:`typing` module is :term:`provisional <provisional api>`, |
| 1592 | all changes introduced in Python 3.6 have also been |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1593 | backported to Python 3.5.x. |
| 1594 | |
Yury Selivanov | 6bf87d3 | 2016-11-14 14:49:18 -0500 | [diff] [blame] | 1595 | The :mod:`typing` module has a much improved support for generic type |
| 1596 | aliases. For example ``Dict[str, Tuple[S, T]]`` is now a valid |
| 1597 | type annotation. |
| 1598 | (Contributed by Guido van Rossum in `Github #195 |
| 1599 | <https://github.com/python/typing/pull/195>`_.) |
| 1600 | |
Brett Cannon | 9e080e0 | 2016-04-08 12:15:27 -0700 | [diff] [blame] | 1601 | The :class:`typing.ContextManager` class has been added for |
| 1602 | representing :class:`contextlib.AbstractContextManager`. |
| 1603 | (Contributed by Brett Cannon in :issue:`25609`.) |
| 1604 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1605 | The :class:`typing.Collection` class has been added for |
| 1606 | representing :class:`collections.abc.Collection`. |
| 1607 | (Contributed by Ivan Levkivskyi in :issue:`27598`.) |
| 1608 | |
| 1609 | The :const:`typing.ClassVar` type construct has been added to |
| 1610 | mark class variables. As introduced in :pep:`526`, a variable annotation |
| 1611 | wrapped in ClassVar indicates that a given attribute is intended to be used as |
| 1612 | a class variable and should not be set on instances of that class. |
| 1613 | (Contributed by Ivan Levkivskyi in `Github #280 |
Sanyam Khurana | 338cd83 | 2018-01-20 05:55:37 +0530 | [diff] [blame] | 1614 | <https://github.com/python/typing/pull/280>`_.) |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1615 | |
| 1616 | A new :const:`~typing.TYPE_CHECKING` constant that is assumed to be |
| 1617 | ``True`` by the static type chekers, but is ``False`` at runtime. |
| 1618 | (Contributed by Guido van Rossum in `Github #230 |
| 1619 | <https://github.com/python/typing/issues/230>`_.) |
| 1620 | |
| 1621 | A new :func:`~typing.NewType` helper function has been added to create |
| 1622 | lightweight distinct types for annotations:: |
| 1623 | |
| 1624 | from typing import NewType |
| 1625 | |
| 1626 | UserId = NewType('UserId', int) |
| 1627 | some_id = UserId(524313) |
| 1628 | |
| 1629 | The static type checker will treat the new type as if it were a subclass |
| 1630 | of the original type. (Contributed by Ivan Levkivskyi in `Github #189 |
| 1631 | <https://github.com/python/typing/issues/189>`_.) |
| 1632 | |
Brett Cannon | 9e080e0 | 2016-04-08 12:15:27 -0700 | [diff] [blame] | 1633 | |
Benjamin Peterson | 6775231 | 2016-09-14 23:53:47 -0700 | [diff] [blame] | 1634 | unicodedata |
| 1635 | ----------- |
| 1636 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1637 | The :mod:`unicodedata` module now uses data from `Unicode 9.0.0 |
| 1638 | <http://unicode.org/versions/Unicode9.0.0/>`_. |
| 1639 | (Contributed by Benjamin Peterson.) |
Benjamin Peterson | 6775231 | 2016-09-14 23:53:47 -0700 | [diff] [blame] | 1640 | |
| 1641 | |
Victor Stinner | 2c2a4e6 | 2016-03-11 22:17:48 +0100 | [diff] [blame] | 1642 | unittest.mock |
| 1643 | ------------- |
| 1644 | |
| 1645 | The :class:`~unittest.mock.Mock` class has the following improvements: |
| 1646 | |
| 1647 | * Two new methods, :meth:`Mock.assert_called() |
| 1648 | <unittest.mock.Mock.assert_called>` and :meth:`Mock.assert_called_once() |
| 1649 | <unittest.mock.Mock.assert_called_once>` to check if the mock object |
| 1650 | was called. |
| 1651 | (Contributed by Amit Saha in :issue:`26323`.) |
| 1652 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1653 | * The :meth:`Mock.reset_mock() <unittest.mock.Mock.reset_mock>` method |
| 1654 | now has two optional keyword only arguments: *return_value* and |
| 1655 | *side_effect*. |
| 1656 | (Contributed by Kushal Das in :issue:`21271`.) |
| 1657 | |
Victor Stinner | 2c2a4e6 | 2016-03-11 22:17:48 +0100 | [diff] [blame] | 1658 | |
Martin Panter | 3c0d0ba | 2016-08-24 06:33:33 +0000 | [diff] [blame] | 1659 | urllib.request |
| 1660 | -------------- |
| 1661 | |
Martin Panter | ef91bb2 | 2016-08-27 01:39:26 +0000 | [diff] [blame] | 1662 | If a HTTP request has a file or iterable body (other than a |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1663 | bytes object) but no ``Content-Length`` header, rather than |
Martin Panter | 3c0d0ba | 2016-08-24 06:33:33 +0000 | [diff] [blame] | 1664 | throwing an error, :class:`~urllib.request.AbstractHTTPHandler` now |
| 1665 | falls back to use chunked transfer encoding. |
| 1666 | (Contributed by Demian Brecht and Rolf Krahl in :issue:`12319`.) |
| 1667 | |
| 1668 | |
Berker Peksag | 960e848 | 2015-10-08 12:27:06 +0300 | [diff] [blame] | 1669 | urllib.robotparser |
| 1670 | ------------------ |
| 1671 | |
Martin Panter | fad4b60 | 2015-11-14 01:29:17 +0000 | [diff] [blame] | 1672 | :class:`~urllib.robotparser.RobotFileParser` now supports the ``Crawl-delay`` and |
Berker Peksag | 960e848 | 2015-10-08 12:27:06 +0300 | [diff] [blame] | 1673 | ``Request-rate`` extensions. |
| 1674 | (Contributed by Nikolay Bogoychev in :issue:`16099`.) |
| 1675 | |
| 1676 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1677 | venv |
| 1678 | ---- |
| 1679 | |
| 1680 | :mod:`venv` accepts a new parameter ``--prompt``. This parameter provides an |
| 1681 | alternative prefix for the virtual environment. (Proposed by Łukasz Balcerzak |
| 1682 | and ported to 3.6 by Stéphane Wirtel in :issue:`22829`.) |
| 1683 | |
| 1684 | |
Victor Stinner | 914cde8 | 2016-03-19 01:03:51 +0100 | [diff] [blame] | 1685 | warnings |
| 1686 | -------- |
| 1687 | |
| 1688 | A new optional *source* parameter has been added to the |
| 1689 | :func:`warnings.warn_explicit` function: the destroyed object which emitted a |
| 1690 | :exc:`ResourceWarning`. A *source* attribute has also been added to |
| 1691 | :class:`warnings.WarningMessage` (contributed by Victor Stinner in |
| 1692 | :issue:`26568` and :issue:`26567`). |
| 1693 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1694 | When a :exc:`ResourceWarning` warning is logged, the :mod:`tracemalloc` module is now |
| 1695 | used to try to retrieve the traceback where the destroyed object was allocated. |
Victor Stinner | 914cde8 | 2016-03-19 01:03:51 +0100 | [diff] [blame] | 1696 | |
| 1697 | Example with the script ``example.py``:: |
| 1698 | |
Victor Stinner | ee803a8 | 2016-03-19 10:33:25 +0100 | [diff] [blame] | 1699 | import warnings |
Victor Stinner | 914cde8 | 2016-03-19 01:03:51 +0100 | [diff] [blame] | 1700 | |
Victor Stinner | ee803a8 | 2016-03-19 10:33:25 +0100 | [diff] [blame] | 1701 | def func(): |
| 1702 | return open(__file__) |
| 1703 | |
| 1704 | f = func() |
| 1705 | f = None |
Victor Stinner | 914cde8 | 2016-03-19 01:03:51 +0100 | [diff] [blame] | 1706 | |
| 1707 | Output of the command ``python3.6 -Wd -X tracemalloc=5 example.py``:: |
| 1708 | |
Victor Stinner | ee803a8 | 2016-03-19 10:33:25 +0100 | [diff] [blame] | 1709 | example.py:7: ResourceWarning: unclosed file <_io.TextIOWrapper name='example.py' mode='r' encoding='UTF-8'> |
Victor Stinner | 914cde8 | 2016-03-19 01:03:51 +0100 | [diff] [blame] | 1710 | f = None |
| 1711 | Object allocated at (most recent call first): |
Victor Stinner | ee803a8 | 2016-03-19 10:33:25 +0100 | [diff] [blame] | 1712 | File "example.py", lineno 4 |
| 1713 | return open(__file__) |
| 1714 | File "example.py", lineno 6 |
| 1715 | f = func() |
Victor Stinner | 914cde8 | 2016-03-19 01:03:51 +0100 | [diff] [blame] | 1716 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1717 | The "Object allocated at" traceback is new and is only displayed if |
Victor Stinner | ee803a8 | 2016-03-19 10:33:25 +0100 | [diff] [blame] | 1718 | :mod:`tracemalloc` is tracing Python memory allocations and if the |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1719 | :mod:`warnings` module was already imported. |
Victor Stinner | 914cde8 | 2016-03-19 01:03:51 +0100 | [diff] [blame] | 1720 | |
| 1721 | |
Steve Dower | 80ac11d | 2016-05-24 15:42:04 -0700 | [diff] [blame] | 1722 | winreg |
| 1723 | ------ |
| 1724 | |
Steve Dower | 4d4bc42 | 2016-05-25 11:26:07 -0700 | [diff] [blame] | 1725 | Added the 64-bit integer type :data:`REG_QWORD <winreg.REG_QWORD>`. |
Steve Dower | 80ac11d | 2016-05-24 15:42:04 -0700 | [diff] [blame] | 1726 | (Contributed by Clement Rouault in :issue:`23026`.) |
| 1727 | |
| 1728 | |
Zachary Ware | c401881 | 2016-09-06 16:32:43 -0500 | [diff] [blame] | 1729 | winsound |
| 1730 | -------- |
| 1731 | |
| 1732 | Allowed keyword arguments to be passed to :func:`Beep <winsound.Beep>`, |
| 1733 | :func:`MessageBeep <winsound.MessageBeep>`, and :func:`PlaySound |
| 1734 | <winsound.PlaySound>` (:issue:`27982`). |
| 1735 | |
| 1736 | |
Serhiy Storchaka | 352601c | 2016-09-11 11:23:38 +0300 | [diff] [blame] | 1737 | xmlrpc.client |
| 1738 | ------------- |
| 1739 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1740 | The :mod:`xmlrpc.client` module now supports unmarshalling |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1741 | additional data types used by the Apache XML-RPC implementation |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1742 | for numerics and ``None``. |
Serhiy Storchaka | 352601c | 2016-09-11 11:23:38 +0300 | [diff] [blame] | 1743 | (Contributed by Serhiy Storchaka in :issue:`26885`.) |
| 1744 | |
| 1745 | |
Serhiy Storchaka | 503f908 | 2016-02-08 00:02:25 +0200 | [diff] [blame] | 1746 | zipfile |
| 1747 | ------- |
| 1748 | |
| 1749 | A new :meth:`ZipInfo.from_file() <zipfile.ZipInfo.from_file>` class method |
Martin Panter | 288ed03 | 2016-02-10 05:45:55 +0000 | [diff] [blame] | 1750 | allows making a :class:`~zipfile.ZipInfo` instance from a filesystem file. |
Serhiy Storchaka | 503f908 | 2016-02-08 00:02:25 +0200 | [diff] [blame] | 1751 | A new :meth:`ZipInfo.is_dir() <zipfile.ZipInfo.is_dir>` method can be used |
| 1752 | to check if the :class:`~zipfile.ZipInfo` instance represents a directory. |
| 1753 | (Contributed by Thomas Kluyver in :issue:`26039`.) |
| 1754 | |
Serhiy Storchaka | 18ee29d | 2016-05-13 13:52:49 +0300 | [diff] [blame] | 1755 | The :meth:`ZipFile.open() <zipfile.ZipFile.open>` method can now be used to |
| 1756 | write data into a ZIP file, as well as for extracting data. |
| 1757 | (Contributed by Thomas Kluyver in :issue:`26039`.) |
| 1758 | |
Serhiy Storchaka | 503f908 | 2016-02-08 00:02:25 +0200 | [diff] [blame] | 1759 | |
Martin Panter | 1fe0d13 | 2016-02-10 10:06:36 +0000 | [diff] [blame] | 1760 | zlib |
| 1761 | ---- |
| 1762 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1763 | The :func:`~zlib.compress` and :func:`~zlib.decompress` functions now accept |
| 1764 | keyword arguments. |
| 1765 | (Contributed by Aviv Palivoda in :issue:`26243` and |
| 1766 | Xiang Zhang in :issue:`16764` respectively.) |
Serhiy Storchaka | b275210 | 2016-04-27 23:13:46 +0300 | [diff] [blame] | 1767 | |
| 1768 | |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 1769 | Optimizations |
| 1770 | ============= |
| 1771 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1772 | * The Python interpreter now uses a 16-bit wordcode instead of bytecode which |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1773 | made a number of opcode optimizations possible. |
| 1774 | (Contributed by Demur Rumed with input and reviews from |
| 1775 | Serhiy Storchaka and Victor Stinner in :issue:`26647` and :issue:`28050`.) |
| 1776 | |
Yury Selivanov | 1217470 | 2016-12-15 17:56:43 -0500 | [diff] [blame] | 1777 | * The :class:`asyncio.Future` class now has an optimized C implementation. |
| 1778 | (Contributed by Yury Selivanov and INADA Naoki in :issue:`26081`.) |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1779 | |
Yury Selivanov | 1217470 | 2016-12-15 17:56:43 -0500 | [diff] [blame] | 1780 | * The :class:`asyncio.Task` class now has an optimized |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1781 | C implementation. (Contributed by Yury Selivanov in :issue:`28544`.) |
| 1782 | |
Yury Selivanov | 6bf87d3 | 2016-11-14 14:49:18 -0500 | [diff] [blame] | 1783 | * Various implementation improvements in the :mod:`typing` module |
| 1784 | (such as caching of generic types) allow up to 30 times performance |
| 1785 | improvements and reduced memory footprint. |
| 1786 | |
Martin Panter | fad4b60 | 2015-11-14 01:29:17 +0000 | [diff] [blame] | 1787 | * The ASCII decoder is now up to 60 times as fast for error handlers |
Victor Stinner | ebcf9ed | 2015-10-14 10:10:00 +0200 | [diff] [blame] | 1788 | ``surrogateescape``, ``ignore`` and ``replace`` (Contributed |
| 1789 | by Victor Stinner in :issue:`24870`). |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 1790 | |
Terry Jan Reedy | 6dc9ce1 | 2015-10-20 01:07:53 -0400 | [diff] [blame] | 1791 | * The ASCII and the Latin1 encoders are now up to 3 times as fast for the |
Yury Selivanov | 6bf87d3 | 2016-11-14 14:49:18 -0500 | [diff] [blame] | 1792 | error handler ``surrogateescape`` |
| 1793 | (Contributed by Victor Stinner in :issue:`25227`). |
Victor Stinner | c3713e9 | 2015-09-29 12:32:13 +0200 | [diff] [blame] | 1794 | |
Martin Panter | fad4b60 | 2015-11-14 01:29:17 +0000 | [diff] [blame] | 1795 | * The UTF-8 encoder is now up to 75 times as fast for error handlers |
Victor Stinner | ebcf9ed | 2015-10-14 10:10:00 +0200 | [diff] [blame] | 1796 | ``ignore``, ``replace``, ``surrogateescape``, ``surrogatepass`` (Contributed |
| 1797 | by Victor Stinner in :issue:`25267`). |
Victor Stinner | 01ada39 | 2015-10-01 21:54:51 +0200 | [diff] [blame] | 1798 | |
Martin Panter | fad4b60 | 2015-11-14 01:29:17 +0000 | [diff] [blame] | 1799 | * The UTF-8 decoder is now up to 15 times as fast for error handlers |
Victor Stinner | ebcf9ed | 2015-10-14 10:10:00 +0200 | [diff] [blame] | 1800 | ``ignore``, ``replace`` and ``surrogateescape`` (Contributed |
| 1801 | by Victor Stinner in :issue:`25301`). |
| 1802 | |
| 1803 | * ``bytes % args`` is now up to 2 times faster. (Contributed by Victor Stinner |
| 1804 | in :issue:`25349`). |
| 1805 | |
| 1806 | * ``bytearray % args`` is now between 2.5 and 5 times faster. (Contributed by |
| 1807 | Victor Stinner in :issue:`25399`). |
Victor Stinner | 1d65d91 | 2015-10-05 13:43:50 +0200 | [diff] [blame] | 1808 | |
Victor Stinner | 2bf8993 | 2015-10-14 11:25:33 +0200 | [diff] [blame] | 1809 | * Optimize :meth:`bytes.fromhex` and :meth:`bytearray.fromhex`: they are now |
| 1810 | between 2x and 3.5x faster. (Contributed by Victor Stinner in :issue:`25401`). |
| 1811 | |
Victor Stinner | fac3956 | 2016-03-21 10:38:58 +0100 | [diff] [blame] | 1812 | * Optimize ``bytes.replace(b'', b'.')`` and ``bytearray.replace(b'', b'.')``: |
| 1813 | up to 80% faster. (Contributed by Josh Snider in :issue:`26574`). |
| 1814 | |
Victor Stinner | 8153ac8 | 2016-04-24 22:33:26 +0200 | [diff] [blame] | 1815 | * Allocator functions of the :c:func:`PyMem_Malloc` domain |
| 1816 | (:c:data:`PYMEM_DOMAIN_MEM`) now use the :ref:`pymalloc memory allocator |
| 1817 | <pymalloc>` instead of :c:func:`malloc` function of the C library. The |
| 1818 | pymalloc allocator is optimized for objects smaller or equal to 512 bytes |
| 1819 | with a short lifetime, and use :c:func:`malloc` for larger memory blocks. |
| 1820 | (Contributed by Victor Stinner in :issue:`26249`). |
| 1821 | |
Victor Stinner | 19ed27e | 2016-05-20 11:42:37 +0200 | [diff] [blame] | 1822 | * :func:`pickle.load` and :func:`pickle.loads` are now up to 10% faster when |
| 1823 | deserializing many small objects (Contributed by Victor Stinner in |
| 1824 | :issue:`27056`). |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 1825 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1826 | * Passing :term:`keyword arguments <keyword argument>` to a function has an |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1827 | overhead in comparison with passing :term:`positional arguments |
| 1828 | <positional argument>`. Now in extension functions implemented with using |
| 1829 | Argument Clinic this overhead is significantly decreased. |
| 1830 | (Contributed by Serhiy Storchaka in :issue:`27574`). |
| 1831 | |
Serhiy Storchaka | 28ab634 | 2016-09-06 22:33:41 +0300 | [diff] [blame] | 1832 | * Optimized :func:`~glob.glob` and :func:`~glob.iglob` functions in the |
| 1833 | :mod:`glob` module; they are now about 3--6 times faster. |
| 1834 | (Contributed by Serhiy Storchaka in :issue:`25596`). |
| 1835 | |
Serhiy Storchaka | 680cb15 | 2016-09-07 10:58:05 +0300 | [diff] [blame] | 1836 | * Optimized globbing in :mod:`pathlib` by using :func:`os.scandir`; |
| 1837 | it is now about 1.5--4 times faster. |
| 1838 | (Contributed by Serhiy Storchaka in :issue:`26032`). |
Serhiy Storchaka | 9171a8b | 2016-08-14 10:52:18 +0300 | [diff] [blame] | 1839 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1840 | * :class:`xml.etree.ElementTree` parsing, iteration and deepcopy performance |
| 1841 | has been significantly improved. |
| 1842 | (Contributed by Serhiy Storchaka in :issue:`25638`, :issue:`25873`, |
| 1843 | and :issue:`25869`.) |
| 1844 | |
| 1845 | * Creation of :class:`fractions.Fraction` instances from floats and |
| 1846 | decimals is now 2 to 3 times faster. |
| 1847 | (Contributed by Serhiy Storchaka in :issue:`25971`.) |
| 1848 | |
Yury Selivanov | f5df730 | 2016-11-07 16:40:20 -0500 | [diff] [blame] | 1849 | |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 1850 | Build and C API Changes |
| 1851 | ======================= |
| 1852 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1853 | * Python now requires some C99 support in the toolchain to build. |
| 1854 | Most notably, Python now uses standard integer types and macros in |
| 1855 | place of custom macros like ``PY_LONG_LONG``. |
| 1856 | For more information, see :pep:`7` and :issue:`17884`. |
Benjamin Peterson | cfbd48b | 2016-09-08 10:27:20 -0700 | [diff] [blame] | 1857 | |
Xavier de Gaye | 032c0fb | 2016-09-13 18:04:15 +0200 | [diff] [blame] | 1858 | * Cross-compiling CPython with the Android NDK and the Android API level set to |
Xtreak | c151f78 | 2018-06-16 10:38:31 +0530 | [diff] [blame] | 1859 | 21 (Android 5.0 Lollipop) or greater runs successfully. While Android is not |
Xavier de Gaye | 032c0fb | 2016-09-13 18:04:15 +0200 | [diff] [blame] | 1860 | yet a supported platform, the Python test suite runs on the Android emulator |
| 1861 | with only about 16 tests failures. See the Android meta-issue :issue:`26865`. |
| 1862 | |
Gregory P. Smith | 2863c38 | 2016-11-21 00:12:40 -0800 | [diff] [blame] | 1863 | * The ``--enable-optimizations`` configure flag has been added. Turning it on |
Brett Cannon | 1d8f755 | 2016-11-03 16:20:00 -0700 | [diff] [blame] | 1864 | will activate expensive optimizations like PGO. |
Martin Panter | ced4b90 | 2017-01-11 11:56:22 +0000 | [diff] [blame] | 1865 | (Original patch by Alecsandru Patrascu of Intel in :issue:`26359`.) |
Brett Cannon | 63d98bc | 2016-09-06 17:12:40 -0700 | [diff] [blame] | 1866 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1867 | * The :term:`GIL <global interpreter lock>` must now be held when allocator |
| 1868 | functions of :c:data:`PYMEM_DOMAIN_OBJ` (ex: :c:func:`PyObject_Malloc`) and |
| 1869 | :c:data:`PYMEM_DOMAIN_MEM` (ex: :c:func:`PyMem_Malloc`) domains are called. |
| 1870 | |
Martin Panter | b4ce1fc | 2015-11-30 03:18:29 +0000 | [diff] [blame] | 1871 | * New :c:func:`Py_FinalizeEx` API which indicates if flushing buffered data |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1872 | failed. |
| 1873 | (Contributed by Martin Panter in :issue:`5319`.) |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 1874 | |
Serhiy Storchaka | f41b82f | 2016-06-09 16:30:29 +0300 | [diff] [blame] | 1875 | * :c:func:`PyArg_ParseTupleAndKeywords` now supports :ref:`positional-only |
| 1876 | parameters <positional-only_parameter>`. Positional-only parameters are |
| 1877 | defined by empty names. |
Berker Peksag | e807e89 | 2016-07-01 12:12:19 +0300 | [diff] [blame] | 1878 | (Contributed by Serhiy Storchaka in :issue:`26282`). |
Serhiy Storchaka | f41b82f | 2016-06-09 16:30:29 +0300 | [diff] [blame] | 1879 | |
Nick Coghlan | d003423 | 2016-08-15 13:11:34 +1000 | [diff] [blame] | 1880 | * ``PyTraceback_Print`` method now abbreviates long sequences of repeated lines |
| 1881 | as ``"[Previous line repeated {count} more times]"``. |
| 1882 | (Contributed by Emanuel Barry in :issue:`26823`.) |
| 1883 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1884 | * The new :c:func:`PyErr_SetImportErrorSubclass` function allows for |
| 1885 | specifying a subclass of :exc:`ImportError` to raise. |
| 1886 | (Contributed by Eric Snow in :issue:`15767`.) |
| 1887 | |
| 1888 | * The new :c:func:`PyErr_ResourceWarning` function can be used to generate |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 1889 | a :exc:`ResourceWarning` providing the source of the resource allocation. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1890 | (Contributed by Victor Stinner in :issue:`26567`.) |
| 1891 | |
| 1892 | * The new :c:func:`PyOS_FSPath` function returns the file system |
| 1893 | representation of a :term:`path-like object`. |
| 1894 | (Contributed by Brett Cannon in :issue:`27186`.) |
| 1895 | |
| 1896 | * The :c:func:`PyUnicode_FSConverter` and :c:func:`PyUnicode_FSDecoder` |
| 1897 | functions will now accept :term:`path-like objects <path-like object>`. |
| 1898 | |
| 1899 | |
INADA Naoki | f576343 | 2016-11-24 17:20:40 +0900 | [diff] [blame] | 1900 | Other Improvements |
| 1901 | ================== |
| 1902 | |
| 1903 | * When :option:`--version` (short form: :option:`-V`) is supplied twice, |
| 1904 | Python prints :data:`sys.version` for detailed information. |
| 1905 | |
| 1906 | .. code-block:: shell-session |
| 1907 | |
| 1908 | $ ./python -VV |
| 1909 | Python 3.6.0b4+ (3.6:223967b49e49+, Nov 21 2016, 20:55:04) |
| 1910 | [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] |
| 1911 | |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 1912 | |
| 1913 | Deprecated |
| 1914 | ========== |
| 1915 | |
Yury Selivanov | 7a21911 | 2015-05-28 17:10:29 -0400 | [diff] [blame] | 1916 | New Keywords |
| 1917 | ------------ |
| 1918 | |
Yury Selivanov | 62f27b5 | 2015-08-03 14:57:21 -0400 | [diff] [blame] | 1919 | ``async`` and ``await`` are not recommended to be used as variable, class, |
| 1920 | function or module names. Introduced by :pep:`492` in Python 3.5, they will |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1921 | become proper keywords in Python 3.7. Starting in Python 3.6, the use of |
| 1922 | ``async`` or ``await`` as names will generate a :exc:`DeprecationWarning`. |
Christian Heimes | c4d2e50 | 2016-09-12 01:14:35 +0200 | [diff] [blame] | 1923 | |
Serhiy Storchaka | d73c318 | 2016-08-06 23:22:08 +0300 | [diff] [blame] | 1924 | |
Martin Panter | 7e3a91a | 2016-02-10 04:40:48 +0000 | [diff] [blame] | 1925 | Deprecated Python behavior |
| 1926 | -------------------------- |
| 1927 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 1928 | Raising the :exc:`StopIteration` exception inside a generator will now |
| 1929 | generate a :exc:`DeprecationWarning`, and will trigger a :exc:`RuntimeError` |
| 1930 | in Python 3.7. See :ref:`whatsnew-pep-479` for details. |
| 1931 | |
| 1932 | The :meth:`__aiter__` method is now expected to return an asynchronous |
| 1933 | iterator directly instead of returning an awaitable as previously. |
| 1934 | Doing the former will trigger a :exc:`DeprecationWarning`. Backward |
| 1935 | compatibility will be removed in Python 3.7. |
| 1936 | (Contributed by Yury Selivanov in :issue:`27243`.) |
| 1937 | |
| 1938 | A backslash-character pair that is not a valid escape sequence now generates |
| 1939 | a :exc:`DeprecationWarning`. Although this will eventually become a |
| 1940 | :exc:`SyntaxError`, that will not be for several Python releases. |
| 1941 | (Contributed by Emanuel Barry in :issue:`27364`.) |
| 1942 | |
| 1943 | When performing a relative import, falling back on ``__name__`` and |
| 1944 | ``__path__`` from the calling module when ``__spec__`` or |
| 1945 | ``__package__`` are not defined now raises an :exc:`ImportWarning`. |
| 1946 | (Contributed by Rose Ames in :issue:`25791`.) |
| 1947 | |
| 1948 | |
| 1949 | Deprecated Python modules, functions and methods |
| 1950 | ------------------------------------------------ |
| 1951 | |
| 1952 | asynchat |
| 1953 | ~~~~~~~~ |
| 1954 | |
| 1955 | The :mod:`asynchat` has been deprecated in favor of :mod:`asyncio`. |
| 1956 | (Contributed by Mariatta in :issue:`25002`.) |
| 1957 | |
| 1958 | |
| 1959 | asyncore |
| 1960 | ~~~~~~~~ |
| 1961 | |
| 1962 | The :mod:`asyncore` has been deprecated in favor of :mod:`asyncio`. |
| 1963 | (Contributed by Mariatta in :issue:`25002`.) |
| 1964 | |
| 1965 | |
| 1966 | dbm |
| 1967 | ~~~ |
| 1968 | |
| 1969 | Unlike other :mod:`dbm` implementations, the :mod:`dbm.dumb` module |
| 1970 | creates databases with the ``'rw'`` mode and allows modifying the database |
| 1971 | opened with the ``'r'`` mode. This behavior is now deprecated and will |
| 1972 | be removed in 3.8. |
| 1973 | (Contributed by Serhiy Storchaka in :issue:`21708`.) |
| 1974 | |
| 1975 | |
| 1976 | distutils |
| 1977 | ~~~~~~~~~ |
| 1978 | |
| 1979 | The undocumented ``extra_path`` argument to the |
| 1980 | :class:`~distutils.Distribution` constructor is now considered deprecated |
| 1981 | and will raise a warning if set. Support for this parameter will be |
| 1982 | removed in a future Python release. See :issue:`27919` for details. |
| 1983 | |
| 1984 | |
| 1985 | grp |
| 1986 | ~~~ |
| 1987 | |
| 1988 | The support of non-integer arguments in :func:`~grp.getgrgid` has been |
| 1989 | deprecated. |
| 1990 | (Contributed by Serhiy Storchaka in :issue:`26129`.) |
| 1991 | |
| 1992 | |
| 1993 | importlib |
| 1994 | ~~~~~~~~~ |
| 1995 | |
| 1996 | The :meth:`importlib.machinery.SourceFileLoader.load_module` and |
| 1997 | :meth:`importlib.machinery.SourcelessFileLoader.load_module` methods |
| 1998 | are now deprecated. They were the only remaining implementations of |
| 1999 | :meth:`importlib.abc.Loader.load_module` in :mod:`importlib` that had not |
| 2000 | been deprecated in previous versions of Python in favour of |
| 2001 | :meth:`importlib.abc.Loader.exec_module`. |
| 2002 | |
Steve Dower | 2036742 | 2016-12-07 13:02:27 -0800 | [diff] [blame] | 2003 | The :class:`importlib.machinery.WindowsRegistryFinder` class is now |
| 2004 | deprecated. As of 3.6.0, it is still added to :attr:`sys.meta_path` by |
| 2005 | default (on Windows), but this may change in future releases. |
| 2006 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2007 | os |
| 2008 | ~~ |
| 2009 | |
| 2010 | Undocumented support of general :term:`bytes-like objects <bytes-like object>` |
| 2011 | as paths in :mod:`os` functions, :func:`compile` and similar functions is |
| 2012 | now deprecated. |
| 2013 | (Contributed by Serhiy Storchaka in :issue:`25791` and :issue:`26754`.) |
| 2014 | |
| 2015 | re |
| 2016 | ~~ |
| 2017 | |
| 2018 | Support for inline flags ``(?letters)`` in the middle of the regular |
| 2019 | expression has been deprecated and will be removed in a future Python |
| 2020 | version. Flags at the start of a regular expression are still allowed. |
| 2021 | (Contributed by Serhiy Storchaka in :issue:`22493`.) |
| 2022 | |
| 2023 | ssl |
| 2024 | ~~~ |
| 2025 | |
| 2026 | OpenSSL 0.9.8, 1.0.0 and 1.0.1 are deprecated and no longer supported. |
| 2027 | In the future the :mod:`ssl` module will require at least OpenSSL 1.0.2 or |
| 2028 | 1.1.0. |
| 2029 | |
| 2030 | SSL-related arguments like ``certfile``, ``keyfile`` and ``check_hostname`` |
| 2031 | in :mod:`ftplib`, :mod:`http.client`, :mod:`imaplib`, :mod:`poplib`, |
| 2032 | and :mod:`smtplib` have been deprecated in favor of ``context``. |
| 2033 | (Contributed by Christian Heimes in :issue:`28022`.) |
| 2034 | |
| 2035 | A couple of protocols and functions of the :mod:`ssl` module are now |
| 2036 | deprecated. Some features will no longer be available in future versions |
| 2037 | of OpenSSL. Other features are deprecated in favor of a different API. |
| 2038 | (Contributed by Christian Heimes in :issue:`28022` and :issue:`26470`.) |
| 2039 | |
| 2040 | tkinter |
| 2041 | ~~~~~~~ |
| 2042 | |
| 2043 | The :mod:`tkinter.tix` module is now deprecated. :mod:`tkinter` users |
| 2044 | should use :mod:`tkinter.ttk` instead. |
| 2045 | |
| 2046 | venv |
| 2047 | ~~~~ |
| 2048 | |
| 2049 | The ``pyvenv`` script has been deprecated in favour of ``python3 -m venv``. |
| 2050 | This prevents confusion as to what Python interpreter ``pyvenv`` is |
| 2051 | connected to and thus what Python interpreter will be used by the virtual |
| 2052 | environment. (Contributed by Brett Cannon in :issue:`25154`.) |
| 2053 | |
| 2054 | |
| 2055 | Deprecated functions and types of the C API |
| 2056 | ------------------------------------------- |
| 2057 | |
| 2058 | Undocumented functions :c:func:`PyUnicode_AsEncodedObject`, |
| 2059 | :c:func:`PyUnicode_AsDecodedObject`, :c:func:`PyUnicode_AsEncodedUnicode` |
| 2060 | and :c:func:`PyUnicode_AsDecodedUnicode` are deprecated now. |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 2061 | Use the :ref:`generic codec based API <codec-registry>` instead. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2062 | |
| 2063 | |
| 2064 | Deprecated Build Options |
| 2065 | ------------------------ |
| 2066 | |
| 2067 | The ``--with-system-ffi`` configure flag is now on by default on non-macOS |
| 2068 | UNIX platforms. It may be disabled by using ``--without-system-ffi``, but |
| 2069 | using the flag is deprecated and will not be accepted in Python 3.7. |
| 2070 | macOS is unaffected by this change. Note that many OS distributors already |
| 2071 | use the ``--with-system-ffi`` flag when building their system Python. |
Martin Panter | 7e3a91a | 2016-02-10 04:40:48 +0000 | [diff] [blame] | 2072 | |
| 2073 | |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 2074 | Removed |
| 2075 | ======= |
| 2076 | |
| 2077 | API and Feature Removals |
| 2078 | ------------------------ |
| 2079 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2080 | * Unknown escapes consisting of ``'\'`` and an ASCII letter in |
Serhiy Storchaka | 53c53ea | 2016-12-06 19:15:29 +0200 | [diff] [blame] | 2081 | regular expressions will now cause an error. In replacement templates for |
| 2082 | :func:`re.sub` they are still allowed, but deprecated. |
| 2083 | The :const:`re.LOCALE` flag can now only be used with binary patterns. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2084 | |
Yury Selivanov | 5661316 | 2015-07-23 17:51:34 +0300 | [diff] [blame] | 2085 | * ``inspect.getmoduleinfo()`` was removed (was deprecated since CPython 3.3). |
Yury Selivanov | 6dfbc5d | 2015-07-23 17:49:00 +0300 | [diff] [blame] | 2086 | :func:`inspect.getmodulename` should be used for obtaining the module |
| 2087 | name for a given path. |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2088 | (Contributed by Yury Selivanov in :issue:`13248`.) |
Yury Selivanov | 6dfbc5d | 2015-07-23 17:49:00 +0300 | [diff] [blame] | 2089 | |
Senthil Kumaran | 613065b | 2016-01-17 20:12:16 -0800 | [diff] [blame] | 2090 | * ``traceback.Ignore`` class and ``traceback.usage``, ``traceback.modname``, |
| 2091 | ``traceback.fullmodname``, ``traceback.find_lines_from_code``, |
| 2092 | ``traceback.find_lines``, ``traceback.find_strings``, |
| 2093 | ``traceback.find_executable_lines`` methods were removed from the |
| 2094 | :mod:`traceback` module. They were undocumented methods deprecated since |
| 2095 | Python 3.2 and equivalent functionality is available from private methods. |
| 2096 | |
Serhiy Storchaka | 2e208b7 | 2016-05-16 22:35:46 +0300 | [diff] [blame] | 2097 | * The ``tk_menuBar()`` and ``tk_bindForTraversal()`` dummy methods in |
| 2098 | :mod:`tkinter` widget classes were removed (corresponding Tk commands |
| 2099 | were obsolete since Tk 4.0). |
| 2100 | |
Serhiy Storchaka | e670be2 | 2016-06-11 19:32:44 +0300 | [diff] [blame] | 2101 | * The :meth:`~zipfile.ZipFile.open` method of the :class:`zipfile.ZipFile` |
| 2102 | class no longer supports the ``'U'`` mode (was deprecated since Python 3.4). |
| 2103 | Use :class:`io.TextIOWrapper` for reading compressed text files in |
| 2104 | :term:`universal newlines` mode. |
| 2105 | |
Zachary Ware | 20737cc | 2016-09-08 11:38:46 -0700 | [diff] [blame] | 2106 | * The undocumented ``IN``, ``CDROM``, ``DLFCN``, ``TYPES``, ``CDIO``, and |
| 2107 | ``STROPTS`` modules have been removed. They had been available in the |
| 2108 | platform specific ``Lib/plat-*/`` directories, but were chronically out of |
| 2109 | date, inconsistently available across platforms, and unmaintained. The |
| 2110 | script that created these modules is still available in the source |
| 2111 | distribution at :source:`Tools/scripts/h2py.py`. |
| 2112 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2113 | * The deprecated ``asynchat.fifo`` class has been removed. |
| 2114 | |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 2115 | |
| 2116 | Porting to Python 3.6 |
| 2117 | ===================== |
| 2118 | |
| 2119 | This section lists previously described changes and other bugfixes |
| 2120 | that may require changes to your code. |
| 2121 | |
Serhiy Storchaka | 7e160ce | 2016-07-03 21:03:53 +0300 | [diff] [blame] | 2122 | Changes in 'python' Command Behavior |
| 2123 | ------------------------------------ |
| 2124 | |
| 2125 | * The output of a special Python build with defined ``COUNT_ALLOCS``, |
| 2126 | ``SHOW_ALLOC_COUNT`` or ``SHOW_TRACK_COUNT`` macros is now off by |
| 2127 | default. It can be re-enabled using the ``-X showalloccount`` option. |
| 2128 | It now outputs to ``stderr`` instead of ``stdout``. |
| 2129 | (Contributed by Serhiy Storchaka in :issue:`23034`.) |
| 2130 | |
| 2131 | |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 2132 | Changes in the Python API |
| 2133 | ------------------------- |
| 2134 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2135 | * :func:`open() <open>` will no longer allow combining the ``'U'`` mode flag |
| 2136 | with ``'+'``. |
| 2137 | (Contributed by Jeff Balogh and John O'Connor in :issue:`2091`.) |
| 2138 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 2139 | * :mod:`sqlite3` no longer implicitly commits an open transaction before DDL |
Berker Peksag | ab994ed | 2016-09-11 12:57:15 +0300 | [diff] [blame] | 2140 | statements. |
| 2141 | |
Victor Stinner | e66987e | 2016-09-06 16:33:52 -0700 | [diff] [blame] | 2142 | * On Linux, :func:`os.urandom` now blocks until the system urandom entropy pool |
| 2143 | is initialized to increase the security. |
| 2144 | |
Brett Cannon | 696c35e | 2016-06-25 10:58:17 -0700 | [diff] [blame] | 2145 | * When :meth:`importlib.abc.Loader.exec_module` is defined, |
| 2146 | :meth:`importlib.abc.Loader.create_module` must also be defined. |
| 2147 | |
Eric Snow | 46f97b8 | 2016-09-07 16:56:15 -0700 | [diff] [blame] | 2148 | * :c:func:`PyErr_SetImportError` now sets :exc:`TypeError` when its **msg** |
| 2149 | argument is not set. Previously only ``NULL`` was returned. |
| 2150 | |
Victor Stinner | f3914eb | 2016-01-20 12:16:21 +0100 | [diff] [blame] | 2151 | * The format of the ``co_lnotab`` attribute of code objects changed to support |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 2152 | a negative line number delta. By default, Python does not emit bytecode with |
| 2153 | a negative line number delta. Functions using ``frame.f_lineno``, |
Victor Stinner | f3914eb | 2016-01-20 12:16:21 +0100 | [diff] [blame] | 2154 | ``PyFrame_GetLineNumber()`` or ``PyCode_Addr2Line()`` are not affected. |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 2155 | Functions directly decoding ``co_lnotab`` should be updated to use a signed |
| 2156 | 8-bit integer type for the line number delta, but this is only required to |
| 2157 | support applications using a negative line number delta. See |
Victor Stinner | f3914eb | 2016-01-20 12:16:21 +0100 | [diff] [blame] | 2158 | ``Objects/lnotab_notes.txt`` for the ``co_lnotab`` format and how to decode |
| 2159 | it, and see the :pep:`511` for the rationale. |
| 2160 | |
Brett Cannon | 1e3c3e9 | 2015-12-27 13:17:04 -0800 | [diff] [blame] | 2161 | * The functions in the :mod:`compileall` module now return booleans instead |
| 2162 | of ``1`` or ``0`` to represent success or failure, respectively. Thanks to |
| 2163 | booleans being a subclass of integers, this should only be an issue if you |
| 2164 | were doing identity checks for ``1`` or ``0``. See :issue:`25768`. |
| 2165 | |
Robert Collins | dfa95c9 | 2015-08-10 09:53:30 +1200 | [diff] [blame] | 2166 | * Reading the :attr:`~urllib.parse.SplitResult.port` attribute of |
| 2167 | :func:`urllib.parse.urlsplit` and :func:`~urllib.parse.urlparse` results |
| 2168 | now raises :exc:`ValueError` for out-of-range values, rather than |
| 2169 | returning :const:`None`. See :issue:`20059`. |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 2170 | |
Brett Cannon | c0d91af | 2015-10-16 12:21:37 -0700 | [diff] [blame] | 2171 | * The :mod:`imp` module now raises a :exc:`DeprecationWarning` instead of |
| 2172 | :exc:`PendingDeprecationWarning`. |
| 2173 | |
Martin Panter | 28a465c | 2015-11-14 12:52:08 +0000 | [diff] [blame] | 2174 | * The following modules have had missing APIs added to their :attr:`__all__` |
Martin Panter | 0d3535a | 2016-06-06 02:09:08 +0000 | [diff] [blame] | 2175 | attributes to match the documented APIs: |
| 2176 | :mod:`calendar`, :mod:`cgi`, :mod:`csv`, |
Martin Panter | dcfebb3 | 2016-04-01 06:55:55 +0000 | [diff] [blame] | 2177 | :mod:`~xml.etree.ElementTree`, :mod:`enum`, |
Martin Panter | 0d3535a | 2016-06-06 02:09:08 +0000 | [diff] [blame] | 2178 | :mod:`fileinput`, :mod:`ftplib`, :mod:`logging`, :mod:`mailbox`, |
| 2179 | :mod:`mimetypes`, :mod:`optparse`, :mod:`plistlib`, :mod:`smtpd`, |
| 2180 | :mod:`subprocess`, :mod:`tarfile`, :mod:`threading` and |
Martin Panter | 28a465c | 2015-11-14 12:52:08 +0000 | [diff] [blame] | 2181 | :mod:`wave`. This means they will export new symbols when ``import *`` |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2182 | is used. |
| 2183 | (Contributed by Joel Taddei and Jacek Kołodziej in :issue:`23883`.) |
Martin Panter | 28a465c | 2015-11-14 12:52:08 +0000 | [diff] [blame] | 2184 | |
Brett Cannon | 849113a | 2016-01-22 15:25:50 -0800 | [diff] [blame] | 2185 | * When performing a relative import, if ``__package__`` does not compare equal |
| 2186 | to ``__spec__.parent`` then :exc:`ImportWarning` is raised. |
| 2187 | (Contributed by Brett Cannon in :issue:`25791`.) |
Brett Cannon | 63b8505 | 2016-01-15 13:33:03 -0800 | [diff] [blame] | 2188 | |
Brett Cannon | 9fa8126 | 2016-01-22 16:39:02 -0800 | [diff] [blame] | 2189 | * When a relative import is performed and no parent package is known, then |
| 2190 | :exc:`ImportError` will be raised. Previously, :exc:`SystemError` could be |
Martin Panter | d9108d1 | 2016-02-21 08:49:56 +0000 | [diff] [blame] | 2191 | raised. (Contributed by Brett Cannon in :issue:`18018`.) |
| 2192 | |
| 2193 | * Servers based on the :mod:`socketserver` module, including those |
| 2194 | defined in :mod:`http.server`, :mod:`xmlrpc.server` and |
| 2195 | :mod:`wsgiref.simple_server`, now only catch exceptions derived |
| 2196 | from :exc:`Exception`. Therefore if a request handler raises |
| 2197 | an exception like :exc:`SystemExit` or :exc:`KeyboardInterrupt`, |
| 2198 | :meth:`~socketserver.BaseServer.handle_error` is no longer called, and |
| 2199 | the exception will stop a single-threaded server. (Contributed by |
| 2200 | Martin Panter in :issue:`23430`.) |
Brett Cannon | 9fa8126 | 2016-01-22 16:39:02 -0800 | [diff] [blame] | 2201 | |
Berker Peksag | 3c3d7f4 | 2016-03-19 11:44:17 +0200 | [diff] [blame] | 2202 | * :func:`spwd.getspnam` now raises a :exc:`PermissionError` instead of |
| 2203 | :exc:`KeyError` if the user doesn't have privileges. |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 2204 | |
Martin Panter | 50ab1a3 | 2016-04-11 00:38:12 +0000 | [diff] [blame] | 2205 | * The :meth:`socket.socket.close` method now raises an exception if |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2206 | an error (e.g. ``EBADF``) was reported by the underlying system call. |
| 2207 | (Contributed by Martin Panter in :issue:`26685`.) |
Martin Panter | 50ab1a3 | 2016-04-11 00:38:12 +0000 | [diff] [blame] | 2208 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 2209 | * The *decode_data* argument for the :class:`smtpd.SMTPChannel` and |
Serhiy Storchaka | 8c740c4 | 2016-05-29 23:43:24 +0300 | [diff] [blame] | 2210 | :class:`smtpd.SMTPServer` constructors is now ``False`` by default. |
| 2211 | This means that the argument passed to |
| 2212 | :meth:`~smtpd.SMTPServer.process_message` is now a bytes object by |
| 2213 | default, and ``process_message()`` will be passed keyword arguments. |
| 2214 | Code that has already been updated in accordance with the deprecation |
| 2215 | warning generated by 3.5 will not be affected. |
| 2216 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2217 | * All optional arguments of the :func:`~json.dump`, :func:`~json.dumps`, |
Serhiy Storchaka | aacd53f | 2016-06-22 00:03:20 +0300 | [diff] [blame] | 2218 | :func:`~json.load` and :func:`~json.loads` functions and |
| 2219 | :class:`~json.JSONEncoder` and :class:`~json.JSONDecoder` class |
| 2220 | constructors in the :mod:`json` module are now :ref:`keyword-only |
| 2221 | <keyword-only_parameter>`. |
| 2222 | (Contributed by Serhiy Storchaka in :issue:`18726`.) |
| 2223 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2224 | * Subclasses of :class:`type` which don't override ``type.__new__`` may no |
| 2225 | longer use the one-argument form to get the type of an object. |
| 2226 | |
Nick Coghlan | 607e1c4 | 2016-07-31 12:42:49 +1000 | [diff] [blame] | 2227 | * As part of :pep:`487`, the handling of keyword arguments passed to |
| 2228 | :class:`type` (other than the metaclass hint, ``metaclass``) is now |
| 2229 | consistently delegated to :meth:`object.__init_subclass__`. This means that |
| 2230 | :meth:`type.__new__` and :meth:`type.__init__` both now accept arbitrary |
| 2231 | keyword arguments, but :meth:`object.__init_subclass__` (which is called from |
| 2232 | :meth:`type.__new__`) will reject them by default. Custom metaclasses |
| 2233 | accepting additional keyword arguments will need to adjust their calls to |
| 2234 | :meth:`type.__new__` (whether direct or via :class:`super`) accordingly. |
| 2235 | |
Jason R. Coombs | c758d51 | 2016-08-21 16:09:27 -0400 | [diff] [blame] | 2236 | * In :class:`distutils.command.sdist.sdist`, the ``default_format`` |
| 2237 | attribute has been removed and is no longer honored. Instead, the |
| 2238 | gzipped tarfile format is the default on all platforms and no |
| 2239 | platform-specific selection is made. |
| 2240 | In environments where distributions are |
| 2241 | built on Windows and zip distributions are required, configure |
Serhiy Storchaka | 46936d5 | 2018-04-08 19:18:04 +0300 | [diff] [blame] | 2242 | the project with a ``setup.cfg`` file containing the following: |
| 2243 | |
| 2244 | .. code-block:: ini |
Jason R. Coombs | c758d51 | 2016-08-21 16:09:27 -0400 | [diff] [blame] | 2245 | |
| 2246 | [sdist] |
| 2247 | formats=zip |
| 2248 | |
| 2249 | This behavior has also been backported to earlier Python versions |
| 2250 | by Setuptools 26.0.0. |
Serhiy Storchaka | aacd53f | 2016-06-22 00:03:20 +0300 | [diff] [blame] | 2251 | |
Martin Panter | ef91bb2 | 2016-08-27 01:39:26 +0000 | [diff] [blame] | 2252 | * In the :mod:`urllib.request` module and the |
| 2253 | :meth:`http.client.HTTPConnection.request` method, if no Content-Length |
| 2254 | header field has been specified and the request body is a file object, |
| 2255 | it is now sent with HTTP 1.1 chunked encoding. If a file object has to |
| 2256 | be sent to a HTTP 1.0 server, the Content-Length value now has to be |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2257 | specified by the caller. |
| 2258 | (Contributed by Demian Brecht and Rolf Krahl with tweaks from |
| 2259 | Martin Panter in :issue:`12319`.) |
| 2260 | |
| 2261 | * The :class:`~csv.DictReader` now returns rows of type |
| 2262 | :class:`~collections.OrderedDict`. |
| 2263 | (Contributed by Steve Holden in :issue:`27842`.) |
| 2264 | |
| 2265 | * The :const:`crypt.METHOD_CRYPT` will no longer be added to ``crypt.methods`` |
| 2266 | if unsupported by the platform. |
| 2267 | (Contributed by Victor Stinner in :issue:`25287`.) |
| 2268 | |
| 2269 | * The *verbose* and *rename* arguments for |
| 2270 | :func:`~collections.namedtuple` are now keyword-only. |
| 2271 | (Contributed by Raymond Hettinger in :issue:`25628`.) |
| 2272 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2273 | * On Linux, :func:`ctypes.util.find_library` now looks in |
| 2274 | ``LD_LIBRARY_PATH`` for shared libraries. |
| 2275 | (Contributed by Vinay Sajip in :issue:`9998`.) |
| 2276 | |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2277 | * The :class:`imaplib.IMAP4` class now handles flags containing the |
| 2278 | ``']'`` character in messages sent from the server to improve |
| 2279 | real-world compatibility. |
| 2280 | (Contributed by Lita Cho in :issue:`21815`.) |
| 2281 | |
| 2282 | * The :func:`mmap.write() <mmap.write>` function now returns the number |
| 2283 | of bytes written like other write methods. |
| 2284 | (Contributed by Jakub Stasiak in :issue:`26335`.) |
| 2285 | |
| 2286 | * The :func:`pkgutil.iter_modules` and :func:`pkgutil.walk_packages` |
| 2287 | functions now return :class:`~pkgutil.ModuleInfo` named tuples. |
| 2288 | (Contributed by Ramchandra Apte in :issue:`17211`.) |
| 2289 | |
| 2290 | * :func:`re.sub` now raises an error for invalid numerical group |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 2291 | references in replacement templates even if the pattern is not |
| 2292 | found in the string. The error message for invalid group references |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2293 | now includes the group index and the position of the reference. |
| 2294 | (Contributed by SilentGhost, Serhiy Storchaka in :issue:`25953`.) |
| 2295 | |
| 2296 | * :class:`zipfile.ZipFile` will now raise :exc:`NotImplementedError` for |
| 2297 | unrecognized compression values. Previously a plain :exc:`RuntimeError` |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 2298 | was raised. Additionally, calling :class:`~zipfile.ZipFile` methods |
| 2299 | on a closed ZipFile or calling the :meth:`~zipfile.ZipFile.write` method |
Yury Selivanov | c48ec27 | 2016-11-10 13:27:22 -0500 | [diff] [blame] | 2300 | on a ZipFile created with mode ``'r'`` will raise a :exc:`ValueError`. |
| 2301 | Previously, a :exc:`RuntimeError` was raised in those scenarios. |
| 2302 | |
Nick Coghlan | 19d2467 | 2016-12-05 16:47:55 +1000 | [diff] [blame] | 2303 | * when custom metaclasses are combined with zero-argument :func:`super` or |
| 2304 | direct references from methods to the implicit ``__class__`` closure |
| 2305 | variable, the implicit ``__classcell__`` namespace entry must now be passed |
| 2306 | up to ``type.__new__`` for initialisation. Failing to do so will result in |
Serhiy Storchaka | 8ae8e6a | 2018-05-20 08:13:52 +0300 | [diff] [blame] | 2307 | a :exc:`DeprecationWarning` in Python 3.6 and a :exc:`RuntimeError` in |
| 2308 | Python 3.8. |
Martin Panter | ef91bb2 | 2016-08-27 01:39:26 +0000 | [diff] [blame] | 2309 | |
Yury Selivanov | d1da507 | 2015-05-27 22:09:10 -0400 | [diff] [blame] | 2310 | Changes in the C API |
| 2311 | -------------------- |
| 2312 | |
Martin Panter | a2f7ee8 | 2016-11-21 13:38:59 +0000 | [diff] [blame] | 2313 | * The :c:func:`PyMem_Malloc` allocator family now uses the :ref:`pymalloc allocator |
| 2314 | <pymalloc>` rather than the system :c:func:`malloc`. Applications calling |
Victor Stinner | f5c4b99 | 2016-04-22 16:26:23 +0200 | [diff] [blame] | 2315 | :c:func:`PyMem_Malloc` without holding the GIL can now crash. Set the |
| 2316 | :envvar:`PYTHONMALLOC` environment variable to ``debug`` to validate the |
| 2317 | usage of memory allocators in your application. See :issue:`26249`. |
| 2318 | |
Martin Panter | b4ce1fc | 2015-11-30 03:18:29 +0000 | [diff] [blame] | 2319 | * :c:func:`Py_Exit` (and the main interpreter) now override the exit status |
| 2320 | with 120 if flushing buffered data failed. See :issue:`5319`. |
Yury Selivanov | 27ec5bf | 2016-11-28 11:45:36 -0500 | [diff] [blame] | 2321 | |
| 2322 | |
| 2323 | CPython bytecode changes |
| 2324 | ------------------------ |
| 2325 | |
| 2326 | There have been several major changes to the :term:`bytecode` in Python 3.6. |
| 2327 | |
| 2328 | * The Python interpreter now uses a 16-bit wordcode instead of bytecode. |
| 2329 | (Contributed by Demur Rumed with input and reviews from |
| 2330 | Serhiy Storchaka and Victor Stinner in :issue:`26647` and :issue:`28050`.) |
| 2331 | |
| 2332 | * The new :opcode:`FORMAT_VALUE` and :opcode:`BUILD_STRING` opcodes as part |
| 2333 | of the :ref:`formatted string literal <whatsnew36-pep498>` implementation. |
| 2334 | (Contributed by Eric Smith in :issue:`25483` and |
| 2335 | Serhiy Storchaka in :issue:`27078`.) |
| 2336 | |
| 2337 | * The new :opcode:`BUILD_CONST_KEY_MAP` opcode to optimize the creation |
| 2338 | of dictionaries with constant keys. |
| 2339 | (Contributed by Serhiy Storchaka in :issue:`27140`.) |
| 2340 | |
| 2341 | * The function call opcodes have been heavily reworked for better performance |
| 2342 | and simpler implementation. |
| 2343 | The :opcode:`MAKE_FUNCTION`, :opcode:`CALL_FUNCTION`, |
| 2344 | :opcode:`CALL_FUNCTION_KW` and :opcode:`BUILD_MAP_UNPACK_WITH_CALL` opcodes |
| 2345 | have been modified, the new :opcode:`CALL_FUNCTION_EX` and |
| 2346 | :opcode:`BUILD_TUPLE_UNPACK_WITH_CALL` have been added, and |
| 2347 | ``CALL_FUNCTION_VAR``, ``CALL_FUNCTION_VAR_KW`` and ``MAKE_CLOSURE`` opcodes |
| 2348 | have been removed. |
| 2349 | (Contributed by Demur Rumed in :issue:`27095`, and Serhiy Storchaka in |
| 2350 | :issue:`27213`, :issue:`28257`.) |
| 2351 | |
| 2352 | * The new :opcode:`SETUP_ANNOTATIONS` and :opcode:`STORE_ANNOTATION` opcodes |
| 2353 | have been added to support the new :term:`variable annotation` syntax. |
| 2354 | (Contributed by Ivan Levkivskyi in :issue:`27985`.) |
Ned Deily | 9d6171d | 2018-06-11 04:09:34 -0400 | [diff] [blame] | 2355 | |
| 2356 | |
| 2357 | Notable changes in Python 3.6.2 |
| 2358 | =============================== |
| 2359 | |
| 2360 | New ``make regen-all`` build target |
| 2361 | ----------------------------------- |
| 2362 | |
| 2363 | To simplify cross-compilation, and to ensure that CPython can reliably be |
| 2364 | compiled without requiring an existing version of Python to already be |
| 2365 | available, the autotools-based build system no longer attempts to implicitly |
| 2366 | recompile generated files based on file modification times. |
| 2367 | |
| 2368 | Instead, a new ``make regen-all`` command has been added to force regeneration |
| 2369 | of these files when desired (e.g. after an initial version of Python has |
| 2370 | already been built based on the pregenerated versions). |
| 2371 | |
| 2372 | More selective regeneration targets are also defined - see |
| 2373 | :source:`Makefile.pre.in` for details. |
| 2374 | |
| 2375 | (Contributed by Victor Stinner in :issue:`23404`.) |
| 2376 | |
| 2377 | .. versionadded:: 3.6.2 |
| 2378 | |
| 2379 | |
| 2380 | Removal of ``make touch`` build target |
| 2381 | -------------------------------------- |
| 2382 | |
| 2383 | The ``make touch`` build target previously used to request implicit regeneration |
| 2384 | of generated files by updating their modification times has been removed. |
| 2385 | |
| 2386 | It has been replaced by the new ``make regen-all`` target. |
| 2387 | |
| 2388 | (Contributed by Victor Stinner in :issue:`23404`.) |
| 2389 | |
| 2390 | .. versionchanged:: 3.6.2 |
| 2391 | |
| 2392 | |
| 2393 | Notable changes in Python 3.6.4 |
| 2394 | =============================== |
| 2395 | |
| 2396 | The ``PyExc_RecursionErrorInst`` singleton that was part of the public API |
| 2397 | has been removed as its members being never cleared may cause a segfault |
| 2398 | during finalization of the interpreter. |
| 2399 | (Contributed by Xavier de Gaye in :issue:`22898` and :issue:`30697`.) |
| 2400 | |
| 2401 | |
| 2402 | Notable changes in Python 3.6.5 |
| 2403 | =============================== |
| 2404 | |
| 2405 | The :func:`locale.localeconv` function now sets temporarily the ``LC_CTYPE`` |
| 2406 | locale to the ``LC_NUMERIC`` locale in some cases. |
| 2407 | (Contributed by Victor Stinner in :issue:`31900`.) |