diff --git a/api/src/opentrons/protocol_engine/state/tips.py b/api/src/opentrons/protocol_engine/state/tips.py index 2de48fa27c3..2c8e33b381b 100644 --- a/api/src/opentrons/protocol_engine/state/tips.py +++ b/api/src/opentrons/protocol_engine/state/tips.py @@ -124,7 +124,9 @@ def _handle_command(self, command: Command) -> None: pipette_id = command.params.pipetteId self._state.length_by_pipette_id.pop(pipette_id, None) - def _set_used_tips(self, pipette_id: str, well_name: str, labware_id: str) -> None: + def _set_used_tips( # noqa: C901 + self, pipette_id: str, well_name: str, labware_id: str + ) -> None: columns = self._state.column_by_labware_id.get(labware_id, []) wells = self._state.tips_by_labware_id.get(labware_id, {}) nozzle_map = self._state.nozzle_map_by_pipette_id[pipette_id] @@ -143,17 +145,25 @@ def _set_used_tips(self, pipette_id: str, well_name: str, labware_id: str) -> No for i in range(num_nozzle_cols): for j in range(num_nozzle_rows): if nozzle_map.starting_nozzle == "A1": - well = columns[critical_column + i][critical_row + j] - wells[well] = TipRackWellState.USED + if (critical_column + i < len(columns)) and ( + critical_row + j < len(columns[critical_column]) + ): + well = columns[critical_column + i][critical_row + j] + wells[well] = TipRackWellState.USED elif nozzle_map.starting_nozzle == "A12": - well = columns[critical_column + i][critical_row - j] - wells[well] = TipRackWellState.USED + if (critical_column - i >= 0) and ( + critical_row + j < len(columns[critical_column]) + ): + well = columns[critical_column - i][critical_row + j] + wells[well] = TipRackWellState.USED elif nozzle_map.starting_nozzle == "H1": - well = columns[critical_column - i][critical_row + j] - wells[well] = TipRackWellState.USED + if (critical_column + i < len(columns)) and (critical_row - j >= 0): + well = columns[critical_column + i][critical_row - j] + wells[well] = TipRackWellState.USED elif nozzle_map.starting_nozzle == "H12": - well = columns[critical_column - i][critical_row - j] - wells[well] = TipRackWellState.USED + if (critical_column - i >= 0) and (critical_row - j >= 0): + well = columns[critical_column - i][critical_row - j] + wells[well] = TipRackWellState.USED class TipView(HasState[TipState]):