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.
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.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 ^^^.