Skip to content

Commit 2e61816

Browse files
authored
Update precommit (#8852)
1 parent 4b65be0 commit 2e61816

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+374
-306
lines changed

.flake8

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ ignore =
2222
B028
2323
# do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`
2424
E721
25+
# multiple statements on one line; required for black compat
26+
E701, E704
2527

2628
per-file-ignores =
2729
**/tests/*:

.pre-commit-config.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,37 @@ repos:
1212
- id: isort
1313
language_version: python3
1414
- repo: https://github.com/asottile/pyupgrade
15-
rev: v3.15.0
15+
rev: v3.17.0
1616
hooks:
1717
- id: pyupgrade
1818
args:
1919
- --py39-plus
2020
- repo: https://github.com/psf/black
21-
rev: 23.12.1
21+
rev: 24.8.0
2222
hooks:
2323
- id: black
2424
language_version: python3
2525
args:
2626
- --target-version=py39
2727
- repo: https://github.com/pycqa/flake8
28-
rev: 7.0.0
28+
rev: 7.1.1
2929
hooks:
3030
- id: flake8
3131
language_version: python3
3232
additional_dependencies:
3333
# NOTE: autoupdate does not pick up flake8-bugbear since it is a transitive
3434
# dependency. Make sure to update flake8-bugbear manually on a regular basis.
35-
- flake8-bugbear==23.12.2
35+
- flake8-bugbear==24.8.19
3636
- repo: https://github.com/codespell-project/codespell
37-
rev: v2.2.6
37+
rev: v2.3.0
3838
hooks:
3939
- id: codespell
4040
additional_dependencies:
4141
- tomli
4242
types_or: [rst, markdown]
4343
files: docs
4444
- repo: https://github.com/pre-commit/mirrors-mypy
45-
rev: v1.8.0
45+
rev: v1.11.2
4646
hooks:
4747
- id: mypy
4848
# Override default --ignore-missing-imports

continuous_integration/scripts/host_info.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def main() -> None:
3838
else:
3939
print("CPU frequency:")
4040
for freq in freqs:
41-
# FIXME types-psutil
42-
print(f" - current={freq.current}, min={freq.min}, max={freq.max}") # type: ignore
41+
print(f" - current={freq.current}, min={freq.min}, max={freq.max}")
4342

4443
mem = psutil.virtual_memory()
4544
print("Memory:")

continuous_integration/scripts/parse_stdout.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""On Windows, pytest-timeout kills off the whole test suite, leaving no junit report
22
behind. Parse the stdout of pytest to generate one.
33
"""
4+
45
from __future__ import annotations
56

67
import html

distributed/_concurrent_futures_thread.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
# workers to exit when their work queues are empty and then waits until the
3232
# threads finish.
3333

34-
_threads_queues: weakref.WeakKeyDictionary[
35-
threading.Thread, queue.Queue
36-
] = weakref.WeakKeyDictionary()
34+
_threads_queues: weakref.WeakKeyDictionary[threading.Thread, queue.Queue] = (
35+
weakref.WeakKeyDictionary()
36+
)
3737
_shutdown = False
3838

3939

distributed/active_memory_manager.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
See also :mod:`distributed.worker_memory` and :mod:`distributed.spill`, which implement
55
spill/pause/terminate mechanics on the Worker side.
66
"""
7+
78
from __future__ import annotations
89

910
import abc
@@ -392,12 +393,12 @@ def _enact_suggestions(self) -> None:
392393
logger.debug("Enacting suggestions for %d tasks:", len(self.pending))
393394

394395
validate = self.scheduler.validate
395-
drop_by_worker: (
396-
defaultdict[scheduler_module.WorkerState, list[Key]]
397-
) = defaultdict(list)
398-
repl_by_worker: (
399-
defaultdict[scheduler_module.WorkerState, list[Key]]
400-
) = defaultdict(list)
396+
drop_by_worker: defaultdict[scheduler_module.WorkerState, list[Key]] = (
397+
defaultdict(list)
398+
)
399+
repl_by_worker: defaultdict[scheduler_module.WorkerState, list[Key]] = (
400+
defaultdict(list)
401+
)
401402

402403
for ts, (pending_repl, pending_drop) in self.pending.items():
403404
if not ts.who_has:

distributed/actor.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,10 @@ class BaseActorFuture(abc.ABC, Awaitable[_T]):
245245
"""
246246

247247
@abc.abstractmethod
248-
def result(self, timeout: str | timedelta | float | None = None) -> _T:
249-
...
248+
def result(self, timeout: str | timedelta | float | None = None) -> _T: ...
250249

251250
@abc.abstractmethod
252-
def done(self) -> bool:
253-
...
251+
def done(self) -> bool: ...
254252

255253
def __repr__(self) -> Literal["<ActorFuture>"]:
256254
return "<ActorFuture>"

distributed/broker.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,12 @@ def _send_to_subscribers(self, topic: str, event: Any) -> None:
8484
self._scheduler.send_all(client_msgs, worker_msgs={})
8585

8686
@overload
87-
def get_events(self, topic: str) -> tuple[tuple[float, Any], ...]:
88-
...
87+
def get_events(self, topic: str) -> tuple[tuple[float, Any], ...]: ...
8988

9089
@overload
9190
def get_events(
9291
self, topic: None = None
93-
) -> dict[str, tuple[tuple[float, Any], ...]]:
94-
...
92+
) -> dict[str, tuple[tuple[float, Any], ...]]: ...
9593

9694
def get_events(
9795
self, topic: str | None = None

distributed/cfexecutor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _cascade_future(future, cf_future):
3030
try:
3131
typ, exc, tb = result
3232
raise exc.with_traceback(tb)
33-
except BaseException as exc:
33+
except BaseException as exc: # noqa: B036
3434
cf_future.set_exception(exc)
3535

3636

distributed/cli/dask_worker.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,11 @@ async def run():
406406
host=host,
407407
dashboard=dashboard,
408408
dashboard_address=dashboard_address,
409-
name=name
410-
if n_workers == 1 or name is None or name == ""
411-
else str(name) + "-" + str(i),
409+
name=(
410+
name
411+
if n_workers == 1 or name is None or name == ""
412+
else str(name) + "-" + str(i)
413+
),
412414
**kwargs,
413415
**port_kwargs_i,
414416
)

distributed/cli/tests/test_dask_worker.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,9 @@ async def test_set_lifetime_stagger_via_env_var(c, s):
610610
env = os.environ.copy()
611611
env["DASK_DISTRIBUTED__WORKER__LIFETIME__DURATION"] = "10 seconds"
612612
env["DASK_DISTRIBUTED__WORKER__LIFETIME__STAGGER"] = "2 seconds"
613-
with popen(["dask", "worker", s.address], env=env), popen(
614-
["dask", "worker", s.address], env=env
613+
with (
614+
popen(["dask", "worker", s.address], env=env),
615+
popen(["dask", "worker", s.address], env=env),
615616
):
616617
await c.wait_for_workers(2)
617618
[lifetime1, lifetime2] = (

distributed/client.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@
133133

134134
logger = logging.getLogger(__name__)
135135

136-
_global_clients: weakref.WeakValueDictionary[
137-
int, Client
138-
] = weakref.WeakValueDictionary()
136+
_global_clients: weakref.WeakValueDictionary[int, Client] = (
137+
weakref.WeakValueDictionary()
138+
)
139139
_global_client_index = [0]
140140

141141
_current_client: ContextVar[Client | None] = ContextVar("_current_client", default=None)
@@ -483,6 +483,7 @@ def execute_callback(fut):
483483
fn(fut)
484484
except BaseException:
485485
logger.exception("Error in callback %s of %s:", fn, fut)
486+
raise
486487

487488
self.client.loop.add_callback(
488489
done_callback, self, partial(cls._cb_executor.submit, execute_callback)
@@ -3873,13 +3874,13 @@ async def _restart_workers(
38733874
name_to_addr = {meta["name"]: addr for addr, meta in info["workers"].items()}
38743875
worker_addrs = [name_to_addr.get(w, w) for w in workers]
38753876

3876-
out: dict[
3877-
str, Literal["OK", "removed", "timed out"]
3878-
] = await self.scheduler.restart_workers(
3879-
workers=worker_addrs,
3880-
timeout=timeout,
3881-
on_error="raise" if raise_for_error else "return",
3882-
stimulus_id=f"client-restart-workers-{time()}",
3877+
out: dict[str, Literal["OK", "removed", "timed out"]] = (
3878+
await self.scheduler.restart_workers(
3879+
workers=worker_addrs,
3880+
timeout=timeout,
3881+
on_error="raise" if raise_for_error else "return",
3882+
stimulus_id=f"client-restart-workers-{time()}",
3883+
)
38833884
)
38843885
# Map keys back to original `workers` input names/addresses
38853886
out = {w: out[w_addr] for w, w_addr in zip(workers, worker_addrs)}

distributed/comm/registry.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88

99
class _EntryPoints(Protocol):
10-
def __call__(self, **kwargs: str) -> Iterable[importlib.metadata.EntryPoint]:
11-
...
10+
def __call__(self, **kwargs: str) -> Iterable[importlib.metadata.EntryPoint]: ...
1211

1312

1413
_entry_points: _EntryPoints = importlib.metadata.entry_points # type: ignore[assignment]

distributed/comm/ucx.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
.. _UCX: https://github.com/openucx/ucx
77
"""
8+
89
from __future__ import annotations
910

1011
import functools
@@ -360,7 +361,7 @@ async def read(self, deserializers=("cuda", "dask", "pickle", "error")):
360361
await self.ep.recv(header)
361362
header = struct.unpack(header_fmt, header)
362363
cuda_frames, sizes = header[:nframes], header[nframes:]
363-
except BaseException as e:
364+
except BaseException as e: # noqa: B036
364365
# In addition to UCX exceptions, may be CancelledError or another
365366
# "low-level" exception. The only safe thing to do is to abort.
366367
# (See also https://github.com/dask/distributed/pull/6574).
@@ -390,7 +391,7 @@ async def read(self, deserializers=("cuda", "dask", "pickle", "error")):
390391
try:
391392
for each_frame in recv_frames:
392393
await self.ep.recv(each_frame)
393-
except BaseException as e:
394+
except BaseException as e: # noqa: B036
394395
# In addition to UCX exceptions, may be CancelledError or another
395396
# "low-level" exception. The only safe thing to do is to abort.
396397
# (See also https://github.com/dask/distributed/pull/6574).

distributed/dashboard/components/scheduler.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -3923,9 +3923,11 @@ def update(self):
39233923

39243924
# Format event loop as time and GIL (if configured) as %
39253925
self.data["text"] = [
3926-
f"{x * 100:.1f}%"
3927-
if i % 2 and s.monitor.monitor_gil_contention
3928-
else format_time(x)
3926+
(
3927+
f"{x * 100:.1f}%"
3928+
if i % 2 and s.monitor.monitor_gil_contention
3929+
else format_time(x)
3930+
)
39293931
for i, x in enumerate(self.data["values"])
39303932
]
39313933
update(self.source, self.data)

distributed/deploy/ssh.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -434,28 +434,34 @@ def SSHCluster(
434434
"cls": Scheduler,
435435
"options": {
436436
"address": hosts[0],
437-
"connect_options": connect_options
438-
if isinstance(connect_options, dict)
439-
else connect_options[0],
437+
"connect_options": (
438+
connect_options
439+
if isinstance(connect_options, dict)
440+
else connect_options[0]
441+
),
440442
"kwargs": scheduler_options,
441-
"remote_python": remote_python[0]
442-
if isinstance(remote_python, list)
443-
else remote_python,
443+
"remote_python": (
444+
remote_python[0] if isinstance(remote_python, list) else remote_python
445+
),
444446
},
445447
}
446448
workers = {
447449
i: {
448450
"cls": Worker,
449451
"options": {
450452
"address": host,
451-
"connect_options": connect_options
452-
if isinstance(connect_options, dict)
453-
else connect_options[i + 1],
453+
"connect_options": (
454+
connect_options
455+
if isinstance(connect_options, dict)
456+
else connect_options[i + 1]
457+
),
454458
"kwargs": worker_options,
455459
"worker_class": worker_class,
456-
"remote_python": remote_python[i + 1]
457-
if isinstance(remote_python, list)
458-
else remote_python,
460+
"remote_python": (
461+
remote_python[i + 1]
462+
if isinstance(remote_python, list)
463+
else remote_python
464+
),
459465
},
460466
}
461467
for i, host in enumerate(hosts[1:])

distributed/deploy/tests/test_adaptive.py

+21-15
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,17 @@ async def test_adapt_quickly():
189189
Instead we want to wait a few beats before removing a worker in case the
190190
user is taking a brief pause between work
191191
"""
192-
async with LocalCluster(
193-
n_workers=0,
194-
asynchronous=True,
195-
processes=False,
196-
silence_logs=False,
197-
dashboard_address=":0",
198-
threads_per_worker=1,
199-
) as cluster, Client(cluster, asynchronous=True) as client:
192+
async with (
193+
LocalCluster(
194+
n_workers=0,
195+
asynchronous=True,
196+
processes=False,
197+
silence_logs=False,
198+
dashboard_address=":0",
199+
threads_per_worker=1,
200+
) as cluster,
201+
Client(cluster, asynchronous=True) as client,
202+
):
200203
adapt = cluster.adapt(interval="20 ms", wait_count=5, maximum=10)
201204
future = client.submit(slowinc, 1, delay=0.100)
202205
await wait(future)
@@ -240,13 +243,16 @@ async def test_adapt_quickly():
240243
@gen_test()
241244
async def test_adapt_down():
242245
"""Ensure that redefining adapt with a lower maximum removes workers"""
243-
async with LocalCluster(
244-
n_workers=0,
245-
asynchronous=True,
246-
processes=False,
247-
silence_logs=False,
248-
dashboard_address=":0",
249-
) as cluster, Client(cluster, asynchronous=True) as client:
246+
async with (
247+
LocalCluster(
248+
n_workers=0,
249+
asynchronous=True,
250+
processes=False,
251+
silence_logs=False,
252+
dashboard_address=":0",
253+
) as cluster,
254+
Client(cluster, asynchronous=True) as client,
255+
):
250256
cluster.adapt(interval="20ms", maximum=5)
251257

252258
futures = client.map(slowinc, range(1000), delay=0.1)

distributed/deploy/tests/test_cluster.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
@gen_test()
1212
async def test_eq():
13-
async with Cluster(asynchronous=True, name="A") as clusterA, Cluster(
14-
asynchronous=True, name="A2"
15-
) as clusterA2, Cluster(asynchronous=True, name="B") as clusterB:
13+
async with (
14+
Cluster(asynchronous=True, name="A") as clusterA,
15+
Cluster(asynchronous=True, name="A2") as clusterA2,
16+
Cluster(asynchronous=True, name="B") as clusterB,
17+
):
1618
assert clusterA != "A"
1719
assert not (clusterA == "A")
1820
assert clusterA == clusterA
@@ -75,8 +77,11 @@ def test_exponential_backoff():
7577
@gen_test()
7678
async def test_sync_context_manager_used_with_async_cluster():
7779
async with Cluster(asynchronous=True, name="A") as cluster:
78-
with pytest.raises(
79-
TypeError,
80-
match=r"Used 'with' with asynchronous class; please use 'async with'",
81-
), cluster:
80+
with (
81+
pytest.raises(
82+
TypeError,
83+
match=r"Used 'with' with asynchronous class; please use 'async with'",
84+
),
85+
cluster,
86+
):
8287
pass

0 commit comments

Comments
 (0)