From 21b4108acadaf72e55adfbd9ad849dc98b5bed04 Mon Sep 17 00:00:00 2001 From: comfuture Date: Sun, 1 Dec 2024 14:27:19 +0000 Subject: [PATCH] refactor: Update Doc type handling to use DocMeta protocol --- function_schema/core.py | 4 ++-- function_schema/types.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/function_schema/core.py b/function_schema/core.py index 3f538a5..fdd0775 100644 --- a/function_schema/core.py +++ b/function_schema/core.py @@ -12,7 +12,7 @@ get_type_hints, ) -from .types import FunctionSchema, Doc +from .types import FunctionSchema, Doc, DocMeta from .utils import unwrap_doc @@ -102,7 +102,7 @@ def get_function_schema( # find description in param_args tuple try: description = next( - unwrap_doc(arg) for arg in param_args if isinstance(arg, Doc) + unwrap_doc(arg) for arg in param_args if isinstance(arg, DocMeta) ) except StopIteration: try: diff --git a/function_schema/types.py b/function_schema/types.py index ddab827..f0dac80 100644 --- a/function_schema/types.py +++ b/function_schema/types.py @@ -15,14 +15,20 @@ from typing_extensions import Doc except ImportError: - @runtime_checkable - class Doc(Protocol): + class Doc: documentation: str def __init__(self, documentation: str, /): self.documentation = documentation +@runtime_checkable +class DocMeta(Protocol): + """Represents the protocol for the Doc class.""" + + documentation: str + + class ParamSchema(TypedDict): """ Represents the schema for a parameter.