Skip to content

Commit 15c8447

Browse files
authored
Merge pull request #64 from cloudblue/LITE-26630-improve-documentation
LITE-26630: improve documentation
2 parents 2f1e1a2 + 7f4fc05 commit 15c8447

8 files changed

Lines changed: 187 additions & 82 deletions

File tree

connect/client/fluent.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import contextvars
77
import threading
88
from json.decoder import JSONDecodeError
9+
from typing import Union
910

1011
import httpx
1112
import requests
@@ -60,7 +61,7 @@ def __init__(
6061
self.resourceset_append = resourceset_append
6162

6263
@property
63-
def response(self):
64+
def response(self) -> requests.Response:
6465
"""
6566
Returns the raw
6667
[`requests`](https://requests.readthedocs.io/en/latest/api/#requests.Response)
@@ -69,7 +70,7 @@ def response(self):
6970
return self._response
7071

7172
@response.setter
72-
def response(self, value):
73+
def response(self, value: requests.Response):
7374
self._response = value
7475

7576
def __getattr__(self, name):
@@ -80,7 +81,7 @@ def __getattr__(self, name):
8081
def __call__(self, name):
8182
return self.ns(name)
8283

83-
def ns(self, name):
84+
def ns(self, name: str) -> Union[NS, AsyncNS]:
8485
"""
8586
Returns a `Namespace` object identified by its name.
8687
@@ -107,7 +108,7 @@ def ns(self, name):
107108

108109
return self._get_namespace_class()(self, name)
109110

110-
def collection(self, name):
111+
def collection(self, name: str) -> Union[Collection, AsyncCollection]:
111112
"""
112113
Returns a `Collection` object identified by its name.
113114

connect/client/logger.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44

55
class RequestLogger:
6+
67
def __init__(self, file=sys.stdout):
78
self._file = file
89

9-
def obfuscate(self, key, value):
10+
def obfuscate(self, key: str, value: str) -> str:
1011
if key in ('authorization', 'authentication'):
1112
if value.startswith('ApiKey '):
1213
return value.split(':')[0] + '*' * 10
@@ -19,7 +20,7 @@ def obfuscate(self, key, value):
1920
return f'{value[0:start_idx + 2]}******{value[end_idx - 2:]}'
2021
return value
2122

22-
def log_request(self, method, url, kwargs):
23+
def log_request(self, method: str, url: str, kwargs):
2324
other_args = {k: v for k, v in kwargs.items() if k not in ('headers', 'json', 'params')}
2425

2526
if 'params' in kwargs:

connect/client/mixins.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Copyright (c) 2023 Ingram Micro. All Rights Reserved.
55
#
66
import time
7+
from typing import Any, Dict
78

89
from httpx import HTTPError
910
from requests.exceptions import RequestException, Timeout
@@ -13,7 +14,7 @@
1314

1415
class SyncClientMixin:
1516

16-
def get(self, url, **kwargs):
17+
def get(self, url: str, **kwargs) -> Any:
1718
"""
1819
Make a GET call to the given url.
1920
@@ -22,7 +23,7 @@ def get(self, url, **kwargs):
2223
"""
2324
return self.execute('get', url, **kwargs)
2425

25-
def create(self, url, payload=None, **kwargs):
26+
def create(self, url: str, payload: Dict = None, **kwargs) -> Any:
2627
"""
2728
Make a POST call to the given url with the payload.
2829
@@ -37,7 +38,7 @@ def create(self, url, payload=None, **kwargs):
3738

3839
return self.execute('post', url, **kwargs)
3940

40-
def update(self, url, payload=None, **kwargs):
41+
def update(self, url: str, payload: Dict = None, **kwargs) -> Any:
4142
"""
4243
Make a PUT call to the given url with the payload.
4344
@@ -52,7 +53,7 @@ def update(self, url, payload=None, **kwargs):
5253

5354
return self.execute('put', url, **kwargs)
5455

55-
def delete(self, url, payload=None, **kwargs):
56+
def delete(self, url: str, payload: Dict = None, **kwargs) -> Any:
5657
"""
5758
Make a DELETE call to the given url with the payload.
5859
@@ -67,7 +68,7 @@ def delete(self, url, payload=None, **kwargs):
6768

6869
return self.execute('delete', url, **kwargs)
6970

70-
def execute(self, method, path, **kwargs):
71+
def execute(self, method: str, path: str, **kwargs) -> Any:
7172
if (
7273
self._use_specs
7374
and self._validate_using_specs
@@ -127,7 +128,7 @@ def _execute_http_call(self, method, url, kwargs): # noqa: CCR001
127128

128129
class AsyncClientMixin:
129130

130-
async def get(self, url, **kwargs):
131+
async def get(self, url: str, **kwargs) -> Any:
131132
"""
132133
Make a GET call to the given url.
133134
@@ -136,7 +137,7 @@ async def get(self, url, **kwargs):
136137
"""
137138
return await self.execute('get', url, **kwargs)
138139

139-
async def create(self, url, payload=None, **kwargs):
140+
async def create(self, url: str, payload: Dict = None, **kwargs) -> Any:
140141
"""
141142
Make a POST call to the given url with the payload.
142143
@@ -151,7 +152,7 @@ async def create(self, url, payload=None, **kwargs):
151152

152153
return await self.execute('post', url, **kwargs)
153154

154-
async def update(self, url, payload=None, **kwargs):
155+
async def update(self, url: str, payload: Dict = None, **kwargs) -> Any:
155156
"""
156157
Make a PUT call to the given url with the payload.
157158
@@ -166,7 +167,7 @@ async def update(self, url, payload=None, **kwargs):
166167

167168
return await self.execute('put', url, **kwargs)
168169

169-
async def delete(self, url, payload=None, **kwargs):
170+
async def delete(self, url: str, payload: Dict = None, **kwargs) -> Any:
170171
"""
171172
Make a DELETE call to the given url with the payload.
172173
@@ -181,7 +182,7 @@ async def delete(self, url, payload=None, **kwargs):
181182

182183
return await self.execute('delete', url, **kwargs)
183184

184-
async def execute(self, method, path, **kwargs):
185+
async def execute(self, method: str, path: str, **kwargs) -> Any:
185186
if (
186187
self._use_specs
187188
and self._validate_using_specs

connect/client/models/base.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, client, path):
2121
self._path = path
2222

2323
@property
24-
def path(self):
24+
def path(self) -> str:
2525
return self._path
2626

2727
def __getattr__(self, name):
@@ -35,7 +35,7 @@ def __iter__(self):
3535
def __call__(self, name):
3636
return self.ns(name)
3737

38-
def collection(self, name):
38+
def collection(self, name: str):
3939
"""
4040
Returns a `[Async]Collection` object nested under this namespace object
4141
identified by its name.
@@ -55,6 +55,10 @@ def collection(self, name):
5555
5656
Args:
5757
name (str): The name of the collection to access.
58+
59+
Returns:
60+
(Union[Collection, AsyncCollection]): Returns an object nested under this namespace
61+
object identified by its name.
5862
"""
5963

6064
if not isinstance(name, str):
@@ -68,7 +72,7 @@ def collection(self, name):
6872
f'{self._path}/{name}',
6973
)
7074

71-
def ns(self, name):
75+
def ns(self, name: str):
7276
"""
7377
Returns a `[Async]Namespace` object nested under this namespace
7478
identified by its name.
@@ -88,6 +92,10 @@ def ns(self, name):
8892
8993
Args:
9094
name (str): The name of the namespace to access.
95+
96+
Returns:
97+
(Union[NS, AsyncNS]): Returns an object nested under this namespace
98+
identified by its name.
9199
"""
92100
if not isinstance(name, str):
93101
raise TypeError('`name` must be a string.')
@@ -149,6 +157,10 @@ def all(self):
149157
"""
150158
Returns a `[Async]ResourceSet` object that that allow to access all the resources that
151159
belong to this collection.
160+
161+
Returns:
162+
(Union[ResourceSet, AsyncResourceSet]): Returns an object that that allow to access
163+
all the resources that belong to this collection.
152164
"""
153165
return self._get_resourceset_class()(
154166
self._client,
@@ -188,6 +200,10 @@ def filter(self, *args, **kwargs):
188200
```
189201
190202
Also keyword arguments will be combined with logical **and**.
203+
204+
Returns:
205+
(Union[ResourceSet, AsyncResourceSet]): The returned ResourceSet object will be
206+
filtered based on the arguments and keyword arguments.
191207
"""
192208
query = R()
193209
for arg in args:
@@ -208,7 +224,7 @@ def filter(self, *args, **kwargs):
208224
query=query,
209225
)
210226

211-
def resource(self, resource_id):
227+
def resource(self, resource_id: str):
212228
"""
213229
Returns a `[Async]Resource` object that represent a resource that belong to
214230
this collection identified by its unique identifier.
@@ -227,6 +243,10 @@ def resource(self, resource_id):
227243
228244
Args:
229245
resource_id (str): The unique identifier of the resource.
246+
247+
Returns:
248+
(Union[Resource, AsyncResource]): Returns an object that represent a resource that
249+
belong to this collection identified by its unique identifier.
230250
"""
231251
if not isinstance(resource_id, (str, int)):
232252
raise TypeError('`resource_id` must be a string or int.')
@@ -239,13 +259,17 @@ def resource(self, resource_id):
239259
f'{self._path}/{resource_id}',
240260
)
241261

242-
def action(self, name):
262+
def action(self, name: str):
243263
"""
244264
Returns an `[Async]Action` object that represent an action to perform
245265
on this collection identified by its name.
246266
247267
Args:
248268
name (str): The name of the action to perform.
269+
270+
Returns:
271+
(Union[Action, AsyncAction]): Returns an object that represent an action to perform
272+
on this collection identified by its name.
249273
"""
250274
if not isinstance(name, str):
251275
raise TypeError('`name` must be a string.')
@@ -311,7 +335,7 @@ def __getattr__(self, name):
311335
def __call__(self, name):
312336
return self.action(name)
313337

314-
def collection(self, name):
338+
def collection(self, name: str):
315339
"""
316340
Returns a `[Async]Collection` object nested under this resource object
317341
identified by its name.
@@ -335,6 +359,10 @@ def collection(self, name):
335359
336360
Args:
337361
name (str): The name of the collection to access.
362+
363+
Returns:
364+
(Union[Collection, AsyncCollection]): Returns an object nested under this resource
365+
object identified by its name.
338366
""" # noqa: E501
339367
if not isinstance(name, str):
340368
raise TypeError('`name` must be a string.')
@@ -347,7 +375,7 @@ def collection(self, name):
347375
f'{self._path}/{name}',
348376
)
349377

350-
def action(self, name):
378+
def action(self, name: str):
351379
"""
352380
Returns an `[Async]Action` object that can be performed on this this resource object
353381
identified by its name.
@@ -370,6 +398,10 @@ def action(self, name):
370398
371399
Args:
372400
name (str): The name of the action to perform.
401+
402+
Returns:
403+
(Union[Action, AsyncAction]): Returns an object that can be performed on this this
404+
resource object identified by its name.
373405
"""
374406
if not isinstance(name, str):
375407
raise TypeError('`name` must be a string.')

0 commit comments

Comments
 (0)