From 111fc7a0c57bb4d96d94f300f8c2f188f7bda148 Mon Sep 17 00:00:00 2001 From: sayantan sadhu <56483183+sayantan1410@users.noreply.github.com> Date: Thu, 20 Jan 2022 19:36:51 +0530 Subject: [PATCH] Fix for issues related to mypy (#2435) * fixed mypy failing errors * fixed errors related to mypy * removed whitespace that was failing flake tests * removed extra whitespace for failing flake test Co-authored-by: vfdev --- ignite/contrib/handlers/neptune_logger.py | 2 +- ignite/engine/deterministic.py | 4 ++-- ignite/handlers/checkpoint.py | 2 +- ignite/handlers/param_scheduler.py | 2 +- ignite/handlers/time_profilers.py | 2 +- tests/run_code_style.sh | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ignite/contrib/handlers/neptune_logger.py b/ignite/contrib/handlers/neptune_logger.py index 1dd4c41795c..642b16bb42c 100644 --- a/ignite/contrib/handlers/neptune_logger.py +++ b/ignite/contrib/handlers/neptune_logger.py @@ -585,7 +585,7 @@ def __call__(self, checkpoint: Mapping, filename: str, metadata: Optional[Mappin with tempfile.NamedTemporaryFile() as tmp: # we can not use tmp.name to open tmp.file twice on Win32 # https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile - torch.save(checkpoint, tmp.file) # type: ignore[attr-defined] + torch.save(checkpoint, tmp.file) self._logger.log_artifact(tmp.name, filename) @idist.one_rank_only(with_barrier=True) diff --git a/ignite/engine/deterministic.py b/ignite/engine/deterministic.py index b82e68fef0d..86c3512f924 100644 --- a/ignite/engine/deterministic.py +++ b/ignite/engine/deterministic.py @@ -251,12 +251,12 @@ def _from_iteration(self, iteration: int) -> Iterator: if isinstance(data, DataLoader): try: # following is unsafe for IterableDatasets - iteration %= len(data.batch_sampler) # type: ignore[attr-defined, arg-type] + iteration %= len(data.batch_sampler) # type: ignore[arg-type] # Synchronize dataflow according to state.iteration self._setup_seed() if iteration > 0: # batch sampler is ReproducibleBatchSampler - data.batch_sampler.start_iteration = iteration # type: ignore[attr-defined, union-attr] + data.batch_sampler.start_iteration = iteration # type: ignore[union-attr] return iter(data) except TypeError as e: # Probably we can do nothing with DataLoader built upon IterableDatasets diff --git a/ignite/handlers/checkpoint.py b/ignite/handlers/checkpoint.py index 9a366c4f6ec..1267a5a2ef8 100644 --- a/ignite/handlers/checkpoint.py +++ b/ignite/handlers/checkpoint.py @@ -718,7 +718,7 @@ def _save_func(self, checkpoint: Mapping, path: str, func: Callable, rank: int = tmp: Optional[IO[bytes]] = None if rank == 0: tmp = tempfile.NamedTemporaryFile(delete=False, dir=self.dirname) - tmp_file = tmp.file # type: ignore + tmp_file = tmp.file tmp_name = tmp.name try: func(checkpoint, tmp_file, **self.kwargs) diff --git a/ignite/handlers/param_scheduler.py b/ignite/handlers/param_scheduler.py index 460a28357af..334acec5fca 100644 --- a/ignite/handlers/param_scheduler.py +++ b/ignite/handlers/param_scheduler.py @@ -893,7 +893,7 @@ def simulate_values( # type: ignore[override] torch.save(obj, cache_filepath.as_posix()) values = [] - scheduler = cls(save_history=False, lr_scheduler=lr_scheduler, **kwargs) # type: ignore[call-arg] + scheduler = cls(save_history=False, lr_scheduler=lr_scheduler, **kwargs) for i in range(num_events): params = [p[scheduler.param_name] for p in scheduler.optimizer_param_groups] values.append([i] + params) diff --git a/ignite/handlers/time_profilers.py b/ignite/handlers/time_profilers.py index be0d8c6e884..abe2e0b732b 100644 --- a/ignite/handlers/time_profilers.py +++ b/ignite/handlers/time_profilers.py @@ -585,7 +585,7 @@ def attach(self, engine: Engine) -> None: if not engine.has_event_handler(self._as_first_started): engine._event_handlers[Events.STARTED].insert(0, (self._as_first_started, (engine,), {})) - def get_results(self) -> List[List[Union[str, float]]]: + def get_results(self) -> List[List[Union[str, float, Tuple[Union[str, float], Union[str, float]]]]]: """ Method to fetch the aggregated profiler results after the engine is run diff --git a/tests/run_code_style.sh b/tests/run_code_style.sh index 4e0ec75beb4..beadb887ddd 100755 --- a/tests/run_code_style.sh +++ b/tests/run_code_style.sh @@ -12,5 +12,5 @@ elif [ $1 = "fmt" ]; then elif [ $1 = "mypy" ]; then mypy --config-file mypy.ini elif [ $1 = "install" ]; then - pip install flake8 "black==21.12b0" "isort==5.7.0" "mypy==0.910" + pip install flake8 "black==21.12b0" "isort==5.7.0" "mypy" fi