Skip to content

Commit

Permalink
refactor(api): Enable more type-checking inside pipette_handler.py (#…
Browse files Browse the repository at this point in the history
…16523)

## Overview

Delete some `@overload`s that didn't seem like they were doing anything,
and reincorporate their parameter annotations into the main function
definitions.

Formerly, the main function bodies were mostly not type-checked because
the parameters didn't have annotations. (It's perhaps surprising that
they didn't automatically "inherit" the annotations from the
`@overload`s, but I guess mypy and pyright just don't work like that.)
This fixes that.

## Test Plan and Hands on Testing

None needed, just automated linting and tests.

## Review requests

Any reason not to do this?

## Risk assessment

Low.
  • Loading branch information
SyntaxColoring authored Oct 28, 2024
1 parent 24fcc0d commit 965bc0d
Showing 1 changed file with 11 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
Sequence,
Iterator,
TypeVar,
overload,
)
import numpy

Expand Down Expand Up @@ -503,25 +502,12 @@ def plunger_flowrate(
ul_per_s = mm_per_s * instr.ul_per_mm(instr.liquid_class.max_volume, action)
return round(ul_per_s, 6)

@overload
def plan_check_aspirate(
self, mount: top_types.Mount, volume: Optional[float], rate: float
) -> Optional[LiquidActionSpec]:
...

@overload
def plan_check_aspirate(
self, mount: OT3Mount, volume: Optional[float], rate: float
) -> Optional[LiquidActionSpec]:
...

# note on this type ignore: see motion_utilities
def plan_check_aspirate( # type: ignore[no-untyped-def]
self,
mount,
volume,
rate,
):
mount: MountType,
volume: Optional[float],
rate: float,
) -> Optional[LiquidActionSpec]:
"""Check preconditions for aspirate, parse args, and calculate positions.
While the mechanics of issuing an aspirate move itself are left to child
Expand Down Expand Up @@ -580,28 +566,12 @@ def plan_check_aspirate( # type: ignore[no-untyped-def]
current=instrument.plunger_motor_current.run,
)

@overload
def plan_check_dispense(
self,
mount: top_types.Mount,
volume: Optional[float],
rate: float,
push_out: Optional[float],
) -> Optional[LiquidActionSpec]:
...

@overload
def plan_check_dispense(
self,
mount: OT3Mount,
mount: MountType,
volume: Optional[float],
rate: float,
push_out: Optional[float],
) -> Optional[LiquidActionSpec]:
...

def plan_check_dispense( # type: ignore[no-untyped-def]
self, mount, volume, rate, push_out
) -> Optional[LiquidActionSpec]:
"""Check preconditions for dispense, parse args, and calculate positions.
Expand Down Expand Up @@ -695,15 +665,7 @@ def plan_check_dispense( # type: ignore[no-untyped-def]
current=instrument.plunger_motor_current.run,
)

@overload
def plan_check_blow_out(self, mount: top_types.Mount) -> LiquidActionSpec:
...

@overload
def plan_check_blow_out(self, mount: OT3Mount) -> LiquidActionSpec:
...

def plan_check_blow_out(self, mount): # type: ignore[no-untyped-def]
def plan_check_blow_out(self, mount: MountType) -> LiquidActionSpec:
"""Check preconditions and calculate values for blowout."""
instrument = self.get_pipette(mount)
speed = self.plunger_speed(
Expand Down Expand Up @@ -751,33 +713,13 @@ def build_one_shake() -> List[Tuple[top_types.Point, Optional[float]]]:
else:
return []

@overload
def plan_check_pick_up_tip(
self,
mount: top_types.Mount,
presses: Optional[int],
increment: Optional[float],
tip_length: float = 0,
) -> Tuple[PickUpTipSpec, Callable[[], None]]:
...

@overload
def plan_check_pick_up_tip(
self,
mount: OT3Mount,
mount: MountType,
presses: Optional[int],
increment: Optional[float],
tip_length: float = 0,
) -> Tuple[PickUpTipSpec, Callable[[], None]]:
...

def plan_check_pick_up_tip( # type: ignore[no-untyped-def]
self,
mount,
presses,
increment,
tip_length=0,
):
# Prechecks: ready for pickup tip and press/increment are valid
instrument = self.get_pipette(mount)
if instrument.has_tip:
Expand Down Expand Up @@ -925,25 +867,13 @@ def build() -> List[DropTipMove]:

return build

@overload
def plan_check_drop_tip(
self, mount: top_types.Mount, home_after: bool
) -> Tuple[DropTipSpec, Callable[[], None]]:
...

@overload
def plan_check_drop_tip(
self, mount: OT3Mount, home_after: bool
) -> Tuple[DropTipSpec, Callable[[], None]]:
...

# todo(mm, 2024-10-17): The returned _remove_tips() callable is not used by anything
# anymore. Delete it.
def plan_check_drop_tip( # type: ignore[no-untyped-def]
def plan_check_drop_tip(
self,
mount,
home_after,
):
mount: MountType,
home_after: bool,
) -> Tuple[DropTipSpec, Callable[[], None]]:
instrument = self.get_pipette(mount)

if not instrument.drop_configurations.plunger_eject:
Expand Down

0 comments on commit 965bc0d

Please sign in to comment.