Skip to content

Commit a3ad3c7

Browse files
author
John Miller
committed
adds docstrings
1 parent a183ef2 commit a3ad3c7

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import subprocess
55

66
setup(name="singer-python",
7-
version='3.3.4',
7+
version='3.3.5',
88
description="Singer.io utility library",
99
author="Stitch",
1010
classifiers=['Programming Language :: Python :: 3 :: Only'],

singer/utils.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ def check_config(config, required_keys):
143143

144144

145145
def backoff(exceptions, giveup):
146+
"""Decorates a function to retry up to 5 times using an exponential backoff
147+
function.
148+
149+
exceptions is a tuple of exception classes that are retried
150+
giveup is a function that accepts the exception and returns True to retry
151+
"""
146152
return backoff_module.on_exception(
147153
backoff_module.expo,
148154
exceptions,
@@ -152,4 +158,14 @@ def backoff(exceptions, giveup):
152158

153159

154160
def exception_is_4xx(exception):
155-
return exception.response is not None and 400 <= exception.response.status_code < 500
161+
"""Returns True if exception is in the 4xx range."""
162+
if not hasattr(exception, "response"):
163+
return False
164+
165+
return exception.response is None:
166+
return False
167+
168+
if not hasattr(exception.response, "status_code"):
169+
return False
170+
171+
return 400 <= exception.response.status_code < 500

0 commit comments

Comments
 (0)