Skip to content

Commit 1919bb6

Browse files
committed
pyupgrade
1 parent 5d78657 commit 1919bb6

36 files changed

Lines changed: 1420 additions & 1455 deletions

src/highdicom/_iods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
from typing import Dict, List
55

6-
IOD_MODULE_MAP: Dict[str, List[Dict[str, str]]] = {
6+
IOD_MODULE_MAP: dict[str, list[dict[str, str]]] = {
77
"12-lead-ecg": [
88
{
99
"ie": "Patient",

src/highdicom/_module_utils.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from enum import Enum
2-
from typing import Any, Dict, List, Optional, Sequence, Union
2+
from typing import Any, Dict, List, Optional, Union
3+
from collections.abc import Sequence
34

45
from pydicom import Dataset
56

@@ -28,7 +29,7 @@ class ModuleUsageValues(Enum):
2829
def check_required_attributes(
2930
dataset: Dataset,
3031
module: str,
31-
base_path: Optional[Sequence[str]] = None,
32+
base_path: Sequence[str] | None = None,
3233
recursive: bool = True,
3334
check_optional_sequences: bool = True
3435
) -> None:
@@ -98,8 +99,8 @@ def check_required_attributes(
9899
# Define recursive function
99100
def check(
100101
dataset: Dataset,
101-
subtree: Dict[str, Any],
102-
path: List[str]
102+
subtree: dict[str, Any],
103+
path: list[str]
103104
) -> None:
104105
for kw, item in subtree['attributes'].items():
105106
required = item['type'] in types_to_check
@@ -140,7 +141,7 @@ def check(
140141
check(dataset, tree, [])
141142

142143

143-
def construct_module_tree(module: str) -> Dict[str, Any]:
144+
def construct_module_tree(module: str) -> dict[str, Any]:
144145
"""Return module attributes arranged in a tree structure.
145146
146147
Parameters
@@ -164,7 +165,7 @@ def construct_module_tree(module: str) -> Dict[str, Any]:
164165
from highdicom._modules import MODULE_ATTRIBUTE_MAP
165166
if module not in MODULE_ATTRIBUTE_MAP:
166167
raise AttributeError(f"No such module found: '{module}'.")
167-
tree: Dict[str, Any] = {'attributes': {}}
168+
tree: dict[str, Any] = {'attributes': {}}
168169
for item in MODULE_ATTRIBUTE_MAP[module]:
169170
location = tree['attributes']
170171
for p in item['path']:
@@ -180,7 +181,7 @@ def construct_module_tree(module: str) -> Dict[str, Any]:
180181
def get_module_usage(
181182
module_key: str,
182183
sop_class_uid: str
183-
) -> Union[ModuleUsageValues, None]:
184+
) -> ModuleUsageValues | None:
184185
"""Get the usage (M/C/U) of a module within an IOD.
185186
186187
Parameters

src/highdicom/_modules.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""DICOM modulesauto-generated on 2024-10-04 at 14:31:17."""
2-
from typing import Dict, List, Sequence, Union
2+
from typing import Dict, List, Union
3+
from collections.abc import Sequence
34

4-
MODULE_ATTRIBUTE_MAP: Dict[str, List[Dict[str, Union[str, Sequence[str]]]]] = {
5+
MODULE_ATTRIBUTE_MAP: dict[str, list[dict[str, str | Sequence[str]]]] = {
56
"acquisition-context": [
67
{
78
"keyword": "AcquisitionContextSequence",

src/highdicom/ann/content.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Content that is specific to Annotation IODs."""
22
from copy import deepcopy
3-
from typing import cast, List, Optional, Sequence, Tuple, Union
3+
from typing import cast
4+
from collections.abc import Sequence
45
from typing_extensions import Self
56

67
import numpy as np
@@ -24,9 +25,9 @@ class Measurements(Dataset):
2425

2526
def __init__(
2627
self,
27-
name: Union[Code, CodedConcept],
28+
name: Code | CodedConcept,
2829
values: np.ndarray,
29-
unit: Union[Code, CodedConcept]
30+
unit: Code | CodedConcept
3031
) -> None:
3132
"""
3233
Parameters
@@ -178,22 +179,22 @@ def __init__(
178179
number: int,
179180
uid: str,
180181
label: str,
181-
annotated_property_category: Union[Code, CodedConcept],
182-
annotated_property_type: Union[Code, CodedConcept],
183-
graphic_type: Union[str, GraphicTypeValues],
182+
annotated_property_category: Code | CodedConcept,
183+
annotated_property_type: Code | CodedConcept,
184+
graphic_type: str | GraphicTypeValues,
184185
graphic_data: Sequence[np.ndarray],
185-
algorithm_type: Union[str, AnnotationGroupGenerationTypeValues],
186-
algorithm_identification: Optional[
186+
algorithm_type: str | AnnotationGroupGenerationTypeValues,
187+
algorithm_identification: None | (
187188
AlgorithmIdentificationSequence
188-
] = None,
189-
measurements: Optional[Sequence[Measurements]] = None,
190-
description: Optional[str] = None,
191-
anatomic_regions: Optional[
192-
Sequence[Union[Code, CodedConcept]]
193-
] = None,
194-
primary_anatomic_structures: Optional[
195-
Sequence[Union[Code, CodedConcept]]
196-
] = None
189+
) = None,
190+
measurements: Sequence[Measurements] | None = None,
191+
description: str | None = None,
192+
anatomic_regions: None | (
193+
Sequence[Code | CodedConcept]
194+
) = None,
195+
primary_anatomic_structures: None | (
196+
Sequence[Code | CodedConcept]
197+
) = None
197198
):
198199
"""
199200
Parameters
@@ -479,7 +480,7 @@ def algorithm_type(self) -> AnnotationGroupGenerationTypeValues:
479480
@property
480481
def algorithm_identification(
481482
self
482-
) -> Union[AlgorithmIdentificationSequence, None]:
483+
) -> AlgorithmIdentificationSequence | None:
483484
"""Union[highdicom.AlgorithmIdentificationSequence, None]:
484485
Information useful for identification of the algorithm, if any.
485486
@@ -489,7 +490,7 @@ def algorithm_identification(
489490
return None
490491

491492
@property
492-
def anatomic_regions(self) -> List[CodedConcept]:
493+
def anatomic_regions(self) -> list[CodedConcept]:
493494
"""List[highdicom.sr.CodedConcept]:
494495
List of anatomic regions into which the annotations fall.
495496
May be empty.
@@ -500,7 +501,7 @@ def anatomic_regions(self) -> List[CodedConcept]:
500501
return list(self.AnatomicRegionSequence)
501502

502503
@property
503-
def primary_anatomic_structures(self) -> List[CodedConcept]:
504+
def primary_anatomic_structures(self) -> list[CodedConcept]:
504505
"""List[highdicom.sr.CodedConcept]:
505506
List of anatomic structures the annotations represent.
506507
May be empty.
@@ -512,8 +513,8 @@ def primary_anatomic_structures(self) -> List[CodedConcept]:
512513

513514
def get_graphic_data(
514515
self,
515-
coordinate_type: Union[str, AnnotationCoordinateTypeValues]
516-
) -> List[np.ndarray]:
516+
coordinate_type: str | AnnotationCoordinateTypeValues
517+
) -> list[np.ndarray]:
517518
"""Get spatial coordinates of all graphical annotations.
518519
519520
Parameters
@@ -582,10 +583,10 @@ def get_graphic_data(
582583
GraphicTypeValues.ELLIPSE,
583584
):
584585
# Fixed 4 coordinates per object
585-
split_param: Union[
586-
int,
586+
split_param: (
587+
int |
587588
Sequence[int]
588-
] = len(decoded_coordinates_data) // 4
589+
) = len(decoded_coordinates_data) // 4
589590
elif graphic_type == GraphicTypeValues.POINT:
590591
# Fixed 1 coordinate per object
591592
split_param = len(decoded_coordinates_data)
@@ -619,7 +620,7 @@ def get_graphic_data(
619620
def get_coordinates(
620621
self,
621622
annotation_number: int,
622-
coordinate_type: Union[str, AnnotationCoordinateTypeValues]
623+
coordinate_type: str | AnnotationCoordinateTypeValues
623624
) -> np.ndarray:
624625
"""Get spatial coordinates of a graphical annotation.
625626
@@ -653,9 +654,9 @@ def number_of_annotations(self) -> int:
653654

654655
def get_measurements(
655656
self,
656-
name: Optional[Union[Code, CodedConcept]] = None
657-
) -> Tuple[
658-
List[CodedConcept], np.ndarray, List[CodedConcept]
657+
name: Code | CodedConcept | None = None
658+
) -> tuple[
659+
list[CodedConcept], np.ndarray, list[CodedConcept]
659660
]:
660661
"""Get measurements.
661662

src/highdicom/ann/sop.py

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77
Any,
88
BinaryIO,
99
cast,
10-
Dict,
11-
List,
12-
Optional,
13-
Sequence,
14-
Tuple,
15-
Union,
1610
)
11+
from collections.abc import Sequence
1712
from typing_extensions import Self
1813

1914
import numpy as np
@@ -46,24 +41,24 @@ class MicroscopyBulkSimpleAnnotations(SOPClass):
4641
def __init__(
4742
self,
4843
source_images: Sequence[Dataset],
49-
annotation_coordinate_type: Union[str, AnnotationCoordinateTypeValues],
44+
annotation_coordinate_type: str | AnnotationCoordinateTypeValues,
5045
annotation_groups: Sequence[AnnotationGroup],
5146
series_instance_uid: str,
5247
series_number: int,
5348
sop_instance_uid: str,
5449
instance_number: int,
5550
manufacturer: str,
5651
manufacturer_model_name: str,
57-
software_versions: Union[str, Tuple[str]],
52+
software_versions: str | tuple[str],
5853
device_serial_number: str,
59-
content_description: Optional[str] = None,
60-
content_creator_name: Optional[Union[str, PersonName]] = None,
61-
transfer_syntax_uid: Union[str, UID] = ExplicitVRLittleEndian,
62-
pixel_origin_interpretation: Union[
63-
str,
54+
content_description: str | None = None,
55+
content_creator_name: str | PersonName | None = None,
56+
transfer_syntax_uid: str | UID = ExplicitVRLittleEndian,
57+
pixel_origin_interpretation: (
58+
str |
6459
PixelOriginInterpretationValues
65-
] = PixelOriginInterpretationValues.VOLUME,
66-
content_label: Optional[str] = None,
60+
) = PixelOriginInterpretationValues.VOLUME,
61+
content_label: str | None = None,
6762
**kwargs: Any
6863
) -> None:
6964
"""
@@ -207,14 +202,14 @@ def __init__(
207202
ref.ReferencedSOPInstanceUID = src_img.SOPInstanceUID
208203
self.ReferencedImageSequence = [ref]
209204

210-
referenced_series: Dict[str, List[Dataset]] = defaultdict(list)
205+
referenced_series: dict[str, list[Dataset]] = defaultdict(list)
211206
for img in source_images:
212207
ref = Dataset()
213208
ref.ReferencedSOPClassUID = img.SOPClassUID
214209
ref.ReferencedSOPInstanceUID = img.SOPInstanceUID
215210
referenced_series[img.SeriesInstanceUID].append(ref)
216211

217-
self.ReferencedSeriesSequence: List[Dataset] = []
212+
self.ReferencedSeriesSequence: list[Dataset] = []
218213
for series_instance_uid, referenced_images in referenced_series.items():
219214
ref = Dataset()
220215
ref.SeriesInstanceUID = series_instance_uid
@@ -238,8 +233,8 @@ def __init__(
238233

239234
def get_annotation_group(
240235
self,
241-
number: Optional[int] = None,
242-
uid: Optional[Union[str, UID]] = None,
236+
number: int | None = None,
237+
uid: str | UID | None = None,
243238
) -> AnnotationGroup:
244239
"""Get an individual annotation group.
245240
@@ -303,17 +298,17 @@ def get_annotation_group(
303298

304299
def get_annotation_groups(
305300
self,
306-
annotated_property_category: Optional[Union[Code, CodedConcept]] = None,
307-
annotated_property_type: Optional[Union[Code, CodedConcept]] = None,
308-
label: Optional[str] = None,
309-
graphic_type: Optional[Union[str, GraphicTypeValues]] = None,
310-
algorithm_type: Optional[
311-
Union[str, AnnotationGroupGenerationTypeValues]
312-
] = None,
313-
algorithm_name: Optional[str] = None,
314-
algorithm_family: Optional[Union[Code, CodedConcept]] = None,
315-
algorithm_version: Optional[str] = None,
316-
) -> List[AnnotationGroup]:
301+
annotated_property_category: Code | CodedConcept | None = None,
302+
annotated_property_type: Code | CodedConcept | None = None,
303+
label: str | None = None,
304+
graphic_type: str | GraphicTypeValues | None = None,
305+
algorithm_type: None | (
306+
str | AnnotationGroupGenerationTypeValues
307+
) = None,
308+
algorithm_name: str | None = None,
309+
algorithm_family: Code | CodedConcept | None = None,
310+
algorithm_version: str | None = None,
311+
) -> list[AnnotationGroup]:
317312
"""Get annotation groups matching search criteria.
318313
319314
Parameters
@@ -462,7 +457,7 @@ def from_dataset(
462457

463458

464459
def annread(
465-
fp: Union[str, bytes, PathLike, BinaryIO],
460+
fp: str | bytes | PathLike | BinaryIO,
466461
) -> MicroscopyBulkSimpleAnnotations:
467462
"""Read a bulk annotations object stored in DICOM File Format.
468463

0 commit comments

Comments
 (0)