widget: Define TypedDicts for todo/poll widget outputs and JSON payloads#1614
Open
NexionisJake wants to merge 1 commit intozulip:mainfrom
Open
widget: Define TypedDicts for todo/poll widget outputs and JSON payloads#1614NexionisJake wants to merge 1 commit intozulip:mainfrom
NexionisJake wants to merge 1 commit intozulip:mainfrom
Conversation
Member
|
Hello @zulip/server-refactoring members, this pull request was labeled with the "area: refactoring" label, so you may want to check it out! |
faac8f3 to
52209d9
Compare
This commit improves type safety for widget handling by: - Adding TypedDicts in api_types.py for all widget event JSON structures: - TodoInitialTask, TodoWidgetExtraData, TodoWidgetInit - TodoNewTaskEvent, TodoStrikeEvent, TodoNewTitleEvent - PollWidgetExtraData, PollWidgetInit, PollQuestionEvent - PollVoteEvent, PollNewOptionEvent - Union types: TodoWidgetEvent, PollWidgetEvent, WidgetEvent - Updating widget.py to use typed structures with casts for JSON parsing, providing better type checking and IDE support - Adding factory fixtures for Submessage content in tests: - submessage_factory() for constructing Submessage dicts - Helper functions for todo and poll widget JSON content - Submessage is now properly defined in api_types.py and used to improve the Message TypedDict definition - Fixed model.py to use correct Submessage field names (id, msg_type) - Updated test_model.py expected submessage formats to match new schema - Fixed model.py mypy error by casting msg_type to Literal["widget"] Fixes: zulip#1576
52209d9 to
123d1b2
Compare
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.
What does this PR do, and why?
This PR improves type safety for widget handling by defining TypedDicts for todo/poll widget outputs and JSON payloads.
Changes include:
Adding TypedDicts in api_types.py for all widget event JSON structures:
TodoWidgetEvent,PollWidgetEvent,WidgetEventUpdating widget.py to use typed structures with casts for JSON parsing, providing better type checking and IDE support
Adding factory fixtures for Submessage content in tests:
Submessage is now properly defined in api_types.py and used to improve the Message TypedDict definition
External discussion & connections
Widget followup workHow did you test this?
Self-review checklist for each commit