Skip to content

Latest commit

 

History

History

python_3_7

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Python 3.7 Overview & Features

Release Date: June 27, 2018
Key Focus: Data Classes (dataclasses), Debugging Built-in (breakpoint), Future Annotations, Nanosecond Resolution Timers, and Context Variables (contextvars).


🚀 Key Features & Syntax Additions

1. Data Classes (@dataclass) (PEP 557)

Introduced the @dataclass decorator in the dataclasses standard module, automatically generating boilerplate methods (__init__, __repr__, __eq__, __hash__, comparisons) based on type annotations.

2. Built-in breakpoint() (PEP 553)

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.

3. Postponed Evaluation of Annotations (PEP 563)

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.

4. High-Precision Time Functions (Nanoseconds)

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.

5. Context Variables (contextvars) (PEP 567)

Introduced contextvars.ContextVar to manage thread-local and task-local states across concurrent asynchronous tasks safely.

6. Module __getattr__ and __dir__ (PEP 562)

Modules now support defining __getattr__(name) and __dir__() at module level, enabling module-level deprecation warnings, lazy loading of submodules, and dynamic attributes.

7. Guaranteed Dictionary Insertion Order

Dictionary key order preservation became an official language specification requirement (rather than a CPython implementation detail).


🛠️ Summary Table of Important PEPs

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()

💻 Pythonic Code Showcase

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()