Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 1 | **************************** |
| 2 | What's New In Python 3.8 |
| 3 | **************************** |
| 4 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 5 | .. Rules for maintenance: |
| 6 | |
| 7 | * Anyone can add text to this document. Do not spend very much time |
| 8 | on the wording of your changes, because your text will probably |
| 9 | get rewritten to some degree. |
| 10 | |
| 11 | * The maintainer will go through Misc/NEWS periodically and add |
| 12 | changes; it's therefore more important to add your changes to |
| 13 | Misc/NEWS than to this file. |
| 14 | |
| 15 | * This is not a complete list of every single change; completeness |
| 16 | is the purpose of Misc/NEWS. Some changes I consider too small |
| 17 | or esoteric to include. If such a change is added to the text, |
| 18 | I'll just remove it. (This is another reason you shouldn't spend |
| 19 | too much time on writing your addition.) |
| 20 | |
| 21 | * If you want to draw your new text to the attention of the |
| 22 | maintainer, add 'XXX' to the beginning of the paragraph or |
| 23 | section. |
| 24 | |
| 25 | * It's OK to just add a fragmentary note about a change. For |
| 26 | example: "XXX Describe the transmogrify() function added to the |
| 27 | socket module." The maintainer will research the change and |
| 28 | write the necessary text. |
| 29 | |
| 30 | * You can comment out your additions if you like, but it's not |
| 31 | necessary (especially when a final release is some months away). |
| 32 | |
| 33 | * Credit the author of a patch or bugfix. Just the name is |
| 34 | sufficient; the e-mail address isn't necessary. |
| 35 | |
| 36 | * It's helpful to add the bug/patch number as a comment: |
| 37 | |
| 38 | XXX Describe the transmogrify() function added to the socket |
| 39 | module. |
| 40 | (Contributed by P.Y. Developer in :issue:`12345`.) |
| 41 | |
| 42 | This saves the maintainer the effort of going through the Mercurial log |
| 43 | when researching a change. |
| 44 | |
| 45 | This article explains the new features in Python 3.8, compared to 3.7. |
| 46 | |
Ned Deily | 45ab51c | 2018-02-28 13:58:38 -0500 | [diff] [blame] | 47 | For full details, see the :ref:`changelog <changelog>`. |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 48 | |
| 49 | .. note:: |
| 50 | |
| 51 | Prerelease users should be aware that this document is currently in draft |
| 52 | form. It will be updated substantially as Python 3.8 moves towards release, |
| 53 | so it's worth checking back even after reading earlier versions. |
| 54 | |
| 55 | |
| 56 | Summary -- Release highlights |
| 57 | ============================= |
| 58 | |
| 59 | .. This section singles out the most important changes in Python 3.8. |
| 60 | Brevity is key. |
| 61 | |
| 62 | |
| 63 | .. PEP-sized items next. |
| 64 | |
| 65 | |
| 66 | |
| 67 | New Features |
| 68 | ============ |
| 69 | |
Nick Coghlan | 16eb3bc | 2018-06-20 21:25:01 +1000 | [diff] [blame] | 70 | Parallel filesystem cache for compiled bytecode files |
| 71 | ----------------------------------------------------- |
| 72 | |
| 73 | The new :envvar:`PYTHONPYCACHEPREFIX` setting (also available as |
| 74 | :option:`-X` ``pycache_prefix``) configures the implicit bytecode |
| 75 | cache to use a separate parallel filesystem tree, rather than |
| 76 | the default ``__pycache__`` subdirectories within each source |
| 77 | directory. |
| 78 | |
| 79 | The location of the cache is reported in :data:`sys.pycache_prefix` |
| 80 | (:const:`None` indicates the default location in ``__pycache__`` |
| 81 | subdirectories). |
| 82 | |
| 83 | (Contributed by Carl Meyer in :issue:`33499`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 84 | |
| 85 | |
| 86 | Other Language Changes |
| 87 | ====================== |
| 88 | |
Serhiy Storchaka | fe2bbb1 | 2018-03-18 09:56:52 +0200 | [diff] [blame] | 89 | * A :keyword:`continue` statement was illegal in the :keyword:`finally` clause |
| 90 | due to a problem with the implementation. In Python 3.8 this restriction |
| 91 | was lifted. |
| 92 | (Contributed by Serhiy Storchaka in :issue:`32489`.) |
| 93 | |
Serhiy Storchaka | b2e2025 | 2018-10-20 00:46:31 +0300 | [diff] [blame] | 94 | * The :class:`int` type now has a new :meth:`~int.as_integer_ratio` method |
| 95 | compatible with the existing :meth:`float.as_integer_ratio` method. |
Lisa Roach | 5ac7043 | 2018-09-13 23:56:23 -0700 | [diff] [blame] | 96 | (Contributed by Lisa Roach in :issue:`33073`.) |
| 97 | |
Serhiy Storchaka | a445feb | 2018-02-10 00:08:17 +0200 | [diff] [blame] | 98 | * Added support of ``\N{name}`` escapes in :mod:`regular expressions <re>`. |
| 99 | (Contributed by Jonathan Eunice and Serhiy Storchaka in :issue:`30688`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 100 | |
Rémi Lapeyre | 6531bf6 | 2018-11-06 01:38:54 +0100 | [diff] [blame] | 101 | * Dict and dictviews are now iterable in reversed insertion order using |
| 102 | :func:`reversed`. (Contributed by Rémi Lapeyre in :issue:`33462`.) |
| 103 | |
Benjamin Peterson | c9a71dd | 2018-09-12 17:14:39 -0700 | [diff] [blame] | 104 | * The syntax allowed for keyword names in function calls was further |
| 105 | restricted. In particular, ``f((keyword)=arg)`` is no longer allowed. It was |
| 106 | never intended to permit more than a bare name on the left-hand side of a |
| 107 | keyword argument assignment term. See :issue:`34641`. |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 108 | |
jChapman | 8fabae3 | 2018-09-22 21:13:10 -0400 | [diff] [blame] | 109 | * Iterable unpacking is now allowed without parentheses in :keyword:`yield` |
| 110 | and :keyword:`return` statements. |
| 111 | (Contributed by David Cuthbert and Jordan Chapman in :issue:`32117`.) |
| 112 | |
Serhiy Storchaka | 6543912 | 2018-10-19 17:42:06 +0300 | [diff] [blame] | 113 | * A backslash-character pair that is not a valid escape sequence generates |
| 114 | a :exc:`DeprecationWarning` since Python 3.6. In Python 3.8 it generates |
| 115 | a :exc:`SyntaxWarning` instead. |
| 116 | (Contributed by Serhiy Storchaka in :issue:`32912`.) |
| 117 | |
| 118 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 119 | New Modules |
| 120 | =========== |
| 121 | |
| 122 | * None yet. |
| 123 | |
| 124 | |
| 125 | Improved Modules |
| 126 | ================ |
| 127 | |
Raymond Hettinger | 0bb4bdf | 2019-01-31 00:59:50 -0800 | [diff] [blame^] | 128 | * The :meth:`_asdict()` method for :func:`collections.namedtuple` now returns |
| 129 | a :class:`dict` instead of a :class:`collections.OrderedDict`. This works because |
| 130 | regular dicts have guaranteed ordering in since Python 3.7. If the extra |
| 131 | features of :class:`OrderedDict` are required, the suggested remediation is |
| 132 | to cast the result to the desired type: ``OrderedDict(nt._asdict())``. |
| 133 | (Contributed by Raymond Hettinger in :issue:`35864`.) |
| 134 | |
| 135 | |
Victor Stinner | 6ea29c5 | 2018-09-25 08:27:08 -0700 | [diff] [blame] | 136 | asyncio |
| 137 | ------- |
| 138 | |
| 139 | On Windows, the default event loop is now :class:`~asyncio.ProactorEventLoop`. |
| 140 | |
Terry Jan Reedy | fdcb5ae | 2018-09-25 12:45:27 -0400 | [diff] [blame] | 141 | |
Cheryl Sabella | 637a33b | 2018-11-07 09:12:20 -0500 | [diff] [blame] | 142 | gettext |
| 143 | ------- |
| 144 | |
| 145 | Added :func:`~gettext.pgettext` and its variants. |
| 146 | (Contributed by Franz Glasner, Éric Araujo, and Cheryl Sabella in :issue:`2504`.) |
| 147 | |
guoci | 0e7497c | 2018-11-07 04:50:23 -0500 | [diff] [blame] | 148 | gzip |
| 149 | ---- |
| 150 | |
| 151 | Added the *mtime* parameter to :func:`gzip.compress` for reproducible output. |
| 152 | (Contributed by Guo Ci Teo in :issue:`34898`.) |
| 153 | |
| 154 | |
Terry Jan Reedy | fdcb5ae | 2018-09-25 12:45:27 -0400 | [diff] [blame] | 155 | idlelib and IDLE |
| 156 | ---------------- |
| 157 | |
| 158 | Output over N lines (50 by default) is squeezed down to a button. |
| 159 | N can be changed in the PyShell section of the General page of the |
| 160 | Settings dialog. Fewer, but possibly extra long, lines can be squeezed by |
| 161 | right clicking on the output. Squeezed output can be expanded in place |
| 162 | by double-clicking the button or into the clipboard or a separate window |
| 163 | by right-clicking the button. (Contributed by Tal Einat in :issue:`1529353`.) |
| 164 | |
| 165 | The changes above have been backported to 3.7 maintenance releases. |
| 166 | |
| 167 | |
HongWeipeng | f194479 | 2018-11-07 18:09:32 +0800 | [diff] [blame] | 168 | json.tool |
| 169 | --------- |
| 170 | |
| 171 | Add option ``--json-lines`` to parse every input line as separate JSON object. |
| 172 | (Contributed by Weipeng Hong in :issue:`31553`.) |
| 173 | |
Serhiy Storchaka | 0185f34 | 2018-09-18 11:28:51 +0300 | [diff] [blame] | 174 | os.path |
| 175 | ------- |
| 176 | |
| 177 | :mod:`os.path` functions that return a boolean result like |
| 178 | :func:`~os.path.exists`, :func:`~os.path.lexists`, :func:`~os.path.isdir`, |
| 179 | :func:`~os.path.isfile`, :func:`~os.path.islink`, and :func:`~os.path.ismount` |
| 180 | now return ``False`` instead of raising :exc:`ValueError` or its subclasses |
| 181 | :exc:`UnicodeEncodeError` and :exc:`UnicodeDecodeError` for paths that contain |
| 182 | characters or bytes unrepresentable at the OS level. |
| 183 | (Contributed by Serhiy Storchaka in :issue:`33721`.) |
| 184 | |
Serhiy Storchaka | b232df9 | 2018-10-30 13:22:42 +0200 | [diff] [blame] | 185 | |
| 186 | ncurses |
| 187 | ------- |
| 188 | |
| 189 | Added a new variable holding structured version information for the |
| 190 | underlying ncurses library: :data:`~curses.ncurses_version`. |
| 191 | (Contributed by Serhiy Storchaka in :issue:`31680`.) |
| 192 | |
| 193 | |
Serhiy Storchaka | 0185f34 | 2018-09-18 11:28:51 +0300 | [diff] [blame] | 194 | pathlib |
| 195 | ------- |
| 196 | |
| 197 | :mod:`pathlib.Path` methods that return a boolean result like |
| 198 | :meth:`~pathlib.Path.exists()`, :meth:`~pathlib.Path.is_dir()`, |
| 199 | :meth:`~pathlib.Path.is_file()`, :meth:`~pathlib.Path.is_mount()`, |
| 200 | :meth:`~pathlib.Path.is_symlink()`, :meth:`~pathlib.Path.is_block_device()`, |
| 201 | :meth:`~pathlib.Path.is_char_device()`, :meth:`~pathlib.Path.is_fifo()`, |
| 202 | :meth:`~pathlib.Path.is_socket()` now return ``False`` instead of raising |
| 203 | :exc:`ValueError` or its subclass :exc:`UnicodeEncodeError` for paths that |
| 204 | contain characters unrepresentable at the OS level. |
| 205 | (Contributed by Serhiy Storchaka in :issue:`33721`.) |
| 206 | |
jab | 9e00d9e | 2018-12-28 13:03:40 -0500 | [diff] [blame] | 207 | |
| 208 | shutil |
| 209 | ------ |
| 210 | |
| 211 | :func:`shutil.copytree` now accepts a new ``dirs_exist_ok`` keyword argument. |
| 212 | (Contributed by Josh Bronson in :issue:`20849`.) |
| 213 | |
| 214 | |
Christian Heimes | 9fb051f | 2018-09-23 08:32:31 +0200 | [diff] [blame] | 215 | ssl |
| 216 | --- |
| 217 | |
| 218 | Added :attr:`SSLContext.post_handshake_auth` to enable and |
| 219 | :meth:`ssl.SSLSocket.verify_client_post_handshake` to initiate TLS 1.3 |
| 220 | post-handshake authentication. |
| 221 | (Contributed by Christian Heimes in :issue:`34670`.) |
| 222 | |
Tal Einat | dfba1f6 | 2018-10-24 10:20:05 +0300 | [diff] [blame] | 223 | tokenize |
| 224 | -------- |
| 225 | |
| 226 | The :mod:`tokenize` module now implicitly emits a ``NEWLINE`` token when |
| 227 | provided with input that does not have a trailing new line. This behavior |
| 228 | now matches what the C tokenizer does internally. |
| 229 | (Contributed by Ammar Askar in :issue:`33899`.) |
| 230 | |
Juliette Monsel | af5658a | 2018-10-08 18:29:24 +0200 | [diff] [blame] | 231 | tkinter |
| 232 | ------- |
| 233 | |
| 234 | Added methods :meth:`~tkinter.Spinbox.selection_from`, |
| 235 | :meth:`~tkinter.Spinbox.selection_present`, |
| 236 | :meth:`~tkinter.Spinbox.selection_range` and |
| 237 | :meth:`~tkinter.Spinbox.selection_to` |
| 238 | in the :class:`tkinter.Spinbox` class. |
| 239 | (Contributed by Juliette Monsel in :issue:`34829`.) |
| 240 | |
Juliette Monsel | bf03471 | 2018-10-12 18:44:10 +0200 | [diff] [blame] | 241 | Added method :meth:`~tkinter.Canvas.moveto` |
| 242 | in the :class:`tkinter.Canvas` class. |
| 243 | (Contributed by Juliette Monsel in :issue:`23831`.) |
| 244 | |
Joannah Nanjekye | 572168a | 2019-01-10 19:56:38 +0300 | [diff] [blame] | 245 | time |
| 246 | ---- |
| 247 | |
| 248 | Added new clock :data:`~time.CLOCK_UPTIME_RAW` for macOS 10.12. |
| 249 | (Contributed by Joannah Nanjekye in :issue:`35702`.) |
| 250 | |
Max Bélanger | 2810dd7 | 2018-11-04 15:58:24 -0800 | [diff] [blame] | 251 | unicodedata |
| 252 | ----------- |
| 253 | |
| 254 | * New function :func:`~unicodedata.is_normalized` can be used to verify a string |
| 255 | is in a specific normal form. (Contributed by Max Belanger and David Euresti in |
| 256 | :issue:`32285`). |
| 257 | |
Lisa Roach | 0f221d0 | 2018-11-08 18:34:33 -0800 | [diff] [blame] | 258 | unittest |
| 259 | -------- |
| 260 | |
| 261 | * Added :func:`~unittest.addModuleCleanup()` and |
| 262 | :meth:`~unittest.TestCase.addClassCleanup()` to unittest to support |
| 263 | cleanups for :func:`~unittest.setUpModule()` and |
| 264 | :meth:`~unittest.TestCase.setUpClass()`. |
| 265 | (Contributed by Lisa Roach in :issue:`24412`.) |
| 266 | |
Brett Cannon | d64ee1a | 2018-09-21 15:27:26 -0700 | [diff] [blame] | 267 | venv |
| 268 | ---- |
| 269 | |
| 270 | * :mod:`venv` now includes an ``Activate.ps1`` script on all platforms for |
| 271 | activating virtual environments under PowerShell Core 6.1. |
| 272 | (Contributed by Brett Cannon in :issue:`32718`.) |
| 273 | |
Christian Heimes | 17b1d5d | 2018-09-23 09:50:25 +0200 | [diff] [blame] | 274 | xml |
| 275 | --- |
| 276 | |
| 277 | * As mitigation against DTD and external entity retrieval, the |
Andrés Delfino | ca68261 | 2018-11-07 14:29:14 -0300 | [diff] [blame] | 278 | :mod:`xml.dom.minidom` and :mod:`xml.sax` modules no longer process |
Christian Heimes | 17b1d5d | 2018-09-23 09:50:25 +0200 | [diff] [blame] | 279 | external entities by default. |
| 280 | (Contributed by Christian Heimes in :issue:`17239`.) |
| 281 | |
| 282 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 283 | Optimizations |
| 284 | ============= |
| 285 | |
Victor Stinner | 9daecf3 | 2019-01-16 00:02:35 +0100 | [diff] [blame] | 286 | * The :mod:`subprocess` module can now use the :func:`os.posix_spawn` function |
| 287 | in some cases for better performance. Currently, it is only used on macOS |
| 288 | and Linux (using glibc 2.24 or newer) if all these conditions are met: |
| 289 | |
| 290 | * *close_fds* is false; |
Victor Stinner | f6243ac | 2019-01-23 19:00:39 +0100 | [diff] [blame] | 291 | * *preexec_fn*, *pass_fds*, *cwd* and *start_new_session* parameters |
| 292 | are not set; |
Victor Stinner | 8c34956 | 2019-01-16 23:38:06 +0100 | [diff] [blame] | 293 | * the *executable* path contains a directory. |
Victor Stinner | 9daecf3 | 2019-01-16 00:02:35 +0100 | [diff] [blame] | 294 | |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 295 | * :func:`shutil.copyfile`, :func:`shutil.copy`, :func:`shutil.copy2`, |
| 296 | :func:`shutil.copytree` and :func:`shutil.move` use platform-specific |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 297 | "fast-copy" syscalls on Linux, macOS and Solaris in order to copy the file |
| 298 | more efficiently. |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 299 | "fast-copy" means that the copying operation occurs within the kernel, |
| 300 | avoiding the use of userspace buffers in Python as in |
| 301 | "``outfd.write(infd.read())``". |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 302 | On Windows :func:`shutil.copyfile` uses a bigger default buffer size (1 MiB |
| 303 | instead of 16 KiB) and a :func:`memoryview`-based variant of |
| 304 | :func:`shutil.copyfileobj` is used. |
| 305 | The speedup for copying a 512 MiB file within the same partition is about |
| 306 | +26% on Linux, +50% on macOS and +40% on Windows. Also, much less CPU cycles |
| 307 | are consumed. |
| 308 | See :ref:`shutil-platform-dependent-efficient-copy-operations` section. |
Mariatta | 16501b7 | 2018-12-06 21:59:42 -0800 | [diff] [blame] | 309 | (Contributed by Giampaolo Rodola' in :issue:`33671`.) |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 310 | |
Giampaolo Rodola | 19c46a4 | 2018-11-12 06:18:15 -0800 | [diff] [blame] | 311 | * :func:`shutil.copytree` uses :func:`os.scandir` function and all copy |
| 312 | functions depending from it use cached :func:`os.stat` values. The speedup |
| 313 | for copying a directory with 8000 files is around +9% on Linux, +20% on |
| 314 | Windows and +30% on a Windows SMB share. Also the number of :func:`os.stat` |
| 315 | syscalls is reduced by 38% making :func:`shutil.copytree` especially faster |
| 316 | on network filesystems. (Contributed by Giampaolo Rodola' in :issue:`33695`.) |
| 317 | |
Łukasz Langa | c51d8c9 | 2018-04-03 23:06:53 -0700 | [diff] [blame] | 318 | * The default protocol in the :mod:`pickle` module is now Protocol 4, |
| 319 | first introduced in Python 3.4. It offers better performance and smaller |
| 320 | size compared to Protocol 3 available since Python 3.0. |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 321 | |
INADA Naoki | d5c875b | 2018-07-11 17:42:49 +0900 | [diff] [blame] | 322 | * Removed one ``Py_ssize_t`` member from ``PyGC_Head``. All GC tracked |
| 323 | objects (e.g. tuple, list, dict) size is reduced 4 or 8 bytes. |
| 324 | (Contributed by Inada Naoki in :issue:`33597`) |
| 325 | |
Tal Einat | 5475253 | 2018-09-10 16:11:04 +0300 | [diff] [blame] | 326 | * :class:`uuid.UUID` now uses ``__slots__`` to reduce its memory footprint. |
Tal Einat | 5475253 | 2018-09-10 16:11:04 +0300 | [diff] [blame] | 327 | |
Pablo Galindo | c61e229 | 2018-10-28 22:03:18 +0000 | [diff] [blame] | 328 | * The :class:`list` constructor does not overallocate the internal item buffer |
| 329 | if the input iterable has a known length (the input implements ``__len__``). |
| 330 | This makes the created list 12% smaller on average. (Contributed by Pablo |
| 331 | Galindo in :issue:`33234`.) |
| 332 | |
Serhiy Storchaka | ceeef10 | 2018-06-15 11:09:43 +0300 | [diff] [blame] | 333 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 334 | Build and C API Changes |
| 335 | ======================= |
| 336 | |
Victor Stinner | bf4ac2d | 2019-01-22 17:39:03 +0100 | [diff] [blame] | 337 | * The :c:func:`PyByteArray_Init` and :c:func:`PyByteArray_Fini` functions have |
| 338 | been removed. They did nothing since Python 2.7.4 and Python 3.2.0, were |
| 339 | excluded from the limited API (stable ABI), and were not documented. |
| 340 | |
Serhiy Storchaka | ceeef10 | 2018-06-15 11:09:43 +0300 | [diff] [blame] | 341 | * The result of :c:func:`PyExceptionClass_Name` is now of type |
| 342 | ``const char *`` rather of ``char *``. |
| 343 | (Contributed by Serhiy Storchaka in :issue:`33818`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 344 | |
Antoine Pitrou | 961d54c | 2018-07-16 19:03:03 +0200 | [diff] [blame] | 345 | * The duality of ``Modules/Setup.dist`` and ``Modules/Setup`` has been |
| 346 | removed. Previously, when updating the CPython source tree, one had |
| 347 | to manually copy ``Modules/Setup.dist`` (inside the source tree) to |
| 348 | ``Modules/Setup`` (inside the build tree) in order to reflect any changes |
| 349 | upstream. This was of a small benefit to packagers at the expense of |
| 350 | a frequent annoyance to developers following CPython development, as |
| 351 | forgetting to copy the file could produce build failures. |
| 352 | |
| 353 | Now the build system always reads from ``Modules/Setup`` inside the source |
| 354 | tree. People who want to customize that file are encouraged to maintain |
| 355 | their changes in a git fork of CPython or as patch files, as they would do |
| 356 | for any other change to the source tree. |
| 357 | |
| 358 | (Contributed by Antoine Pitrou in :issue:`32430`.) |
| 359 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 360 | |
| 361 | Deprecated |
| 362 | ========== |
| 363 | |
Serhiy Storchaka | 02ec92f | 2018-07-24 12:03:34 +0300 | [diff] [blame] | 364 | * Deprecated methods ``getchildren()`` and ``getiterator()`` in |
| 365 | the :mod:`~xml.etree.ElementTree` module emit now a |
| 366 | :exc:`DeprecationWarning` instead of :exc:`PendingDeprecationWarning`. |
| 367 | They will be removed in Python 3.9. |
| 368 | (Contributed by Serhiy Storchaka in :issue:`29209`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 369 | |
Elvis Pranskevichus | 22d2508 | 2018-07-30 11:42:43 +0100 | [diff] [blame] | 370 | * Passing an object that is not an instance of |
| 371 | :class:`concurrent.futures.ThreadPoolExecutor` to |
Yury Selivanov | 7c7605f | 2018-09-11 09:54:40 -0700 | [diff] [blame] | 372 | :meth:`asyncio.loop.set_default_executor()` is |
Elvis Pranskevichus | 22d2508 | 2018-07-30 11:42:43 +0100 | [diff] [blame] | 373 | deprecated and will be prohibited in Python 3.9. |
| 374 | (Contributed by Elvis Pranskevichus in :issue:`34075`.) |
| 375 | |
Berker Peksag | ef8861c | 2018-08-21 17:58:49 +0300 | [diff] [blame] | 376 | * The :meth:`__getitem__` methods of :class:`xml.dom.pulldom.DOMEventStream`, |
| 377 | :class:`wsgiref.util.FileWrapper` and :class:`fileinput.FileInput` have been |
| 378 | deprecated. |
| 379 | |
| 380 | Implementations of these methods have been ignoring their *index* parameter, |
| 381 | and returning the next item instead. |
| 382 | |
| 383 | (Contributed by Berker Peksag in :issue:`9372`.) |
| 384 | |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 385 | * :mod:`ast` classes ``Num``, ``Str``, ``Bytes``, ``NameConstant`` and |
| 386 | ``Ellipsis`` are considered deprecated and will be removed in future Python |
| 387 | versions. :class:`~ast.Constant` should be used instead. |
| 388 | (Contributed by Serhiy Storchaka in :issue:`32892`.) |
| 389 | |
Serhiy Storchaka | fec35c9 | 2018-10-27 08:00:41 +0300 | [diff] [blame] | 390 | * The following functions and methods are deprecated in the :mod:`gettext` |
| 391 | module: :func:`~gettext.lgettext`, :func:`~gettext.ldgettext`, |
| 392 | :func:`~gettext.lngettext` and :func:`~gettext.ldngettext`. |
| 393 | They return encoded bytes, and it's possible that you will get unexpected |
| 394 | Unicode-related exceptions if there are encoding problems with the |
| 395 | translated strings. It's much better to use alternatives which return |
| 396 | Unicode strings in Python 3. These functions have been broken for a long time. |
| 397 | |
| 398 | Function :func:`~gettext.bind_textdomain_codeset`, methods |
| 399 | :meth:`~gettext.NullTranslations.output_charset` and |
| 400 | :meth:`~gettext.NullTranslations.set_output_charset`, and the *codeset* |
| 401 | parameter of functions :func:`~gettext.translation` and |
| 402 | :func:`~gettext.install` are also deprecated, since they are only used for |
| 403 | for the ``l*gettext()`` functions. |
| 404 | |
| 405 | (Contributed by Serhiy Storchaka in :issue:`33710`.) |
| 406 | |
Dong-hee Na | 89669ff | 2019-01-17 21:14:45 +0900 | [diff] [blame] | 407 | * The :meth:`~threading.Thread.isAlive()` method of :class:`threading.Thread` has been deprecated. |
| 408 | (Contributed by Dong-hee Na in :issue:`35283`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 409 | |
Victor Stinner | 73104fa | 2018-11-29 09:58:20 +0100 | [diff] [blame] | 410 | API and Feature Removals |
| 411 | ======================== |
| 412 | |
| 413 | The following features and APIs have been removed from Python 3.8: |
| 414 | |
Victor Stinner | d7538dd | 2018-12-14 13:37:26 +0100 | [diff] [blame] | 415 | * The :mod:`macpath` module, deprecated in Python 3.7, has been removed. |
| 416 | (Contributed by Victor Stinner in :issue:`35471`.) |
| 417 | |
Victor Stinner | 73104fa | 2018-11-29 09:58:20 +0100 | [diff] [blame] | 418 | * The function :func:`platform.popen` has been removed, it was deprecated since |
| 419 | Python 3.3: use :func:`os.popen` instead. |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 420 | |
Brett Cannon | a8c3424 | 2018-04-20 14:15:40 -0700 | [diff] [blame] | 421 | * The ``pyvenv`` script has been removed in favor of ``python3.8 -m venv`` |
| 422 | to help eliminate confusion as to what Python interpreter the ``pyvenv`` |
| 423 | script is tied to. (Contributed by Brett Cannon in :issue:`25427`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 424 | |
INADA Naoki | 698865d | 2018-06-19 17:28:50 +0900 | [diff] [blame] | 425 | * ``parse_qs``, ``parse_qsl``, and ``escape`` are removed from :mod:`cgi` |
| 426 | module. They are deprecated from Python 3.2 or older. |
| 427 | |
INADA Naoki | 461a1c4 | 2018-06-28 17:10:36 +0900 | [diff] [blame] | 428 | * ``filemode`` function is removed from :mod:`tarfile` module. |
| 429 | It is not documented and deprecated since Python 3.3. |
INADA Naoki | 698865d | 2018-06-19 17:28:50 +0900 | [diff] [blame] | 430 | |
Serhiy Storchaka | 02ec92f | 2018-07-24 12:03:34 +0300 | [diff] [blame] | 431 | * The :class:`~xml.etree.ElementTree.XMLParser` constructor no longer accepts |
| 432 | the *html* argument. It never had effect and was deprecated in Python 3.4. |
| 433 | All other parameters are now :ref:`keyword-only <keyword-only_parameter>`. |
| 434 | (Contributed by Serhiy Storchaka in :issue:`29209`.) |
| 435 | |
| 436 | * Removed the ``doctype()`` method of :class:`~xml.etree.ElementTree.XMLParser`. |
| 437 | (Contributed by Serhiy Storchaka in :issue:`29209`.) |
| 438 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 439 | |
| 440 | Porting to Python 3.8 |
| 441 | ===================== |
| 442 | |
| 443 | This section lists previously described changes and other bugfixes |
| 444 | that may require changes to your code. |
| 445 | |
| 446 | |
Serhiy Storchaka | 07ca9af | 2018-02-04 10:53:48 +0200 | [diff] [blame] | 447 | Changes in Python behavior |
| 448 | -------------------------- |
| 449 | |
| 450 | * Yield expressions (both ``yield`` and ``yield from`` clauses) are now disallowed |
| 451 | in comprehensions and generator expressions (aside from the iterable expression |
Serhiy Storchaka | 2b57c43 | 2018-12-19 08:09:46 +0200 | [diff] [blame] | 452 | in the leftmost :keyword:`!for` clause). |
Serhiy Storchaka | 07ca9af | 2018-02-04 10:53:48 +0200 | [diff] [blame] | 453 | (Contributed by Serhiy Storchaka in :issue:`10544`.) |
| 454 | |
Serhiy Storchaka | 3bcbedc | 2019-01-18 07:47:48 +0200 | [diff] [blame] | 455 | * The compiler now produces a :exc:`SyntaxWarning` when identity checks |
| 456 | (``is`` and ``is not``) are used with certain types of literals |
| 457 | (e.g. strings, ints). These can often work by accident in CPython, |
| 458 | but are not guaranteed by the language spec. The warning advises users |
| 459 | to use equality tests (``==`` and ``!=``) instead. |
| 460 | (Contributed by Serhiy Storchaka in :issue:`34850`.) |
| 461 | |
Serhiy Storchaka | 07ca9af | 2018-02-04 10:53:48 +0200 | [diff] [blame] | 462 | |
Serhiy Storchaka | 97f1ca1 | 2018-02-01 18:49:21 +0200 | [diff] [blame] | 463 | Changes in the Python API |
| 464 | ------------------------- |
| 465 | |
Victor Stinner | 73104fa | 2018-11-29 09:58:20 +0100 | [diff] [blame] | 466 | * The function :func:`platform.popen` has been removed, it was deprecated since |
| 467 | Python 3.3: use :func:`os.popen` instead. |
| 468 | |
Serhiy Storchaka | 97f1ca1 | 2018-02-01 18:49:21 +0200 | [diff] [blame] | 469 | * The :meth:`~tkinter.ttk.Treeview.selection` method of the |
| 470 | :class:`tkinter.ttk.Treeview` class no longer takes arguments. Using it with |
| 471 | arguments for changing the selection was deprecated in Python 3.6. Use |
| 472 | specialized methods like :meth:`~tkinter.ttk.Treeview.selection_set` for |
| 473 | changing the selection. (Contributed by Serhiy Storchaka in :issue:`31508`.) |
Serhiy Storchaka | 6c85efa5 | 2018-02-05 22:47:31 +0200 | [diff] [blame] | 474 | |
| 475 | * A :mod:`dbm.dumb` database opened with flags ``'r'`` is now read-only. |
| 476 | :func:`dbm.dumb.open` with flags ``'r'`` and ``'w'`` no longer creates |
| 477 | a database if it does not exist. |
| 478 | (Contributed by Serhiy Storchaka in :issue:`32749`.) |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 479 | |
Serhiy Storchaka | 02ec92f | 2018-07-24 12:03:34 +0300 | [diff] [blame] | 480 | * The ``doctype()`` method defined in a subclass of |
| 481 | :class:`~xml.etree.ElementTree.XMLParser` will no longer be called and will |
| 482 | cause emitting a :exc:`RuntimeWarning` instead of a :exc:`DeprecationWarning`. |
| 483 | Define the :meth:`doctype() <xml.etree.ElementTree.TreeBuilder.doctype>` |
| 484 | method on a target for handling an XML doctype declaration. |
| 485 | (Contributed by Serhiy Storchaka in :issue:`29209`.) |
| 486 | |
Serhiy Storchaka | f5e7b19 | 2018-05-20 08:48:12 +0300 | [diff] [blame] | 487 | * A :exc:`RuntimeError` is now raised when the custom metaclass doesn't |
| 488 | provide the ``__classcell__`` entry in the namespace passed to |
| 489 | ``type.__new__``. A :exc:`DeprecationWarning` was emitted in Python |
| 490 | 3.6--3.7. (Contributed by Serhiy Storchaka in :issue:`23722`.) |
| 491 | |
Scott Sanderson | cebe80b | 2018-06-07 05:46:42 -0400 | [diff] [blame] | 492 | * The :class:`cProfile.Profile` class can now be used as a context |
| 493 | manager. (Contributed by Scott Sanderson in :issue:`29235`.) |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 494 | |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 495 | * :func:`shutil.copyfile`, :func:`shutil.copy`, :func:`shutil.copy2`, |
| 496 | :func:`shutil.copytree` and :func:`shutil.move` use platform-specific |
| 497 | "fast-copy" syscalls (see |
| 498 | :ref:`shutil-platform-dependent-efficient-copy-operations` section). |
| 499 | |
| 500 | * :func:`shutil.copyfile` default buffer size on Windows was changed from |
| 501 | 16 KiB to 1 MiB. |
| 502 | |
INADA Naoki | d5c875b | 2018-07-11 17:42:49 +0900 | [diff] [blame] | 503 | * ``PyGC_Head`` struct is changed completely. All code touched the |
| 504 | struct member should be rewritten. (See :issue:`33597`) |
| 505 | |
Alex Grönholm | cca4eec | 2018-08-09 00:06:47 +0300 | [diff] [blame] | 506 | * Asyncio tasks can now be named, either by passing the ``name`` keyword |
| 507 | argument to :func:`asyncio.create_task` or |
Yury Selivanov | 7c7605f | 2018-09-11 09:54:40 -0700 | [diff] [blame] | 508 | the :meth:`~asyncio.loop.create_task` event loop method, or by |
Alex Grönholm | cca4eec | 2018-08-09 00:06:47 +0300 | [diff] [blame] | 509 | calling the :meth:`~asyncio.Task.set_name` method on the task object. The |
| 510 | task name is visible in the ``repr()`` output of :class:`asyncio.Task` and |
| 511 | can also be retrieved using the :meth:`~asyncio.Task.get_name` method. |
| 512 | |
Berker Peksag | e7d4b2f | 2018-08-22 21:21:05 +0300 | [diff] [blame] | 513 | * The :meth:`mmap.flush() <mmap.mmap.flush>` method now returns ``None`` on |
| 514 | success and raises an exception on error under all platforms. Previously, |
| 515 | its behavior was platform-depended: a nonzero value was returned on success; |
| 516 | zero was returned on error under Windows. A zero value was returned on |
| 517 | success; an exception was raised on error under Unix. |
| 518 | (Contributed by Berker Peksag in :issue:`2122`.) |
| 519 | |
Pablo Galindo | fa221d8 | 2018-09-08 00:16:17 +0100 | [diff] [blame] | 520 | * The function :func:`math.factorial` no longer accepts arguments that are not |
| 521 | int-like. (Contributed by Pablo Galindo in :issue:`33083`.) |
| 522 | |
Andrés Delfino | ca68261 | 2018-11-07 14:29:14 -0300 | [diff] [blame] | 523 | * :mod:`xml.dom.minidom` and :mod:`xml.sax` modules no longer process |
Christian Heimes | 17b1d5d | 2018-09-23 09:50:25 +0200 | [diff] [blame] | 524 | external entities by default. |
| 525 | (Contributed by Christian Heimes in :issue:`17239`.) |
INADA Naoki | d5c875b | 2018-07-11 17:42:49 +0900 | [diff] [blame] | 526 | |
Xiang Zhang | 4fb0b8b | 2018-12-12 20:46:55 +0800 | [diff] [blame] | 527 | * Deleting a key from a read-only :mod:`dbm` database (:mod:`dbm.dumb`, |
| 528 | :mod:`dbm.gnu` or :mod:`dbm.ndbm`) raises :attr:`error` (:exc:`dbm.dumb.error`, |
| 529 | :exc:`dbm.gnu.error` or :exc:`dbm.ndbm.error`) instead of :exc:`KeyError`. |
| 530 | (Contributed by Xiang Zhang in :issue:`33106`.) |
| 531 | |
| 532 | |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 533 | CPython bytecode changes |
| 534 | ------------------------ |
| 535 | |
| 536 | * The interpreter loop has been simplified by moving the logic of unrolling |
| 537 | the stack of blocks into the compiler. The compiler emits now explicit |
Serhiy Storchaka | 3f819ca | 2018-10-31 02:26:06 +0200 | [diff] [blame] | 538 | instructions for adjusting the stack of values and calling the |
| 539 | cleaning-up code for :keyword:`break`, :keyword:`continue` and |
| 540 | :keyword:`return`. |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 541 | |
| 542 | Removed opcodes :opcode:`BREAK_LOOP`, :opcode:`CONTINUE_LOOP`, |
| 543 | :opcode:`SETUP_LOOP` and :opcode:`SETUP_EXCEPT`. Added new opcodes |
| 544 | :opcode:`ROT_FOUR`, :opcode:`BEGIN_FINALLY`, :opcode:`CALL_FINALLY` and |
| 545 | :opcode:`POP_FINALLY`. Changed the behavior of :opcode:`END_FINALLY` |
| 546 | and :opcode:`WITH_CLEANUP_START`. |
| 547 | |
| 548 | (Contributed by Mark Shannon, Antoine Pitrou and Serhiy Storchaka in |
| 549 | :issue:`17611`.) |
Serhiy Storchaka | 702f8f3 | 2018-03-23 14:34:35 +0200 | [diff] [blame] | 550 | |
| 551 | * Added new opcode :opcode:`END_ASYNC_FOR` for handling exceptions raised |
| 552 | when awaiting a next item in an :keyword:`async for` loop. |
| 553 | (Contributed by Serhiy Storchaka in :issue:`33041`.) |