Skip to content

Commit 4d1ec47

Browse files
Apply ruff/pyupgrade rules (UP) (#1717)
Co-authored-by: Martin Durant <[email protected]>
1 parent b9daa8b commit 4d1ec47

14 files changed

+36
-36
lines changed

Diff for: fsspec/asyn.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -816,11 +816,9 @@ async def _glob(self, path, maxdepth=None, **kwargs):
816816
p: info
817817
for p, info in sorted(allpaths.items())
818818
if pattern.match(
819-
(
820-
p + "/"
821-
if append_slash_to_dirname and info["type"] == "directory"
822-
else p
823-
)
819+
p + "/"
820+
if append_slash_to_dirname and info["type"] == "directory"
821+
else p
824822
)
825823
}
826824

Diff for: fsspec/caching.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import os
88
import threading
99
import warnings
10+
from concurrent.futures import Future, ThreadPoolExecutor
1011
from itertools import groupby
1112
from operator import itemgetter
12-
from concurrent.futures import Future, ThreadPoolExecutor
1313
from typing import (
1414
TYPE_CHECKING,
1515
Any,
@@ -87,12 +87,7 @@ def _log_stats(self) -> str:
8787
if self.hit_count == 0 and self.miss_count == 0:
8888
# a cache that does nothing, this is for logs only
8989
return ""
90-
return " , %s: %d hits, %d misses, %d total requested bytes" % (
91-
self.name,
92-
self.hit_count,
93-
self.miss_count,
94-
self.total_requested_bytes,
95-
)
90+
return f" , {self.name}: {self.hit_count} hits, {self.miss_count} misses, {self.total_requested_bytes} total requested bytes"
9691

9792
def __repr__(self) -> str:
9893
# TODO: use rich for better formatting

Diff for: fsspec/implementations/asyn_wrapper.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
2-
import inspect
32
import functools
3+
import inspect
4+
45
from fsspec.asyn import AsyncFileSystem
56

67

Diff for: fsspec/implementations/reference.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def open_refs(field, record):
176176
try:
177177
df = self.pd.read_parquet(data, engine=self.engine)
178178
refs = {c: df[c].to_numpy() for c in df.columns}
179-
except IOError:
179+
except OSError:
180180
refs = None
181181
return refs
182182

@@ -431,7 +431,7 @@ def write(self, field, record, base_url=None, storage_options=None):
431431
if len(partition) < self.record_size:
432432
try:
433433
original = self.open_refs(field, record)
434-
except IOError:
434+
except OSError:
435435
pass
436436

437437
if original:

Diff for: fsspec/implementations/tests/test_asyn_wrapper.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import asyncio
2-
import pytest
32
import os
43

4+
import pytest
5+
56
import fsspec
67
from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper
78
from fsspec.implementations.local import LocalFileSystem
9+
810
from .test_local import csv_files, filetexts
911

1012

Diff for: fsspec/implementations/tests/test_smb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030

3131
def stop_docker(container):
32-
cmd = shlex.split('docker ps -a -q --filter "name=%s"' % container)
32+
cmd = shlex.split(f'docker ps -a -q --filter "name={container}"')
3333
cid = subprocess.check_output(cmd).strip().decode()
3434
if cid:
3535
subprocess.call(["docker", "rm", "-f", "-v", cid])

Diff for: fsspec/implementations/tests/test_zip.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_zip_glob_star(m):
105105
outfiles = fs.glob("*")
106106
assert len(outfiles) == 1
107107

108-
fn = f"{os.path.dirname(os.path.abspath((__file__)))}/out.zip"
108+
fn = f"{os.path.dirname(os.path.abspath(__file__))}/out.zip"
109109
fs = fsspec.filesystem("zip", fo=fn, mode="r")
110110
outfiles = fs.glob("*")
111111
assert len(outfiles) == 1

Diff for: fsspec/spec.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from errno import ESPIPE
1111
from glob import has_magic
1212
from hashlib import sha256
13-
from typing import Any, ClassVar, Dict, Tuple
13+
from typing import Any, ClassVar
1414

1515
from .callbacks import DEFAULT_CALLBACK
1616
from .config import apply_config, conf
@@ -117,8 +117,8 @@ class AbstractFileSystem(metaclass=_Cached):
117117
_extra_tokenize_attributes = ()
118118

119119
# Set by _Cached metaclass
120-
storage_args: Tuple[Any, ...]
121-
storage_options: Dict[str, Any]
120+
storage_args: tuple[Any, ...]
121+
storage_options: dict[str, Any]
122122

123123
def __init__(self, *args, **storage_options):
124124
"""Create and configure file-system instance
@@ -615,11 +615,9 @@ def glob(self, path, maxdepth=None, **kwargs):
615615
p: info
616616
for p, info in sorted(allpaths.items())
617617
if pattern.match(
618-
(
619-
p + "/"
620-
if append_slash_to_dirname and info["type"] == "directory"
621-
else p
622-
)
618+
p + "/"
619+
if append_slash_to_dirname and info["type"] == "directory"
620+
else p
623621
)
624622
}
625623

@@ -1442,7 +1440,7 @@ def from_json(blob: str) -> AbstractFileSystem:
14421440

14431441
return json.loads(blob, cls=FilesystemJSONDecoder)
14441442

1445-
def to_dict(self, *, include_password: bool = True) -> Dict[str, Any]:
1443+
def to_dict(self, *, include_password: bool = True) -> dict[str, Any]:
14461444
"""
14471445
JSON-serializable dictionary representation of this filesystem instance.
14481446
@@ -1483,7 +1481,7 @@ def to_dict(self, *, include_password: bool = True) -> Dict[str, Any]:
14831481
)
14841482

