From 18f99f00dd19c7e69f894e88dd5f57fcb450c0d7 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Thu, 8 Jun 2023 23:24:47 -0400 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Martin Durant --- fsspec/caching.py | 8 ++------ fsspec/utils.py | 9 +++------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/fsspec/caching.py b/fsspec/caching.py index 8846a1d8c..97cb650bf 100644 --- a/fsspec/caching.py +++ b/fsspec/caching.py @@ -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() @@ -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 @@ -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] diff --git a/fsspec/utils.py b/fsspec/utils.py index 2126ba333..eae6159f6 100644 --- a/fsspec/utils.py +++ b/fsspec/utils.py @@ -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 @@ -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(