Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Durant <[email protected]>
  • Loading branch information
alanhdu and martindurant committed Oct 18, 2023
1 parent 322bf74 commit 18f99f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
8 changes: 2 additions & 6 deletions fsspec/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __getstate__(self) -> dict[str, Any]:
del state["cache"]
return state

def __setstate__(self, state) -> None:
def __setstate__(self, state: dict[str, Any]) -> None:
# Restore instance attributes
self.__dict__.update(state)
self.cache = self._makefile()
Expand Down Expand Up @@ -278,7 +278,7 @@ def __getstate__(self) -> dict[str, Any]:
del state["_fetch_block_cached"]
return state

def __setstate__(self, state) -> None:
def __setstate__(self, state: dict[str, Any]) -> None:
self.__dict__.update(state)
self._fetch_block_cached = functools.lru_cache(state["maxblocks"])(
self._fetch_block
Expand Down Expand Up @@ -471,10 +471,6 @@ def __init__(
self.data = data

def _fetch(self, start: int | None, stop: int | None) -> bytes:
if start is None:
start = 0
if stop is None:
stop = len(self.data)
return self.data[start:stop]


Expand Down
9 changes: 3 additions & 6 deletions fsspec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,7 @@ def read_block(
length = end - start

f.seek(offset)
if length is not None:
b = f.read(length)
else:
b = f.read()
b = f.read(length) # type: ignore[arg-type]
return b


Expand Down Expand Up @@ -348,14 +345,14 @@ def stringify_path(filepath: str | os.PathLike[str] | pathlib.Path) -> str:
"""
if isinstance(filepath, str):
return filepath
elif hasattr(filepath, "__fspath__") or isinstance(filepath, os.PathLike):
elif hasattr(filepath, "__fspath__"):
return filepath.__fspath__()
elif isinstance(filepath, pathlib.Path):
return str(filepath)
elif hasattr(filepath, "path"):
return filepath.path
else:
return filepath
return filepath # type: ignore[return-value]


def make_instance(
Expand Down

0 comments on commit 18f99f0

Please sign in to comment.