diff options
| author | tslil <tslil@posteo.de> | 2025-10-17 20:35:53 +0100 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2025-10-17 23:48:42 +0100 |
| commit | a775b8f56e5422e47c40927328baf3045c500a32 (patch) | |
| tree | fc003854fb4bc7e3b0cb815034540536a5fd286e /python/src/types/selection.py | |
| parent | 1376a23bda5e6fe94148cb57ca1447907c6bb21e (diff) | |
Starting on RIIR, first steps have been whelming
Diffstat (limited to 'python/src/types/selection.py')
| -rw-r--r-- | python/src/types/selection.py | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/python/src/types/selection.py b/python/src/types/selection.py index 478b5b9..d75c9f0 100644 --- a/python/src/types/selection.py +++ b/python/src/types/selection.py @@ -38,15 +38,13 @@ class Selection: @classmethod def empty(cls) -> "Selection": - return cls(selection=Position(0), buffers=set()) + return cls(selection=Ranges(ranges=[]), buffers=set()) def promote(self, to_rank: int) -> "Selection": if to_rank < 0 or to_rank > 3: raise ValueError(f"Invalid rank: {to_rank}") if self.rank > to_rank: - raise ValueError( - f"Cannot coerce selection of rank {self.rank} to rank {to_rank}" - ) + raise ValueError(f"Cannot coerce selection of rank {self.rank} to rank {to_rank}") if self.rank == to_rank: return self match self.selection: @@ -61,22 +59,16 @@ class Selection: if to_rank == 2: return Selection(selection=as_ranges, buffers=self.buffers) if to_rank == 3: - return Selection( - MultiRanges({buffer: as_ranges for buffer in self.buffers}) - ) + return Selection(MultiRanges({buffer: as_ranges for buffer in self.buffers})) case Range(_, _): as_ranges = Ranges(ranges=[self.selection]) if to_rank == 2: return Selection(selection=as_ranges, buffers=self.buffers) if to_rank == 3: - return Selection( - MultiRanges({buffer: as_ranges for buffer in self.buffers}) - ) + return Selection(MultiRanges({buffer: as_ranges for buffer in self.buffers})) case Ranges(_): - return Selection( - MultiRanges({buffer: self.selection for buffer in self.buffers}) - ) - + return Selection(MultiRanges({buffer: self.selection for buffer in self.buffers})) + raise RuntimeError("Unexpected promotion issue") @classmethod @@ -101,7 +93,7 @@ class Selection: if max_rank == 2: all_ranges = [] for sel in promoted: - if not type(sel.selection) is Ranges: + if type(sel.selection) is not Ranges: raise ValueError( f"Selection of rank {sel.rank} is not a range. Should have been promoted to rank 2." ) @@ -111,7 +103,7 @@ class Selection: if max_rank == 3: buffer_ranges: dict[Buffer, list[Range]] = {buf: [] for buf in all_buffers} for sel in promoted: - if not type(sel.selection) is MultiRanges: + if type(sel.selection) is not MultiRanges: raise ValueError( f"Selection of rank {sel.rank} is not a multi-range. Should have been promoted to rank 3." ) |
