The checks.py module#
Summary#
Make sure that the design is active before executing a method. |
|
Check if a parameter has a float or integer value. |
|
Check if a |
|
Check if a |
|
Check if a |
|
Check if a |
|
Check if input |
|
Check if an input object is of the same class as an expected object. |
|
Check if an input object is of the same type as expected types. |
|
Check if all elements in an iterable are of the same type as expected. |
|
Compare a minimum required version to the current backend version. |
|
Decorate a method as deprecated. |
|
Decorate a method argument as deprecated. |
|
Check if graphics are available. |
|
Decorate a method as requiring graphics. |
|
Check that no unexpected kwargs are passed to the method. |
Message to display when graphics are required for a method. |
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.
- checks.check_ndarray_is_float_int(param: numpy.ndarray, param_name: str | None = None) None#
Check if a
numpy.ndarrayhas float/integer types.- Parameters:
- param
ndarray numpy.ndarrayinstance to check.- param_name
str, default:None numpy.ndarrayinstance name (if any).
- param
- Raises:
TypeErrorIf the
numpy.ndarrayinstance 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.ndarrayis allNone.- Parameters:
- param
ndarray numpy.ndarrayinstance to check.- param_name
str, default:None numpy.ndarrayinstance name (if any).
- param
- Raises:
ValueErrorIf the
numpy.ndarrayinstance has a value ofNonefor all parameters.
- checks.check_ndarray_is_all_nan(param: numpy.ndarray, param_name: str | None = None) None#
Check if a
numpy.ndarrayis all nan-valued.- Parameters:
- param
ndarray numpy.ndarrayinstance to check.- param_name
strorNone, default:None numpy.ndarrayinstance name (if any).
- param
- Raises:
ValueErrorIf the
numpy.ndarrayinstance is all nan-valued.
- checks.check_ndarray_is_non_zero(param: numpy.ndarray, param_name: str | None = None) None#
Check if a
numpy.ndarrayis zero-valued.- Parameters:
- param
ndarray numpy.ndarrayinstance to check.- param_name
str, default:None numpy.ndarrayinstance name (if any).
- param
- Raises:
ValueErrorIf the
numpy.ndarrayinstance is zero-valued.
- checks.check_pint_unit_compatibility(input: pint.Unit, expected: pint.Unit) None#
Check if input
pint.Unitis compatible with the expected input.
- checks.check_type_equivalence(input: object, expected: object) None#
Check if an input object is of the same class as an expected object.
- 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.
- 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.
- checks.min_backend_version(major: int, minor: int, service_pack: int)#
Compare a minimum required version to the current backend version.
- Parameters:
- Raises:
GeometryRuntimeErrorIf the method version is higher than the backend version.
GeometryRuntimeErrorIf the client is not available.
- checks.deprecated_method(alternative: str | None = None, info: str | None = None, version: str | None = None, remove: str | None = None)#
Decorate a method as deprecated.
- Parameters:
- alternative
str, default:None Alternative method to use. If provided, the warning message will include the alternative method.
- info
str, default:None Additional information to include in the warning message.
- version
str, default:None Version where the method was deprecated.
- remove
str, default:None Version where the method will be removed.
- alternative
- checks.deprecated_argument(arg: str, alternative: str | None = None, info: str | None = None, version: str | None = None, remove: str | None = None)#
Decorate a method argument as deprecated.
- Parameters:
- arg
str Argument to mark as deprecated.
- alternative
str, default:None Alternative argument to use. If provided, the warning message will include the alternative argument.
- info
str, default:None Additional information to include in the warning message.
- version
str, default:None Version where the method was deprecated.
- remove
str, default:None Version where the method will be removed.
- arg
- checks.run_if_graphics_required()#
Check if graphics are available.
- checks.graphics_required(method)#
Decorate a method as requiring graphics.
- Parameters:
- method
callable() Method to decorate.
- method
- Returns:
callable()Decorated method.
- checks.kwargs_passed_not_accepted(method)#
Check that no unexpected kwargs are passed to the method.
This decorator will raise a TypeError if any keyword arguments are passed to the decorated method that don’t correspond to the method’s parameters. If the method has
**kwargsin its signature, this decorator will raise an error for any kwargs passed to it (that are not explicitly accepted).- Parameters:
- method
callable() The method to decorate.
- method
- Returns:
callable()Decorated method that raises TypeError if unexpected kwargs are passed.
- Raises:
TypeErrorIf unexpected keyword arguments are passed to the decorated method.
Examples
>>> @kwargs_passed_not_accepted ... def my_method(arg1, arg2): ... return arg1 + arg2 >>> my_method(1, 2) # Works fine 3 >>> my_method(arg1=1, arg2=2) # Works fine 3 >>> my_method(1, 2, invalid_arg=3) # Raises TypeError TypeError: The following keyword arguments are not accepted in the method 'my_method': invalid_arg. >>> @kwargs_passed_not_accepted ... def my_method_with_kwargs(arg1, arg2, **kwargs): ... return arg1 + arg2 >>> my_method_with_kwargs(1, 2, invalid_arg=3) # Raises TypeError TypeError: The following keyword arguments are not accepted in the method 'my_method_with_kwargs': invalid_arg.
- checks.ERROR_GRAPHICS_REQUIRED = 'Graphics are required for this method. Please install the ``graphics`` target to use this...#
Message to display when graphics are required for a method.