qhana_plugin_runner.api.extra_fields module

Module containing extra marshmallow field classes to be used in plugin micro frontends.

class qhana_plugin_runner.api.extra_fields.CSVList(element_type: Field, **kwargs)

Bases: Field

Validator for validating comma separated lists.

Parameters:

element_type (Type[Field]) – the field type of list elements

Raises:

ValueError – if fields are of an invalid type

class qhana_plugin_runner.api.extra_fields.EnumField(enum_type: Type[Enum], use_value: bool = False, **kwargs)

Bases: Field

default_error_messages = {'invalid': 'Not a valid choice.'}

Default error messages.

class qhana_plugin_runner.api.extra_fields.OneOfEnum(enum: Type[Enum], choices: Iterable[str], labels: Iterable[str] | None, *, error: str | None, use_value: bool = False)

Bases: OneOf

Validator for validating enum based choices.

Succeeds if a value is a member of the enumeration.

If choices contains the empty string "" then None will also validate.

Parameters:
  • enum (Type[Enum]) – the enum type the choices are based on

  • choices (Iterable[str]) – the names of the enum items that are valid choices (can be a subset of the whole enum; can include "")

  • labels (Optional[Iterable[str]]) – the labels for the individual choices

  • error (Optional[str]) – Error message to raise in case of a validation error. Can be interpolated with {input}, {choices} and {labels}.

  • use_value (Optional[bool]) – If true, the enum value is used for choices instead of the enum name. Use labels to provide meaningful labels in this case.

Raises:

ValueError – if the choices cannot be mapped to the given enum