Skip to content

Commit 1cef4d4

Browse files
committed
fix: remove TYPE_CHECKING and unused type ignores for mypy
- Remove TYPE_CHECKING block that caused mypy type conflicts - Keep only import-not-found ignores for MCP imports - Remove unused type: ignore comments in except block - Tested with --python-version 3.9 to match GitHub Actions
1 parent 4643519 commit 1cef4d4

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

examples/mcp_http_error_handling_demo.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,21 @@
1313

1414
import asyncio
1515
import json
16-
from typing import TYPE_CHECKING, Any
16+
from typing import Any
1717

1818
from agents import Agent, Runner, function_tool
1919

2020
# Import MCP types for proper error handling
21-
if TYPE_CHECKING:
22-
from mcp.shared.exceptions import McpError # type: ignore[import-not-found]
23-
from mcp.types import ErrorData # type: ignore[import-not-found]
24-
25-
MCP_AVAILABLE: bool
26-
INTERNAL_ERROR: int
27-
21+
# We avoid TYPE_CHECKING to prevent mypy from seeing conflicting type assignments
2822
try:
29-
from mcp.shared.exceptions import McpError
30-
from mcp.types import INTERNAL_ERROR, ErrorData # type: ignore[no-redef]
23+
from mcp.shared.exceptions import McpError # type: ignore[import-not-found]
24+
from mcp.types import INTERNAL_ERROR, ErrorData # type: ignore[import-not-found]
3125

3226
MCP_AVAILABLE = True
3327
except ImportError:
3428
# Fallback for Python < 3.10 or when MCP is not installed
3529
MCP_AVAILABLE = False
30+
# Use Any to avoid mypy type conflicts
3631
McpError = Exception
3732
ErrorData = type("ErrorData", (), {})
3833
INTERNAL_ERROR = -32603

0 commit comments

Comments
 (0)