On Tue, 1 Dec 2020 at 13:16, Paul Sokolovsky <pmiscml@gmail.com> wrote:
If you want immutable dict you [know whom to thank for the lack of it - stroked thru] can use types.MappingProxyType, as was explained (it's all about PEP603).
The last case with immutable dict also shows that proliferation of both mutable and immutable type counterparts doesn't scale. What we need is some generic types.roproxy (yes, all lower-case, to emphasize its fundementalness) which can be applied to any object, and will filter out __setitem__ and __setattr__ (and del counterparts, and custom list of mutator methods, you get an idea).
Is it not more simple for the moment to have it only as a sort of warning for the developer? I mean, if the object is mutated, a warning is raised at runtime. If the object is rebound, a SyntaxError is emitted. I suppose that this is possible for dicts, since they have an internal attribute ma_version_tag, that is increased every time the dict mutates. Classes have __dict__. Don't know for the other builtin types. Speed optimizations could be done later, if they are possible.