add_ro_dict_property

sconstool.util.add_ro_dict_property(cls, dictattr, attr, default=None, **kw)[source]

Add to class cls a read-only property returning a predefined entry from a dict.

Parameters:
  • cls (type) – the target class to be modified,
  • dictattr (str) – name of the attribute of cls being the source dict,
  • attr (str,tuple) – name of the generated attribute, or a tuple (attr, key), where attr is the generated attribute name and key is the corresponding key in the dictionary,
  • default – default value returned by the property, if the dictionary has no requested key, if default is callable, it shall be a function default(obj), where an instance of cls will be passed as obj,
  • doc (str) – optional documentation string, the string may use substitutions, such as "%(cls)s", "%(dictattr)s", "%(attr)s", "%(key)s", "%(default)s". Extra variables for necessary substitutions may be provided via keyword arguments **kw.