flowrep.parsers.label_helpers module

class flowrep.parsers.label_helpers.OutputMeta(*, label: str | None = None)[source]

Bases: BaseModel

Metadata for output port annotations.

Can be used directly in Annotated hints or as a dict (which will be coerced). Extra keys are ignored, allowing interoperability with other packages. Downstream packages can explicitly extra=”forbid” to lock things down again.

Examples

# Using the model directly def f(x) -> Annotated[float, OutputMeta(label=”result”)]:

# Using a plain dict (coerced automatically) def f(x) -> Annotated[float, {“label”: “result”}]:

# Extra keys are ignored (useful for other packages) def f(x) -> Annotated[float, {“label”: “result”, “units”: “m”, “iri”: “…”}]:

classmethod from_annotation(meta: Any) Self | None[source]

Attempt to coerce annotation metadata into OutputMeta.

Returns None if the metadata cannot be interpreted as OutputMeta.

label: str | None
model_config: ClassVar[ConfigDict] = {'extra': 'ignore'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

flowrep.parsers.label_helpers.default_output_label(i: int) str[source]
flowrep.parsers.label_helpers.extract_label_from_annotated(hint: Any) str | None[source]

Extract label from an Annotated type hint.

Accepts either OutputMeta instances or dicts with a “label” key. Returns None if no label metadata found.

flowrep.parsers.label_helpers.get_annotated_output_labels(func: LambdaType) list[str | None] | None[source]

Extract output labels from return type annotation using Annotated.

For TUPLE unpacking - looks at tuple element annotations. Unwraps outer Annotated wrapper if present to get to tuple elements.

Supports:
  • Single: -> Annotated[T, {“label”: “name”}]

  • Tuple: -> tuple[Annotated[T1, {“label”: “a”}], Annotated[T2, {“label”: “b”}]]

  • Wrapped: -> Annotated[tuple[Annotated[…], …], {“label”: “ignored”}]

Returns None if no annotation or no label metadata found. Returns list with None elements for positions without labels.

flowrep.parsers.label_helpers.index_label(prefix: str, index: int) str[source]
flowrep.parsers.label_helpers.merge_labels(first_choice: Collection[str | None] | None, fallback: Collection[str], message_prefix: str = '') list[str][source]
flowrep.parsers.label_helpers.unique_suffix(name: str, references: Iterable[str]) str[source]