Fix type errors in cli.py and db.py

- Add type annotation for Database.conn to fix context manager errors
- Convert exception objects to str() when raising ClickException
- Handle None return from find_spatialite() with proper error message

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Simon Willison 2025-12-16 16:25:03 -08:00
commit 29842be858
2 changed files with 8 additions and 4 deletions

View file

@ -393,7 +393,7 @@ def analyze(path, names):
else:
db.analyze()
except OperationalError as e:
raise click.ClickException(e)
raise click.ClickException(str(e))
@cli.command()
@ -536,7 +536,7 @@ def add_foreign_key(
try:
db[table].add_foreign_key(column, other_table, other_column, ignore=ignore)
except AlterError as e:
raise click.ClickException(e)
raise click.ClickException(str(e))
@cli.command(name="add-foreign-keys")
@ -571,7 +571,7 @@ def add_foreign_keys(path, foreign_key, load_extension):
try:
db.add_foreign_keys(tuples)
except AlterError as e:
raise click.ClickException(e)
raise click.ClickException(str(e))
@cli.command(name="index-foreign-keys")
@ -3361,7 +3361,10 @@ def _load_extensions(db, load_extension):
db.conn.enable_load_extension(True)
for ext in load_extension:
if ext == "spatialite" and not os.path.exists(ext):
ext = find_spatialite()
found = find_spatialite()
if found is None:
raise click.ClickException("Could not find SpatiaLite extension")
ext = found
if ":" in ext:
path, _, entrypoint = ext.partition(":")
db.conn.execute("SELECT load_extension(?, ?)", [path, entrypoint])

View file

@ -328,6 +328,7 @@ class Database:
_counts_table_name = "_counts"
use_counts_table = False
conn: sqlite3.Connection
def __init__(
self,