Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bunch of serialization fixes in Python SDK #54

Merged
merged 2 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)