flowrep.parsers.constant_parser module

exception flowrep.parsers.constant_parser.ConstantParseError[source]

Bases: ValueError

Raised 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 ConstantRecipe for value, register it in nodes, and wire its output into (consumer_label, consumer_port) as a peer edge.

The ConstantRecipe model enforces the JSON invariant; a non-JSON literal (e.g. a tuple) surfaces here as a ValidationError and is re-raised with the consuming node/port for context.

flowrep.parsers.constant_parser.make_constant(value: Any, context: str) ConstantRecipe[source]

Build a ConstantRecipe for value, re-raising the model’s ValidationError as a ConstantParseError prefixed with context.

The ConstantRecipe model 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.