Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] Add a frozendict builtin type

Victor Stinnervictor.stinner at haypocalc.com
Tue Feb 28 12:45:54 CET 2012


> I think you need to elaborate on your use cases further, ...A frozendict can be used as a member of a set or as a key in a dictionary.For example, frozendict is indirectly needed when you want to use anobject as a key of a dict, whereas one attribute of this object is adict. Use a frozendict instead of a dict for this attribute answers tothis problem.frozendict helps also in threading and multiprocessing.--> ... and explain> what *additional* changes would be needed, such as allowing frozendict> instances as __dict__ attributes in order to create truly immutable> objects in pure Python code.> In current Python, you *can't* create a truly immutable object without dropping> down to a C extension:Using frozendict in for type dictionary might be a use case, butplease don't focus on this example. There is currently a discussion onpython-ideas about this specific use case. I first proposed to usefrozendict in type.__new__, but then I proposed something completlydifferent: add a flag to a set to deny any modification of the type.The flag may be set using "__final__ = True" in the class body forexample.Victor


More information about the Python-Devmailing list

[8]ページ先頭

©2009-2025 Movatter.jp