Skip to content

Update loss.py type hints to Python 3.10+ syntax#3501

Merged
vfdev-5 merged 3 commits intomasterfrom
copilot/update-typing-hints-in-metrics
Jan 27, 2026
Merged

Update loss.py type hints to Python 3.10+ syntax#3501
vfdev-5 merged 3 commits intomasterfrom
copilot/update-typing-hints-in-metrics

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 27, 2026

Modernize type hints in ignite/metrics/loss.py to use PEP 604 union syntax and built-in generics, aligning with Python 3.10+ (now minimum supported version).

Changes

  • Union[str, torch.device]str | torch.device
  • Tuple[...]tuple[...]
  • Dictdict
  • Improved update() signature from Sequence[Union[torch.Tensor, Dict]] to tuple[torch.Tensor, torch.Tensor] | tuple[torch.Tensor, torch.Tensor, dict] for better type safety
  • Removed obsolete typing imports
# Before
def update(self, output: Sequence[Union[torch.Tensor, Dict]]) -> None:
    if len(output) == 2:
        y_pred, y = cast(Tuple[torch.Tensor, torch.Tensor], output)
        kwargs: Dict = {}

# After  
def update(self, output: tuple[torch.Tensor, torch.Tensor] | tuple[torch.Tensor, torch.Tensor, dict]) -> None:
    if len(output) == 2:
        y_pred, y = cast(tuple[torch.Tensor, torch.Tensor], output)
        kwargs: dict = {}

Part of ongoing effort to modernize typing across the codebase.

Original prompt

Work on this issue: #3481
Pick a python file from ignite/metrics with old typing hints and replace them with the new typing hints. Send a PR with a single changed file


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

Copilot AI changed the title [WIP] Update typing hints in ignite metrics Update loss.py type hints to Python 3.10+ syntax Jan 27, 2026
Copilot AI requested a review from vfdev-5 January 27, 2026 16:15
@github-actions github-actions bot added the module: metrics Metrics module label Jan 27, 2026
@vfdev-5 vfdev-5 marked this pull request as ready for review January 27, 2026 16:25
@vfdev-5 vfdev-5 enabled auto-merge January 27, 2026 16:25
@vfdev-5 vfdev-5 added this pull request to the merge queue Jan 27, 2026
Merged via the queue into master with commit 9294aae Jan 27, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: metrics Metrics module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants