Skip to main content
🎯
PEP 657 · Speedrun · Python 3.11 (2022)

PEP 657 in 90 seconds — tracebacks that point at the actual sub-expression

From 'somewhere on this line' to 'this exact `[0]`'.

Pre-3.11, a traceback like `TypeError: 'NoneType' object is not subscriptable` would point at the LINE it happened on. If the line was `total = parse(req).get('items')[0].price` you got to guess which of the seven sub-expressions was None. Senior devs all learned to break their lines apart to debug, then re-collapse them once it worked.

PEP 657 (Python 3.11, 2022) ships with the standard interpreter: tracebacks now underline the SPECIFIC sub-expression that raised. The output uses `^^^` carets under the exact column range — `parse(req).get('items')[0].price` becomes self-diagnosing. It's the kind of change you don't appreciate until you're three coffees deep in a 3am incident.

Before — Python ≤ 3.10 traceback
Traceback (most recent call last):
  File "incident.py", line 42, in handle
    total = parse(req).get("items")[0].price
TypeError: 'NoneType' object is not subscriptable

# Which of seven things is None? Good luck.
After — Python ≥ 3.11 traceback
Traceback (most recent call last):
  File "incident.py", line 42, in handle
    total = parse(req).get("items")[0].price
            ~~~~~~~~~~~~~~~~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable

# .get("items") returned None → [0] failed.

🎯 Predict the output

Which Python sub-expression does this 3.11+ traceback identify as the cause? Type it exactly as shown by the carets.

# Suppose the snippet:
#   value = config.load("api").credentials.token
# raises:
#   AttributeError: 'NoneType' object has no attribute 'credentials'
# and the carets point at columns 9..21.
#
# Type the substring of the line that is "underlined" by ^^^.
More CPython internals → Senior track

Or speedrun another PEP

PEP 572Assignment as an expression — 3 lines become 1.
PEP 572 in 90 seconds — the walrus that ate your for-loop
PEP 484Python stays dynamic — but you can opt into typing.
PEP 484 in 90 seconds — type hints, without TypeScript-envy
PEP 622Switch statements are a 5% feature. Pattern matching is the 95%.
PEP 622 in 90 seconds — match / case isn't just a switch