@@ -101,29 +101,26 @@ def coerce(self, value: Any, target_type: type | None = None) -> Any:
101101 """
102102 ...
103103
104- def is_reconstructable (self , target_type : Any ) -> bool :
104+ def can_reconstruct (self , target_type : Any ) -> bool :
105105 """Return True if this converter can rebuild ``target_type`` from a payload.
106106
107107 Inbound type-discovery calls this to decide whether a function's
108108 annotated *input* type (or an activity's *return* annotation) should be
109109 passed to :meth:`deserialize` / :meth:`coerce`. When it returns ``False``
110110 the SDK passes the raw deserialized payload through unchanged -- this
111- gate is what stops the SDK from invoking an arbitrary constructor on a
112- builtin or otherwise unrecognized annotation .
113-
114- The default recognizes the types the built-in codec can rebuild --
115- dataclasses and ``from_json()``-capable types, plus ``Optional`` /
116- ``list`` / ``Sequence`` hints wrapping them -- and excludes builtins
117- (``int``, ``str``, ``dict``, ...) and unknown annotations.
118-
119- Override this to teach the SDK about a custom converter's own types (for
111+ gate is what stops the SDK from invoking reconstruction on a type the
112+ converter does not actually handle .
113+
114+ The base implementation is conservative and returns ``False``: a
115+ converter makes no reconstruction claims unless it opts in.
116+ :class:`JsonDataConverter` overrides this to recognize the types its
117+ codec can rebuild (dataclasses and ``from_json()``-capable types, plus
118+ ``Optional`` / ``list`` / ``Sequence`` hints wrapping them). Override
119+ this in a custom converter to teach the SDK about its own types (for
120120 example ``pydantic.BaseModel`` subclasses) so that inputs annotated with
121- them are reconstructed instead of arriving as raw JSON. The default
122- implementation recurses through ``self.is_reconstructable``, so an
123- override is also consulted for the element types of ``Optional`` /
124- ``list`` hints (e.g. ``list[MyModel]``).
121+ them are reconstructed instead of arriving as raw JSON.
125122 """
126- return _is_reconstructable ( self , target_type )
123+ return False
127124
128125
129126class JsonDataConverter (DataConverter ):
@@ -187,6 +184,9 @@ def coerce(self, value: Any, target_type: type | None = None) -> Any:
187184 self ._log_coercion_fallback (target_type , e )
188185 return value
189186
187+ def can_reconstruct (self , target_type : Any ) -> bool :
188+ return _can_reconstruct (self , target_type )
189+
190190 @staticmethod
191191 def _log_coercion_fallback (target_type : type , error : Exception ) -> None :
192192 logger .debug (
@@ -211,24 +211,25 @@ def _log_coercion_fallback(target_type: type, error: Exception) -> None:
211211# ---------------------------------------------------------------------------
212212
213213
214- def _is_reconstructable (converter : DataConverter , target_type : Any ) -> bool :
215- """Default :meth:`DataConverter.is_reconstructable` policy.
214+ def _can_reconstruct (converter : DataConverter , target_type : Any ) -> bool :
215+ """:class:`JsonDataConverter`'s reconstruction policy.
216216
217217 Recognizes dataclasses and ``from_json()``-capable types, plus ``Optional``
218218 / ``list`` / ``Sequence`` hints wrapping them; builtins and unknown
219- annotations are excluded. Recurses through ``converter.is_reconstructable``
220- (not itself) so a subclass override participates in the element-type checks
221- of ``Optional`` / ``list`` hints.
219+ annotations are excluded. Recurses through ``converter.can_reconstruct``
220+ (not itself) so a :class:`JsonDataConverter` subclass that overrides
221+ ``can_reconstruct`` still participates in the element-type checks of
222+ ``Optional`` / ``list`` hints.
222223 """
223224 origin = typing .get_origin (target_type )
224225 if origin is not None :
225226 args = typing .get_args (target_type )
226227 if origin is typing .Union or origin is types .UnionType :
227228 return any (
228- converter .is_reconstructable (a ) for a in args if a is not type (None )
229+ converter .can_reconstruct (a ) for a in args if a is not type (None )
229230 )
230231 if origin in (list , Sequence ):
231- return any (converter .is_reconstructable (a ) for a in args )
232+ return any (converter .can_reconstruct (a ) for a in args )
232233 return False
233234 if not isinstance (target_type , type ):
234235 return False
0 commit comments