Skip to content

Commit ee98ae3

Browse files
Apply more ruff rules (#1660)
1 parent 4f883ad commit ee98ae3

19 files changed

+32
-54
lines changed

fsspec/asyn.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ async def flush(self, force=False):
10721072
self.offset = 0
10731073
try:
10741074
await self._initiate_upload()
1075-
except: # noqa: E722
1075+
except:
10761076
self.closed = True
10771077
raise
10781078

fsspec/implementations/arrow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def cp_file(self, path1, path2, **kwargs):
128128
with self.open(tmp_fname, "wb") as rstream:
129129
shutil.copyfileobj(lstream, rstream)
130130
self.fs.move(tmp_fname, path2)
131-
except BaseException: # noqa
131+
except BaseException:
132132
with suppress(FileNotFoundError):
133133
self.fs.delete_file(tmp_fname)
134134
raise

fsspec/implementations/dbfs.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def ls(self, path, detail=True, **kwargs):
7979
if e.error_code == "RESOURCE_DOES_NOT_EXIST":
8080
raise FileNotFoundError(e.message) from e
8181

82-
raise e
82+
raise
8383
files = r["files"]
8484
out = [
8585
{
@@ -125,7 +125,7 @@ def makedirs(self, path, exist_ok=True):
125125
if e.error_code == "RESOURCE_ALREADY_EXISTS":
126126
raise FileExistsError(e.message) from e
127127

128-
raise e
128+
raise
129129
self.invalidate_cache(self._parent(path))
130130

131131
def mkdir(self, path, create_parents=True, **kwargs):
@@ -171,7 +171,7 @@ def rm(self, path, recursive=False, **kwargs):
171171
# Using the same exception as the os module would use here
172172
raise OSError(e.message) from e
173173

174-
raise e
174+
raise
175175
self.invalidate_cache(self._parent(path))
176176

177177
def mv(
@@ -216,7 +216,7 @@ def mv(
216216
elif e.error_code == "RESOURCE_ALREADY_EXISTS":
217217
raise FileExistsError(e.message) from e
218218

219-
raise e
219+
raise
220220
self.invalidate_cache(self._parent(source_path))
221221
self.invalidate_cache(self._parent(destination_path))
222222

@@ -299,7 +299,7 @@ def _create_handle(self, path, overwrite=True):
299299
if e.error_code == "RESOURCE_ALREADY_EXISTS":
300300
raise FileExistsError(e.message) from e
301301

302-
raise e
302+
raise
303303

304304
def _close_handle(self, handle):
305305
"""
@@ -316,7 +316,7 @@ def _close_handle(self, handle):
316316
if e.error_code == "RESOURCE_DOES_NOT_EXIST":
317317
raise FileNotFoundError(e.message) from e
318318

319-
raise e
319+
raise
320320

321321
def _add_data(self, handle, data):
322322
"""
@@ -346,7 +346,7 @@ def _add_data(self, handle, data):
346346
elif e.error_code == "MAX_BLOCK_SIZE_EXCEEDED":
347347
raise ValueError(e.message) from e
348348

349-
raise e
349+
raise
350350

351351
def _get_data(self, path, start, end):
352352
"""
@@ -376,7 +376,7 @@ def _get_data(self, path, start, end):
376376
elif e.error_code in ["INVALID_PARAMETER_VALUE", "MAX_READ_SIZE_EXCEEDED"]:
377377
raise ValueError(e.message) from e
378378

379-
raise e
379+
raise
380380

381381
def invalidate_cache(self, path=None):
382382
if path is None:

fsspec/implementations/reference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def open_refs(field, record):
159159
path = self.url.format(field=field, record=record)
160160
data = io.BytesIO(self.fs.cat_file(path))
161161
df = self.pd.read_parquet(data, engine="fastparquet")
162-
refs = {c: df[c].values for c in df.columns}
162+
refs = {c: df[c].to_numpy() for c in df.columns}
163163
return refs
164164

165165
self.open_refs = open_refs

fsspec/implementations/smb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def _connect(self):
202202
else:
203203
# All another ValueError exceptions should be raised, as they are not
204204
# related to network issues.
205-
raise exc
205+
raise
206206
except Exception as exc:
207207
# Save the exception and retry to connect. This except might be dropped
208208
# in the future, once all exceptions suited for retry are identified.

fsspec/implementations/tests/test_arrow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
pyarrow_fs = pytest.importorskip("pyarrow.fs")
66
FileSystem = pyarrow_fs.FileSystem
77

8-
from fsspec.implementations.arrow import ArrowFSWrapper, HadoopFileSystem # noqa
8+
from fsspec.implementations.arrow import ArrowFSWrapper, HadoopFileSystem # noqa: E402
99

1010

1111
@pytest.fixture(scope="function")

fsspec/implementations/tests/test_reference.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from fsspec.tests.conftest import data, realfile, reset_files, server, win # noqa: F401
1414

1515

16-
def test_simple(server): # noqa: F811
16+
def test_simple(server):
1717
# The dictionary in refs may be dumped with a different separator
1818
# depending on whether json or ujson is imported
1919
from fsspec.implementations.reference import json as json_impl
@@ -37,7 +37,7 @@ def test_simple(server): # noqa: F811
3737
assert f.read(2) == "he"
3838

3939

40-
def test_simple_ver1(server): # noqa: F811
40+
def test_simple_ver1(server):
4141
# The dictionary in refs may be dumped with a different separator
4242
# depending on whether json or ujson is imported
4343
from fsspec.implementations.reference import json as json_impl
@@ -75,7 +75,7 @@ def test_target_options(m):
7575
assert fs.cat("a") == b"hello"
7676

7777

78-
def test_ls(server): # noqa: F811
78+
def test_ls(server):
7979
refs = {"a": b"data", "b": (realfile, 0, 5), "c/d": (realfile, 1, 6)}
8080
h = fsspec.filesystem("http")
8181
fs = fsspec.filesystem("reference", fo=refs, fs=h)
@@ -99,7 +99,7 @@ def test_nested_dirs_ls():
9999
assert {e["name"] for e in fs.ls("B")} == {"B/C", "B/_"}
100100

101101

102-
def test_info(server): # noqa: F811
102+
def test_info(server):
103103
refs = {
104104
"a": b"data",
105105
"b": (realfile, 0, 5),
@@ -173,7 +173,7 @@ def test_put_get_single(tmpdir):
173173
assert fs.cat("hi") == b"data"
174174

175175

176-
def test_defaults(server): # noqa: F811
176+
def test_defaults(server):
177177
refs = {"a": b"data", "b": (None, 0, 5)}
178178
fs = fsspec.filesystem(
179179
"reference",

fsspec/implementations/tests/test_smb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def smb_params(request):
5050
cfg = "-p -u 'testuser;testpass' -s 'home;/share;no;no;no;testuser'"
5151
port = request.param if request.param is not None else default_port
5252
img = (
53-
f"docker run --name {container} --detach -p 139:139 -p {port}:445 dperson/samba" # noqa: E231 E501
53+
f"docker run --name {container} --detach -p 139:139 -p {port}:445 dperson/samba"
5454
)
5555
cmd = f"{img} {cfg}"
5656
try:

fsspec/implementations/webhdfs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __init__(
102102
if self._cached:
103103
return
104104
super().__init__(**kwargs)
105-
self.url = f"{'https' if use_https else 'http'}://{host}:{port}/webhdfs/v1" # noqa
105+
self.url = f"{'https' if use_https else 'http'}://{host}:{port}/webhdfs/v1"
106106
self.kerb = kerberos
107107
self.kerb_kwargs = kerb_kwargs or {}
108108
self.pars = {}
@@ -393,7 +393,7 @@ def cp_file(self, lpath, rpath, **kwargs):
393393
with self.open(tmp_fname, "wb") as rstream:
394394
shutil.copyfileobj(lstream, rstream)
395395
self.mv(tmp_fname, rpath)
396-
except BaseException: # noqa
396+
except BaseException:
397397
with suppress(FileNotFoundError):
398398
self.rm(tmp_fname)
399399
raise

fsspec/spec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ def flush(self, force=False):
18921892
self.offset = 0
18931893
try:
18941894
self._initiate_upload()
1895-
except: # noqa: E722
1895+
except:
18961896
self.closed = True
18971897
raise
18981898

fsspec/tests/abstract/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import pytest
55

66
from fsspec.implementations.local import LocalFileSystem
7-
from fsspec.tests.abstract.copy import AbstractCopyTests # noqa
8-
from fsspec.tests.abstract.get import AbstractGetTests # noqa
9-
from fsspec.tests.abstract.put import AbstractPutTests # noqa
7+
from fsspec.tests.abstract.copy import AbstractCopyTests # noqa: F401
8+
from fsspec.tests.abstract.get import AbstractGetTests # noqa: F401
9+
from fsspec.tests.abstract.put import AbstractPutTests # noqa: F401
1010

1111

1212
class BaseAbstractFixtures:

fsspec/tests/test_async.py

-3
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ async def _upload_chunk(self, final=False):
203203
async def get_data(self):
204204
return self.temp_buffer.getbuffer().tobytes()
205205

206-
async def get_data(self):
207-
return self.temp_buffer.getbuffer().tobytes()
208-
209206

210207
@pytest.mark.asyncio
211208
async def test_async_streamed_file_write():

fsspec/tests/test_downstream.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pytest.importorskip("moto")
55

66
try:
7-
from s3fs.tests.test_s3fs import ( # noqa: E402,F401
7+
from s3fs.tests.test_s3fs import ( # noqa: F401
88
endpoint_uri,
99
s3,
1010
s3_base,

fsspec/tests/test_fuse.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import pytest
77

88
try:
9-
pytest.importorskip("fuse") # noqa: E402
9+
pytest.importorskip("fuse")
1010
except OSError:
1111
# can succeed in importing fuse, but fail to load so
12-
pytest.importorskip("nonexistent") # noqa: E402
12+
pytest.importorskip("nonexistent")
1313

1414
from fsspec.fuse import main, run
1515
from fsspec.implementations.memory import MemoryFileSystem

fsspec/tests/test_registry.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_entry_points_registered_on_import(clear_registry, clean_imports):
105105
import_location = "importlib.metadata.entry_points"
106106
with patch(import_location, return_value={"fsspec.specs": [mock_ep]}):
107107
assert "test" not in registry
108-
import fsspec # noqa
108+
import fsspec # noqa: F401
109109

110110
get_filesystem_class("test")
111111
assert "test" in registry
@@ -117,7 +117,7 @@ def test_filesystem_warning_arrow_hdfs_deprecated(clear_registry, clean_imports)
117117
mock_ep.value = "fsspec.spec.AbstractFileSystem"
118118
import_location = "importlib.metadata.entry_points"
119119
with patch(import_location, return_value={"fsspec.specs": [mock_ep]}):
120-
import fsspec # noqa
120+
import fsspec # noqa: F401
121121

122122
with pytest.warns(DeprecationWarning):
123123
filesystem("arrow_hdfs")

fsspec/tests/test_spec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ def glob_files_folder(tmp_path):
12761276
local_fake_dir = str(tmp_path)
12771277
for path_info in PATHS_FOR_GLOB_TESTS:
12781278
if path_info["type"] == "file":
1279-
local_fs.touch(path=f"{str(tmp_path)}/{path_info['name']}")
1279+
local_fs.touch(path=f"{tmp_path}/{path_info['name']}")
12801280
return local_fake_dir
12811281

12821282

fsspec/tests/test_utils.py

-13
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ def test_common_prefix(paths, out):
261261
(
262262
(["/path1"], "/path2", False, ["/path2"]),
263263
(["/path1"], "/path2", True, ["/path2/path1"]),
264-
(["/path1"], "/path2", False, ["/path2"]),
265264
(["/path1"], "/path2/", True, ["/path2/path1"]),
266265
(["/path1"], ["/path2"], False, ["/path2"]),
267266
(["/path1"], ["/path2"], True, ["/path2"]),
@@ -279,18 +278,6 @@ def test_common_prefix(paths, out):
279278
True,
280279
["/path2/more/path1", "/path2/more/path2"],
281280
),
282-
(
283-
["/more/path1", "/more/path2"],
284-
"/path2",
285-
False,
286-
["/path2/path1", "/path2/path2"],
287-
),
288-
(
289-
["/more/path1", "/more/path2"],
290-
"/path2",
291-
True,
292-
["/path2/more/path1", "/path2/more/path2"],
293-
),
294281
(
295282
["/more/path1", "/more/path2"],
296283
"/path2/",

fsspec/utils.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,7 @@ def is_exception(obj: Any) -> bool:
427427

428428

429429
def isfilelike(f: Any) -> TypeGuard[IO[bytes]]:
430-
for attr in ["read", "close", "tell"]:
431-
if not hasattr(f, attr):
432-
return False
433-
return True
430+
return all(hasattr(f, attr) for attr in ["read", "close", "tell"])
434431

435432

436433
def get_protocol(url: str) -> str:

pyproject.toml

-3
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,6 @@ ignore = [
192192
"B026",
193193
# No explicit `stacklevel` keyword argument found
194194
"B028",
195-
# Within an `except` clause, raise exceptions with `raise ... from err` or
196-
# `raise ... from None` to distinguish them from errors in exception handling
197-
"B904",
198195
# Assigning lambda expression
199196
"E731",
200197
# Ambiguous variable names

0 commit comments

Comments
 (0)