RuleAttrExist Class
- class kwhelp.rules.RuleAttrExist(key: str, name: str, value: object, raise_errors: bool, originator: object)[source]
Bases:
kwhelp.rules.IRuleRule to ensure an attribute does exist before its value is set.
- __init__(key: str, name: str, value: object, raise_errors: bool, originator: object)
Constructor
- Parameters
key (str) – the key that rule is to apply to.
name (str) – the name of the field that value was assigned
value (object) – the value that is assigned to
field_nameraise_errors (bool) – determinins if rule could raise an error when validation fails
originator (object) – the object that attributes validated for
- Raises
TypeError – If any arg is not of the correct type
- validate() bool[source]
Validates that
field_nameis an existing attribute oforiginatorinstance.- Raises
AttributeError – If
raise_errorsisTrueandfield_nameis not an attribue oforiginatorinstance.- Returns
Trueiffield_nameis an existing attribue oforiginatorinstance; Otherwise,False.- Return type
bool
- property field_name: str
Name of the field assigned.
- Getter
Gets the name of the field assigned
- Setter
Sets the name of the field assigned
- property field_value: object
The value assigned to
field_name- Getter
Gets value assigned to
field_name- Setter
Sets value assigned to
field_name
- property key: str
Gets the key currently being read
- property originator: object
Gets object that attributes validated for
- property raise_errors: bool
Determines if a rule can raise an error when validation fails.
- Getter
Gets if a rule could raise an error when validation fails
- Setter
Sets if a rule could raise an error when validation fails