Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): fix InstrumentContext.name for Flex and update LiquidClass.get_for() #17289

Merged
merged 10 commits into from
Jan 30, 2025
Prev Previous commit
Next Next commit
change from 'tipracks' to 'tip_racks'
sanni-t committed Jan 29, 2025
commit e548bdc702b7efad2168b6fe1799962920922c94
12 changes: 6 additions & 6 deletions api/src/opentrons/protocol_api/_liquid.py
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ def display_name(self) -> str:
return self._display_name

def get_for(
self, pipette: Union[str, InstrumentContext], tiprack: Union[str, Labware]
self, pipette: Union[str, InstrumentContext], tip_rack: Union[str, Labware]
) -> TransferProperties:
"""Get liquid class transfer properties for the specified pipette and tip."""
from . import InstrumentContext, Labware
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we just import this at the top of the file (and get rid of the if TYPE_CHECKING bit)?

You are clearly using the symbols InstrumentContext and Labware in your implementation (versus only importing it for the typechecker), so why not treat it as a normal import?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding to this, I can see limited use of getting liquid class properties without having to provide the names, but I'd almost rather that be it's own function which would allow us to remove this internal import. That or we could always flip around the isinstance to check for str instead of InstrumentContext or Labware

Copy link
Member Author

@sanni-t sanni-t Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we just import this at the top of the file (and get rid of the if TYPE_CHECKING bit)?

Because it results in a circular import for InstrumentContext. InstrumentContext already imports from _liquid.

I can see limited use of getting liquid class properties without having to provide the names, but I'd almost rather that be it's own function

Not sure I understand. Can you elaborate?

That or we could always flip around the isinstance to check for str instead of InstrumentContext or Labware

If we want to verify that the args are not of some third, unsupported type then we will have to check if isinstance of InstrumentContext and Labware. Sure we can maybe check that if it's not a string and if there's an error doing pipette.load_name or tiprack.uri, the args are wrong. But it's not as foolproof as doing isinstance checks.

@@ -83,13 +83,13 @@ def get_for(
f" or a pipette name string."
)

if isinstance(tiprack, Labware):
tiprack_uri = tiprack.uri
elif isinstance(tiprack, str):
tiprack_uri = tiprack
if isinstance(tip_rack, Labware):
tiprack_uri = tip_rack.uri
elif isinstance(tip_rack, str):
tiprack_uri = tip_rack
else:
raise ValueError(
f"{tiprack} should either be a tiprack Labware object"
f"{tip_rack} should either be a tiprack Labware object"
f" or a tiprack URI string."
)

3 changes: 1 addition & 2 deletions api/src/opentrons/protocol_api/core/engine/instrument.py
Original file line number Diff line number Diff line change
@@ -997,8 +997,7 @@ def transfer_liquid( # noqa: C901
)
tiprack_uri_for_transfer_props = tip_racks[0][1].get_uri()
transfer_props = liquid_class.get_for(
pipette=self.get_pipette_name(),
tiprack=tiprack_uri_for_transfer_props,
pipette=self.get_pipette_name(), tip_rack=tiprack_uri_for_transfer_props
)
# TODO: use the ID returned by load_liquid_class in command annotations
self.load_liquid_class(
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ def sample_transfer_props(
) -> TransferProperties:
"""Return a mocked out liquid class fixture."""
return LiquidClass.create(maximal_liquid_class_def).get_for(
pipette="flex_1channel_50", tiprack="opentrons_flex_96_tiprack_50ul"
pipette="flex_1channel_50", tip_rack="opentrons_flex_96_tiprack_50ul"
)