14851483
@staticmethod
1486-
def from_dict(dct: Dict[str, Any]) -> AbstractFileSystem:
1484+
def from_dict(dct: dict[str, Any]) -> AbstractFileSystem:
14871485
"""
14881486
Recreate a filesystem instance from dictionary representation.
14891487

Diff for: fsspec/tests/abstract/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def _10_files_with_hashed_names(self, some_fs, some_join, some_path):
225225
for i in range(10):
226226
hashed_i = md5(str(i).encode("utf-8")).hexdigest()
227227
path = some_join(source, f"{hashed_i}.txt")
228-
some_fs.pipe(path=path, value=f"{i}".encode("utf-8"))
228+
some_fs.pipe(path=path, value=f"{i}".encode())
229229
return source
230230

231231

Diff for: fsspec/tests/test_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ async def get_data(self):
208208
async def test_async_streamed_file_write():
209209
test_fs = DummyAsyncFS()
210210
streamed_file = await test_fs.open_async("misc/foo.txt", mode="wb")
211-
inp_data = "foo-bar".encode("utf8") * streamed_file.blocksize * 2
211+
inp_data = b"foo-bar" * streamed_file.blocksize * 2
212212
await streamed_file.write(inp_data)
213213
assert streamed_file.loc == len(inp_data)
214214
await streamed_file.close()

Diff for: fsspec/tests/test_fuse.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ def test_chmod(mount_local):
121121

122122
cp = subprocess.run(
123123
["cp", str(mount_dir / "text"), str(mount_dir / "new")],
124-
stdout=subprocess.PIPE,
125-
stderr=subprocess.PIPE,
124+
capture_output=True,
126125
check=False,
127126
)
128127

Diff for: fsspec/tests/test_utils.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ def test_read_block():
4545

4646
def test_read_block_split_before():
4747
"""Test start/middle/end cases of split_before."""
48-
d = (
49-
"#header" + "".join(">foo{i}\nFOOBAR{i}\n".format(i=i) for i in range(100000))
50-
).encode()
48+
d = ("#header" + "".join(f">foo{i}\nFOOBAR{i}\n" for i in range(100000))).encode()
5149

5250
# Read single record at beginning.
5351
# All reads include beginning of file and read through termination of

Diff for: fsspec/utils.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def infer_storage_options(
8282
# https://msdn.microsoft.com/en-us/library/jj710207.aspx
8383
windows_path = re.match(r"^/([a-zA-Z])[:|]([\\/].*)$", path)
8484
if windows_path:
85-
path = "%s:%s" % windows_path.groups()
85+
drive, path = windows_path.groups()
86+
path = f"{drive}:{path}"
8687

8788
if protocol in ["http", "https"]:
8889
# for HTTP, we don't want to parse, as requests will anyway

Diff for: pyproject.toml

+8
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ select = [
184184
"RUF024",
185185
"SIM",
186186
"SLOT",
187+
"SIM101",
188+
"UP",
187189
]
188190
ignore = [
189191
# Loop control variable `loop` not used within loop body
@@ -208,6 +210,12 @@ ignore = [
208210
# Fix these codes later
209211
"G004",
210212
"PERF203",
213+
"UP007",
214+
"UP011",
215+
"UP015",
216+
"UP018",
217+
# deprecated
218+
"UP027",
211219
"SIM102",
212220
"SIM105",
213221
"SIM108",

0 commit comments

Comments
 (0)