Skip to content

Commit c65066c

Browse files
committed
Fix all type errors in existing code
Signed-off-by: Gigon Bae <[email protected]>
1 parent 74ba93c commit c65066c

File tree

13 files changed

+158
-117
lines changed

13 files changed

+158
-117
lines changed

examples/apps/ai_spleen_seg_app/spleen_seg_operator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import logging
1313

1414
from monai.deploy.core import ExecutionContext, Image, InputContext, IOType, Operator, OutputContext, env, input, output
15+
1516
from monai.deploy.operators.monai_seg_inference_operator import InMemImageReader, MonaiSegInferenceOperator
1617
from monai.transforms import (
1718
Activationsd,

monai/deploy/cli/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# limitations under the License.
1111

1212

13-
from main import main
13+
from main import main # type: ignore # for pytype
1414

1515
if __name__ == "__main__":
1616
main()

monai/deploy/core/domain/dicom_series.py

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# See the License for the specific language governing permissions and
1010
# limitations under the License.
1111

12+
from typing import Any
13+
1214
from .dicom_sop_instance import DICOMSOPInstance
1315
from .domain import Domain
1416

@@ -21,6 +23,23 @@ def __init__(self, series_instance_uid):
2123
self._series_instance_uid = series_instance_uid
2224
self._sop_instances = []
2325

26+
self._series_date: Any = None
27+
self._series_time: Any = None
28+
self._modality: Any = None
29+
self._series_description: Any = None
30+
self._body_part_examined: Any = None
31+
self._patient_position: Any = None
32+
self._series_number: Any = None
33+
self._laterality: Any = None
34+
self._row_pixel_spacing: Any = None
35+
self._col_pixel_spacing: Any = None
36+
self._depth_pixel_spacing: Any = None
37+
self._row_direction_cosine: Any = None
38+
self._col_direction_cosine: Any = None
39+
self._depth_direction_cosine: Any = None
40+
self._dicom_affine_transform: Any = None
41+
self._nifti_affine_transform: Any = None
42+
2443
def get_series_instance_uid(self):
2544
return self._series_instance_uid
2645

@@ -33,131 +52,131 @@ def get_sop_instances(self):
3352

3453
@property
3554
def series_date(self):
36-
return self.__series_date
55+
return self._series_date
3756

3857
@series_date.setter
3958
def series_date(self, val):
40-
self.__series_date = val
59+
self._series_date = val
4160

4261
@property
4362
def series_time(self):
44-
return self.__series_time
63+
return self._series_time
4564

4665
@series_time.setter
4766
def series_time(self, val):
48-
self.__series_time = val
67+
self._series_time = val
4968

5069
@property
5170
def modality(self):
52-
return self.__modality
71+
return self._modality
5372

5473
@modality.setter
5574
def modality(self, val):
56-
self.__modality = val
75+
self._modality = val
5776

5877
@property
5978
def series_description(self):
60-
return self.__series_description
79+
return self._series_description
6180

6281
@series_description.setter
6382
def series_description(self, val):
64-
self.__series_description = val
83+
self._series_description = val
6584

6685
@property
6786
def body_part_examined(self):
68-
return self.__body_part_examined
87+
return self._body_part_examined
6988

7089
@body_part_examined.setter
7190
def body_part_examined(self, val):
72-
self.__body_part_examined = val
91+
self._body_part_examined = val
7392

7493
@property
7594
def patient_position(self):
76-
return self.__patient_position
95+
return self._patient_position
7796

7897
@patient_position.setter
7998
def patient_position(self, val):
80-
self.__patient_position = val
99+
self._patient_position = val
81100

82101
@property
83102
def series_number(self):
84-
return self.__series_number
103+
return self._series_number
85104

86105
@series_number.setter
87106
def series_number(self, val):
88-
self.__series_number = val
107+
self._series_number = val
89108

90109
@property
91110
def laterality(self):
92-
return self.__laterality
111+
return self._laterality
93112

94113
@laterality.setter
95114
def laterality(self, val):
96-
self.__laterality = val
115+
self._laterality = val
97116

98117
@property
99118
def row_pixel_spacing(self):
100-
return self.__row_pixel_spacing
119+
return self._row_pixel_spacing
101120

102121
@row_pixel_spacing.setter
103122
def row_pixel_spacing(self, val):
104-
self.__row_pixel_spacing = val
123+
self._row_pixel_spacing = val
105124

106125
@property
107126
def col_pixel_spacing(self):
108-
return self.__col_pixel_spacing
127+
return self._col_pixel_spacing
109128

110129
@col_pixel_spacing.setter
111130
def col_pixel_spacing(self, val):
112-
self.__col_pixel_spacing = val
131+
self._col_pixel_spacing = val
113132

114133
@property
115134
def depth_pixel_spacing(self):
116-
return self.__depth_pixel_spacing
135+
return self._depth_pixel_spacing
117136

118137
@depth_pixel_spacing.setter
119138
def depth_pixel_spacing(self, val):
120-
self.__depth_pixel_spacing = val
139+
self._depth_pixel_spacing = val
121140

122141
@property
123142
def row_direction_cosine(self):
124-
return self.__row_direction_cosine
143+
return self._row_direction_cosine
125144

126145
@row_direction_cosine.setter
127146
def row_direction_cosine(self, val):
128-
self.__row_direction_cosine = val
147+
self._row_direction_cosine = val
129148

130149
@property
131150
def col_direction_cosine(self):
132-
return self.__col_direction_cosine
151+
return self._col_direction_cosine
133152

134153
@col_direction_cosine.setter
135154
def col_direction_cosine(self, val):
136-
self.__col_direction_cosine = val
155+
self._col_direction_cosine = val
137156

138157
@property
139158
def depth_direction_cosine(self):
140-
return self.__depth_direction_cosine
159+
return self._depth_direction_cosine
141160

142161
@depth_direction_cosine.setter
143162
def depth_direction_cosine(self, val):
144-
self.__depth_direction_cosine = val
163+
self._depth_direction_cosine = val
145164

146165
@property
147166
def dicom_affine_transform(self):
148-
return self.__dicom_affine_transform
167+
return self._dicom_affine_transform
149168

150169
@dicom_affine_transform.setter
151170
def dicom_affine_transform(self, val):
152-
self.__dicom_affine_transform = val
171+
self._dicom_affine_transform = val
153172

154173
@property
155174
def nifti_affine_transform(self):
156-
return self.__nifti_affine_transform
175+
return self._nifti_affine_transform
157176

158177
@nifti_affine_transform.setter
159178
def nifti_affine_transform(self, val):
160-
self.__nifti_affine_transform = val
179+
self._nifti_affine_transform = val
161180

162181
def __str__(self):
163182
result = "---------------" + "\n"

monai/deploy/core/domain/dicom_sop_instance.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@
99
# See the License for the specific language governing permissions and
1010
# limitations under the License.
1111

12-
from typing import Union
12+
from typing import Any, Union
1313

1414
from monai.deploy.utils.importutil import optional_import
1515

1616
from .domain import Domain
1717

18-
DataElement, _ = optional_import("pydicom", name="DataElement")
19-
Dataset, _ = optional_import("pydicom", name="Dataset")
20-
Tag, _ = optional_import("pydicom.tag", name="Tag")
21-
BaseTag, _ = optional_import("pydicom.tag", name="BaseTag")
22-
tag_in_exception, _ = optional_import("pydicom.tag", name="tag_in_exception")
23-
TagType, _ = optional_import("pydicom.tag", name="TagType")
18+
DataElement_, _ = optional_import("pydicom", name="DataElement")
19+
# Dynamic class is not handled so make it Any for now: https://github.com/python/mypy/issues/2477
20+
DataElement: Any = DataElement_
21+
Dataset_, _ = optional_import("pydicom", name="Dataset")
22+
# Dynamic class is not handled so make it Any for now: https://github.com/python/mypy/issues/2477
23+
Dataset: Any = Dataset_
24+
TagType_, _ = optional_import("pydicom.tag", name="TagType")
25+
# Dynamic class is not handled so make it Any for now: https://github.com/python/mypy/issues/2477
26+
TagType: Any = TagType_
2427

2528

2629
class DICOMSOPInstance(Domain):
@@ -31,12 +34,12 @@ class DICOMSOPInstance(Domain):
3134

3235
def __init__(self, native_sop):
3336
super().__init__(None)
34-
self._sop = native_sop
37+
self._sop: Any = native_sop
3538

3639
def get_native_sop_instance(self):
3740
return self._sop
3841

39-
def __getitem__(self, key: Union[int, slice, "TagType"]) -> Union["Dataset", "DataElement"]:
42+
def __getitem__(self, key: Union[int, slice, TagType]) -> Union[Dataset, DataElement]:
4043
return self._sop.__getitem__(key)
4144

4245
def get_pixel_array(self):

monai/deploy/core/domain/dicom_study.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# limitations under the License.
1111

1212

13+
from typing import Any
14+
1315
from .domain import Domain
1416

1517

@@ -24,6 +26,12 @@ def __init__(self, study_instance_uid):
2426
self._study_instance_uid = study_instance_uid
2527
self._series_dict = {}
2628

29+
self._study_id: Any = None
30+
self._study_date: Any = None
31+
self._study_time: Any = None
32+
self._study_description: Any = None
33+
self._accession_number: Any = None
34+
2735
def get_study_instance_uid(self):
2836
return self._study_instance_uid
2937

@@ -35,43 +43,43 @@ def get_all_series(self):
3543

3644
@property
3745
def study_id(self):
38-
return self.__study_id
46+
return self._study_id
3947

4048
@study_id.setter
4149
def study_id(self, val):
42-
self.__study_id = val
50+
self._study_id = val
4351

4452
@property
4553
def study_date(self):
46-
return self.__study_date
54+
return self._study_date
4755

4856
@study_date.setter
4957
def study_date(self, val):
50-
self.__study_date = val
58+
self._study_date = val
5159

5260
@property
5361
def study_time(self):
54-
return self.__study_time
62+
return self._study_time
5563

5664
@study_time.setter
5765
def study_time(self, val):
58-
self.__study_time = val
66+
self._study_time = val
5967

6068
@property
6169
def study_description(self):
62-
return self.__study_description
70+
return self._study_description
6371

6472
@study_description.setter
6573
def study_description(self, val):
66-
self.__study_description = val
74+
self._study_description = val
6775

6876
@property
6977
def accession_number(self):
70-
return self.__accession_number
78+
return self._accession_number
7179

7280
@accession_number.setter
7381
def accession_number(self, val):
74-
self.__accession_number = val
82+
self._accession_number = val
7583

7684
def __str__(self):
7785
result = "---------------" + "\n"

monai/deploy/core/domain/domain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ def __init__(self, metadata: Optional[Dict] = None):
2929
else:
3030
self._metadata = {}
3131

32-
def metadata(self) -> Optional[Dict]:
32+
def metadata(self) -> Dict:
3333
return self._metadata

monai/deploy/operators/dicom_data_loader_operator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# limitations under the License.
1111

1212
import os
13+
from typing import List
1314

1415
from monai.deploy.core import (
1516
DataPath,
@@ -48,13 +49,13 @@ def compute(self, input: InputContext, output: OutputContext, context: Execution
4849
It groups them by a collection of studies where each study contains one or more series.
4950
This method returns a set of studies.
5051
"""
51-
files = []
52+
files: List[str] = []
5253
input_path = input.get().path
5354
self._list_files(input_path, files)
5455
dicom_study_list = self._load_data(files)
5556
output.set(dicom_study_list)
5657

57-
def _list_files(self, path, files):
58+
def _list_files(self, path, files: List[str]):
5859
"""Collects fully qualified names of all files recurvisely given a directory path.
5960
6061
Args:
@@ -68,7 +69,7 @@ def _list_files(self, path, files):
6869
else:
6970
files.append(item)
7071

71-
def _load_data(self, files):
72+
def _load_data(self, files: List[str]):
7273
"""Provides a list of DICOM Studies given a list of fully qualified file names.
7374
7475
Args:

0 commit comments

Comments
 (0)