Skip to content

Address/cleanup pyright type issues throughout the codebase: Phase 1#153

Merged
speediedan merged 4 commits intomainfrom
copilot/fix-137
Aug 22, 2025
Merged

Address/cleanup pyright type issues throughout the codebase: Phase 1#153
speediedan merged 4 commits intomainfrom
copilot/fix-137

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Aug 22, 2025

Completed first phase of pyright type checking expansion addressing issue #137.

✅ Phase 1 Complete: Initial Pyright Expansion

Expanded pyright coverage from 1 → 9 files (900% increase)
All files under pyright checking now have 0 errors

Files now under pyright checking (9 total, all with 0 errors):

  • src/interpretune/adapters/lightning.py: 0 errors (already configured)
  • src/interpretune/adapters/core.py: 0 errors (added)
  • src/interpretune/adapter_registry.py: 0 errors (added)
  • src/interpretune/utils/data_movement.py: 0 errors (added)
  • src/interpretune/utils/tokenization.py: 0 errors (added)
  • src/interpretune/utils/logging.py: 0 errors (fixed 2 errors)
  • src/interpretune/utils/exceptions.py: 0 errors (fixed 10 errors)
  • src/interpretune/utils/warnings.py: 0 errors (added)
  • src/interpretune/utils/schema_validation.py: 0 errors, 2 warnings (added)

Type fixes implemented:

utils/logging.py (2 errors → 0 errors):

  • Fixed orig_fn potentially being None in context manager finally block
  • Added type ignore for function attribute assignment (deliberate pattern)

utils/exceptions.py (10 errors → 0 errors):

  • Fixed code_context being potentially None from frame inspection
  • Added explicit Dict[str, Any] type annotations to resolve type inference issues
  • Fixed indentation after code_context null check

Current status:

  • Total files under pyright checking: 9 (increased from 1)
  • All files have 0 errors
  • Only 2 warnings (missing optional dependency imports, acceptable)
  • All changes pass ruff linting
  • All changes are minimal and non-invasive

Files assessed for future phases:

Phase 2 candidates (moderate complexity):

  • 🔧 src/interpretune/utils/import_utils.py: 8 errors (type inference issues)
  • 🔧 src/interpretune/adapters/registration.py: 7 errors (dict typing issues)
  • 🔧 src/interpretune/session.py: 3 errors (parameter naming issues)
  • 🔧 src/interpretune/base/call.py: 2 errors (tensor type issues)

Phase 3 candidates (complex):

  • 🔧 src/interpretune/base/components/cli.py: 24 errors (complex CLI typing)
  • 🔧 src/interpretune/base/components/mixins.py: 35 errors (ML tensor operations)
  • 🔧 src/interpretune/base/components/core.py: 10 errors (protocol compatibility)
  • 🔧 src/interpretune/config/shared.py: 11 errors (generic type issues)
  • 🔧 src/interpretune/config/analysis.py: 12 errors (complex protocols)
  • 🔧 src/interpretune/registry.py: 15 errors (registry type system)

Methodology validated:

  1. ✅ Start with files that already have 0 errors
  2. ✅ Fix simple typing issues with minimal changes
  3. ✅ Use explicit type annotations to resolve inference issues
  4. ✅ Add # type: ignore for deliberate patterns
  5. ✅ Expand configuration incrementally
  6. ✅ Maintain 100% pass rate before adding new files

Next steps for subsequent PRs:

  1. Work through Phase 2 candidates with moderate complexity
  2. Create shared type definitions if patterns emerge
  3. Consider structural improvements for Phase 3 complex files
  4. Eventually expand to broader directories with wildcard includes

This establishes a solid foundation for continued incremental pyright expansion.

Fixes #137.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: speediedan <7462936+speediedan@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

No CI pin file changes detected by regen-ci-req-check.

@speediedan
Copy link
Copy Markdown
Owner

@copilot try again after your error

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Aug 22, 2025

@copilot try again after your error

I've resolved the network timeout errors that were preventing dependency installation. The pyright type checking expansion is now working correctly:

Pyright passes: 0 errors, 2 warnings (acceptable optional dependency imports)
Ruff linting passes: No style issues in source code
All 9 files verified: Expanded from 1 → 9 files under type checking
Type fixes confirmed: Resolved the specific issues in utils/logging.py and utils/exceptions.py

The changes are ready and all validation that can run in this environment passes successfully. Commit: 81bf0b9

@github-actions github-actions bot added area: docs Documentation files area: ci Continuous integration labels Aug 22, 2025
@speediedan speediedan marked this pull request as ready for review August 22, 2025 16:01
Copilot AI review requested due to automatic review settings August 22, 2025 16:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements Phase 1 of a systematic pyright type checking expansion, addressing issue #137 by increasing type checking coverage from 1 to 9 files with zero errors. The changes focus on fixing type issues in utility modules and expanding pyright configuration to enable gradual adoption of static type checking across the codebase.

Key changes:

  • Fixed type errors in logging and exception handling utilities
  • Expanded pyright configuration to include 8 additional files
  • Updated documentation with GPU pipeline and dependency management guidance

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/interpretune/utils/logging.py Fixed potential None reference and added type ignore for deliberate function attribute assignment
src/interpretune/utils/exceptions.py Added explicit type annotations and fixed potential None access from frame inspection
pyproject.toml Expanded pyright include list from 1 to 9 files for incremental type checking adoption
.github/copilot-instructions.md Added documentation for Azure GPU pipeline, dependency regeneration, and type-checking caveats

# add the attribute to the function but don't overwrite if it already exists
rank_zero_only.rank = getattr(rank_zero_only, "rank", _get_rank() or 0)
# type: ignore[attr-defined] - we're deliberately adding an attribute to a function
rank_zero_only.rank = getattr(rank_zero_only, "rank", _get_rank() or 0) # type: ignore[attr-defined]
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The type ignore comment is duplicated. The comment at line 99 already explains the deliberate pattern, so the inline comment should just be # type: ignore[attr-defined] without the explanation.

Copilot uses AI. Check for mistakes.
@speediedan speediedan merged commit fb7d0a7 into main Aug 22, 2025
9 checks passed
@speediedan
Copy link
Copy Markdown
Owner

Next steps for subsequent PRs:

  1. Work through Phase 2 candidates with moderate complexity
  2. Create shared type definitions if patterns emerge
  3. Consider structural improvements for Phase 3 complex files
  4. Eventually expand to broader directories with wildcard includes
    @copilot continue with subsequent PRs per the described plan above in this PR. Re-open and keep open issue Address/cleanup pyright type issues throughout the codebase #137, creating sub-issues for each proposed phase of this type-checking enhancement.

@speediedan speediedan changed the title [WIP] Address/cleanup pyright type issues throughout the codebase Address/cleanup pyright type issues throughout the codebase: Phase 1 Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: build Build system and packaging area: ci Continuous integration area: docs Documentation files config Configuration file changes dependencies Dependency updates module: utils Utility functions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Address/cleanup pyright type issues throughout the codebase

3 participants