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 <[email protected]> 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 <[email protected]>
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:

tests/test_apply_filter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def test_3d(self):
6464
],
6565
]
6666
)
67-
expected = expected
6867
# testing shapes
6968
k = torch.tensor([[[1, 1, 1], [1, 1, 1], [1, 1, 1]]])
7069
for kernel in (k, k[None], k[None][None]):

tests/test_fpn_block.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from monai.networks.blocks.feature_pyramid_network import FeaturePyramidNetwork
2020
from monai.networks.nets.resnet import resnet50
2121
from monai.utils import optional_import
22-
from tests.utils import test_script_save
22+
from tests.utils import SkipIfBeforePyTorchVersion, test_script_save
2323

2424
_, has_torchvision = optional_import("torchvision")
2525

@@ -53,6 +53,7 @@ def test_fpn_block(self, input_param, input_shape, expected_shape):
5353
self.assertEqual(result["feat1"].shape, expected_shape[1])
5454

5555
@parameterized.expand(TEST_CASES)
56+
@SkipIfBeforePyTorchVersion((1, 9, 1))
5657
def test_script(self, input_param, input_shape, expected_shape):
5758
# test whether support torchscript
5859
net = FeaturePyramidNetwork(**input_param)
@@ -73,6 +74,7 @@ def test_fpn(self, input_param, input_shape, expected_shape):
7374
self.assertEqual(result["pool"].shape, expected_shape[1])
7475

7576
@parameterized.expand(TEST_CASES2)
77+
@SkipIfBeforePyTorchVersion((1, 9, 1))
7678
def test_script(self, input_param, input_shape, expected_shape):
7779
# test whether support torchscript
7880
net = _resnet_fpn_extractor(backbone=resnet50(), spatial_dims=input_param["spatial_dims"], returned_layers=[1])

tests/test_gmm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
@skip_if_no_cuda
260260
class GMMTestCase(unittest.TestCase):
261261
def setUp(self):
262-
self._var = os.environ.get("TORCH_EXTENSIONS_DIR", None)
262+
self._var = os.environ.get("TORCH_EXTENSIONS_DIR")
263263
self.tempdir = tempfile.mkdtemp()
264264
os.environ["TORCH_EXTENSIONS_DIR"] = self.tempdir
265265

tests/test_k_space_spike_noised.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_data(im_shape, im_type):
4343
create_test_image = create_test_image_2d if len(im_shape) == 2 else create_test_image_3d
4444
ims = create_test_image(*im_shape, rad_max=20, noise_max=0.0, num_seg_classes=5)
4545
ims = [im_type(im[None]) for im in ims]
46-
return {k: v for k, v in zip(KEYS, ims)}
46+
return dict(zip(KEYS, ims))
4747

4848
@parameterized.expand(TESTS)
4949
def test_same_result(self, im_shape, im_type):

tests/test_monai_env_vars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TestMONAIEnvVars(unittest.TestCase):
1919
@classmethod
2020
def setUpClass(cls):
2121
super(__class__, cls).setUpClass()
22-
cls.orig_value = os.environ.get("MONAI_DEBUG", None)
22+
cls.orig_value = os.environ.get("MONAI_DEBUG")
2323

2424
@classmethod
2525
def tearDownClass(cls):

tests/test_rand_k_space_spike_noised.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_data(im_shape, im_type):
4040
create_test_image = create_test_image_2d if len(im_shape) == 2 else create_test_image_3d
4141
ims = create_test_image(*im_shape, rad_max=20, noise_max=0.0, num_seg_classes=5)
4242
ims = [im_type(im[None]) for im in ims]
43-
return {k: v for k, v in zip(KEYS, ims)}
43+
return dict(zip(KEYS, ims))
4444

4545
@parameterized.expand(TESTS)
4646
def test_same_result(self, im_shape, im_type):

tests/test_separable_filter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def test_3d(self):
6464
],
6565
]
6666
)
67-
expected = expected
6867
# testing shapes
6968
k = torch.tensor([1, 1, 1])
7069
for kernel in (k, [k] * 3):

tests/test_transform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TestTransform(unittest.TestCase):
2929
@classmethod
3030
def setUpClass(cls):
3131
super(__class__, cls).setUpClass()
32-
cls.orig_value = os.environ.get("MONAI_DEBUG", None)
32+
cls.orig_value = os.environ.get("MONAI_DEBUG")
3333

3434
@classmethod
3535
def tearDownClass(cls):

tests/test_varnet.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from monai.apps.reconstruction.networks.nets.complex_unet import ComplexUnet
1919
from monai.apps.reconstruction.networks.nets.varnet import VariationalNetworkModel
2020
from monai.networks import eval_mode
21-
from tests.utils import test_script_save
21+
from tests.utils import SkipIfBeforePyTorchVersion, test_script_save
2222

2323
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
2424
coil_sens_model = CoilSensitivityModel(spatial_dims=2, features=[8, 16, 32, 64, 128, 8])
@@ -43,6 +43,7 @@ def test_shape(self, coil_sens_model, refinement_model, num_cascades, input_shap
4343
self.assertEqual(result.shape, expected_shape)
4444

4545
@parameterized.expand(TESTS)
46+
@SkipIfBeforePyTorchVersion((1, 9, 1))
4647
def test_script(self, coil_sens_model, refinement_model, num_cascades, input_shape, expected_shape):
4748
net = VariationalNetworkModel(coil_sens_model, refinement_model, num_cascades)
4849

0 commit comments

Comments
 (0)