mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-11 19:14:10 +02:00
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 <noreply@anthropic.com>
This commit is contained in:
parent
2ba282db8a
commit
da739fbaba
2 changed files with 5 additions and 3 deletions
|
|
@ -1037,6 +1037,7 @@ def insert_upsert_implementation(
|
|||
if csv or tsv:
|
||||
if sniff:
|
||||
# Read first 2048 bytes and use that to detect
|
||||
assert sniff_buffer is not None
|
||||
first_bytes = sniff_buffer.peek(2048)
|
||||
dialect = csv_std.Sniffer().sniff(
|
||||
first_bytes.decode(encoding, "ignore")
|
||||
|
|
@ -2120,7 +2121,8 @@ def _execute_query(
|
|||
else:
|
||||
headers = [c[0] for c in cursor.description]
|
||||
if raw:
|
||||
data = cursor.fetchone()[0]
|
||||
row = cursor.fetchone() # type: ignore[union-attr]
|
||||
data = row[0] if row else None
|
||||
if isinstance(data, bytes):
|
||||
sys.stdout.buffer.write(data)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -819,7 +819,7 @@ class Database:
|
|||
tables = [table for table in self.tables if table.has_counts_triggers]
|
||||
with self.conn:
|
||||
self._ensure_counts_table()
|
||||
counts_table = self[self._counts_table_name]
|
||||
counts_table = self.table(self._counts_table_name)
|
||||
counts_table.delete_where()
|
||||
counts_table.insert_all(
|
||||
{"table": table.name, "count": table.execute_count()}
|
||||
|
|
@ -1275,7 +1275,7 @@ class Database:
|
|||
def index_foreign_keys(self):
|
||||
"Create indexes for every foreign key column on every table in the database."
|
||||
for table_name in self.table_names():
|
||||
table = self[table_name]
|
||||
table = self.table(table_name)
|
||||
existing_indexes = {
|
||||
i.columns[0] for i in table.indexes if len(i.columns) == 1
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue