Skip to content

Commit c0f62ed

Browse files
committed
style: Drop underscore prefix from test helpers and tighten comments
1 parent 4f1e9ff commit c0f62ed

4 files changed

Lines changed: 9 additions & 12 deletions

File tree

src/apify_client/_resource_clients/key_value_store.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,7 @@ async def set_record(
802802
content_type: The content type of the saved value.
803803
timeout: Timeout for the API HTTP request.
804804
"""
805-
# Encoding reads file-like values and may serialize large payloads, which is blocking; offload it to a
806-
# worker thread so it does not stall the event loop (mirrors the transport's own body-prep offload).
805+
# Encoding may read a file or serialize a large payload (blocking), so run it off the event loop.
807806
value, content_type = await asyncio.to_thread(
808807
encode_key_value_store_record_value, value, content_type=content_type
809808
)

src/apify_client/_utils/encoding.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ def encode_key_value_store_record_value(value: Any, *, content_type: str | None
2121
Returns:
2222
A tuple of (encoded_value, content_type).
2323
"""
24-
# Read file-like values into memory; the underlying HTTP transport only accepts bytes-like bodies,
25-
# so a file object would otherwise reach it unread and raise a raw `TypeError`. Detect them by a
26-
# callable `read` rather than `io.IOBase` so duck-typed file-likes (upload wrappers, raw streams)
27-
# are read too, instead of falling through to JSON serialization.
24+
# Read file-like values into memory; the transport only accepts bytes-like bodies. Detect them by a
25+
# callable `read` (not `io.IOBase`) so duck-typed file-likes are read, not JSON-serialized.
2826
read = getattr(value, 'read', None)
2927
if callable(read):
3028
value = read()

tests/unit/test_key_value_store.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
_RECORD_PATH = f'/v2/key-value-stores/{_MOCKED_KVS_ID}/records/f'
1616

1717

18-
def _decode_body(request: Request) -> bytes:
18+
def decode_body(request: Request) -> bytes:
1919
raw = request.get_data()
2020
return gzip.decompress(raw) if request.headers.get('Content-Encoding') == 'gzip' else raw
2121

@@ -36,7 +36,7 @@ def capture_request(request: Request) -> Response:
3636
client.key_value_store(_MOCKED_KVS_ID).set_record('f', io.BytesIO(b'buffer data'))
3737

3838
assert len(captured_requests) == 1
39-
assert _decode_body(captured_requests[0]) == b'buffer data'
39+
assert decode_body(captured_requests[0]) == b'buffer data'
4040
assert captured_requests[0].headers['content-type'] == 'application/octet-stream'
4141

4242

@@ -56,7 +56,7 @@ def capture_request(request: Request) -> Response:
5656
await client.key_value_store(_MOCKED_KVS_ID).set_record('f', io.BytesIO(b'buffer data'))
5757

5858
assert len(captured_requests) == 1
59-
assert _decode_body(captured_requests[0]) == b'buffer data'
59+
assert decode_body(captured_requests[0]) == b'buffer data'
6060
assert captured_requests[0].headers['content-type'] == 'application/octet-stream'
6161

6262

@@ -76,5 +76,5 @@ def capture_request(request: Request) -> Response:
7676
client.key_value_store(_MOCKED_KVS_ID).set_record('f', io.StringIO('buffer data'))
7777

7878
assert len(captured_requests) == 1
79-
assert _decode_body(captured_requests[0]) == b'buffer data'
79+
assert decode_body(captured_requests[0]) == b'buffer data'
8080
assert captured_requests[0].headers['content-type'] == 'text/plain; charset=utf-8'

tests/unit/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ def test_encode_key_value_store_record_value_stringio() -> None:
267267
def test_encode_key_value_store_record_value_duck_typed_file_like() -> None:
268268
"""Test that a duck-typed file-like value (a callable `read`, not an `io.IOBase`) is read into bytes."""
269269

270-
class _Reader:
270+
class Reader:
271271
def read(self) -> bytes:
272272
return b'buffer data'
273273

274-
value, content_type = encode_key_value_store_record_value(_Reader())
274+
value, content_type = encode_key_value_store_record_value(Reader())
275275
assert value == b'buffer data'
276276
assert content_type == 'application/octet-stream'
277277

0 commit comments

Comments
 (0)