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

TypeFloat

Floating point number attribute descriptor.

TypeString

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

__get__(obj, objtype=None)[source]

Accessor method, which reads controlled value.

This is invoked whenever the validated variable is read.

Parameters:
  • obj – The object that contains the validated variable.

  • objtype – The type of the object that contains the validated variable.

Return type:

float

__set__(obj, value)[source]

Setter for the validated variable.

This function invokes the validate method of the derived class.

Parameters:
  • obj – The object that contains the validated variable.

  • value (None | float) – The new value of the validated variable.

Return type:

None

class firecrown.descriptors.TypeString(minsize=None, maxsize=None, predicate=None)[source]

String attribute descriptor.

TypeString provides 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

__get__(obj, objtype=None)[source]

Accessor method, which reads controlled value.

This is invoked whenever the validated variable is read.

Parameters:
  • obj – The object that contains the validated variable.

  • objtype – The type of the object that contains the validated variable.

Return type:

str

__set__(obj, value)[source]

Setter for the validated variable.

This function invokes the validate method of the derived class.

Parameters:
  • obj – The object that contains the validated variable.

  • value (None | str) – The new value of the validated variable.

Return type:

None