Skip to content

Conversation

@junkmd
Copy link
Collaborator

@junkmd junkmd commented Dec 18, 2025

#371 (comment)

This pull request enhances testing for Scripting.Dictionary and WindowsInstaller.Installer, and improves type safety for generated dispmethods.

Changes

  • Refactor and enhance test_dict.py

    • Replaced magic numbers in test_dynamic with Scripting constants.
    • Added a new test method test_static to verify the behavior of Scripting.IDictionary dual interface.
    • Improved overall code quality, readability, and test case robustness.
  • Add test_msi.py for WindowsInstaller.Installer

    • Introduced a new test suite to validate the behavior of the WindowsInstaller.Installer pure dispatch interface.
    • Includes tests for registry value access, key existence checks, and property access, including safeguards for the currently unsupported named arguments on dispmethods.
  • Enforce positional-only arguments for dispmethods (typing)

    • Modified the code generator to mark all arguments in generated dispmethod type hints as positional-only (/).
    • This allows static type checkers to prevent invalid calls using named arguments, which are not yet supported.

@junkmd junkmd added this to the 1.4.15 milestone Dec 18, 2025
@junkmd junkmd added tests enhance or fix tests typing related to Python static typing system labels Dec 18, 2025
@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.88%. Comparing base (b823fc6) to head (8dc6b01).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #885      +/-   ##
==========================================
+ Coverage   84.76%   84.88%   +0.11%     
==========================================
  Files         125      126       +1     
  Lines       11587    11668      +81     
==========================================
+ Hits         9822     9904      +82     
+ Misses       1765     1764       -1     

☔ 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.

…od calls.

Verifies the `WindowsInstaller.Installer` COM object's creation,
its pure dispatch nature (non-dual), and its dispmethod calls.
Adds a test for `Installer.RegistryValue`'s key existence check.
Also renames a test method for clarity and updates comments.
Adds a test to ensure a `ValueError` is raised when calling a
dispmethod with named parameters, which is not yet supported.
This acts as a safeguard against invalid calls.
Adds a test for the `Installer.ProductState` property to verify both
correct value retrieval and error handling.
Corrected a typo in a comment from "assing" to "assign".
Renamed the test method `test_dict` to `test_dynamic` to more accurately
reflect that it tests the dynamic dispatch capabilities of `comtypes`.
Updated the comment for the `HashVal` property to clarify that it is a
'hidden' member used internally by `Scripting.Dictionary`, not intended
for external use.
…nstants.

Replaced magic numbers with `comtypes.gen.Scripting` constants in
`comtypes/test/test_dict.py`.
This improves readability and maintainability by using named constants from the
`scrrun.dll` type library, aligning with official documentation for
`Scripting.Dictionary.CompareMode`.
To improve type safety, this change marks all arguments in generated
dispmethod stubs as positional-only. This allows static type checkers
to catch invalid calls using named arguments, which are not supported.
Modified `DispMethodAnnotator` to prevent adding a positional-only
parameter marker ('/') to method signatures that have no arguments.
This fixes a bug where it would generate inappropriate type hints like `def method(self, /)`.

An additional test case with a no-argument dispmethod (`egg`) was also
added to `test_disp_interface` to verify the fix.
@junkmd junkmd force-pushed the positional_params_typing branch from 61d092a to 8dc6b01 Compare December 18, 2025 22:19
@junkmd junkmd merged commit b400277 into enthought:main Dec 19, 2025
367 of 395 checks passed
@junkmd junkmd deleted the positional_params_typing branch December 19, 2025 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests enhance or fix tests typing related to Python static typing system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant