File tree Expand file tree Collapse file tree 1 file changed +16
-11
lines changed Expand file tree Collapse file tree 1 file changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -417,18 +417,23 @@ 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 , any_with_context = [], False
425+ for c in self .converters .values ():
426+ if isinstance (c , WithSerializationContext ):
427+ converters .append (c .with_context (context ))
428+ any_with_context = True
429+ else :
430+ converters .append (c )
431+
432+ if not any_with_context :
433+ return self
434+
421435 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- )
436+ new_instance ._set_converters (* converters )
432437 return new_instance
433438
434439
You can’t perform that action at this time.
0 commit comments