Skip to content

Commit 6716cd6

Browse files
refactor(api): Use new labware features even when the labware is schema 2 (#17785)
1 parent 711c6b4 commit 6716cd6

File tree

3 files changed

+17
-46
lines changed

3 files changed

+17
-46
lines changed

api/src/opentrons/protocol_engine/commands/load_labware.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55

66
from pydantic import BaseModel, Field
77
from pydantic.json_schema import SkipJsonSchema
8-
from typing_extensions import Literal, TypeGuard, assert_type
8+
from typing_extensions import Literal, TypeGuard
99

10-
from opentrons_shared_data.labware.labware_definition import (
11-
LabwareDefinition,
12-
LabwareDefinition2,
13-
LabwareDefinition3,
14-
)
10+
from opentrons_shared_data.labware.labware_definition import LabwareDefinition
1511

1612
from ..errors import LabwareIsNotAllowedInLocationError
1713
from ..resources import labware_validation, fixture_validation
@@ -107,7 +103,7 @@ def _is_loading_to_module(
107103
module: LoadedModule = self._state_view.modules.get(location.moduleId)
108104
return module.model == module_model
109105

110-
async def execute( # noqa: C901
106+
async def execute(
111107
self, params: LoadLabwareParams
112108
) -> SuccessData[LoadLabwareResult]:
113109
"""Load definition and calibration data necessary for a labware."""
@@ -175,18 +171,13 @@ async def execute( # noqa: C901
175171
):
176172
# This parent is assumed to be compatible, unless the lid enumerates
177173
# all its compatible parents and this parent is missing from the list.
178-
if isinstance(loaded_labware.definition, LabwareDefinition2):
179-
# Labware schema 2 has no compatibleParentLabware list.
180-
parent_is_incompatible = False
181-
else:
182-
assert_type(loaded_labware.definition, LabwareDefinition3)
183-
parent_is_incompatible = (
184-
loaded_labware.definition.compatibleParentLabware is not None
185-
and self._state_view.labware.get_load_name(
186-
verified_location.labwareId
187-
)
188-
not in loaded_labware.definition.compatibleParentLabware
174+
parent_is_incompatible = (
175+
loaded_labware.definition.compatibleParentLabware is not None
176+
and self._state_view.labware.get_load_name(
177+
verified_location.labwareId
189178
)
179+
not in loaded_labware.definition.compatibleParentLabware
180+
)
190181

191182
if parent_is_incompatible:
192183
raise ValueError(

api/src/opentrons/protocol_engine/execution/equipment.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22

33
from dataclasses import dataclass
44
from typing import Optional, overload, List
5-
from typing_extensions import assert_type
65

7-
from opentrons_shared_data.labware.labware_definition import (
8-
LabwareDefinition,
9-
LabwareDefinition2,
10-
LabwareDefinition3,
11-
)
6+
from opentrons_shared_data.labware.labware_definition import LabwareDefinition
127
from opentrons_shared_data.pipette.types import PipetteNameType
138

149
from opentrons.calibration_storage.helpers import uri_from_details
@@ -441,7 +436,7 @@ async def load_module(
441436
definition=attached_module.definition,
442437
)
443438

444-
async def load_lids( # noqa: C901
439+
async def load_lids(
445440
self,
446441
load_name: str,
447442
namespace: str,
@@ -489,15 +484,11 @@ async def load_lids( # noqa: C901
489484
f"Requested quantity {quantity} is greater than the stack limit of {stack_limit} provided by definition for {load_name}."
490485
)
491486

492-
if isinstance(definition, LabwareDefinition2):
493-
is_deck_slot_compatible = True
494-
else:
495-
assert_type(definition, LabwareDefinition3)
496-
is_deck_slot_compatible = (
497-
True
498-
if definition.parameters.isDeckSlotCompatible is None
499-
else definition.parameters.isDeckSlotCompatible
500-
)
487+
is_deck_slot_compatible = (
488+
True
489+
if definition.parameters.isDeckSlotCompatible is None
490+
else definition.parameters.isDeckSlotCompatible
491+
)
501492

502493
if isinstance(location, DeckSlotLocation) and not is_deck_slot_compatible:
503494
raise ValueError(

api/src/opentrons/protocol_engine/state/labware.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@
2323
from opentrons_shared_data.labware.labware_definition import (
2424
InnerWellGeometry,
2525
LabwareDefinition,
26-
LabwareDefinition2,
2726
LabwareRole,
2827
WellDefinition2,
2928
WellDefinition3,
30-
CircularWellDefinition2,
31-
RectangularWellDefinition2,
3229
)
3330
from opentrons_shared_data.pipette.types import LabwareUri
3431

@@ -684,19 +681,11 @@ def get_well_geometry(
684681
) -> InnerWellGeometry:
685682
"""Get a well's inner geometry by labware and well name."""
686683
labware_def = self.get_definition(labware_id)
687-
if (
688-
isinstance(labware_def, LabwareDefinition2)
689-
or labware_def.innerLabwareGeometry is None
690-
):
684+
if labware_def.innerLabwareGeometry is None:
691685
raise errors.IncompleteLabwareDefinitionError(
692686
message=f"No innerLabwareGeometry found in labware definition for labware_id: {labware_id}."
693687
)
694688
well_def = self.get_well_definition(labware_id, well_name)
695-
# Assert for type-checking. We expect the well definitions from schema *3*, specifically.
696-
# This should always pass because we exclude LabwareDefinition2 above.
697-
assert not isinstance(
698-
well_def, (RectangularWellDefinition2, CircularWellDefinition2)
699-
)
700689
geometry_id = well_def.geometryDefinitionId
701690
if geometry_id is None:
702691
raise errors.IncompleteWellDefinitionError(

0 commit comments

Comments
 (0)