Skip to content

Commit ec13d27

Browse files
authored
Add ruff pre-commit hook (#1502)
1 parent 7b774c2 commit ec13d27

File tree

16 files changed

+82
-27
lines changed

16 files changed

+82
-27
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ repos:
1616
rev: 22.3.0
1717
hooks:
1818
- id: black
19+
- repo: https://github.com/astral-sh/ruff-pre-commit
20+
# Ruff version.
21+
rev: v0.1.13
22+
hooks:
23+
# Run the linter.
24+
- id: ruff
25+
args: [ --fix ]
1926
- repo: https://github.com/PyCQA/flake8
2027
rev: 5.0.4
2128
hooks:

fsspec/exceptions.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ class BlocksizeMismatchError(ValueError):
1010
written with
1111
"""
1212

13-
...
14-
1513

1614
class FSTimeoutError(asyncio.TimeoutError):
1715
"""
1816
Raised when a fsspec function timed out occurs
1917
"""
20-
21-
...

fsspec/gui.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ def _emit(self, sig, value=None):
153153
break
154154
except Exception as e:
155155
logger.exception(
156-
"Exception (%s) while executing callback for signal: %s"
157-
"" % (e, sig)
156+
"Exception (%s) while executing callback for signal: %s",
157+
e,
158+
sig,
158159
)
159160

160161
def show(self, threads=False):

fsspec/implementations/cache_mapper.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22

33
import abc
44
import hashlib
5-
from typing import TYPE_CHECKING
65

76
from fsspec.implementations.local import make_path_posix
87

9-
if TYPE_CHECKING:
10-
from typing import Any
11-
128

139
class AbstractCacheMapper(abc.ABC):
1410
"""Abstract super-class for mappers from remote URLs to local cached
@@ -19,7 +15,7 @@ class AbstractCacheMapper(abc.ABC):
1915
def __call__(self, path: str) -> str:
2016
...
2117

22-
def __eq__(self, other: Any) -> bool:
18+
def __eq__(self, other: object) -> bool:
2319
# Identity only depends on class. When derived classes have attributes
2420
# they will need to be included.
2521
return isinstance(other, type(self))
@@ -56,7 +52,7 @@ def __call__(self, path: str) -> str:
5652
else:
5753
return prefix # No separator found, simple filename
5854

59-
def __eq__(self, other: Any) -> bool:
55+
def __eq__(self, other: object) -> bool:
6056
return super().__eq__(other) and self.directory_levels == other.directory_levels
6157

6258
def __hash__(self) -> int:

fsspec/implementations/http.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ async def _get_file(
251251
if isfilelike(lpath):
252252
outfile = lpath
253253
else:
254-
outfile = open(lpath, "wb")
254+
outfile = open(lpath, "wb") # noqa: ASYNC101
255255

256256
try:
257257
chunk = True
@@ -279,7 +279,7 @@ async def gen_chunks():
279279
context = nullcontext(lpath)
280280
use_seek = False # might not support seeking
281281
else:
282-
context = open(lpath, "rb")
282+
context = open(lpath, "rb") # noqa: ASYNC101
283283
use_seek = True
284284

285285
with context as f:
@@ -801,7 +801,7 @@ async def get_range(session, url, start, end, file=None, **kwargs):
801801
async with r:
802802
out = await r.read()
803803
if file:
804-
with open(file, "r+b") as f:
804+
with open(file, "r+b") as f: # noqa: ASYNC101
805805
f.seek(start)
806806
f.write(out)
807807
else:

fsspec/implementations/tests/test_cached.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ def test_multi_cache(protocol):
10221022
def test_multi_cat(protocol, ftp_writable):
10231023
host, port, user, pw = ftp_writable
10241024
fs = FTPFileSystem(host, port, user, pw)
1025-
for fn in {"/file0", "/file1"}:
1025+
for fn in ("/file0", "/file1"):
10261026
with fs.open(fn, "wb") as f:
10271027
f.write(b"hello")
10281028

fsspec/implementations/tests/test_dirfs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ async def _walk(path, *args, **kwargs):
355355

356356
actual = []
357357
async for entry in adirfs._walk("root", *ARGS, **KWARGS):
358-
actual.append(entry)
358+
actual.append(entry) # noqa: PERF402
359359
assert actual == [("root", ["foo", "bar"], ["baz", "qux"])]
360360
adirfs.fs._walk.assert_called_once_with(f"{PATH}/root", *ARGS, **KWARGS)
361361

fsspec/implementations/tests/test_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ async def test_async_walk(server):
557557
# No maxdepth
558558
res = []
559559
async for a in fs._walk(server + "/index"):
560-
res.append(a)
560+
res.append(a) # noqa: PERF402
561561
assert res == [(server + "/index", [], ["realfile"])]
562562

563563
# maxdepth=0

fsspec/implementations/tests/test_reference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ def test_nested_dirs_ls():
6161
refs = {"a": "A", "B/C/b": "B", "B/C/d": "d", "B/_": "_"}
6262
fs = fsspec.filesystem("reference", fo=refs)
6363
assert len(fs.ls("")) == 2
64-
assert set(e["name"] for e in fs.ls("")) == set(["a", "B"])
64+
assert {e["name"] for e in fs.ls("")} == {"a", "B"}
6565
assert len(fs.ls("B")) == 2
66-
assert set(e["name"] for e in fs.ls("B")) == set(["B/C", "B/_"])
66+
assert {e["name"] for e in fs.ls("B")} == {"B/C", "B/_"}
6767

6868

6969
def test_info(server): # noqa: F811

fsspec/implementations/tests/test_tar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_info():
4242
assert lhs == expected
4343

4444
# Iterate over all files.
45-
for f, v in archive_data.items():
45+
for f in archive_data:
4646
lhs = fs.info(f)
4747

4848
# Probe some specific fields of Tar archives.

0 commit comments

Comments
 (0)