Skip to content

Commit

Permalink
Docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Feb 4, 2025
1 parent ffd2a8e commit 31f40aa
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions temporalio/contrib/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@


class PydanticModelTypeConverter(JSONTypeConverter):
"""
Type converter for pydantic model instances.
"""

def to_typed_value(self, hint: Type, value: Any) -> Any:
if not inspect.isclass(hint) or not issubclass(hint, pydantic.BaseModel):
return JSONTypeConverter.Unhandled
Expand Down Expand Up @@ -67,17 +71,24 @@ def to_typed_value(self, hint: Type, value: Any) -> Any:


class PydanticJSONEncoder(AdvancedJSONEncoder):
"""
JSON encoder for python objects containing pydantic model instances.
"""

def default(self, o: Any) -> Any:
if isinstance(o, pydantic.BaseModel):
return to_jsonable_python(o)
return super().default(o)


class PydanticPayloadConverter(CompositePayloadConverter):
"""Pydantic payload converter.
"""
Payload converter for payloads containing pydantic model instances.
Payload converter that replaces the default JSON conversion with Pydantic
JSON conversion.
JSON conversion is replaced with a converter that uses
:py:class:`PydanticJSONEncoder` to convert the python object to JSON, and
:py:class:`PydanticModelTypeConverter` to convert raw python values to
pydantic model instances.
"""

def __init__(self) -> None:
Expand All @@ -98,7 +109,7 @@ def __init__(self) -> None:
pydantic_data_converter = DataConverter(
payload_converter_class=PydanticPayloadConverter
)
"""Data converter for Pydantic models.
"""Data converter for payloads containing pydantic model instances.
To use, pass this as the ``data_converter`` argument to :py:class:`temporalio.client.Client`
To use, pass as the ``data_converter`` argument of :py:class:`temporalio.client.Client`
"""

0 comments on commit 31f40aa

Please sign in to comment.