Fix mypy type-checker errors

- Add explicit bool type annotation to _initialized field
- Fix return value in task_started method to not return _safe_telemetry_operation result
- Simplify initialization logic to set _initialized once in __init__

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-06-03 21:22:17 +00:00
parent 5427f3dae3
commit fec719bdc0

View File

@@ -77,14 +77,14 @@ class Telemetry:
return cls._instance return cls._instance
def __init__(self) -> None: def __init__(self) -> None:
if self._initialized: if hasattr(self, '_initialized') and self._initialized:
return return
self.ready: bool = False self.ready: bool = False
self.trace_set: bool = False self.trace_set: bool = False
self._initialized: bool = True
if self._is_telemetry_disabled(): if self._is_telemetry_disabled():
self._initialized = True
return return
try: try:
@@ -110,8 +110,6 @@ class Telemetry:
): ):
raise # Re-raise the exception to not interfere with system signals raise # Re-raise the exception to not interfere with system signals
self.ready = False self.ready = False
finally:
self._initialized = True
def _is_telemetry_disabled(self) -> bool: def _is_telemetry_disabled(self) -> bool:
"""Check if telemetry should be disabled based on environment variables.""" """Check if telemetry should be disabled based on environment variables."""
@@ -435,7 +433,8 @@ class Telemetry:
return span return span
return self._safe_telemetry_operation(operation) self._safe_telemetry_operation(operation)
return None
def task_ended(self, span: Span, task: Task, crew: Crew): def task_ended(self, span: Span, task: Task, crew: Crew):
"""Records the completion of a task execution in a crew. """Records the completion of a task execution in a crew.
@@ -785,7 +784,8 @@ class Telemetry:
return span return span
if crew.share_crew: if crew.share_crew:
return self._safe_telemetry_operation(operation) self._safe_telemetry_operation(operation)
return operation()
return None return None
def end_crew(self, crew, final_string_output): def end_crew(self, crew, final_string_output):