fix: Replace remaining Type imports with built-in type annotations

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-09-04 02:23:58 +00:00
parent 3257d2757f
commit bf2b0c5864
2 changed files with 8 additions and 10 deletions

View File

@@ -7,7 +7,6 @@ from typing import (
Callable,
Generic,
Optional,
Type,
TypeVar,
Union,
cast,
@@ -61,7 +60,7 @@ StateT = TypeVar(
) # State validation type parameter
def ensure_state_type(state: Any, expected_type: Type[StateT]) -> StateT:
def ensure_state_type(state: Any, expected_type: type[StateT]) -> StateT:
"""Ensure state matches expected type with proper validation.
Args:
@@ -441,11 +440,11 @@ class Flow(Generic[T], metaclass=FlowMeta):
_listeners: dict[str, tuple[str, list[str]]] = {}
_routers: set[str] = set()
_router_paths: dict[str, list[str]] = {}
initial_state: Union[Type[T], T, None] = None
initial_state: Union[type[T], T, None] = None
name: Optional[str] = None
tracing: Optional[bool] = False
def __class_getitem__(cls: Type["Flow"], item: Type[T]) -> Type["Flow"]:
def __class_getitem__(cls: type["Flow"], item: type[T]) -> type["Flow"]:
class _FlowGeneric(cls): # type: ignore
_initial_state_T = item # type: ignore

View File

@@ -14,7 +14,6 @@ from typing import (
Callable,
ClassVar,
Optional,
Type,
Union,
get_args,
get_origin,
@@ -105,11 +104,11 @@ class Task(BaseModel):
description="Whether the task should be executed asynchronously or not.",
default=False,
)
output_json: Optional[Type[BaseModel]] = Field(
output_json: Optional[type[BaseModel]] = Field(
description="A Pydantic model to be used to create a JSON output.",
default=None,
)
output_pydantic: Optional[Type[BaseModel]] = Field(
output_pydantic: Optional[type[BaseModel]] = Field(
description="A Pydantic model to be used to create a Pydantic output.",
default=None,
)
@@ -145,7 +144,7 @@ class Task(BaseModel):
description="Whether the task should instruct the agent to return the final answer formatted in Markdown",
default=False,
)
converter_cls: Optional[Type[Converter]] = Field(
converter_cls: Optional[type[Converter]] = Field(
description="A converter class used to export structured output",
default=None,
)
@@ -225,7 +224,7 @@ class Task(BaseModel):
return_annotation_args[1] is Any
or return_annotation_args[1] is str
or return_annotation_args[1] is TaskOutput
or return_annotation_args[1] == Union[str, TaskOutput]
or return_annotation_args[1] == (str | TaskOutput)
)
):
raise ValueError(
@@ -760,7 +759,7 @@ Follow these guidelines:
return OutputFormat.PYDANTIC
return OutputFormat.RAW
def _save_file(self, result: Union[Dict, str, Any]) -> None:
def _save_file(self, result: Union[dict, str, Any]) -> None:
"""Save task output to a file.
Note: