Skip to content
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
2 changes: 2 additions & 0 deletions chartlets.js/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* The demo application now allows for switching the theme mode between
dark, light, and system mode.

* Changed the yet unused descriptor type `CbFunction` for callback functions.

## Version 0.0.29 (from 2024/11/26)

* Resolved warnings that appeared when using Vega charts.
Expand Down
8 changes: 6 additions & 2 deletions chartlets.js/packages/lib/src/types/model/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ export interface JsonSchema {
export interface CbFunction {
name: string;
parameters: CbParameter[];
returnType: JsonSchema;
return: CbReturn;
}

export interface CbParameter {
name: string;
type?: JsonSchema;
schema?: JsonSchema;
default?: unknown;
}

export interface CbReturn {
schema?: JsonSchema;
}

/**
* A reference to a specific contribution.
*/
Expand Down
1 change: 1 addition & 0 deletions chartlets.py/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

* Renamed `Plot` into `VegaChart`, which now also respects a `theme` property.

* Changed schema of the yet unused descriptor for callback functions.

## Version 0.0.29 (from 2024/11/26)

Expand Down
11 changes: 7 additions & 4 deletions chartlets.py/chartlets/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ def to_dict(self) -> dict[str, Any]:
"function": {
"name": self.function.__qualname__,
"parameters": [_parameter_to_dict(p) for p in parameters],
"returnType": _annotation_to_json_schema(
self.signature.return_annotation
),
"return": _return_to_dict(self.signature.return_annotation),
}
}
if self.inputs:
Expand Down Expand Up @@ -152,11 +150,16 @@ def _parameter_to_dict(parameter: inspect.Parameter) -> dict[str, Any]:
empty = inspect.Parameter.empty
d = {"name": parameter.name}
if parameter.annotation is not empty:
d |= {"type": _annotation_to_json_schema(parameter.annotation)}
d |= {"schema": _annotation_to_json_schema(parameter.annotation)}
if parameter.default is not empty:
d |= {"default": parameter.default}
return d

def _return_to_dict(return_annotation: Any) -> dict[str, Any]:
return {
"schema": _annotation_to_json_schema(return_annotation)
}


_basic_types = {
None: "null",
Expand Down
30 changes: 15 additions & 15 deletions chartlets.py/tests/callback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def my_callback(
b: str | int = "",
c: bool | None = False,
d: list[str] = (),
e: dict[str, Any] = (),
e: dict[str, Any] | None = None,
) -> str:
return f"{a}-{b}-{c}-{d}"
return f"{a}-{b}-{c}-{d}-{e}"


def my_callback_2(ctx, n: int) -> tuple[list[str], str | None]:
Expand Down Expand Up @@ -45,29 +45,29 @@ def test_to_dict_with_no_outputs(self):
"function": {
"name": "my_callback",
"parameters": [
{"name": "a", "type": {"type": "integer"}},
{"name": "a", "schema": {"type": "integer"}},
{
"default": "",
"name": "b",
"type": {"type": ["string", "integer"]},
"schema": {"type": ["string", "integer"]},
"default": "",
},
{
"default": False,
"name": "c",
"type": {"type": ["boolean", "null"]},
"schema": {"type": ["boolean", "null"]},
"default": False,
},
{
"default": (),
"name": "d",
"type": {"items": {"type": "string"}, "type": "array"},
"schema": {"items": {"type": "string"}, "type": "array"},
"default": (),
},
{
"default": (),
"name": "e",
"type": {"additionalProperties": {}, "type": "object"},
"schema": {'type': ['object', 'null']},
"default": None,
},
],
"returnType": {"type": "string"},
"return": {"schema": {"type": "string"}},
},
"inputs": [
{"id": "a", "property": "value"},
Expand Down Expand Up @@ -95,14 +95,14 @@ def test_to_dict_with_two_outputs(self):
{
"function": {
"name": "my_callback_2",
"parameters": [{"name": "n", "type": {"type": "integer"}}],
"returnType": {
"parameters": [{"name": "n", "schema": {"type": "integer"}}],
"return": {"schema":{
"items": [
{"items": {"type": "string"}, "type": "array"},
{"type": ["string", "null"]},
],
"type": "array",
},
}},
},
"inputs": [{"id": "n", "property": "value"}],
"outputs": [
Expand Down
Loading