core[patch]: make get_all_basemodel_annotations public (#27761)

This commit is contained in:
Bagatur
2024-10-30 14:43:29 -07:00
committed by GitHub
parent 94ea950c6c
commit 5d337326b0
3 changed files with 24 additions and 17 deletions

View File

@@ -449,7 +449,7 @@ class ChildTool(BaseTool):
def tool_call_schema(self) -> type[BaseModel]:
full_schema = self.get_input_schema()
fields = []
for name, type_ in _get_all_basemodel_annotations(full_schema).items():
for name, type_ in get_all_basemodel_annotations(full_schema).items():
if not _is_injected_arg_type(type_):
fields.append(name)
return _create_subset_model(
@@ -962,7 +962,7 @@ def _is_injected_arg_type(type_: type) -> bool:
)
def _get_all_basemodel_annotations(
def get_all_basemodel_annotations(
cls: Union[TypeBaseModel, Any], *, default_to_bound: bool = True
) -> dict[str, type]:
# cls has no subscript: cls = FooBar
@@ -980,7 +980,7 @@ def _get_all_basemodel_annotations(
orig_bases: tuple = getattr(cls, "__orig_bases__", ())
# cls has subscript: cls = FooBar[int]
else:
annotations = _get_all_basemodel_annotations(
annotations = get_all_basemodel_annotations(
get_origin(cls), default_to_bound=False
)
orig_bases = (cls,)
@@ -994,7 +994,7 @@ def _get_all_basemodel_annotations(
# if class = FooBar inherits from Baz, parent = Baz
if isinstance(parent, type) and is_pydantic_v1_subclass(parent):
annotations.update(
_get_all_basemodel_annotations(parent, default_to_bound=False)
get_all_basemodel_annotations(parent, default_to_bound=False)
)
continue