Skip to content

Commit

Permalink
Apply ruff/flake8-simplify rules (SIM) (#1715)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos authored Nov 15, 2024
1 parent dbed2ec commit 2eb2f59
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 11 deletions.
4 changes: 1 addition & 3 deletions fsspec/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,7 @@ def get_fs_token_paths(
elif not isinstance(paths, list):
paths = list(paths)
else:
if "w" in mode and expand:
paths = _expand_paths(paths, name_function, num)
elif "x" in mode and expand:
if ("w" in mode or "x" in mode) and expand:
paths = _expand_paths(paths, name_function, num)
elif "*" in paths:
paths = [f for f in sorted(fs.glob(paths)) if not fs.isdir(f)]
Expand Down
2 changes: 1 addition & 1 deletion fsspec/implementations/cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def cat(
**kwargs,
):
paths = self.expand_path(
path, recursive=recursive, maxdepth=kwargs.get("maxdepth", None)
path, recursive=recursive, maxdepth=kwargs.get("maxdepth")
)
getpaths = []
storepaths = []
Expand Down
2 changes: 1 addition & 1 deletion fsspec/implementations/ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def _mlsd2(ftp, path="."):
"size": split_line[4],
},
)
if "d" == this[1]["unix.mode"][0]:
if this[1]["unix.mode"][0] == "d":
this[1]["type"] = "dir"
else:
this[1]["type"] = "file"
Expand Down
4 changes: 2 additions & 2 deletions fsspec/implementations/tests/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def test_not_found():
def test_isfile():
fs = LocalFileSystem()
with filetexts(files, mode="b"):
for f in files.keys():
for f in files:
assert fs.isfile(f)
assert fs.isfile(f"file://{f}")
assert not fs.isfile("not-a-file")
Expand All @@ -257,7 +257,7 @@ def test_isfile():
def test_isdir():
fs = LocalFileSystem()
with filetexts(files, mode="b"):
for f in files.keys():
for f in files:
assert fs.isdir(os.path.dirname(os.path.abspath(f)))
assert not fs.isdir(f)
assert not fs.isdir("not-a-dir")
Expand Down
2 changes: 1 addition & 1 deletion fsspec/implementations/tests/test_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def zip_file_fixture(tmp_path):


def _assert_all_except_context_dependent_variables(result, expected_result):
for path in expected_result.keys():
for path in expected_result:
assert result[path]
fields = [
"orig_filename",
Expand Down
2 changes: 1 addition & 1 deletion fsspec/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def _add_header_magic(data):
# Add b"PAR1" to file headers
for path in list(data.keys()):
add_magic = True
for k in data[path].keys():
for k in data[path]:
if k[0] == 0 and k[1] >= 4:
add_magic = False
break
Expand Down
2 changes: 1 addition & 1 deletion fsspec/tests/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_open_parquet_file(
# the footer metadata, so there should NOT
# be a key for the last 8 bytes of the file
bad_key = (file_size - 8, file_size)
assert bad_key not in data.keys()
assert bad_key not in data

for (start, stop), byte_data in data.items():
f.seek(start)
Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ select = [
"RUF006",
"RUF015",
"RUF024",
"SIM",
"SLOT",
"SIM101",
]
ignore = [
# Loop control variable `loop` not used within loop body
Expand All @@ -207,6 +207,12 @@ ignore = [
# Fix these codes later
"G004",
"PERF203",
"SIM102",
"SIM105",
"SIM108",
"SIM114",
"SIM115",
"SIM117",
# https://github.com/astral-sh/ruff/issues/7871
"UP038",
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
Expand Down

0 comments on commit 2eb2f59

Please sign in to comment.