Source code for tisserande.models.function_types

"""Pydantic models for function type tables (PythonFunction, MemberFunction, ShellFunction)."""

from typing import ClassVar

from pydantic import BaseModel, ConfigDict, Field


[docs] class PythonFunctionBase(BaseModel): """Model for a python function."""
[docs] name: str = Field(..., description="Name of the function")
[docs] module_: str = Field(..., description="Module where it lives")
[docs] class PythonFunctionCreate(PythonFunctionBase): """Fields used to create a PythonFunction."""
[docs] class PythonFunction(PythonFunctionBase): """PythonFunction response model."""
[docs] model_config = ConfigDict(from_attributes=True)
[docs] col_names_for_table: ClassVar[list[str]] = ["id_", "name", "module_"]
[docs] id_: int = Field(..., gt=0)
[docs] class MemberFunctionBase(BaseModel): """Model for a member function."""
[docs] name: str = Field(..., description="Name of the function")
[docs] class MemberFunctionCreate(MemberFunctionBase): """Fields used to create a MemberFunction."""
[docs] class_name: str | None = Field(default=None, description="Name of the owning class")
[docs] class_id: int | None = Field(default=None, description="ID of the owning class")
[docs] class MemberFunction(MemberFunctionBase): """MemberFunction response model."""
[docs] model_config = ConfigDict(from_attributes=True)
[docs] col_names_for_table: ClassVar[list[str]] = ["id_", "name", "class_id"]
[docs] id_: int = Field(..., gt=0)
[docs] class_id: int = Field(..., description="Foreign key into class table")
[docs] class ShellFunctionBase(BaseModel): """Model for a shell function/script."""
[docs] name: str = Field(..., description="Name of the shell function")
[docs] class ShellFunctionCreate(ShellFunctionBase): """Fields used to create a ShellFunction."""
[docs] class ShellFunction(ShellFunctionBase): """ShellFunction response model."""
[docs] model_config = ConfigDict(from_attributes=True)
[docs] col_names_for_table: ClassVar[list[str]] = ["id_", "name"]
[docs] id_: int = Field(..., gt=0)