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 as Evaluable) in the MRO, e.g.:

class MyDist(GenericExpressionMixin, Distribution): ...

The mixin automatically provides:

  • model_config — allows sp.Expr private 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.Expr private attrs.

  • expression_str – The raw mathematical expression string (aliased to "expression" in serialised form).

__init__()

Methods

setup_expression()

Parse and analyze the expression during initialization.

Attributes

GenericExpressionMixin.setup_expression()[source]

Parse and analyze the expression during initialization.

Return type:

GenericExpressionMixin

GenericExpressionMixin.expression_str