ros_sugar.config.base_attrs
#
Module Contents#
Classes#
Implements setattr method to re-use validators at set time |
API#
- class ros_sugar.config.base_attrs.BaseAttrs#
Implements setattr method to re-use validators at set time
- asdict(filter: Optional[Callable] = None) Dict #
Convert class to dict.
- Return type:
dict
- from_dict(dict_obj: Dict) None #
Gets attributes values from given dictionary
- Parameters:
dict_obj (Dict) – Dictionary {attribute_name: attribute_value}
- Raises:
ValueError – If attribute_name in dictionary does not exists in class attributes
TypeError – If attribute_value type in dictionary does not correspond to class attribute type
- from_yaml(file_path: str, nested_root_name: str | None = None, get_common: bool = False) None #
Update class attributes from yaml
- Parameters:
file_path (str) – Path to config file (.yaml)
nested_root_name (str | None, optional) – Nested root name for the config, defaults to None
- to_json() Union[str, bytes, bytearray] #
Dump to json
- Returns:
description
- Return type:
str | bytes | bytearray
- from_json(json_obj: Union[str, bytes, bytearray]) None #
Gets attributes values from given json
- Parameters:
json_obj (str | bytes | bytearray) – Json object
- has_attribute(attr_name: str) bool #
Checks if class object has attribute with given name
- Parameters:
attr_name (str) – description
- Returns:
If object has attribute with given name
- Return type:
bool
- get_attribute_type(attr_name: str) Optional[type] #
Gets type of given attribute name
- Parameters:
attr_name (str) – description
- Raises:
AttributeError – If class does not have attribute with given name
- Returns:
Attribute type
- Return type:
type
- update_value(attr_name: str, attr_value: Any) bool #
Updates the value of an attribute in the class
- Parameters:
attr_name (str) – Attribute name - can be nested name
attr_value (Any) – Attribute value
- Raises:
AttributeError – If class does not containe attribute with given name
TypeError – If class attribute with given name if of different type
- Returns:
If attribute value is updated
- Return type:
bool