From f9ad19e94be09d37f1a20f67a478952297dc604d Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 26 Feb 2026 15:34:21 +0100 Subject: [PATCH] refactor: enable additional ruff rule categories Enable 11 new zero-violation guardrail rules (ASYNC, DTZ, EXE, FLY, ICN, ISC, LOG, PTH, SLF, SLOT, T10) and RSE (8 auto-fixed unnecessary parentheses on raises). Suppress ASYNC105 on the intentional unawaited trio.sleep return in _portable_async_sleep. Co-Authored-By: Claude Opus 4.6 Change-Id: I0c9ce63d66f43757ed2292d6151c031a4a21362d --- pyproject.toml | 2 +- tenacity/asyncio/__init__.py | 2 +- tests/test_asyncio.py | 10 +++++----- tests/test_tenacity.py | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 33571f7..447c639 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -103,7 +103,7 @@ target-version = "py310" exclude = ["tenacity/_version.py"] [tool.ruff.lint] -select = ["B", "C4", "E", "F", "FURB", "I", "PERF", "PGH", "PIE", "PYI", "RET", "RUF", "SIM", "TC", "UP", "W"] +select = ["ASYNC", "B", "C4", "DTZ", "E", "EXE", "F", "FLY", "FURB", "I", "ICN", "ISC", "LOG", "PERF", "PGH", "PIE", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "SLOT", "T10", "TC", "UP", "W"] ignore = [ "B008", # function calls in default arguments (intentional API design) "B905", # zip() without strict= (not needed in existing code) diff --git a/tenacity/asyncio/__init__.py b/tenacity/asyncio/__init__.py index b2b203e..214a7ae 100644 --- a/tenacity/asyncio/__init__.py +++ b/tenacity/asyncio/__init__.py @@ -63,7 +63,7 @@ def _portable_async_sleep(seconds: float) -> t.Awaitable[None]: import trio if sniffio.current_async_library() == "trio": - return trio.sleep(seconds) + return trio.sleep(seconds) # noqa: ASYNC105 # Otherwise, assume asyncio # Lazy import asyncio as it's expensive (responsible for 25-50% of total import overhead). import asyncio diff --git a/tests/test_asyncio.py b/tests/test_asyncio.py index e2e2cd4..7b5c641 100644 --- a/tests/test_asyncio.py +++ b/tests/test_asyncio.py @@ -232,7 +232,7 @@ class CustomError(Exception): stop=stop_after_attempt(1), reraise=True ): with attempt: - raise CustomError() + raise CustomError except CustomError: pass else: @@ -246,7 +246,7 @@ async def test_sleeps(self) -> None: stop=stop_after_attempt(1), wait=wait_fixed(1) ): with attempt: - raise Exception() + raise Exception except RetryError: pass t = current_time_ms() - start @@ -312,7 +312,7 @@ async def is_exc(e: BaseException) -> bool: with attempt: attempts += 1 if attempts < 3: - raise CustomException() + raise CustomException assert attempt.retry_state.outcome # help mypy if not attempt.retry_state.outcome.failed: @@ -343,7 +343,7 @@ def is_exc(e: BaseException) -> bool: with attempt: attempts += 1 if 2 < attempts < 4: - raise CustomException() + raise CustomException assert attempt.retry_state.outcome # help mypy if not attempt.retry_state.outcome.failed: @@ -374,7 +374,7 @@ async def is_exc(e: BaseException) -> bool: with attempt: attempts += 1 if 2 < attempts < 4: - raise CustomException() + raise CustomException assert attempt.retry_state.outcome # help mypy if not attempt.retry_state.outcome.failed: diff --git a/tests/test_tenacity.py b/tests/test_tenacity.py index ab78ccc..efefba8 100644 --- a/tests/test_tenacity.py +++ b/tests/test_tenacity.py @@ -911,7 +911,7 @@ def go(self) -> typing.Any: try: self.go2() except NameError as e: - raise OSError() from e + raise OSError from e return True @@ -936,7 +936,7 @@ def go(self) -> typing.Any: try: self.go2() except OSError as e: - raise NameError() from e + raise NameError from e return True @@ -1994,7 +1994,7 @@ class TestMockingSleep: } def _fail(self) -> None: - raise NotImplementedError() + raise NotImplementedError @retry(**RETRY_ARGS) # type: ignore[call-overload, untyped-decorator] def _decorated_fail(self) -> None: