Skip to content

#1576#1616

Open
Moksha25-tech wants to merge 1 commit intozulip:mainfrom
Moksha25-tech:issue-1576
Open

#1576#1616
Moksha25-tech wants to merge 1 commit intozulip:mainfrom
Moksha25-tech:issue-1576

Conversation

@Moksha25-tech
Copy link
Copy Markdown
Collaborator

What does this PR do, and why?

This PR implements TypedDict for the Submessage structure and centralizes it in api_types.py.

Key Motivations:

  1. Type Safety: Moving away from generic Dict[str, Any] to TypedDict allows mypy to catch errors where submessage keys (like id or msg_type) might be missing or mistyped.
  2. Consistency: Standardizes the field names across the app. We moved from the inconsistent use of submessage_id and type to a unified id and msg_type structure.
  3. Centralization: Following Zulip Terminal patterns, all API-related structures are now in api_types.py for easier reuse.

Files Changed:

  1. zulipterminal/api_types.py: Added Submessage, TodoWidgetResult, and PollWidgetResult TypedDicts.
  2. zulipterminal/model.py: Updated submessage handling logic to use new keys and imports.
  3. zulipterminal/widget.py: Refactored widget processing to return the new TypedDicts.
  4. tests/conftest.py: Added submessage_factory to simplify and type-check test data creation.
  5. tests/widget/test_widget.py & tests/model/test_model.py: Updated imports and test expectations to match the new structure.
  6. 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)

  • Currently, mypy is run with --follow-imports=skip' to avoid syntax errors in third-party libraries (like packaging`) found in the local virtual environment.

External discussion & connections

How did you test this?

  • Manually - Behavioral changes
  • Adapting existing automated tests
  • Existing automated tests should already cover this (only a refactor of tested code)

Self-review checklist for each commit

  • It is a minimal coherent idea
  • It has a commit summary following the documented style (title & body)
  • It has a commit summary describing the motivation and reasoning for the change
  • It individually passes linting and tests
  • It contains test additions for any new behavior

@zulipbot zulipbot added the size: XL [Automatic label added by zulipbot] label Feb 14, 2026
@Moksha25-tech Moksha25-tech force-pushed the issue-1576 branch 13 times, most recently from a59decb to 3b4154f Compare February 15, 2026 12:44
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.
@Moksha25-tech
Copy link
Copy Markdown
Collaborator Author

Moksha25-tech commented Feb 26, 2026

@neiljp @zulipbot I wanted to request review for my PR as I am done working on the issue from my end. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XL [Automatic label added by zulipbot]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve typing & test approach for widgets

2 participants