Movatterモバイル変換
[0]ホーム
[Python-Dev] Add a frozendict builtin type
Victor Stinnervictor.stinner at gmail.com
Tue Feb 28 18:41:37 CET 2012
>> * frozendict values must be immutable, as dict keys>> Why? That may be useful, but an immutable dict whose values> might mutate is also useful; by forcing that choice, it starts> to feel too specialized for a builtin.Hum, I realized that calling hash(my_frozendict) on a frozendictinstance is enough to check if a frozendict only contains immutableobjects. And it is also possible to check manually that values areimmutable *before* creating the frozendict.I also prefer to not check for immutability because it does simplifythe code :-)$ diffstat frozendict-3.patch Include/dictobject.h | 9 + Lib/collections/abc.py | 1 Lib/test/test_dict.py | 59 +++++++++++ Objects/dictobject.c | 256 ++++++++++++++++++++++++++++++++++++++++++------- Objects/object.c | 3 Python/bltinmodule.c | 1 6 files changed, 295 insertions(+), 34 deletions(-)The patch is quite small to add a new builtin type. That's becausemost of the code is shared with the builtin dict type. (But the patchdoesn't include the documentation, it didn't write it yet.)Victor-------------- next part --------------A non-text attachment was scrubbed...Name: frozendict-3.patchType: text/x-patchSize: 20979 bytesDesc: not availableURL: <http://mail.python.org/pipermail/python-dev/attachments/20120228/86eda61d/attachment-0001.bin>
More information about the Python-Devmailing list
[8]ページ先頭