Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup mypy 1.7.0 errors #7231

Merged
merged 4 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Shadow-Devil marked this conversation as resolved.
Show resolved Hide resolved
# 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
Loading