Skip to content

Commit 2eb2f59

Browse files
Apply ruff/flake8-simplify rules (SIM) (#1715)
1 parent dbed2ec commit 2eb2f59

File tree

8 files changed

+15
-11
lines changed

8 files changed

+15
-11
lines changed

fsspec/core.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,7 @@ def get_fs_token_paths(
680680
elif not isinstance(paths, list):
681681
paths = list(paths)
682682
else:
683-
if "w" in mode and expand:
684-
paths = _expand_paths(paths, name_function, num)
685-
elif "x" in mode and expand:
683+
if ("w" in mode or "x" in mode) and expand:
686684
paths = _expand_paths(paths, name_function, num)
687685
elif "*" in paths:
688686
paths = [f for f in sorted(fs.glob(paths)) if not fs.isdir(f)]

fsspec/implementations/cached.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def cat(
612612
**kwargs,
613613
):
614614
paths = self.expand_path(
615-
path, recursive=recursive, maxdepth=kwargs.get("maxdepth", None)
615+
path, recursive=recursive, maxdepth=kwargs.get("maxdepth")
616616
)
617617
getpaths = []
618618
storepaths = []

fsspec/implementations/ftp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def _mlsd2(ftp, path="."):
387387
"size": split_line[4],
388388
},
389389
)
390-
if "d" == this[1]["unix.mode"][0]:
390+
if this[1]["unix.mode"][0] == "d":
391391
this[1]["type"] = "dir"
392392
else:
393393
this[1]["type"] = "file"

fsspec/implementations/tests/test_local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def test_not_found():
247247
def test_isfile():
248248
fs = LocalFileSystem()
249249
with filetexts(files, mode="b"):
250-
for f in files.keys():
250+
for f in files:
251251
assert fs.isfile(f)
252252
assert fs.isfile(f"file://{f}")
253253
assert not fs.isfile("not-a-file")
@@ -257,7 +257,7 @@ def test_isfile():
257257
def test_isdir():
258258
fs = LocalFileSystem()
259259
with filetexts(files, mode="b"):
260-
for f in files.keys():
260+
for f in files:
261261
assert fs.isdir(os.path.dirname(os.path.abspath(f)))
262262
assert not fs.isdir(f)
263263
assert not fs.isdir("not-a-dir")

fsspec/implementations/tests/test_zip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def zip_file_fixture(tmp_path):
162162

163163

164164
def _assert_all_except_context_dependent_variables(result, expected_result):
165-
for path in expected_result.keys():
165+
for path in expected_result:
166166
assert result[path]
167167
fields = [
168168
"orig_filename",

fsspec/parquet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def _add_header_magic(data):
336336
# Add b"PAR1" to file headers
337337
for path in list(data.keys()):
338338
add_magic = True
339-
for k in data[path].keys():
339+
for k in data[path]:
340340
if k[0] == 0 and k[1] >= 4:
341341
add_magic = False
342342
break

fsspec/tests/test_parquet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_open_parquet_file(
9191
# the footer metadata, so there should NOT
9292
# be a key for the last 8 bytes of the file
9393
bad_key = (file_size - 8, file_size)
94-
assert bad_key not in data.keys()
94+
assert bad_key not in data
9595

9696
for (start, stop), byte_data in data.items():
9797
f.seek(start)

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ select = [
181181
"RUF006",
182182
"RUF015",
183183
"RUF024",
184+
"SIM",
184185
"SLOT",
185-
"SIM101",
186186
]
187187
ignore = [
188188
# Loop control variable `loop` not used within loop body
@@ -207,6 +207,12 @@ ignore = [
207207
# Fix these codes later
208208
"G004",
209209
"PERF203",
210+
"SIM102",
211+
"SIM105",
212+
"SIM108",
213+
"SIM114",
214+
"SIM115",
215+
"SIM117",
210216
# https://github.com/astral-sh/ruff/issues/7871
211217
"UP038",
212218
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules

0 commit comments

Comments
 (0)