Skip to content

Commit e190419

Browse files
committed
Changed the yet unused descriptor type CbFunction for callback functions.
1 parent 43e93e2 commit e190419

File tree

7 files changed

+35
-23
lines changed

7 files changed

+35
-23
lines changed

chartlets.js/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version 0.0.x (in development)
2+
3+
* Changed the yet unused descriptor type `CbFunction` for callback functions.
4+
15
## Version 0.0.28 (from 2024/11/26)
26

37
* Updated docs.

chartlets.js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chartlets",
3-
"version": "0.0.28",
3+
"version": "0.0.29",
44
"description": "An experimental library for integrating interactive charts into existing JavaScript applications.",
55
"type": "module",
66
"files": [

chartlets.js/src/lib/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
@@ -2,6 +2,7 @@
22

33
* Fixed a bug that prevent using annotations of type `dict` or `dict[str, T]`.
44
in callback functions.
5+
* Changed schema of the yet unused descriptor for callback functions.
56

67

78
## Version 0.0.28 (from 2024/11/26)

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/chartlets/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "0.0.28"
1+
version = "0.0.29"

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)