Skip to content

Add missing -> bool return type hints in utils/imports.py - #4123

Open
RudrenduPaul wants to merge 1 commit into
huggingface:mainfrom
RudrenduPaul:add-return-type-hints-imports
Open

Add missing -> bool return type hints in utils/imports.py#4123
RudrenduPaul wants to merge 1 commit into
huggingface:mainfrom
RudrenduPaul:add-return-type-hints-imports

Conversation

@RudrenduPaul

Copy link
Copy Markdown

What this PR does

Adds -> bool return type hints to nine is_*_available device/feature-check
helper functions in src/accelerate/utils/imports.py, matching the existing
precedent set by is_torch_distributed_available() -> bool in the same file.

This is a self-identified typing-consistency fix (no linked issue) — the file
already establishes the -> bool convention for one helper but several
sibling functions with identical return semantics were left unannotated.

Functions updated

  • is_torch_xla_available
  • is_bf16_available
  • is_mps_available
  • is_mlu_available
  • is_musa_available
  • is_npu_available
  • is_sdaa_available
  • is_hpu_available
  • is_xpu_available

Each of these functions returns only bool values on every code path
(verified by reading the full function body of each before annotating).

Scope note: torchao_required / deepspeed_required intentionally excluded

Both are decorator factories that take a func argument and return a
wrapper callable (via functools.wraps) — they never return bool.
Adding -> bool to them would be a factually incorrect type hint, so they
were left unannotated in this PR rather than introduce an inaccurate
signature. Happy to follow up with a correct Callable-based annotation
for those two in a separate PR if maintainers want it.

No behaviour change

Type-hint-only change. No logic was modified.

Testing

  • ruff check src/accelerate/utils/imports.py — 6 pre-existing findings,
    none on changed lines, none introduced by this change (verified against
    upstream main before/after).
  • ruff format --check src/accelerate/utils/imports.py — passes, file
    already formatted.
  • python3 -m py_compile on the modified file — passes.

Note: Claude Code was used to assist in drafting this change. All
changes were reviewed by the submitter.

Adds -> bool to is_torch_xla_available, is_bf16_available, is_mps_available,
is_mlu_available, is_musa_available, is_npu_available, is_sdaa_available,
is_hpu_available, and is_xpu_available, matching the existing precedent set
by is_torch_distributed_available() -> bool.
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