espnet3.contract.check.check_declaration
Less than 1 minute
espnet3.contract.check.check_declaration
espnet3.contract.check.check_declaration(obj, inputs_attr: str = 'inputs', outputs_attr: str = 'outputs') → None
Raise TypeError unless obj declares its fields correctly.
Shared by every interface declared with Field: a tuple of fields with distinct names, required ones before optional ones, and no optional output.
- Parameters:
- obj – The class to check, or an instance whose own attributes (set in its
__init__) declare fields its class does not. - inputs_attr – The name of the inputs attribute to check.
- outputs_attr – The name of the outputs attribute to check.
- obj – The class to check, or an instance whose own attributes (set in its
- Returns: None.
- Raises:TypeError – With the rule that was broken.
Examples
>>> from espnet3.contract import Field
>>> class Bad:
... inputs = (Field("prompt", "text", optional=True),
... Field("speech", "audio"))
... outputs = (Field("text", "text"),)
>>> check_declaration(Bad)
Traceback (most recent call last):
TypeError: Bad.inputs must list required fields before optional ones, ...