Skip to content

Replace Union/Optional type hints with PEP604 style X | Y. - #993

Merged
junkmd merged 9 commits into
enthought:mainfrom
junkmd:union_pep604_up007
Nov 12, 2026
Merged

junkmd merged 9 commits into
enthought:mainfrom
junkmd:union_pep604_up007

Conversation

@junkmd

@junkmd junkmd commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR changes all type hints from Union[X, Y] and Optional[X] to the modern X | Y and X | None syntax (PEP 604).

What Was Changed

  • All .py files in comtypes/ package
  • All .py files in comtypes/test/ package
  • Stub file comtypes/hints.pyi
  • Updated pyproject.toml to confirm Python 3.10+ requirement

Convert `Optional[T]` and `Union[T, S]` annotations to `T | None` and `T | S`
in a package-wide pass, following PEP 604 and pyupgrade's UP007 rule.
This makes union type hints consistent and easier to read.
Some cases cannot be converted in this bulk pass and will be handled in a
follow-up change.
Sort imports and normalize formatting alongside the annotation changes.
Python 3.10 is now the minimum supported version, so type aliases no longer
need the older `typing.Union` form. Use `|` consistently in the remaining
aliases to make the COM type descriptions easier to read and maintain.
Python 3.10 is the minimum supported version, so `typing.Union` and `Optional`
are no longer needed.
Use `|` consistently in the remaining type annotations to make them easier to
read and maintain.
Keep forward references as strings when their types are only available to type
checkers, so the annotations do not require those names at runtime.
The `automation` module no longer needs the unused ctypes imports or the
runtime-only `_CArgObject` alias.
Python 3.9 is no longer supported, so it should not determine whether these
tests run. Keep skipping only Python 3.10 releases before 3.10.10 and Python
3.11 releases before 3.11.2, where the enthoughtGH-212 issue still affects the tests.
@junkmd junkmd added typing related to Python static typing system coding style Topics related to style, formatters, linters, and delinting. labels Nov 12, 2026
@codecov-commenter

codecov-commenter commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.67%. Comparing base (1dc7ab2) to head (f8bfd5d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #993      +/-   ##
==========================================
+ Coverage   90.80%   91.67%   +0.87%     
==========================================
  Files         149      149              
  Lines       15466    15281     -185     
==========================================
- Hits        14044    14009      -35     
+ Misses       1422     1272     -150     

☔ View full report in Codecov by Harness.
📢 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 added this to the 1.5.1 milestone Nov 12, 2026
@junkmd
junkmd merged commit fa5831f into enthought:main Nov 12, 2026
394 of 403 checks passed
@junkmd
junkmd deleted the union_pep604_up007 branch November 12, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coding style Topics related to style, formatters, linters, and delinting. typing related to Python static typing system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants