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

40
Pipfile.lock generated
View file

@ -54,7 +54,7 @@
"sha256:02a409bd2cb193b20d9eb015ca31400bd3e1721ec5d702e1b96de54608ff5a8f", "sha256:02a409bd2cb193b20d9eb015ca31400bd3e1721ec5d702e1b96de54608ff5a8f",
"sha256:d39c3afebb59ec865fb1247dfd951d7090c159ab0cf3e4291e0869d3be33776c" "sha256:d39c3afebb59ec865fb1247dfd951d7090c159ab0cf3e4291e0869d3be33776c"
], ],
"markers": "python_version >= '3.6' and python_version < '4'", "markers": "python_version >= '3.6' and python_version < '4.0'",
"version": "==0.1.4" "version": "==0.1.4"
}, },
"certifi": { "certifi": {
@ -151,7 +151,7 @@
"sha256:f0b278ce10936db1a37e6954e15a3730bea96a0997c26d7fee88e6c396c2086d", "sha256:f0b278ce10936db1a37e6954e15a3730bea96a0997c26d7fee88e6c396c2086d",
"sha256:f11642dddbb0253cc8853254301b51390ba0081750a8ac03f20ea8103f0c56b6" "sha256:f11642dddbb0253cc8853254301b51390ba0081750a8ac03f20ea8103f0c56b6"
], ],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4.0'",
"version": "==5.5" "version": "==5.5"
}, },
"expiringdict": { "expiringdict": {
@ -250,7 +250,7 @@
"sha256:4f286ea585e596aeb67a02d5bd822b2c89828693026085829e15e415a2d2d287", "sha256:4f286ea585e596aeb67a02d5bd822b2c89828693026085829e15e415a2d2d287",
"sha256:970bb6a81f0e007b55e575e6eafe6bba10974d671f2767b91631f001ff53cf0e" "sha256:970bb6a81f0e007b55e575e6eafe6bba10974d671f2767b91631f001ff53cf0e"
], ],
"markers": "python_version >= '3.6' and python_version < '4'", "markers": "python_version >= '3.6' and python_version < '4.0'",
"version": "==1.2.4" "version": "==1.2.4"
}, },
"markupsafe": { "markupsafe": {
@ -676,7 +676,7 @@
"sha256:39fb8672126159acb139a7718dd10806104dec1e2f0f6c88aab05d17df10c8d4", "sha256:39fb8672126159acb139a7718dd10806104dec1e2f0f6c88aab05d17df10c8d4",
"sha256:f57b4c16c62fa2760b7e3d97c35b255512fb6b59a259730f36ba32ce9f8e342f" "sha256:f57b4c16c62fa2760b7e3d97c35b255512fb6b59a259730f36ba32ce9f8e342f"
], ],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4.0'",
"version": "==1.26.6" "version": "==1.26.6"
}, },
"webargs": { "webargs": {
@ -748,11 +748,11 @@
}, },
"astroid": { "astroid": {
"hashes": [ "hashes": [
"sha256:38b95085e9d92e2ca06cf8b35c12a74fa81da395a6f9e65803742e6509c05892", "sha256:11e598e49e31f288ae43d13e8d0eb28454e5e2aa745cbc16cc799f147bb7e8dd",
"sha256:606b2911d10c3dcf35e58d2ee5c97360e8477d7b9f3efc3f24811c93e6fc2cd9" "sha256:958c2aa6ba47e0b69773ce2b30cd6c2c99d15a5cc611e323d231f4c44db36d54"
], ],
"markers": "python_version ~= '3.6'", "markers": "python_version ~= '3.6'",
"version": "==2.6.2" "version": "==2.6.3"
}, },
"attrs": { "attrs": {
"hashes": [ "hashes": [
@ -783,7 +783,7 @@
"sha256:02a409bd2cb193b20d9eb015ca31400bd3e1721ec5d702e1b96de54608ff5a8f", "sha256:02a409bd2cb193b20d9eb015ca31400bd3e1721ec5d702e1b96de54608ff5a8f",
"sha256:d39c3afebb59ec865fb1247dfd951d7090c159ab0cf3e4291e0869d3be33776c" "sha256:d39c3afebb59ec865fb1247dfd951d7090c159ab0cf3e4291e0869d3be33776c"
], ],
"markers": "python_version >= '3.6' and python_version < '4'", "markers": "python_version >= '3.6' and python_version < '4.0'",
"version": "==0.1.4" "version": "==0.1.4"
}, },
"certifi": { "certifi": {
@ -880,7 +880,7 @@
"sha256:f0b278ce10936db1a37e6954e15a3730bea96a0997c26d7fee88e6c396c2086d", "sha256:f0b278ce10936db1a37e6954e15a3730bea96a0997c26d7fee88e6c396c2086d",
"sha256:f11642dddbb0253cc8853254301b51390ba0081750a8ac03f20ea8103f0c56b6" "sha256:f11642dddbb0253cc8853254301b51390ba0081750a8ac03f20ea8103f0c56b6"
], ],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4.0'",
"version": "==5.5" "version": "==5.5"
}, },
"docutils": { "docutils": {
@ -980,7 +980,7 @@
"sha256:eed17b53c3e7912425579853d078a0832820f023191561fcee9d7cae424e0813", "sha256:eed17b53c3e7912425579853d078a0832820f023191561fcee9d7cae424e0813",
"sha256:f65ce5bd4cbc6abdfbe29afc2f0245538ab358c14590912df638033f157d555e" "sha256:f65ce5bd4cbc6abdfbe29afc2f0245538ab358c14590912df638033f157d555e"
], ],
"markers": "python_version < '4.0' and python_full_version >= '3.6.1'", "markers": "python_version < '4' and python_full_version >= '3.6.1'",
"version": "==5.9.2" "version": "==5.9.2"
}, },
"itsdangerous": { "itsdangerous": {
@ -1011,7 +1011,7 @@
"sha256:4f286ea585e596aeb67a02d5bd822b2c89828693026085829e15e415a2d2d287", "sha256:4f286ea585e596aeb67a02d5bd822b2c89828693026085829e15e415a2d2d287",
"sha256:970bb6a81f0e007b55e575e6eafe6bba10974d671f2767b91631f001ff53cf0e" "sha256:970bb6a81f0e007b55e575e6eafe6bba10974d671f2767b91631f001ff53cf0e"
], ],
"markers": "python_version >= '3.6' and python_version < '4'", "markers": "python_version >= '3.6' and python_version < '4.0'",
"version": "==1.2.4" "version": "==1.2.4"
}, },
"lazy-object-proxy": { "lazy-object-proxy": {
@ -1371,7 +1371,7 @@
"sha256:6fb3021603d4421c6fcc40072bbcf150a6c52ef70ff4d3be089b8b04e015ef5a", "sha256:6fb3021603d4421c6fcc40072bbcf150a6c52ef70ff4d3be089b8b04e015ef5a",
"sha256:70b97cb194b978dc464c70793e85e6f746cddf82b84a38bfb135946ad71ae19c" "sha256:70b97cb194b978dc464c70793e85e6f746cddf82b84a38bfb135946ad71ae19c"
], ],
"markers": "python_version >= '3.6' and python_version < '4.0'", "markers": "python_version >= '3.6' and python_version < '4'",
"version": "==0.10.0" "version": "==0.10.0"
}, },
"prance": { "prance": {
@ -1740,6 +1740,20 @@
"markers": "python_version < '3.8' and implementation_name == 'cpython'", "markers": "python_version < '3.8' and implementation_name == 'cpython'",
"version": "==1.4.3" "version": "==1.4.3"
}, },
"types-python-dateutil": {
"hashes": [
"sha256:39bfe0bde61fc673b8fa28167bd78622d976210f791971b9f3e10877cbf119a4",
"sha256:e6486ca27b6dde73e0ec079a9e1b03e208766e6bc7f1e08964a7e9104a5c7d7a"
],
"version": "==0.1.4"
},
"types-setuptools": {
"hashes": [
"sha256:71ed0f4c71d8fb5f3026a90ae82d163c13749b110e157d82126725ac8f714360",
"sha256:b3ada82b21dcb8e0cafd7658d8a16018a000e55bdb7f6f3cec033223360563ce"
],
"version": "==57.0.0"
},
"typing-extensions": { "typing-extensions": {
"hashes": [ "hashes": [
"sha256:7cb407020f00f7bfc3cb3e7881628838e69d8f3fcab2f64742a5e76b2f841918", "sha256:7cb407020f00f7bfc3cb3e7881628838e69d8f3fcab2f64742a5e76b2f841918",
@ -1754,7 +1768,7 @@
"sha256:39fb8672126159acb139a7718dd10806104dec1e2f0f6c88aab05d17df10c8d4", "sha256:39fb8672126159acb139a7718dd10806104dec1e2f0f6c88aab05d17df10c8d4",
"sha256:f57b4c16c62fa2760b7e3d97c35b255512fb6b59a259730f36ba32ce9f8e342f" "sha256:f57b4c16c62fa2760b7e3d97c35b255512fb6b59a259730f36ba32ce9f8e342f"
], ],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'", "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4.0'",
"version": "==1.26.6" "version": "==1.26.6"
}, },
"webargs": { "webargs": {

View file

@ -2,7 +2,7 @@ import inspect
import logging import logging
import time import time
from contextlib import contextmanager 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 import numpy as np
from labthings import current_action, fields, find_component from labthings import current_action, fields, find_component
@ -346,7 +346,8 @@ class AutofocusExtension(BaseExtension):
camera: BaseCamera = microscope.camera camera: BaseCamera = microscope.camera
stage: BaseStage = microscope.stage stage: BaseStage = microscope.stage
if not dz: 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: with set_properties(stage, backlash=256), stage.lock, camera.lock:
sharpnesses: List[float] = [] sharpnesses: List[float] = []