iodata.attrutils module

Utilities for building attr classes.


Return a function to convert arrays to the given type.


Return a validator for the shape of an array or the length of an iterable.


shape_requirements (tuple) – Specifications for the required shape. Every item of the tuple describes the required size of the corresponding axis of an array. Also the number of items should match the dimensionality of the array. When the validator is used for general iterables, this tuple should contain just one element. Possible values for each item are explained in the “Notes” section below.


A validator function for the attr library.

Return type



Every element of shape_requirements defines the expected size of an array along the corresponding axis. An item in this tuple at position (or index) i can be one of the following:

  1. An integer, which is taken as the expected size along axis i.

  2. None. In this case, the size of the array along axis i is not checked.

  3. A string, which should be the name of another integer attribute with the expected size along axis i. The other attribute is always an attribute of the same object as the attribute being checked.

  4. A 2-tuple containing a name and an integer. In this case, the name refers to another attribute which is an array or an iterable. When the integer is 0, just the length of the other attribute is used. When the integer is non-zero, the other attribute must be an array and the integer selects an axis. The size of the other array along the selected axis is then used as the expected size of the array being checked along axis i.