mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-07-01 21:28:10 +00:00
fix(tools): tighten _is_base_file return type to TypeGuard[FileInput]
Mypy could not infer that BaseFile values are valid FileInput entries. Using TypeGuard[FileInput] makes the type narrowing explicit.
This commit is contained in:
@@ -13,15 +13,19 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping, Sequence
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import TYPE_CHECKING, Any, TypeGuard
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from crewai_files import BaseFile, FileInput
|
||||
|
||||
|
||||
def _is_base_file(value: Any) -> bool:
|
||||
"""Return True if ``value`` is a ``crewai_files.BaseFile`` subclass instance."""
|
||||
def _is_base_file(value: Any) -> TypeGuard[FileInput]:
|
||||
"""Return True if ``value`` is a ``crewai_files.BaseFile`` subclass instance.
|
||||
|
||||
``FileInput`` is the union of all concrete ``BaseFile`` subclasses, so any
|
||||
``BaseFile`` instance is by definition a ``FileInput``.
|
||||
"""
|
||||
try:
|
||||
from crewai_files import BaseFile
|
||||
except ImportError:
|
||||
|
||||
Reference in New Issue
Block a user