Skip to content

Commit e16063f

Browse files
Apply Sourcery suggestions and fix typos
1 parent dcb167e commit e16063f

28 files changed

+84
-97
lines changed

docs/source/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Enhancements
177177
- "tree" text display of filesystem contents (#1750)
178178
- async wrapper for sync FSs (#1745)
179179
- new known implementation: tosfs (#1739)
180-
- consilidate block fetch requests (#1733)
180+
- consolidate block fetch requests (#1733)
181181

182182
Fixes
183183

fsspec/archive.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def info(self, path, **kwargs):
4343
return {"name": "", "type": "directory", "size": 0}
4444
if path in self.dir_cache:
4545
return self.dir_cache[path]
46-
elif path + "/" in self.dir_cache:
47-
return self.dir_cache[path + "/"]
46+
elif f"{path}/" in self.dir_cache:
47+
return self.dir_cache[f"{path}/"]
4848
else:
4949
raise FileNotFoundError(path)
5050

@@ -69,7 +69,6 @@ def ls(self, path, detail=True, **kwargs):
6969
out = {"name": ppath, "size": 0, "type": "directory"}
7070
paths[ppath] = out
7171
if detail:
72-
out = sorted(paths.values(), key=operator.itemgetter("name"))
73-
return out
72+
return sorted(paths.values(), key=operator.itemgetter("name"))
7473
else:
7574
return sorted(paths)

fsspec/asyn.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ def sync(loop, func, *args, timeout=None, **kwargs):
8686
result = [None]
8787
event = threading.Event()
8888
asyncio.run_coroutine_threadsafe(_runner(event, coro, result, timeout), loop)
89-
while True:
90-
# this loops allows thread to get interrupted
91-
if event.wait(1):
92-
break
89+
while not event.wait(1):
90+
# this loop allows thread to get interrupted
9391
if timeout is not None:
9492
timeout -= 1
9593
if timeout < 0:
@@ -357,10 +355,11 @@ async def _copy(
357355
batch_size=None,
358356
**kwargs,
359357
):
360-
if on_error is None and recursive:
361-
on_error = "ignore"
362-
elif on_error is None:
363-
on_error = "raise"
358+
if on_error is None:
359+
if recursive:
360+
on_error = "ignore"
361+
else:
362+
on_error = "raise"
364363

365364
if isinstance(path1, list) and isinstance(path2, list):
366365
# No need to expand paths when both source and destination
@@ -715,7 +714,7 @@ async def _walk(self, path, maxdepth=None, on_error="omit", **kwargs):
715714
detail = kwargs.pop("detail", False)
716715
try:
717716
listing = await self._ls(path, detail=True, **kwargs)
718-
except (FileNotFoundError, OSError) as e:
717+
except OSError as e:
719718
if on_error == "raise":
720719
raise
721720
elif callable(on_error):
@@ -767,7 +766,7 @@ async def _glob(self, path, maxdepth=None, **kwargs):
767766
ends_with_sep = path.endswith(seps) # _strip_protocol strips trailing slash
768767
path = self._strip_protocol(path)
769768
append_slash_to_dirname = ends_with_sep or path.endswith(
770-
tuple(sep + "**" for sep in seps)
769+
tuple(f"{sep}**" for sep in seps)
771770
)
772771
idx_star = path.find("*") if path.find("*") >= 0 else len(path)
773772
idx_qmark = path.find("?") if path.find("?") >= 0 else len(path)
@@ -815,7 +814,7 @@ async def _glob(self, path, maxdepth=None, **kwargs):
815814
p: info
816815
for p, info in sorted(allpaths.items())
817816
if pattern.match(
818-
p + "/"
817+
f"{p}/"
819818
if append_slash_to_dirname and info["type"] == "directory"
820819
else p
821820
)

fsspec/caching.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ def _fetch_block(self, block_number: int) -> bytes:
429429
self.total_requested_bytes += end - start
430430
self.miss_count += 1
431431
logger.info("BlockCache fetching block %d", block_number)
432-
block_contents = super()._fetch(start, end)
433-
return block_contents
432+
return super()._fetch(start, end)
434433

435434
def _read_cache(
436435
self, start: int, end: int, start_block_number: int, end_block_number: int
@@ -703,7 +702,7 @@ class UpdatableLRU(Generic[P, T]):
703702
"""
704703
Custom implementation of LRU cache that allows updating keys
705704
706-
Used by BackgroudBlockCache
705+
Used by BackgroundBlockCache
707706
"""
708707

709708
class CacheInfo(NamedTuple):
@@ -856,7 +855,7 @@ def _fetch(self, start: int | None, end: int | None) -> bytes:
856855
self._fetch_future = None
857856
else:
858857
# Must join if we need the block for the current fetch
859-
must_join = bool(
858+
must_join = (
860859
start_block_number
861860
<= self._fetch_future_block_number
862861
<= end_block_number
@@ -919,8 +918,7 @@ def _fetch_block(self, block_number: int, log_info: str = "sync") -> bytes:
919918
logger.info("BlockCache fetching block (%s) %d", log_info, block_number)
920919
self.total_requested_bytes += end - start
921920
self.miss_count += 1
922-
block_contents = super()._fetch(start, end)
923-
return block_contents
921+
return super()._fetch(start, end)
924922

925923
def _read_cache(
926924
self, start: int, end: int, start_block_number: int, end_block_number: int

fsspec/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def _un_chain(path, kwargs):
339339
if "://" in p or x.match(p):
340340
bits.append(p)
341341
else:
342-
bits.append(p + "://")
342+
bits.append(f"{p}://")
343343
else:
344344
bits = [path]
345345
# [[url, protocol, kwargs], ...]

fsspec/fuse.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ def read(self, path, size, offset, fh):
7676

7777
f = self.cache[fh]
7878
f.seek(offset)
79-
out = f.read(size)
80-
return out
79+
return f.read(size)
8180

8281
def write(self, path, data, offset, fh):
8382
logger.debug("write %s", (path, offset))
@@ -119,7 +118,7 @@ def unlink(self, path):
119118
fn = "".join([self.root, path.lstrip("/")])
120119
try:
121120
self.fs.rm(fn, False)
122-
except (OSError, FileNotFoundError) as exc:
121+
except OSError as exc:
123122
raise FuseOSError(EIO) from exc
124123

125124
def release(self, path, fh):

fsspec/implementations/cache_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def on_close_cached_file(self, f: Any, path: str) -> None:
167167
168168
The actual closing of the file is the responsibility of the caller.
169169
"""
170-
# File must be writeble, so in self.cached_files[-1]
170+
# File must be writeable, so in self.cached_files[-1]
171171
c = self.cached_files[-1][path]
172172
if c["blocks"] is not True and len(c["blocks"]) * f.blocksize >= f.size:
173173
c["blocks"] = True

fsspec/implementations/cached.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ def info(self, path, **kwargs):
826826
if f:
827827
size = os.path.getsize(f[0].fn) if f[0].closed else f[0].tell()
828828
return {"name": path, "size": size, "type": "file"}
829-
f = any(_.path.startswith(path + "/") for _ in self.transaction.files)
829+
f = any(_.path.startswith(f"{path}/") for _ in self.transaction.files)
830830
if f:
831831
return {"name": path, "size": 0, "type": "directory"}
832832
return self.fs.info(path, **kwargs)

fsspec/implementations/github.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def ls(self, path, detail=False, sha=None, _sha=None, **kwargs):
153153
_sha = sha or self.root
154154
for part in parts:
155155
out = self.ls(so_far, True, sha=sha, _sha=_sha)
156-
so_far += "/" + part if so_far else part
156+
so_far += f"/{part}" if so_far else part
157157
out = [o for o in out if o["name"] == so_far]
158158
if not out:
159159
raise FileNotFoundError(path)

fsspec/implementations/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ async def _glob(self, path, maxdepth=None, **kwargs):
457457
"""
458458
Find files by glob-matching.
459459
460-
This implementation is idntical to the one in AbstractFileSystem,
460+
This implementation is identical to the one in AbstractFileSystem,
461461
but "?" is not considered as a character for globbing, because it is
462462
so common in URLs, often identifying the "query" part.
463463
"""

0 commit comments

Comments
 (0)