diff --git a/fsspec/asyn.py b/fsspec/asyn.py index a040efc4b..f203fa0a4 100644 --- a/fsspec/asyn.py +++ b/fsspec/asyn.py @@ -1072,7 +1072,7 @@ async def flush(self, force=False): self.offset = 0 try: await self._initiate_upload() - except: # noqa: E722 + except: self.closed = True raise diff --git a/fsspec/implementations/arrow.py b/fsspec/implementations/arrow.py index f9fea70d2..530df901a 100644 --- a/fsspec/implementations/arrow.py +++ b/fsspec/implementations/arrow.py @@ -128,7 +128,7 @@ def cp_file(self, path1, path2, **kwargs): with self.open(tmp_fname, "wb") as rstream: shutil.copyfileobj(lstream, rstream) self.fs.move(tmp_fname, path2) - except BaseException: # noqa + except BaseException: with suppress(FileNotFoundError): self.fs.delete_file(tmp_fname) raise diff --git a/fsspec/implementations/dbfs.py b/fsspec/implementations/dbfs.py index 19f2ffc19..30c2947b0 100644 --- a/fsspec/implementations/dbfs.py +++ b/fsspec/implementations/dbfs.py @@ -79,7 +79,7 @@ def ls(self, path, detail=True, **kwargs): if e.error_code == "RESOURCE_DOES_NOT_EXIST": raise FileNotFoundError(e.message) from e - raise e + raise files = r["files"] out = [ { @@ -125,7 +125,7 @@ def makedirs(self, path, exist_ok=True): if e.error_code == "RESOURCE_ALREADY_EXISTS": raise FileExistsError(e.message) from e - raise e + raise self.invalidate_cache(self._parent(path)) def mkdir(self, path, create_parents=True, **kwargs): @@ -171,7 +171,7 @@ def rm(self, path, recursive=False, **kwargs): # Using the same exception as the os module would use here raise OSError(e.message) from e - raise e + raise self.invalidate_cache(self._parent(path)) def mv( @@ -216,7 +216,7 @@ def mv( elif e.error_code == "RESOURCE_ALREADY_EXISTS": raise FileExistsError(e.message) from e - raise e + raise self.invalidate_cache(self._parent(source_path)) self.invalidate_cache(self._parent(destination_path)) @@ -299,7 +299,7 @@ def _create_handle(self, path, overwrite=True): if e.error_code == "RESOURCE_ALREADY_EXISTS": raise FileExistsError(e.message) from e - raise e + raise def _close_handle(self, handle): """ @@ -316,7 +316,7 @@ def _close_handle(self, handle): if e.error_code == "RESOURCE_DOES_NOT_EXIST": raise FileNotFoundError(e.message) from e - raise e + raise def _add_data(self, handle, data): """ @@ -346,7 +346,7 @@ def _add_data(self, handle, data): elif e.error_code == "MAX_BLOCK_SIZE_EXCEEDED": raise ValueError(e.message) from e - raise e + raise def _get_data(self, path, start, end): """ @@ -376,7 +376,7 @@ def _get_data(self, path, start, end): elif e.error_code in ["INVALID_PARAMETER_VALUE", "MAX_READ_SIZE_EXCEEDED"]: raise ValueError(e.message) from e - raise e + raise def invalidate_cache(self, path=None): if path is None: diff --git a/fsspec/implementations/reference.py b/fsspec/implementations/reference.py index 5340aaf1c..6904d7b60 100644 --- a/fsspec/implementations/reference.py +++ b/fsspec/implementations/reference.py @@ -159,7 +159,7 @@ def open_refs(field, record): path = self.url.format(field=field, record=record) data = io.BytesIO(self.fs.cat_file(path)) df = self.pd.read_parquet(data, engine="fastparquet") - refs = {c: df[c].values for c in df.columns} + refs = {c: df[c].to_numpy() for c in df.columns} return refs self.open_refs = open_refs diff --git a/fsspec/implementations/smb.py b/fsspec/implementations/smb.py index a3c2d1b2d..db6b3f5c3 100644 --- a/fsspec/implementations/smb.py +++ b/fsspec/implementations/smb.py @@ -202,7 +202,7 @@ def _connect(self): else: # All another ValueError exceptions should be raised, as they are not # related to network issues. - raise exc + raise except Exception as exc: # Save the exception and retry to connect. This except might be dropped # in the future, once all exceptions suited for retry are identified. diff --git a/fsspec/implementations/tests/test_arrow.py b/fsspec/implementations/tests/test_arrow.py index af706c530..b9cbb2137 100644 --- a/fsspec/implementations/tests/test_arrow.py +++ b/fsspec/implementations/tests/test_arrow.py @@ -5,7 +5,7 @@ pyarrow_fs = pytest.importorskip("pyarrow.fs") FileSystem = pyarrow_fs.FileSystem -from fsspec.implementations.arrow import ArrowFSWrapper, HadoopFileSystem # noqa +from fsspec.implementations.arrow import ArrowFSWrapper, HadoopFileSystem # noqa: E402 @pytest.fixture(scope="function") diff --git a/fsspec/implementations/tests/test_reference.py b/fsspec/implementations/tests/test_reference.py index d980cd139..09ea3eb33 100644 --- a/fsspec/implementations/tests/test_reference.py +++ b/fsspec/implementations/tests/test_reference.py @@ -13,7 +13,7 @@ from fsspec.tests.conftest import data, realfile, reset_files, server, win # noqa: F401 -def test_simple(server): # noqa: F811 +def test_simple(server): # The dictionary in refs may be dumped with a different separator # depending on whether json or ujson is imported from fsspec.implementations.reference import json as json_impl @@ -37,7 +37,7 @@ def test_simple(server): # noqa: F811 assert f.read(2) == "he" -def test_simple_ver1(server): # noqa: F811 +def test_simple_ver1(server): # The dictionary in refs may be dumped with a different separator # depending on whether json or ujson is imported from fsspec.implementations.reference import json as json_impl @@ -75,7 +75,7 @@ def test_target_options(m): assert fs.cat("a") == b"hello" -def test_ls(server): # noqa: F811 +def test_ls(server): refs = {"a": b"data", "b": (realfile, 0, 5), "c/d": (realfile, 1, 6)} h = fsspec.filesystem("http") fs = fsspec.filesystem("reference", fo=refs, fs=h) @@ -99,7 +99,7 @@ def test_nested_dirs_ls(): assert {e["name"] for e in fs.ls("B")} == {"B/C", "B/_"} -def test_info(server): # noqa: F811 +def test_info(server): refs = { "a": b"data", "b": (realfile, 0, 5), @@ -173,7 +173,7 @@ def test_put_get_single(tmpdir): assert fs.cat("hi") == b"data" -def test_defaults(server): # noqa: F811 +def test_defaults(server): refs = {"a": b"data", "b": (None, 0, 5)} fs = fsspec.filesystem( "reference", diff --git a/fsspec/implementations/tests/test_smb.py b/fsspec/implementations/tests/test_smb.py index 68b595725..a83e3cc91 100644 --- a/fsspec/implementations/tests/test_smb.py +++ b/fsspec/implementations/tests/test_smb.py @@ -50,7 +50,7 @@ def smb_params(request): cfg = "-p -u 'testuser;testpass' -s 'home;/share;no;no;no;testuser'" port = request.param if request.param is not None else default_port img = ( - f"docker run --name {container} --detach -p 139:139 -p {port}:445 dperson/samba" # noqa: E231 E501 + f"docker run --name {container} --detach -p 139:139 -p {port}:445 dperson/samba" ) cmd = f"{img} {cfg}" try: diff --git a/fsspec/implementations/webhdfs.py b/fsspec/implementations/webhdfs.py index 4bac5d51a..300bb9cdf 100644 --- a/fsspec/implementations/webhdfs.py +++ b/fsspec/implementations/webhdfs.py @@ -102,7 +102,7 @@ def __init__( if self._cached: return super().__init__(**kwargs) - self.url = f"{'https' if use_https else 'http'}://{host}:{port}/webhdfs/v1" # noqa + self.url = f"{'https' if use_https else 'http'}://{host}:{port}/webhdfs/v1" self.kerb = kerberos self.kerb_kwargs = kerb_kwargs or {} self.pars = {} @@ -393,7 +393,7 @@ def cp_file(self, lpath, rpath, **kwargs): with self.open(tmp_fname, "wb") as rstream: shutil.copyfileobj(lstream, rstream) self.mv(tmp_fname, rpath) - except BaseException: # noqa + except BaseException: with suppress(FileNotFoundError): self.rm(tmp_fname) raise diff --git a/fsspec/spec.py b/fsspec/spec.py index 1463a4499..8229170e2 100644 --- a/fsspec/spec.py +++ b/fsspec/spec.py @@ -1892,7 +1892,7 @@ def flush(self, force=False): self.offset = 0 try: self._initiate_upload() - except: # noqa: E722 + except: self.closed = True raise diff --git a/fsspec/tests/abstract/__init__.py b/fsspec/tests/abstract/__init__.py index 45d081921..44181420f 100644 --- a/fsspec/tests/abstract/__init__.py +++ b/fsspec/tests/abstract/__init__.py @@ -4,9 +4,9 @@ import pytest from fsspec.implementations.local import LocalFileSystem -from fsspec.tests.abstract.copy import AbstractCopyTests # noqa -from fsspec.tests.abstract.get import AbstractGetTests # noqa -from fsspec.tests.abstract.put import AbstractPutTests # noqa +from fsspec.tests.abstract.copy import AbstractCopyTests # noqa: F401 +from fsspec.tests.abstract.get import AbstractGetTests # noqa: F401 +from fsspec.tests.abstract.put import AbstractPutTests # noqa: F401 class BaseAbstractFixtures: diff --git a/fsspec/tests/test_async.py b/fsspec/tests/test_async.py index e1a29420f..aa3c9bd4f 100644 --- a/fsspec/tests/test_async.py +++ b/fsspec/tests/test_async.py @@ -203,9 +203,6 @@ async def _upload_chunk(self, final=False): async def get_data(self): return self.temp_buffer.getbuffer().tobytes() - async def get_data(self): - return self.temp_buffer.getbuffer().tobytes() - @pytest.mark.asyncio async def test_async_streamed_file_write(): diff --git a/fsspec/tests/test_downstream.py b/fsspec/tests/test_downstream.py index 172b2a7a7..1f0a0bc0e 100644 --- a/fsspec/tests/test_downstream.py +++ b/fsspec/tests/test_downstream.py @@ -4,7 +4,7 @@ pytest.importorskip("moto") try: - from s3fs.tests.test_s3fs import ( # noqa: E402,F401 + from s3fs.tests.test_s3fs import ( # noqa: F401 endpoint_uri, s3, s3_base, diff --git a/fsspec/tests/test_fuse.py b/fsspec/tests/test_fuse.py index db627ffc9..5222d2fd9 100644 --- a/fsspec/tests/test_fuse.py +++ b/fsspec/tests/test_fuse.py @@ -6,10 +6,10 @@ import pytest try: - pytest.importorskip("fuse") # noqa: E402 + pytest.importorskip("fuse") except OSError: # can succeed in importing fuse, but fail to load so - pytest.importorskip("nonexistent") # noqa: E402 + pytest.importorskip("nonexistent") from fsspec.fuse import main, run from fsspec.implementations.memory import MemoryFileSystem diff --git a/fsspec/tests/test_registry.py b/fsspec/tests/test_registry.py index 0664912a1..fae72368f 100644 --- a/fsspec/tests/test_registry.py +++ b/fsspec/tests/test_registry.py @@ -105,7 +105,7 @@ def test_entry_points_registered_on_import(clear_registry, clean_imports): import_location = "importlib.metadata.entry_points" with patch(import_location, return_value={"fsspec.specs": [mock_ep]}): assert "test" not in registry - import fsspec # noqa + import fsspec # noqa: F401 get_filesystem_class("test") assert "test" in registry @@ -117,7 +117,7 @@ def test_filesystem_warning_arrow_hdfs_deprecated(clear_registry, clean_imports) mock_ep.value = "fsspec.spec.AbstractFileSystem" import_location = "importlib.metadata.entry_points" with patch(import_location, return_value={"fsspec.specs": [mock_ep]}): - import fsspec # noqa + import fsspec # noqa: F401 with pytest.warns(DeprecationWarning): filesystem("arrow_hdfs") diff --git a/fsspec/tests/test_spec.py b/fsspec/tests/test_spec.py index e11b7abdd..3927c6550 100644 --- a/fsspec/tests/test_spec.py +++ b/fsspec/tests/test_spec.py @@ -1276,7 +1276,7 @@ def glob_files_folder(tmp_path): local_fake_dir = str(tmp_path) for path_info in PATHS_FOR_GLOB_TESTS: if path_info["type"] == "file": - local_fs.touch(path=f"{str(tmp_path)}/{path_info['name']}") + local_fs.touch(path=f"{tmp_path}/{path_info['name']}") return local_fake_dir diff --git a/fsspec/tests/test_utils.py b/fsspec/tests/test_utils.py index b9167b5d2..1eeee912b 100644 --- a/fsspec/tests/test_utils.py +++ b/fsspec/tests/test_utils.py @@ -261,7 +261,6 @@ def test_common_prefix(paths, out): ( (["/path1"], "/path2", False, ["/path2"]), (["/path1"], "/path2", True, ["/path2/path1"]), - (["/path1"], "/path2", False, ["/path2"]), (["/path1"], "/path2/", True, ["/path2/path1"]), (["/path1"], ["/path2"], False, ["/path2"]), (["/path1"], ["/path2"], True, ["/path2"]), @@ -279,18 +278,6 @@ def test_common_prefix(paths, out): True, ["/path2/more/path1", "/path2/more/path2"], ), - ( - ["/more/path1", "/more/path2"], - "/path2", - False, - ["/path2/path1", "/path2/path2"], - ), - ( - ["/more/path1", "/more/path2"], - "/path2", - True, - ["/path2/more/path1", "/path2/more/path2"], - ), ( ["/more/path1", "/more/path2"], "/path2/", diff --git a/fsspec/utils.py b/fsspec/utils.py index 703d55f4e..faa63937f 100644 --- a/fsspec/utils.py +++ b/fsspec/utils.py @@ -427,10 +427,7 @@ def is_exception(obj: Any) -> bool: def isfilelike(f: Any) -> TypeGuard[IO[bytes]]: - for attr in ["read", "close", "tell"]: - if not hasattr(f, attr): - return False - return True + return all(hasattr(f, attr) for attr in ["read", "close", "tell"]) def get_protocol(url: str) -> str: diff --git a/pyproject.toml b/pyproject.toml index 945ecdabd..48368711f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -192,9 +192,6 @@ ignore = [ "B026", # No explicit `stacklevel` keyword argument found "B028", - # Within an `except` clause, raise exceptions with `raise ... from err` or - # `raise ... from None` to distinguish them from errors in exception handling - "B904", # Assigning lambda expression "E731", # Ambiguous variable names