Skip to content

Minor clean up / bikeshedding - #406

Open
alessio-locatelli wants to merge 9 commits into
requests-cache:mainfrom
alessio-locatelli:rename_functions
Open

Minor clean up / bikeshedding#406
alessio-locatelli wants to merge 9 commits into
requests-cache:mainfrom
alessio-locatelli:rename_functions

Conversation

@alessio-locatelli

Copy link
Copy Markdown
Collaborator

The changes are behavior-preserving refactors or cleanup, so no changelog entry is needed.

The function sets up a mock aiohttp test application, performs a GET
request through a test client, and wraps the result in a
`CachedResponse`. The name reflects the primary action (fetching over
HTTP) and the return type, while leaving the mock infrastructure as an
implementation detail.

Alternatives considered:
- `get_cached_response` — easily confused with HTTP GET
- `make_cached_response` — downplays the network round-trip
- `mock_request_cached_response` — accurate but overly verbose
The function is a test factory that returns a `MagicMock` with
`spec=CachedResponse` and sensible defaults (`status=200`, `is_expired=False`,
etc.). The name follows Python testing conventions (`make_*` for lightweight
test factories) and clearly describes both the action and the return type.

Alternatives considered:
- `mock_cached_response` — reads like a fixture, not a callable
- `create_mock_cached_response` — implies heavier construction than exists here
- `build_cached_response_mock` — overly verbose and awkward word order
The function extracts parameter definitions from multiple input Callables,
deduplicates overlapping kwargs, and returns a unified forged signature.
The name reflects the core operation (merging multiple signatures) and
the return type.

Alternatives considered:
- `combine_signatures` — equally valid, but `merge` is more idiomatic for unifying collections
- `compose_signatures` — implies functional composition, which doesn't apply here
- `collect_signature_params` — too narrow; returns a full signature, not just a dict
The inner async function connects to a Redis instance, calls `info()`
to confirm the server is reachable, then closes the connection. The
name uses `probe` to convey a lightweight connectivity check.

Alternatives considered:
- `_ping_redis` — common idiom but technically inaccurate; calls `info()`, not `PING`
- `_check_redis_connection` — descriptive but overly long for a nested closure
- `_redis_info` — sounds like a getter, not a connectivity probe
- `_connect_and_verify` — generic; doesn't name the target service
The code adds a name that does not improve the reader's understanding.
That is usually a poor tradeoff: it adds a statement, a local variable,
and a name that the reader must mentally associate with statement.
Do not introduce a local variable solely to satisfy a line-length limit.
The argument is already `str`.
@alessio-locatelli

alessio-locatelli commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

FYI: The first CI attempt failed with RuntimeError: <asyncio.locks.Lock object at 0x7fd061728d70 [locked]> is bound to a different event loop (https://github.com/requests-cache/aiohttp-client-cache/actions/runs/30759231448/job/91526679033), but pass on re-run. Please let me know is that error worth investigating, documenting as a known bug, or auto-retrying in the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant