pyhs3.generic_parse.GenericExpressionMixin¶
- class pyhs3.generic_parse.GenericExpressionMixin[source]¶
Mixin for pydantic models that evaluate a user-supplied math expression string.
Inherit this mixin before the pydantic
BaseModel(or subclass such asEvaluable) in the MRO, e.g.:class MyDist(GenericExpressionMixin, Distribution): ...
The mixin automatically provides:
model_config— allowssp.Exprprivate attributes and alias-based serialisation.expression_str— the raw expression string, aliased to"expression"in serialised form.setup_expression— a@model_validator(mode="after")that parses and analyses the expression at construction time.
Subclasses do not need to redeclare any of these.
- Variables:
model_config – Pydantic config that permits
sp.Exprprivate attrs.expression_str – The raw mathematical expression string (aliased to
"expression"in serialised form).
- __init__()¶
Methods
Parse and analyze the expression during initialization.
Attributes
- GenericExpressionMixin.setup_expression()[source]¶
Parse and analyze the expression during initialization.
- Return type:
- GenericExpressionMixin.expression_str¶