From cefca200c8657ebd2de981aa03c6591aed7fb5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= Date: Thu, 5 Feb 2026 00:09:44 -0600 Subject: [PATCH] Apply the Ruff `I` rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Edgar Ramírez Mondragón --- CHANGELOG.md | 2 ++ backoff/__init__.py | 2 +- backoff/_common.py | 1 - backoff/_decorator.py | 4 ++-- docs/examples.md | 4 +++- docs/getting-started.md | 3 ++- docs/index.md | 3 ++- docs/user-guide/async.md | 7 +++++-- docs/user-guide/decorators.md | 3 ++- docs/user-guide/event-handlers.md | 2 +- docs/user-guide/logging.md | 2 +- pyproject.toml | 1 + tests/test_integration.py | 7 +++---- tests/test_package.py | 5 +++-- tests/test_types.py | 1 - tests/test_typing.py | 1 - tests/test_wait_gen.py | 3 ++- 17 files changed, 30 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05b26db..99a41c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - Apply the Ruff `RET` rules [#92](https://github.com/python-backoff/backoff/pull/92) (from [@edgarrmondragon](https://github.com/edgarrmondragon)) +- Apply the Ruff `I` rules [#99](https://github.com/python-backoff/backoff/pull/99) (from [@edgarrmondragon](https://github.com/edgarrmondragon)) + ## [v2.3.1] - 2025-12-18 ### Fixed diff --git a/backoff/__init__.py b/backoff/__init__.py index 831d1f7..23682df 100644 --- a/backoff/__init__.py +++ b/backoff/__init__.py @@ -14,7 +14,7 @@ from backoff._decorator import on_exception, on_predicate from backoff._jitter import full_jitter, random_jitter -from backoff._wait_gen import constant, expo, fibo, runtime, decay +from backoff._wait_gen import constant, decay, expo, fibo, runtime __all__ = [ "on_predicate", diff --git a/backoff/_common.py b/backoff/_common.py index 30476e4..fd6316b 100644 --- a/backoff/_common.py +++ b/backoff/_common.py @@ -4,7 +4,6 @@ import traceback import warnings - # Use module-specific logger with a default null handler. _logger = logging.getLogger("backoff") _logger.addHandler(logging.NullHandler()) # pragma: no cover diff --git a/backoff/_decorator.py b/backoff/_decorator.py index 5c3d69a..708152e 100644 --- a/backoff/_decorator.py +++ b/backoff/_decorator.py @@ -3,14 +3,14 @@ import operator from typing import Any, Callable, Iterable, Optional, Type, Union +from backoff import _async, _sync from backoff._common import ( - _prepare_logger, _config_handlers, _log_backoff, _log_giveup, + _prepare_logger, ) from backoff._jitter import full_jitter -from backoff import _async, _sync from backoff._typing import ( _CallableT, _Handler, diff --git a/docs/examples.md b/docs/examples.md index 5b3c6e0..a7f31a7 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -7,9 +7,10 @@ Real-world examples of using backoff in production. ### Basic API Retry ```python -import backoff import requests +import backoff + @backoff.on_exception( backoff.expo, @@ -111,6 +112,7 @@ def execute_transaction(session, operation): ```python import aiohttp + import backoff diff --git a/docs/getting-started.md b/docs/getting-started.md index 62a5722..2c2488a 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -22,9 +22,10 @@ Backoff provides two main decorators: Let's start with a simple example - retrying a network request: ```python -import backoff import requests +import backoff + @backoff.on_exception( backoff.expo, diff --git a/docs/index.md b/docs/index.md index ed64404..33a41dc 100644 --- a/docs/index.md +++ b/docs/index.md @@ -29,9 +29,10 @@ pip install python-backoff Basic retry on exception: ```python -import backoff import requests +import backoff + @backoff.on_exception( backoff.expo, diff --git a/docs/user-guide/async.md b/docs/user-guide/async.md index db1f564..b3e62a7 100644 --- a/docs/user-guide/async.md +++ b/docs/user-guide/async.md @@ -7,9 +7,10 @@ Backoff fully supports Python's `async`/`await` syntax for asynchronous code. Simply decorate async functions with the same decorators: ```python -import backoff import aiohttp +import backoff + @backoff.on_exception(backoff.expo, aiohttp.ClientError) async def fetch_data(url): @@ -142,9 +143,11 @@ async def async_function(): ```python import asyncio +import logging + import aiohttp + import backoff -import logging logger = logging.getLogger(__name__) diff --git a/docs/user-guide/decorators.md b/docs/user-guide/decorators.md index 02d72bb..d4938bd 100644 --- a/docs/user-guide/decorators.md +++ b/docs/user-guide/decorators.md @@ -9,9 +9,10 @@ The `on_exception` decorator retries a function when a specified exception is ra ### Basic Usage ```python -import backoff import requests +import backoff + @backoff.on_exception( backoff.expo, diff --git a/docs/user-guide/event-handlers.md b/docs/user-guide/event-handlers.md index 24a2b8b..e5ba694 100644 --- a/docs/user-guide/event-handlers.md +++ b/docs/user-guide/event-handlers.md @@ -170,8 +170,8 @@ def my_function(): ### Structured Logging ```python -import logging import json +import logging logger = logging.getLogger(__name__) diff --git a/docs/user-guide/logging.md b/docs/user-guide/logging.md index c2c9502..c17c732 100644 --- a/docs/user-guide/logging.md +++ b/docs/user-guide/logging.md @@ -111,8 +111,8 @@ logging.getLogger("backoff").addHandler(logging.StreamHandler()) ### Structured Logging (JSON) ```python -import logging import json +import logging class JsonFormatter(logging.Formatter): diff --git a/pyproject.toml b/pyproject.toml index 1d41e5d..cfa70a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -186,6 +186,7 @@ docstring-code-line-length = 20 [tool.ruff.lint] extend-select = [ "RET", # flake8-return + "I", # isort "SIM", # flake8-simplify "UP", # pyupgrade ] diff --git a/tests/test_integration.py b/tests/test_integration.py index 9a59cb1..56b98a9 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -4,12 +4,11 @@ backoff patterns. """ -import backoff - - import requests -from requests import HTTPError import responses +from requests import HTTPError + +import backoff @responses.activate diff --git a/tests/test_package.py b/tests/test_package.py index 4f7677b..c5a5ad0 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -1,9 +1,10 @@ import sys from importlib.metadata import version -import backoff -from packaging.version import Version from packaging.specifiers import SpecifierSet +from packaging.version import Version + +import backoff if sys.version_info >= (3, 11): import tomllib diff --git a/tests/test_types.py b/tests/test_types.py index 5e40da0..dbbe1b5 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -1,4 +1,3 @@ from backoff.types import Details - assert Details # type: ignore[truthy-function] diff --git a/tests/test_typing.py b/tests/test_typing.py index 24a20b5..646a558 100644 --- a/tests/test_typing.py +++ b/tests/test_typing.py @@ -1,6 +1,5 @@ import backoff - # No pyunit tests are defined here yet, but the following decorator calls will # be analyzed by mypy which would have caught a bug the last release. diff --git a/tests/test_wait_gen.py b/tests/test_wait_gen.py index 2a7c4f4..33b1eec 100644 --- a/tests/test_wait_gen.py +++ b/tests/test_wait_gen.py @@ -1,6 +1,7 @@ -import backoff import math +import backoff + def test_decay(): gen = backoff.decay()