Skip to content

Commit 7bde7df

Browse files
committed
Fixed ext_ctx annotations and api docs
1 parent 2caf28e commit 7bde7df

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

chartlets.py/chartlets/controllers/callback.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,29 @@
33
from chartlets.extensioncontext import ExtensionContext
44
from chartlets.response import Response
55
from chartlets.util.assertions import assert_is_instance_of
6-
from chartlets.util.assertions import assert_is_not_none
76
from ._helpers import get_contribution
87

98

10-
# POST /chartlets/callback
119
def get_callback_results(
12-
ext_ctx: ExtensionContext | None, data: dict[str, Any]
10+
ext_ctx: ExtensionContext, data: dict[str, Any]
1311
) -> Response:
1412
"""Generate the response for the endpoint `POST /chartlets/callback`.
1513
1614
Args:
17-
ext_ctx: Extension context. If `None`,
18-
the function returns a 404 error response.
15+
ext_ctx: Extension context.
1916
data: A dictionary deserialized from a request JSON body
2017
that should contain a key `callbackRequests` of type `list`.
2118
Returns:
2219
A `Response` object.
2320
On success, the response is a list of state-change requests
2421
grouped by contributions.
2522
"""
26-
assert_is_not_none("ext_ctx", ext_ctx)
23+
assert_is_instance_of("ext_ctx", ext_ctx, ExtensionContext)
2724
assert_is_instance_of("data", data, dict)
2825

2926
# TODO: validate data
3027
callback_requests: list[dict] = data.get("callbackRequests") or []
3128

32-
# TODO: assert correctness, set status code on error
3329
state_change_requests: list[dict[str, Any]] = []
3430
for callback_request in callback_requests:
3531
contrib_point_name: str = callback_request["contribPoint"]
@@ -80,6 +76,7 @@ def get_callback_results(
8076
}
8177
)
8278

79+
# find an existing state change request
8380
existing_scr: dict[str, Any] | None = None
8481
for scr in state_change_requests:
8582
if (
@@ -88,9 +85,12 @@ def get_callback_results(
8885
):
8986
existing_scr = scr
9087
break
88+
9189
if existing_scr is not None:
90+
# merge with existing state change request
9291
existing_scr["stateChanges"].extend(state_changes)
9392
else:
93+
# append new state change request
9494
state_change_requests.append(
9595
{
9696
"contribPoint": contrib_point_name,

chartlets.py/chartlets/controllers/contributions.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
from chartlets.extensioncontext import ExtensionContext
22
from chartlets.response import Response
3-
from chartlets.util.assertions import assert_is_not_none
3+
from chartlets.util.assertions import assert_is_instance_of
44

55

6-
def get_contributions(ext_ctx: ExtensionContext | None) -> Response:
6+
def get_contributions(ext_ctx: ExtensionContext) -> Response:
77
"""Generate the response for the endpoint `GET /chartlets/contributions`.
88
99
Args:
10-
ext_ctx: Extension context. If `None`,
11-
the function returns a 404 error response.
10+
ext_ctx: Extension context.
1211
Returns:
1312
A `Response` object.
1413
On success, the response is a dictionary that represents
1514
a JSON-serialized component tree.
1615
"""
17-
assert_is_not_none("ext_ctx", ext_ctx)
16+
assert_is_instance_of("ext_ctx", ext_ctx, ExtensionContext)
1817
extensions = ext_ctx.extensions
1918
contributions = ext_ctx.contributions
2019
return Response.success(

chartlets.py/chartlets/controllers/layout.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def get_layout(
10-
ext_ctx: ExtensionContext | None,
10+
ext_ctx: ExtensionContext,
1111
contrib_point_name: str,
1212
contrib_index: int,
1313
data: dict[str, Any],
@@ -16,8 +16,7 @@ def get_layout(
1616
`POST /chartlets/layout/{contrib_point_name}/{contrib_index}`.
1717
1818
Args:
19-
ext_ctx: Extension context. If `None`,
20-
the function returns a 404 error response.
19+
ext_ctx: Extension context.
2120
contrib_point_name: Contribution point name.
2221
contrib_index: Contribution index.
2322
data: A dictionary deserialized from a request JSON body
@@ -27,6 +26,7 @@ def get_layout(
2726
On success, the response is a dictionary that represents
2827
a JSON-serialized component tree.
2928
"""
29+
assert_is_instance_of("ext_ctx", ext_ctx, ExtensionContext)
3030
assert_is_instance_of("data", data, dict)
3131

3232
# TODO: validate data

0 commit comments

Comments
 (0)