2017-11-30 2:16 GMT+01:00 Rob Cliffe
This is sort of a subset of an idea I once posted on Python-Ideas: Dictionaries, sets and lists (etc. ?) could have a mutable flag, and once it was set to False you could neither change it back nor change the object. (OK there might be some backdoor hacks, this is Python.) This would avoid having to explain to beginners "Why does Python have lists and tuples?" because instead of a tuple, all you need is an immutable list. (Or if you prefer, instead of a list, all you need is a mutable tuple.)
Here is a concept implementation of a freeze() function which does something similar. Rather than mutating the mutable object to become immutable, it makes an immutable copy.
freeze({"x": [1,2,{3,4}]}) mappingproxy({'x': (1, 2, frozenset({3, 4}))})
https://gist.github.com/stephanh42/d277170dd8a3a2f026c272a4fda15396 Stephan
Rob Cliffe
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/