Code Duplication    Length = 14-15 lines in 2 locations

tests/transforms/test_custom_image_subclass_fix.py 1 location

@@ 9-23 (lines=15) @@
6
import torchio as tio
7
8
9
class HistoryScalarImage(tio.ScalarImage):
10
    """Custom ScalarImage subclass that stores history metadata."""
11
12
    def __init__(self, tensor, affine, history, **kwargs):
13
        super().__init__(tensor=tensor, affine=affine, **kwargs)
14
        self.history = history
15
16
    def new_like(self, tensor, affine=None):
17
        """Override new_like to preserve history attribute."""
18
        return type(self)(
19
            tensor=tensor,
20
            affine=affine if affine is not None else self.affine,
21
            history=self.history,  # Preserve custom attribute
22
            check_nans=self.check_nans,
23
            reader=self.reader,
24
        )
25
26

tests/transforms/test_custom_image_subclass.py 1 location

@@ 9-22 (lines=14) @@
6
import torchio as tio
7
8
9
class HistoryImage(tio.ScalarImage):
10
    """Test custom Image with required parameter."""
11
12
    def __init__(self, tensor, affine, history, **kwargs):
13
        super().__init__(tensor=tensor, affine=affine, **kwargs)
14
        self.history = history
15
16
    def new_like(self, tensor, affine=None):
17
        return type(self)(
18
            tensor=tensor,
19
            affine=affine if affine is not None else self.affine,
20
            history=self.history,
21
            check_nans=self.check_nans,
22
            reader=self.reader,
23
        )
24
25