Frozendict in Python (PEP 814): The Safer Default-Argument Story for Mappings
Python’s mutable-default-argument gotcha is infamous. In my earlier post, I went one step further and tried to exploit it: using a mutable default as a state bucket, then showing why it breaks the moment you want multiple independent instances (and why it gets even uglier around concurrency). Now there’s a language-level proposal that’s relevant to the same theme—but in a much more principled way. PEP 814 proposes a new built-in type: frozendict, an immutable mapping designed to be “safe by design.” It’s currently a Draft targeting Python 3.15. ...