Summary
Three layers probe the same "is the Rust extension available?" question, and
they can disagree:
cuprum/_rust_backend.py:8-30 — is_available(), uncached
(importlib.import_module on every call).
cuprum/rust.py:8-23 — is_rust_available(), a thin pass-through.
cuprum/_backend.py:71-89 — _check_rust_available(), lru_cached and
honouring the _RUST_AVAILABILITY_FOR_TESTING override.
Problem
The cached, override-aware _check_rust_available() is what actually governs
dispatch, but the public is_rust_available() bypasses both the cache and the
test override. A caller using the documented public API can therefore observe a
different availability than the dispatcher uses — a real inconsistency in how the
optional extension's absence is handled.
Proposed resolution
- Route the public
is_rust_available() (and the consumers of
_rust_backend.is_available()) through the same cached / override-aware
resolver used by dispatch, so there is one source of truth.
- If an uncached probe is deliberately retained, document explicitly in
rust.py that it does not honour the backend cache or the test override.
Verification
- Unit test asserting the public probe and the dispatch probe agree, including
under the test override.
make check-fmt lint test green.
References
- Cuprum refactoring audit — consistency / three divergent availability probes.
Summary
Three layers probe the same "is the Rust extension available?" question, and
they can disagree:
cuprum/_rust_backend.py:8-30—is_available(), uncached(
importlib.import_moduleon every call).cuprum/rust.py:8-23—is_rust_available(), a thin pass-through.cuprum/_backend.py:71-89—_check_rust_available(),lru_cached andhonouring the
_RUST_AVAILABILITY_FOR_TESTINGoverride.Problem
The cached, override-aware
_check_rust_available()is what actually governsdispatch, but the public
is_rust_available()bypasses both the cache and thetest override. A caller using the documented public API can therefore observe a
different availability than the dispatcher uses — a real inconsistency in how the
optional extension's absence is handled.
Proposed resolution
is_rust_available()(and the consumers of_rust_backend.is_available()) through the same cached / override-awareresolver used by dispatch, so there is one source of truth.
rust.pythat it does not honour the backend cache or the test override.Verification
under the test override.
make check-fmt lint testgreen.References