mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
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:
@@ -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):
|
||||||
|
|||||||
Reference in New Issue
Block a user