Skip to content

Unify Windows message handling APIs in messageloop.py.#932

Merged
junkmd merged 7 commits intoenthought:mainfrom
junkmd:unify_messageloop
Mar 7, 2026
Merged

Unify Windows message handling APIs in messageloop.py.#932
junkmd merged 7 commits intoenthought:mainfrom
junkmd:unify_messageloop

Conversation

@junkmd
Copy link
Collaborator

@junkmd junkmd commented Mar 7, 2026

Overview

This PR centralizes the definitions of Windows message-related APIs and constants into messageloop.py.
It also strengthens the type safety of these definitions and eliminates redundant boilerplate code across the test suite.

Improved Maintainability and Type Safety

Explicit Function Signatures

The argtypes and restype for GetMessage, TranslateMessage, DispatchMessage, and PeekMessage are now explicitly defined.
This transition from "loose" calls to typed calls allows ctypes to perform basic argument validation, preventing common developer errors related to stack corruption or incorrect type passing.

Standardized Resource usage

The code now leverages standard ctypes.wintypes (such as MSG, HWND, and BOOL) more consistently.

junkmd added 7 commits March 7, 2026 13:01
…ng `LPLONG` as `LRESULT` from `ctypes.wintypes`.
…s.wintypes.MSG`

- Removes redundant `POINT` and `MSG` structure definitions.
- Directly imports `MSG` from `ctypes.wintypes`, simplifying the import statements.
- Reduces boilerplate code and improves consistency by leveraging standard
  `wintypes` definitions.
…p.py`.

- Adds `argtypes` and `restype` for `GetMessage`, `TranslateMessage`, and
  `DispatchMessage`.
…ests.

- Define `PeekMessage` with `argtypes` and `restype` in `messageloop.py`.
- Update `test_eventinterface.py` and `test_git.py` to use `PeekMessage` and
  others from `messageloop`, removing redundant WinAPI definitions.
- Add `PM_NOREMOVE`, `PM_REMOVE`, and `PM_NOYIELD` constants to
  `messageloop.py`.
- Update `test_eventinterface.py` and `test_git.py` to import `PM_REMOVE`
  from `messageloop`, removing redundant local definitions.
@junkmd junkmd added this to the 1.4.17 milestone Mar 7, 2026
@junkmd junkmd added the tests enhance or fix tests label Mar 7, 2026
@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

❌ Patch coverage is 86.95652% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.59%. Comparing base (4a1a11a) to head (1ac90f2).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
comtypes/test/test_eventinterface.py 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #932      +/-   ##
==========================================
+ Coverage   88.50%   88.59%   +0.08%     
==========================================
  Files         139      139              
  Lines       13620    13613       -7     
==========================================
+ Hits        12055    12060       +5     
+ Misses       1565     1553      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@junkmd junkmd merged commit 069b9d1 into enthought:main Mar 7, 2026
52 checks passed
@junkmd junkmd deleted the unify_messageloop branch March 7, 2026 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests enhance or fix tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant