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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- `tilebox-workflows`: Allow task `execute()` methods to use a `-> None` return annotation when postponed annotation
evaluation is enabled.

## [0.55.0] - 2026-07-01

### Added
Expand Down
31 changes: 31 additions & 0 deletions tilebox-workflows/tests/test_task.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import __future__

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aah maybe that's why I never noticed it, does the issue only occur when the __future__.annotations codemod is active?


import json
from dataclasses import dataclass
from typing import Annotated
Expand Down Expand Up @@ -46,6 +48,35 @@ def execute(self, context: ExecutionContext) -> None:
assert TaskMeta.for_task(SimpleTask).executable is True


def _compile_task_with_postponed_return_annotation(return_annotation: str) -> type:
source = f"""
class PostponedAnnotationsTask(Task):
def execute(self, context: ExecutionContext) -> {return_annotation}:
pass
"""
namespace: dict[str, type] = {"Task": Task, "ExecutionContext": ExecutionContext}
code = compile(
source,
filename="<postponed-annotations-test>",
mode="exec",
flags=__future__.annotations.compiler_flag,
dont_inherit=True,
)
exec(code, namespace) # noqa: S102
return namespace["PostponedAnnotationsTask"]


def test_task_validation_execute_none_return_type_with_postponed_annotations() -> None:
task_class = _compile_task_with_postponed_return_annotation("None")

assert TaskMeta.for_task(task_class).executable is True


def test_task_validation_execute_invalid_return_type_with_postponed_annotations() -> None:
with pytest.raises(TypeError, match="to not have a return value"):
_compile_task_with_postponed_return_annotation("int")


def test_task_validation_execute_invalid_signature_no_params() -> None:
with pytest.raises(TypeError, match="Expected a function signature of"):
# validation happens at class creation time, that's why we create it in a function
Expand Down
3 changes: 2 additions & 1 deletion tilebox-workflows/tilebox/workflows/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def _validate_execute_method(
f"but got {class_name}.execute{signature}!"
)

if signature.return_annotation is not None and signature.return_annotation != inspect._empty: # noqa: SLF001
# `from __future__ import annotations` stores `-> None` as the string "None".
if signature.return_annotation not in (None, "None", inspect.Signature.empty):
raise TypeError(f"Expected {class_name}.execute{signature} to not have a return value!")

return True
Expand Down
Loading