diff --git a/fsspec/__init__.py b/fsspec/__init__.py index 452c78a05..183564af0 100644 --- a/fsspec/__init__.py +++ b/fsspec/__init__.py @@ -16,21 +16,21 @@ __all__ = [ "AbstractFileSystem", - "FSTimeoutError", + "Callback", "FSMap", + "FSTimeoutError", + "available_compressions", + "available_protocols", + "caching", "filesystem", - "register_implementation", "get_filesystem_class", "get_fs_token_paths", "get_mapper", "open", "open_files", "open_local", + "register_implementation", "registry", - "caching", - "Callback", - "available_protocols", - "available_compressions", "url_to_fs", ] diff --git a/fsspec/gui.py b/fsspec/gui.py index 9d914c8be..da658e884 100644 --- a/fsspec/gui.py +++ b/fsspec/gui.py @@ -170,8 +170,17 @@ def show(self, threads=False): class SingleSelect(SigSlot): """A multiselect which only allows you to select one item for an event""" - signals = ["_selected", "selected"] # the first is internal - slots = ["set_options", "set_selection", "add", "clear", "select"] + signals: ClassVar[Sequence[str]] = [ + "_selected", + "selected", + ] # the first is internal + slots: ClassVar[Sequence[str]] = [ + "set_options", + "set_selection", + "add", + "clear", + "select", + ] def __init__(self, **kwargs): self.kwargs = kwargs @@ -213,7 +222,7 @@ class FileSelector(SigSlot): them as the output of a cell, or in a separate browser tab using ``.show()``. """ - signals = [ + signals: ClassVar[Sequence[str]] = [ "protocol_changed", "selection_changed", "directory_entered", @@ -222,7 +231,7 @@ class FileSelector(SigSlot): "go_clicked", "filters_changed", ] - slots = ["set_filters", "go_home"] + slots: ClassVar[Sequence[str]] = ["set_filters", "go_home"] def __init__(self, url=None, filters=None, ignore=None, kwargs=None): """ diff --git a/fsspec/implementations/gist.py b/fsspec/implementations/gist.py index 74117b544..8f302768f 100644 --- a/fsspec/implementations/gist.py +++ b/fsspec/implementations/gist.py @@ -141,16 +141,16 @@ def _get_kwargs_from_urls(path): """ so = infer_storage_options(path) out = {} - if "username" in so and so["username"]: + if so.get("username"): out["username"] = so["username"] - if "password" in so and so["password"]: + if so.get("password"): out["token"] = so["password"] - if "host" in so and so["host"]: + if so.get("host"): # We interpret 'host' as the gist ID out["gist_id"] = so["host"] # Extract SHA and filename from path - if "path" in so and so["path"]: + if so.get("path"): path_parts = so["path"].rsplit("/", 2)[-2:] if len(path_parts) == 2: if path_parts[0]: # SHA present diff --git a/fsspec/implementations/memory.py b/fsspec/implementations/memory.py index 838876d1f..4f3caf216 100644 --- a/fsspec/implementations/memory.py +++ b/fsspec/implementations/memory.py @@ -1,6 +1,7 @@ from __future__ import annotations import logging +from collections.abc import Sequence from datetime import datetime, timezone from errno import ENOTEMPTY from io import BytesIO @@ -22,7 +23,7 @@ class MemoryFileSystem(AbstractFileSystem): """ store: ClassVar[dict[str, Any]] = {} # global, do not overwrite! - pseudo_dirs = [""] # global, do not overwrite! + pseudo_dirs: ClassVar[Sequence[str]] = [""] # global, do not overwrite! protocol = "memory" root_marker = "/" diff --git a/fsspec/implementations/tests/conftest.py b/fsspec/implementations/tests/conftest.py index 7dce3ee4e..d71c31032 100644 --- a/fsspec/implementations/tests/conftest.py +++ b/fsspec/implementations/tests/conftest.py @@ -10,7 +10,7 @@ class MultiProtocolFileSystem(LocalFileSystem): - protocol = ["file", "other"] + protocol = ("file", "other") FILESYSTEMS = { diff --git a/fsspec/implementations/tests/test_archive.py b/fsspec/implementations/tests/test_archive.py index 457714b39..dce41a4f2 100644 --- a/fsspec/implementations/tests/test_archive.py +++ b/fsspec/implementations/tests/test_archive.py @@ -214,14 +214,14 @@ class TestAnyArchive: will adhere to the same specification. """ - scenarios = [ + scenarios = ( scenario_zip, scenario_tar, scenario_targz, scenario_tarbz2, scenario_tarxz, scenario_libarchive, - ] + ) def test_repr(self, scenario: ArchiveTestScenario): with scenario.provider() as archive: diff --git a/fsspec/implementations/tests/test_smb.py b/fsspec/implementations/tests/test_smb.py index a4b443528..24b31489d 100644 --- a/fsspec/implementations/tests/test_smb.py +++ b/fsspec/implementations/tests/test_smb.py @@ -20,8 +20,6 @@ def delay_rerun(*args): return True -# ruff: noqa: F821 - if os.environ.get("WSL_INTEROP"): # Running on WSL (Windows) port_test = [9999] diff --git a/fsspec/registry.py b/fsspec/registry.py index 96ffad7f4..d535d1ce3 100644 --- a/fsspec/registry.py +++ b/fsspec/registry.py @@ -4,7 +4,7 @@ import types import warnings -__all__ = ["registry", "get_filesystem_class", "default"] +__all__ = ["default", "get_filesystem_class", "registry"] # internal, mutable _registry: dict[str, type] = {} diff --git a/fsspec/tests/conftest.py b/fsspec/tests/conftest.py index ccf7bdccf..7daaed062 100644 --- a/fsspec/tests/conftest.py +++ b/fsspec/tests/conftest.py @@ -6,6 +6,7 @@ from collections import ChainMap from http.server import BaseHTTPRequestHandler, HTTPServer from types import SimpleNamespace +from typing import ClassVar import pytest @@ -45,7 +46,7 @@ def reset_files(): class HTTPTestHandler(BaseHTTPRequestHandler): - static_files = { + static_files: ClassVar[dict[str, bytes]] = { "/index/realfile": data, "/index/otherfile": data, "/index": _make_index_listing, @@ -55,7 +56,7 @@ class HTTPTestHandler(BaseHTTPRequestHandler): "/simple/dir/": _make_listing("/simple/dir/file"), "/simple/dir/file": data, } - dynamic_files = {} + dynamic_files: ClassVar[dict[str, bytes]] = {} files = ChainMap(dynamic_files, static_files) diff --git a/fsspec/utils.py b/fsspec/utils.py index 6441c5b1d..f473f79c8 100644 --- a/fsspec/utils.py +++ b/fsspec/utils.py @@ -172,7 +172,7 @@ def build_name_function(max_int: float) -> Callable[[int], str]: # handle corner cases max_int is 0 or exact power of 10 max_int += 1e-8 - pad_length = int(math.ceil(math.log10(max_int))) + pad_length = math.ceil(math.log10(max_int)) def name_function(i: int) -> str: return str(i).zfill(pad_length) diff --git a/pyproject.toml b/pyproject.toml index 80f76a0db..d8d3f7787 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -176,9 +176,7 @@ select = [ "PIE810", # "PT", enable in later PR "PYI", - "RUF006", - "RUF015", - "RUF024", + "RUF", "SIM", "SLOT", "SIM101", @@ -213,6 +211,8 @@ ignore = [ "UP011", "UP015", "UP018", + "RUF001", + "RUF005", "SIM102", "SIM105", "SIM108",