=locals= is different in that the underlying implementation is not based on hash dict. instead, for speed purpose, it's stored as a c array associated with the frame object. cf. https://github.com/python/cpython/blob/master/Python/ceval.c#L878
for a clear picture. I don't recommend modifying the local variables (and the enclosure ones), but if you really want, you can import ctypes and do the hack.