Skip to content

Ruff legacy alias #1887

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ repos:
- id: check-json
- id: check-yaml
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.11.13
rev: v0.12.2
hooks:
# Run the linter.
- id: ruff
- id: ruff-check
args: [ --fix, "--show-fixes"]
- id: ruff-format
types_or: [python]
Expand Down
3 changes: 2 additions & 1 deletion fsspec/asyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import os
import re
import threading
from collections.abc import Iterable
from glob import has_magic
from typing import TYPE_CHECKING, Iterable
from typing import TYPE_CHECKING

from .callbacks import DEFAULT_CALLBACK
from .exceptions import FSTimeoutError
Expand Down
5 changes: 2 additions & 3 deletions fsspec/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import threading
import warnings
from collections import OrderedDict
from concurrent.futures import Future, ThreadPoolExecutor
from itertools import groupby
from operator import itemgetter
Expand All @@ -17,8 +18,6 @@
ClassVar,
Generic,
NamedTuple,
Optional,
OrderedDict,
TypeVar,
)

Expand Down Expand Up @@ -629,7 +628,7 @@ def __init__(
blocksize: int,
fetcher: Fetcher,
size: int,
data: Optional[dict[tuple[int, int], bytes]] = None,
data: dict[tuple[int, int], bytes] | None = None,
strict: bool = True,
**_: Any,
):
Expand Down
9 changes: 4 additions & 5 deletions fsspec/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import shutil
import uuid
from typing import Optional

from .asyn import AsyncFileSystem, _run_coros_in_chunks, sync_wrapper
from .callbacks import DEFAULT_CALLBACK
Expand Down Expand Up @@ -289,7 +288,7 @@ async def _cp_file(
url2,
blocksize=2**20,
callback=DEFAULT_CALLBACK,
tempdir: Optional[str] = None,
tempdir: str | None = None,
**kwargs,
):
fs = _resolve_fs(url, self.method)
Expand Down Expand Up @@ -319,9 +318,9 @@ async def _copy(
path2: list[str],
recursive: bool = False,
on_error: str = "ignore",
maxdepth: Optional[int] = None,
batch_size: Optional[int] = None,
tempdir: Optional[str] = None,
maxdepth: int | None = None,
batch_size: int | None = None,
tempdir: str | None = None,
**kwargs,
):
# TODO: special case for one FS being local, which can use get/put
Expand Down
3 changes: 2 additions & 1 deletion fsspec/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import logging
import os
import re
from typing import ClassVar, Sequence
from collections.abc import Sequence
from typing import ClassVar

import panel as pn

Expand Down
5 changes: 3 additions & 2 deletions fsspec/implementations/cache_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
import json

if TYPE_CHECKING:
from typing import Any, Dict, Iterator, Literal
from collections.abc import Iterator
from typing import Any, Literal

from typing_extensions import TypeAlias

from .cached import CachingFileSystem

Detail: TypeAlias = Dict[str, Any]
Detail: TypeAlias = dict[str, Any]


