pygraphistry icon indicating copy to clipboard operation
pygraphistry copied to clipboard

Incremental MyPy strictness adoption

Open lmeyerov opened this issue 2 months ago • 0 comments

Background

Issue #801 identified that our MyPy configuration is very permissive. While the critical None dereference bugs have been fixed in PR #804, we should incrementally adopt stricter type checking to catch more issues early.

Current State

Our mypy.ini configuration is minimal:

  • No strict mode flags enabled
  • Tests completely excluded: exclude = graph_vector_pb2|versioneer|_version|graphistry/tests
  • All external dependencies set to ignore_missing_imports = True
  • python_version = 3.8 (outdated - should be 3.9 per CI minimum)

Proposed Incremental Approach

Enable strict flags one at a time, one module at a time to avoid overwhelming failures.

Phase 1: Enable warn_unused_ignores globally

  • Flag: warn_unused_ignores = True
  • Impact: Identifies type ignore comments that are no longer needed
  • Action: Clean up unused # type: ignore comments

Phase 2: Enable warn_return_any for core modules

  • Flag: warn_return_any = True
  • Scope: Start with graphistry/compute/ modules
  • Impact: Requires explicit return type annotations
  • Action: Add return type hints to functions in compute layer

Phase 3: Enable check_untyped_defs for tested modules

  • Flag: check_untyped_defs = True
  • Scope: Start with modules that have good test coverage
  • Impact: Type checks function bodies even without annotations
  • Action: Add type hints to function signatures

Phase 4: Enable no_implicit_optional globally

  • Flag: no_implicit_optional = True
  • Impact: Requires explicit Optional[...] instead of implicit None defaults
  • Action: Update function signatures with Optional types

Phase 5: Enable warn_redundant_casts globally

  • Flag: warn_redundant_casts = True
  • Impact: Identifies unnecessary cast() calls
  • Action: Remove redundant casts (like the one fixed in #804)

Phase 6: Include tests directory

  • Remove tests from exclude pattern
  • Start with compute tests that have good type coverage
  • Gradually expand to other test directories

Success Criteria

  • Each phase is a separate PR
  • No regressions in existing functionality
  • Each PR reduces technical debt and improves type safety
  • CI passes with new flags enabled

Non-Goals

  • Full strict mode all at once (would create 100s of errors)
  • 100% type coverage immediately
  • Breaking changes to public API

Related Issues

  • #801 - Original issue identifying MyPy configuration gaps
  • #804 - Fixed critical None dereference bugs (merged)

🤖 Generated with Claude Code

lmeyerov avatar Oct 19 '25 02:10 lmeyerov