Skip to content

Commit e2415af

Browse files
committed
Refactor for clarity
1 parent e6bc181 commit e2415af

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

pydantic_ai_slim/pydantic_ai/agent/__init__.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ def output_json_schema(self, output_type: OutputSpec[OutputDataT | RunOutputData
963963
output_type = self.output_type
964964

965965
# forces output_type to an iterable
966-
output_type = list(_flatten_output_spec(output_type))
966+
output_type = _flatten_output_spec(output_type)
967967

968968
flat_output_type: list[OutputSpec[OutputDataT | RunOutputDataT] | type[str]] = []
969969
for output_spec in output_type:
@@ -975,18 +975,15 @@ def output_json_schema(self, output_type: OutputSpec[OutputDataT | RunOutputData
975975
flat_output_type.append(str)
976976
elif isinstance(output_spec, _output.ToolOutput):
977977
flat_output_type += _flatten_output_spec(output_spec.output)
978+
elif inspect.isfunction(output_spec) or inspect.ismethod(output_spec):
979+
return_annotation = inspect.signature(output_spec).return_annotation
980+
flat_output_type += _flatten_output_spec(return_annotation)
978981
else:
979982
flat_output_type.append(output_spec)
980983

981984
json_schemas: list[JsonSchema] = []
982985
for output_spec in flat_output_type:
983-
if inspect.isfunction(output_spec) or inspect.ismethod(output_spec):
984-
json_schema = TypeAdapter(inspect.signature(output_spec).return_annotation).json_schema(
985-
mode='serialization'
986-
)
987-
else:
988-
json_schema = TypeAdapter(output_spec).json_schema(mode='serialization')
989-
986+
json_schema = TypeAdapter(output_spec).json_schema(mode='serialization')
990987
if json_schema not in json_schemas:
991988
json_schemas.append(json_schema)
992989

0 commit comments

Comments
 (0)