configconfig.validator

Validate values obtained from the YAML file and coerce into the appropriate return types.

Classes:

Validator(config_var)

Methods are named visit_<type>.

Functions:

validate_files(schemafile, *datafiles[, …])

Validate the given datafiles against the given schema.

class Validator(config_var)[source]

Bases: object

Methods are named visit_<type>.

Methods:

unknown_type()

Called when the desired type has no visitor.

validate([raw_config_vars])

Validate the configuration value.

visit_bool(raw_config_vars)

Used to validate and convert bool values.

visit_dict(raw_config_vars)

Used to validate and convert dict values.

visit_float(raw_config_vars)

Used to validate and convert float values.

visit_int(raw_config_vars)

Used to validate and convert int values.

visit_list(raw_config_vars)

Used to validate and convert list values.

visit_literal(raw_config_vars)

Used to validate and convert typing.Literal values.

visit_str(raw_config_vars)

Used to validate and convert str values.

visit_union(raw_config_vars)

Used to validate and convert typing.Union values.

unknown_type()[source]

Called when the desired type has no visitor.

Return type

NoReturn

validate(raw_config_vars=None)[source]

Validate the configuration value.

Parameters

raw_config_vars (Optional[Dict[str, Any]]) – Default None.

Return type

Any

Returns

The validated value.

visit_bool(raw_config_vars)[source]

Used to validate and convert bool values.

Parameters

raw_config_vars (Dict[str, Any])

Return type

bool

visit_dict(raw_config_vars)[source]

Used to validate and convert dict values.

Parameters

raw_config_vars (Dict[str, Any])

Return type

Dict

visit_float(raw_config_vars)[source]

Used to validate and convert float values.

Parameters

raw_config_vars (Dict[str, Any])

Return type

float

visit_int(raw_config_vars)[source]

Used to validate and convert int values.

Parameters

raw_config_vars (Dict[str, Any])

Return type

int

visit_list(raw_config_vars)[source]

Used to validate and convert list values.

Parameters

raw_config_vars (Dict[str, Any])

Return type

List

visit_literal(raw_config_vars)[source]

Used to validate and convert typing.Literal values.

Parameters

raw_config_vars (Dict[str, Any])

Return type

Any

visit_str(raw_config_vars)[source]

Used to validate and convert str values.

Parameters

raw_config_vars (Dict[str, Any])

Return type

str

visit_union(raw_config_vars)[source]

Used to validate and convert typing.Union values.

Parameters

raw_config_vars (Dict[str, Any])

Return type

Any

validate_files(schemafile, *datafiles, encoding='utf-8')[source]

Validate the given datafiles against the given schema.

Parameters
  • schemafile (Union[str, Path, PathLike]) – The json or yaml formatted schema to validate with.

  • *datafiles (Union[str, Path, PathLike]) – The json or yaml files to validate.

  • encoding (str) – Encoding to open the files with. Default 'utf-8'.

New in version 0.4.0.