Skip to content

Commit 24b84a4

Browse files
chore: apply ruff linting fixes to crews module
1 parent 8e571ea commit 24b84a4

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/crewai/crews/crew_output.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Any, Dict, Optional
2+
from typing import Any
33

44
from pydantic import BaseModel, Field
55

@@ -12,27 +12,29 @@ class CrewOutput(BaseModel):
1212
"""Class that represents the result of a crew."""
1313

1414
raw: str = Field(description="Raw output of crew", default="")
15-
pydantic: Optional[BaseModel] = Field(
15+
pydantic: BaseModel | None = Field(
1616
description="Pydantic output of Crew", default=None
1717
)
18-
json_dict: Optional[Dict[str, Any]] = Field(
18+
json_dict: dict[str, Any] | None = Field(
1919
description="JSON dict output of Crew", default=None
2020
)
2121
tasks_output: list[TaskOutput] = Field(
2222
description="Output of each task", default=[]
2323
)
24-
token_usage: UsageMetrics = Field(description="Processed token summary", default={})
24+
token_usage: UsageMetrics = Field(
25+
description="Processed token summary", default_factory=UsageMetrics
26+
)
2527

2628
@property
27-
def json(self) -> Optional[str]:
29+
def json(self) -> str | None: # type: ignore[override]
2830
if self.tasks_output[-1].output_format != OutputFormat.JSON:
2931
raise ValueError(
3032
"No JSON output found in the final task. Please make sure to set the output_json property in the final task in your crew."
3133
)
3234

3335
return json.dumps(self.json_dict)
3436

35-
def to_dict(self) -> Dict[str, Any]:
37+
def to_dict(self) -> dict[str, Any]:
3638
"""Convert json_output and pydantic_output to a dictionary."""
3739
output_dict = {}
3840
if self.json_dict:
@@ -44,10 +46,9 @@ def to_dict(self) -> Dict[str, Any]:
4446
def __getitem__(self, key):
4547
if self.pydantic and hasattr(self.pydantic, key):
4648
return getattr(self.pydantic, key)
47-
elif self.json_dict and key in self.json_dict:
49+
if self.json_dict and key in self.json_dict:
4850
return self.json_dict[key]
49-
else:
50-
raise KeyError(f"Key '{key}' not found in CrewOutput.")
51+
raise KeyError(f"Key '{key}' not found in CrewOutput.")
5152

5253
def __str__(self):
5354
if self.pydantic:

0 commit comments

Comments
 (0)