Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ def is_type_compatible(source_type: type | UnionType | Any, target_type: type |
if target_type is Any:
return True

# Case 0b: source_type is Any - the value can be of any type, so it is compatible with every
# target, the same way static type checkers treat Any.
if source_type is Any:
return True

# Case 1: exact type match
if source_type == target_type:
return True
Expand Down
4 changes: 4 additions & 0 deletions python/packages/core/tests/workflow/test_typing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ def test_type_compatibility_basic() -> None:
# Any compatibility
assert is_type_compatible(str, Any)
assert is_type_compatible(list[int], Any)
assert is_type_compatible(Any, str)
assert is_type_compatible(Any, list[int])
assert is_type_compatible(Any, Union[str, int])
assert is_type_compatible(list[Any], list[str])

# Subclass compatibility
class Animal:
Expand Down
10 changes: 10 additions & 0 deletions python/packages/core/tests/workflow/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ def test_type_compatibility_with_any_type_passes():
assert workflow is not None


def test_type_compatibility_from_any_source_passes():
"""An executor declaring WorkflowContext[Any] can send to a typed executor."""
any_executor = AnyExecutor(id="any_executor")
string_executor = StringExecutor(id="string_executor")

workflow = WorkflowBuilder(start_executor=any_executor).add_edge(any_executor, string_executor).build()

assert workflow is not None


def test_type_compatibility_with_no_output_types():
no_output_executor = NoOutputTypesExecutor(id="no_output")
string_executor = StringExecutor(id="string_executor")
Expand Down
Loading