Skip to content

Commit 517aa31

Browse files
authored
docs: Update docstrings and align to 120 line width (#312)
- Rm type hints in the brackets - Use sentences. - Align to 120 line width.
1 parent 4dcd980 commit 517aa31

37 files changed

+1345
-1273
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ ruff = "~0.8.0"
6262
setuptools = "~75.6.0" # setuptools are used by pytest but not explicitly required
6363

6464
[tool.ruff]
65-
line-length = 150
65+
line-length = 120
6666

6767
[tool.ruff.lint]
6868
select = ["ALL"]

scripts/check_async_docstrings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
print(f'Missing docstring for "{async_class.name}.{async_method.name}"!')
4848
found_issues = True
4949
elif expected_docstring != async_docstring:
50-
print(f'Docstring for "{async_class.name}.{async_method.name}" is out of sync with "{sync_class.name}.{sync_method.name}"!')
50+
print(
51+
f'Docstring for "{async_class.name}.{async_method.name}" is out of sync with "{sync_class.name}.{sync_method.name}"!' # noqa: E501
52+
)
5153
found_issues = True
5254

5355
if found_issues:

scripts/fix_async_docstrings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
if async_docstring == correct_async_docstring:
4242
continue
4343

44-
# Work around a bug in Red Baron, which indents docstrings too much when you insert them, so we have to un-indent it one level first
44+
# Work around a bug in Red Baron, which indents docstrings too much when you insert them,
45+
# so we have to un-indent it one level first.
4546
correct_async_docstring = re.sub('^ ', '', correct_async_docstring, flags=re.MULTILINE)
4647

4748
if not isinstance(async_docstring, str):

src/apify_client/_errors.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ class ApifyClientError(Exception):
1111
class ApifyApiError(ApifyClientError):
1212
"""Error specific to requests to the Apify API.
1313
14-
An `ApifyApiError` is thrown for successful HTTP requests that reach the API,
15-
but the API responds with an error response. Typically, those are rate limit
16-
errors and internal errors, which are automatically retried, or validation
17-
errors, which are thrown immediately, because a correction by the user is needed.
14+
An `ApifyApiError` is thrown for successful HTTP requests that reach the API, but the API responds with
15+
an error response. Typically, those are rate limit errors and internal errors, which are automatically retried,
16+
or validation errors, which are thrown immediately, because a correction by the user is needed.
1817
"""
1918

2019
@ignore_docs
2120
def __init__(self, response: httpx.Response, attempt: int) -> None:
22-
"""Create the ApifyApiError instance.
21+
"""A default constructor.
2322
2423
Args:
25-
response (httpx.Response): The response to the failed API call
26-
attempt (int): Which attempt was the request that failed
24+
response: The response to the failed API call.
25+
attempt: Which attempt was the request that failed.
2726
"""
2827
self.message: str | None = None
2928
self.type: str | None = None
@@ -53,17 +52,17 @@ def __init__(self, response: httpx.Response, attempt: int) -> None:
5352
class InvalidResponseBodyError(ApifyClientError):
5453
"""Error caused by the response body failing to be parsed.
5554
56-
This error exists for the quite common situation, where only a partial JSON response is received and
57-
an attempt to parse the JSON throws an error. In most cases this can be resolved by retrying the
58-
request. We do that by identifying this error in the HTTPClient.
55+
This error exists for the quite common situation, where only a partial JSON response is received and an attempt
56+
to parse the JSON throws an error. In most cases this can be resolved by retrying the request. We do that by
57+
identifying this error in the HTTPClient.
5958
"""
6059

6160
@ignore_docs
6261
def __init__(self, response: httpx.Response) -> None:
63-
"""Create the InvalidResponseBodyError instance.
62+
"""A default constructor.
6463
6564
Args:
66-
response: The response which failed to be parsed
65+
response: The response which failed to be parsed.
6766
"""
6867
super().__init__('Response body could not be parsed')
6968

src/apify_client/_http_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ def _make_request(stop_retrying: Callable, attempt: int) -> httpx.Response:
170170
if response.status_code < 300: # noqa: PLR2004
171171
logger.debug('Request successful', extra={'status_code': response.status_code})
172172
if not stream:
173-
_maybe_parsed_body = self._maybe_parse_response(response) if parse_response else response.content
173+
_maybe_parsed_body = (
174+
self._maybe_parse_response(response) if parse_response else response.content
175+
)
174176
setattr(response, '_maybe_parsed_body', _maybe_parsed_body) # noqa: B010
175177

176178
return response
@@ -242,7 +244,9 @@ async def _make_request(stop_retrying: Callable, attempt: int) -> httpx.Response
242244
if response.status_code < 300: # noqa: PLR2004
243245
logger.debug('Request successful', extra={'status_code': response.status_code})
244246
if not stream:
245-
_maybe_parsed_body = self._maybe_parse_response(response) if parse_response else response.content
247+
_maybe_parsed_body = (
248+
self._maybe_parse_response(response) if parse_response else response.content
249+
)
246250
setattr(response, '_maybe_parsed_body', _maybe_parsed_body) # noqa: B010
247251

248252
return response

src/apify_client/client.py

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ def __init__(
6969
min_delay_between_retries_millis: int | None = 500,
7070
timeout_secs: int | None = 360,
7171
) -> None:
72-
"""Initialize the Apify API Client.
72+
"""A default constructor.
7373
7474
Args:
75-
token (str, optional): The Apify API token
76-
api_url (str, optional): The URL of the Apify API server to which to connect to. Defaults to https://api.apify.com
77-
max_retries (int, optional): How many times to retry a failed request at most
78-
min_delay_between_retries_millis (int, optional): How long will the client wait between retrying requests
79-
(increases exponentially from this value)
80-
timeout_secs (int, optional): The socket timeout of the HTTP requests sent to the Apify API
75+
token: The Apify API token.
76+
api_url: The URL of the Apify API server to which to connect to. Defaults to https://api.apify.com.
77+
max_retries: How many times to retry a failed request at most.
78+
min_delay_between_retries_millis: How long will the client wait between retrying requests
79+
(increases exponentially from this value).
80+
timeout_secs: The socket timeout of the HTTP requests sent to the Apify API.
8181
"""
8282
self.token = token
8383
api_url = (api_url or DEFAULT_API_URL).rstrip('/')
@@ -108,15 +108,15 @@ def __init__(
108108
min_delay_between_retries_millis: int | None = 500,
109109
timeout_secs: int | None = 360,
110110
) -> None:
111-
"""Initialize the ApifyClient.
111+
"""A default constructor.
112112
113113
Args:
114-
token (str, optional): The Apify API token
115-
api_url (str, optional): The URL of the Apify API server to which to connect to. Defaults to https://api.apify.com
116-
max_retries (int, optional): How many times to retry a failed request at most
117-
min_delay_between_retries_millis (int, optional): How long will the client wait between retrying requests
118-
(increases exponentially from this value)
119-
timeout_secs (int, optional): The socket timeout of the HTTP requests sent to the Apify API
114+
token: The Apify API token.
115+
api_url: The URL of the Apify API server to which to connect to. Defaults to https://api.apify.com.
116+
max_retries: How many times to retry a failed request at most.
117+
min_delay_between_retries_millis: How long will the client wait between retrying requests
118+
(increases exponentially from this value).
119+
timeout_secs: The socket timeout of the HTTP requests sent to the Apify API.
120120
"""
121121
super().__init__(
122122
token,
@@ -137,7 +137,7 @@ def actor(self, actor_id: str) -> ActorClient:
137137
"""Retrieve the sub-client for manipulating a single Actor.
138138
139139
Args:
140-
actor_id (str): ID of the Actor to be manipulated
140+
actor_id: ID of the Actor to be manipulated.
141141
"""
142142
return ActorClient(resource_id=actor_id, **self._options())
143143

@@ -149,7 +149,7 @@ def build(self, build_id: str) -> BuildClient:
149149
"""Retrieve the sub-client for manipulating a single Actor build.
150150
151151
Args:
152-
build_id (str): ID of the Actor build to be manipulated
152+
build_id: ID of the Actor build to be manipulated.
153153
"""
154154
return BuildClient(resource_id=build_id, **self._options())
155155

@@ -161,7 +161,7 @@ def run(self, run_id: str) -> RunClient:
161161
"""Retrieve the sub-client for manipulating a single Actor run.
162162
163163
Args:
164-
run_id (str): ID of the Actor run to be manipulated
164+
run_id: ID of the Actor run to be manipulated.
165165
"""
166166
return RunClient(resource_id=run_id, **self._options())
167167

@@ -173,7 +173,7 @@ def dataset(self, dataset_id: str) -> DatasetClient:
173173
"""Retrieve the sub-client for manipulating a single dataset.
174174
175175
Args:
176-
dataset_id (str): ID of the dataset to be manipulated
176+
dataset_id: ID of the dataset to be manipulated.
177177
"""
178178
return DatasetClient(resource_id=dataset_id, **self._options())
179179

@@ -185,7 +185,7 @@ def key_value_store(self, key_value_store_id: str) -> KeyValueStoreClient:
185185
"""Retrieve the sub-client for manipulating a single key-value store.
186186
187187
Args:
188-
key_value_store_id (str): ID of the key-value store to be manipulated
188+
key_value_store_id: ID of the key-value store to be manipulated.
189189
"""
190190
return KeyValueStoreClient(resource_id=key_value_store_id, **self._options())
191191

@@ -197,8 +197,8 @@ def request_queue(self, request_queue_id: str, *, client_key: str | None = None)
197197
"""Retrieve the sub-client for manipulating a single request queue.
198198
199199
Args:
200-
request_queue_id (str): ID of the request queue to be manipulated
201-
client_key (str): A unique identifier of the client accessing the request queue
200+
request_queue_id: ID of the request queue to be manipulated.
201+
client_key: A unique identifier of the client accessing the request queue.
202202
"""
203203
return RequestQueueClient(resource_id=request_queue_id, client_key=client_key, **self._options())
204204

@@ -210,7 +210,7 @@ def webhook(self, webhook_id: str) -> WebhookClient:
210210
"""Retrieve the sub-client for manipulating a single webhook.
211211
212212
Args:
213-
webhook_id (str): ID of the webhook to be manipulated
213+
webhook_id: ID of the webhook to be manipulated.
214214
"""
215215
return WebhookClient(resource_id=webhook_id, **self._options())
216216

@@ -222,7 +222,7 @@ def webhook_dispatch(self, webhook_dispatch_id: str) -> WebhookDispatchClient:
222222
"""Retrieve the sub-client for accessing a single webhook dispatch.
223223
224224
Args:
225-
webhook_dispatch_id (str): ID of the webhook dispatch to access
225+
webhook_dispatch_id: ID of the webhook dispatch to access.
226226
"""
227227
return WebhookDispatchClient(resource_id=webhook_dispatch_id, **self._options())
228228

@@ -234,7 +234,7 @@ def schedule(self, schedule_id: str) -> ScheduleClient:
234234
"""Retrieve the sub-client for manipulating a single schedule.
235235
236236
Args:
237-
schedule_id (str): ID of the schedule to be manipulated
237+
schedule_id: ID of the schedule to be manipulated.
238238
"""
239239
return ScheduleClient(resource_id=schedule_id, **self._options())
240240

@@ -246,15 +246,15 @@ def log(self, build_or_run_id: str) -> LogClient:
246246
"""Retrieve the sub-client for retrieving logs.
247247
248248
Args:
249-
build_or_run_id (str): ID of the Actor build or run for which to access the log
249+
build_or_run_id: ID of the Actor build or run for which to access the log.
250250
"""
251251
return LogClient(resource_id=build_or_run_id, **self._options())
252252

253253
def task(self, task_id: str) -> TaskClient:
254254
"""Retrieve the sub-client for manipulating a single task.
255255
256256
Args:
257-
task_id (str): ID of the task to be manipulated
257+
task_id: ID of the task to be manipulated.
258258
"""
259259
return TaskClient(resource_id=task_id, **self._options())
260260

@@ -266,7 +266,7 @@ def user(self, user_id: str | None = None) -> UserClient:
266266
"""Retrieve the sub-client for querying users.
267267
268268
Args:
269-
user_id (str, optional): ID of user to be queried. If None, queries the user belonging to the token supplied to the client
269+
user_id: ID of user to be queried. If None, queries the user belonging to the token supplied to the client.
270270
"""
271271
return UserClient(resource_id=user_id, **self._options())
272272

@@ -289,15 +289,15 @@ def __init__(
289289
min_delay_between_retries_millis: int | None = 500,
290290
timeout_secs: int | None = 360,
291291
) -> None:
292-
"""Initialize the ApifyClientAsync.
292+
"""A default constructor.
293293
294294
Args:
295-
token (str, optional): The Apify API token
296-
api_url (str, optional): The URL of the Apify API server to which to connect to. Defaults to https://api.apify.com
297-
max_retries (int, optional): How many times to retry a failed request at most
298-
min_delay_between_retries_millis (int, optional): How long will the client wait between retrying requests
299-
(increases exponentially from this value)
300-
timeout_secs (int, optional): The socket timeout of the HTTP requests sent to the Apify API
295+
token: The Apify API token.
296+
api_url: The URL of the Apify API server to which to connect to. Defaults to https://api.apify.com.
297+
max_retries: How many times to retry a failed request at most.
298+
min_delay_between_retries_millis: How long will the client wait between retrying requests
299+
(increases exponentially from this value).
300+
timeout_secs: The socket timeout of the HTTP requests sent to the Apify API.
301301
"""
302302
super().__init__(
303303
token,
@@ -318,7 +318,7 @@ def actor(self, actor_id: str) -> ActorClientAsync:
318318
"""Retrieve the sub-client for manipulating a single Actor.
319319
320320
Args:
321-
actor_id (str): ID of the Actor to be manipulated
321+
actor_id: ID of the Actor to be manipulated.
322322
"""
323323
return ActorClientAsync(resource_id=actor_id, **self._options())
324324

@@ -330,7 +330,7 @@ def build(self, build_id: str) -> BuildClientAsync:
330330
"""Retrieve the sub-client for manipulating a single Actor build.
331331
332332
Args:
333-
build_id (str): ID of the Actor build to be manipulated
333+
build_id: ID of the Actor build to be manipulated.
334334
"""
335335
return BuildClientAsync(resource_id=build_id, **self._options())
336336

@@ -342,7 +342,7 @@ def run(self, run_id: str) -> RunClientAsync:
342342
"""Retrieve the sub-client for manipulating a single Actor run.
343343
344344
Args:
345-
run_id (str): ID of the Actor run to be manipulated
345+
run_id: ID of the Actor run to be manipulated.
346346
"""
347347
return RunClientAsync(resource_id=run_id, **self._options())
348348

@@ -354,7 +354,7 @@ def dataset(self, dataset_id: str) -> DatasetClientAsync:
354354
"""Retrieve the sub-client for manipulating a single dataset.
355355
356356
Args:
357-
dataset_id (str): ID of the dataset to be manipulated
357+
dataset_id: ID of the dataset to be manipulated.
358358
"""
359359
return DatasetClientAsync(resource_id=dataset_id, **self._options())
360360

@@ -366,7 +366,7 @@ def key_value_store(self, key_value_store_id: str) -> KeyValueStoreClientAsync:
366366
"""Retrieve the sub-client for manipulating a single key-value store.
367367
368368
Args:
369-
key_value_store_id (str): ID of the key-value store to be manipulated
369+
key_value_store_id: ID of the key-value store to be manipulated.
370370
"""
371371
return KeyValueStoreClientAsync(resource_id=key_value_store_id, **self._options())
372372

@@ -378,8 +378,8 @@ def request_queue(self, request_queue_id: str, *, client_key: str | None = None)
378378
"""Retrieve the sub-client for manipulating a single request queue.
379379
380380
Args:
381-
request_queue_id (str): ID of the request queue to be manipulated
382-
client_key (str): A unique identifier of the client accessing the request queue
381+
request_queue_id: ID of the request queue to be manipulated.
382+
client_key: A unique identifier of the client accessing the request queue.
383383
"""
384384
return RequestQueueClientAsync(resource_id=request_queue_id, client_key=client_key, **self._options())
385385

@@ -391,7 +391,7 @@ def webhook(self, webhook_id: str) -> WebhookClientAsync:
391391
"""Retrieve the sub-client for manipulating a single webhook.
392392
393393
Args:
394-
webhook_id (str): ID of the webhook to be manipulated
394+
webhook_id: ID of the webhook to be manipulated.
395395
"""
396396
return WebhookClientAsync(resource_id=webhook_id, **self._options())
397397

@@ -403,7 +403,7 @@ def webhook_dispatch(self, webhook_dispatch_id: str) -> WebhookDispatchClientAsy
403403
"""Retrieve the sub-client for accessing a single webhook dispatch.
404404
405405
Args:
406-
webhook_dispatch_id (str): ID of the webhook dispatch to access
406+
webhook_dispatch_id: ID of the webhook dispatch to access.
407407
"""
408408
return WebhookDispatchClientAsync(resource_id=webhook_dispatch_id, **self._options())
409409

@@ -415,7 +415,7 @@ def schedule(self, schedule_id: str) -> ScheduleClientAsync:
415415
"""Retrieve the sub-client for manipulating a single schedule.
416416
417417
Args:
418-
schedule_id (str): ID of the schedule to be manipulated
418+
schedule_id: ID of the schedule to be manipulated.
419419
"""
420420
return ScheduleClientAsync(resource_id=schedule_id, **self._options())
421421

@@ -427,15 +427,15 @@ def log(self, build_or_run_id: str) -> LogClientAsync:
427427
"""Retrieve the sub-client for retrieving logs.
428428
429429
Args:
430-
build_or_run_id (str): ID of the Actor build or run for which to access the log
430+
build_or_run_id: ID of the Actor build or run for which to access the log.
431431
"""
432432
return LogClientAsync(resource_id=build_or_run_id, **self._options())
433433

434434
def task(self, task_id: str) -> TaskClientAsync:
435435
"""Retrieve the sub-client for manipulating a single task.
436436
437437
Args:
438-
task_id (str): ID of the task to be manipulated
438+
task_id: ID of the task to be manipulated.
439439
"""
440440
return TaskClientAsync(resource_id=task_id, **self._options())
441441

@@ -447,7 +447,7 @@ def user(self, user_id: str | None = None) -> UserClientAsync:
447447
"""Retrieve the sub-client for querying users.
448448
449449
Args:
450-
user_id (str, optional): ID of user to be queried. If None, queries the user belonging to the token supplied to the client
450+
user_id: ID of user to be queried. If None, queries the user belonging to the token supplied to the client.
451451
"""
452452
return UserClientAsync(resource_id=user_id, **self._options())
453453

0 commit comments

Comments
 (0)