File tree Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -417,18 +417,24 @@ def from_payloads(
417417 return values
418418
419419 def with_context (self , context : SerializationContext ) -> Self :
420- """Return a new instance with context set on the component converters"""
420+ """Return a new instance with context set on the component converters.
421+
422+ If none of the component converters support with_context, return self.
423+ """
424+ converters : list [EncodingPayloadConverter ] = []
425+ any_with_context = False
426+ for c in self .converters .values ():
427+ if isinstance (c , WithSerializationContext ):
428+ converters .append (c .with_context (context ))
429+ any_with_context = True
430+ else :
431+ converters .append (c )
432+
433+ if not any_with_context :
434+ return self
435+
421436 new_instance = type (self )()
422- new_instance ._set_converters (
423- * (
424- (
425- c .with_context (context )
426- if isinstance (c , WithSerializationContext )
427- else c
428- )
429- for c in self .converters .values ()
430- )
431- )
437+ new_instance ._set_converters (* converters )
432438 return new_instance
433439
434440
You can’t perform that action at this time.
0 commit comments