Repository navigation
Replace Union/Optional type hints with PEP604 style X | Y. - #993
Merged
Merged
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
Summary
This PR changes all type hints from
Union[X, Y]andOptional[X]to the modernX | YandX | Nonesyntax (PEP 604).What Was Changed
.pyfiles incomtypes/package.pyfiles incomtypes/test/packagecomtypes/hints.pyipyproject.tomlto confirm Python 3.10+ requirement