Skip to content

Fix error message typo and remove redundant type casts#3503

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

Fix error message typo and remove redundant type casts#3503
vfdev-5 merged 5 commits intomasterfrom
copilot/update-typing-hints-in-metrics-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 3, 2026

Addresses code review findings and Pyrefly warnings in metrics module.

Error Message Correction

MeanPairwiseDistance.compute() raised NotComputableError with incorrect class name reference:

# Before
raise NotComputableError("MeanAbsoluteError must have at least one example...")

# After
raise NotComputableError("MeanPairwiseDistance must have at least one example...")

Updated corresponding test expectation in test_mean_pairwise_distance.py::test_zero_sample.

Redundant Cast Removal

Removed unnecessary cast() calls in Loss.update() where function signature already provides type narrowing:

def update(self, output: tuple[Tensor, Tensor] | tuple[Tensor, Tensor, dict]) -> None:
    if len(output) == 2:
        y_pred, y = output  # cast() removed - type already constrained
    else:
        y_pred, y, kwargs = output  # cast() removed - type already constrained

Removed unused cast import from typing.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Remove Union import (no longer needed)
- Replace Union[str, torch.device] with str | torch.device
- Replace Union[float, torch.Tensor] with float | torch.Tensor

Co-authored-by: vfdev-5 <[email protected]>
Copilot AI changed the title [WIP] Update old typing hints in ignite metrics Modernize type hints in mean_pairwise_distance.py to Python 3.10+ syntax Feb 3, 2026
Copilot AI requested a review from vfdev-5 February 3, 2026 08:32
Copilot AI and others added 2 commits February 3, 2026 08:39
- Remove redundant cast() calls on lines 95 and 98
- Remove unused 'cast' import from typing
- Type annotation on function signature already provides type safety

Co-authored-by: vfdev-5 <[email protected]>
Copilot AI changed the title Modernize type hints in mean_pairwise_distance.py to Python 3.10+ syntax Fix error message typo and remove redundant type casts Feb 3, 2026
Copilot AI requested a review from vfdev-5 February 3, 2026 08:41
@vfdev-5 vfdev-5 marked this pull request as ready for review February 3, 2026 08:45
@vfdev-5 vfdev-5 enabled auto-merge February 3, 2026 08:45
Update the expected error message in test to match the fix made to
MeanPairwiseDistance.compute() where "MeanAbsoluteError" was corrected
to "MeanPairwiseDistance".

Co-authored-by: vfdev-5 <[email protected]>
auto-merge was automatically disabled February 3, 2026 09:12

Head branch was pushed to by a user without write access

Copilot AI requested a review from vfdev-5 February 3, 2026 09:14
@vfdev-5 vfdev-5 enabled auto-merge February 3, 2026 09:15
@vfdev-5 vfdev-5 added this pull request to the merge queue Feb 3, 2026
Merged via the queue into master with commit a9b7e0a Feb 3, 2026
26 checks passed
@vfdev-5 vfdev-5 deleted the copilot/update-typing-hints-in-metrics-again branch February 3, 2026 10:01
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