dict_with_defaults_property
- PlasmaCalcs.tools.properties.dict_with_defaults_property(internal_name, *, key_aliases, doc=None)
return a property which gives a dictionary, and gives key_aliases a chance to edit the dict.
internal_name: strthe name where this property is stored internally for obj.key_aliases: str or iterable of strs.the attributes of obj which are alias_key_of this property.str –> use obj.key_aliases.doc: None or strthe docstring for this propertyif None, use f’dict with defaults determined by self.{key_aliases}’.Example:class Foo():special = dict_with_defaults_property(‘_special’, key_aliases=’_special_key_aliases’)_special_key_aliases = [‘special_key1’, ‘special_key2’]special_key1 = alias_key_of(‘_special’, ‘key1’, setdefault_value=5)special_key2 = alias_key_of(‘_special’, ‘key2’)foo = Foo()# every time getting the dict from foo, use all the setdefault values as appropriate:foo.special # –> dict(key1=5)foo.special = dict(key1=100)foo.special # –> dict(key1=100)foo.special = dict(key3=30)foo.special # –> dict(key3=30, key1=5)foo.special_key1 = 70foo.special # –> dict(key3=30, key1=70)del foo.special[‘key1’]foo.special # –> dict(key3=30, key1=5) # key1 was missing, so its setdefault value is used.# note that the dict itself is a normal dict; the magic happens when doing foo.special:foo.special = dict(key3=10, key1=80)special = foo.specialspecial # –> dict(key3=10, key1=80)del special[‘key1’]special # –> dict(key3=10)foo.special # –> dict(key3=10, key1=5) # key1 was missing, so its setdefault value is used.special # –> dict(key3=10, key1=5) # a new dict isn’t created; foo.special is special.