Skip to content

Conversation

cidrblock
Copy link
Contributor

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:

  1. Unused type: ignore comments that were no longer needed
  2. Missing type annotations for functions handling AnsibleBaseYAMLObject parameters
  3. Complex conditional imports from Ansible that type checkers struggle to analyze
  4. Cross-version compatibility requirements where the same symbols have different types

Changes Made

MyPy Error Resolution:

  • Removed unused type: ignore comments causing unused-ignore errors
  • Fixed assignment type error in jinja.py by properly typing orig_exc as BaseException
  • Added type: ignore[no-any-unimported] for functions with AnsibleBaseYAMLObject parameters
  • Added targeted type: ignore comments for AnsibleLoader and Origin compatibility issues

PyRight Error Resolution:

  • Added pyright: ignore[reportAttributeAccessIssue] for import symbols from conditional imports
  • Added pyright: ignore[reportAssignmentType] for cross-version type compatibility
  • Added pyright: ignore[reportAttributeAccessIssue] for internal Ansible/Jinja2 attribute access

Technical Details

The ignore comments are necessary rather than proper fixes because:

  1. Conditional Imports: Ansible types are imported differently based on version (2.19+ vs pre-2.19), making static analysis challenging
  2. Cross-Version Compatibility: The same symbol names refer to different types across Ansible versions
  3. Internal API Access: Some functionality requires accessing internal Ansible/Jinja2 attributes not part of the public API

Testing

  • tox -e lint -- mypy passes (0 errors, down from 44)
  • tox -e lint -- pyright passes (0 errors, down from 10)
  • All existing functionality preserved

This approach maintains type safety while respecting the complex compatibility requirements of the Ansible ecosystem.

- Remove unused type: ignore comments that were causing mypy unused-ignore errors
- Add type: ignore[no-any-unimported] for functions with AnsibleBaseYAMLObject parameters
- Fix assignment type error in jinja.py by properly typing orig_exc as BaseException
- Add pyright: ignore comments for import symbols and attribute access issues
- Add type: ignore comments for AnsibleLoader and Origin compatibility across Ansible versions

These changes resolve all remaining type checker errors while maintaining
compatibility with different Ansible versions. The ignore comments are
necessary due to conditional imports and version-specific type definitions
in the Ansible ecosystem.
@cidrblock cidrblock requested a review from a team as a code owner August 13, 2025 22:46
@github-actions github-actions bot added the chore label Aug 13, 2025
@cidrblock cidrblock merged commit 06f26f6 into ansible:main Aug 13, 2025
24 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant