Skip to content

Commit cb7af36

Browse files
committed
Update _api.py
1 parent 1c4b79f commit cb7af36

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/posit/connect/_api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@
1313
# * Perform API calls on property retrieval
1414
# * Dictionary endpoints: Retrieve all attributes during init unless provided
1515
# * List endpoints: Do not retrieve until `.fetch()` is called directly. Avoids cache invalidation issues.
16+
# * Only expose methods needed for `ReadOnlyDict`.
17+
# * Ex: When inheriting from `dict`, we'd need to shut down `update`, `pop`, etc.
18+
# * Use `ApiContextProtocol` to ensure that the class has the necessary attributes for API calls.
19+
# * Inherit from `EndpointMixin` to add all helper methods for API calls.
20+
# * Classes should write the `path` only once within its init method.
21+
# * Through regular interactions, the path should only be written once.
1622

1723

1824
class ApiContextProtocol(Protocol):
1925
_ctx: Context
2026
_path: str
2127

2228

23-
# TODO-future; Add type hints for the ReadOnlyDict class
29+
# TODO-future?; Add type hints for the ReadOnlyDict class
2430
# ArgsT = TypeVar("ArgsT", bound="ResponseAttrs")
2531

2632

@@ -176,6 +182,7 @@ def fetch(self) -> tuple[T, ...]:
176182
results = self._get_api()
177183
return tuple(self._to_instance(result) for result in results)
178184

185+
# Return a `tuple` to provide immutability to hint that this is a read-only collection.
179186
def __iter__(self) -> tuple[T, ...]:
180187
return self.fetch()
181188

0 commit comments

Comments
 (0)