Skip to content

Add comprehensive type hint coverage analysis tooling with mypy integration - #1271

Merged
bact merged 8 commits into
devfrom
copilot/scan-repository-type-hints
Feb 3, 2026
Merged

Add comprehensive type hint coverage analysis tooling with mypy integration#1271
bact merged 8 commits into
devfrom
copilot/scan-repository-type-hints

Conversation

Copilot AI commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

What do these changes do

Adds AST-based analysis tooling to audit type hint coverage across the codebase. Provides actionable data on 720 functions/methods categorized by completeness, scope, internal references, test suite mapping, priority, and mypy error counts.

Deliverables:

  • build_tools/analysis/type_hint_analyzer.py - Main analyzer using Python AST with mypy integration and command-line arguments
  • build_tools/analysis/generate_csv.py - CSV report generator with command-line arguments
  • build_tools/analysis/output/ - Output directory containing JSON and CSV data files (submodule stats with mypy errors, functions without/incomplete hints)
  • TYPE_HINT_COMPLETE_REPORT.md - Executive summary
  • TYPE_HINT_ANALYSIS.md - Detailed technical breakdown
  • TYPE_HINT_QUICKSTART.md - Quick reference
  • .markdownlintrc - Markdown linting configuration

Key Metrics:

  • 82.22% functions have complete type hints (592/720)
  • 7.78% incomplete (56/720)
  • 10.00% no hints (72/720)
  • 9 submodules at 100% coverage
  • No high-priority gaps (all critical public APIs typed)
  • Mypy errors range from 6-9 per submodule (most have 6)

Priority Classification:

  • Maps functions to test suites (core/compact/extra/noauto)
  • Counts internal references (991 to 0)
  • Assigns priority based on scope + usage + test coverage
  • Identifies 94 medium-priority items for improvement

Mypy Integration:

  • Runs mypy on each submodule to count type-related errors
  • Errors included in console output, JSON data, CSV files, and markdown reports
  • Provides complementary view: type hint completeness vs. type consistency

Local Execution Support:

  • Scripts auto-detect repository root (no hardcoded paths)
  • Command-line arguments for flexible configuration:
    • type_hint_analyzer.py --output-dir DIR (default: ./output)
    • generate_csv.py --input FILE --output-dir DIR
  • No dependency on /tmp directory
  • Works seamlessly on Windows, macOS, and Linux

Submodules needing attention: transliterate (48%), classify (20%), el (20%), chat (25%), wangchanberta (44%), coref (40%)

What was wrong

No visibility into type hint coverage across the codebase. Unable to systematically identify gaps, prioritize type safety improvements, or track mypy errors per submodule. Previous analysis tools were not suitable for local development (hardcoded paths, /tmp dependency).

How this fixes it

Implements comprehensive analysis that:

  1. Parses all Python files using ast module
  2. Analyzes function signatures for parameter and return type hints
  3. Categorizes by completeness (complete/incomplete/none)
  4. Maps to project structure (submodule, scope, test suite)
  5. Calculates internal reference frequency via text search
  6. Assigns priority (high: public + >10 refs + core/compact tests; medium: public + 3-10 refs; low: private or rare)
  7. Runs mypy on each submodule to count type-related errors
  8. Generates reports in markdown, CSV, and JSON formats
  9. All markdown reports validated with markdownlint for proper formatting
  10. Auto-detects repository root for portable execution across different environments
  11. Accepts command-line arguments for flexible output configuration
  12. Outputs to build_tools/analysis/output/ directory

Analysis is repeatable via python3 build_tools/analysis/type_hint_analyzer.py from any location in the repository.

Your checklist for this pull request

  • Passed code styles and structures
  • Passed code linting checks and unit test
  • All markdown files pass markdownlint validation
  • Scripts work on local machines without hardcoded paths
  • Command-line arguments implemented with help documentation
Original prompt

Scan the whole repository.
List each of the function/class without type hints or has incomplete type hints.

Categorize them by submodules, how frequent it got referenced internally within the package, public or private scope, which teste suite it is in (core, compact, extra, noauto, outside the former four), priority.

Report percentage of function/class with complete type hints, with incomplete type hints, without type hints at all.


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

Copilot AI and others added 4 commits February 3, 2026 15:01
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Co-authored-by: bact <128572+bact@users.noreply.github.com>
Copilot AI changed the title [WIP] Scan repository for functions and classes without complete type hints Add comprehensive type hint coverage analysis tooling Feb 3, 2026
Copilot AI requested a review from bact February 3, 2026 15:07
@bact

bact commented Feb 3, 2026

Copy link
Copy Markdown
Member

@copilot Cool.

  1. Add number of mypy errors of each submodule
  2. Review the analysis code, make sure the generated Markdown is well-formed according to markdownlint rules at https://github.com/markdownlint/markdownlint/blob/main/docs/RULES.md

Co-authored-by: bact <128572+bact@users.noreply.github.com>

Copilot AI commented Feb 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Cool.

  1. Add number of mypy errors of each submodule
    ...

Done! Both items addressed in commit f59b774:

  1. ✅ Added mypy error counts for each submodule - now included in console output, JSON data, CSV files, and all markdown reports
  2. ✅ Fixed all markdown linting issues - all reports now pass markdownlint validation with proper table formatting, line wrapping, and structure

The analyzer now runs mypy on each submodule during analysis. Errors range from 6-9 per module (most have 6, summarize has 9, word_vector has 8, tag has 7).

Copilot AI changed the title Add comprehensive type hint coverage analysis tooling Add comprehensive type hint coverage analysis tooling with mypy integration Feb 3, 2026
@bact

bact commented Feb 3, 2026

Copy link
Copy Markdown
Member

@copilot I have moved the analyzer output files from docs/ to build_tools/analysis/output.
Please under the scripts to use this new destination.

Also update the script to be able to run on local machine (avoid using /tmp directory) and accept more friendly command line argument (keep it minimal).

Co-authored-by: bact <128572+bact@users.noreply.github.com>

Copilot AI commented Feb 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot I have moved the analyzer output files from docs/ to build_tools/analysis/output.
Please under the scripts to use this new destination.

...

Done in commit c3f1345:

  1. ✅ Updated scripts to use build_tools/analysis/output/ instead of /tmp and docs/
  2. ✅ Added command-line arguments for flexible path configuration:
    • type_hint_analyzer.py --output-dir DIR (default: ./output)
    • generate_csv.py --input FILE --output-dir DIR
  3. ✅ Scripts now auto-detect repository root for local execution (no hardcoded paths)
  4. ✅ Both scripts provide --help for usage information

Scripts now work seamlessly on local machines without requiring /tmp directory or absolute paths.

@sonarqubecloud

sonarqubecloud Bot commented Feb 3, 2026

Copy link
Copy Markdown

@bact
bact marked this pull request as ready for review February 3, 2026 15:56
@bact
bact merged commit 9e2ea22 into dev Feb 3, 2026
6 checks passed
@bact
bact deleted the copilot/scan-repository-type-hints branch February 3, 2026 15:57
@bact bact added the documentation improve documentation and test cases label Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation improve documentation and test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants