chore: clean some isinstance (#37602)

Co-authored-by: WH-2099 <wh2099@pm.me>
This commit is contained in:
Asuka Minato 2026-06-22 12:51:21 +09:00 committed by GitHub
parent 265dc54c51
commit d5cdb2e6f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 36 deletions

View File

@ -74,11 +74,12 @@ def accept_subjects(*accepted: SubjectType) -> Callable[[F], F]:
def _coerce_subject_type(raw: object) -> SubjectType | None:
if raw is None:
match raw:
case None:
return None
if isinstance(raw, SubjectType):
case SubjectType():
return raw
if isinstance(raw, str):
case str():
return SubjectType(raw)
return None

View File

@ -14,6 +14,7 @@ from concurrent.futures import ThreadPoolExecutor
from contextlib import contextmanager
from dataclasses import dataclass
from datetime import timedelta
from http import HTTPStatus
from typing import Any, cast
import httpx
@ -293,15 +294,14 @@ class StreamableHTTPTransport:
json=message.model_dump(by_alias=True, mode="json", exclude_none=True),
headers=headers,
) as response:
if response.status_code == 202:
match response.status_code:
case HTTPStatus.ACCEPTED:
logger.debug("Received 202 Accepted")
return
if response.status_code == 204:
case HTTPStatus.NO_CONTENT:
logger.debug("Received 204 No Content")
return
if response.status_code == 404:
case HTTPStatus.NOT_FOUND:
if isinstance(message.root, JSONRPCRequest):
error_msg = (
f"MCP server URL returned 404 Not Found: {self.url} "

View File

@ -359,14 +359,15 @@ class ApiTool(Tool):
if value is None:
return None
elif property["type"] == "object" or property["type"] == "array":
if isinstance(value, str):
match value:
case str():
try:
return json.loads(value)
except ValueError:
return value
elif isinstance(value, dict):
case dict():
return value
else:
case _:
return value
else:
raise ValueError(f"Invalid type {property['type']} for property {property}")