flowrep.compiler.annotate module
Render Python defaults and annotations into self-contained source text.
Each helper produces candidate source text and then verifies that the text
reconstructs the original object (render-then-verify). On any failure it returns
None so the caller can fall back to binding the live object into a namespace.
- flowrep.compiler.annotate.render_annotation(ann: Any, imports: set[str]) str | None[source]
Return verified source text for an annotation, or
None.Mutates
importswith the bare module name for every non-builtin module the text references. ReturnsNone(without leaving partial imports behind) when any part of the annotation cannot be rendered or the rendered text fails to evaluate back to an equal object.
- flowrep.compiler.annotate.render_default(value: Any) str | None[source]
Return source text for a literal default, or
None.The text is accepted only when
ast.literal_evalreproduces a value equal to (and of the same type as) the input. This covers ints, floats, strs, bytes, bools,None, and nested tuple/list/dict/set of these, and rejects sentinels, enums,nan,frozenset(no literal syntax), and arbitrary instances. No imports are required for any accepted value.