Skip to content

Commit d0b2c47

Browse files
committed
Fix mypy type errors in SpatialCropd
Signed-off-by: Emanuilo Jovanovic <emanuilo.jovanovic@hotmail.com>
1 parent 91f40d0 commit d0b2c47

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

monai/transforms/croppad/dictionary.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from collections.abc import Callable, Hashable, Mapping, Sequence
2121
from copy import deepcopy
22-
from typing import Any
22+
from typing import Any, Optional, Union, cast
2323

2424
import numpy as np
2525
import torch
@@ -486,7 +486,15 @@ def __init__(
486486
self._has_str_roi = any(isinstance(v, str) for v in [roi_center, roi_size, roi_start, roi_end])
487487

488488
if not self._has_str_roi:
489-
cropper = SpatialCrop(roi_center, roi_size, roi_start, roi_end, roi_slices, lazy=lazy)
489+
_Roi = Optional[Union[Sequence[int], int]]
490+
cropper = SpatialCrop(
491+
cast(_Roi, roi_center),
492+
cast(_Roi, roi_size),
493+
cast(_Roi, roi_start),
494+
cast(_Roi, roi_end),
495+
roi_slices,
496+
lazy=lazy,
497+
)
490498
else:
491499
# Placeholder cropper for the string-key path. Replaced on self.cropper at
492500
# __call__ time once string keys are resolved from the data dictionary.
@@ -583,7 +591,7 @@ def inverse(self, data: Mapping[Hashable, MetaTensor]) -> dict[Hashable, MetaTen
583591
cropped = transform[TraceKeys.EXTRA_INFO]["cropped"]
584592
inverse_transform = BorderPad(cropped)
585593
with inverse_transform.trace_transform(False):
586-
d[key] = inverse_transform(d[key])
594+
d[key] = inverse_transform(d[key]) # type: ignore[assignment]
587595
return d
588596

589597

0 commit comments

Comments
 (0)