class CacheMetadata:
Expand Down
2 changes: 1 addition & 1 deletion fsspec/implementations/cached.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def _open(
# explicitly submitting the size to the open call will avoid extra
# operations when opening. This is particularly relevant
# for any file that is read over a network, e.g. S3.
size = detail.get("size", None)
size = detail.get("size")

# call target filesystems open
self._mkcache()
Expand Down
10 changes: 1 addition & 9 deletions fsspec/implementations/ftp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import sys
import uuid
import warnings
from ftplib import FTP, FTP_TLS, Error, error_perm
from typing import Any

Expand Down Expand Up @@ -81,13 +79,7 @@ def _connect(self):
ftp_cls = FTP_TLS
else:
ftp_cls = FTP
if sys.version_info >= (3, 9):
self.ftp = ftp_cls(timeout=self.timeout, encoding=self.encoding)
elif self.encoding:
warnings.warn("`encoding` not supported for python<3.9, ignoring")
self.ftp = ftp_cls(timeout=self.timeout)
else:
self.ftp = ftp_cls(timeout=self.timeout)
self.ftp = ftp_cls(timeout=self.timeout, encoding=self.encoding)
self.ftp.connect(self.host, self.port)
self.ftp.login(*self.cred)

Expand Down
3 changes: 1 addition & 2 deletions fsspec/implementations/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def _path_to_object(self, path, ref):

@staticmethod
def _get_kwargs_from_urls(path):
if path.startswith("git://"):
path = path[6:]
path = path.removeprefix("git://")
out = {}
if ":" in path:
out["path"], path = path.split(":", 1)
Expand Down
3 changes: 1 addition & 2 deletions fsspec/implementations/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def _strip_protocol(cls, path):
else:
path = stringify_path(path)

if path.startswith("memory://"):
path = path[len("memory://") :]
path = path.removeprefix("memory://")
if "::" in path or "://" in path:
return path.rstrip("/")
path = path.lstrip("/").rstrip("/")
Expand Down
16 changes: 6 additions & 10 deletions fsspec/json.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import json
from collections.abc import Mapping, Sequence
from contextlib import suppress
from pathlib import PurePath
from typing import (
Any,
Callable,
ClassVar,
Dict,
List,
Mapping,
Optional,
Sequence,
Tuple,
)

from .registry import _import_class, get_filesystem_class
Expand Down Expand Up @@ -49,12 +45,12 @@ class FilesystemJSONDecoder(json.JSONDecoder):
def __init__(
self,
*,
object_hook: Optional[Callable[[Dict[str, Any]], Any]] = None,
object_hook: Optional[Callable[[dict[str, Any]], Any]] = None,
parse_float: Optional[Callable[[str], Any]] = None,
parse_int: Optional[Callable[[str], Any]] = None,
parse_constant: Optional[Callable[[str], Any]] = None,
strict: bool = True,
object_pairs_hook: Optional[Callable[[List[Tuple[str, Any]]], Any]] = None,
object_pairs_hook: Optional[Callable[[list[tuple[str, Any]]], Any]] = None,
) -> None:
self.original_object_hook = object_hook

Expand All @@ -68,7 +64,7 @@ def __init__(
)

@classmethod
def try_resolve_path_cls(cls, dct: Dict[str, Any]):
def try_resolve_path_cls(cls, dct: dict[str, Any]):
with suppress(Exception):
fqp = dct["cls"]

Expand All @@ -80,7 +76,7 @@ def try_resolve_path_cls(cls, dct: Dict[str, Any]):
return None

@classmethod
def try_resolve_fs_cls(cls, dct: Dict[str, Any]):
def try_resolve_fs_cls(cls, dct: dict[str, Any]):
with suppress(Exception):
if "cls" in dct:
try:
Expand All @@ -95,7 +91,7 @@ def try_resolve_fs_cls(cls, dct: Dict[str, Any]):

return None

def custom_object_hook(self, dct: Dict[str, Any]):
def custom_object_hook(self, dct: dict[str, Any]):
if "cls" in dct:
if (obj_cls := self.try_resolve_fs_cls(dct)) is not None:
return AbstractFileSystem.from_dict(dct)
Expand Down
7 changes: 4 additions & 3 deletions fsspec/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,10 @@ def test_target_protocol_options(ftp_writable):
host, port, username, password = ftp_writable
data = {"afile": b"hello"}
options = {"host": host, "port": port, "username": username, "password": password}
with tempzip(data) as lfile, fsspec.open(
"ftp:///archive.zip", "wb", **options
) as f:
with (
tempzip(data) as lfile,
fsspec.open("ftp:///archive.zip", "wb", **options) as f,
):
f.write(open(lfile, "rb").read())
with fsspec.open(
"zip://afile",
Expand Down
4 changes: 1 addition & 3 deletions fsspec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
import sys
import tempfile
from collections.abc import Iterable, Iterator, Sequence
from functools import partial
from hashlib import md5
from importlib.metadata import version
Expand All @@ -15,9 +16,6 @@
TYPE_CHECKING,
Any,
Callable,
Iterable,
Iterator,
Sequence,
TypeVar,
)
from urllib.parse import urlsplit
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ version-file = "fsspec/_version.py"
exclude = ["**/tests/*", "!**/tests/abstract/"]

[tool.ruff]
target-version = "py38"
exclude = [".tox", "build", "docs/source/conf.py", "fsspec/_version"]
line-length = 88

Expand Down Expand Up @@ -209,6 +208,7 @@ ignore = [
# Fix these codes later
"G004",
"PERF203",
"PLC0415",
"UP007",
"UP011",
"UP015",
Expand All @@ -219,6 +219,7 @@ ignore = [
"SIM114",
"SIM115",
"SIM117",
"TC003",
# https://github.com/astral-sh/ruff/issues/7871
"UP038",
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
Expand Down
Loading