Skip to content

Commit 46926cd

Browse files
committed
test(func_metadata): cast convert_result to tuple for pyright union narrowing
Signed-off-by: SAY-5 <say.apm35@gmail.com>
1 parent c37062a commit 46926cd

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

tests/server/mcpserver/test_func_metadata.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,11 +1036,18 @@ def func_with_aliases() -> ModelWithAliases: # pragma: no cover
10361036
assert "field_first" not in meta.output_schema["properties"]
10371037
assert "field_second" not in meta.output_schema["properties"]
10381038

1039-
# Check that the actual output uses aliases too
1039+
# Check that the actual output uses aliases too. ``convert_result``
1040+
# returns either a sequence, a CallToolResult, or a 2-tuple of
1041+
# (unstructured, structured) — for a model with an output schema the
1042+
# 2-tuple branch fires, so cast accordingly to keep pyright happy
1043+
# without runtime narrowing surprises.
1044+
from typing import cast
1045+
10401046
result = ModelWithAliases(**{"first": "hello", "second": "world"})
1041-
converted = meta.convert_result(result)
1042-
assert isinstance(converted, tuple)
1043-
_, structured_content = converted
1047+
structured_content = cast(
1048+
"tuple[Any, dict[str, Any]]",
1049+
meta.convert_result(result),
1050+
)[1]
10441051

10451052
# The structured content should use aliases to match the schema
10461053
assert "first" in structured_content
@@ -1052,9 +1059,10 @@ def func_with_aliases() -> ModelWithAliases: # pragma: no cover
10521059

10531060
# Also test the case where we have a model with defaults to ensure aliases work in all cases
10541061
result_with_defaults = ModelWithAliases() # Uses default None values
1055-
converted_defaults = meta.convert_result(result_with_defaults)
1056-
assert isinstance(converted_defaults, tuple)
1057-
_, structured_content_defaults = converted_defaults
1062+
structured_content_defaults = cast(
1063+
"tuple[Any, dict[str, Any]]",
1064+
meta.convert_result(result_with_defaults),
1065+
)[1]
10581066

10591067
# Even with defaults, should use aliases in output
10601068
assert "first" in structured_content_defaults

0 commit comments

Comments
 (0)