feat(eq2db): dunder surface on BaseCatalogue for debug logging + ergonomics#150
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_dbnow emits a DEBUG trace ([eq2db] init_db %r) using it.Helping the classes themselves:
__bool__—if not catalogue:reads as "not provisioned" (the samepath.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-pointspath.__fspath__— catalogues areos.PathLike:Path(cat),os.path.getsize(cat), and evensqlite3.connect(cat)work directly.__enter__/__exit__—with cat as conn:opens viainit_db(schema guaranteed) and closes on exit — unlikewith 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_schemais rejected at class-definition time with a clear TypeError, instead ofNotImplementedErroron the firstinit_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