Skip to content

Commit b85e1f8

Browse files
committed
dream: type bulk sync create_func as Callable
Dream dream-2026-07-23.1 finding 012.
1 parent 4460ef9 commit b85e1f8

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/bloomy/utils/abstract_operations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from collections.abc import Callable
56
from typing import Any
67

78
from ..models import BulkCreateError, BulkCreateResult
@@ -70,7 +71,7 @@ def _validate_bulk_item(
7071
def _process_bulk_sync[T](
7172
self,
7273
items: list[dict[str, Any]],
73-
create_func: Any,
74+
create_func: Callable[[dict[str, Any]], T],
7475
required_fields: list[str],
7576
) -> BulkCreateResult[T]:
7677
"""Process bulk creation synchronously.

tests/test_abstract_operations.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,26 @@ def test_prepare_params(self) -> None:
8585
# Test with all None values
8686
params = ops._prepare_params(a=None, b=None)
8787
assert params == {}
88+
89+
def test_process_bulk_sync_create_func_signature(self) -> None:
90+
"""_process_bulk_sync accepts Callable[[dict[str, Any]], T] create_func."""
91+
client = MockHTTPClient()
92+
ops = ConcreteOperations(client)
93+
94+
def create_func(item_data: dict) -> str:
95+
return f"created-{item_data['title']}"
96+
97+
result = ops._process_bulk_sync(
98+
[
99+
{"title": "a"},
100+
{"title": "b"},
101+
{}, # missing required field
102+
],
103+
create_func,
104+
required_fields=["title"],
105+
)
106+
107+
assert result.successful == ["created-a", "created-b"]
108+
assert len(result.failed) == 1
109+
assert result.failed[0].index == 2
110+
assert "title" in result.failed[0].error

0 commit comments

Comments
 (0)