@@ -139,7 +139,7 @@ class WithSerializationContext(ABC):
139
139
during serialization and deserialization.
140
140
"""
141
141
142
- def with_context (self , context : Optional [ SerializationContext ] ) -> Self :
142
+ def with_context (self , context : SerializationContext ) -> Self :
143
143
"""Return a copy of this object configured to use the given context.
144
144
145
145
Args:
@@ -401,7 +401,7 @@ def from_payloads(
401
401
) from err
402
402
return values
403
403
404
- def with_context (self , context : Optional [ SerializationContext ] ) -> Self :
404
+ def with_context (self , context : SerializationContext ) -> Self :
405
405
"""Return a new instance with the given context."""
406
406
converters = [
407
407
c .with_context (context ) if isinstance (c , WithSerializationContext ) else c
@@ -1313,12 +1313,13 @@ def _with_context(self, context: Optional[SerializationContext]) -> Self:
1313
1313
payload_converter = self .payload_converter
1314
1314
payload_codec = self .payload_codec
1315
1315
failure_converter = self .failure_converter
1316
- if isinstance (payload_converter , WithSerializationContext ):
1317
- payload_converter = payload_converter .with_context (context )
1318
- if isinstance (payload_codec , WithSerializationContext ):
1319
- payload_codec = payload_codec .with_context (context )
1320
- if isinstance (failure_converter , WithSerializationContext ):
1321
- failure_converter = failure_converter .with_context (context )
1316
+ if context :
1317
+ if isinstance (payload_converter , WithSerializationContext ):
1318
+ payload_converter = payload_converter .with_context (context )
1319
+ if isinstance (payload_codec , WithSerializationContext ):
1320
+ payload_codec = payload_codec .with_context (context )
1321
+ if isinstance (failure_converter , WithSerializationContext ):
1322
+ failure_converter = failure_converter .with_context (context )
1322
1323
object .__setattr__ (cloned , "payload_converter" , payload_converter )
1323
1324
object .__setattr__ (cloned , "payload_codec" , payload_codec )
1324
1325
object .__setattr__ (cloned , "failure_converter" , failure_converter )
0 commit comments