chore: make ruff format and ty clean

Format two mcp modules with the current ruff, and narrow the text-block
check in conversation_store through a typed helper so ty stops flagging
dict.get on an unnarrowed block.
This commit is contained in:
hh
2026-08-27 23:22:23 +02:00
parent d33039f497
commit a2a80ab150
3 changed files with 22 additions and 32 deletions
+13 -24
View File
@@ -84,23 +84,19 @@ class LenientStdioTransport(ClientTransport):
self, **session_kwargs: Unpack[SessionKwargs]
) -> AsyncIterator[ClientSession]:
errlog: TextIO = self.log_file if self.log_file is not None else sys.stderr
async with _lenient_stdio_client(
StdioServerParameters(
command=self.command,
args=self.args,
env=self.env,
cwd=self.cwd,
),
errlog=errlog,
) as (read_stream, write_stream), ClientSession(
read_stream, write_stream, **session_kwargs
) as session:
async with (
_lenient_stdio_client(
StdioServerParameters(
command=self.command, args=self.args, env=self.env, cwd=self.cwd
),
errlog=errlog,
) as (read_stream, write_stream),
ClientSession(read_stream, write_stream, **session_kwargs) as session,
):
yield session
def __repr__(self) -> str:
return (
f"<LenientStdioTransport(command={self.command!r}, args={self.args!r})>"
)
return f"<LenientStdioTransport(command={self.command!r}, args={self.args!r})>"
@contextlib.asynccontextmanager
@@ -133,9 +129,7 @@ async def _lenient_stdio_client( # noqa: PLR0915 — mirrors mcp.client.stdio.s
command=command,
args=server.args,
env=(
{**env_default, **server.env}
if server.env is not None
else env_default
{**env_default, **server.env} if server.env is not None else env_default
),
errlog=errlog,
cwd=server.cwd,
@@ -164,9 +158,7 @@ async def _lenient_stdio_client( # noqa: PLR0915 — mirrors mcp.client.stdio.s
if not stripped:
continue
try:
message = types.JSONRPCMessage.model_validate_json(
stripped
)
message = types.JSONRPCMessage.model_validate_json(stripped)
except Exception: # noqa: BLE001 — by design, see module doc
_log.debug(
"lenient stdio: dropped non-JSON line: %r",
@@ -194,10 +186,7 @@ async def _lenient_stdio_client( # noqa: PLR0915 — mirrors mcp.client.stdio.s
except anyio.ClosedResourceError:
await anyio.lowlevel.checkpoint()
async with (
anyio.create_task_group() as tg,
process,
):
async with anyio.create_task_group() as tg, process:
tg.start_soon(stdout_reader)
tg.start_soon(stdin_writer)
try:
+1 -3
View File
@@ -62,9 +62,7 @@ class PythonToolMcp(_BaseMcp):
tools: tuple[Callable[..., object], ...]
McpServerT = Annotated[
StdioMcp | HttpMcp | PythonToolMcp, Field(discriminator="kind")
]
McpServerT = Annotated[StdioMcp | HttpMcp | PythonToolMcp, Field(discriminator="kind")]
class McpServer: