Open
Conversation
a59decb to
3b4154f
Compare
Replace the informal dict used for submessages with a properly typed TypedDict named 'Submessage' defined in api_types.py. This improves type safety across the codebase when processing widgets (polls, todos, etc.) by allowing mypy to validate: - The submessage structure with id, sender_id, content, msg_type - Function signatures in widget.py that process submessages - Event handling in model.py that constructs submessages Fixes zulip#1576.
3b4154f to
9719398
Compare
Collaborator
Author
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 implements TypedDict for the
Submessagestructure and centralizes it inapi_types.py.Key Motivations:
Dict[str, Any]toTypedDictallowsmypyto catch errors where submessage keys (likeidormsg_type) might be missing or mistyped.submessage_idandtypeto a unifiedidandmsg_typestructure.api_types.pyfor easier reuse.Files Changed:
zulipterminal/api_types.py: AddedSubmessage,TodoWidgetResult, andPollWidgetResultTypedDicts.zulipterminal/model.py: Updated submessage handling logic to use new keys and imports.zulipterminal/widget.py: Refactored widget processing to return the new TypedDicts.tests/conftest.py: Addedsubmessage_factoryto simplify and type-check test data creation.tests/widget/test_widget.py&tests/model/test_model.py: Updated imports and test expectations to match the new structure.tests/helper/test_helper.py&tests/cli/test_run.py: Fixed pre-existing environment-related failures (path normalization and CLI output capturing) to ensure a green test suite in WSL/Linux.Outstanding aspect(s)
mypyis run with--follow-imports=skip' to avoid syntax errors in third-party libraries (likepackaging`) found in the local virtual environment.External discussion & connections
How did you test this?
Self-review checklist for each commit