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 | |
Guido van Rossum | 09d434c | 2019-04-24 11:30:17 -0700 | [diff] [blame] | 70 | Assignment expressions |
| 71 | ---------------------- |
| 72 | |
| 73 | There is new syntax (the "walrus operator", ``:=``) to assign values |
| 74 | to variables as part of an expression. Example:: |
| 75 | |
| 76 | if (n := len(a)) > 10: |
| 77 | print(f"List is too long ({n} elements, expected <= 10)") |
| 78 | |
| 79 | See :pep:`572` for a full description. |
| 80 | |
| 81 | (Contributed by Emily Morehouse in :issue:`35224`.) |
| 82 | |
| 83 | .. TODO: Emily will sprint on docs at PyCon US 2019. |
| 84 | |
| 85 | |
Nick Coghlan | 16eb3bc | 2018-06-20 21:25:01 +1000 | [diff] [blame] | 86 | Parallel filesystem cache for compiled bytecode files |
| 87 | ----------------------------------------------------- |
| 88 | |
| 89 | The new :envvar:`PYTHONPYCACHEPREFIX` setting (also available as |
| 90 | :option:`-X` ``pycache_prefix``) configures the implicit bytecode |
| 91 | cache to use a separate parallel filesystem tree, rather than |
| 92 | the default ``__pycache__`` subdirectories within each source |
| 93 | directory. |
| 94 | |
| 95 | The location of the cache is reported in :data:`sys.pycache_prefix` |
| 96 | (:const:`None` indicates the default location in ``__pycache__`` |
| 97 | subdirectories). |
| 98 | |
| 99 | (Contributed by Carl Meyer in :issue:`33499`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 100 | |
| 101 | |
| 102 | Other Language Changes |
| 103 | ====================== |
| 104 | |
Serhiy Storchaka | fe2bbb1 | 2018-03-18 09:56:52 +0200 | [diff] [blame] | 105 | * A :keyword:`continue` statement was illegal in the :keyword:`finally` clause |
| 106 | due to a problem with the implementation. In Python 3.8 this restriction |
| 107 | was lifted. |
| 108 | (Contributed by Serhiy Storchaka in :issue:`32489`.) |
| 109 | |
Serhiy Storchaka | b2e2025 | 2018-10-20 00:46:31 +0300 | [diff] [blame] | 110 | * The :class:`int` type now has a new :meth:`~int.as_integer_ratio` method |
| 111 | compatible with the existing :meth:`float.as_integer_ratio` method. |
Lisa Roach | 5ac7043 | 2018-09-13 23:56:23 -0700 | [diff] [blame] | 112 | (Contributed by Lisa Roach in :issue:`33073`.) |
| 113 | |
Serhiy Storchaka | a445feb | 2018-02-10 00:08:17 +0200 | [diff] [blame] | 114 | * Added support of ``\N{name}`` escapes in :mod:`regular expressions <re>`. |
| 115 | (Contributed by Jonathan Eunice and Serhiy Storchaka in :issue:`30688`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 116 | |
Rémi Lapeyre | 6531bf6 | 2018-11-06 01:38:54 +0100 | [diff] [blame] | 117 | * Dict and dictviews are now iterable in reversed insertion order using |
| 118 | :func:`reversed`. (Contributed by Rémi Lapeyre in :issue:`33462`.) |
| 119 | |
Benjamin Peterson | c9a71dd | 2018-09-12 17:14:39 -0700 | [diff] [blame] | 120 | * The syntax allowed for keyword names in function calls was further |
| 121 | restricted. In particular, ``f((keyword)=arg)`` is no longer allowed. It was |
| 122 | never intended to permit more than a bare name on the left-hand side of a |
| 123 | keyword argument assignment term. See :issue:`34641`. |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 124 | |
jChapman | 8fabae3 | 2018-09-22 21:13:10 -0400 | [diff] [blame] | 125 | * Iterable unpacking is now allowed without parentheses in :keyword:`yield` |
| 126 | and :keyword:`return` statements. |
| 127 | (Contributed by David Cuthbert and Jordan Chapman in :issue:`32117`.) |
| 128 | |
Serhiy Storchaka | 6543912 | 2018-10-19 17:42:06 +0300 | [diff] [blame] | 129 | * A backslash-character pair that is not a valid escape sequence generates |
| 130 | a :exc:`DeprecationWarning` since Python 3.6. In Python 3.8 it generates |
| 131 | a :exc:`SyntaxWarning` instead. |
| 132 | (Contributed by Serhiy Storchaka in :issue:`32912`.) |
| 133 | |
Serhiy Storchaka | 62e4481 | 2019-02-16 08:12:19 +0200 | [diff] [blame] | 134 | * The compiler now produces a :exc:`SyntaxWarning` in some cases when a comma |
| 135 | is missed before tuple or list. For example:: |
| 136 | |
| 137 | data = [ |
| 138 | (1, 2, 3) # oops, missing comma! |
| 139 | (4, 5, 6) |
| 140 | ] |
| 141 | |
| 142 | (Contributed by Serhiy Storchaka in :issue:`15248`.) |
| 143 | |
Paul Ganssle | d9503c3 | 2019-02-08 11:02:00 -0500 | [diff] [blame] | 144 | * Arithmetic operations between subclasses of :class:`datetime.date` or |
| 145 | :class:`datetime.datetime` and :class:`datetime.timedelta` objects now return |
| 146 | an instance of the subclass, rather than the base class. This also affects |
| 147 | the return type of operations whose implementation (directly or indirectly) |
| 148 | uses :class:`datetime.timedelta` arithmetic, such as |
| 149 | :meth:`datetime.datetime.astimezone`. |
| 150 | (Contributed by Paul Ganssle in :issue:`32417`.) |
| 151 | |
Gregory P. Smith | 06babb2 | 2019-02-23 10:43:49 -0800 | [diff] [blame] | 152 | * When the Python interpreter is interrupted by Ctrl-C (SIGINT) and the |
| 153 | resulting :exc:`KeyboardInterrupt` exception is not caught, the Python process |
| 154 | now exits via a SIGINT signal or with the correct exit code such that the |
| 155 | calling process can detect that it died due to a Ctrl-C. Shells on POSIX |
| 156 | and Windows use this to properly terminate scripts in interactive sessions. |
| 157 | (Contributed by Google via Gregory P. Smith in :issue:`1054041`.) |
| 158 | |
Serhiy Storchaka | 6543912 | 2018-10-19 17:42:06 +0300 | [diff] [blame] | 159 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 160 | New Modules |
| 161 | =========== |
| 162 | |
| 163 | * None yet. |
| 164 | |
| 165 | |
| 166 | Improved Modules |
| 167 | ================ |
| 168 | |
Raymond Hettinger | 0bb4bdf | 2019-01-31 00:59:50 -0800 | [diff] [blame] | 169 | * The :meth:`_asdict()` method for :func:`collections.namedtuple` now returns |
| 170 | a :class:`dict` instead of a :class:`collections.OrderedDict`. This works because |
| 171 | regular dicts have guaranteed ordering in since Python 3.7. If the extra |
| 172 | features of :class:`OrderedDict` are required, the suggested remediation is |
| 173 | to cast the result to the desired type: ``OrderedDict(nt._asdict())``. |
| 174 | (Contributed by Raymond Hettinger in :issue:`35864`.) |
| 175 | |
Benjamin Peterson | 738c19f | 2019-03-09 16:25:55 -0800 | [diff] [blame] | 176 | * The :mod:`unicodedata` module has been upgraded to use the `Unicode 12.0.0 |
| 177 | <http://blog.unicode.org/2019/03/announcing-unicode-standard-version-120.html>`_ |
| 178 | release. |
| 179 | |
Raymond Hettinger | 0bb4bdf | 2019-01-31 00:59:50 -0800 | [diff] [blame] | 180 | |
Victor Stinner | 6ea29c5 | 2018-09-25 08:27:08 -0700 | [diff] [blame] | 181 | asyncio |
| 182 | ------- |
| 183 | |
| 184 | On Windows, the default event loop is now :class:`~asyncio.ProactorEventLoop`. |
| 185 | |
Terry Jan Reedy | fdcb5ae | 2018-09-25 12:45:27 -0400 | [diff] [blame] | 186 | |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 187 | ctypes |
| 188 | ------ |
| 189 | |
| 190 | On Windows, :class:`~ctypes.CDLL` and subclasses now accept a *winmode* parameter |
| 191 | to specify flags for the underlying ``LoadLibraryEx`` call. The default flags are |
| 192 | set to only load DLL dependencies from trusted locations, including the path |
| 193 | where the DLL is stored (if a full or partial path is used to load the initial |
| 194 | DLL) and paths added by :func:`~os.add_dll_directory`. |
| 195 | |
| 196 | |
Cheryl Sabella | 637a33b | 2018-11-07 09:12:20 -0500 | [diff] [blame] | 197 | gettext |
| 198 | ------- |
| 199 | |
| 200 | Added :func:`~gettext.pgettext` and its variants. |
| 201 | (Contributed by Franz Glasner, Éric Araujo, and Cheryl Sabella in :issue:`2504`.) |
| 202 | |
Raymond Hettinger | d1e768a | 2019-03-25 13:01:13 -0700 | [diff] [blame] | 203 | inspect |
| 204 | ------- |
| 205 | |
| 206 | The :func:`inspect.getdoc` function can now find docstrings for ``__slots__`` |
| 207 | if that attribute is a :class:`dict` where the values are docstrings. |
| 208 | This provides documentation options similar to what we already have |
| 209 | for :func:`property`, :func:`classmethod`, and :func:`staticmethod`:: |
| 210 | |
| 211 | class AudioClip: |
| 212 | __slots__ = {'bit_rate': 'expressed in kilohertz to one decimal place', |
| 213 | 'duration': 'in seconds, rounded up to an integer'} |
| 214 | def __init__(self, bit_rate, duration): |
| 215 | self.bit_rate = round(bit_rate / 1000.0, 1) |
| 216 | self.duration = ceil(duration) |
Pablo Galindo | 175421b | 2019-02-23 03:02:06 +0000 | [diff] [blame] | 217 | |
| 218 | gc |
| 219 | -- |
| 220 | |
| 221 | :func:`~gc.get_objects` can now receive an optional *generation* parameter |
| 222 | indicating a generation to get objects from. Contributed in |
| 223 | :issue:`36016` by Pablo Galindo. |
| 224 | |
| 225 | |
guoci | 0e7497c | 2018-11-07 04:50:23 -0500 | [diff] [blame] | 226 | gzip |
| 227 | ---- |
| 228 | |
| 229 | Added the *mtime* parameter to :func:`gzip.compress` for reproducible output. |
| 230 | (Contributed by Guo Ci Teo in :issue:`34898`.) |
| 231 | |
| 232 | |
Terry Jan Reedy | fdcb5ae | 2018-09-25 12:45:27 -0400 | [diff] [blame] | 233 | idlelib and IDLE |
| 234 | ---------------- |
| 235 | |
| 236 | Output over N lines (50 by default) is squeezed down to a button. |
| 237 | N can be changed in the PyShell section of the General page of the |
| 238 | Settings dialog. Fewer, but possibly extra long, lines can be squeezed by |
| 239 | right clicking on the output. Squeezed output can be expanded in place |
| 240 | by double-clicking the button or into the clipboard or a separate window |
| 241 | by right-clicking the button. (Contributed by Tal Einat in :issue:`1529353`.) |
| 242 | |
| 243 | The changes above have been backported to 3.7 maintenance releases. |
| 244 | |
| 245 | |
HongWeipeng | f194479 | 2018-11-07 18:09:32 +0800 | [diff] [blame] | 246 | json.tool |
| 247 | --------- |
| 248 | |
| 249 | Add option ``--json-lines`` to parse every input line as separate JSON object. |
| 250 | (Contributed by Weipeng Hong in :issue:`31553`.) |
| 251 | |
Pablo Galindo | bc09851 | 2019-02-07 07:04:02 +0000 | [diff] [blame] | 252 | |
| 253 | math |
| 254 | ---- |
| 255 | |
Raymond Hettinger | 3ff5962 | 2019-02-16 11:00:42 -0800 | [diff] [blame] | 256 | Added new function :func:`math.dist` for computing Euclidean distance |
| 257 | between two points. (Contributed by Raymond Hettinger in :issue:`33089`.) |
| 258 | |
| 259 | Expanded the :func:`math.hypot` function to handle multiple dimensions. |
| 260 | Formerly, it only supported the 2-D case. |
| 261 | (Contributed by Raymond Hettinger in :issue:`33089`.) |
| 262 | |
Pablo Galindo | bc09851 | 2019-02-07 07:04:02 +0000 | [diff] [blame] | 263 | Added new function, :func:`math.prod`, as analogous function to :func:`sum` |
| 264 | that returns the product of a 'start' value (default: 1) times an iterable of |
Raymond Hettinger | 3ff5962 | 2019-02-16 11:00:42 -0800 | [diff] [blame] | 265 | numbers. (Contributed by Pablo Galindo in :issue:`35606`) |
Pablo Galindo | bc09851 | 2019-02-07 07:04:02 +0000 | [diff] [blame] | 266 | |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 267 | os |
| 268 | -- |
| 269 | |
| 270 | Added new function :func:`~os.add_dll_directory` on Windows for providing |
| 271 | additional search paths for native dependencies when importing extension |
| 272 | modules or loading DLLs using :mod:`ctypes`. |
| 273 | |
Pablo Galindo | bc09851 | 2019-02-07 07:04:02 +0000 | [diff] [blame] | 274 | |
Serhiy Storchaka | 0185f34 | 2018-09-18 11:28:51 +0300 | [diff] [blame] | 275 | os.path |
| 276 | ------- |
| 277 | |
| 278 | :mod:`os.path` functions that return a boolean result like |
| 279 | :func:`~os.path.exists`, :func:`~os.path.lexists`, :func:`~os.path.isdir`, |
| 280 | :func:`~os.path.isfile`, :func:`~os.path.islink`, and :func:`~os.path.ismount` |
| 281 | now return ``False`` instead of raising :exc:`ValueError` or its subclasses |
| 282 | :exc:`UnicodeEncodeError` and :exc:`UnicodeDecodeError` for paths that contain |
| 283 | characters or bytes unrepresentable at the OS level. |
| 284 | (Contributed by Serhiy Storchaka in :issue:`33721`.) |
| 285 | |
Steve Dower | 8ef864d | 2019-03-12 15:15:26 -0700 | [diff] [blame] | 286 | :func:`~os.path.expanduser` on Windows now prefers the :envvar:`USERPROFILE` |
| 287 | environment variable and does not use :envvar:`HOME`, which is not normally set |
| 288 | for regular user accounts. |
| 289 | |
Serhiy Storchaka | b232df9 | 2018-10-30 13:22:42 +0200 | [diff] [blame] | 290 | |
| 291 | ncurses |
| 292 | ------- |
| 293 | |
| 294 | Added a new variable holding structured version information for the |
| 295 | underlying ncurses library: :data:`~curses.ncurses_version`. |
| 296 | (Contributed by Serhiy Storchaka in :issue:`31680`.) |
| 297 | |
| 298 | |
Serhiy Storchaka | 0185f34 | 2018-09-18 11:28:51 +0300 | [diff] [blame] | 299 | pathlib |
| 300 | ------- |
| 301 | |
| 302 | :mod:`pathlib.Path` methods that return a boolean result like |
| 303 | :meth:`~pathlib.Path.exists()`, :meth:`~pathlib.Path.is_dir()`, |
| 304 | :meth:`~pathlib.Path.is_file()`, :meth:`~pathlib.Path.is_mount()`, |
| 305 | :meth:`~pathlib.Path.is_symlink()`, :meth:`~pathlib.Path.is_block_device()`, |
| 306 | :meth:`~pathlib.Path.is_char_device()`, :meth:`~pathlib.Path.is_fifo()`, |
| 307 | :meth:`~pathlib.Path.is_socket()` now return ``False`` instead of raising |
| 308 | :exc:`ValueError` or its subclass :exc:`UnicodeEncodeError` for paths that |
| 309 | contain characters unrepresentable at the OS level. |
| 310 | (Contributed by Serhiy Storchaka in :issue:`33721`.) |
| 311 | |
jab | 9e00d9e | 2018-12-28 13:03:40 -0500 | [diff] [blame] | 312 | |
Giampaolo Rodola | eb7e29f | 2019-04-09 00:34:02 +0200 | [diff] [blame] | 313 | socket |
| 314 | ------ |
| 315 | |
| 316 | Added :meth:`~socket.create_server()` and :meth:`~socket.has_dualstack_ipv6()` |
| 317 | convenience functions to automate the necessary tasks usually involved when |
| 318 | creating a server socket, including accepting both IPv4 and IPv6 connections |
| 319 | on the same socket. (Contributed by Giampaolo Rodola in :issue:`17561`.) |
| 320 | |
| 321 | |
jab | 9e00d9e | 2018-12-28 13:03:40 -0500 | [diff] [blame] | 322 | shutil |
| 323 | ------ |
| 324 | |
| 325 | :func:`shutil.copytree` now accepts a new ``dirs_exist_ok`` keyword argument. |
| 326 | (Contributed by Josh Bronson in :issue:`20849`.) |
| 327 | |
CAM Gerlach | 89a8944 | 2019-04-06 23:47:49 -0500 | [diff] [blame] | 328 | :func:`shutil.make_archive` now defaults to the modern pax (POSIX.1-2001) |
| 329 | format for new archives to improve portability and standards conformance, |
| 330 | inherited from the corresponding change to the :mod:`tarfile` module. |
| 331 | (Contributed by C.A.M. Gerlach in :issue:`30661`.) |
| 332 | |
jab | 9e00d9e | 2018-12-28 13:03:40 -0500 | [diff] [blame] | 333 | |
Christian Heimes | 9fb051f | 2018-09-23 08:32:31 +0200 | [diff] [blame] | 334 | ssl |
| 335 | --- |
| 336 | |
| 337 | Added :attr:`SSLContext.post_handshake_auth` to enable and |
| 338 | :meth:`ssl.SSLSocket.verify_client_post_handshake` to initiate TLS 1.3 |
| 339 | post-handshake authentication. |
| 340 | (Contributed by Christian Heimes in :issue:`34670`.) |
| 341 | |
Raymond Hettinger | 47d9987 | 2019-02-21 15:06:29 -0800 | [diff] [blame] | 342 | |
| 343 | statistics |
| 344 | ---------- |
| 345 | |
| 346 | Added :func:`statistics.fmean` as a faster, floating point variant of |
| 347 | :func:`statistics.mean()`. (Contributed by Raymond Hettinger and |
| 348 | Steven D'Aprano in :issue:`35904`.) |
| 349 | |
Raymond Hettinger | 6463ba3 | 2019-04-07 09:20:03 -0700 | [diff] [blame] | 350 | Added :func:`statistics.geometric_mean()` |
| 351 | (Contributed by Raymond Hettinger in :issue:`27181`.) |
| 352 | |
Raymond Hettinger | fc06a19 | 2019-03-12 00:43:27 -0700 | [diff] [blame] | 353 | Added :func:`statistics.multimode` that returns a list of the most |
| 354 | common values. (Contributed by Raymond Hettinger in :issue:`35892`.) |
| 355 | |
Raymond Hettinger | 9013ccf | 2019-04-23 00:06:35 -0700 | [diff] [blame] | 356 | Added :func:`statistics.quantiles` that divides data or a distribution |
| 357 | in to equiprobable intervals (e.g. quartiles, deciles, or percentiles). |
| 358 | (Contributed by Raymond Hettinger in :issue:`36546`.) |
| 359 | |
Raymond Hettinger | 11c7953 | 2019-02-23 14:44:07 -0800 | [diff] [blame] | 360 | Added :class:`statistics.NormalDist`, a tool for creating |
| 361 | and manipulating normal distributions of a random variable. |
| 362 | (Contributed by Raymond Hettinger in :issue:`36018`.) |
| 363 | |
| 364 | :: |
| 365 | |
| 366 | >>> temperature_feb = NormalDist.from_samples([4, 12, -3, 2, 7, 14]) |
| 367 | >>> temperature_feb |
| 368 | NormalDist(mu=6.0, sigma=6.356099432828281) |
| 369 | |
| 370 | >>> temperature_feb.cdf(3) # Chance of being under 3 degrees |
| 371 | 0.3184678262814532 |
| 372 | >>> # Relative chance of being 7 degrees versus 10 degrees |
| 373 | >>> temperature_feb.pdf(7) / temperature_feb.pdf(10) |
| 374 | 1.2039930378537762 |
| 375 | |
| 376 | >>> el_nino = NormalDist(4, 2.5) |
| 377 | >>> temperature_feb += el_nino # Add in a climate effect |
| 378 | >>> temperature_feb |
| 379 | NormalDist(mu=10.0, sigma=6.830080526611674) |
| 380 | |
| 381 | >>> temperature_feb * (9/5) + 32 # Convert to Fahrenheit |
| 382 | NormalDist(mu=50.0, sigma=12.294144947901014) |
| 383 | >>> temperature_feb.samples(3) # Generate random samples |
| 384 | [7.672102882379219, 12.000027119750287, 4.647488369766392] |
| 385 | |
Raymond Hettinger | 47d9987 | 2019-02-21 15:06:29 -0800 | [diff] [blame] | 386 | |
CAM Gerlach | e680c3d | 2019-03-21 09:44:51 -0500 | [diff] [blame] | 387 | tarfile |
| 388 | ------- |
| 389 | |
| 390 | The :mod:`tarfile` module now defaults to the modern pax (POSIX.1-2001) |
| 391 | format for new archives, instead of the previous GNU-specific one. |
| 392 | This improves cross-platform portability with a consistent encoding (UTF-8) |
| 393 | in a standardized and extensible format, and offers several other benefits. |
| 394 | (Contributed by C.A.M. Gerlach in :issue:`36268`.) |
| 395 | |
| 396 | |
Tal Einat | dfba1f6 | 2018-10-24 10:20:05 +0300 | [diff] [blame] | 397 | tokenize |
| 398 | -------- |
| 399 | |
| 400 | The :mod:`tokenize` module now implicitly emits a ``NEWLINE`` token when |
| 401 | provided with input that does not have a trailing new line. This behavior |
| 402 | now matches what the C tokenizer does internally. |
| 403 | (Contributed by Ammar Askar in :issue:`33899`.) |
| 404 | |
Juliette Monsel | af5658a | 2018-10-08 18:29:24 +0200 | [diff] [blame] | 405 | tkinter |
| 406 | ------- |
| 407 | |
| 408 | Added methods :meth:`~tkinter.Spinbox.selection_from`, |
| 409 | :meth:`~tkinter.Spinbox.selection_present`, |
| 410 | :meth:`~tkinter.Spinbox.selection_range` and |
| 411 | :meth:`~tkinter.Spinbox.selection_to` |
| 412 | in the :class:`tkinter.Spinbox` class. |
| 413 | (Contributed by Juliette Monsel in :issue:`34829`.) |
| 414 | |
Juliette Monsel | bf03471 | 2018-10-12 18:44:10 +0200 | [diff] [blame] | 415 | Added method :meth:`~tkinter.Canvas.moveto` |
| 416 | in the :class:`tkinter.Canvas` class. |
| 417 | (Contributed by Juliette Monsel in :issue:`23831`.) |
| 418 | |
Zackery Spytz | 50866e9 | 2019-04-05 04:17:13 -0600 | [diff] [blame] | 419 | The :class:`tkinter.PhotoImage` class now has |
| 420 | :meth:`~tkinter.PhotoImage.transparency_get` and |
| 421 | :meth:`~tkinter.PhotoImage.transparency_set` methods. (Contributed by |
| 422 | Zackery Spytz in :issue:`25451`.) |
| 423 | |
Joannah Nanjekye | 572168a | 2019-01-10 19:56:38 +0300 | [diff] [blame] | 424 | time |
| 425 | ---- |
| 426 | |
| 427 | Added new clock :data:`~time.CLOCK_UPTIME_RAW` for macOS 10.12. |
| 428 | (Contributed by Joannah Nanjekye in :issue:`35702`.) |
| 429 | |
Max Bélanger | 2810dd7 | 2018-11-04 15:58:24 -0800 | [diff] [blame] | 430 | unicodedata |
| 431 | ----------- |
| 432 | |
| 433 | * New function :func:`~unicodedata.is_normalized` can be used to verify a string |
| 434 | is in a specific normal form. (Contributed by Max Belanger and David Euresti in |
| 435 | :issue:`32285`). |
| 436 | |
Lisa Roach | 0f221d0 | 2018-11-08 18:34:33 -0800 | [diff] [blame] | 437 | unittest |
| 438 | -------- |
| 439 | |
| 440 | * Added :func:`~unittest.addModuleCleanup()` and |
| 441 | :meth:`~unittest.TestCase.addClassCleanup()` to unittest to support |
| 442 | cleanups for :func:`~unittest.setUpModule()` and |
| 443 | :meth:`~unittest.TestCase.setUpClass()`. |
| 444 | (Contributed by Lisa Roach in :issue:`24412`.) |
| 445 | |
Brett Cannon | d64ee1a | 2018-09-21 15:27:26 -0700 | [diff] [blame] | 446 | venv |
| 447 | ---- |
| 448 | |
| 449 | * :mod:`venv` now includes an ``Activate.ps1`` script on all platforms for |
| 450 | activating virtual environments under PowerShell Core 6.1. |
| 451 | (Contributed by Brett Cannon in :issue:`32718`.) |
| 452 | |
Christian Heimes | 17b1d5d | 2018-09-23 09:50:25 +0200 | [diff] [blame] | 453 | xml |
| 454 | --- |
| 455 | |
| 456 | * As mitigation against DTD and external entity retrieval, the |
Andrés Delfino | ca68261 | 2018-11-07 14:29:14 -0300 | [diff] [blame] | 457 | :mod:`xml.dom.minidom` and :mod:`xml.sax` modules no longer process |
Christian Heimes | 17b1d5d | 2018-09-23 09:50:25 +0200 | [diff] [blame] | 458 | external entities by default. |
| 459 | (Contributed by Christian Heimes in :issue:`17239`.) |
| 460 | |
| 461 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 462 | Optimizations |
| 463 | ============= |
| 464 | |
Victor Stinner | 9daecf3 | 2019-01-16 00:02:35 +0100 | [diff] [blame] | 465 | * The :mod:`subprocess` module can now use the :func:`os.posix_spawn` function |
| 466 | in some cases for better performance. Currently, it is only used on macOS |
| 467 | and Linux (using glibc 2.24 or newer) if all these conditions are met: |
| 468 | |
| 469 | * *close_fds* is false; |
Victor Stinner | f6243ac | 2019-01-23 19:00:39 +0100 | [diff] [blame] | 470 | * *preexec_fn*, *pass_fds*, *cwd* and *start_new_session* parameters |
| 471 | are not set; |
Victor Stinner | 8c34956 | 2019-01-16 23:38:06 +0100 | [diff] [blame] | 472 | * the *executable* path contains a directory. |
Victor Stinner | 9daecf3 | 2019-01-16 00:02:35 +0100 | [diff] [blame] | 473 | |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 474 | * :func:`shutil.copyfile`, :func:`shutil.copy`, :func:`shutil.copy2`, |
| 475 | :func:`shutil.copytree` and :func:`shutil.move` use platform-specific |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 476 | "fast-copy" syscalls on Linux, macOS and Solaris in order to copy the file |
| 477 | more efficiently. |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 478 | "fast-copy" means that the copying operation occurs within the kernel, |
| 479 | avoiding the use of userspace buffers in Python as in |
| 480 | "``outfd.write(infd.read())``". |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 481 | On Windows :func:`shutil.copyfile` uses a bigger default buffer size (1 MiB |
| 482 | instead of 16 KiB) and a :func:`memoryview`-based variant of |
| 483 | :func:`shutil.copyfileobj` is used. |
| 484 | The speedup for copying a 512 MiB file within the same partition is about |
| 485 | +26% on Linux, +50% on macOS and +40% on Windows. Also, much less CPU cycles |
| 486 | are consumed. |
| 487 | See :ref:`shutil-platform-dependent-efficient-copy-operations` section. |
Mariatta | 16501b7 | 2018-12-06 21:59:42 -0800 | [diff] [blame] | 488 | (Contributed by Giampaolo Rodola' in :issue:`33671`.) |
Giampaolo Rodola | 4a172cc | 2018-06-12 23:04:50 +0200 | [diff] [blame] | 489 | |
Giampaolo Rodola | 19c46a4 | 2018-11-12 06:18:15 -0800 | [diff] [blame] | 490 | * :func:`shutil.copytree` uses :func:`os.scandir` function and all copy |
| 491 | functions depending from it use cached :func:`os.stat` values. The speedup |
| 492 | for copying a directory with 8000 files is around +9% on Linux, +20% on |
| 493 | Windows and +30% on a Windows SMB share. Also the number of :func:`os.stat` |
| 494 | syscalls is reduced by 38% making :func:`shutil.copytree` especially faster |
| 495 | on network filesystems. (Contributed by Giampaolo Rodola' in :issue:`33695`.) |
| 496 | |
Łukasz Langa | c51d8c9 | 2018-04-03 23:06:53 -0700 | [diff] [blame] | 497 | * The default protocol in the :mod:`pickle` module is now Protocol 4, |
| 498 | first introduced in Python 3.4. It offers better performance and smaller |
| 499 | size compared to Protocol 3 available since Python 3.0. |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 500 | |
INADA Naoki | d5c875b | 2018-07-11 17:42:49 +0900 | [diff] [blame] | 501 | * Removed one ``Py_ssize_t`` member from ``PyGC_Head``. All GC tracked |
| 502 | objects (e.g. tuple, list, dict) size is reduced 4 or 8 bytes. |
| 503 | (Contributed by Inada Naoki in :issue:`33597`) |
| 504 | |
Tal Einat | 5475253 | 2018-09-10 16:11:04 +0300 | [diff] [blame] | 505 | * :class:`uuid.UUID` now uses ``__slots__`` to reduce its memory footprint. |
Tal Einat | 5475253 | 2018-09-10 16:11:04 +0300 | [diff] [blame] | 506 | |
Raymond Hettinger | 63fa1cf | 2019-02-16 12:02:22 -0800 | [diff] [blame] | 507 | * Improved performance of :func:`operator.itemgetter` by 33%. Optimized |
| 508 | argument handling and added a fast path for the common case of a single |
| 509 | non-negative integer index into a tuple (which is the typical use case in |
| 510 | the standard library). (Contributed by Raymond Hettinger in |
| 511 | :issue:`35664`.) |
| 512 | |
| 513 | * Sped-up field lookups in :func:`collections.namedtuple`. They are now more |
| 514 | than two times faster, making them the fastest form of instance variable |
| 515 | lookup in Python. (Contributed by Raymond Hettinger, Pablo Galindo, and |
Joe Jevnik | f36f892 | 2019-02-21 16:00:40 -0500 | [diff] [blame] | 516 | Joe Jevnik, Serhiy Storchaka in :issue:`32492`.) |
Raymond Hettinger | 63fa1cf | 2019-02-16 12:02:22 -0800 | [diff] [blame] | 517 | |
Pablo Galindo | c61e229 | 2018-10-28 22:03:18 +0000 | [diff] [blame] | 518 | * The :class:`list` constructor does not overallocate the internal item buffer |
| 519 | if the input iterable has a known length (the input implements ``__len__``). |
Raymond Hettinger | e182318 | 2019-02-16 12:47:48 -0800 | [diff] [blame] | 520 | This makes the created list 12% smaller on average. (Contributed by |
| 521 | Raymond Hettinger and Pablo Galindo in :issue:`33234`.) |
Pablo Galindo | c61e229 | 2018-10-28 22:03:18 +0000 | [diff] [blame] | 522 | |
Stefan Behnel | d8b9e1f | 2019-02-20 18:29:24 +0100 | [diff] [blame] | 523 | * Doubled the speed of class variable writes. When a non-dunder attribute |
| 524 | was updated, there was an unnecessary call to update slots. |
| 525 | (Contributed by Stefan Behnel, Pablo Galindo Salgado, Raymond Hettinger, |
| 526 | Neil Schemenauer, and Serhiy Storchaka in :issue:`36012`.) |
| 527 | |
Serhiy Storchaka | 3191391 | 2019-03-14 10:32:22 +0200 | [diff] [blame] | 528 | * Reduced an overhead of converting arguments passed to many builtin functions |
| 529 | and methods. This sped up calling some simple builtin functions and |
| 530 | methods up to 20--50%. (Contributed by Serhiy Storchaka in :issue:`23867`, |
| 531 | :issue:`35582` and :issue:`36127`.) |
| 532 | |
Serhiy Storchaka | ceeef10 | 2018-06-15 11:09:43 +0300 | [diff] [blame] | 533 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 534 | Build and C API Changes |
| 535 | ======================= |
| 536 | |
Victor Stinner | bf4ac2d | 2019-01-22 17:39:03 +0100 | [diff] [blame] | 537 | * The :c:func:`PyByteArray_Init` and :c:func:`PyByteArray_Fini` functions have |
| 538 | been removed. They did nothing since Python 2.7.4 and Python 3.2.0, were |
| 539 | excluded from the limited API (stable ABI), and were not documented. |
| 540 | |
Serhiy Storchaka | ceeef10 | 2018-06-15 11:09:43 +0300 | [diff] [blame] | 541 | * The result of :c:func:`PyExceptionClass_Name` is now of type |
| 542 | ``const char *`` rather of ``char *``. |
| 543 | (Contributed by Serhiy Storchaka in :issue:`33818`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 544 | |
Antoine Pitrou | 961d54c | 2018-07-16 19:03:03 +0200 | [diff] [blame] | 545 | * The duality of ``Modules/Setup.dist`` and ``Modules/Setup`` has been |
| 546 | removed. Previously, when updating the CPython source tree, one had |
| 547 | to manually copy ``Modules/Setup.dist`` (inside the source tree) to |
| 548 | ``Modules/Setup`` (inside the build tree) in order to reflect any changes |
| 549 | upstream. This was of a small benefit to packagers at the expense of |
| 550 | a frequent annoyance to developers following CPython development, as |
| 551 | forgetting to copy the file could produce build failures. |
| 552 | |
| 553 | Now the build system always reads from ``Modules/Setup`` inside the source |
| 554 | tree. People who want to customize that file are encouraged to maintain |
| 555 | their changes in a git fork of CPython or as patch files, as they would do |
| 556 | for any other change to the source tree. |
| 557 | |
| 558 | (Contributed by Antoine Pitrou in :issue:`32430`.) |
| 559 | |
Serhiy Storchaka | 6a44f6e | 2019-02-25 17:57:58 +0200 | [diff] [blame] | 560 | * Functions that convert Python number to C integer like |
| 561 | :c:func:`PyLong_AsLong` and argument parsing functions like |
| 562 | :c:func:`PyArg_ParseTuple` with integer converting format units like ``'i'`` |
| 563 | will now use the :meth:`~object.__index__` special method instead of |
| 564 | :meth:`~object.__int__`, if available. The deprecation warning will be |
| 565 | emitted for objects with the ``__int__()`` method but without the |
| 566 | ``__index__()`` method (like :class:`~decimal.Decimal` and |
| 567 | :class:`~fractions.Fraction`). :c:func:`PyNumber_Check` will now return |
| 568 | ``1`` for objects implementing ``__index__()``. |
| 569 | (Contributed by Serhiy Storchaka in :issue:`36048`.) |
| 570 | |
Eddie Elizondo | 364f0b0 | 2019-03-27 07:52:18 -0400 | [diff] [blame] | 571 | * Heap-allocated type objects will now increase their reference count |
| 572 | in :c:func:`PyObject_Init` (and its parallel macro ``PyObject_INIT``) |
| 573 | instead of in :c:func:`PyType_GenericAlloc`. Types that modify instance |
| 574 | allocation or deallocation may need to be adjusted. |
| 575 | (Contributed by Eddie Elizondo in :issue:`35810`.) |
| 576 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 577 | |
| 578 | Deprecated |
| 579 | ========== |
| 580 | |
Serhiy Storchaka | 02ec92f | 2018-07-24 12:03:34 +0300 | [diff] [blame] | 581 | * Deprecated methods ``getchildren()`` and ``getiterator()`` in |
| 582 | the :mod:`~xml.etree.ElementTree` module emit now a |
| 583 | :exc:`DeprecationWarning` instead of :exc:`PendingDeprecationWarning`. |
| 584 | They will be removed in Python 3.9. |
| 585 | (Contributed by Serhiy Storchaka in :issue:`29209`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 586 | |
Elvis Pranskevichus | 22d2508 | 2018-07-30 11:42:43 +0100 | [diff] [blame] | 587 | * Passing an object that is not an instance of |
| 588 | :class:`concurrent.futures.ThreadPoolExecutor` to |
Yury Selivanov | 7c7605f | 2018-09-11 09:54:40 -0700 | [diff] [blame] | 589 | :meth:`asyncio.loop.set_default_executor()` is |
Elvis Pranskevichus | 22d2508 | 2018-07-30 11:42:43 +0100 | [diff] [blame] | 590 | deprecated and will be prohibited in Python 3.9. |
| 591 | (Contributed by Elvis Pranskevichus in :issue:`34075`.) |
| 592 | |
Berker Peksag | ef8861c | 2018-08-21 17:58:49 +0300 | [diff] [blame] | 593 | * The :meth:`__getitem__` methods of :class:`xml.dom.pulldom.DOMEventStream`, |
| 594 | :class:`wsgiref.util.FileWrapper` and :class:`fileinput.FileInput` have been |
| 595 | deprecated. |
| 596 | |
| 597 | Implementations of these methods have been ignoring their *index* parameter, |
| 598 | and returning the next item instead. |
| 599 | |
| 600 | (Contributed by Berker Peksag in :issue:`9372`.) |
| 601 | |
Raymond Hettinger | f7b57df | 2019-03-18 09:53:56 -0700 | [diff] [blame] | 602 | * The :class:`typing.NamedTuple` class has deprecated the ``_field_types`` |
| 603 | attribute in favor of the ``__annotations__`` attribute which has the same |
| 604 | information. (Contributed by Raymond Hettinger in :issue:`36320`.) |
| 605 | |
Serhiy Storchaka | 3f22811 | 2018-09-27 17:42:37 +0300 | [diff] [blame] | 606 | * :mod:`ast` classes ``Num``, ``Str``, ``Bytes``, ``NameConstant`` and |
| 607 | ``Ellipsis`` are considered deprecated and will be removed in future Python |
| 608 | versions. :class:`~ast.Constant` should be used instead. |
| 609 | (Contributed by Serhiy Storchaka in :issue:`32892`.) |
| 610 | |
Serhiy Storchaka | fec35c9 | 2018-10-27 08:00:41 +0300 | [diff] [blame] | 611 | * The following functions and methods are deprecated in the :mod:`gettext` |
| 612 | module: :func:`~gettext.lgettext`, :func:`~gettext.ldgettext`, |
| 613 | :func:`~gettext.lngettext` and :func:`~gettext.ldngettext`. |
| 614 | They return encoded bytes, and it's possible that you will get unexpected |
| 615 | Unicode-related exceptions if there are encoding problems with the |
| 616 | translated strings. It's much better to use alternatives which return |
| 617 | Unicode strings in Python 3. These functions have been broken for a long time. |
| 618 | |
| 619 | Function :func:`~gettext.bind_textdomain_codeset`, methods |
| 620 | :meth:`~gettext.NullTranslations.output_charset` and |
| 621 | :meth:`~gettext.NullTranslations.set_output_charset`, and the *codeset* |
| 622 | parameter of functions :func:`~gettext.translation` and |
| 623 | :func:`~gettext.install` are also deprecated, since they are only used for |
| 624 | for the ``l*gettext()`` functions. |
| 625 | |
| 626 | (Contributed by Serhiy Storchaka in :issue:`33710`.) |
| 627 | |
Dong-hee Na | 89669ff | 2019-01-17 21:14:45 +0900 | [diff] [blame] | 628 | * The :meth:`~threading.Thread.isAlive()` method of :class:`threading.Thread` has been deprecated. |
| 629 | (Contributed by Dong-hee Na in :issue:`35283`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 630 | |
Serhiy Storchaka | 6a44f6e | 2019-02-25 17:57:58 +0200 | [diff] [blame] | 631 | * Many builtin and extension functions that take integer arguments will |
| 632 | now emit a deprecation warning for :class:`~decimal.Decimal`\ s, |
| 633 | :class:`~fractions.Fraction`\ s and any other objects that can be converted |
| 634 | to integers only with a loss (e.g. that have the :meth:`~object.__int__` |
| 635 | method but do not have the :meth:`~object.__index__` method). In future |
| 636 | version they will be errors. |
| 637 | (Contributed by Serhiy Storchaka in :issue:`36048`.) |
| 638 | |
Serhiy Storchaka | 42a139e | 2019-04-01 09:16:35 +0300 | [diff] [blame] | 639 | * Deprecated passing the following arguments as keyword arguments: |
| 640 | |
| 641 | - *func* in :func:`functools.partialmethod`, :func:`weakref.finalize`, |
| 642 | :meth:`profile.Profile.runcall`, :meth:`cProfile.Profile.runcall`, |
| 643 | :meth:`bdb.Bdb.runcall`, :meth:`trace.Trace.runfunc` and |
| 644 | :func:`curses.wrapper`. |
| 645 | - *function* in :func:`unittest.addModuleCleanup` and |
| 646 | :meth:`unittest.TestCase.addCleanup`. |
| 647 | - *fn* in the :meth:`~concurrent.futures.Executor.submit` method of |
| 648 | :class:`concurrent.futures.ThreadPoolExecutor` and |
| 649 | :class:`concurrent.futures.ProcessPoolExecutor`. |
| 650 | - *callback* in :meth:`contextlib.ExitStack.callback`, |
| 651 | :meth:`contextlib.AsyncExitStack.callback` and |
| 652 | :meth:`contextlib.AsyncExitStack.push_async_callback`. |
| 653 | - *c* and *typeid* in the :meth:`~multiprocessing.managers.Server.create` |
| 654 | method of :class:`multiprocessing.managers.Server` and |
| 655 | :class:`multiprocessing.managers.SharedMemoryServer`. |
| 656 | - *obj* in :func:`weakref.finalize`. |
| 657 | |
| 658 | In future releases of Python they will be :ref:`positional-only |
| 659 | <positional-only_parameter>`. |
| 660 | (Contributed by Serhiy Storchaka in :issue:`36492`.) |
| 661 | |
Serhiy Storchaka | 6a44f6e | 2019-02-25 17:57:58 +0200 | [diff] [blame] | 662 | |
Victor Stinner | 73104fa | 2018-11-29 09:58:20 +0100 | [diff] [blame] | 663 | API and Feature Removals |
| 664 | ======================== |
| 665 | |
| 666 | The following features and APIs have been removed from Python 3.8: |
| 667 | |
Victor Stinner | d7538dd | 2018-12-14 13:37:26 +0100 | [diff] [blame] | 668 | * The :mod:`macpath` module, deprecated in Python 3.7, has been removed. |
| 669 | (Contributed by Victor Stinner in :issue:`35471`.) |
| 670 | |
Victor Stinner | 73104fa | 2018-11-29 09:58:20 +0100 | [diff] [blame] | 671 | * The function :func:`platform.popen` has been removed, it was deprecated since |
| 672 | Python 3.3: use :func:`os.popen` instead. |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 673 | |
Brett Cannon | a8c3424 | 2018-04-20 14:15:40 -0700 | [diff] [blame] | 674 | * The ``pyvenv`` script has been removed in favor of ``python3.8 -m venv`` |
| 675 | to help eliminate confusion as to what Python interpreter the ``pyvenv`` |
| 676 | script is tied to. (Contributed by Brett Cannon in :issue:`25427`.) |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 677 | |
INADA Naoki | 698865d | 2018-06-19 17:28:50 +0900 | [diff] [blame] | 678 | * ``parse_qs``, ``parse_qsl``, and ``escape`` are removed from :mod:`cgi` |
| 679 | module. They are deprecated from Python 3.2 or older. |
| 680 | |
INADA Naoki | 461a1c4 | 2018-06-28 17:10:36 +0900 | [diff] [blame] | 681 | * ``filemode`` function is removed from :mod:`tarfile` module. |
| 682 | It is not documented and deprecated since Python 3.3. |
INADA Naoki | 698865d | 2018-06-19 17:28:50 +0900 | [diff] [blame] | 683 | |
Serhiy Storchaka | 02ec92f | 2018-07-24 12:03:34 +0300 | [diff] [blame] | 684 | * The :class:`~xml.etree.ElementTree.XMLParser` constructor no longer accepts |
| 685 | the *html* argument. It never had effect and was deprecated in Python 3.4. |
| 686 | All other parameters are now :ref:`keyword-only <keyword-only_parameter>`. |
| 687 | (Contributed by Serhiy Storchaka in :issue:`29209`.) |
| 688 | |
| 689 | * Removed the ``doctype()`` method of :class:`~xml.etree.ElementTree.XMLParser`. |
| 690 | (Contributed by Serhiy Storchaka in :issue:`29209`.) |
| 691 | |
Inada Naoki | 6a16b18 | 2019-03-18 15:44:11 +0900 | [diff] [blame] | 692 | * "unicode_internal" codec is removed. |
| 693 | (Contributed by Inada Naoki in :issue:`36297`.) |
| 694 | |
Ned Deily | 07a1892 | 2018-01-31 18:12:38 -0500 | [diff] [blame] | 695 | |
| 696 | Porting to Python 3.8 |
| 697 | ===================== |
| 698 | |
| 699 | This section lists previously described changes and other bugfixes |
| 700 | that may require changes to your code. |
| 701 | |
| 702 | |
Serhiy Storchaka | 07ca9af | 2018-02-04 10:53:48 +0200 | [diff] [blame] | 703 | Changes in Python behavior |
| 704 | -------------------------- |
| 705 | |
| 706 | * Yield expressions (both ``yield`` and ``yield from`` clauses) are now disallowed |
| 707 | in comprehensions and generator expressions (aside from the iterable expression |
Serhiy Storchaka | 2b57c43 | 2018-12-19 08:09:46 +0200 | [diff] [blame] | 708 | in the leftmost :keyword:`!for` clause). |
Serhiy Storchaka | 07ca9af | 2018-02-04 10:53:48 +0200 | [diff] [blame] | 709 | (Contributed by Serhiy Storchaka in :issue:`10544`.) |
| 710 | |
Serhiy Storchaka | 3bcbedc | 2019-01-18 07:47:48 +0200 | [diff] [blame] | 711 | * The compiler now produces a :exc:`SyntaxWarning` when identity checks |
| 712 | (``is`` and ``is not``) are used with certain types of literals |
| 713 | (e.g. strings, ints). These can often work by accident in CPython, |
| 714 | but are not guaranteed by the language spec. The warning advises users |
| 715 | to use equality tests (``==`` and ``!=``) instead. |
| 716 | (Contributed by Serhiy Storchaka in :issue:`34850`.) |
| 717 | |
Serhiy Storchaka | 7a0630c | 2019-04-08 14:34:04 +0300 | [diff] [blame] | 718 | * The CPython interpreter can swallow exceptions in some circumstances. |
| 719 | In Python 3.8 this happens in less cases. In particular, exceptions |
| 720 | raised when getting the attribute from the type dictionary are no longer |
| 721 | ignored. (Contributed by Serhiy Storchaka in :issue:`35459`.) |
| 722 | |
Michael Felt | 9d949f7 | 2019-04-12 16:15:32 +0200 | [diff] [blame] | 723 | * On AIX, :attr:`sys.platform` doesn't contain the major version anymore. |
| 724 | It is always ``'aix'``, instead of ``'aix3'`` .. ``'aix7'``. Since |
| 725 | older Python versions include the version number, it is recommended to |
| 726 | always use the ``sys.platform.startswith('aix')``. |
| 727 | (Contributed by M. Felt in :issue:`36588`.) |
Serhiy Storchaka | 07ca9af | 2018-02-04 10:53:48 +0200 | [diff] [blame] | 728 | |
Serhiy Storchaka | 97f1ca1 | 2018-02-01 18:49:21 +0200 | [diff] [blame] | 729 | Changes in the Python API |
| 730 | ------------------------- |
| 731 | |
Victor Stinner | d7befad | 2019-04-25 14:30:16 +0200 | [diff] [blame^] | 732 | * :class:`subprocess.Popen` can now use :func:`os.posix_spawn` in some cases |
| 733 | for better performance. On Windows Subsystem for Linux and QEMU User |
| 734 | Emulation, Popen constructor using :func:`os.posix_spawn` no longer raise an |
| 735 | exception on errors like missing program, but the child process fails with a |
| 736 | non-zero :attr:`~Popen.returncode`. |
| 737 | |
Victor Stinner | 74125a6 | 2019-04-15 18:23:20 +0200 | [diff] [blame] | 738 | * The :meth:`imap.IMAP4.logout` method no longer ignores silently arbitrary |
| 739 | exceptions. |
| 740 | |
Victor Stinner | 73104fa | 2018-11-29 09:58:20 +0100 | [diff] [blame] | 741 | * The function :func:`platform.popen` has been removed, it was deprecated since |
| 742 | Python 3.3: use :func:`os.popen` instead. |
| 743 | |
Raymond Hettinger | fc06a19 | 2019-03-12 00:43:27 -0700 | [diff] [blame] | 744 | * The :func:`statistics.mode` function no longer raises an exception |
| 745 | when given multimodal data. Instead, it returns the first mode |
| 746 | encountered in the input data. (Contributed by Raymond Hettinger |
| 747 | in :issue:`35892`.) |
| 748 | |
Serhiy Storchaka | 97f1ca1 | 2018-02-01 18:49:21 +0200 | [diff] [blame] | 749 | * The :meth:`~tkinter.ttk.Treeview.selection` method of the |
| 750 | :class:`tkinter.ttk.Treeview` class no longer takes arguments. Using it with |
| 751 | arguments for changing the selection was deprecated in Python 3.6. Use |
| 752 | specialized methods like :meth:`~tkinter.ttk.Treeview.selection_set` for |
| 753 | changing the selection. (Contributed by Serhiy Storchaka in :issue:`31508`.) |
Serhiy Storchaka | 6c85efa5 | 2018-02-05 22:47:31 +0200 | [diff] [blame] | 754 | |
Diego Rojas | 06e1e68 | 2019-03-16 18:44:56 -0500 | [diff] [blame] | 755 | * The :meth:`writexml`, :meth:`toxml` and :meth:`toprettyxml` methods of the |
| 756 | :mod:`xml.dom.minidom` module, and :mod:`xml.etree` now preserve the attribute |
| 757 | order specified by the user. |
| 758 | (Contributed by Diego Rojas and Raymond Hettinger in :issue:`34160`.) |
| 759 | |
Serhiy Storchaka | 6c85efa5 | 2018-02-05 22:47:31 +0200 | [diff] [blame] | 760 | * A :mod:`dbm.dumb` database opened with flags ``'r'`` is now read-only. |
| 761 | :func:`dbm.dumb.open` with flags ``'r'`` and ``'w'`` no longer creates |
| 762 | a database if it does not exist. |
| 763 | (Contributed by Serhiy Storchaka in :issue:`32749`.) |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 764 | |
Serhiy Storchaka | 02ec92f | 2018-07-24 12:03:34 +0300 | [diff] [blame] | 765 | * The ``doctype()`` method defined in a subclass of |
| 766 | :class:`~xml.etree.ElementTree.XMLParser` will no longer be called and will |
| 767 | cause emitting a :exc:`RuntimeWarning` instead of a :exc:`DeprecationWarning`. |
| 768 | Define the :meth:`doctype() <xml.etree.ElementTree.TreeBuilder.doctype>` |
| 769 | method on a target for handling an XML doctype declaration. |
| 770 | (Contributed by Serhiy Storchaka in :issue:`29209`.) |
| 771 | |
Serhiy Storchaka | f5e7b19 | 2018-05-20 08:48:12 +0300 | [diff] [blame] | 772 | * A :exc:`RuntimeError` is now raised when the custom metaclass doesn't |
| 773 | provide the ``__classcell__`` entry in the namespace passed to |
| 774 | ``type.__new__``. A :exc:`DeprecationWarning` was emitted in Python |
| 775 | 3.6--3.7. (Contributed by Serhiy Storchaka in :issue:`23722`.) |
| 776 | |
Scott Sanderson | cebe80b | 2018-06-07 05:46:42 -0400 | [diff] [blame] | 777 | * The :class:`cProfile.Profile` class can now be used as a context |
| 778 | manager. (Contributed by Scott Sanderson in :issue:`29235`.) |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 779 | |
Giampaolo Rodola | c7f02a9 | 2018-06-19 08:27:29 -0700 | [diff] [blame] | 780 | * :func:`shutil.copyfile`, :func:`shutil.copy`, :func:`shutil.copy2`, |
| 781 | :func:`shutil.copytree` and :func:`shutil.move` use platform-specific |
| 782 | "fast-copy" syscalls (see |
| 783 | :ref:`shutil-platform-dependent-efficient-copy-operations` section). |
| 784 | |
| 785 | * :func:`shutil.copyfile` default buffer size on Windows was changed from |
| 786 | 16 KiB to 1 MiB. |
| 787 | |
INADA Naoki | d5c875b | 2018-07-11 17:42:49 +0900 | [diff] [blame] | 788 | * ``PyGC_Head`` struct is changed completely. All code touched the |
| 789 | struct member should be rewritten. (See :issue:`33597`) |
| 790 | |
Eric Snow | be3b295 | 2019-02-23 11:35:52 -0700 | [diff] [blame] | 791 | * The ``PyInterpreterState`` struct has been moved into the "internal" |
| 792 | header files (specifically Include/internal/pycore_pystate.h). An |
| 793 | opaque ``PyInterpreterState`` is still available as part of the public |
| 794 | API (and stable ABI). The docs indicate that none of the struct's |
| 795 | fields are public, so we hope no one has been using them. However, |
| 796 | if you do rely on one or more of those private fields and have no |
| 797 | alternative then please open a BPO issue. We'll work on helping |
| 798 | you adjust (possibly including adding accessor functions to the |
| 799 | public API). (See :issue:`35886`.) |
| 800 | |
Alex Grönholm | cca4eec | 2018-08-09 00:06:47 +0300 | [diff] [blame] | 801 | * Asyncio tasks can now be named, either by passing the ``name`` keyword |
| 802 | argument to :func:`asyncio.create_task` or |
Yury Selivanov | 7c7605f | 2018-09-11 09:54:40 -0700 | [diff] [blame] | 803 | the :meth:`~asyncio.loop.create_task` event loop method, or by |
Alex Grönholm | cca4eec | 2018-08-09 00:06:47 +0300 | [diff] [blame] | 804 | calling the :meth:`~asyncio.Task.set_name` method on the task object. The |
| 805 | task name is visible in the ``repr()`` output of :class:`asyncio.Task` and |
| 806 | can also be retrieved using the :meth:`~asyncio.Task.get_name` method. |
| 807 | |
Berker Peksag | e7d4b2f | 2018-08-22 21:21:05 +0300 | [diff] [blame] | 808 | * The :meth:`mmap.flush() <mmap.mmap.flush>` method now returns ``None`` on |
| 809 | success and raises an exception on error under all platforms. Previously, |
| 810 | its behavior was platform-depended: a nonzero value was returned on success; |
| 811 | zero was returned on error under Windows. A zero value was returned on |
| 812 | success; an exception was raised on error under Unix. |
| 813 | (Contributed by Berker Peksag in :issue:`2122`.) |
| 814 | |
Pablo Galindo | fa221d8 | 2018-09-08 00:16:17 +0100 | [diff] [blame] | 815 | * The function :func:`math.factorial` no longer accepts arguments that are not |
| 816 | int-like. (Contributed by Pablo Galindo in :issue:`33083`.) |
| 817 | |
Andrés Delfino | ca68261 | 2018-11-07 14:29:14 -0300 | [diff] [blame] | 818 | * :mod:`xml.dom.minidom` and :mod:`xml.sax` modules no longer process |
Christian Heimes | 17b1d5d | 2018-09-23 09:50:25 +0200 | [diff] [blame] | 819 | external entities by default. |
| 820 | (Contributed by Christian Heimes in :issue:`17239`.) |
INADA Naoki | d5c875b | 2018-07-11 17:42:49 +0900 | [diff] [blame] | 821 | |
Xiang Zhang | 4fb0b8b | 2018-12-12 20:46:55 +0800 | [diff] [blame] | 822 | * Deleting a key from a read-only :mod:`dbm` database (:mod:`dbm.dumb`, |
| 823 | :mod:`dbm.gnu` or :mod:`dbm.ndbm`) raises :attr:`error` (:exc:`dbm.dumb.error`, |
| 824 | :exc:`dbm.gnu.error` or :exc:`dbm.ndbm.error`) instead of :exc:`KeyError`. |
| 825 | (Contributed by Xiang Zhang in :issue:`33106`.) |
| 826 | |
Steve Dower | 8ef864d | 2019-03-12 15:15:26 -0700 | [diff] [blame] | 827 | * :func:`~os.path.expanduser` on Windows now prefers the :envvar:`USERPROFILE` |
| 828 | environment variable and does not use :envvar:`HOME`, which is not normally |
| 829 | set for regular user accounts. |
| 830 | |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 831 | .. _bpo-36085-whatsnew: |
| 832 | |
| 833 | * DLL dependencies for extension modules and DLLs loaded with :mod:`ctypes` on |
| 834 | Windows are now resolved more securely. Only the system paths, the directory |
| 835 | containing the DLL or PYD file, and directories added with |
| 836 | :func:`~os.add_dll_directory` are searched for load-time dependencies. |
| 837 | Specifically, :envvar:`PATH` and the current working directory are no longer |
| 838 | used, and modifications to these will no longer have any effect on normal DLL |
| 839 | resolution. If your application relies on these mechanisms, you should check |
| 840 | for :func:`~os.add_dll_directory` and if it exists, use it to add your DLLs |
Steve Dower | 79da388 | 2019-03-30 20:58:17 -0700 | [diff] [blame] | 841 | directory while loading your library. Note that Windows 7 users will need to |
| 842 | ensure that Windows Update KB2533625 has been installed (this is also verified |
| 843 | by the installer). |
Steve Dower | 2438cdf | 2019-03-29 16:37:16 -0700 | [diff] [blame] | 844 | (See :issue:`36085`.) |
| 845 | |
Pablo Galindo | f2cf1e3 | 2019-04-13 17:05:14 +0100 | [diff] [blame] | 846 | * The header files and functions related to pgen have been removed after its |
| 847 | replacement by a pure Python implementation. (Contributed by Pablo Galindo |
| 848 | in :issue:`36623`.) |
| 849 | |
Xiang Zhang | 4fb0b8b | 2018-12-12 20:46:55 +0800 | [diff] [blame] | 850 | |
Inada Naoki | d3c72a2 | 2019-03-23 21:04:40 +0900 | [diff] [blame] | 851 | Changes in the C API |
| 852 | -------------------- |
| 853 | |
| 854 | * Use of ``#`` variants of formats in parsing or building value (e.g. |
| 855 | :c:func:`PyArg_ParseTuple`, :c:func:`Py_BuildValue`, :c:func:`PyObject_CallFunction`, |
| 856 | etc.) without ``PY_SSIZE_T_CLEAN`` defined raises ``DeprecationWarning`` now. |
| 857 | It will be removed in 3.10 or 4.0. Read :ref:`arg-parsing` for detail. |
| 858 | (Contributed by Inada Naoki in :issue:`36381`.) |
| 859 | |
| 860 | |
Eddie Elizondo | 364f0b0 | 2019-03-27 07:52:18 -0400 | [diff] [blame] | 861 | Changes in the C API |
| 862 | -------------------------- |
| 863 | |
| 864 | * Instances of heap-allocated types (such as those created with |
| 865 | :c:func:`PyType_FromSpec`) hold a reference to their type object. |
| 866 | Increasing the reference count of these type objects has been moved from |
| 867 | :c:func:`PyType_GenericAlloc` to the more low-level functions, |
| 868 | :c:func:`PyObject_Init` and :c:func:`PyObject_INIT`. |
| 869 | This makes types created through :c:func:`PyType_FromSpec` behave like |
| 870 | other classes in managed code. |
| 871 | |
| 872 | Statically allocated types are not affected. |
| 873 | |
| 874 | For the vast majority of cases, there should be no side effect. |
| 875 | However, types that manually increase the reference count after allocating |
| 876 | an instance (perhaps to work around the bug) may now become immortal. |
| 877 | To avoid this, these classes need to call Py_DECREF on the type object |
| 878 | during instance deallocation. |
| 879 | |
| 880 | To correctly port these types into 3.8, please apply the following |
| 881 | changes: |
| 882 | |
| 883 | * Remove :c:macro:`Py_INCREF` on the type object after allocating an |
| 884 | instance - if any. |
| 885 | This may happen after calling :c:func:`PyObject_New`, |
| 886 | :c:func:`PyObject_NewVar`, :c:func:`PyObject_GC_New`, |
| 887 | :c:func:`PyObject_GC_NewVar`, or any other custom allocator that uses |
| 888 | :c:func:`PyObject_Init` or :c:func:`PyObject_INIT`. |
| 889 | |
| 890 | Example:: |
| 891 | |
| 892 | static foo_struct * |
| 893 | foo_new(PyObject *type) { |
| 894 | foo_struct *foo = PyObject_GC_New(foo_struct, (PyTypeObject *) type); |
| 895 | if (foo == NULL) |
| 896 | return NULL; |
| 897 | #if PY_VERSION_HEX < 0x03080000 |
| 898 | // Workaround for Python issue 35810; no longer necessary in Python 3.8 |
| 899 | PY_INCREF(type) |
| 900 | #endif |
| 901 | return foo; |
| 902 | } |
| 903 | |
| 904 | * Ensure that all custom ``tp_dealloc`` functions of heap-allocated types |
| 905 | decrease the type's reference count. |
| 906 | |
| 907 | Example:: |
| 908 | |
| 909 | static void |
| 910 | foo_dealloc(foo_struct *instance) { |
| 911 | PyObject *type = Py_TYPE(instance); |
| 912 | PyObject_GC_Del(instance); |
| 913 | #if PY_VERSION_HEX >= 0x03080000 |
| 914 | // This was not needed before Python 3.8 (Python issue 35810) |
| 915 | Py_DECREF(type); |
| 916 | #endif |
| 917 | } |
| 918 | |
| 919 | (Contributed by Eddie Elizondo in :issue:`35810`.) |
| 920 | |
| 921 | |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 922 | CPython bytecode changes |
| 923 | ------------------------ |
| 924 | |
| 925 | * The interpreter loop has been simplified by moving the logic of unrolling |
| 926 | the stack of blocks into the compiler. The compiler emits now explicit |
Serhiy Storchaka | 3f819ca | 2018-10-31 02:26:06 +0200 | [diff] [blame] | 927 | instructions for adjusting the stack of values and calling the |
| 928 | cleaning-up code for :keyword:`break`, :keyword:`continue` and |
| 929 | :keyword:`return`. |
Serhiy Storchaka | 520b7ae | 2018-02-22 23:33:30 +0200 | [diff] [blame] | 930 | |
| 931 | Removed opcodes :opcode:`BREAK_LOOP`, :opcode:`CONTINUE_LOOP`, |
| 932 | :opcode:`SETUP_LOOP` and :opcode:`SETUP_EXCEPT`. Added new opcodes |
| 933 | :opcode:`ROT_FOUR`, :opcode:`BEGIN_FINALLY`, :opcode:`CALL_FINALLY` and |
| 934 | :opcode:`POP_FINALLY`. Changed the behavior of :opcode:`END_FINALLY` |
| 935 | and :opcode:`WITH_CLEANUP_START`. |
| 936 | |
| 937 | (Contributed by Mark Shannon, Antoine Pitrou and Serhiy Storchaka in |
| 938 | :issue:`17611`.) |
Serhiy Storchaka | 702f8f3 | 2018-03-23 14:34:35 +0200 | [diff] [blame] | 939 | |
| 940 | * Added new opcode :opcode:`END_ASYNC_FOR` for handling exceptions raised |
| 941 | when awaiting a next item in an :keyword:`async for` loop. |
| 942 | (Contributed by Serhiy Storchaka in :issue:`33041`.) |
Raymond Hettinger | f75d59e | 2019-02-02 22:54:56 -0800 | [diff] [blame] | 943 | |
| 944 | |
| 945 | Demos and Tools |
| 946 | --------------- |
| 947 | |
| 948 | * Added a benchmark script for timing various ways to access variables: |
| 949 | ``Tools/scripts/var_access_benchmark.py``. |
| 950 | (Contributed by Raymond Hettinger in :issue:`35884`.) |