From 21ec512c11166bd6448990492b11ae94f4b5a154 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 6 Apr 2026 23:24:52 -0700 Subject: [PATCH] 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 --- .../src/crewai_tools/tools/rag/rag_tool.py | 10 +++++----- .../src/crewai_tools/utilities/safe_path.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/crewai-tools/src/crewai_tools/tools/rag/rag_tool.py b/lib/crewai-tools/src/crewai_tools/tools/rag/rag_tool.py index 5942407d9..61bc34776 100644 --- a/lib/crewai-tools/src/crewai_tools/tools/rag/rag_tool.py +++ b/lib/crewai-tools/src/crewai_tools/tools/rag/rag_tool.py @@ -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) diff --git a/lib/crewai-tools/src/crewai_tools/utilities/safe_path.py b/lib/crewai-tools/src/crewai_tools/utilities/safe_path.py index e3c2ff54b..6d059c086 100644 --- a/lib/crewai-tools/src/crewai_tools/utilities/safe_path.py +++ b/lib/crewai-tools/src/crewai_tools/utilities/safe_path.py @@ -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}. "