weldx.util.ureg_check_class#

weldx.util.ureg_check_class(*args)#

Decorate class __init__ function with pint.UnitRegistry.check.

Useful for adding unit checks to classes created with @dataclass decorator.

Parameters:

args (str or pint.util.UnitsContainer or None) – Dimensions of each of the input arguments. Use None to skip argument conversion.

Returns:

The class with unit checks added to its __init__ function.

Return type:

type

Raises:
  • TypeError – If number of given dimensions does not match the number of function parameters.

  • ValueError – If the any of the provided dimensions cannot be parsed as a dimension.

Examples

A simple dataclass could look like this:

@ureg_check_class("[length]","[time]")
@dataclass
class A:
    a: pint.Quantity
    b: pint.Quantity

A(Q_(3,"mm"),Q_(3,"s"))