Skip to content

Commit 242e58b

Browse files
flake8, bugbear, pyupgrade → ruff (#9147)
Co-authored-by: Jacob Tomlinson <[email protected]>
1 parent e383c61 commit 242e58b

31 files changed

+124
-189
lines changed

.flake8

Lines changed: 0 additions & 41 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
1-
# NOTE: autoupdate does not pick up flake8-bugbear since it is a transitive
2-
# dependency. Make sure to update flake8-bugbear manually on a regular basis.
31
repos:
42
- repo: https://github.com/MarcoGorelli/absolufy-imports
53
rev: v0.3.1
64
hooks:
75
- id: absolufy-imports
86
name: absolufy-imports
7+
- repo: https://github.com/astral-sh/ruff-pre-commit
8+
rev: v0.14.5
9+
hooks:
10+
- id: ruff-check
911
- repo: https://github.com/pycqa/isort
1012
rev: 5.13.2
1113
hooks:
1214
- id: isort
1315
language_version: python3
14-
- repo: https://github.com/asottile/pyupgrade
15-
rev: v3.17.0
16-
hooks:
17-
- id: pyupgrade
18-
args:
19-
- --py39-plus
2016
- repo: https://github.com/psf/black-pre-commit-mirror
2117
rev: 25.11.0
2218
hooks:
2319
- id: black
24-
- repo: https://github.com/pycqa/flake8
25-
rev: 7.1.1
26-
hooks:
27-
- id: flake8
28-
language_version: python3
29-
additional_dependencies:
30-
# NOTE: autoupdate does not pick up flake8-bugbear since it is a transitive
31-
# dependency. Make sure to update flake8-bugbear manually on a regular basis.
32-
- flake8-bugbear==24.8.19
3320
- repo: https://github.com/codespell-project/codespell
3421
rev: v2.3.0
3522
hooks:

distributed/_concurrent_futures_thread.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def _python_exit():
4141
global _shutdown
4242
_shutdown = True
4343
items = list(_threads_queues.items())
44-
for t, q in items:
44+
for _, q in items:
4545
q.put(None)
46-
for t, q in items:
46+
for t, _ in items:
4747
t.join()
4848

4949

distributed/active_memory_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,7 @@ class Suggestion(NamedTuple):
436436

437437

438438
if TYPE_CHECKING:
439-
# TODO import from typing (requires Python >=3.10)
440-
from typing_extensions import TypeAlias
439+
from typing import TypeAlias
441440

442441
SuggestionGenerator: TypeAlias = Generator[
443442
Suggestion, Union["scheduler_module.WorkerState", None], None

distributed/cfexecutor.py

Lines changed: 1 addition & 1 deletion
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: # noqa: B036
33+
except BaseException as exc:
3434
cf_future.set_exception(exc)
3535

3636

distributed/cli/dask_ssh.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,7 @@ def main(
189189
import distributed
190190

191191
print("\n---------------------------------------------------------------")
192-
print(
193-
" Dask.distributed v{version}\n".format(
194-
version=distributed.__version__
195-
)
196-
)
192+
print(f" Dask.distributed v{distributed.__version__}\n")
197193
print(f"Worker nodes: {len(hostnames)}")
198194
for i, host in enumerate(hostnames):
199195
print(f" {i}: {host}")

distributed/client.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717
import warnings
1818
import weakref
1919
from collections import defaultdict
20-
from collections.abc import Collection, Coroutine, Iterable, Iterator, Sequence
20+
from collections.abc import (
21+
Callable,
22+
Collection,
23+
Coroutine,
24+
Iterable,
25+
Iterator,
26+
Sequence,
27+
)
2128
from concurrent.futures import ThreadPoolExecutor
2229
from concurrent.futures._base import DoneAndNotDoneFutures
2330
from contextlib import asynccontextmanager, contextmanager, suppress
@@ -29,7 +36,6 @@
2936
from typing import (
3037
TYPE_CHECKING,
3138
Any,
32-
Callable,
3339
ClassVar,
3440
Generic,
3541
Literal,
@@ -125,7 +131,7 @@
125131
from distributed.worker import get_client, get_worker, secede
126132

127133
if TYPE_CHECKING:
128-
from typing_extensions import TypeAlias
134+
from typing import TypeAlias
129135

130136
logger = logging.getLogger(__name__)
131137

@@ -1121,9 +1127,7 @@ def __init__(
11211127
security = getattr(self.cluster, "security", None)
11221128
elif address is not None and not isinstance(address, str):
11231129
raise TypeError(
1124-
"Scheduler address must be a string or a Cluster instance, got {}".format(
1125-
type(address)
1126-
)
1130+
f"Scheduler address must be a string or a Cluster instance, got {type(address)}"
11271131
)
11281132

11291133
# If connecting to an address and no explicit security is configured, attempt
@@ -1375,10 +1379,7 @@ def __repr__(self):
13751379
return text
13761380

13771381
elif self.scheduler is not None:
1378-
return "<{}: scheduler={!r}>".format(
1379-
self.__class__.__name__,
1380-
self.scheduler.address,
1381-
)
1382+
return f"<{self.__class__.__name__}: scheduler={self.scheduler.address!r}>"
13821383
else:
13831384
return f"<{self.__class__.__name__}: No scheduler connected>"
13841385

@@ -2368,7 +2369,7 @@ async def _gather(self, futures, errors="raise", direct=None, local_worker=None)
23682369
"Cannot gather Futures created by another client. "
23692370
f"These are the {len(mismatched_futures)} (out of {len(futures)}) "
23702371
f"mismatched Futures and their client IDs (this client is {self.id}): "
2371-
f"{ {f: f.client.id for f in mismatched_futures} }" # noqa: E201, E202
2372+
f"{ {f: f.client.id for f in mismatched_futures} }"
23722373
)
23732374
keys = [future.key for future in future_set]
23742375
bad_data = dict()
@@ -5892,8 +5893,8 @@ def count(self):
58925893
return len(self.futures) + len(self.queue.queue)
58935894

58945895
def __repr__(self):
5895-
return "<as_completed: waiting={} done={}>".format(
5896-
len(self.futures), len(self.queue.queue)
5896+
return (
5897+
f"<as_completed: waiting={len(self.futures)} done={len(self.queue.queue)}>"
58975898
)
58985899

58995900
def __iter__(self):

distributed/dashboard/components/nvml.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,8 @@ def update(self):
151151
"escaped_worker": [url_escape(w) for w in worker],
152152
}
153153

154-
self.memory_figure.title.text = "GPU Memory: {} / {}".format(
155-
format_bytes(sum(memory)),
156-
format_bytes(memory_total),
154+
self.memory_figure.title.text = (
155+
f"GPU Memory: {format_bytes(sum(memory))} / {format_bytes(memory_total)}"
157156
)
158157
self.memory_figure.x_range.end = memory_max
159158

distributed/deploy/adaptive.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import annotations
22

33
import logging
4-
from collections.abc import Hashable
4+
from collections.abc import Callable, Hashable
55
from datetime import timedelta
66
from inspect import isawaitable
7-
from typing import TYPE_CHECKING, Any, Callable, Literal, cast
7+
from typing import TYPE_CHECKING, Any, Literal, cast
88

99
from tornado.ioloop import IOLoop
1010

@@ -18,7 +18,7 @@
1818
from distributed.utils import log_errors
1919

2020
if TYPE_CHECKING:
21-
from typing_extensions import TypeAlias
21+
from typing import TypeAlias
2222

2323
import distributed
2424
from distributed.deploy.cluster import Cluster

distributed/deploy/old_ssh.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import logging
44
import os
5-
import socket
65
import sys
76
import traceback
87
import warnings
@@ -136,7 +135,7 @@ def read_from_stdout():
136135
)
137136
)
138137
line = stdout.readline()
139-
except (PipeTimeout, socket.timeout):
138+
except (TimeoutError, PipeTimeout):
140139
pass
141140

142141
def read_from_stderr():
@@ -155,7 +154,7 @@ def read_from_stderr():
155154
+ bcolors.ENDC
156155
)
157156
line = stderr.readline()
158-
except (PipeTimeout, socket.timeout):
157+
except (TimeoutError, PipeTimeout):
159158
pass
160159

161160
def communicate():
@@ -208,16 +207,12 @@ def communicate():
208207
def start_scheduler(
209208
logdir, addr, port, ssh_username, ssh_port, ssh_private_key, remote_python=None
210209
):
211-
cmd = "{python} -m distributed.cli.dask_scheduler --port {port}".format(
212-
python=remote_python or sys.executable, port=port
213-
)
210+
cmd = f"{remote_python or sys.executable} -m distributed.cli.dask_scheduler --port {port}"
214211

215212
# Optionally re-direct stdout and stderr to a logfile
216213
if logdir is not None:
217214
cmd = f"mkdir -p {logdir} && {cmd}"
218-
cmd += "&> {logdir}/dask_scheduler_{addr}:{port}.log".format(
219-
addr=addr, port=port, logdir=logdir
220-
)
215+
cmd += f"&> {logdir}/dask_scheduler_{addr}:{port}.log"
221216

222217
# Format output labels we can prepend to each line of output, and create
223218
# a 'status' key to keep track of jobs that terminate prematurely.
@@ -297,16 +292,11 @@ def start_worker(
297292
)
298293

299294
if local_directory is not None:
300-
cmd += " --local-directory {local_directory}".format(
301-
local_directory=local_directory
302-
)
295+
cmd += f" --local-directory {local_directory}"
303296

304297
# Optionally redirect stdout and stderr to a logfile
305298
if logdir is not None:
306-
cmd = f"mkdir -p {logdir} && {cmd}"
307-
cmd += "&> {logdir}/dask_scheduler_{addr}.log".format(
308-
addr=worker_addr, logdir=logdir
309-
)
299+
cmd = f"mkdir -p {logdir} && {cmd}&> {logdir}/dask_scheduler_{worker_addr}.log"
310300

311301
label = f"worker {worker_addr}"
312302

@@ -401,10 +391,8 @@ def __init__(
401391
"dask-ssh_" + datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S"),
402392
)
403393
print(
404-
bcolors.WARNING + "Output will be redirected to logfiles "
405-
'stored locally on individual worker nodes under "{logdir}".'.format(
406-
logdir=logdir
407-
)
394+
bcolors.WARNING
395+
+ f'Output will be redirected to logfiles stored locally on individual worker nodes under "{logdir}".'
408396
+ bcolors.ENDC
409397
)
410398
self.logdir = logdir

0 commit comments

Comments
 (0)