Skip to content

Commit d582f59

Browse files
fix(python): add type casts to fix ty check errors
Add cast() calls for handler results that go through inspect.isawaitable(), which loses type narrowing: - session.py: _handle_permission_request, _handle_user_input_request - client.py: _execute_tool_call Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 157987d commit d582f59

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

python/copilot/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ async def _execute_tool_call(
15891589
toolTelemetry={},
15901590
)
15911591

1592-
return self._normalize_tool_result(result)
1592+
return self._normalize_tool_result(cast(ToolResult, result))
15931593

15941594
def _normalize_tool_result(self, result: ToolResult) -> ToolResult:
15951595
"""

python/copilot/session.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import asyncio
99
import inspect
1010
import threading
11-
from typing import Any, Callable, Optional
11+
from typing import Any, Callable, Optional, cast
1212

1313
from .generated.rpc import SessionRpc
1414
from .generated.session_events import SessionEvent, SessionEventType, session_event_from_dict
@@ -336,7 +336,7 @@ async def _handle_permission_request(
336336
result = handler(request, {"session_id": self.session_id})
337337
if inspect.isawaitable(result):
338338
result = await result
339-
return result
339+
return cast(PermissionRequestResult, result)
340340
except Exception: # pylint: disable=broad-except
341341
# Handler failed, deny permission
342342
return {"kind": "denied-no-approval-rule-and-could-not-request-from-user"}
@@ -388,7 +388,7 @@ async def _handle_user_input_request(self, request: dict) -> UserInputResponse:
388388
)
389389
if inspect.isawaitable(result):
390390
result = await result
391-
return result
391+
return cast(UserInputResponse, result)
392392
except Exception:
393393
raise
394394

0 commit comments

Comments
 (0)