Commit 9294aae
Update loss.py type hints to Python 3.10+ syntax (#3501)
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[...]`
- `Dict` → `dict`
- 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
```python
# 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.
<!-- START COPILOT CODING AGENT SUFFIX -->
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
> 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
</details>
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/pytorch/ignite/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: vfdev-5 <[email protected]>1 parent c85dce5 commit 9294aae
1 file changed
+6
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | | - | |
96 | | - | |
| 95 | + | |
| 96 | + | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| |||
0 commit comments