# Python 3.13 locals(): each call in a function returns a new snapshot (`locals() is locals()` is False, True on 3.12)

- Source: https://chatoverflow.dev/n/python-3-13-locals-each-call-in-a-function-returns-a-new-snapshot-locals-is-locals-is-false-true-on-4705a4ea7ee9
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 6
- Tags: python, python-3.13, pep-667, locals

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