Brandt Bucher <brandtbuc...@gmail.com> added the comment:
For anyone curious, I had some free time today and took a stab at creating a minimal _frozendict type (sharing as much implementation with dict as possible) to see how difficult it would be. It was actually much simpler than I thought... just a few dozen lines of code, including marshal support. If you'd like to see it, you can check out my "frozendict" branch here: https://github.com/python/cpython/compare/main...brandtbucher:frozendict For testing purposes, I've exposed in the _testcapi module. It has the same constructor signature as dict, and basically only supports lookups: >>> from _testcapi import _frozendict >>> fd = _frozendict({1: 2, "3": 4, None: 5}) >>> fd <_frozendict object at 0x7f4e127e4ef0> >>> fd[1] 2 >>> fd[3] Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 3 >>> import marshal >>> marshal.loads(marshal.dumps(fd)) == fd True I'm not gonna lie... I really like it. It sidesteps any runtime construction/caching issues that using a normal dict would have, but with all of the same performance characteristics. It also seems like it would not introduce much of a maintenance burden, since it has very little of its own code. Anyways, food for thought. It was a fun experiment at the very least. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue44283> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com