The checks.py module#

Summary#

ensure_design_is_active

Make sure that the design is active before executing a method.

check_is_float_int

Check if a parameter has a float or integer value.

check_ndarray_is_float_int

Check if a numpy.ndarray has float/integer types.

check_ndarray_is_not_none

Check if a numpy.ndarray is all None.

check_ndarray_is_all_nan

Check if a numpy.ndarray is all nan-valued.

check_ndarray_is_non_zero

Check if a numpy.ndarray is zero-valued.

check_pint_unit_compatibility

Check if input pint.Unit is compatible with the expected input.

check_type_equivalence

Check if an input object is of the same class as an expected object.

check_type

Check if an input object is of the same type as expected types.

check_type_all_elements_in_iterable

Check if all elements in an iterable are of the same type as expected.

min_backend_version

Compare a minimum required version to the current backend version.

deprecated_method

Decorate a method as deprecated.

deprecated_argument

Decorate a method argument as deprecated.

Description#

Provides functions for performing common checks.

Module detail#

checks.ensure_design_is_active(method)#

Make sure that the design is active before executing a method.

This function is necessary to be called whenever we do any operation on the design. If we are just accessing information of the class, it is not necessary to call this.

checks.check_is_float_int(param: object, param_name: str | None = None) None#

Check if a parameter has a float or integer value.

Parameters:
paramobject

Object instance to check.

param_namestr, default: None

Parameter name (if any).

Raises:
TypeError

If the parameter does not have a float or integer value.

checks.check_ndarray_is_float_int(param: numpy.ndarray, param_name: str | None = None) None#

Check if a numpy.ndarray has float/integer types.

Parameters:
paramndarray

numpy.ndarray instance to check.

param_namestr, default: None

numpy.ndarray instance name (if any).

Raises:
TypeError

If the numpy.ndarray instance does not have float or integer values.

checks.check_ndarray_is_not_none(param: numpy.ndarray, param_name: str | None = None) None#

Check if a numpy.ndarray is all None.

Parameters:
paramndarray

numpy.ndarray instance to check.

param_namestr, default: None

numpy.ndarray instance name (if any).

Raises:
ValueError

If the numpy.ndarray instance has a value of None for all parameters.

checks.check_ndarray_is_all_nan(param: numpy.ndarray, param_name: str | None = None) None#

Check if a numpy.ndarray is all nan-valued.

Parameters:
paramndarray

numpy.ndarray instance to check.

param_namestr or None, default: None

numpy.ndarray instance name (if any).

Raises:
ValueError

If the numpy.ndarray instance is all nan-valued.

checks.check_ndarray_is_non_zero(param: numpy.ndarray, param_name: str | None = None) None#

Check if a numpy.ndarray is zero-valued.

Parameters:
paramndarray

numpy.ndarray instance to check.

param_namestr, default: None

numpy.ndarray instance name (if any).

Raises:
ValueError

If the numpy.ndarray instance is zero-valued.

checks.check_pint_unit_compatibility(input: pint.Unit, expected: pint.Unit) None#

Check if input pint.Unit is compatible with the expected input.

Parameters:
inputUnit

pint.Unit input.

expectedUnit

pint.Unit expected dimensionality.

Raises:
TypeError

If the input is not compatible with the pint.Unit class.

checks.check_type_equivalence(input: object, expected: object) None#

Check if an input object is of the same class as an expected object.

Parameters:
inputobject

Input object.

expectedobject

Expected object.

Raises:
TypeError

If the objects are not of the same class.

checks.check_type(input: object, expected_type: type | tuple[type, Ellipsis]) None#

Check if an input object is of the same type as expected types.

Parameters:
inputobject

Input object.

expected_typetype | tuple[type, …]

One or more types to compare the input object against.

Raises:
TypeError

If the object does not match the one or more expected types.

checks.check_type_all_elements_in_iterable(input: collections.abc.Iterable, expected_type: type | tuple[type, Ellipsis]) None#

Check if all elements in an iterable are of the same type as expected.

Parameters:
inputIterable

Input iterable.

expected_typetype | tuple[type, …]

One or more types to compare the input object against.

Raises:
TypeError

If one of the elements in the iterable does not match the one or more expected types.

checks.min_backend_version(major: int, minor: int, service_pack: int)#

Compare a minimum required version to the current backend version.

Parameters:
majorint

Minimum major version required by the method.

minorint

Minimum minor version required by the method.

service_packint

Minimum service pack version required by the method.

Raises:
GeometryRuntimeError

If the method version is higher than the backend version.

GeometryRuntimeError

If the client is not available.

checks.deprecated_method(alternative: str | None = None, info: str | None = None)#

Decorate a method as deprecated.

Parameters:
alternativestr, default: None

Alternative method to use. If provided, the warning message will include the alternative method.

infostr, default: None

Additional information to include in the warning message.

checks.deprecated_argument(arg: str, alternative: str | None = None, info: str | None = None)#

Decorate a method argument as deprecated.

Parameters:
argstr

Argument to mark as deprecated.

alternativestr, default: None

Alternative argument to use. If provided, the warning message will include the alternative argument.

infostr, default: None

Additional information to include in the warning message.