Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply more ruff rules #1660

Merged
merged 8 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fsspec/asyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion fsspec/implementations/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions fsspec/implementations/dbfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion fsspec/implementations/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
martindurant marked this conversation as resolved.
Show resolved Hide resolved
return refs

self.open_refs = open_refs
Expand Down
2 changes: 1 addition & 1 deletion fsspec/implementations/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion fsspec/implementations/tests/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions fsspec/implementations/tests/test_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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),
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion fsspec/implementations/tests/test_smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions fsspec/implementations/webhdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fsspec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,7 @@ def flush(self, force=False):
self.offset = 0
try:
self._initiate_upload()
except: # noqa: E722
except:
self.closed = True
raise

Expand Down
6 changes: 3 additions & 3 deletions fsspec/tests/abstract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions fsspec/tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion fsspec/tests/test_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions fsspec/tests/test_fuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions fsspec/tests/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion fsspec/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
13 changes: 0 additions & 13 deletions fsspec/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ def test_common_prefix(paths, out):
(
(["/path1"], "/path2", False, ["/path2"]),
(["/path1"], "/path2", True, ["/path2/path1"]),
(["/path1"], "/path2", False, ["/path2"]),
martindurant marked this conversation as resolved.
Show resolved Hide resolved
(["/path1"], "/path2/", True, ["/path2/path1"]),
(["/path1"], ["/path2"], False, ["/path2"]),
(["/path1"], ["/path2"], True, ["/path2"]),
Expand All @@ -279,18 +278,6 @@ def test_common_prefix(paths, out):
True,
["/path2/more/path1", "/path2/more/path2"],
),
(
DimitriPapadopoulos marked this conversation as resolved.
Show resolved Hide resolved
["/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/",
Expand Down
5 changes: 1 addition & 4 deletions fsspec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading