Skip to content

Commit 9980bf5

Browse files
committed
Use from clause when re-raising exceptions
1 parent 9923fc2 commit 9980bf5

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

dbutils/persistent_db.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,11 @@ def connection(self, shareable=False): # noqa: ARG002
210210
"""
211211
try:
212212
con = self.thread.connection
213-
except AttributeError:
213+
except AttributeError as error:
214214
con = self.steady_connection()
215215
if not con.threadsafety():
216-
raise NotSupportedError("Database module is not thread-safe.")
216+
raise NotSupportedError(
217+
"Database module is not thread-safe.") from error
217218
self.thread.connection = con
218219
con._ping_check()
219220
return con

dbutils/steady_db.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,11 @@ def _create(self):
277277
con.OperationalError,
278278
con.InterfaceError,
279279
con.InternalError)
280-
except AttributeError:
280+
except AttributeError as error:
281281
raise AttributeError(
282282
"Could not determine failure exceptions"
283-
" (please set failures or creator.dbapi).")
283+
" (please set failures or creator.dbapi)."
284+
) from error
284285
if isinstance(self._failures, tuple):
285286
self._failure = self._failures[0]
286287
else:
@@ -535,8 +536,8 @@ def __init__(self, con, *args, **kwargs):
535536
self._clearsizes()
536537
try:
537538
self._cursor = con._cursor(*args, **kwargs)
538-
except AttributeError:
539-
raise TypeError(f"{con!r} is not a SteadyDBConnection.")
539+
except AttributeError as error:
540+
raise TypeError(f"{con!r} is not a SteadyDBConnection.") from error
540541
self._closed = False
541542

542543
def __enter__(self):

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ select = [
106106
]
107107
# You can use `ruff rule ...` to see what these ignored rules check
108108
ignore = [
109-
"B904",
110109
"E722",
111110
"N811",
112111
"N818",

0 commit comments

Comments
 (0)