Fix mypy and pyright type checking errors #4724
Merged
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.
This PR resolves all remaining mypy and pyright type checking errors in the codebase while maintaining compatibility across different Ansible versions.
Background
The codebase had accumulated type checking errors due to:
type: ignore
comments that were no longer neededAnsibleBaseYAMLObject
parametersChanges Made
MyPy Error Resolution:
type: ignore
comments causingunused-ignore
errorsjinja.py
by properly typingorig_exc
asBaseException
type: ignore[no-any-unimported]
for functions withAnsibleBaseYAMLObject
parameterstype: ignore
comments forAnsibleLoader
andOrigin
compatibility issuesPyRight Error Resolution:
pyright: ignore[reportAttributeAccessIssue]
for import symbols from conditional importspyright: ignore[reportAssignmentType]
for cross-version type compatibilitypyright: ignore[reportAttributeAccessIssue]
for internal Ansible/Jinja2 attribute accessTechnical Details
The ignore comments are necessary rather than proper fixes because:
Testing
tox -e lint -- mypy
passes (0 errors, down from 44)tox -e lint -- pyright
passes (0 errors, down from 10)This approach maintains type safety while respecting the complex compatibility requirements of the Ansible ecosystem.