flowrep.parsers.constant_parser module
- exception flowrep.parsers.constant_parser.ConstantParseError[source]
Bases:
ValueErrorRaised when a literal call argument cannot become a constant node.
- flowrep.parsers.constant_parser.inject_constant(nodes: dict[Annotated[str, BeforeValidator(func=_validate_label, json_schema_input_type=PydanticUndefined)], Annotated[AtomicRecipe | ConstantRecipe | ForEachRecipe | IfRecipe | TryRecipe | WhileRecipe | WorkflowRecipe, FieldInfo(annotation=NoneType, required=True, discriminator='type')]], scope: SymbolScope, value: Any, consumer_label: str, consumer_port: str) None[source]
Create a
ConstantRecipefor value, register it in nodes, and wire its output into(consumer_label, consumer_port)as a peer edge.The
ConstantRecipemodel enforces the JSON invariant; a non-JSON literal (e.g. a tuple) surfaces here as aValidationErrorand is re-raised with the consuming node/port for context.
- flowrep.parsers.constant_parser.make_constant(value: Any, context: str) ConstantRecipe[source]
Build a
ConstantRecipefor value, re-raising the model’sValidationErroras aConstantParseErrorprefixed with context.The
ConstantRecipemodel is the single source of truth for the JSON/finite invariant; this only adds call-site context to the error.
- flowrep.parsers.constant_parser.try_parse_constant(arg: expr) tuple[bool, Any][source]
Return
(True, value)if arg is a Python literal, else(False, None).Uses
ast.literal_eval, so it accepts scalars, lists, dicts, and negatives, and returns(False, None)for names, calls, lambdas, comprehensions, etc.