mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-04-28 13:52:47 +00:00
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:
@@ -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)
|
||||
|
||||
|
||||
@@ -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}. "
|
||||
|
||||
Reference in New Issue
Block a user