Repository: pytorch/ignite

Issue:
Typefix
 🐛 Due to changes in variable types in the nightly PyTorch version, some # type ignore comments are redundant and we need some in some new places for mypy tests to pass Due to changes in variable types in the nightly PyTorch version, some # type ignore comments are redundant and we need some in some new places for mypy tests to pass.

<!-- A clear and concise description of what the bug is. --> Mypy tests failing
<!-- Please, add steps on how to reproduce it. --> Install pytorch nightly version by `conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch-nightly` and run `bash ./tests/run_code_style.sh mypy`
<!-- If you have a code sample, error messages, stack traces, please provide it here as well --> 
![image](https://user-images.githubusercontent.com/43926001/179356465-2dcbda33-a424-4b7d-8ef1-16e55b6ab1f1.png)
<!-- A clear and concise description of what you expected to happen. --> Expected the tests to pass

## Environment

- PyTorch Version: 1.13.0.dev20220715
- Ignite Version: 0.5.0
- OS: Ubuntu 20.04
- How you installed Ignite: `pip`
- Python version: `3.10.4`


Discussion:

Resolving patch:
diff --git a/ignite/handlers/lr_finder.py b/ignite/handlers/lr_finder.py
--- a/ignite/handlers/lr_finder.py
+++ b/ignite/handlers/lr_finder.py
@@ -122,8 +122,8 @@ def _run(
             start_lr = optimizer.param_groups[0]["lr"]
         # Initialize the proper learning rate policy
         if step_mode.lower() == "exp":
-            start_lr = [start_lr] * len(optimizer.param_groups)  # type: ignore
-            self._lr_schedule = LRScheduler(_ExponentialLR(optimizer, start_lr, end_lr, num_iter))
+            start_lr_list = [start_lr] * len(optimizer.param_groups)
+            self._lr_schedule = LRScheduler(_ExponentialLR(optimizer, start_lr_list, end_lr, num_iter))
         else:
             self._lr_schedule = PiecewiseLinear(
                 optimizer, param_name="lr", milestones_values=[(0, start_lr), (num_iter, end_lr)]
@@ -487,7 +487,7 @@ class _ExponentialLR(_LRScheduler):
 
     """
 
-    def __init__(self, optimizer: Optimizer, start_lr: float, end_lr: float, num_iter: int, last_epoch: int = -1):
+    def __init__(self, optimizer: Optimizer, start_lr: List[float], end_lr: float, num_iter: int, last_epoch: int = -1):
         self.end_lr = end_lr
         self.num_iter = num_iter
         super(_ExponentialLR, self).__init__(optimizer, last_epoch)
@@ -496,6 +496,6 @@ def __init__(self, optimizer: Optimizer, start_lr: float, end_lr: float, num_ite
         self.base_lrs = start_lr
 
     def get_lr(self) -> List[float]:  # type: ignore
-        curr_iter = self.last_epoch + 1  # type: ignore[attr-defined]
+        curr_iter = self.last_epoch + 1
         r = curr_iter / self.num_iter
-        return [base_lr * (self.end_lr / base_lr) ** r for base_lr in self.base_lrs]  # type: ignore[attr-defined]
+        return [base_lr * (self.end_lr / base_lr) ** r for base_lr in self.base_lrs]
diff --git a/ignite/handlers/param_scheduler.py b/ignite/handlers/param_scheduler.py
--- a/ignite/handlers/param_scheduler.py
+++ b/ignite/handlers/param_scheduler.py
@@ -851,7 +851,7 @@ def __init__(
 
         self.lr_scheduler = lr_scheduler
         super(LRScheduler, self).__init__(
-            optimizer=self.lr_scheduler.optimizer,  # type: ignore[attr-defined]
+            optimizer=self.lr_scheduler.optimizer,
             param_name="lr",
             save_history=save_history,
         )
@@ -861,13 +861,13 @@ def __init__(
                 "instead of Events.ITERATION_STARTED to make sure to use "
                 "the first lr value from the optimizer, otherwise it is will be skipped"
             )
-            self.lr_scheduler.last_epoch += 1  # type: ignore[attr-defined]
+            self.lr_scheduler.last_epoch += 1
 
         self._state_attrs += ["lr_scheduler"]
 
     def __call__(self, engine: Optional[Engine], name: Optional[str] = None) -> None:
         super(LRScheduler, self).__call__(engine, name)
-        self.lr_scheduler.last_epoch += 1  # type: ignore[attr-defined]
+        self.lr_scheduler.last_epoch += 1
 
     def get_param(self) -> Union[float, List[float]]:
         """Method to get current optimizer's parameter value"""
@@ -908,7 +908,7 @@ def simulate_values(  # type: ignore[override]
             cache_filepath = Path(tmpdirname) / "ignite_lr_scheduler_cache.pt"
             obj = {
                 "lr_scheduler": lr_scheduler.state_dict(),
-                "optimizer": lr_scheduler.optimizer.state_dict(),  # type: ignore[attr-defined]
+                "optimizer": lr_scheduler.optimizer.state_dict(),
             }
             torch.save(obj, cache_filepath.as_posix())
 
@@ -921,7 +921,7 @@ def simulate_values(  # type: ignore[override]
 
             obj = torch.load(cache_filepath.as_posix())
             lr_scheduler.load_state_dict(obj["lr_scheduler"])
-            lr_scheduler.optimizer.load_state_dict(obj["optimizer"])  # type: ignore[attr-defined]
+            lr_scheduler.optimizer.load_state_dict(obj["optimizer"])
 
             return values
 
@@ -1403,7 +1403,7 @@ def simulate_values(cls, num_events: int, schedulers: List[_LRScheduler], **kwar
             cache_filepath = Path(tmpdirname) / "ignite_lr_scheduler_cache.pt"
             objs = {f"lr_scheduler_{i}": s.state_dict() for i, s in enumerate(schedulers)}
             # all schedulers should be related to the same optimizer
-            objs["optimizer"] = schedulers[0].optimizer.state_dict()  # type: ignore[attr-defined]
+            objs["optimizer"] = schedulers[0].optimizer.state_dict()
 
             torch.save(objs, cache_filepath.as_posix())
 
@@ -1417,7 +1417,7 @@ def simulate_values(cls, num_events: int, schedulers: List[_LRScheduler], **kwar
             objs = torch.load(cache_filepath.as_posix())
             for i, s in enumerate(schedulers):
                 s.load_state_dict(objs[f"lr_scheduler_{i}"])
-                s.optimizer.load_state_dict(objs["optimizer"])  # type: ignore[attr-defined]
+                s.optimizer.load_state_dict(objs["optimizer"])
 
             return values
 
@@ -1561,8 +1561,8 @@ def get_param(self) -> Union[float, List[float]]:
     def _reduce_lr(self, epoch: int) -> None:
         for i, param_group in enumerate(self.optimizer_param_groups):
             old_lr = float(param_group["lr"])
-            new_lr = max(old_lr * self.scheduler.factor, self.scheduler.min_lrs[i])  # type: ignore[attr-defined]
-            if old_lr - new_lr > self.scheduler.eps:  # type: ignore[attr-defined]
+            new_lr = max(old_lr * self.scheduler.factor, self.scheduler.min_lrs[i])
+            if old_lr - new_lr > self.scheduler.eps:
                 param_group["lr"] = new_lr
 
     @classmethod


Test patch: