Skip to content

Commit 5b3b741

Browse files
pre-commit-ci[bot]deepsource-autofix[bot]wyli
authored
[pre-commit.ci] pre-commit suggestions/consolidate autofixes (#5256)
<!--pre-commit.ci start--> updates: - [github.com/asottile/pyupgrade: v2.34.0 → v2.38.2](asottile/pyupgrade@v2.34.0...v2.38.2) - [github.com/asottile/yesqa: v1.3.0 → v1.4.0](asottile/yesqa@v1.3.0...v1.4.0) - [github.com/hadialqattan/pycln: v1.3.5 → v2.1.1](hadialqattan/pycln@v1.3.5...v2.1.1) <!--pre-commit.ci end--> Signed-off-by: Wenqi Li <wenqil@nvidia.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> Co-authored-by: Wenqi Li <wenqil@nvidia.com>
1 parent ea43d54 commit 5b3b741

19 files changed

+26
-33
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ repos:
2828
- id: mixed-line-ending
2929

3030
- repo: https://github.com/asottile/pyupgrade
31-
rev: v2.34.0
31+
rev: v2.38.2
3232
hooks:
3333
- id: pyupgrade
3434
args: [--py37-plus]
@@ -40,7 +40,7 @@ repos:
4040
)$
4141
4242
- repo: https://github.com/asottile/yesqa
43-
rev: v1.3.0
43+
rev: v1.4.0
4444
hooks:
4545
- id: yesqa
4646
name: Unused noqa
@@ -58,7 +58,7 @@ repos:
5858
)$
5959
6060
- repo: https://github.com/hadialqattan/pycln
61-
rev: v1.3.5
61+
rev: v2.1.1
6262
hooks:
6363
- id: pycln
6464
args: [--config=pyproject.toml]

monai/bundle/config_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def get_component_module_name(self, name: str) -> Optional[Union[List[str], str]
106106
# init component and module mapping table
107107
self._components_table = self._find_classes_or_functions(self._find_module_names())
108108

109-
mods: Optional[Union[List[str], str]] = self._components_table.get(name, None)
109+
mods: Optional[Union[List[str], str]] = self._components_table.get(name)
110110
if isinstance(mods, list) and len(mods) == 1:
111111
mods = mods[0]
112112
return mods

monai/data/dataloader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, dataset: Dataset, num_workers: int = 0, **kwargs) -> None:
7676
# when num_workers > 0, random states are determined by worker_init_fn
7777
# this is to make the behavior consistent when num_workers == 0
7878
# torch.int64 doesn't work well on some versions of windows
79-
_g = torch.random.default_generator if kwargs.get("generator", None) is None else kwargs["generator"]
79+
_g = torch.random.default_generator if kwargs.get("generator") is None else kwargs["generator"]
8080
init_seed = _g.initial_seed()
8181
_seed = torch.empty((), dtype=torch.int64).random_(generator=_g).item()
8282
set_rnd(dataset, int(_seed))

monai/data/wsi_reader.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,6 @@ class OpenSlideWSIReader(BaseWSIReader):
555555
supported_suffixes = ["tif", "tiff", "svs"]
556556
backend = "openslide"
557557

558-
def __init__(self, level: int = 0, channel_dim: int = 0, **kwargs):
559-
super().__init__(level, channel_dim, **kwargs)
560-
561558
@staticmethod
562559
def get_level_count(wsi) -> int:
563560
"""
@@ -702,9 +699,6 @@ class TiffFileWSIReader(BaseWSIReader):
702699
supported_suffixes = ["tif", "tiff", "svs"]
703700
backend = "tifffile"
704701

705-
def __init__(self, level: int = 0, channel_dim: int = 0, **kwargs):
706-
super().__init__(level, channel_dim, **kwargs)
707-
708702
@staticmethod
709703
def get_level_count(wsi) -> int:
710704
"""

monai/networks/blocks/feature_pyramid_network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,6 @@ def forward(self, x: Dict[str, Tensor]) -> Dict[str, Tensor]:
258258
results, names = self.extra_blocks(results, x_values, names)
259259

260260
# make it back an OrderedDict
261-
out = OrderedDict([(k, v) for k, v in zip(names, results)])
261+
out = OrderedDict(list(zip(names, results)))
262262

263263
return out

monai/networks/blocks/fft_utils_t.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ def ifftn_centered_t(ksp: Tensor, spatial_dims: int, is_complex: bool = True) ->
139139
output2 = ifftn_centered(ksp, spatial_dims=2, is_complex=True)
140140
"""
141141
# define spatial dims to perform ifftshift, fftshift, and ifft
142-
shift = [i for i in range(-spatial_dims, 0)] # noqa: C416
142+
shift = list(range(-spatial_dims, 0))
143143
if is_complex:
144144
if ksp.shape[-1] != 2:
145145
raise ValueError(f"ksp.shape[-1] is not 2 ({ksp.shape[-1]}).")
146-
shift = [i for i in range(-spatial_dims - 1, -1)] # noqa: C416
147-
dims = [i for i in range(-spatial_dims, 0)] # noqa: C416
146+
shift = list(range(-spatial_dims - 1, -1))
147+
dims = list(range(-spatial_dims, 0))
148148

149149
x = ifftshift(ksp, shift)
150150

@@ -187,12 +187,12 @@ def fftn_centered_t(im: Tensor, spatial_dims: int, is_complex: bool = True) -> T
187187
output2 = fftn_centered(im, spatial_dims=2, is_complex=True)
188188
"""
189189
# define spatial dims to perform ifftshift, fftshift, and fft
190-
shift = [i for i in range(-spatial_dims, 0)] # noqa: C416
190+
shift = list(range(-spatial_dims, 0))
191191
if is_complex:
192192
if im.shape[-1] != 2:
193193
raise ValueError(f"img.shape[-1] is not 2 ({im.shape[-1]}).")
194-
shift = [i for i in range(-spatial_dims - 1, -1)] # noqa: C416
195-
dims = [i for i in range(-spatial_dims, 0)] # noqa: C416
194+
shift = list(range(-spatial_dims - 1, -1))
195+
dims = list(range(-spatial_dims, 0))
196196

197197
x = ifftshift(im, shift)
198198

monai/networks/layers/weight_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def trunc_normal_(tensor, mean=0.0, std=1.0, a=-2.0, b=2.0):
5555
b: the maximum cutoff value
5656
"""
5757

58-
if not std > 0:
58+
if std <= 0:
5959
raise ValueError("the standard deviation should be greater than zero.")
6060

6161
if a >= b:

monai/transforms/utility/dictionary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def __call__(
423423
output = []
424424
results = [self.splitter(d[key]) for key in all_keys]
425425
for row in zip(*results):
426-
new_dict = {k: v for k, v in zip(all_keys, row)}
426+
new_dict = dict(zip(all_keys, row))
427427
# fill in the extra keys with unmodified data
428428
for k in set(d.keys()).difference(set(all_keys)):
429429
new_dict[k] = deepcopy(d[k])

monai/transforms/utils_create_transform_ims.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,6 @@ def create_transform_im(
427427
seed = seed + 1 if isinstance(transform, MapTransform) else seed
428428
transform.set_random_state(seed)
429429

430-
from monai.utils.misc import MONAIEnvVars
431-
432430
out_dir = MONAIEnvVars.doc_images()
433431
if out_dir is None:
434432
raise RuntimeError(

monai/utils/misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ class MONAIEnvVars:
397397

398398
@staticmethod
399399
def data_dir() -> Optional[str]:
400-
return os.environ.get("MONAI_DATA_DIRECTORY", None)
400+
return os.environ.get("MONAI_DATA_DIRECTORY")
401401

402402
@staticmethod
403403
def debug() -> bool:
@@ -406,7 +406,7 @@ def debug() -> bool:
406406

407407
@staticmethod
408408
def doc_images() -> Optional[str]:
409-
return os.environ.get("MONAI_DOC_IMAGES", None)
409+
return os.environ.get("MONAI_DOC_IMAGES")
410410

411411

412412
class ImageMetaKey:

0 commit comments

Comments
 (0)