Skip to content

Commit 46328d2

Browse files
committed
Factor out get_converters_with_context
1 parent e854537 commit 46328d2

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

temporalio/converter.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,20 @@ def with_context(self, context: SerializationContext) -> Self:
422422
423423
If none of the component converters returned new instances, return self.
424424
"""
425+
converters = self.get_converters_with_context(context)
426+
if converters is None:
427+
return self
428+
new_instance = type(self)() # Must have a nullary constructor
429+
new_instance._set_converters(*converters)
430+
return new_instance
431+
432+
def get_converters_with_context(
433+
self, context: SerializationContext
434+
) -> Optional[List[EncodingPayloadConverter]]:
435+
"""Return converter instances with context set.
436+
437+
If no converter uses context, return None.
438+
"""
425439
converters: list[EncodingPayloadConverter] = []
426440
any_with_context = False
427441
for c in self.converters.values():
@@ -431,13 +445,7 @@ def with_context(self, context: SerializationContext) -> Self:
431445
else:
432446
converters.append(c)
433447

434-
if not any_with_context:
435-
return self
436-
437-
# Must have a nullary constructor
438-
new_instance = type(self)()
439-
new_instance._set_converters(*converters)
440-
return new_instance
448+
return converters if any_with_context else None
441449

442450

443451
class DefaultPayloadConverter(CompositePayloadConverter):

0 commit comments

Comments
 (0)