Skip to content

Commit da739fb

Browse files
simonwclaude
andcommitted
Fix remaining type warnings in sqlite_utils package
- Add assert for sniff_buffer not being None - Handle cursor.fetchone() potentially returning None - Use db.table() for counts_table and index_foreign_keys - Add type: ignore for cursor union type in raw mode 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 2ba282d commit da739fb

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

sqlite_utils/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,7 @@ def insert_upsert_implementation(
10371037
if csv or tsv:
10381038
if sniff:
10391039
# Read first 2048 bytes and use that to detect
1040+
assert sniff_buffer is not None
10401041
first_bytes = sniff_buffer.peek(2048)
10411042
dialect = csv_std.Sniffer().sniff(
10421043
first_bytes.decode(encoding, "ignore")
@@ -2120,7 +2121,8 @@ def _execute_query(
21202121
else:
21212122
headers = [c[0] for c in cursor.description]
21222123
if raw:
2123-
data = cursor.fetchone()[0]
2124+
row = cursor.fetchone() # type: ignore[union-attr]
2125+
data = row[0] if row else None
21242126
if isinstance(data, bytes):
21252127
sys.stdout.buffer.write(data)
21262128
else:

sqlite_utils/db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ def reset_counts(self):
819819
tables = [table for table in self.tables if table.has_counts_triggers]
820820
with self.conn:
821821
self._ensure_counts_table()
822-
counts_table = self[self._counts_table_name]
822+
counts_table = self.table(self._counts_table_name)
823823
counts_table.delete_where()
824824
counts_table.insert_all(
825825
{"table": table.name, "count": table.execute_count()}
@@ -1275,7 +1275,7 @@ def add_foreign_keys(self, foreign_keys: Iterable[Tuple[str, str, str, str]]):
12751275
def index_foreign_keys(self):
12761276
"Create indexes for every foreign key column on every table in the database."
12771277
for table_name in self.table_names():
1278-
table = self[table_name]
1278+
table = self.table(table_name)
12791279
existing_indexes = {
12801280
i.columns[0] for i in table.indexes if len(i.columns) == 1
12811281
}

0 commit comments

Comments
 (0)