Skip to content

Commit c5acf97

Browse files
Use Ruff to give the codebase a consistent format (#66)
* Use Ruff to give the codebase a consistent format Signed-off-by: Edgar Ramírez Mondragón <[email protected]> * Apply suggestions from code review * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Split arguments into separate lines in decorator examples Signed-off-by: Edgar Ramírez Mondragón <[email protected]> --------- Signed-off-by: Edgar Ramírez Mondragón <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1cb2556 commit c5acf97

31 files changed

+1368
-940
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
rev: v0.14.6
1717
hooks:
1818
- id: ruff-check
19-
# - id: ruff-format
19+
- id: ruff-format
2020
- repo: https://github.com/astral-sh/uv-pre-commit
2121
rev: 0.9.13
2222
hooks:
@@ -26,3 +26,10 @@ repos:
2626
hooks:
2727
- id: check-github-workflows
2828
- id: check-renovate
29+
- repo: https://github.com/adamtheturtle/doccmd-pre-commit
30+
rev: v2025.12.8.5
31+
hooks:
32+
- id: doccmd
33+
args: ["--language", "python", "--no-pad-file", "--no-pad-groups", "--command", "ruff format", "docs/"]
34+
additional_dependencies:
35+
- ruff==0.14.8

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
- Switch to [Zensical for building the documentation](https://zensical.org/) [#62](https://github.com/python-backoff/backoff/pull/62) (from [@edgarrmondragon](https://github.com/edgarrmondragon))
88
- Include changelog in the documentation [#65](https://github.com/python-backoff/backoff/pull/65) (from [@edgarrmondragon](https://github.com/edgarrmondragon))
99

10+
### Internal
11+
12+
- Use Ruff to give the codebase a consistent format [#66](https://github.com/python-backoff/backoff/pull/66) (from [@edgarrmondragon](https://github.com/edgarrmondragon))
13+
1014
## [v2.3.0] - 2025-11-28
1115

1216
### Changed

README.rst

Lines changed: 104 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ is raised. Here's an example using exponential backoff when any
4040

4141
.. code-block:: python
4242
43-
@backoff.on_exception(backoff.expo,
44-
requests.exceptions.RequestException)
43+
@backoff.on_exception(
44+
backoff.expo,
45+
requests.exceptions.RequestException,
46+
)
4547
def get_url(url):
4648
return requests.get(url)
4749
@@ -50,9 +52,13 @@ the same backoff behavior is desired for more than one exception type:
5052

5153
.. code-block:: python
5254
53-
@backoff.on_exception(backoff.expo,
54-
(requests.exceptions.Timeout,
55-
requests.exceptions.ConnectionError))
55+
@backoff.on_exception(
56+
backoff.expo,
57+
(
58+
requests.exceptions.Timeout,
59+
requests.exceptions.ConnectionError,
60+
),
61+
)
5662
def get_url(url):
5763
return requests.get(url)
5864
@@ -66,9 +72,11 @@ of total time in seconds that can elapse before giving up.
6672

6773
.. code-block:: python
6874
69-
@backoff.on_exception(backoff.expo,
70-
requests.exceptions.RequestException,
71-
max_time=60)
75+
@backoff.on_exception(
76+
backoff.expo,
77+
requests.exceptions.RequestException,
78+
max_time=60,
79+
)
7280
def get_url(url):
7381
return requests.get(url)
7482
@@ -78,10 +86,12 @@ to make to the target function before giving up.
7886

7987
.. code-block:: python
8088
81-
@backoff.on_exception(backoff.expo,
82-
requests.exceptions.RequestException,
83-
max_tries=8,
84-
jitter=None)
89+
@backoff.on_exception(
90+
backoff.expo,
91+
requests.exceptions.RequestException,
92+
max_tries=8,
93+
jitter=None,
94+
)
8595
def get_url(url):
8696
return requests.get(url)
8797
@@ -97,10 +107,13 @@ be retried:
97107
def fatal_code(e):
98108
return 400 <= e.response.status_code < 500
99109
100-
@backoff.on_exception(backoff.expo,
101-
requests.exceptions.RequestException,
102-
max_time=300,
103-
giveup=fatal_code)
110+
111+
@backoff.on_exception(
112+
backoff.expo,
113+
requests.exceptions.RequestException,
114+
max_time=300,
115+
giveup=fatal_code,
116+
)
104117
def get_url(url):
105118
return requests.get(url)
106119
@@ -118,11 +131,14 @@ case, regardless of the logic in the `on_exception` handler.
118131
def fatal_code(e):
119132
return 400 <= e.response.status_code < 500
120133
121-
@backoff.on_exception(backoff.expo,
122-
requests.exceptions.RequestException,
123-
max_time=300,
124-
raise_on_giveup=False,
125-
giveup=fatal_code)
134+
135+
@backoff.on_exception(
136+
backoff.expo,
137+
requests.exceptions.RequestException,
138+
max_time=300,
139+
raise_on_giveup=False,
140+
giveup=fatal_code,
141+
)
126142
def get_url(url):
127143
return requests.get(url)
128144
@@ -142,7 +158,11 @@ return value of the target function is the empty list:
142158

143159
.. code-block:: python
144160
145-
@backoff.on_predicate(backoff.fibo, lambda x: x == [], max_value=13)
161+
@backoff.on_predicate(
162+
backoff.fibo,
163+
lambda x: x == [],
164+
max_value=13,
165+
)
146166
def poll_for_messages(queue):
147167
return queue.get()
148168
@@ -164,7 +184,11 @@ gets a non-falsey result could be defined like like this:
164184

165185
.. code-block:: python
166186
167-
@backoff.on_predicate(backoff.constant, jitter=None, interval=1)
187+
@backoff.on_predicate(
188+
backoff.constant,
189+
jitter=None,
190+
interval=1,
191+
)
168192
def poll_for_message(queue):
169193
return queue.get()
170194
@@ -217,12 +241,16 @@ backoff behavior for different cases:
217241
.. code-block:: python
218242
219243
@backoff.on_predicate(backoff.fibo, max_value=13)
220-
@backoff.on_exception(backoff.expo,
221-
requests.exceptions.HTTPError,
222-
max_time=60)
223-
@backoff.on_exception(backoff.expo,
224-
requests.exceptions.Timeout,
225-
max_time=300)
244+
@backoff.on_exception(
245+
backoff.expo,
246+
requests.exceptions.HTTPError,
247+
max_time=60,
248+
)
249+
@backoff.on_exception(
250+
backoff.expo,
251+
requests.exceptions.Timeout,
252+
max_time=300,
253+
)
226254
def poll_for_message(queue):
227255
return queue.get()
228256
@@ -245,9 +273,13 @@ runtime to obtain the value:
245273
# and that it has a dictionary-like 'config' property
246274
return app.config["BACKOFF_MAX_TIME"]
247275
248-
@backoff.on_exception(backoff.expo,
249-
ValueError,
250-
max_time=lookup_max_time)
276+
277+
@backoff.on_exception(
278+
backoff.expo,
279+
ValueError,
280+
max_time=lookup_max_time,
281+
)
282+
def my_function(): ...
251283
252284
Event handlers
253285
--------------
@@ -275,13 +307,18 @@ implemented like so:
275307
.. code-block:: python
276308
277309
def backoff_hdlr(details):
278-
print ("Backing off {wait:0.1f} seconds after {tries} tries "
279-
"calling function {target} with args {args} and kwargs "
280-
"{kwargs}".format(**details))
310+
print(
311+
"Backing off {wait:0.1f} seconds after {tries} tries "
312+
"calling function {target} with args {args} and kwargs "
313+
"{kwargs}".format(**details)
314+
)
315+
281316
282-
@backoff.on_exception(backoff.expo,
283-
requests.exceptions.RequestException,
284-
on_backoff=backoff_hdlr)
317+
@backoff.on_exception(
318+
backoff.expo,
319+
requests.exceptions.RequestException,
320+
on_backoff=backoff_hdlr,
321+
)
285322
def get_url(url):
286323
return requests.get(url)
287324
@@ -293,9 +330,14 @@ handler functions as the value of the ``on_backoff`` keyword arg:
293330

294331
.. code-block:: python
295332
296-
@backoff.on_exception(backoff.expo,
297-
requests.exceptions.RequestException,
298-
on_backoff=[backoff_hdlr1, backoff_hdlr2])
333+
@backoff.on_exception(
334+
backoff.expo,
335+
requests.exceptions.RequestException,
336+
on_backoff=[
337+
backoff_hdlr1,
338+
backoff_hdlr2,
339+
],
340+
)
299341
def get_url(url):
300342
return requests.get(url)
301343
@@ -326,7 +368,11 @@ asynchronous HTTP client/server library.
326368

327369
.. code-block:: python
328370
329-
@backoff.on_exception(backoff.expo, aiohttp.ClientError, max_time=60)
371+
@backoff.on_exception(
372+
backoff.expo,
373+
aiohttp.ClientError,
374+
max_time=60,
375+
)
330376
async def get_url(url):
331377
async with aiohttp.ClientSession(raise_for_status=True) as session:
332378
async with session.get(url) as response:
@@ -343,41 +389,46 @@ as:
343389

344390
.. code-block:: python
345391
346-
logging.getLogger('backoff').addHandler(logging.StreamHandler())
392+
logging.getLogger("backoff").addHandler(logging.StreamHandler())
347393
348394
The default logging level is INFO, which corresponds to logging
349395
anytime a retry event occurs. If you would instead like to log
350396
only when a giveup event occurs, set the logger level to ERROR.
351397

352398
.. code-block:: python
353399
354-
logging.getLogger('backoff').setLevel(logging.ERROR)
400+
logging.getLogger("backoff").setLevel(logging.ERROR)
355401
356402
It is also possible to specify an alternate logger with the ``logger``
357403
keyword argument. If a string value is specified the logger will be
358404
looked up by name.
359405

360406
.. code-block:: python
361407
362-
@backoff.on_exception(backoff.expo,
363-
requests.exceptions.RequestException,
364-
logger='my_logger')
365-
# ...
408+
@backoff.on_exception(
409+
backoff.expo,
410+
requests.exceptions.RequestException,
411+
logger="my_logger",
412+
)
413+
def my_function(): ...
366414
367415
It is also supported to specify a Logger (or LoggerAdapter) object
368416
directly.
369417

370418
.. code-block:: python
371419
372-
my_logger = logging.getLogger('my_logger')
420+
my_logger = logging.getLogger("my_logger")
373421
my_handler = logging.StreamHandler()
374422
my_logger.addHandler(my_handler)
375423
my_logger.setLevel(logging.ERROR)
376424
377-
@backoff.on_exception(backoff.expo,
378-
requests.exceptions.RequestException,
379-
logger=my_logger)
380-
# ...
425+
426+
@backoff.on_exception(
427+
backoff.expo,
428+
requests.exceptions.RequestException,
429+
logger=my_logger,
430+
)
431+
def my_function(): ...
381432
382433
Default logging can be disabled all together by specifying
383434
``logger=None``. In this case, if desired alternative logging behavior

backoff/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@
1212
For examples and full documentation see the README at
1313
https://github.com/python-backoff/backoff
1414
"""
15+
1516
from backoff._decorator import on_exception, on_predicate
1617
from backoff._jitter import full_jitter, random_jitter
1718
from backoff._wait_gen import constant, expo, fibo, runtime, decay
1819

1920
__all__ = [
20-
'on_predicate',
21-
'on_exception',
22-
'constant',
23-
'expo',
24-
'decay',
25-
'fibo',
26-
'runtime',
27-
'full_jitter',
28-
'random_jitter',
21+
"on_predicate",
22+
"on_exception",
23+
"constant",
24+
"expo",
25+
"decay",
26+
"fibo",
27+
"runtime",
28+
"full_jitter",
29+
"random_jitter",
2930
]
3031

3132
__version__ = "2.2.1"

0 commit comments

Comments
 (0)