types

Added in version 3.2.0.

This module contains the internal type definitions and utility functions for working with them.

Functions

coerce_value(value, verify_type=True)[source]

Take a native Python value and convert it to a value of a data type which can be represented by a Rule Engine DataType. This function is useful for converting native Python values at the engine boundaries such as when resolving a symbol from an object external to the engine.

Added in version 2.0.0.

Parameters:
  • value – The value to convert.

  • verify_type (bool) – Whether or not to verify the converted value’s type.

Returns:

The converted value.

is_integer_number(value)[source]

Check whether value is an integer number (i.e. a whole, number). This can, for example, be used to check if a floating point number such as 3.0 can safely be converted to an integer without loss of information.

Added in version 2.1.0.

Parameters:

value – The value to check. This value is a native Python type.

Returns:

Whether or not the value is an integer number.

Return type:

bool

is_natural_number(value)[source]

Check whether value is a natural number (i.e. a whole, non-negative number). This can, for example, be used to check if a floating point number such as 3.0 can safely be converted to an integer without loss of information.

Parameters:

value – The value to check. This value is a native Python type.

Returns:

Whether or not the value is a natural number.

Return type:

bool

is_numeric(value)[source]

Check whether value is a numeric value (i.e. capable of being represented as a floating point value without loss of information).

Parameters:

value – The value to check. This value is a native Python type.

Returns:

Whether or not the value is numeric.

Return type:

bool

is_real_number(value)[source]

Check whether value is a real number (i.e. capable of being represented as a floating point value without loss of information as well as being finite). Despite being able to be represented as a float, NaN is not considered a real number for the purposes of this function.

Parameters:

value – The value to check. This value is a native Python type.

Returns:

Whether or not the value is a natural number.

Return type:

bool

iterable_member_value_type(python_value)[source]

Take a native python_value and return the corresponding data type of each of its members if the types are either the same or NULL. NULL is considered a special case to allow nullable-values. This by extension means that an iterable may not be defined as only capable of containing NULL values.

Returns:

The data type of the sequence members. This will never be NULL, because that is considered a special case. It will either be UNSPECIFIED or one of the other types.

Classes

class DataType[source]

Bases: object

A collection of constants representing the different supported data types. There are three ways to compare data types. All three are effectively the same when dealing with scalars.

Equality checking
dt == DataType.TYPE

This is the most explicit form of testing and when dealing with compound data types, it recursively checks that all of the member types are also equal.

Class checking
isinstance(dt, DataType.TYPE.__class__)

This checks that the data types are the same but when dealing with compound data types, the member types are ignored.

Compatibility checking
DataType.is_compatible(dt, DataType.TYPE)

This checks that the types are compatible without any kind of conversion. When dealing with compound data types, this ensures that the member types are either the same or UNDEFINED.

static ARRAY(value_type, value_type_nullable=True)
Parameters:
  • value_type – The type of the members.

  • value_type_nullable (bool) – Whether or not members are allowed to be NULL.

BOOLEAN
BYTES
DATETIME
FLOAT
static FUNCTION(name, return_type=UNDEFINED, argument_types=UNDEFINED, minimum_arguments=None)

Added in version 4.0.0.

Parameters:
  • name (str) – The name of the function, e.g. “split”.

  • return_type – The data type of the functions return value.

  • argument_types (tuple) – The data types of the functions arguments.

  • minimum_arguments (int) – The minimum number of arguments the function requires.

If argument_types is specified and minimum_arguments is not, then minimum_arguments will default to the length of argument_types effectively meaning that every defined argument is required. If

static MAPPING(key_type, value_type=UNDEFINED, value_type_nullable=True)
Parameters:
  • key_type – The type of the mapping keys.

  • value_type – The type of the mapping values.

  • value_type_nullable (bool) – Whether or not mapping values are allowed to be NULL.

NULL
static SET(value_type, value_type_nullable=True)
Parameters:
  • value_type – The type of the members.

  • value_type_nullable (bool) – Whether or not members are allowed to be NULL.

STRING
TIMEDELTA
UNDEFINED = UNDEFINED

Undefined values. This constant can be used to indicate that a particular symbol is valid, but it’s data type is currently unknown.

UNDEFINED = UNDEFINED

Undefined values. This constant can be used to indicate that a particular symbol is valid, but it’s data type is currently unknown.

classmethod from_name(name)[source]

Get the data type from its name.

Added in version 2.0.0.

Parameters:

name (str) – The name of the data type to retrieve.

Returns:

One of the constants.

classmethod from_type(python_type)[source]

Get the supported data type constant for the specified Python type/type hint. If the type or typehint can not be mapped to a supported data type, then a ValueError exception will be raised. This function will not return UNDEFINED.

Parameters:

python_type (type) – The native Python type or type hint to retrieve the corresponding type constant for.

Returns:

One of the constants.

Changed in version 4.1.0: Added support for typehints.

classmethod from_value(python_value)[source]

Get the supported data type constant for the specified Python value. If the value can not be mapped to a supported data type, then a TypeError exception will be raised. This function will not return UNDEFINED.

Parameters:

python_value – The native Python value to retrieve the corresponding data type constant for.

Returns:

One of the constants.

classmethod is_compatible(dt1, dt2)[source]

Check if two data type definitions are compatible without any kind of conversion. This evaluates to True when one or both are UNDEFINED or both types are the same. In the case of compound data types (such as ARRAY) the member types are checked recursively in the same manner.

Added in version 2.1.0.

Parameters:
  • dt1 – The first data type to compare.

  • dt2 – The second data type to compare.

Returns:

Whether or not the two types are compatible.

Return type:

bool

classmethod is_definition(value)[source]

Check if value is a data type definition.

Added in version 2.1.0.

Parameters:

value – The value to check.

Returns:

True if value is a data type definition.

Return type:

bool