Skip to content

Refactor: unify the three divergent Rust-availability probes behind one resolver #128

Description

@lodyai

Summary

Three layers probe the same "is the Rust extension available?" question, and
they can disagree:

  • cuprum/_rust_backend.py:8-30is_available(), uncached
    (importlib.import_module on every call).
  • cuprum/rust.py:8-23is_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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions