Skip to content

Commit e3b88f2

Browse files
authored
Merge pull request #67 from bcdev/forman-x-callback_function_descriptor
Changed the yet unused descriptor type `CbFunction`
2 parents edee572 + ced52de commit e3b88f2

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

chartlets.js/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* The demo application now allows for switching the theme mode between
2929
dark, light, and system mode.
3030

31+
* Changed the yet unused descriptor type `CbFunction` for callback functions.
32+
3133
## Version 0.0.29 (from 2024/11/26)
3234

3335
* Resolved warnings that appeared when using Vega charts.

chartlets.js/packages/lib/src/types/model/callback.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ export interface JsonSchema {
2323
export interface CbFunction {
2424
name: string;
2525
parameters: CbParameter[];
26-
returnType: JsonSchema;
26+
return: CbReturn;
2727
}
2828

2929
export interface CbParameter {
3030
name: string;
31-
type?: JsonSchema;
31+
schema?: JsonSchema;
3232
default?: unknown;
3333
}
3434

35+
export interface CbReturn {
36+
schema?: JsonSchema;
37+
}
38+
3539
/**
3640
* A reference to a specific contribution.
3741
*/

chartlets.py/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

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

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

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

chartlets.py/chartlets/callback.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ def to_dict(self) -> dict[str, Any]:
104104
"function": {
105105
"name": self.function.__qualname__,
106106
"parameters": [_parameter_to_dict(p) for p in parameters],
107-
"returnType": _annotation_to_json_schema(
108-
self.signature.return_annotation
109-
),
107+
"return": _return_to_dict(self.signature.return_annotation),
110108
}
111109
}
112110
if self.inputs:
@@ -152,11 +150,16 @@ def _parameter_to_dict(parameter: inspect.Parameter) -> dict[str, Any]:
152150
empty = inspect.Parameter.empty
153151
d = {"name": parameter.name}
154152
if parameter.annotation is not empty:
155-
d |= {"type": _annotation_to_json_schema(parameter.annotation)}
153+
d |= {"schema": _annotation_to_json_schema(parameter.annotation)}
156154
if parameter.default is not empty:
157155
d |= {"default": parameter.default}
158156
return d
159157

158+
def _return_to_dict(return_annotation: Any) -> dict[str, Any]:
159+
return {
160+
"schema": _annotation_to_json_schema(return_annotation)
161+
}
162+
160163

161164
_basic_types = {
162165
None: "null",

chartlets.py/tests/callback_test.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def my_callback(
1515
b: str | int = "",
1616
c: bool | None = False,
1717
d: list[str] = (),
18-
e: dict[str, Any] = (),
18+
e: dict[str, Any] | None = None,
1919
) -> str:
20-
return f"{a}-{b}-{c}-{d}"
20+
return f"{a}-{b}-{c}-{d}-{e}"
2121

2222

2323
def my_callback_2(ctx, n: int) -> tuple[list[str], str | None]:
@@ -45,29 +45,29 @@ def test_to_dict_with_no_outputs(self):
4545
"function": {
4646
"name": "my_callback",
4747
"parameters": [
48-
{"name": "a", "type": {"type": "integer"}},
48+
{"name": "a", "schema": {"type": "integer"}},
4949
{
50-
"default": "",
5150
"name": "b",
52-
"type": {"type": ["string", "integer"]},
51+
"schema": {"type": ["string", "integer"]},
52+
"default": "",
5353
},
5454
{
55-
"default": False,
5655
"name": "c",
57-
"type": {"type": ["boolean", "null"]},
56+
"schema": {"type": ["boolean", "null"]},
57+
"default": False,
5858
},
5959
{
60-
"default": (),
6160
"name": "d",
62-
"type": {"items": {"type": "string"}, "type": "array"},
61+
"schema": {"items": {"type": "string"}, "type": "array"},
62+
"default": (),
6363
},
6464
{
65-
"default": (),
6665
"name": "e",
67-
"type": {"additionalProperties": {}, "type": "object"},
66+
"schema": {'type': ['object', 'null']},
67+
"default": None,
6868
},
6969
],
70-
"returnType": {"type": "string"},
70+
"return": {"schema": {"type": "string"}},
7171
},
7272
"inputs": [
7373
{"id": "a", "property": "value"},
@@ -95,14 +95,14 @@ def test_to_dict_with_two_outputs(self):
9595
{
9696
"function": {
9797
"name": "my_callback_2",
98-
"parameters": [{"name": "n", "type": {"type": "integer"}}],
99-
"returnType": {
98+
"parameters": [{"name": "n", "schema": {"type": "integer"}}],
99+
"return": {"schema":{
100100
"items": [
101101
{"items": {"type": "string"}, "type": "array"},
102102
{"type": ["string", "null"]},
103103
],
104104
"type": "array",
105-
},
105+
}},
106106
},
107107
"inputs": [{"id": "n", "property": "value"}],
108108
"outputs": [

0 commit comments

Comments
 (0)