backend.typed
Handles the definitions of arguments types for Spock (backend: attrs)
#
SavePath Objectsclass SavePath(str)
Spock special key for saving the Spock config to file
Defines a special key use to save the current Spock config to file
#
_extract_base_typedef _extract_base_type(typed)
Extracts the name of the type from a _GenericAlias
Assumes that the derived types are only of length 1 as the args are [0] recursed... this is not true for tuples
Arguments:
typed
- the type of the parameter
Returns:
name of type
#
_recursive_generic_validatordef _recursive_generic_validator(typed)
Recursively assembles the validators for nested generic types
Walks through the nested type structure and determines whether to recurse all the way to a base type. Once it hits the base type it bubbles up the correct validator that is nested within the upper validator
Arguments:
typed
- input type
Returns:
return_type
- recursively built deep_iterable validators
#
_generic_alias_katradef _generic_alias_katra(typed, default=None, optional=False)
Private interface to create a subscripted generic_alias katra
A 'katra' is the basic functional unit of spock
. It defines a parameter using
attrs as the backend, type checks
both simple types and subscripted GenericAlias types (e.g. lists and tuples),
handles setting default parameters,
and deals with parameter optionality
Handles: List[type], Tuple[type], Dict[type]
Arguments:
typed
- the type of the parameter to definedefault
- the default value to assign if givenoptional
- whether to make the parameter optional or not (thus allowing None)
Returns:
x
- Attribute from attrs
#
_check_enum_propsdef _check_enum_props(typed)
Handles properties of enums
Checks if all types of the enum are the same and assembles a list of allowed values
Arguments:
typed
- the type of parameter (Enum)
Returns:
base_type
- the base type of the Enumallowed
- List of allowed values of the Enum
#
_enum_katradef _enum_katra(typed, default=None, optional=False)
Private interface to create a Enum typed katra
A 'katra' is the basic functional unit of spock
. It defines a parameter using
attrs as the backend, type checks
both simple types and subscripted GenericAlias types (e.g. lists and tuples),
handles setting default parameters,
and deals with parameter optionality
Arguments:
typed
- the type of the parameter to definedefault
- the default value to assign if givenoptional
- whether to make the parameter optional or not (thus allowing None)
Returns:
x
- Attribute from attrs
#
_cast_enum_defaultdef _cast_enum_default(default)
Allows the enum default to be the specific value or the Enum structured value
Checks if enum type and extracts the value from the Enum
Arguments:
default
- the default value to assign if given
Returns:
default value or the Enum extracted value
#
_enum_base_katradef _enum_base_katra(typed, base_type, allowed, default=None, optional=False)
Private interface to create a base Enum typed katra
Here we handle the base types of enums that allows us to force a type check on the instance
A 'katra' is the basic functional unit of spock
. It defines a parameter using
attrs as the backend, type checks
both simple types and subscripted GenericAlias types (e.g. lists and tuples),
handles setting default parameters,
and deals with parameter optionality
Arguments:
typed
- the type of the parameter to definebase_type
- underlying base typeallowed
- set of allowed valuesdefault
- the default value to assign if givenoptional
- whether to make the parameter optional or not (thus allowing None)
Returns:
x
- Attribute from attrs
#
_enum_class_katradef _enum_class_katra(typed, allowed, default=None, optional=False)
Private interface to create a base Enum typed katra
Here we handle the class based types of enums. Seeing as these classes are generated dynamically we cannot force type checking of a specific instance however the in_ validator will catch an incorrect instance type
A 'katra' is the basic functional unit of spock
. It defines a parameter using
attrs as the backend, type checks
both simple types and subscripted GenericAlias types (e.g. lists and tuples),
handles setting default parameters,
and deals with parameter optionality
Arguments:
typed
- the type of the parameter to defineallowed
- set of allowed valuesdefault
- the default value to assign if givenoptional
- whether to make the parameter optional or not (thus allowing None)
Returns:
x
- Attribute from attrs
#
_type_katradef _type_katra(typed, default=None, optional=False)
Private interface to create a simple typed katra
A 'katra' is the basic functional unit of spock
. It defines a parameter using
attrs as the backend, type checks
both simple types and subscripted GenericAlias types (e.g. lists and tuples),
handles setting default parameters,
and deals with parameter optionality
Handles: bool, string, float, int, List, and Tuple
Arguments:
typed
- the type of the parameter to definedefault
- the default value to assign if givenoptional
- whether to make the parameter optional or not (thus allowing None)
Returns:
x
- Attribute from attrs
#
_handle_optional_typingdef _handle_optional_typing(typed)
Handles when a type hint is Optional
Handles Optional[type] typing and strips out the base type to pass back to the creation of a katra which needs base typing
Arguments:
typed
- type
Returns:
typed
- type (modified if Optional)optional
- boolean for katra creation
#
_callable_katradef _callable_katra(typed, default=None, optional=False)
Private interface to create a Callable katra
Here we handle the callable type katra that allows us to force a callable check on the value provided
A 'katra' is the basic functional unit of spock
. It defines a parameter using attrs as the backend, type checks
both simple types and subscripted GenericAlias types (e.g. lists and tuples), handles setting default parameters,
and deals with parameter optionality
Handles: callable
Arguments:
typed
- the type of the parameter to definedefault
- the default value to assign if givenoptional
- whether to make the parameter optional or not (thus allowing None)
Returns:
x
- Attribute from attrs
#
katradef katra(typed, default=None, inherit_optional=False)
Public interface to create a katra
A 'katra' is the basic functional unit of spock
. It defines a parameter using
attrs as the backend, type checks both simple types and subscripted GenericAlias
types (e.g. lists and tuples), handles setting default parameters,
and deals with parameter optionality
Arguments:
typed
- the type of the parameter to definedefault
- the default value to assign if giveninherit_optional
- optionality from inheritance
Returns:
x
- Attribute from attrs