pycram.has_parameters#

Attributes#

HasParameters

Base class for everything that contains potentially parameters for a plan.

LeafTypes

leaf_types

T

Classes#

HasParametersMeta

Metaclass for flattening and reconstructing nested Python datastructures until they reach something mentioned in leaf_types.

HasParameters

Base class for everything that contains potentially parameters for a plan.

Functions#

has_parameters(→ T)

Insert parameters of a class post construction.

Module Contents#

pycram.has_parameters.HasParameters#
pycram.has_parameters.LeafTypes#
pycram.has_parameters.leaf_types#
class pycram.has_parameters.HasParametersMeta(*args, **kwargs)#

Bases: type

Metaclass for flattening and reconstructing nested Python datastructures until they reach something mentioned in leaf_types. This is very similar to JAX PyTrees `https://docs.jax.dev/en/latest/pytrees.html#pytrees`_. Will scan the constructor of the class for fields to be used and not class variables.

_parameters: ParameterDict = None#

A dictionary that maps field names to their types, including nested types. The keys are the names of the variables. The values are the types of the variables or nested types.

classmethod create_parameters(target_class)#

Creates the flattened parameters for the given class.

Parameters:

target_class – Class for which to create the parameters.

class pycram.has_parameters.HasParameters#

Base class for everything that contains potentially parameters for a plan.

flatten() typing_extensions.List#

Flattens the object into a list of field values.

Returns:

A list of flattened field values from the object.

Raises:

TypeError – If the object is not an instance of the target class.

classmethod flattened_parameters() typing_extensions.Dict[str, leaf_types]#

Returns a dictionary of all flattened fields and their types.

Returns:

A dictionary mapping field names to their types.

classmethod number_of_fields() int#
Returns:

The total number of fields in the flattened list.

classmethod field_indices() typing_extensions.Dict[str, typing_extensions.Tuple[int, int]]#
Returns:

A dictionary mapping field names to their indices in the flattened list.

classmethod reconstruct(flattened: typing_extensions.List)#

Reconstructs the object from a flattened list of field values.

Parameters:

flattened – The flattened list of field values.

Returns:

An instance of the target class with the reconstructed field values.

Raises:

TypeError – If the object is not a list or if the length of the list does not match the number of fields.

classmethod define_parameters() ParameterDict#
Abstractmethod:

Override this method if you want to define a custom parameter dict for this class.

Returns:

Dict like cls._parameters

pycram.has_parameters.T#
pycram.has_parameters.has_parameters(target_class: T) T#

Insert parameters of a class post construction. Use this when dataclasses should be combined with HasParameters.

Parameters:

target_class – The class to get the parameters from.

Returns:

The updated class