Skip to content

Improve mypy strictness settings #40

@flipbit03

Description

@flipbit03

Summary

The codebase currently uses lenient mypy settings. Analysis shows we can progressively enable stricter type checking.

Current Settings (Lenient)

disallow_untyped_calls = false
disallow_untyped_defs = false
disallow_untyped_decorators = false
check_untyped_defs = false
ignore_missing_imports = true
allow_redefinition = true

Analysis Results

Setting Source Errors Test Errors Effort
disallow_untyped_calls=true 0 0 Free
disallow_untyped_decorators=true 0 0 Free
ignore_missing_imports=false 0 0 Free
disallow_untyped_defs=true 7 71 Low (source) / High (tests)
check_untyped_defs=true 0 4 Low
Full --strict 17 92 Medium / High

Phases

Phase 1: Free Wins ✅ (Done in PR #39)

  • disallow_untyped_calls = true
  • disallow_untyped_decorators = true
  • ignore_missing_imports = false

Phase 2: Source Code Typing (Medium Effort, ~17 fixes)

Files affected:

  • handler/rewriter/__init__.py - 10 errors (7 type-arg, 3 no-untyped-def)
  • mixin.py - 4 errors (1 type-arg, 3 no-untyped-def)
  • handler/sqlalchemy_easy_softdelete.py - 1 error (no-untyped-def)
  • hook.py - 1 error (no-untyped-def)

Work needed:

  • Add return type -> bool to hook.py:match_name
  • Add type hints to mixin.py nested functions
  • Add return type to soft_delete_execute function
  • Add type parameters to generic types (Select[Any], CompoundSelect[Any], etc.)

Phase 3: Test Typing (High Effort, Optional)

Use per-module config to exempt tests from strict checking:

[mypy-tests.*]
disallow_untyped_defs = false

Or fix all 71 test functions to have -> None return types.

Commands to Test

# Current baseline
uv run mypy sqlalchemy_easy_softdelete tests/

# Test strict mode on source only
uv run mypy --strict sqlalchemy_easy_softdelete/

# Test individual settings
uv run mypy --disallow-untyped-defs sqlalchemy_easy_softdelete tests/
uv run mypy --check-untyped-defs sqlalchemy_easy_softdelete tests/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions