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

refactor(robot-server): Type-check robot_server.robot #17534

Open
wants to merge 4 commits into
base: edge
Choose a base branch
from

Conversation

SyntaxColoring
Copy link
Contributor

@SyntaxColoring SyntaxColoring commented Feb 14, 2025

Overview

robot_server.robot.* is old code that was excluded from type-checking. This removes the exclusion and fixes the type-checking errors, to the extent that I could without disturbing the code too much.

This helps with EXEC-1206 and EXEC-1230.

Test Plan and Hands on Testing

I think we're good with CI and careful code review, but if that makes anyone nervous, I can smoke-test the OT-2's calibration flows next week.

Review requests

robot-server/robot_server/robot/calibration/check/user_flow.py was pretty bad. There are a lot of things there that look like they're forgetting to handle the possibility of a None value, and a lot of things that look like they're accessing properties that don't exist (!). I don't know how, or even if, it was working at all.

I’ve left comments in the code for those problems, and a GitHub review comment below. Anyone have insight into them?

Risk assessment

Low—I tried to avoid disrupting the code too much.

I added a number of assert foo is not Nones, but only where we were accessing properties like foo.bar, so at worst, it will turn an AttributeError into an AssertionError.

@SyntaxColoring SyntaxColoring requested a review from a team February 14, 2025 19:34
@SyntaxColoring SyntaxColoring requested review from a team as code owners February 14, 2025 19:34
Comment on lines +350 to +358
# todo(mm, 2025-02-14): These return types are the source of a lot of ignored and
# asserted-away type errors in this file. Double-check that they're actually correct.
def _get_current_calibrations(
self,
) -> tuple[
cal_models.DeckCalibrationModel | None,
dict[Mount, cal_models.InstrumentOffsetModel | None],
dict[Mount, cal_models.TipLengthModel | None],
]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It smells to me like this is "supposed to be" returning PipetteOffsetCalibration instead of InstrumentOffsetModel, and TipLengthCalibration instead of TipLengthModel. That would explain the # type: ignore[attr-defined]s that I've had to add in this file.

But these types follow directly from the calls to get_pipette_offset() and self._get_tip_length_from_pipette(), so 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similarly, if the None possibilities were removed, it would resolve a lot.

Resolve conflicts in:
* robot-server/robot_server/robot/calibration/check/user_flow.py
* robot-server/robot_server/robot/calibration/deck/user_flow.py
* robot-server/robot_server/robot/calibration/pipette_offset/user_flow.py
* robot-server/robot_server/robot/calibration/tip_length/user_flow.py
* robot-server/robot_server/robot/calibration/util.py
Copy link

codecov bot commented Feb 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 26.16%. Comparing base (41e0f6f) to head (dbd4427).
Report is 1 commits behind head on edge.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             edge   #17534   +/-   ##
=======================================
  Coverage   26.16%   26.16%           
=======================================
  Files        2838     2838           
  Lines      217729   217730    +1     
  Branches     9280     9281    +1     
=======================================
+ Hits        56970    56972    +2     
+ Misses     160742   160741    -1     
  Partials       17       17           
Flag Coverage Δ
app 3.42% <ø> (+<0.01%) ⬆️
protocol-designer 18.85% <ø> (ø)
step-generation 4.34% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 2 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant