Skip to content

feat(eq2db): dunder surface on BaseCatalogue for debug logging + ergonomics#150

Merged
VortexUK merged 1 commit into
mainfrom
refactor/catalogue-dunders
Jul 11, 2026
Merged

feat(eq2db): dunder surface on BaseCatalogue for debug logging + ergonomics#150
VortexUK merged 1 commit into
mainfrom
refactor/catalogue-dunders

Conversation

@VortexUK

Copy link
Copy Markdown
Owner

Summary

Adds a uniform dunder surface to BaseCatalogue (#149) so every catalogue is pleasant to log, compare, and use.

Debug/trace logging:

  • __repr__ — one log-safe line: class, path, ready/missing, and per-instance cache sizes via a new _cache_info() hook (overridden by the three cache-holding catalogues). Live examples:
    • SpellCatalogue(path='…\spells.db', ready, crc_cache=1)
    • AACatalogue(path='…\aas.db', ready, tree_index=157, trees=0, …)
    • RaidCatalogue(path='data\nonexistent.db', missing)
  • init_db now emits a DEBUG trace ([eq2db] init_db %r) using it.

Helping the classes themselves:

  • __bool__if not catalogue: reads as "not provisioned" (the same path.exists() check every read path already guards with; grep confirmed no existing bare-truthiness call sites change behaviour).
  • __eq__ / __hash__ — value semantics by (type, path); usable as dict keys / in sets, with a documented caveat about hashing before conftest re-points path.
  • __fspath__ — catalogues are os.PathLike: Path(cat), os.path.getsize(cat), and even sqlite3.connect(cat) work directly.
  • __enter__ / __exit__with cat as conn: opens via init_db (schema guaranteed) and closes on exit — unlike with cat.init_db() as conn: (sqlite3's own CM commits but never closes the handle). Nest-safe via a per-instance connection stack.
  • __init_subclass__ — a concrete subclass that forgets _create_schema is rejected at class-definition time with a clear TypeError, instead of NotImplementedError on the first init_db() call. Subclassing a concrete catalogue (test doubles) still works — the schema is inherited.

Tests

tests/eq2db/test_catalogue_base.py — 19 tests exercising the whole surface through real subclasses (RaidCatalogue, SpellCatalogue): repr states + cache rendering, bool, eq/hash/dict-key, fspath incl. sqlite3.connect(cat), CM close-on-exit / nesting / close-on-exception, and the __init_subclass__ guard.

Full suite: 1521 passed; ruff + pyright clean.

🤖 Generated with Claude Code

…nomics

Uniform dunders across all seven catalogues:

- __repr__ — class, path, ready/missing, per-instance cache sizes (via a
  new _cache_info hook, overridden by AACatalogue / ClassCatalogue /
  SpellCatalogue); safe to drop into any log line. init_db now emits a
  DEBUG trace using it.
- __bool__ — truthiness = "DB file provisioned"; mirrors the
  path.exists() guard every read path already uses.
- __eq__/__hash__ — value semantics by (type, path); catalogues are
  dict-key/set safe (documented caveat: don't hash before conftest
  re-points path).
- __fspath__ — catalogues are os.PathLike: Path(cat) and
  sqlite3.connect(cat) work directly.
- __enter__/__exit__ — `with cat as conn:` opens via init_db and CLOSES
  on exit (sqlite3's own conn CM commits but never closes); nest-safe
  via a per-instance connection stack.
- __init_subclass__ — a concrete subclass that forgets _create_schema
  fails at class-definition time instead of on the first init_db call.

19 new tests in tests/eq2db/test_catalogue_base.py exercising the
surface through real subclasses (RaidCatalogue, SpellCatalogue).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@VortexUK
VortexUK merged commit 9b0131a into main Jul 11, 2026
6 checks passed
@VortexUK
VortexUK deleted the refactor/catalogue-dunders branch July 11, 2026 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant