labthings_fastapi.thing_class_settings

Settings that control how a lt.Thing interacts with LabThings.

This module defines the type used by lt.Thing._class_settings to control how it interacts with LabThings. Most of this module is intended for internal use: the only user-facing item is the type ThingClassSettings

Attributes

SETTINGS_TYPEADAPTER

Classes

ThingClassSettings

Settings that define how a Thing operates.

Functions

validate_thing_class_settings(→ None)

Validate a class settings dict.

get_class_settings(→ ThingClassSettings)

Retrieve a class settings dict or default to an empty dict.

get_validate_properties_on_set(→ bool)

Determine whether properties should perform validation when set from Python.

Module Contents

class labthings_fastapi.thing_class_settings.ThingClassSettings

Bases: TypedDict

Settings that define how a Thing operates.

Initialize self. See help(type(self)) for accurate signature.

validate_properties_on_set: ReadOnly[bool]

Whether property values are validated when set from Python.

This is not yet enabled by default, but will be in future. A DeprecationWarning will be raised if it is not set to True.

labthings_fastapi.thing_class_settings.SETTINGS_TYPEADAPTER
labthings_fastapi.thing_class_settings.validate_thing_class_settings(cls: type[Thing]) None

Validate a class settings dict.

This retrieves the dict from the class, and ensures the attribute is a valid ThingClassSettings typed dict.

Parameters:

cls – The Thing subclass where we are validating.

Raises:

InvalidClassSettingsError – if the dictionary is not valid.

labthings_fastapi.thing_class_settings.get_class_settings(cls: type[Thing]) ThingClassSettings

Retrieve a class settings dict or default to an empty dict.

Parameters:

cls – The class from which to retrieve the dict.

Returns:

The _class_settings dict, or an empty dict.

Raises:

TypeError – if the settings is not a dictionary.

labthings_fastapi.thing_class_settings.get_validate_properties_on_set(cls: type[Thing]) bool

Determine whether properties should perform validation when set from Python.

Note

Check that the default value defined here matches the docstring for ThingClassSettings.

Parameters:

cls – the Thing subclass on which the property is defined.

Returns:

whether validation should be performed.