The implicit_coercion.py module#

Summary#

implicit_coerce_single

Attempt to coerce the argument into the given type.

implicit_coerce

Use to decorate functions using the PEP 484 typing system to try and coerce any

Description#

Provides utilities for implicitly coercing arbitrary Python objects into the appropriate IVariableValue type.

Module detail#

implicit_coercion.implicit_coerce_single(arg: Any, arg_type: type) Any#

Attempt to coerce the argument into the given type.

This function uses implicit semantics in that lossy conversions are not considered (such as int64->real64 because precision may be lost).

Parameters:
argAny

Object to attempt to convert.

arg_typetype

Type of object to convert to. The type must be IVariableValue or something derived from it.

Returns:
Any

Converted object

Raises:
TypeError

If the argument cannot be converted to the supplied type.

implicit_coercion.implicit_coerce(func: Any) Any#

Use to decorate functions using the PEP 484 typing system to try and coerce any arguments that accept the IVariableValue type or any derived type into an acceptable value.

Parameters:
funcAny

Function to decorate.

Returns:
Any

Wrapper function.