Fix types

This commit is contained in:
Dickson Tsai 2025-07-19 18:47:07 -07:00
parent a813a4d665
commit 9520852839
No known key found for this signature in database
3 changed files with 12 additions and 9 deletions

View file

@ -42,7 +42,7 @@ class SubprocessCLITransport(Transport):
self._stdout_stream: TextReceiveStream | None = None
self._stderr_stream: TextReceiveStream | None = None
self._stdin_stream: TextSendStream | None = None
self._pending_control_responses: dict[str, Any] = {}
self._pending_control_responses: dict[str, dict[str, Any]] = {}
self._request_counter = 0
self._close_stdin_after_prompt = close_stdin_after_prompt

View file

@ -2,6 +2,7 @@
import os
from collections.abc import AsyncIterable, AsyncIterator
from typing import Any
from ._errors import CLIConnectionError
from .types import ClaudeCodeOptions, Message, ResultMessage
@ -94,19 +95,20 @@ class ClaudeSDKClient:
if options is None:
options = ClaudeCodeOptions()
self.options = options
self._transport = None
self._transport: Any | None = None
os.environ["CLAUDE_CODE_ENTRYPOINT"] = "sdk-py-client"
async def connect(self, prompt: str | AsyncIterable[dict] | None = None) -> None:
async def connect(self, prompt: str | AsyncIterable[dict[str, Any]] | None = None) -> None:
"""Connect to Claude with a prompt or message stream."""
from ._internal.transport.subprocess_cli import SubprocessCLITransport
# Auto-connect with empty async iterable if no prompt is provided
async def _empty_stream():
async def _empty_stream() -> AsyncIterator[dict[str, Any]]:
# Never yields, but indicates that this function is an iterator and
# keeps the connection open.
if False:
yield
# This yield is never reached but makes this an async generator
return
yield {} # type: ignore[unreachable]
self._transport = SubprocessCLITransport(
prompt=_empty_stream() if prompt is None else prompt,
@ -190,12 +192,12 @@ class ClaudeSDKClient:
await self._transport.disconnect()
self._transport = None
async def __aenter__(self):
async def __aenter__(self) -> "ClaudeSDKClient":
"""Enter async context - automatically connects with empty stream for interactive use."""
await self.connect()
return self
async def __aexit__(self, exc_type, exc_val, exc_tb):
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool:
"""Exit async context - always disconnects."""
await self.disconnect()
return False

View file

@ -2,13 +2,14 @@
import os
from collections.abc import AsyncIterable, AsyncIterator
from typing import Any
from ._internal.client import InternalClient
from .types import ClaudeCodeOptions, Message
async def query(
*, prompt: str | AsyncIterable[dict], options: ClaudeCodeOptions | None = None
*, prompt: str | AsyncIterable[dict[str, Any]], options: ClaudeCodeOptions | None = None
) -> AsyncIterator[Message]:
"""
Query Claude Code for one-shot or unidirectional streaming interactions.