diff --git a/fsspec/core.py b/fsspec/core.py index e79f2a894..e44fbe98e 100644 --- a/fsspec/core.py +++ b/fsspec/core.py @@ -673,9 +673,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)] diff --git a/fsspec/implementations/cached.py b/fsspec/implementations/cached.py index 447e4f267..8b8b83295 100644 --- a/fsspec/implementations/cached.py +++ b/fsspec/implementations/cached.py @@ -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 = [] diff --git a/fsspec/implementations/ftp.py b/fsspec/implementations/ftp.py index f3471b996..4186b6ce3 100644 --- a/fsspec/implementations/ftp.py +++ b/fsspec/implementations/ftp.py @@ -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" diff --git a/fsspec/implementations/tests/test_local.py b/fsspec/implementations/tests/test_local.py index ef3927912..15cd75468 100644 --- a/fsspec/implementations/tests/test_local.py +++ b/fsspec/implementations/tests/test_local.py @@ -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") @@ -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") diff --git a/fsspec/implementations/tests/test_zip.py b/fsspec/implementations/tests/test_zip.py index 14d00086e..814273761 100644 --- a/fsspec/implementations/tests/test_zip.py +++ b/fsspec/implementations/tests/test_zip.py @@ -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", diff --git a/fsspec/parquet.py b/fsspec/parquet.py index 5a0fb951c..faedb7b9e 100644 --- a/fsspec/parquet.py +++ b/fsspec/parquet.py @@ -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 diff --git a/fsspec/tests/test_parquet.py b/fsspec/tests/test_parquet.py index 5f38db7c6..7a764142d 100644 --- a/fsspec/tests/test_parquet.py +++ b/fsspec/tests/test_parquet.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 48368711f..d68123444 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -180,8 +180,8 @@ select = [ "RUF006", "RUF015", "RUF024", + "SIM", "SLOT", - "SIM101", ] ignore = [ # Loop control variable `loop` not used within loop body @@ -206,6 +206,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