Python📜History & Evolutionbeginner
Python 3.11 — Faster CPython (2022)
Python · History & Evolution · Run with python3
Explanation
Python 3.11 delivered the first fruits of the "Faster CPython" project (funded by Microsoft, led by Mark Shannon). The interpreter's frame evaluation was rewritten to use "adaptive specialization" — opcodes that observe types at runtime and replace themselves with faster type-specific versions. Benchmarks showed 10–60% speedups on standard workloads. Exception handling became zero-cost for the happy path, and the new `tomllib` module for TOML parsing shipped in the standard library.
Real-World Scenario
Django web request benchmarks improved ~30% on 3.11 over 3.10 with no code changes. Startup time dropped because fewer module imports are needed.
Quick Snippet
snippet.py
# Python 3.11: fine-grained error location in tracebacks
# Before: "TypeError: ..." After: exact column underlined
# Example of the new traceback format:
# result = obj.method()["key"]
# ^^^^^^^^^^^^^^^^
# TypeError: 'NoneType' object is not subscriptable
import tomllib
config = tomllib.loads('[server]\nhost = "localhost"\nport = 8080')
print(config["server"]["host"]) # localhostFull Example
python311_features.py
# Compile: python3 python311_features.py
# Output:
# localhost
import sys
# Python 3.11 feature: tomllib (built-in TOML parser)
if sys.version_info >= (3, 11):
import tomllib
config = tomllib.loads('[server]\nhost = "localhost"\nport = 8080')
print(config["server"]["host"])
else:
# Fallback for older Python
config = {"server": {"host": "localhost", "port": 8080}}
print(config["server"]["host"])
print(f"Python {sys.version_info.major}.{sys.version_info.minor}")
print("3.11 features: fine-grained tracebacks, tomllib, TaskGroup, faster interpreter")
Run command
python3 python311_features.py