fix: resolve mypy type errors in RAG path/URL validation

- Cast sockaddr[0] to str() to satisfy mypy (socket.getaddrinfo returns
  sockaddr where [0] is str but typed as str | int)
- Remove now-unnecessary `type: ignore[assignment]` and
  `type: ignore[literal-required]` comments in rag_tool.py

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Alex
2026-04-06 23:24:52 -07:00
parent 2fc603885e
commit 21ec512c11
2 changed files with 6 additions and 6 deletions

View File

@@ -278,7 +278,7 @@ class RagTool(BaseTool):
try:
parsed = urlparse(source_ref)
except (ValueError, AttributeError):
parsed = None # type: ignore[assignment]
parsed = None
if parsed is not None and parsed.scheme in ("http", "https", "file"):
try:
@@ -304,15 +304,15 @@ class RagTool(BaseTool):
# Validate keyword path/URL arguments — these are equally user-controlled
# and must not bypass the checks applied to positional args.
for kwarg_name in ("path", "file_path"):
if kwarg_name in kwargs and kwargs[kwarg_name] is not None: # type: ignore[literal-required]
_check_path(str(kwargs[kwarg_name]), kwarg_name) # type: ignore[literal-required]
if kwarg_name in kwargs and kwargs[kwarg_name] is not None:
_check_path(str(kwargs[kwarg_name]), kwarg_name)
if "directory_path" in kwargs and kwargs.get("directory_path") is not None:
_check_path(str(kwargs["directory_path"]), "directory_path")
for kwarg_name in ("url", "website", "github_url", "youtube_url"):
if kwarg_name in kwargs and kwargs[kwarg_name] is not None: # type: ignore[literal-required]
_check_url(str(kwargs[kwarg_name]), kwarg_name) # type: ignore[literal-required]
if kwarg_name in kwargs and kwargs[kwarg_name] is not None:
_check_url(str(kwargs[kwarg_name]), kwarg_name)
self.adapter.add(*validated_args, **kwargs)

View File

@@ -183,7 +183,7 @@ def validate_url(url: str) -> str:
raise ValueError(f"Could not resolve hostname: '{parsed.hostname}'") from exc
for _family, _, _, _, sockaddr in addrinfos:
ip_str = sockaddr[0]
ip_str = str(sockaddr[0])
if _is_private_or_reserved(ip_str):
raise ValueError(
f"URL '{url}' resolves to private/reserved IP {ip_str}. "