Skip to content

Commit 17f504b

Browse files
vdusekclaude
andcommitted
Rename with_custom_client to with_custom_http_client
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e34ee03 commit 17f504b

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

scripts/check_async_docstrings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Methods where the async docstring is intentionally different from the sync one
1515
# (e.g. because they accept different parameter types).
1616
SKIPPED_METHODS = {
17-
'with_custom_client',
17+
'with_custom_http_client',
1818
}
1919

2020
# Get the directory of the source files

scripts/fix_async_docstrings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Methods where the async docstring is intentionally different from the sync one
1010
# (e.g. because they accept different parameter types).
1111
SKIPPED_METHODS = {
12-
'with_custom_client',
12+
'with_custom_http_client',
1313
}
1414

1515
# Get the directory of the source files

src/apify_client/_apify_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def __init__(
119119
) -> None:
120120
"""Initialize the Apify API client.
121121
122-
To use a custom HTTP client, use the `with_custom_client` class method instead.
122+
To use a custom HTTP client, use the `with_custom_http_client` class method instead.
123123
124124
Args:
125125
token: The Apify API token. You can find your token on the
@@ -195,7 +195,7 @@ def __init__(
195195
self._headers = headers
196196

197197
@classmethod
198-
def with_custom_client(
198+
def with_custom_http_client(
199199
cls,
200200
token: str | None = None,
201201
*,
@@ -218,7 +218,7 @@ class MyHttpClient(HttpClient):
218218
def call(self, *, method, url, **kwargs) -> HttpResponse:
219219
...
220220
221-
client = ApifyClient.with_custom_client(
221+
client = ApifyClient.with_custom_http_client(
222222
token='MY-APIFY-TOKEN',
223223
http_client=MyHttpClient(),
224224
)
@@ -243,7 +243,7 @@ def token(self) -> str | None:
243243
def http_client(self) -> HttpClient:
244244
"""The HTTP client instance used for API communication.
245245
246-
Returns the custom HTTP client if one was provided via `with_custom_client`,
246+
Returns the custom HTTP client if one was provided via `with_custom_http_client`,
247247
or the default `ImpitHttpClient` otherwise (lazily created on first access).
248248
"""
249249
if self._http_client is None:
@@ -460,7 +460,7 @@ def __init__(
460460
) -> None:
461461
"""Initialize the Apify API client.
462462
463-
To use a custom HTTP client, use the `with_custom_client` class method instead.
463+
To use a custom HTTP client, use the `with_custom_http_client` class method instead.
464464
465465
Args:
466466
token: The Apify API token. You can find your token on the
@@ -536,7 +536,7 @@ def __init__(
536536
self._headers = headers
537537

538538
@classmethod
539-
def with_custom_client(
539+
def with_custom_http_client(
540540
cls,
541541
token: str | None = None,
542542
*,
@@ -559,7 +559,7 @@ class MyHttpClient(HttpClientAsync):
559559
async def call(self, *, method, url, **kwargs) -> HttpResponse:
560560
...
561561
562-
client = ApifyClientAsync.with_custom_client(
562+
client = ApifyClientAsync.with_custom_http_client(
563563
token='MY-APIFY-TOKEN',
564564
http_client=MyHttpClient(),
565565
)
@@ -584,7 +584,7 @@ def token(self) -> str | None:
584584
def http_client(self) -> HttpClientAsync:
585585
"""The HTTP client instance used for API communication.
586586
587-
Returns the custom HTTP client if one was provided via `with_custom_client`,
587+
Returns the custom HTTP client if one was provided via `with_custom_http_client`,
588588
or the default `ImpitHttpClientAsync` otherwise (lazily created on first access).
589589
"""
590590
if self._http_client is None:

tests/unit/test_pluggable_http_client.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ def test_http_client_async_abc_not_instantiable() -> None:
194194
# -- ApifyClient with custom http_client via classmethod --
195195

196196

197-
def test_apify_client_with_custom_client() -> None:
198-
"""Test that ApifyClient.with_custom_client accepts a custom http_client."""
197+
def test_apify_client_with_custom_http_client() -> None:
198+
"""Test that ApifyClient.with_custom_http_client accepts a custom http_client."""
199199
fake_client = FakeHttpClient()
200-
client = ApifyClient.with_custom_client(token='test_token', http_client=fake_client)
200+
client = ApifyClient.with_custom_http_client(token='test_token', http_client=fake_client)
201201

202202
assert client.http_client is fake_client
203203

@@ -212,7 +212,7 @@ def test_apify_client_uses_default_http_client_when_none_provided() -> None:
212212
def test_apify_client_custom_http_client_receives_requests() -> None:
213213
"""Test that requests flow through the custom HTTP client."""
214214
fake_client = FakeHttpClient()
215-
client = ApifyClient.with_custom_client(token='test_token', http_client=fake_client)
215+
client = ApifyClient.with_custom_http_client(token='test_token', http_client=fake_client)
216216

217217
# Use _get() via the dataset client to avoid Pydantic model validation
218218
# (actor.get() would try to validate against ActorResponse model)
@@ -225,10 +225,10 @@ def test_apify_client_custom_http_client_receives_requests() -> None:
225225
assert result == {'data': {'id': 'test123'}}
226226

227227

228-
def test_apify_client_with_custom_client_accepts_url_params() -> None:
229-
"""Test that with_custom_client can be combined with token, api_url, and api_public_url."""
228+
def test_apify_client_with_custom_http_client_accepts_url_params() -> None:
229+
"""Test that with_custom_http_client can be combined with token, api_url, and api_public_url."""
230230
fake_client = FakeHttpClient()
231-
client = ApifyClient.with_custom_client(
231+
client = ApifyClient.with_custom_http_client(
232232
token='test_token',
233233
api_url='https://custom.api.example.com',
234234
api_public_url='https://public.api.example.com',
@@ -240,10 +240,10 @@ def test_apify_client_with_custom_client_accepts_url_params() -> None:
240240
# -- ApifyClientAsync with custom http_client via classmethod --
241241

242242

243-
async def test_apify_client_async_with_custom_client() -> None:
244-
"""Test that ApifyClientAsync.with_custom_client accepts a custom http_client."""
243+
async def test_apify_client_async_with_custom_http_client() -> None:
244+
"""Test that ApifyClientAsync.with_custom_http_client accepts a custom http_client."""
245245
fake_client = FakeHttpClientAsync()
246-
client = ApifyClientAsync.with_custom_client(token='test_token', http_client=fake_client)
246+
client = ApifyClientAsync.with_custom_http_client(token='test_token', http_client=fake_client)
247247

248248
assert client.http_client is fake_client
249249

@@ -258,7 +258,7 @@ async def test_apify_client_async_uses_default_http_client_when_none_provided()
258258
async def test_apify_client_async_custom_http_client_receives_requests() -> None:
259259
"""Test that async requests flow through the custom HTTP client."""
260260
fake_client = FakeHttpClientAsync()
261-
client = ApifyClientAsync.with_custom_client(token='test_token', http_client=fake_client)
261+
client = ApifyClientAsync.with_custom_http_client(token='test_token', http_client=fake_client)
262262

263263
# Use _get() via the dataset client to avoid Pydantic model validation
264264
result = await client.dataset('test-dataset')._get()
@@ -270,10 +270,10 @@ async def test_apify_client_async_custom_http_client_receives_requests() -> None
270270
assert result == {'data': {'id': 'test123'}}
271271

272272

273-
async def test_apify_client_async_with_custom_client_accepts_url_params() -> None:
274-
"""Test that async with_custom_client can be combined with token, api_url, and api_public_url."""
273+
async def test_apify_client_async_with_custom_http_client_accepts_url_params() -> None:
274+
"""Test that async with_custom_http_client can be combined with token, api_url, and api_public_url."""
275275
fake_client = FakeHttpClientAsync()
276-
client = ApifyClientAsync.with_custom_client(
276+
client = ApifyClientAsync.with_custom_http_client(
277277
token='test_token',
278278
api_url='https://custom.api.example.com',
279279
api_public_url='https://public.api.example.com',
@@ -305,7 +305,7 @@ def test_apify_client_http_client_property_returns_correct_type() -> None:
305305

306306
# With custom
307307
fake = FakeHttpClient()
308-
client2 = ApifyClient.with_custom_client(token='test', http_client=fake)
308+
client2 = ApifyClient.with_custom_http_client(token='test', http_client=fake)
309309
assert client2.http_client is fake
310310

311311

@@ -317,7 +317,7 @@ async def test_apify_client_async_http_client_property_returns_correct_type() ->
317317

318318
# With custom
319319
fake = FakeHttpClientAsync()
320-
client2 = ApifyClientAsync.with_custom_client(token='test', http_client=fake)
320+
client2 = ApifyClientAsync.with_custom_http_client(token='test', http_client=fake)
321321
assert client2.http_client is fake
322322

323323

@@ -339,7 +339,7 @@ def call(self, *, method: str, **_kwargs: Any) -> FakeResponse:
339339
def test_custom_http_client_error_handling() -> None:
340340
"""Test that ApifyApiError from custom client is handled correctly by resource clients."""
341341
error_client = ErrorRaisingHttpClient()
342-
client = ApifyClient.with_custom_client(token='test', http_client=error_client)
342+
client = ApifyClient.with_custom_http_client(token='test', http_client=error_client)
343343

344344
# _get() should catch 404 record-not-found and return None
345345
result = client.actor('nonexistent').get()
@@ -361,7 +361,7 @@ async def call(self, *, method: str, **_kwargs: Any) -> FakeResponse:
361361
async def test_custom_http_client_async_error_handling() -> None:
362362
"""Test that ApifyApiError from async custom client is handled correctly by resource clients."""
363363
error_client = ErrorRaisingHttpClientAsync()
364-
client = ApifyClientAsync.with_custom_client(token='test', http_client=error_client)
364+
client = ApifyClientAsync.with_custom_http_client(token='test', http_client=error_client)
365365

366366
# _get() should catch 404 record-not-found and return None
367367
result = await client.actor('nonexistent').get()
@@ -388,7 +388,7 @@ def call(self, *, method: str, url: str, **kwargs: Any) -> HttpResponse:
388388
return inner_client.call(method=method, url=url, **kwargs)
389389

390390
api_url = httpserver.url_for('/').removesuffix('/')
391-
client = ApifyClient.with_custom_client(token='test_token', api_url=api_url, http_client=WrappingHttpClient())
391+
client = ApifyClient.with_custom_http_client(token='test_token', api_url=api_url, http_client=WrappingHttpClient())
392392

393393
# Use _get() to test the raw request flow without Pydantic validation
394394
result = client.dataset('test-dataset')._get()
@@ -414,7 +414,7 @@ async def call(self, *, method: str, url: str, **kwargs: Any) -> HttpResponse:
414414
return await inner_client.call(method=method, url=url, **kwargs)
415415

416416
api_url = httpserver.url_for('/').removesuffix('/')
417-
client = ApifyClientAsync.with_custom_client(
417+
client = ApifyClientAsync.with_custom_http_client(
418418
token='test_token', api_url=api_url, http_client=WrappingHttpClientAsync()
419419
)
420420

0 commit comments

Comments
 (0)