Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion backoff/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion backoff/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
26 changes: 16 additions & 10 deletions docs/user-guide/async.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions docs/user-guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
17 changes: 10 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ docs = [
"zensical==0.0.47",
]
lint = [
"ruff>=0.15.0",
"ruff>=0.16.0",
]
test = [
"coverage>=7.2.7",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down
12 changes: 7 additions & 5 deletions tests/test_backoff.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ruff: file-ignore[float-equality-comparison]

import logging
import re
import sys
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_backoff_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test_wait_gen.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ruff: file-ignore[float-equality-comparison]

import math

import backoff
Expand Down
Loading