Skip to content

Commit 8991e9d

Browse files
committed
refactor: SqliteDb uses its debug object more like other code
1 parent d4c09f9 commit 8991e9d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

coverage/sqldata.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ class SqliteDb(SimpleReprMixin):
10401040
10411041
"""
10421042
def __init__(self, filename, debug):
1043-
self.debug = debug if debug.should("sql") else None
1043+
self.debug = debug
10441044
self.filename = filename
10451045
self.nest = 0
10461046
self.con = None
@@ -1055,7 +1055,7 @@ def _connect(self):
10551055
# effectively causing a nested context. However, given the idempotent
10561056
# nature of the tracer operations, sharing a connection among threads
10571057
# is not a problem.
1058-
if self.debug:
1058+
if self.debug.should("sql"):
10591059
self.debug.write(f"Connecting to {self.filename!r}")
10601060
try:
10611061
self.con = sqlite3.connect(self.filename, check_same_thread=False)
@@ -1091,13 +1091,13 @@ def __exit__(self, exc_type, exc_value, traceback):
10911091
self.con.__exit__(exc_type, exc_value, traceback)
10921092
self.close()
10931093
except Exception as exc:
1094-
if self.debug:
1094+
if self.debug.should("sql"):
10951095
self.debug.write(f"EXCEPTION from __exit__: {exc}")
10961096
raise DataError(f"Couldn't end data file {self.filename!r}: {exc}") from exc
10971097

10981098
def execute(self, sql, parameters=()):
10991099
"""Same as :meth:`python:sqlite3.Connection.execute`."""
1100-
if self.debug:
1100+
if self.debug.should("sql"):
11011101
tail = f" with {parameters!r}" if parameters else ""
11021102
self.debug.write(f"Executing {sql!r}{tail}")
11031103
try:
@@ -1122,7 +1122,7 @@ def execute(self, sql, parameters=()):
11221122
)
11231123
except Exception: # pragma: cant happen
11241124
pass
1125-
if self.debug:
1125+
if self.debug.should("sql"):
11261126
self.debug.write(f"EXCEPTION from execute: {msg}")
11271127
raise DataError(f"Couldn't use data file {self.filename!r}: {msg}") from exc
11281128

@@ -1145,7 +1145,7 @@ def execute_one(self, sql, parameters=()):
11451145

11461146
def executemany(self, sql, data):
11471147
"""Same as :meth:`python:sqlite3.Connection.executemany`."""
1148-
if self.debug:
1148+
if self.debug.should("sql"):
11491149
data = list(data)
11501150
self.debug.write(f"Executing many {sql!r} with {len(data)} rows")
11511151
try:
@@ -1158,7 +1158,7 @@ def executemany(self, sql, data):
11581158

11591159
def executescript(self, script):
11601160
"""Same as :meth:`python:sqlite3.Connection.executescript`."""
1161-
if self.debug:
1161+
if self.debug.should("sql"):
11621162
self.debug.write("Executing script with {} chars: {}".format(
11631163
len(script), clipped_repr(script, 100),
11641164
))

0 commit comments

Comments
 (0)