Skip to content

Commit 18dd62d

Browse files
committed
Fix typing errors reported by mypy
1 parent 3b92850 commit 18dd62d

6 files changed

Lines changed: 15 additions & 13 deletions

File tree

src/highdicom/ann/content.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Content that is specific to Annotation IODs."""
22
from copy import deepcopy
3-
from typing import List, Optional, Sequence, Tuple, Union
3+
from typing import cast, List, Optional, Sequence, Tuple, Union
44

55
import numpy as np
66
from pydicom.dataset import Dataset
@@ -24,7 +24,7 @@ class Measurements(Dataset):
2424
def __init__(
2525
self,
2626
name: Union[Code, CodedConcept],
27-
values: np.array,
27+
values: np.ndarray,
2828
unit: Union[Code, CodedConcept]
2929
) -> None:
3030
"""
@@ -152,7 +152,7 @@ def from_dataset(cls, dataset: Dataset) -> 'Measurements':
152152
)
153153
]
154154

155-
return measurements
155+
return cast(Measurements, measurements)
156156

157157

158158
class AnnotationGroup(Dataset):
@@ -588,9 +588,9 @@ def get_measurements(
588588
if name is None or item.name == name
589589
]
590590
if len(values) > 0:
591-
values = np.vstack(values).T
591+
value_array = np.vstack(values).T
592592
else:
593-
values = np.empty((number_of_annotations, 0), np.float32)
593+
value_array = np.empty((number_of_annotations, 0), np.float32)
594594
names = [
595595
item.name for item in self.MeasurementsSequence
596596
if name is None or item.name == name
@@ -600,10 +600,10 @@ def get_measurements(
600600
if name is None or item.name == name
601601
]
602602
else:
603-
values = np.empty((number_of_annotations, 0), np.float32)
603+
value_array = np.empty((number_of_annotations, 0), np.float32)
604604
names = []
605605
units = []
606-
return (names, values, units)
606+
return (names, value_array, units)
607607

608608
def _get_coordinate_index(
609609
self,
@@ -726,4 +726,4 @@ def from_dataset(cls, dataset: Dataset) -> 'AnnotationGroup':
726726
for ds in group.PrimaryAnatomicStructureSequence
727727
]
728728

729-
return group
729+
return cast(AnnotationGroup, group)

src/highdicom/ann/sop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from collections import defaultdict
33
from copy import deepcopy
44
from operator import eq
5-
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
5+
from typing import Any, cast, Dict, List, Optional, Sequence, Tuple, Union
66

77
import numpy as np
88
from pydicom.dataset import Dataset
@@ -417,4 +417,4 @@ def from_dataset(
417417
for item in ann.AnnotationGroupSequence
418418
]
419419

420-
return ann
420+
return cast(MicroscopyBulkSimpleAnnotations, ann)

src/highdicom/ko/content.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def __init__(
112112
meaning='Source',
113113
)
114114
for ds in referenced_objects:
115+
reference_item: Union[ImageContentItem, CompositeContentItem]
115116
if 'Rows' in ds and 'Columns' in ds:
116117
reference_item = ImageContentItem(
117118
name=name,

src/highdicom/pm/sop.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def __init__(
470470
raise ValueError('Pixel array must be a 2D, 3D, or 4D array.')
471471

472472
# Acquisition Context
473-
self.AcquisitionContextSequence = []
473+
self.AcquisitionContextSequence: List[Dataset] = []
474474

475475
# Image Pixel
476476
self.Rows = pixel_array.shape[1]
@@ -784,7 +784,6 @@ def _encode_frame(self, pixel_array: np.ndarray) -> bytes:
784784
'in case of encapsulated format encoding.'
785785
)
786786
if self.file_meta.TransferSyntaxUID.is_encapsulated:
787-
# Check that only a single plane was passed
788787
return encode_frame(
789788
pixel_array,
790789
transfer_syntax_uid=self.file_meta.TransferSyntaxUID,

src/highdicom/sr/templates.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4023,6 +4023,7 @@ def get_planar_roi_measurement_groups(
40234023
matches.append(found_ref_type == reference_type)
40244024

40254025
if graphic_type is not None:
4026+
found_gt: Union[GraphicTypeValues, GraphicTypeValues3D]
40264027
if isinstance(graphic_type, GraphicTypeValues):
40274028
if ref_value_type == ValueTypeValues.SCOORD:
40284029
found_gt = GraphicTypeValues(ref_item.GraphicType)
@@ -4278,6 +4279,7 @@ def get_volumetric_roi_measurement_groups(
42784279
matches.append(found_ref_type == reference_type)
42794280

42804281
if graphic_type is not None:
4282+
found_gt: Union[GraphicTypeValues, GraphicTypeValues3D]
42814283
if isinstance(graphic_type, GraphicTypeValues):
42824284
if ref_value_type == ValueTypeValues.SCOORD:
42834285
found_gt = GraphicTypeValues(

src/highdicom/sr/value_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def _from_dataset_base(cls, dataset: Dataset) -> 'ContentItem':
218218
item.ConceptNameCodeSequence = [
219219
CodedConcept.from_dataset(item.ConceptNameCodeSequence[0])
220220
]
221-
return item
221+
return cast(ContentItem, item)
222222

223223
@property
224224
def name(self) -> CodedConcept:

0 commit comments

Comments
 (0)