fix typing in autofocus

I have an Optional dz, which is then
populated with a default if it's None.
I've added an explicit cast() to explain this to mypy.
This commit is contained in:
Richard 2021-07-19 21:18:25 +01:00
parent 72f3c11fdd
commit ba0f78df84
2 changed files with 30 additions and 15 deletions

View file

@ -2,7 +2,7 @@ import inspect
import logging
import time
from contextlib import contextmanager
from typing import Callable, Dict, List, Optional, Tuple
from typing import Callable, Dict, List, Optional, Tuple, cast
import numpy as np
from labthings import current_action, fields, find_component
@ -346,7 +346,8 @@ class AutofocusExtension(BaseExtension):
camera: BaseCamera = microscope.camera
stage: BaseStage = microscope.stage
if not dz:
dz: List[int] = list(np.linspace(-300, 300, 7))
dz = list(np.linspace(-300, 300, 7))
dz = cast(List[int], dz) # dz can't now be None, so fix its type.
with set_properties(stage, backlash=256), stage.lock, camera.lock:
sharpnesses: List[float] = []