Skip to content

Commit 7922f93

Browse files
committed
Add notes and str / repr methods
1 parent 1c890e9 commit 7922f93

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/posit/connect/_api.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from __future__ import annotations
22

3+
import itertools
34
import posixpath
45
from abc import ABC, abstractmethod
56
from collections.abc import Mapping
6-
from typing import TYPE_CHECKING, Any, Generic, TypeVar, cast
7+
from typing import TYPE_CHECKING, Any, Generator, Generic, Optional, TypeVar, cast, overload
78

89
from ._api_call import ApiCallMixin, get_api
910
from ._json import Jsonifiable, JsonifiableDict, ResponseAttrs
@@ -23,6 +24,21 @@
2324
# * Classes should write the `path` only once within its init method.
2425
# * Through regular interactions, the path should only be written once.
2526

27+
# TODO-barret; Add `.client` (a `Client` class) within `._ctx`.
28+
29+
# When making a new class,
30+
# * 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`
32+
# * Document all attributes like normal
33+
# * 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+
# * Inherit from `ApiDictEndpoint` or `ApiListEndpoint` as needed
35+
# * 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+
2642

2743
# TODO-future?; Add type hints for the ReadOnlyDict class
2844
# ArgsT = TypeVar("ArgsT", bound="ResponseAttrs")
@@ -45,9 +61,7 @@ def __init__(self, attrs: ResponseAttrs) -> None:
4561
attrs : dict
4662
Resource attributes passed
4763
"""
48-
print("here!", attrs)
4964
super().__init__()
50-
print("mapping attrs", attrs)
5165
self._attrs = attrs
5266

5367
def get(self, key: str, default: Any = None) -> Any:
@@ -133,6 +147,13 @@ def __init__(
133147
# self._ctx.client = client
134148
self._path = path
135149

150+
def __str__(self) -> str:
151+
return self.__repr__()
152+
153+
def __repr__(self) -> str:
154+
# CLASSNAME - v1/content/123/path; {'guid': '123', 'name': 'My Content'}
155+
return repr(f"{self.__class__.__name__} - {self._path}; {super().__repr__()}")
156+
136157

137158
T = TypeVar("T", bound="ReadOnlyDict")
138159
"""A type variable that is bound to the `Active` class"""
@@ -210,7 +231,9 @@ def __str__(self) -> str:
210231

211232
def __repr__(self) -> str:
212233
# Jobs - 123 items
213-
return repr(f"{self.__class__.__name__} - { len(self.fetch()) } items")
234+
return repr(
235+
f"{self.__class__.__name__} - { len(list(self.fetch())) } items - {self._path}"
236+
)
214237

215238
def find(self, uid: str) -> T | None:
216239
"""

0 commit comments

Comments
 (0)