Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
prusse-martin opened this issue Oct 14, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@prusse-martin
Copy link
Member

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"))

@prusse-martin prusse-martin added the enhancement New feature or request label Oct 14, 2021
@prusse-martin prusse-martin changed the title Update all Array properties so we can automatically convert those from "alfacase" Update all Array properties so we can automatically convert those from "alfacase" Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant