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

View File

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