Skip to content

Type checking for custom SiLA types

When creating various sila related resources one inherits from the appropriate sila.myclass .

  • sila.CustomDataType for data types
  • sila.DefinedExecutionError for errors
  • etc.

As of version 0.1.5 forgetting to add the inheritance does not cause any errors (at least for CustomDataType) on server creation / startup. Instead silently does not generate the sila.xml one would expect, and sometimes even a non-valid one.

# Example:
@dataclasses.dataclass
class PositionIndex: # Not inheriting from sila.CustomDataType will cause the server to treat PositionIndex as a string type. :/
    """
    Specifies a position via an index number, starting at 1.

    .. parameter:: Position index number.
    """

    PositionIndex: typing.Annotated[int, sila.constraints.MinimalInclusive(value=1)]

Consider adding a type check isinstance(o, (sila.XXX, str, etc..)), whenever adding a type resource to a server?