Skip to content

Make event models generic over literal names - #26

Merged
strohganoff merged 3 commits into
mainfrom
refactor/generic-event-models
Nov 9, 2026
Merged

strohganoff merged 3 commits into
mainfrom
refactor/generic-event-models

Conversation

@strohganoff

@strohganoff strohganoff commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Make EventBase generic over event-name string literals so concrete event models declare their protocol names with bases such as EventBase[Literal["keyDown"]] and expose precise event types to handlers.

Pydantic's generic metadata validates the event-name type arguments and records each model's event names. The event adapter uses those names to build its dynamic validation schema. The refactor also simplifies EventBase, updates model discovery, and revises the affected tests and README example.

Three event class headers stay on one line with # fmt: skip because Python 3.10's source inspection in Pydantic fails to tokenize those generic bases when written across multiple lines.

Validation: 194 tests passed on Python 3.10; mypy passed; Ruff format check passed for the changed files.

@strohganoff
strohganoff added this pull request to stack #27 November 9, 2026 19:41
@strohganoff strohganoff changed the title Keep generic event model declarations inline Make EventBase generic over literal event names Nov 9, 2026
@strohganoff

strohganoff commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner Author

Scope clarification: this branch migrates concrete event models to EventBase[Literal[...]], derives each model's registered event names from Pydantic's generic metadata, and uses those names to build the adapter's dynamic validation schema. It also covers model discovery and regression tests. This PR is stacked on #25 and should merge after the mypy/Python-version upgrade.

@strohganoff strohganoff changed the title Make EventBase generic over literal event names Make event models generic over literal names Nov 9, 2026
Base automatically changed from refactor/upgrade-mypy to main November 9, 2026 19:44
@strohganoff
strohganoff force-pushed the refactor/generic-event-models branch from c97b869 to a227232 Compare November 9, 2026 19:44
@strohganoff
strohganoff merged commit b1a838a into main Nov 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant