fix: add missing type annotations to fix mypy strict mode errors

Added type annotations to 10 files to resolve mypy type checking errors:
- Added return type annotations to methods missing them
- Added parameter type annotations where missing
- Fixed Optional type hints to be explicit
- Removed redundant type cast in crew.py
- Changed _execute_with_timeout return type from str to Any in agent.py

Additional type errors remain in other files throughout the codebase.
This commit is contained in:
Greyson LaLonde
2025-09-04 11:41:57 -04:00
parent 2ba48dd82a
commit 8354cdf061
10 changed files with 121 additions and 79 deletions

View File

@@ -1,3 +1,5 @@
from typing import Any
from pydantic import BaseModel, Field
from crewai.events.event_bus import crewai_event_bus
@@ -39,11 +41,11 @@ class TrainingTaskEvaluation(BaseModel):
class TaskEvaluator:
def __init__(self, original_agent) -> None:
def __init__(self, original_agent: Any) -> None:
self.llm = original_agent.llm
self.original_agent = original_agent
def evaluate(self, task, output) -> TaskEvaluation:
def evaluate(self, task: Any, output: Any) -> TaskEvaluation:
crewai_event_bus.emit(
self, TaskEvaluationEvent(evaluation_type="task_evaluation", task=task)
)
@@ -74,7 +76,7 @@ class TaskEvaluator:
return converter.to_pydantic()
def evaluate_training_data(
self, training_data: dict, agent_id: str
self, training_data: dict[str, Any], agent_id: str
) -> TrainingTaskEvaluation:
"""
Evaluate the training data based on the llm output, human feedback, and improved output.

View File

@@ -20,18 +20,18 @@ class RPMController(BaseModel):
_shutdown_flag: bool = PrivateAttr(default=False)
@model_validator(mode="after")
def reset_counter(self):
def reset_counter(self) -> "RPMController":
if self.max_rpm is not None:
if not self._shutdown_flag:
self._lock = threading.Lock()
self._reset_request_count()
return self
def check_or_wait(self):
def check_or_wait(self) -> bool:
if self.max_rpm is None:
return True
def _check_and_increment():
def _check_and_increment() -> bool:
if self.max_rpm is not None and self._current_rpm < self.max_rpm:
self._current_rpm += 1
return True
@@ -55,12 +55,12 @@ class RPMController(BaseModel):
self._timer.cancel()
self._timer = None
def _wait_for_next_minute(self):
def _wait_for_next_minute(self) -> None:
time.sleep(60)
self._current_rpm = 0
def _reset_request_count(self):
def _reset():
def _reset_request_count(self) -> None:
def _reset() -> None:
self._current_rpm = 0
if not self._shutdown_flag:
self._timer = threading.Timer(60.0, self._reset_request_count)