Stephane Wirtel is a contributor to CPython and a member of the EuroPython team.
PEP 553: breakpoint()
debugger keyword. And we have a lot of debuggers: pdb, ipdb, pudb, pdbpp, …
Up until now, you had to explicitly import the right debugger, like
import pdb; pdb.set_trace().
Now you can now use
PYTHONBREAKPOING=pudb.set_trace to choose your debugger. Bonus feature: you can also use
PYTHONBREAKPOING=0 to disable debugging entirely.
PEP 557: Data classes
We already have
namedtuple, but we can't assign values to a dotted attribute of a
If we want that, we can use simple classes with just an
__init__ initialiser, a
__eq__ for equality, and
__lt__ for comparison.
Instead, we can now use the much shorter data classes:
from dataclasses import dataclass @dataclass class Person: firstname: str lastname: str post_code: int = 11111
We get default values, comparison, properties, methods, and inheritance. The
dataclass decorator also has some options:
False(default), generate a
__hash__method based on
frozen=False: If True, generates exceptions when fields are tried to be changed.
PEP 562: Module
__getattr__ method of a module can be used to issue deprecation warnings. The
__dir__ method can be used to override the list of accessible properties.
PEP 563: Postponed Evaluation of Annotations
With delayed evaluation of type annotations, we can now use self referential method signatures on classes. This was badly missing. Use
from __future__ import annotations.
PEP 564: Time functions with nanosecond resolution
time.time() function returns the current time as a floating-point numer. This is limited to 64 bits and is in IEEE 754 format, which limits it to losing nanoseconds after 104 days. Now we have
PEP 565: Show DeprecationWarning in main()
DeprecationWarnings are once more shown by default, but only when the code triggering them is running directly in the main module. As a result, developers of single file scripts and those using Python interactively should once again start seeing deprecation warnings for the APIs they use, but deprecation warnings triggered by imported application, library and framework modules will continue to be hidden by default.
That also means that DeprecationWarning and PendingDeprecatinWarning can now be more meaninfully used.
PEP 567: Context Variables
Keep track of values of variables per asynchronous task. Access
foo = contextvars.ContextVar('foo', default=None)
PEP 540: Python documentation translations
We have documentation in English, French, Japanese, and Korean.
Not in PEPs
- async and await are now keywords.
asyncio.run()replaces the combination of
loop.start_tls(): upgrade to TLS
asyncio.current_taskreturns the current task
asyncio.all_tasksdoes exactly that
asyncio.get_event_loopis 15 times faster (C implementation)
python -X importtimeprofiles import times
-X utf8will enable UTF8 mode (disabled by default unless locale enables)
-X devenables development mode of asyncio, adds runtime checks, installs debug hooks into memory allocators, etc.
importlib.resourcesallows to load a binary artifact that is shipped within a package (similar to
pkg_resourcesbut with better performance and less overhead)
- Lots of bug fixes
- Better performance