firecrown.descriptors
Type validation as used in connectors.
Validators are created using the constructor for each class. Access to the data done through the object name, not through any named function. Setting the data is validated with the class’s validate function; the user does not need to call any special functions.
Validators are intended for use in class definitions. An example is a class that has an attribute x that is required to be a float in the range [1.0, 3.0], but is optional and has a default value of None:
class SampleValidatedThing:
x = TypeFloat(1.0, 3.0, allow_none=True)
def __init__(self):
self.x = None
Classes
Floating point number attribute descriptor. |
|
String attribute descriptor. |
Module Contents
- class firecrown.descriptors.TypeFloat(minvalue=None, maxvalue=None, allow_none=False)[source]
Floating point number attribute descriptor.
- Parameters:
minvalue (None | float)
maxvalue (None | float)
allow_none (bool)
- minvalue = None
- maxvalue = None
- allow_none = False
- validate(value)[source]
Run all validators on this value.
Raise an exception if the provided value does not meet all of the required conditions enforced by this validator.
- Parameters:
value (None | float)
- Return type:
None
- __set_name__(_, name)[source]
Create the name of the private instance variable that will hold the value.
- Parameters:
name (str) – The name of the private instance variable to be created.
- Return type:
None
- class firecrown.descriptors.TypeString(minsize=None, maxsize=None, predicate=None)[source]
String attribute descriptor.
TypeStringprovides several different means of validation of the controlled string attribute, all of which are optional.- Parameters:
minsize (None | int)
maxsize (None | int)
predicate (None | collections.abc.Callable[[str], bool])
- minsize = None
- maxsize = None
- predicate = None
- validate(value)[source]
Run all validators on this value.
Raise an exception if the provided value does not meet all of the required conditions enforced by this validator.
- Parameters:
value (None | str) – The value to be validated.
- Return type:
None
- __set_name__(_, name)[source]
Create the name of the private instance variable that will hold the value.
- Parameters:
name (str) – The name of the private instance variable to be created.
- Return type:
None