Skip to content

Commit a079a5e

Browse files
Improves typing of SearchAttributes (#76)
1 parent 232446a commit a079a5e

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

temporalio/common.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,14 @@ class QueryRejectCondition(IntEnum):
130130
"""See :py:attr:`temporalio.api.enums.v1.QueryRejectCondition.QUERY_REJECT_CONDITION_NOT_COMPLETED_CLEANLY`."""
131131

132132

133-
SearchAttributeValue: TypeAlias = Union[str, int, float, bool, datetime]
134-
135133
# We choose to make this a list instead of an iterable so we can catch if people
136134
# are not sending lists each time but maybe accidentally sending a string (which
137135
# is iterable)
138-
SearchAttributes: TypeAlias = Mapping[str, List[SearchAttributeValue]]
136+
SearchAttributeValues: TypeAlias = Union[
137+
List[str], List[int], List[float], List[bool], List[datetime]
138+
]
139+
140+
SearchAttributes: TypeAlias = Mapping[str, SearchAttributeValues]
139141

140142

141143
# Should be set as the "arg" argument for _arg_or_args checks where the argument

temporalio/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ def encode_search_attributes(
620620

621621

622622
def encode_search_attribute_values(
623-
vals: List[temporalio.common.SearchAttributeValue],
623+
vals: temporalio.common.SearchAttributeValues,
624624
) -> temporalio.api.common.v1.Payload:
625625
"""Convert search attribute values into a payload.
626626

tests/worker/test_workflow.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,13 +1192,14 @@ def get_search_attributes(self) -> Mapping[str, Mapping[str, Any]]:
11921192

11931193
@workflow.signal
11941194
def do_search_attribute_update(self) -> None:
1195+
empty_float_list: List[float] = []
11951196
workflow.upsert_search_attributes(
11961197
{
11971198
f"{sa_prefix}text": ["text3"],
11981199
# We intentionally leave keyword off to confirm it still comes back
11991200
f"{sa_prefix}int": [123, 456],
12001201
# Empty list to confirm removed
1201-
f"{sa_prefix}double": [],
1202+
f"{sa_prefix}double": empty_float_list,
12021203
f"{sa_prefix}bool": [False],
12031204
f"{sa_prefix}datetime": [
12041205
datetime(2003, 4, 5, 6, 7, 8, tzinfo=timezone(timedelta(hours=9)))

0 commit comments

Comments
 (0)