Skip to content

Pass Python type information through the Thing Description #356

@rwb27

Description

@rwb27

I believe both JSONSchema and Thing Description permit additional fields. This means we could add, for example a labthings_python_type field, which provides optional information about the Python type that generated the schema. This might include:

  • module and qualified name, allowing the exact type to be imported. This would work really nicely for pydantic-compatible types.
  • a type hint as a string (if it uses builtins) - parsing that safely is likely to be quite hard!
  • hints as to whether to reconstruct an object type as something with attributes (dataclass or pydantic.BaseModel) or something with items (dict or TypedDict).
  • special cases like np.array which aren't pydantic compatible but should have a LabThings wrapper/annotation to make them work.

We'd need to add a field for this in the thing_description._model.DataSchema and populate it when generating the schema.

Just to be clear, I am very keen that this does not replace describing the types properly in JSONSchema. That is, and should remain, the primary way of describing types, as it's cross-language and cross-platform. I am proposing adding some minimal extra information, so that the Python types can match the server more closely. We should continue to test that everything works without this feature, if we choose to implement it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions