Skip to content

Update all Array properties so we can automatically convert those from "alfacase" #199

@prusse-martin

Description

@prusse-martin

Update all Array properties, like:

time: Array = attr.ib(default=Array([0], "s"), validator=instance_of(Array))
speed: Array = attr.ib(default=Array([500], "rpm"), validator=instance_of(Array))

to populate the attrib metadata, like:

tracer_mass_fraction: Array = attr.ib(
default=Array([], "-"),
validator=instance_of(Array),
metadata={"type": "array", "category": "mass fraction"},
)

so we can use get_case_description_attribute_loader_dict to automatically convert those from "alfacase".

The ideal solution would be to use a helper function like:

def attrib_scalar(
default: Union[ScalarLike, AttrNothingType] = attr.NOTHING,
is_optional: bool = False,
category: Optional[str] = None,
) -> attr._make._CountingAttr:
"""
Create a new attr attribute with a converter to Scalar accepting also tuple(value, unit).
:param default:
Value to be used as default when instantiating a class with this attr.ib
If a default is not set (``attr.NOTHING``), a value must be supplied when instantiating;
otherwise, a `TypeError` will be raised.
"""

Some usages of attrib_scalar:

position = attrib_scalar(category="length")

trend_frequency = attrib_scalar(default=Scalar(0.1, "s"))

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions