Skip to content

Commit 7091c57

Browse files
authored
Merge pull request #134 from shenald-dev/apex-forge-repo-improvement-7929688882270510647
fix: resolve mypy type check and ruff linting errors in test suite
2 parents 9d71590 + 8c0dcc6 commit 7091c57

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

tests/test_engine.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,12 @@ async def task_b() -> str:
471471
tasks_dict_ref = None
472472

473473
# We need to capture the reference inside the execution scope
474-
original_execute = engine.execute
475474

476475
async def mock_execute() -> dict[str, typing.Any]:
477476
nonlocal tasks_dict_ref
478477
engine._cached_topo_order = ["A", "B"]
479478

480-
class TasksDict(dict):
479+
class TasksDict(dict[str, asyncio.Task[typing.Any]]):
481480
pass
482481
tasks = TasksDict()
483482
tasks_dict_ref = weakref.ref(tasks)
@@ -501,7 +500,7 @@ class TasksDict(dict):
501500

502501
gc.collect()
503502

504-
assert tasks_dict_ref() is None, (
503+
assert tasks_dict_ref is not None and tasks_dict_ref() is None, (
505504
"Memory leak: tasks dictionary was not garbage collected"
506505
)
507506

tests/test_memory_leak.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import typing
12
import asyncio
23
import gc
34
import weakref
45
import pytest
5-
from catalyst.domain.engine import WorkflowEngine, TaskError
6+
from catalyst.domain.engine import WorkflowEngine
67

78

89
@pytest.mark.asyncio
@@ -43,7 +44,7 @@ async def test_reference_cycle_is_broken() -> None:
4344
"""Ensure that the execution dictionary is not held in a reference cycle."""
4445
engine = WorkflowEngine()
4546

46-
async def my_task():
47+
async def my_task() -> str:
4748
return "success"
4849

4950
engine.add_task("task_a", my_task)
@@ -52,22 +53,25 @@ async def my_task():
5253
results = await engine.execute()
5354
assert results["task_a"] == "success"
5455

55-
weak_dep = None
56+
weak_dep: typing.Any = None
5657

5758
orig_run_node = engine._run_node
5859

5960
# We create a dummy class to hold a reference to tasks so we can weakref it
6061
class TaskHolder:
61-
def __init__(self, tasks):
62+
def __init__(self, tasks: tuple[asyncio.Task[typing.Any], ...]) -> None:
6263
self.tasks = tasks
6364

64-
async def wrapped_run_node(node: str, dep_tasks: tuple[asyncio.Task, ...]):
65+
66+
67+
68+
async def wrapped_run_node(node: str, dep_tasks: tuple[asyncio.Task[typing.Any], ...]) -> typing.Any:
6569
nonlocal weak_dep
6670
holder = TaskHolder(dep_tasks)
6771
weak_dep = weakref.ref(holder)
6872
return await orig_run_node(node, dep_tasks)
6973

70-
engine._run_node = wrapped_run_node
74+
engine._run_node = wrapped_run_node # type: ignore
7175

7276
await engine.execute()
7377
gc.collect()

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)