From 0b27edac2c88f287e06048416cfd31df256be358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Tue, 21 Jul 2026 08:42:32 -0600 Subject: [PATCH] chore: Prepare for Ruff v0.16 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Edgar Ramírez Mondragón style: pre-commit fixes Signed-off-by: Edgar Ramírez Mondragón --- .pre-commit-config.yaml | 6 +++--- README.rst | 2 +- backoff/_async.py | 2 +- backoff/_typing.py | 2 +- docs/user-guide/async.md | 26 ++++++++++++++++---------- docs/user-guide/configuration.md | 4 +--- pyproject.toml | 17 ++++++++++------- tests/test_backoff.py | 12 +++++++----- tests/test_backoff_async.py | 4 ++-- tests/test_wait_gen.py | 2 ++ 10 files changed, 44 insertions(+), 33 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ed462f0..56dc5c5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: - id: check-yaml - id: check-added-large-files - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.18 + rev: v0.16.0 hooks: - id: ruff-check - id: ruff-format @@ -53,11 +53,11 @@ repos: alias: ruff-format-docs args: ["--language", "python", "--no-pad-file", "--no-pad-groups", "--command", "ruff format", "docs/"] additional_dependencies: - - ruff==0.15.18 + - ruff==0.16.0 - id: doccmd name: Ruff check fix docs language: python alias: ruff-check-fix-docs args: ["--language", "python", "--no-pad-file", "--no-pad-groups", "--command", "ruff check --fix", "docs/"] additional_dependencies: - - ruff==0.15.18 + - ruff==0.16.0 diff --git a/README.rst b/README.rst index 3cc54cf..851c623 100644 --- a/README.rst +++ b/README.rst @@ -374,7 +374,7 @@ asynchronous HTTP client/server library. max_time=60, ) async def get_url(url): - async with aiohttp.ClientSession(raise_for_status=True) as session: # noqa: SIM117 + async with aiohttp.ClientSession(raise_for_status=True) as session: # ruff:ignore[multiple-with-statements] async with session.get(url) as response: return await response.text() diff --git a/backoff/_async.py b/backoff/_async.py index 93a049c..e8ce49c 100644 --- a/backoff/_async.py +++ b/backoff/_async.py @@ -11,7 +11,7 @@ def _ensure_coroutine(coro_or_func): return coro_or_func @functools.wraps(coro_or_func) - async def f(*args, **kwargs): + async def f(*args, **kwargs): # ruff:ignore[unused-async] return coro_or_func(*args, **kwargs) return f diff --git a/backoff/_typing.py b/backoff/_typing.py index a975e65..621352c 100644 --- a/backoff/_typing.py +++ b/backoff/_typing.py @@ -31,7 +31,7 @@ class Details(_Details, total=False): T = TypeVar("T") -_CallableT = TypeVar("_CallableT", bound=Callable[..., Any]) # noqa: PYI018 +_CallableT = TypeVar("_CallableT", bound=Callable[..., Any]) # ruff:ignore[unused-private-type-var] _Handler = Union[ Callable[[Details], None], Callable[[Details], Coroutine[Any, Any, None]], diff --git a/docs/user-guide/async.md b/docs/user-guide/async.md index 4cb1c31..f13e4e4 100644 --- a/docs/user-guide/async.md +++ b/docs/user-guide/async.md @@ -47,9 +47,11 @@ async def async_operation(): max_time=60, ) async def get_url(url): - async with aiohttp.ClientSession(raise_for_status=True) as session: # noqa: SIM117 - async with session.get(url) as response: - return await response.text() + async with ( + aiohttp.ClientSession(raise_for_status=True) as session, + session.get(url) as response, + ): + return await response.text() ``` ### Database Operations @@ -100,9 +102,11 @@ async def fetch_all(urls): max_time=300, ) async def poll_job_status(job_id): - async with aiohttp.ClientSession() as session: # noqa: SIM117 - async with session.get(f"/api/jobs/{job_id}") as response: - return await response.json() + async with ( + aiohttp.ClientSession() as session, + session.get(f"/api/jobs/{job_id}") as response, + ): + return await response.json() ``` ## Mixing Sync and Async @@ -172,10 +176,12 @@ async def log_async_retry(details): on_backoff=log_async_retry, ) async def robust_fetch(url, timeout=10): - async with aiohttp.ClientSession() as session: # noqa: SIM117 - async with session.get(url, timeout=timeout) as response: - response.raise_for_status() - return await response.json() + async with ( + aiohttp.ClientSession() as session, + session.get(url, timeout=timeout) as response, + ): + response.raise_for_status() + return await response.json() # Usage diff --git a/docs/user-guide/configuration.md b/docs/user-guide/configuration.md index 234bd1a..508c5cf 100644 --- a/docs/user-guide/configuration.md +++ b/docs/user-guide/configuration.md @@ -323,9 +323,7 @@ def should_retry(result): return True if not result.get("ready"): return True - if result.get("status") == "processing": # noqa: SIM103 - return True - return False + return result.get("status") == "processing" @backoff.on_predicate( diff --git a/pyproject.toml b/pyproject.toml index 9ae5014..fcc77c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,7 +47,7 @@ docs = [ "zensical==0.0.47", ] lint = [ - "ruff>=0.15.0", + "ruff>=0.16.0", ] test = [ "coverage>=7.2.7", @@ -166,7 +166,7 @@ package = [ [tool.ruff] line-length = 88 preview = true -required-version = ">=0.15.5" +required-version = ">=0.16.0" [tool.ruff.format] docstring-code-format = true @@ -194,11 +194,12 @@ extend-select = [ "PERF", # Perflint "UP", # pyupgrade "FURB", # refurb + "RUF", # Ruff-specific rules ] ignore = [ # converting to a `yield from` expression is not safe because this library sends values via `send` # https://docs.astral.sh/ruff/rules/yield-in-for-loop/#fix-safety - "UP028", + "yield-in-for-loop", ] [tool.mypy] @@ -209,12 +210,14 @@ warn_unused_ignores = true [tool.ruff.lint.per-file-ignores] "**/doccmd_*.py" = [ - "F811", # redefinition of unused - "F821", # undefined name - "T201", # print + "redefined-while-unused", + "undefined-name", + "print", + "unused-async", ] "tests/**.py" = [ - "S101", # assert + "assert", + "unused-async", ] [tool.coverage.report] diff --git a/tests/test_backoff.py b/tests/test_backoff.py index ff2c35d..4e61151 100644 --- a/tests/test_backoff.py +++ b/tests/test_backoff.py @@ -1,3 +1,5 @@ +# ruff: file-ignore[float-equality-comparison] + import logging import re import sys @@ -395,7 +397,7 @@ def on_baz(e): def foo_bar_baz(): raise ValueError(vals.pop()) - with pytest.raises(ValueError, match="(baz|bar|foo)"): + with pytest.raises(ValueError, match=r"(baz|bar|foo)"): foo_bar_baz() assert not vals @@ -714,7 +716,7 @@ def return_true(log, n): assert ret is True assert len(log) == 3 - except Exception as ex: # noqa: BLE001 + except Exception as ex: # ruff:ignore[blind-except] result.append(ex) else: result.append("success") @@ -776,7 +778,7 @@ def keyerror_then_true(log, n): assert keyerror_then_true(log, 3) is True assert len(log) == 3 - except Exception as ex: # noqa: BLE001 + except Exception as ex: # ruff:ignore[blind-except] result.append(ex) else: result.append("success") @@ -941,8 +943,8 @@ def test_event_log_levels( ): func() - backoff_re = re.compile("backing off", re.IGNORECASE) - giveup_re = re.compile("giving up", re.IGNORECASE) + backoff_re = re.compile(r"backing off", re.IGNORECASE) + giveup_re = re.compile(r"giving up", re.IGNORECASE) backoff_log_count = 0 giveup_log_count = 0 diff --git a/tests/test_backoff_async.py b/tests/test_backoff_async.py index fa56734..1bb6d57 100644 --- a/tests/test_backoff_async.py +++ b/tests/test_backoff_async.py @@ -336,7 +336,7 @@ def on_baz(e): async def foo_bar_baz(): raise ValueError(vals.pop()) - with pytest.raises(ValueError, match="(baz|bar|foo)"): + with pytest.raises(ValueError, match=r"(baz|bar|foo)"): await foo_bar_baz() assert not vals @@ -355,7 +355,7 @@ async def on_baz(e: Exception) -> bool: async def foo_bar_baz(): raise ValueError(vals.pop()) - with pytest.raises(ValueError, match="(baz|bar|foo)"): + with pytest.raises(ValueError, match=r"(baz|bar|foo)"): await foo_bar_baz() assert not vals diff --git a/tests/test_wait_gen.py b/tests/test_wait_gen.py index 5a30fff..95e64ad 100644 --- a/tests/test_wait_gen.py +++ b/tests/test_wait_gen.py @@ -1,3 +1,5 @@ +# ruff: file-ignore[float-equality-comparison] + import math import backoff