Skip to content

Commit 1dba08d

Browse files
brettcannonpatniko
andauthored
feat(python): add overloads for CopilotClient.on() (#589)
* feat(python): add overloads for `CopilotClient.on()` * Carry forward types in overloads * Rename UnsubscribeHandler to HandlerUnsubcribe in type annotations * Fix type checking * Fix a merge mistake * Try to fix merge error * Fix type casting for model list retrieval in CopilotClient * Remove type warning change --------- Co-authored-by: Patrick Nikoletich <patniko@github.com>
1 parent c9160ba commit 1dba08d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

python/copilot/client.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import uuid
2424
from collections.abc import Awaitable, Callable
2525
from pathlib import Path
26-
from typing import Any, cast
26+
from typing import Any, cast, overload
2727

2828
from .generated.rpc import ServerRpc
2929
from .generated.session_events import PermissionRequest, session_event_from_dict
@@ -53,6 +53,8 @@
5353
ToolResult,
5454
)
5555

56+
HandlerUnsubcribe = Callable[[], None]
57+
5658
NO_RESULT_PERMISSION_V2_ERROR = (
5759
"Permission handlers cannot return 'no-result' when connected to a protocol v2 server."
5860
)
@@ -1097,11 +1099,20 @@ async def set_foreground_session_id(self, session_id: str) -> None:
10971099
error = response.get("error", "Unknown error")
10981100
raise RuntimeError(f"Failed to set foreground session: {error}")
10991101

1102+
@overload
1103+
def on(self, handler: SessionLifecycleHandler, /) -> HandlerUnsubcribe: ...
1104+
1105+
@overload
1106+
def on(
1107+
self, event_type: SessionLifecycleEventType, /, handler: SessionLifecycleHandler
1108+
) -> HandlerUnsubcribe: ...
1109+
11001110
def on(
11011111
self,
11021112
event_type_or_handler: SessionLifecycleEventType | SessionLifecycleHandler,
1113+
/,
11031114
handler: SessionLifecycleHandler | None = None,
1104-
) -> Callable[[], None]:
1115+
) -> HandlerUnsubcribe:
11051116
"""
11061117
Subscribe to session lifecycle events.
11071118

0 commit comments

Comments
 (0)