|
20 | 20 | ) |
21 | 21 |
|
22 | 22 | import google.protobuf.internal.containers |
23 | | -from google.protobuf.message import Message |
24 | 23 | from typing_extensions import TypeAlias |
25 | 24 |
|
26 | 25 | import temporalio.api.common.v1 |
@@ -278,94 +277,6 @@ async def finalize_shutdown(self) -> None: |
278 | 277 | await ref.finalize_shutdown() |
279 | 278 |
|
280 | 279 |
|
281 | | -# See https://mypy.readthedocs.io/en/stable/runtime_troubles.html#using-classes-that-are-generic-in-stubs-but-not-at-runtime |
282 | | -if TYPE_CHECKING: |
283 | | - PayloadContainer: TypeAlias = ( |
284 | | - google.protobuf.internal.containers.RepeatedCompositeFieldContainer[ |
285 | | - temporalio.api.common.v1.Payload |
286 | | - ] |
287 | | - ) |
288 | | -else: |
289 | | - PayloadContainer: TypeAlias = ( |
290 | | - google.protobuf.internal.containers.RepeatedCompositeFieldContainer |
291 | | - ) |
292 | | - |
293 | | - |
294 | | -async def _apply_to_headers( |
295 | | - headers: Mapping[str, temporalio.api.common.v1.Payload], |
296 | | - cb: Callable[ |
297 | | - [Sequence[temporalio.api.common.v1.Payload]], |
298 | | - Awaitable[List[temporalio.api.common.v1.Payload]], |
299 | | - ], |
300 | | -) -> None: |
301 | | - """Apply API payload callback to headers.""" |
302 | | - for payload in headers.values(): |
303 | | - new_payload = (await cb([payload]))[0] |
304 | | - payload.CopyFrom(new_payload) |
305 | | - |
306 | | - |
307 | | -async def _decode_headers( |
308 | | - headers: Mapping[str, temporalio.api.common.v1.Payload], |
309 | | - codec: temporalio.converter.PayloadCodec, |
310 | | -) -> None: |
311 | | - """Decode headers with the given codec.""" |
312 | | - return await _apply_to_headers(headers, codec.decode) |
313 | | - |
314 | | - |
315 | | -async def _encode_headers( |
316 | | - headers: Mapping[str, temporalio.api.common.v1.Payload], |
317 | | - codec: temporalio.converter.PayloadCodec, |
318 | | -) -> None: |
319 | | - """Encode headers with the given codec.""" |
320 | | - return await _apply_to_headers(headers, codec.encode) |
321 | | - |
322 | | - |
323 | | -async def _apply_to_payloads( |
324 | | - payloads: PayloadContainer, |
325 | | - cb: Callable[ |
326 | | - [Sequence[temporalio.api.common.v1.Payload]], |
327 | | - Awaitable[List[temporalio.api.common.v1.Payload]], |
328 | | - ], |
329 | | -) -> None: |
330 | | - """Apply API payload callback to payloads.""" |
331 | | - if len(payloads) == 0: |
332 | | - return |
333 | | - new_payloads = await cb(payloads) |
334 | | - if new_payloads is payloads: |
335 | | - return |
336 | | - del payloads[:] |
337 | | - # TODO(cretz): Copy too expensive? |
338 | | - payloads.extend(new_payloads) |
339 | | - |
340 | | - |
341 | | -async def _apply_to_payload( |
342 | | - payload: temporalio.api.common.v1.Payload, |
343 | | - cb: Callable[ |
344 | | - [Sequence[temporalio.api.common.v1.Payload]], |
345 | | - Awaitable[List[temporalio.api.common.v1.Payload]], |
346 | | - ], |
347 | | -) -> None: |
348 | | - """Apply API payload callback to payload.""" |
349 | | - new_payload = (await cb([payload]))[0] |
350 | | - payload.CopyFrom(new_payload) |
351 | | - |
352 | | - |
353 | | -async def _decode_payloads( |
354 | | - payloads: PayloadContainer, |
355 | | - codec: temporalio.converter.PayloadCodec, |
356 | | -) -> None: |
357 | | - """Decode payloads with the given codec.""" |
358 | | - return await _apply_to_payloads(payloads, codec.decode) |
359 | | - |
360 | | - |
361 | | -async def _decode_payload( |
362 | | - payload: temporalio.api.common.v1.Payload, |
363 | | - codec: temporalio.converter.PayloadCodec, |
364 | | -) -> None: |
365 | | - """Decode a payload with the given codec.""" |
366 | | - return await _apply_to_payload(payload, codec.decode) |
367 | | - |
368 | | - |
369 | 280 | async def decode_activation( |
370 | 281 | act: temporalio.bridge.proto.workflow_activation.WorkflowActivation, |
371 | 282 | codec: temporalio.converter.PayloadCodec, |
|
0 commit comments