Skip to content

Commit 60fd2c8

Browse files
committed
fix: use hasattr guard instead of getattr for response.output
Fixes microsoft#6235 Using hasattr(response, 'output') and then accessing response.output directly gives pyright enough type information to verify the match statement exhaustiveness. This avoids the cast(list[Any]) approach which pyright still flagged as partially unknown.
1 parent 230c8a3 commit 60fd2c8

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎python/packages/openai/agent_framework_openai/_chat_client.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,10 @@ def _parse_response_from_openai(
19711971
metadata: dict[str, Any] = response.metadata or {}
19721972
contents: list[Content] = []
19731973
local_shell_tool_name = self._get_local_shell_tool_name(options.get("tools"))
1974-
response_outputs = cast(list[Any], getattr(response, "output", None) or [])
1974+
if hasattr(response, "output") and response.output:
1975+
response_outputs = response.output # type: ignore[reportUnknownMemberType]
1976+
else:
1977+
response_outputs = []
19751978
for item in response_outputs:
19761979
match item.type:
19771980
# types:

0 commit comments

Comments
 (0)