Release Date: June 27, 2018
Key Focus: Data Classes (dataclasses), Debugging Built-in (breakpoint), Future Annotations, Nanosecond Resolution Timers, and Context Variables (contextvars).
Introduced the @dataclass decorator in the dataclasses standard module, automatically generating boilerplate methods (__init__, __repr__, __eq__, __hash__, comparisons) based on type annotations.
Added breakpoint() as a native language built-in function, cleanly invoking the configured debugger (defaulting to pdb) without needing explicit import pdb; pdb.set_trace() statements. Behaviors can be redirected via PYTHONBREAKPOINT.
Using from __future__ import annotations, type annotations are stored as strings during runtime parsing rather than evaluated immediately. This solves forward-reference cycles (e.g. self-referencing class method return types) and improves module loading speeds.
Added nanosecond-resolution variants to the time module (time.time_ns(), time.monotonic_ns(), time.perf_counter_ns()), avoiding precision loss associated with floating-point representations.
Introduced contextvars.ContextVar to manage thread-local and task-local states across concurrent asynchronous tasks safely.
Modules now support defining __getattr__(name) and __dir__() at module level, enabling module-level deprecation warnings, lazy loading of submodules, and dynamic attributes.
Dictionary key order preservation became an official language specification requirement (rather than a CPython implementation detail).
| PEP | Feature | Description |
|---|---|---|
| PEP 557 | @dataclass |
Automatic method generation for data-holder classes |
| PEP 553 | breakpoint() |
Built-in debugging trigger |
| PEP 563 | Postponed Annotations | from __future__ import annotations for forward references |
| PEP 567 | contextvars |
Context-local variables for async / threading state |
| PEP 562 | Module __getattr__ |
Module-level dynamic attribute lookup and deprecations |
| PEP 564 | Nanosecond Timers | time.time_ns(), time.perf_counter_ns() |
Check main_3_7.py, data_classes.py, break_point.py, and time_feature.py in this directory for runnable code examples demonstrating:
- Building clean data classes with default fields and post-init processing
- Postponed type annotations (
from __future__ import annotations) - Context variable isolation in concurrent contexts
- Module-level dynamic attributes via
__getattr__ - Microsecond/nanosecond benchmarking with
time.perf_counter_ns()