-
Notifications
You must be signed in to change notification settings - Fork 178
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
refactor(api): add explicit Flex hardware protocol #14091
Conversation
# Conflicts: # api/src/opentrons/hardware_control/protocols/configurable.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it, big step forward. Can we do enum literal returns for the robot_type and get mypy automatically narrowing union types?
@@ -302,6 +302,9 @@ async def build_hardware_simulator( | |||
def __repr__(self) -> str: | |||
return "<{} using backend {}>".format(type(self), type(self._backend)) | |||
|
|||
def get_robot_type(self) -> RobotTypeEnum: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you define this to return an enum literal Literal[RobotTypeEnum.OT2]
, and define the Flex protocol's version of the method to return Literal[RobotTypeEnum.FLEX]
(or however we spelled it), then in theory that should let the union of the two protocols get narrowed by the result of calling get_robot_type()
which should remove some casts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise HardwareNotSupportedError( | ||
error_msg or "This command is supported by OT-3 only." | ||
) | ||
|
||
return hardware_api | ||
return hardware_api # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here this cast should be removable if you do the enum-literal thing above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MyPy disagrees :(
…types for robot models
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## edge #14091 +/- ##
==========================================
- Coverage 70.40% 70.39% -0.01%
==========================================
Files 2510 2510
Lines 71201 71188 -13
Branches 8971 8971
==========================================
- Hits 50127 50113 -14
Misses 18880 18880
- Partials 2194 2195 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove TYPE_CHECKING? otherwise looks good
|
||
if TYPE_CHECKING: | ||
from opentrons.hardware_control.ot3api import OT3API | ||
from opentrons.hardware_control import HardwareControlAPI | ||
from opentrons.hardware_control import HardwareControlAPI, OT3HardwareControlAPI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here too - shouldn't need TYPE_CHECKING?
@@ -49,7 +49,7 @@ | |||
from robot_server.subsystems.router import status_route_for, update_route_for | |||
|
|||
if TYPE_CHECKING: | |||
from opentrons.hardware_control.ot3api import OT3API | |||
from opentrons.hardware_control import OT3HardwareControlAPI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no TYPE_CHECKING
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, let's do it!
# Conflicts: # api/tests/opentrons/protocol_engine/execution/test_labware_movement_handler.py
* pass around mypy protocol instead of OT3API * Explicit parameterization of config types * Fix some tests with the protocol engine related to protocol changes * Added a `FlexInstrumentConfigurer` for flex-specific configuration extensions * Update test mocks to differentiate ot2/ot3 hardware * Modifed `get_robot_type` to be parameterized on some singleton class types for robot models * remove unnecessary TYPE_CHECKING import * Add tip presence protocol functions to satisfy edits to tip manager
Overview
We currently differentiate between the OT3 and OT2 API classes with a simple
isinstance
check. This works okay when the simulator for each class is an instance of the normal hardware API, but there are a few reasons that we want to move over to having a separate simulator class for each API that does not depend on the hardware-specific code. In that case, checking the types to differentiate the robot model doesn't work.This PR establishes extensions to the Hardware API MyPy protocols in order to explicitly differentiate an OT-2 from an OT-3. It also adds a function that returns the enumerated model of the robot (OT2 or FLEX). This is preferable to type-checking the class because
isinstance
is slow/not recommended on Protocol classes.Test Plan
Check that
GET /instruments
on OT-2)Changelog
Review requests
Risk assessment
Medium. Touches some core stuff but doesn't really change any behavior.