Skip to content

Commit 83d83ce

Browse files
committed
runner.docker: Appease mypy and avoid redefining the type of "limits"
Mypy really doesn't like redefinitions¹, and we start with List[str] but then convert to List[int]. The limited support for redefinition (--allow-redefinition) doesn't apply here because two different code blocks are involved. This particular shift of code into the try block doesn't impact the handling of exceptions. ¹ python/mypy#1174
1 parent 808ccd6 commit 83d83ce

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

nextstrain/cli/runner/docker.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -153,24 +153,22 @@ def test_memory_limit():
153153
status: RunnerTestResultStatus = ...
154154

155155
if image_exists():
156+
def int_or_none(x):
157+
try:
158+
return int(float(x))
159+
except ValueError:
160+
return None
161+
156162
report_memory = """
157163
awk '/^MemTotal:/ { print $2 * 1024 }' /proc/meminfo
158164
(cat /sys/fs/cgroup/memory.max || cat /sys/fs/cgroup/memory/memory.limit_in_bytes) 2>/dev/null
159165
"""
160166

161167
try:
162-
limits = run_bash(report_memory)
168+
limits = list(filter(None, map(int_or_none, run_bash(report_memory))))
163169
except (OSError, subprocess.CalledProcessError):
164170
pass
165171
else:
166-
def int_or_none(x):
167-
try:
168-
return int(float(x))
169-
except ValueError:
170-
return None
171-
172-
limits = list(filter(None, map(int_or_none, limits)))
173-
174172
if limits:
175173
limit = min(limits)
176174

0 commit comments

Comments
 (0)