Skip to content

Commit

Permalink
Bunch of serialization fixes in Python SDK (#54)
Browse files Browse the repository at this point in the history
* Fix serialization for Table type in Python SDK.

* Fix serialization for `CheckSetupStatusOptions` in python SDK.
  • Loading branch information
badmonster0 authored Mar 7, 2025
1 parent de98b35 commit 9216313
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions python/cocoindex/setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from typing import NamedTuple
from dataclasses import dataclass

from . import flow
from . import _engine

class CheckSetupStatusOptions(NamedTuple):
@dataclass
class CheckSetupStatusOptions:
delete_legacy_flows: bool

def check_setup_status(options: CheckSetupStatusOptions) -> _engine.SetupStatusCheck:
flow.ensure_all_flows_built()
return _engine.check_setup_status(options)
return _engine.check_setup_status(vars(options))

def apply_setup_changes(status_check: _engine.SetupStatusCheck):
_engine.apply_setup_changes(status_check)
10 changes: 5 additions & 5 deletions python/cocoindex/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _dump_fields_schema(cls: type) -> list[dict[str, Any]]:
return [
{
'name': field.name,
'value_type': _dump_enriched_type(field.type),
**_dump_enriched_type(field.type)
}
for field in dataclasses.fields(cls)
]
Expand All @@ -56,7 +56,7 @@ def _dump_type(t, metadata):
elif dataclasses.is_dataclass(elem_type):
encoded_type = {
'kind': 'Table',
'row': _dump_fields_schema(elem_type),
'row': { 'fields': _dump_fields_schema(elem_type) },
}
else:
raise ValueError(f"Unsupported type: {t}")
Expand Down Expand Up @@ -86,9 +86,7 @@ def _dump_type(t, metadata):

return encoded_type

def _dump_enriched_type(t) -> dict[str, Any] | None:
if t is None:
return None
def _dump_enriched_type(t) -> dict[str, Any]:
t, metadata = _get_origin_type_and_metadata(t)
enriched_type_json = {'type': _dump_type(t, metadata)}
attrs = None
Expand All @@ -106,4 +104,6 @@ def dump_type(t) -> dict[str, Any] | None:
"""
Convert a Python type to a CocoIndex's type in JSON.
"""
if t is None:
return None
return _dump_enriched_type(t)

0 comments on commit 9216313

Please sign in to comment.