Skip to content

Commit

Permalink
Fixup mypy 1.7.0 errors (Project-MONAI#7231)
Browse files Browse the repository at this point in the history
Fixes Project-MONAI#7230.

### Description

Fix the typing issues and the deprecation.

Also always run type checking with Linux environment, since
ForkServerContext is not available on Windows.

### Types of changes
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).

---------

Signed-off-by: Felix Schnabel <f.schnabel@tum.de>
Signed-off-by: Juan Pablo de la Cruz Gutiérrez <juampatronics@gmail.com>
  • Loading branch information
Shadow-Devil authored and juampatronics committed Mar 25, 2024
1 parent c43f8ca commit cad947e
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ venv.bak/
examples/scd_lvsegs.npz
temp/
.idea/
.dmypy.json

*~

Expand Down
2 changes: 1 addition & 1 deletion monai/apps/auto3dseg/data_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def get_all_case_stats(self, key="training", transform_list=None):
nprocs = torch.cuda.device_count()
logger.info(f"Found {nprocs} GPUs for data analyzing!")
if nprocs > 1:
tmp_ctx = get_context("forkserver")
tmp_ctx: Any = get_context("forkserver")
with tmp_ctx.Manager() as manager:
manager_list = manager.list()
processes = []
Expand Down
2 changes: 1 addition & 1 deletion monai/apps/deepgrow/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
if not isinstance(transforms, Compose):
transforms = Compose(transforms)

self.transforms = transforms
self.transforms: Compose = transforms
self.max_interactions = max_interactions
self.train = train
self.key_probability = key_probability
Expand Down
5 changes: 4 additions & 1 deletion monai/apps/pathology/metrics/lesion_froc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any, Iterable

import numpy as np

Expand Down Expand Up @@ -94,6 +94,9 @@ def prepare_inference_result(self, sample: dict) -> tuple[np.ndarray, np.ndarray
nms_outputs = self.nms(probs_map=prob_map, resolution_level=sample["level"])

# separate nms outputs
probs: Iterable[Any]
x_coord: Iterable[Any]
y_coord: Iterable[Any]
if nms_outputs:
probs, x_coord, y_coord = zip(*nms_outputs)
else:
Expand Down
4 changes: 2 additions & 2 deletions monai/metrics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import warnings
from functools import lru_cache, partial
from types import ModuleType
from typing import Any, Sequence
from typing import Any, Iterable, Sequence

import numpy as np
import torch
Expand Down Expand Up @@ -383,7 +383,7 @@ def remap_instance_id(pred: torch.Tensor, by_size: bool = False) -> torch.Tensor
by_size: if True, largest instance will be assigned a smaller id.
"""
pred_id = list(pred.unique())
pred_id: Iterable[Any] = list(pred.unique())
# the original implementation has the limitation that if there is no 0 in pred, error will happen
pred_id = [i for i in pred_id if i != 0]

Expand Down
2 changes: 1 addition & 1 deletion monai/transforms/io/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def __call__(self, filename: Sequence[PathLike] | PathLike, reader: ImageReader
break

if img is None or reader is None:
if isinstance(filename, tuple) and len(filename) == 1:
if isinstance(filename, Sequence) and len(filename) == 1:
filename = filename[0]
msg = "\n".join([f"{e}" for e in err])
raise RuntimeError(
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ isort>=5.1
ruff
pytype>=2020.6.1; platform_system != "Windows"
types-pkg_resources
mypy>=0.790
mypy>=1.5.0
ninja
torchvision
psutil
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pretty = False
# Warns about per-module sections in the config file that do not match any files processed when invoking mypy.
warn_unused_configs = True
# Make arguments prepended via Concatenate be truly positional-only.
strict_concatenate = True
extra_checks = True
# Allows variables to be redefined with an arbitrary type,
# as long as the redefinition is in the same block and nesting level as the original definition.
# allow_redefinition = True
Expand Down

0 comments on commit cad947e

Please sign in to comment.