Skip to content

Commit 0f797d7

Browse files
committed
Apply pyupgrade for Python 3.9+ syntax
This should have been included in 14b086b when Python 3.8 support was dropped. Changes were automatically applied by running: pre_commit run --all-files Signed-off-by: James Butler <[email protected]>
1 parent a2be24a commit 0f797d7

36 files changed

+91
-44
lines changed

Diff for: .pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ repos:
3737
rev: v3.19.0
3838
hooks:
3939
- id: pyupgrade
40-
args: [--py38-plus, --keep-runtime-typing]
40+
args: [--py39-plus, --keep-runtime-typing]
4141
name: Upgrade code with exceptions
4242
exclude: |
4343
(?x)(

Diff for: monai/apps/detection/networks/retinanet_network.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import math
4343
import warnings
4444
from collections.abc import Callable, Sequence
45-
from typing import Any, Dict
45+
from typing import Any
4646

4747
import torch
4848
from torch import Tensor, nn
@@ -330,7 +330,7 @@ def forward(self, images: Tensor) -> Any:
330330
features = self.feature_extractor(images)
331331
if isinstance(features, Tensor):
332332
feature_maps = [features]
333-
elif torch.jit.isinstance(features, Dict[str, Tensor]):
333+
elif torch.jit.isinstance(features, dict[str, Tensor]):
334334
feature_maps = list(features.values())
335335
else:
336336
feature_maps = list(features)

Diff for: monai/apps/detection/transforms/array.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
from __future__ import annotations
1717

18-
from typing import Any, Sequence
18+
from typing import Any
19+
20+
from collections.abc import Sequence
1921

2022
import numpy as np
2123
import torch

Diff for: monai/apps/detection/utils/anchor_utils.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939

4040
from __future__ import annotations
4141

42-
from typing import List, Sequence
42+
43+
from collections.abc import Sequence
4344

4445
import torch
4546
from torch import Tensor, nn
@@ -106,7 +107,7 @@ class AnchorGenerator(nn.Module):
106107
anchor_generator = AnchorGenerator(sizes, aspect_ratios)
107108
"""
108109

109-
__annotations__ = {"cell_anchors": List[torch.Tensor]}
110+
__annotations__ = {"cell_anchors": list[torch.Tensor]}
110111

111112
def __init__(
112113
self,
@@ -364,7 +365,7 @@ class AnchorGeneratorWithAnchorShape(AnchorGenerator):
364365
anchor_generator = AnchorGeneratorWithAnchorShape(feature_map_scales, base_anchor_shapes)
365366
"""
366367

367-
__annotations__ = {"cell_anchors": List[torch.Tensor]}
368+
__annotations__ = {"cell_anchors": list[torch.Tensor]}
368369

369370
def __init__(
370371
self,

Diff for: monai/apps/generation/maisi/networks/autoencoderkl_maisi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import gc
1515
import logging
16-
from typing import Sequence
16+
from collections.abc import Sequence
1717

1818
import torch
1919
import torch.nn as nn

Diff for: monai/apps/generation/maisi/networks/controlnet_maisi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from __future__ import annotations
1313

14-
from typing import Sequence
14+
from collections.abc import Sequence
1515

1616
import torch
1717

Diff for: monai/apps/pathology/engines/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
from __future__ import annotations
1313

14-
from typing import Any, Sequence
14+
from typing import Any
15+
16+
from collections.abc import Sequence
1517

1618
import torch
1719

Diff for: monai/apps/pathology/inferers/inferer.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
from __future__ import annotations
1313

14-
from typing import Any, Callable, Sequence
14+
from typing import Any, Callable
15+
16+
from collections.abc import Sequence
1517

1618
import numpy as np
1719
import torch

Diff for: monai/apps/pathology/metrics/lesion_froc.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
from __future__ import annotations
1313

14-
from typing import TYPE_CHECKING, Any, Iterable
14+
from typing import TYPE_CHECKING, Any
15+
16+
from collections.abc import Iterable
1517

1618
import numpy as np
1719

Diff for: monai/apps/pathology/transforms/post/array.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
from __future__ import annotations
1313

1414
import warnings
15-
from typing import Callable, Sequence
15+
from typing import Callable
16+
17+
from collections.abc import Sequence
1618

1719
import numpy as np
1820
import torch

Diff for: monai/apps/tcia/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from __future__ import annotations
1313

1414
import os
15-
from typing import Iterable
15+
from collections.abc import Iterable
1616

1717
import monai
1818
from monai.config.type_definitions import PathLike

Diff for: monai/apps/utils.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ def check_hash(filepath: PathLike, val: str | None = None, hash_type: str = "md5
136136
return True
137137
actual_hash_func = look_up_option(hash_type.lower(), SUPPORTED_HASH_TYPES)
138138

139-
if sys.version_info >= (3, 9):
140-
actual_hash = actual_hash_func(usedforsecurity=False) # allows checks on FIPS enabled machines
141-
else:
142-
actual_hash = actual_hash_func()
139+
actual_hash = actual_hash_func(usedforsecurity=False) # allows checks on FIPS enabled machines
143140

144141
try:
145142
with open(filepath, "rb") as f:

Diff for: monai/apps/vista3d/transforms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from __future__ import annotations
1313

1414
import warnings
15-
from typing import Sequence
15+
from collections.abc import Sequence
1616

1717
import numpy as np
1818
import torch

Diff for: monai/bundle/reference_resolver.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import re
1515
import warnings
1616
from collections.abc import Sequence
17-
from typing import Any, Iterator
17+
from typing import Any
18+
19+
from collections.abc import Iterator
1820

1921
from monai.bundle.config_item import ConfigComponent, ConfigExpression, ConfigItem
2022
from monai.bundle.utils import DEPRECATED_ID_MAPPING, ID_REF_KEY, ID_SEP_KEY

Diff for: monai/bundle/workflows.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
from copy import copy
2020
from logging.config import fileConfig
2121
from pathlib import Path
22-
from typing import Any, Sequence
22+
from typing import Any
23+
24+
from collections.abc import Sequence
2325

2426
from monai.apps.utils import get_logger
2527
from monai.bundle.config_parser import ConfigParser

Diff for: monai/config/type_definitions.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
from __future__ import annotations
1313

1414
import os
15-
from typing import Collection, Hashable, Iterable, Sequence, TypeVar, Union
15+
from typing import TypeVar, Union
16+
17+
from collections.abc import Collection, Hashable, Iterable, Sequence
1618

1719
import numpy as np
1820
import torch

Diff for: monai/data/meta_obj.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import itertools
1515
import pprint
1616
from copy import deepcopy
17-
from typing import Any, Iterable
17+
from typing import Any
18+
19+
from collections.abc import Iterable
1820

1921
import numpy as np
2022
import torch

Diff for: monai/data/meta_tensor.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import functools
1515
import warnings
1616
from copy import deepcopy
17-
from typing import Any, Sequence
17+
from typing import Any
18+
19+
from collections.abc import Sequence
1820

1921
import numpy as np
2022
import torch

Diff for: monai/engines/evaluator.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
from __future__ import annotations
1313

1414
import warnings
15-
from typing import TYPE_CHECKING, Any, Callable, Iterable, Sequence
15+
from typing import TYPE_CHECKING, Any, Callable
16+
17+
from collections.abc import Iterable, Sequence
1618

1719
import torch
1820
from torch.utils.data import DataLoader

Diff for: monai/engines/trainer.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
from __future__ import annotations
1313

1414
import warnings
15-
from typing import TYPE_CHECKING, Any, Callable, Iterable, Sequence
15+
from typing import TYPE_CHECKING, Any, Callable
16+
17+
from collections.abc import Iterable, Sequence
1618

1719
import torch
1820
from torch.optim.optimizer import Optimizer

Diff for: monai/engines/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
from abc import ABC, abstractmethod
1515
from collections.abc import Callable, Sequence
16-
from typing import TYPE_CHECKING, Any, Mapping, cast
16+
from typing import TYPE_CHECKING, Any, cast
17+
18+
from collections.abc import Mapping
1719

1820
import torch
1921
import torch.nn as nn

Diff for: monai/handlers/clearml_handlers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
from __future__ import annotations
1313

14-
from typing import TYPE_CHECKING, Any, Mapping, Sequence
14+
from typing import TYPE_CHECKING, Any
15+
16+
from collections.abc import Mapping, Sequence
1517

1618
from monai.utils import optional_import
1719

Diff for: monai/inferers/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
import itertools
1515
from collections.abc import Callable, Mapping, Sequence
16-
from typing import Any, Iterable
16+
from typing import Any
17+
18+
from collections.abc import Iterable
1719

1820
import numpy as np
1921
import torch

Diff for: monai/metrics/utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import warnings
1515
from functools import lru_cache, partial
1616
from types import ModuleType
17-
from typing import Any, Iterable, Sequence
17+
from typing import Any
18+
19+
from collections.abc import Iterable, Sequence
1820

1921
import numpy as np
2022
import torch

Diff for: monai/transforms/intensity/dictionary.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
from __future__ import annotations
1919

20-
from typing import Callable, Hashable, Mapping, Sequence
20+
from typing import Callable
21+
22+
from collections.abc import Hashable, Mapping, Sequence
2123

2224
import numpy as np
2325

Diff for: monai/transforms/lazy/functional.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
from __future__ import annotations
1313

14-
from typing import Any, Mapping, Sequence
14+
from typing import Any
15+
16+
from collections.abc import Mapping, Sequence
1517

1618
import torch
1719

Diff for: monai/transforms/spatial/array.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
from collections.abc import Callable
1919
from copy import deepcopy
2020
from itertools import zip_longest
21-
from typing import Any, Optional, Sequence, Tuple, Union, cast
21+
from typing import Any, Optional, Union, cast
22+
23+
from collections.abc import Sequence
2224

2325
import numpy as np
2426
import torch
@@ -116,7 +118,7 @@
116118
"RandSimulateLowResolution",
117119
]
118120

119-
RandRange = Optional[Union[Sequence[Union[Tuple[float, float], float]], float]]
121+
RandRange = Optional[Union[Sequence[Union[tuple[float, float], float]], float]]
120122

121123

122124
class SpatialResample(InvertibleTransform, LazyTransform):

Diff for: monai/transforms/utility/dictionary.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import re
2121
from collections.abc import Callable, Hashable, Mapping
2222
from copy import deepcopy
23-
from typing import Any, Sequence, cast
23+
from typing import Any, cast
24+
25+
from collections.abc import Sequence
2426

2527
import numpy as np
2628
import torch

Diff for: monai/transforms/utils_morphological_ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from __future__ import annotations
1313

14-
from typing import Sequence
14+
from collections.abc import Sequence
1515

1616
import torch
1717
import torch.nn.functional as F

Diff for: monai/utils/component_store.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
from collections import namedtuple
1515
from keyword import iskeyword
1616
from textwrap import dedent, indent
17-
from typing import Any, Callable, Iterable, TypeVar
17+
from typing import Any, Callable, TypeVar
18+
19+
from collections.abc import Iterable
1820

1921
T = TypeVar("T")
2022

Diff for: monai/utils/decorators.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
__all__ = ["RestartGenerator", "MethodReplacer"]
1717

18-
from typing import Callable, Generator
18+
from typing import Callable
19+
20+
from collections.abc import Generator
1921

2022

2123
class RestartGenerator:

Diff for: monai/utils/module.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
from pydoc import locate
2626
from re import match
2727
from types import FunctionType, ModuleType
28-
from typing import Any, Iterable, cast
28+
from typing import Any, cast
29+
30+
from collections.abc import Iterable
2931

3032
import torch
3133

Diff for: monai/utils/state_cacher.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import pickle
1717
import tempfile
1818
from types import ModuleType
19-
from typing import Any, Hashable
19+
from typing import Any
20+
21+
from collections.abc import Hashable
2022

2123
import torch
2224
from torch.serialization import DEFAULT_PROTOCOL

0 commit comments

Comments
 (0)