File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff 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
443451class DefaultPayloadConverter (CompositePayloadConverter ):
You can’t perform that action at this time.
0 commit comments