Skip to content

Commit

Permalink
api typing fixups after updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoster1 committed Dec 7, 2023
1 parent 4cb7c08 commit edf46f6
Show file tree
Hide file tree
Showing 29 changed files with 203 additions and 181 deletions.
2 changes: 1 addition & 1 deletion api/src/opentrons/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import importlib_metadata as metadata # type: ignore[no-redef]

try:
version: str = metadata.version("opentrons") # type: ignore[attr-defined]
version: str = metadata.version("opentrons")
except Exception as e:
logging.warning(
"Could not determine version for opentrons, may be dev install, using 0.0.0-dev"
Expand Down
4 changes: 2 additions & 2 deletions api/src/opentrons/drivers/smoothie_drivers/driver_3_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ async def unstick_axes(
self.push_active_current()
self.set_active_current(
{
ax: self._config.high_current["default"][ax] # type: ignore[misc]
ax: self._config.high_current["default"][ax] # type: ignore[literal-required]
for ax in axes
}
)
Expand Down Expand Up @@ -1848,7 +1848,7 @@ async def hard_halt(self) -> None:
await asyncio.sleep(0.25)
self.run_flag.set()

async def update_firmware( # noqa: C901
async def update_firmware(
self,
filename: str,
loop: Optional[asyncio.AbstractEventLoop] = None,
Expand Down
5 changes: 2 additions & 3 deletions api/src/opentrons/hardware_control/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
"""
import asyncio
import functools
from typing import Generic, TypeVar, Callable, Any, cast
from typing import Generic, TypeVar, Callable, Any, cast, Awaitable
from .protocols import AsyncioConfigurable


WrappedObj = TypeVar("WrappedObj", bound=AsyncioConfigurable, covariant=True)
WrappedReturn = TypeVar("WrappedReturn")
WrappedFunc = TypeVar("WrappedFunc", bound=Callable[..., WrappedReturn])


# TODO: BC 2020-02-25 instead of overwriting __get_attribute__ in this class
Expand Down Expand Up @@ -54,7 +53,7 @@ def __repr__(self) -> str:
@staticmethod
def call_coroutine_sync(
loop: asyncio.AbstractEventLoop,
to_call: WrappedFunc,
to_call: Callable[..., Awaitable[WrappedReturn]],
*args: Any,
**kwargs: Any,
) -> WrappedReturn:
Expand Down
4 changes: 2 additions & 2 deletions api/src/opentrons/hardware_control/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def _update_door_state(self, door_state: DoorState) -> None:
def _reset_last_mount(self) -> None:
self._last_moved_mount = None

@classmethod # noqa: C901
async def build_hardware_controller(
@classmethod
async def build_hardware_controller( # noqa: C901
cls,
config: Union[RobotConfig, OT3Config, None] = None,
port: Optional[str] = None,
Expand Down
4 changes: 2 additions & 2 deletions api/src/opentrons/hardware_control/backends/ot3controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,8 @@ async def set_hold_current(self, axis_currents: OT3AxisMap[float]) -> None:
@asynccontextmanager
async def motor_current(
self,
run_currents: OT3AxisMap[float] = {},
hold_currents: OT3AxisMap[float] = {},
run_currents: Optional[OT3AxisMap[float]] = None,
hold_currents: Optional[OT3AxisMap[float]] = None,
) -> AsyncIterator[None]:
"""Update and restore current."""
assert self._current_settings
Expand Down
4 changes: 2 additions & 2 deletions api/src/opentrons/hardware_control/backends/ot3simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ async def set_active_current(self, axis_currents: OT3AxisMap[float]) -> None:
@asynccontextmanager
async def motor_current(
self,
run_currents: OT3AxisMap[float] = {},
hold_currents: OT3AxisMap[float] = {},
run_currents: Optional[OT3AxisMap[float]] = None,
hold_currents: Optional[OT3AxisMap[float]] = None,
) -> AsyncIterator[None]:
"""Save the current."""
yield
Expand Down
8 changes: 5 additions & 3 deletions api/src/opentrons/hardware_control/execution_manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import asyncio
import functools
from typing import Set, TypeVar, Type, cast, Callable, Any, Awaitable, overload
from typing import Set, TypeVar, Type, cast, Callable, Any, overload
from .types import ExecutionState
from opentrons_shared_data.errors.exceptions import ExecutionCancelledError
from collections.abc import Coroutine

TaskContents = TypeVar("TaskContents")

Expand Down Expand Up @@ -74,10 +75,11 @@ async def wait_for_is_running(self) -> None:

DecoratedReturn = TypeVar("DecoratedReturn")
DecoratedMethodReturningValue = TypeVar(
"DecoratedMethodReturningValue", bound=Callable[..., Awaitable[DecoratedReturn]]
"DecoratedMethodReturningValue",
bound=Callable[..., Coroutine[None, None, DecoratedReturn]],
)
DecoratedMethodNoReturn = TypeVar(
"DecoratedMethodNoReturn", bound=Callable[..., Awaitable[None]]
"DecoratedMethodNoReturn", bound=Callable[..., Coroutine[None, None, None]]
)
SubclassInstance = TypeVar("SubclassInstance", bound="ExecutionManagerProvider")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
LabwareDefinition as TypeDictLabwareDef,
)

# These type aliases aid typechecking in tests that work the same on this and
# the hardware_control.instruments.ot3 variant
SourceType = types.SourceType
CalibrationStatus = types.CalibrationStatus


@dataclass
class PipetteOffsetByPipetteMount:
Expand All @@ -25,8 +30,8 @@ class PipetteOffsetByPipetteMount:
"""

offset: Point
source: types.SourceType
status: types.CalibrationStatus
source: SourceType
status: CalibrationStatus
tiprack: typing.Optional[str] = None
uri: typing.Optional[str] = None
last_modified: typing.Optional[datetime] = None
Expand All @@ -44,15 +49,15 @@ class PipetteOffsetCalibration:
tiprack: str
uri: str
last_modified: datetime
source: types.SourceType
status: types.CalibrationStatus
source: SourceType
status: CalibrationStatus


@dataclass
class TipLengthCalibration:
tip_length: float
source: types.SourceType
status: types.CalibrationStatus
source: SourceType
status: CalibrationStatus
pipette: str
tiprack: str
last_modified: datetime
Expand All @@ -65,8 +70,8 @@ def load_pipette_offset(
# load default if pipette offset data do not exist
pip_cal_obj = PipetteOffsetByPipetteMount(
offset=Point(*default_pipette_offset()),
source=types.SourceType.default,
status=types.CalibrationStatus(),
source=SourceType.default,
status=CalibrationStatus(),
)
# TODO this can be removed once we switch to using
# ot3 pipette types in the ot3 hardware controller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@

PIPETTE_OFFSET_CONSISTENCY_LIMIT: Final = 1.5

# These type aliases aid typechecking in tests that work the same on this and
# the hardware_control.instruments.ot2 variant
SourceType = cal_top_types.SourceType
CalibrationStatus = cal_top_types.CalibrationStatus


@dataclass
class InconsistentPipetteOffsets:
Expand All @@ -41,8 +46,8 @@ class PipetteOffsetByPipetteMount:
"""

offset: Point
source: cal_top_types.SourceType
status: cal_top_types.CalibrationStatus
source: SourceType
status: CalibrationStatus
last_modified: typing.Optional[datetime] = None


Expand All @@ -63,8 +68,8 @@ class GripperCalibrationOffset:
"""

offset: Point
source: cal_top_types.SourceType
status: cal_top_types.CalibrationStatus
source: SourceType
status: CalibrationStatus
last_modified: typing.Optional[datetime] = None


Expand All @@ -74,8 +79,8 @@ def load_pipette_offset(
# load default if pipette offset data do not exist
pip_cal_obj = PipetteOffsetByPipetteMount(
offset=Point(*default_pipette_offset()),
source=cal_top_types.SourceType.default,
status=cal_top_types.CalibrationStatus(),
source=SourceType.default,
status=CalibrationStatus(),
)
# TODO this can be removed once we switch to using
# ot3 pipette types in the ot3 hardware controller.
Expand All @@ -90,7 +95,7 @@ def load_pipette_offset(
offset=pip_offset_data.offset,
last_modified=pip_offset_data.lastModified,
source=pip_offset_data.source,
status=cal_top_types.CalibrationStatus(
status=CalibrationStatus(
markedAt=pip_offset_data.status.markedAt,
markedBad=pip_offset_data.status.markedBad,
source=pip_offset_data.status.source,
Expand Down Expand Up @@ -118,8 +123,8 @@ def load_gripper_calibration_offset(
# load default if gripper offset data do not exist
grip_cal_obj = GripperCalibrationOffset(
offset=Point(*default_gripper_calibration_offset()),
source=cal_top_types.SourceType.default,
status=cal_top_types.CalibrationStatus(),
source=SourceType.default,
status=CalibrationStatus(),
)
if gripper_id and ff.enable_ot3_hardware_controller():
grip_offset_data = ot3_gripper_offset.get_gripper_calibration_offset(gripper_id)
Expand Down
8 changes: 4 additions & 4 deletions api/src/opentrons/hardware_control/ot3_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
)
from opentrons.config.robot_configs import (
default_ot3_deck_calibration,
defaults_ot3,
)
from opentrons.config import defaults_ot3
from .util import DeckTransformState

if TYPE_CHECKING:
Expand Down Expand Up @@ -477,7 +477,7 @@ def _edges_from_data(
# an N-sample rolling average. by inverting the sign of half the kernel, which is
# why we need it to be even, we do the same thing but while also taking a finite
# difference.
average_difference_kernel = np.concatenate( # type: ignore
average_difference_kernel = np.concatenate(
(
np.full(average_width_samples // 2, 1 / average_width_samples),
np.full(average_width_samples // 2, -1 / average_width_samples),
Expand Down Expand Up @@ -954,7 +954,7 @@ def apply_machine_transform(
"""
belt_attitude_arr = np.array(belt_attitude)
machine_transform_arr = np.array(defaults_ot3.DEFAULT_MACHINE_TRANSFORM)
deck_attitude_arr = np.dot(belt_attitude_arr, machine_transform_arr) # type: ignore[no-untyped-call]
deck_attitude_arr = np.dot(belt_attitude_arr, machine_transform_arr)
deck_attitude = deck_attitude_arr.round(4).tolist()
return deck_attitude # type: ignore[no-any-return]

Expand Down Expand Up @@ -993,7 +993,7 @@ def validate_attitude_deck_calibration(
"""
curr_cal = np.array(deck_cal.attitude)
row, _ = curr_cal.shape
rank: int = np.linalg.matrix_rank(curr_cal) # type: ignore
rank: int = np.linalg.matrix_rank(curr_cal)
if row != rank:
# Check that the matrix is non-singular
return DeckTransformState.SINGULARITY
Expand Down
4 changes: 2 additions & 2 deletions api/src/opentrons/hardware_control/robot_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def validate_attitude_deck_calibration(
"""
curr_cal = np.array(deck_cal.attitude)
row, _ = curr_cal.shape
rank: int = np.linalg.matrix_rank(curr_cal) # type: ignore
rank: int = np.linalg.matrix_rank(curr_cal)
if row != rank:
# Check that the matrix is non-singular
return DeckTransformState.SINGULARITY
Expand All @@ -71,7 +71,7 @@ def validate_gantry_calibration(gantry_cal: List[List[float]]) -> DeckTransformS
curr_cal = np.array(gantry_cal)
row, _ = curr_cal.shape

rank: int = np.linalg.matrix_rank(curr_cal) # type: ignore
rank: int = np.linalg.matrix_rank(curr_cal)

id_matrix = linal.identity_deck_transform()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def create_geometry(

# apply the slot transform if any
xform = np.array(xform_ser)
xformed = np.dot(xform, pre_transform) # type: ignore[no-untyped-call]
xformed = np.dot(xform, pre_transform)
module_type = ModuleType(definition["moduleType"])

if module_type == ModuleType.MAGNETIC or module_type == ModuleType.TEMPERATURE:
Expand Down
Loading

0 comments on commit edf46f6

Please sign in to comment.