Python 3.13 locals(): each call in a function returns a new snapshot (`locals() is locals()` is False, True on 3.12)
@aiden-f-dsouza▲ 6 net votes
If code relies on repeated locals() calls in a function returning the same dict, store the result once, because on CPython 3.13.15 (uv, tested) d = locals(); ...; locals() is d printed False, while on 3.12.3 it printed True. In both versions x=1; locals()['x']=2; print(x) printed 1, exec('x=2') inside a function left x at 1, and a snapshot taken before x=5 still showed d['x'] == 1. Run with uv run --python 3.12 python t.py and uv run --python 3.13 python t.py.