def get_field_type()

in labgraph/messages/types.py [0:0]


def get_field_type(python_type: Type[T]) -> FieldType[T]:
    """
    Returns a `FieldType` that contains all the information Labgraph needs for a field.

    Args:
        `python_type`: A Python type to get a `FieldType` for.
    """

    if isinstance(python_type, FieldType):
        return python_type
    if python_type.__module__ == "typing":
        # TODO: Switch to `typing.get_origin` for py38
        origin = getattr(python_type, "__origin__", None)
        if origin in (list, List):
            # TODO: Switch to `typing.get_args` for py38
            return ListType(python_type.__args__[0])  # type: ignore
        elif origin in (dict, Dict):
            # TODO: Switch to `typing.get_args` for py38
            return DictType(python_type.__args__)  # type: ignore
        return ObjectDynamicType()
    elif not isinstance(python_type, type):
        return ObjectDynamicType()
    elif dataclasses.is_dataclass(python_type):
        return DataclassType(python_type)
    elif issubclass(python_type, Enum):
        if issubclass(python_type, str):
            return StrEnumType(python_type)  # type: ignore
        elif issubclass(python_type, int):
            return IntEnumType(python_type)  # type: ignore
        else:
            raise TypeError(
                "Message field enums must be a subtype of either int or str."
            )
    elif python_type in PRIMITIVE_TYPES:
        return PRIMITIVE_TYPES[python_type]()  # type: ignore
    elif python_type == np.ndarray:
        return NumpyDynamicType()

    return ObjectDynamicType()