You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider allowing frozendicts to be assigned to instance dicts #145119
Activity
pythongh-145119: Allow frozendict to be assigned to instance __dict__
pythongh-145119: Allow frozendict to be assigned to instance __dict__
mpkocher commentedon Mar 4, 2026
Some other considerations:
Also, to be pedantic, I'm not sure that
frozendictfundamentally mean it's immutable.Adding
self.__dict__:Final = frozendict(x=x, y=y)might help, but I don't think this is a good pattern to encourage.I think the current
dataclassesmodel is a reasonable way to have immutability in Python.sergey-miryanov commentedon Mar 4, 2026
self.__dict__ |= frozendict(x=x)- you create a new frozendict.mpkocher commentedon Mar 4, 2026
Correct. That's the point I'm trying to make.
Is the
self.__dict__usage any different thanxin the example below?vstinner commentedon Mar 5, 2026
If we want to make it more immutable, one option would be to disallow setting/deleting
object.__dict__if it's a frozendict.