Skip to content

Commit 5df3c94

Browse files
Use Ruff to give the codebase a consistent format
Signed-off-by: Edgar Ramírez Mondragón <[email protected]>
1 parent 1cb2556 commit 5df3c94

31 files changed

+1179
-1132
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: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ 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(backoff.expo, requests.exceptions.RequestException)
4544
def get_url(url):
4645
return requests.get(url)
4746
@@ -50,9 +49,9 @@ the same backoff behavior is desired for more than one exception type:
5049

5150
.. code-block:: python
5251
53-
@backoff.on_exception(backoff.expo,
54-
(requests.exceptions.Timeout,
55-
requests.exceptions.ConnectionError))
52+
@backoff.on_exception(
53+
backoff.expo, (requests.exceptions.Timeout, requests.exceptions.ConnectionError)
54+
)
5655
def get_url(url):
5756
return requests.get(url)
5857
@@ -66,9 +65,7 @@ of total time in seconds that can elapse before giving up.
6665

6766
.. code-block:: python
6867
69-
@backoff.on_exception(backoff.expo,
70-
requests.exceptions.RequestException,
71-
max_time=60)
68+
@backoff.on_exception(backoff.expo, requests.exceptions.RequestException, max_time=60)
7269
def get_url(url):
7370
return requests.get(url)
7471
@@ -78,10 +75,9 @@ to make to the target function before giving up.
7875

7976
.. code-block:: python
8077
81-
@backoff.on_exception(backoff.expo,
82-
requests.exceptions.RequestException,
83-
max_tries=8,
84-
jitter=None)
78+
@backoff.on_exception(
79+
backoff.expo, requests.exceptions.RequestException, max_tries=8, jitter=None
80+
)
8581
def get_url(url):
8682
return requests.get(url)
8783
@@ -97,10 +93,10 @@ be retried:
9793
def fatal_code(e):
9894
return 400 <= e.response.status_code < 500
9995
100-
@backoff.on_exception(backoff.expo,
101-
requests.exceptions.RequestException,
102-
max_time=300,
103-
giveup=fatal_code)
96+
97+
@backoff.on_exception(
98+
backoff.expo, requests.exceptions.RequestException, max_time=300, giveup=fatal_code
99+
)
104100
def get_url(url):
105101
return requests.get(url)
106102
@@ -118,11 +114,14 @@ case, regardless of the logic in the `on_exception` handler.
118114
def fatal_code(e):
119115
return 400 <= e.response.status_code < 500
120116
121-
@backoff.on_exception(backoff.expo,
122-
requests.exceptions.RequestException,
123-
max_time=300,
124-
raise_on_giveup=False,
125-
giveup=fatal_code)
117+
118+
@backoff.on_exception(
119+
backoff.expo,
120+
requests.exceptions.RequestException,
121+
max_time=300,
122+
raise_on_giveup=False,
123+
giveup=fatal_code,
124+
)
126125
def get_url(url):
127126
return requests.get(url)
128127
@@ -217,12 +216,8 @@ backoff behavior for different cases:
217216
.. code-block:: python
218217
219218
@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)
219+
@backoff.on_exception(backoff.expo, requests.exceptions.HTTPError, max_time=60)
220+
@backoff.on_exception(backoff.expo, requests.exceptions.Timeout, max_time=300)
226221
def poll_for_message(queue):
227222
return queue.get()
228223
@@ -245,9 +240,9 @@ runtime to obtain the value:
245240
# and that it has a dictionary-like 'config' property
246241
return app.config["BACKOFF_MAX_TIME"]
247242
248-
@backoff.on_exception(backoff.expo,
249-
ValueError,
250-
max_time=lookup_max_time)
243+
244+
@backoff.on_exception(backoff.expo, ValueError, max_time=lookup_max_time)
245+
def my_function(): ...
251246
252247
Event handlers
253248
--------------
@@ -275,13 +270,16 @@ implemented like so:
275270
.. code-block:: python
276271
277272
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))
273+
print(
274+
"Backing off {wait:0.1f} seconds after {tries} tries "
275+
"calling function {target} with args {args} and kwargs "
276+
"{kwargs}".format(**details)
277+
)
281278
282-
@backoff.on_exception(backoff.expo,
283-
requests.exceptions.RequestException,
284-
on_backoff=backoff_hdlr)
279+
280+
@backoff.on_exception(
281+
backoff.expo, requests.exceptions.RequestException, on_backoff=backoff_hdlr
282+
)
285283
def get_url(url):
286284
return requests.get(url)
287285
@@ -293,9 +291,11 @@ handler functions as the value of the ``on_backoff`` keyword arg:
293291

294292
.. code-block:: python
295293
296-
@backoff.on_exception(backoff.expo,
297-
requests.exceptions.RequestException,
298-
on_backoff=[backoff_hdlr1, backoff_hdlr2])
294+
@backoff.on_exception(
295+
backoff.expo,
296+
requests.exceptions.RequestException,
297+
on_backoff=[backoff_hdlr1, backoff_hdlr2],
298+
)
299299
def get_url(url):
300300
return requests.get(url)
301301
@@ -343,41 +343,46 @@ as:
343343

344344
.. code-block:: python
345345
346-
logging.getLogger('backoff').addHandler(logging.StreamHandler())
346+
logging.getLogger("backoff").addHandler(logging.StreamHandler())
347347
348348
The default logging level is INFO, which corresponds to logging
349349
anytime a retry event occurs. If you would instead like to log
350350
only when a giveup event occurs, set the logger level to ERROR.
351351

352352
.. code-block:: python
353353
354-
logging.getLogger('backoff').setLevel(logging.ERROR)
354+
logging.getLogger("backoff").setLevel(logging.ERROR)
355355
356356
It is also possible to specify an alternate logger with the ``logger``
357357
keyword argument. If a string value is specified the logger will be
358358
looked up by name.
359359

360360
.. code-block:: python
361361
362-
@backoff.on_exception(backoff.expo,
363-
requests.exceptions.RequestException,
364-
logger='my_logger')
365-
# ...
362+
@backoff.on_exception(
363+
backoff.expo,
364+
requests.exceptions.RequestException,
365+
logger="my_logger",
366+
)
367+
def my_function(): ...
366368
367369
It is also supported to specify a Logger (or LoggerAdapter) object
368370
directly.
369371

370372
.. code-block:: python
371373
372-
my_logger = logging.getLogger('my_logger')
374+
my_logger = logging.getLogger("my_logger")
373375
my_handler = logging.StreamHandler()
374376
my_logger.addHandler(my_handler)
375377
my_logger.setLevel(logging.ERROR)
376378
377-
@backoff.on_exception(backoff.expo,
378-
requests.exceptions.RequestException,
379-
logger=my_logger)
380-
# ...
379+
380+
@backoff.on_exception(
381+
backoff.expo,
382+
requests.exceptions.RequestException,
383+
logger=my_logger,
384+
)
385+
def my_function(): ...
381386
382387
Default logging can be disabled all together by specifying
383388
``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)