Make the exploration, encounter, and battle handler tables private - #140
Merged
Merged
Conversation
) Each module's HANDLERS map was public and documented as an extension point, but GameSession merged the three into a module-level cache on its first dispatch, so replacing an entry afterward reached no session. The tables are now private (_HANDLERS), and each session builds its own merged table lazily on its first dispatch and keeps it on the instance, so two sessions never share one and GameSession.execute is the only documented way to run a command. Claude-Session: https://claude.ai/code/session_01NmCezTw8hKKujkaEZ3YGAs
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
osrlib.crawl.exploration.HANDLERS,osrlib.crawl.encounter.HANDLERS, andosrlib.crawl.battle.HANDLERSare renamed to_HANDLERS, dropped from each module's__all__, and no longer documented as a public extension point.GameSessionno longer merges the three tables into a module-level_HANDLERS_CACHEincrawl/session.py. Each session now assembles its own merged table lazily, on its first call toexecute, and caches it on the instance (self._handlers), so two sessions never share a table object and replacing a handler after a session's first command reaches that session as intended.GameSession.executeis unchanged in behavior: the same handler runs for every command class,session.command.wrong_modeand the "no handler for command type"ValueErrorbehave as before, and no golden file moved.HANDLERSas public are rewritten to describe the private table andGameSession.executeas the only documented way in; the runnable example inexploration.py'sHANDLERSdocstring, which imported the public name, is removed.CHANGELOG.mdgets one bullet under## [Unreleased]/### Removed.Closes #107
Test plan
uv run pytest --runxfail tests/test_handler_dispatch.py— 3 passed (the two chunk-marked tests now pass under--runxfail, and the control test still passes; the@pytest.mark.xfailmarkers are left in place per the packet).uv run ruff format --check— 160 files already formatted.uv run ruff check— all checks passed.uv run pyright— 0 errors, 0 warnings.uv run pytest— 2928 passed, 146 skipped, 4 xfailed, 2 xpassed (the two handler-dispatch tests, not marked strict so they don't fail the suite).uv run mkdocs build --strict— builds clean.https://claude.ai/code/session_01NmCezTw8hKKujkaEZ3YGAs