|
| 1 | +# TODO-barret-future; Piecemeal migrate everything to leverage `ApiDictEndpoint` and `ApiListEndpoint` classes. |
| 2 | +# TODO-barret-future; Merge any trailing behavior of `Active` or `ActiveList` into the new classes. |
| 3 | + |
1 | 4 | from __future__ import annotations |
2 | 5 |
|
3 | 6 | import itertools |
|
14 | 17 |
|
15 | 18 |
|
16 | 19 | # Design Notes: |
17 | | -# * Perform API calls on property retrieval |
| 20 | +# * Perform API calls on property retrieval. e.g. `my_content.repository` |
18 | 21 | # * Dictionary endpoints: Retrieve all attributes during init unless provided |
19 | 22 | # * List endpoints: Do not retrieve until `.fetch()` is called directly. Avoids cache invalidation issues. |
| 23 | +# * While slower, all ApiListEndpoint helper methods should `.fetch()` on demand. |
20 | 24 | # * Only expose methods needed for `ReadOnlyDict`. |
21 | 25 | # * Ex: When inheriting from `dict`, we'd need to shut down `update`, `pop`, etc. |
22 | 26 | # * Use `ApiContextProtocol` to ensure that the class has the necessary attributes for API calls. |
23 | 27 | # * Inherit from `ApiCallMixin` to add all helper methods for API calls. |
24 | 28 | # * Classes should write the `path` only once within its init method. |
25 | 29 | # * Through regular interactions, the path should only be written once. |
26 | 30 |
|
27 | | -# TODO-barret; Add `.client` (a `Client` class) within `._ctx`. |
28 | | - |
29 | 31 | # When making a new class, |
30 | 32 | # * Use a class to define the parameters and their types |
31 | | -# * If attaching the type info class to the parent class, start with `_`. E.g.: `_Attrs` |
| 33 | +# * If attaching the type info class to the parent class, start with `_`. E.g.: `ContentItemRepository._Attrs` |
32 | 34 | # * Document all attributes like normal |
33 | 35 | # * When the time comes that there are multiple attribute types, we can use overloads with full documentation and unpacking of type info class for each overload method. |
34 | 36 | # * Inherit from `ApiDictEndpoint` or `ApiListEndpoint` as needed |
35 | 37 | # * Init signature should be `def __init__(self, ctx: Context, path: str, /, **attrs: Jsonifiable) -> None:` |
36 | | -# * |
37 | | -# |
38 | | -# |
39 | | -# * Inherit from `ApiDictEndpoint` or `ApiListEndpoint` as needed |
40 | | -# Use a internal |
41 | | - |
42 | | - |
43 | | -# TODO-future?; Add type hints for the ReadOnlyDict class |
44 | | -# ArgsT = TypeVar("ArgsT", bound="ResponseAttrs") |
45 | 38 |
|
46 | 39 |
|
47 | | -class ReadOnlyDict( |
48 | | - # Generic[ArgsT], |
49 | | - Mapping, |
50 | | -): |
51 | | - # _attrs: ArgsT |
| 40 | +# This class should not have typing about the class keys as that would fix the class's typing. If |
| 41 | +# for some reason, we _know_ the keys are fixed (as we've moved on to a higher version), we can add |
| 42 | +# `Generic[AttrsT]` to the class. |
| 43 | +class ReadOnlyDict(Mapping): |
52 | 44 | _attrs: ResponseAttrs |
53 | 45 | """Resource attributes passed.""" |
54 | 46 |
|
@@ -145,8 +137,6 @@ def __init__( |
145 | 137 |
|
146 | 138 | super().__init__(attrs) |
147 | 139 | self._ctx = ctx |
148 | | - # TODO-barret; Look into `client` to make get,put,patch,delete calls. |
149 | | - # self._ctx.client = client |
150 | 140 | self._path = path |
151 | 141 |
|
152 | 142 | def __str__(self) -> str: |
|
0 commit comments