Skip to content

Commit a8acb41

Browse files
authored
Work towards new mypy, 1.18.2 (#4007)
This PR has the usual upgrade-mypy dance of removing and adding various ignores as mypy changes what it can reason about. This PR removes one use of AnyStr which was incorrect: it is a type variable for aligning multiple uses of str|bytes together, but it was not properly used in that was in the removed case. The immediate motivation for this PR is to bring in newer mypy support for match statements, as part of work on parsl-perf which uses match statements now. # Changed Behaviour none ## Type of change - Code maintenance/cleanup
1 parent 728cc14 commit a8acb41

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

parsl/executors/flux/executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def __init__(
224224
# add a ``weakref.finalize()`` function for joining the executor thread
225225
weakref.finalize(
226226
self,
227-
lambda x, y: x.set() or y.join(),
227+
lambda x, y: x.set() or y.join(), # type: ignore[func-returns-value]
228228
self._stop_event,
229229
self._submission_thread,
230230
)

parsl/executors/high_throughput/mpi_resource_management.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ def _get_nodes(self, num_nodes: int) -> List[str]:
145145
)
146146
acquired_nodes = []
147147
with self._free_node_counter.get_lock():
148-
if num_nodes <= self._free_node_counter.value: # type: ignore[attr-defined]
149-
self._free_node_counter.value -= num_nodes # type: ignore[attr-defined]
148+
if num_nodes <= self._free_node_counter.value:
149+
self._free_node_counter.value -= num_nodes
150150
else:
151151
raise MPINodesUnavailable(
152-
requested=num_nodes, available=self._free_node_counter.value # type: ignore[attr-defined]
152+
requested=num_nodes, available=self._free_node_counter.value
153153
)
154154

155155
for i in range(num_nodes):
@@ -162,7 +162,7 @@ def _return_nodes(self, nodes: List[str]) -> None:
162162
for node in nodes:
163163
self.nodes_q.put(node)
164164
with self._free_node_counter.get_lock():
165-
self._free_node_counter.value += len(nodes) # type: ignore[attr-defined]
165+
self._free_node_counter.value += len(nodes)
166166

167167
def put_task(self, task_package: dict):
168168
"""Schedule task if resources are available otherwise backlog the task"""

parsl/executors/high_throughput/process_worker_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def interchange_communicator(self, pair_setup: threading.Event):
349349

350350
logger.debug(
351351
'ready workers: %d, pending tasks: %d',
352-
self.ready_worker_count.value, # type: ignore[attr-defined]
352+
self.ready_worker_count.value,
353353
pending_task_count,
354354
)
355355

parsl/utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from typing import (
1212
IO,
1313
Any,
14-
AnyStr,
1514
Callable,
1615
Dict,
1716
Generator,
@@ -132,7 +131,13 @@ def get_std_fname_mode(
132131
mode = 'a+'
133132
elif isinstance(stdfspec, tuple):
134133
if len(stdfspec) != 2:
135-
msg = (f"std descriptor {fdname} has incorrect tuple length "
134+
# this is annotated as unreachable because the type annotation says
135+
# it cannot be reached. Earlier versions of typeguard did not enforce
136+
# that type annotation at runtime, though, and the parameters to this
137+
# function come from the user.
138+
# When typeguard lower bound is raised to around version 4, this
139+
# unreachable can be removed.
140+
msg = (f"std descriptor {fdname} has incorrect tuple length " # type: ignore[unreachable]
136141
f"{len(stdfspec)}")
137142
raise pe.BadStdStreamFile(msg)
138143
fname, mode = stdfspec
@@ -157,7 +162,7 @@ def wait_for_file(path: str, seconds: int = 10) -> Generator[None, None, None]:
157162

158163

159164
@contextmanager
160-
def time_limited_open(path: str, mode: str, seconds: int = 1) -> Generator[IO[AnyStr], None, None]:
165+
def time_limited_open(path: str, mode: str, seconds: int = 1) -> Generator[IO, None, None]:
161166
with wait_for_file(path, seconds):
162167
logger.debug("wait_for_file yielded")
163168
f = open(path, mode)

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pytest-cov
55
pytest-random-order
66
nbsphinx
77
sphinx_rtd_theme
8-
mypy==1.5.1
8+
mypy==1.18.2
99
types-mock
1010
types-python-dateutil
1111
types-requests

0 commit comments

Comments
 (0)