mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-11 19:14:10 +02:00
Use ctx.meta instead of dynamic attribute for database cleanup
Click's Context.meta dictionary is the proper way to store arbitrary data on the context object, avoiding type checker warnings about dynamic attribute assignment. 🤖 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
cb172edca0
commit
0ee090f541
1 changed files with 8 additions and 9 deletions
|
|
@ -50,20 +50,19 @@ def _register_db_for_cleanup(db):
|
|||
ctx = click.get_current_context(silent=True)
|
||||
if ctx is None:
|
||||
return
|
||||
if not hasattr(ctx, "_databases_to_close"):
|
||||
ctx._databases_to_close = []
|
||||
if "_databases_to_close" not in ctx.meta:
|
||||
ctx.meta["_databases_to_close"] = []
|
||||
ctx.call_on_close(lambda: _close_databases(ctx))
|
||||
ctx._databases_to_close.append(db)
|
||||
ctx.meta["_databases_to_close"].append(db)
|
||||
|
||||
|
||||
def _close_databases(ctx):
|
||||
"""Close all databases registered for cleanup."""
|
||||
if hasattr(ctx, "_databases_to_close"):
|
||||
for db in ctx._databases_to_close:
|
||||
try:
|
||||
db.close()
|
||||
except Exception:
|
||||
pass
|
||||
for db in ctx.meta.get("_databases_to_close", []):
|
||||
try:
|
||||
db.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
VALID_COLUMN_TYPES = ("INTEGER", "TEXT", "FLOAT", "REAL", "BLOB")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue