Skip to content

Fix docs CI: remove redundant quotes from GradScaler annotations after adding from __future__ import annotations#3586

Closed
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-ci-job-failure
Closed

Fix docs CI: remove redundant quotes from GradScaler annotations after adding from __future__ import annotations#3586
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-ci-job-failure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 24, 2026

PR #3576 introduced from __future__ import annotations but left torch.amp.GradScaler in explicit forward-reference quotes (e.g., "torch.amp.GradScaler" | None). With PEP 563, all annotations are stored as raw strings, so the quoted form becomes the literal string '"torch.amp.GradScaler" | None'. Sphinx's get_type_hints() then tries to eval that expression and hits a TypeError (str | NoneType is not a valid union), producing 2 warnings that are treated as errors in CI.

Changes

  • ignite/engine/__init__.py

    • Add from __future__ import annotations
    • Move Sequence import to collections.abc; drop Dict, Optional, Tuple, Union from typing
    • Replace all legacy typing annotations with modern X | Y, X | None, dict[...], tuple[...] syntax
    • Remove quotes from torch.amp.GradScaler in annotations — redundant (and harmful) once from __future__ import annotations is present
  • docs/source/conf.py

    • Add ("py:class", "torch.amp.GradScaler") to nitpick_ignore so Sphinx silences the unresolvable cross-reference rather than erroring
# Before (broken with PEP 563)
scaler: "torch.amp.GradScaler" | None = None  # stored as '"torch.amp.GradScaler" | None' → eval fails

# After
scaler: torch.amp.GradScaler | None = None    # stored as 'torch.amp.GradScaler | None' → resolves correctly

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Root cause: from __future__ import annotations was added but quoted
"torch.amp.GradScaler" annotations remained. This caused Sphinx's
get_type_hints() to fail when evaluating '"torch.amp.GradScaler" | None'
(TypeError: unsupported operand for |: str and NoneType).

Fix: remove quotes from torch.amp.GradScaler annotations (safe since
from __future__ import annotations handles forward references), and add
torch.amp.GradScaler to nitpick_ignore in docs/source/conf.py.

Co-authored-by: vfdev-5 <[email protected]>
Copilot AI changed the title [WIP] Investigate and fix CI job failure Fix docs CI: remove redundant quotes from GradScaler annotations after adding from __future__ import annotations Feb 24, 2026
Copilot AI requested a review from vfdev-5 February 24, 2026 22:40
@github-actions github-actions bot added docs module: engine Engine module labels Feb 24, 2026
@vfdev-5 vfdev-5 closed this Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants