Skip to content

Commit 4dee569

Browse files
committed
ruff check --select UP --fix
1 parent 064f221 commit 4dee569

File tree

12 files changed

+27
-48
lines changed

12 files changed

+27
-48
lines changed

fsspec/caching.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@
88
import threading
99
import warnings
1010
from collections import OrderedDict
11+
from collections.abc import Callable
1112
from concurrent.futures import Future, ThreadPoolExecutor
1213
from itertools import groupby
1314
from operator import itemgetter
14-
from typing import (
15-
TYPE_CHECKING,
16-
Any,
17-
Callable,
18-
ClassVar,
19-
Generic,
20-
NamedTuple,
21-
TypeVar,
22-
)
15+
from typing import TYPE_CHECKING, Any, ClassVar, Generic, NamedTuple, TypeVar
2316

2417
if TYPE_CHECKING:
2518
import mmap

fsspec/implementations/cache_metadata.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515

1616
if TYPE_CHECKING:
1717
from collections.abc import Iterator
18-
from typing import Any, Literal
19-
20-
from typing_extensions import TypeAlias
18+
from typing import Any, Literal, TypeAlias
2119

2220
from .cached import CachingFileSystem
2321

@@ -57,7 +55,7 @@ def __init__(self, storage: list[str]):
5755
def _load(self, fn: str) -> Detail:
5856
"""Low-level function to load metadata from specific file"""
5957
try:
60-
with open(fn, "r") as f:
58+
with open(fn) as f:
6159
loaded = json.load(f)
6260
except ValueError:
6361
with open(fn, "rb") as f:

fsspec/implementations/cached.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import tempfile
77
import time
88
import weakref
9+
from collections.abc import Callable
910
from shutil import rmtree
10-
from typing import TYPE_CHECKING, Any, Callable, ClassVar
11+
from typing import TYPE_CHECKING, Any, ClassVar
1112

1213
from fsspec import filesystem
1314
from fsspec.callbacks import DEFAULT_CALLBACK

fsspec/implementations/data.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import base64
22
import io
3-
from typing import Optional
43
from urllib.parse import unquote
54

65
from fsspec import AbstractFileSystem
@@ -50,7 +49,7 @@ def _open(
5049
return io.BytesIO(self.cat_file(path))
5150

5251
@staticmethod
53-
def encode(data: bytes, mime: Optional[str] = None):
52+
def encode(data: bytes, mime: str | None = None):
5453
"""Format the given data into data-URL syntax
5554
5655
This version always base64 encodes, even when the data is ascii/url-safe.

fsspec/implementations/libarchive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def _open(
195195
if mode != "rb":
196196
raise NotImplementedError
197197

198-
data = bytes()
198+
data = b""
199199
with self._open_archive() as arc:
200200
for entry in arc:
201201
if entry.pathname != path:

fsspec/implementations/reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def create(root, storage_options=None, fs=None, record_size=10000, **kwargs):
219219
fs.pipe("/".join([root, ".zmetadata"]), json.dumps(met).encode())
220220
return LazyReferenceMapper(root, fs, **kwargs)
221221

222-
@lru_cache()
222+
@lru_cache
223223
def listdir(self):
224224
"""List top-level directories"""
225225
dirs = (p.rsplit("/", 1)[0] for p in self.zmetadata if not p.startswith(".z"))

fsspec/implementations/tests/test_cached.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_metadata_replace_pickle_with_json(tmpdir):
185185
assert f.read(5) == b"test"
186186

187187
# Confirm metadata is in json format
188-
with open(cache_fn, "r") as f:
188+
with open(cache_fn) as f:
189189
metadata = json.load(f)
190190
assert list(metadata.keys()) == [make_path_posix(afile)]
191191

@@ -253,7 +253,7 @@ def test_blockcache_workflow(ftp_writable, tmp_path, force_save_pickle):
253253
with open(tmp_path / "cache", "rb") as f:
254254
cache = pickle.load(f)
255255
else:
256-
with open(tmp_path / "cache", "r") as f:
256+
with open(tmp_path / "cache") as f:
257257
cache = json.load(f)
258258
assert "/out" in cache
259259
assert cache["/out"]["blocks"] == [0, 1]
@@ -370,7 +370,7 @@ def __ager(cache_fn, fn, del_fn=False):
370370
with open(cache_fn, "rb") as f:
371371
cached_files = pickle.load(f)
372372
else:
373-
with open(cache_fn, "r") as f:
373+
with open(cache_fn) as f:
374374
cached_files = json.load(f)
375375
fn_posix = pathlib.Path(fn).as_posix()
376376
cached_files[fn_posix]["time"] = cached_files[fn_posix]["time"] - 691200

fsspec/implementations/tests/test_git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def repo():
2424
open(os.path.join(d, "file1"), "wb").write(b"data0")
2525
subprocess.call("git add file1", shell=True, cwd=d)
2626
subprocess.call('git commit -m "init"', shell=True, cwd=d)
27-
sha = open(os.path.join(d, ".git/refs/heads/master"), "r").read().strip()
27+
sha = open(os.path.join(d, ".git/refs/heads/master")).read().strip()
2828
open(os.path.join(d, "file1"), "wb").write(b"data00")
2929
subprocess.check_output('git commit -a -m "tagger"', shell=True, cwd=d)
3030
subprocess.call('git tag -a thetag -m "make tag"', shell=True, cwd=d)

fsspec/json.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import json
2-
from collections.abc import Mapping, Sequence
2+
from collections.abc import Callable, Mapping, Sequence
33
from contextlib import suppress
44
from pathlib import PurePath
5-
from typing import (
6-
Any,
7-
Callable,
8-
ClassVar,
9-
Optional,
10-
)
5+
from typing import Any, ClassVar
116

127
from .registry import _import_class, get_filesystem_class
138
from .spec import AbstractFileSystem
@@ -45,12 +40,12 @@ class FilesystemJSONDecoder(json.JSONDecoder):
4540
def __init__(
4641
self,
4742
*,
48-
object_hook: Optional[Callable[[dict[str, Any]], Any]] = None,
49-
parse_float: Optional[Callable[[str], Any]] = None,
50-
parse_int: Optional[Callable[[str], Any]] = None,
51-
parse_constant: Optional[Callable[[str], Any]] = None,
43+
object_hook: Callable[[dict[str, Any]], Any] | None = None,
44+
parse_float: Callable[[str], Any] | None = None,
45+
parse_int: Callable[[str], Any] | None = None,
46+
parse_constant: Callable[[str], Any] | None = None,
5247
strict: bool = True,
53-
object_pairs_hook: Optional[Callable[[list[tuple[str, Any]]], Any]] = None,
48+
object_pairs_hook: Callable[[list[tuple[str, Any]]], Any] | None = None,
5449
) -> None:
5550
self.original_object_hook = object_hook
5651

fsspec/tests/test_core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,14 @@ def test_open_file_write_with_special_characters(tmp_path, char, monkeypatch):
304304
with fsspec.open(file_path, "w", expand=False) as f:
305305
f.write(expected_content)
306306

307-
with open(file_path, "r") as f:
307+
with open(file_path) as f:
308308
actual_content = f.read()
309309

310310
monkeypatch.setattr(fsspec.core, "DEFAULT_EXPAND", False)
311311
with fsspec.open(file_path, "w") as f:
312312
f.write(expected_content * 2)
313313

314-
with open(file_path, "r") as f:
314+
with open(file_path) as f:
315315
assert f.read() == actual_content * 2
316316

317317
assert actual_content == expected_content
@@ -347,7 +347,7 @@ def test_open_files_write_with_special_characters(tmp_path, char):
347347
)[0] as f:
348348
f.write(expected_content)
349349

350-
with open(file_path, "r") as f:
350+
with open(file_path) as f:
351351
actual_content = f.read()
352352

353353
assert actual_content == expected_content

0 commit comments

Comments
 (0)