Skip to content

Fix mypy type errors (117 errors across 23 files) #2

@mortentabor

Description

@mortentabor

Summary

The CI runs mypy with strict = true and currently reports 63 errors across 12 source files. These are pre-existing type annotation issues — the Type Check job is set to continue-on-error: true so it doesn't block merging, but we should resolve them.

Error Breakdown by Category

no-any-return (10 errors)

Functions with return type annotations that return numpy/pandas values mypy can't verify.

File Lines
models/ols.py 74, 88, 110
models/ar.py 102, 112
models/adl.py 119, 129
results/base.py 143
tests/bai_perron.py 452, 459, 632
visualization/params.py 145

Fix: Add explicit casts or adjust return type annotations.

arg-type — numpy dtype mismatches (17 errors)

Numpy signedinteger vs float64 dtype mismatches when appending to typed lists, plus ArrayLike | None vs ArrayLike issues.

File Lines
models/ar.py 450, 455, 461, 610
models/adl.py 668, 674, 680, 790, 1032
rolling/ar.py 281, 286, 546, 551
rolling/adl.py 400, 406, 412, 443, 739, 745, 751, 782
tests/bai_perron.py 361
visualization/breaks.py 280

Fix: Use broader NDArray[np.floating[Any]] type annotations for lists, or cast arrays.

assignment — Figure type narrowing (6 errors)

ax.get_figure() returns Figure | SubFigure | None, but variables are typed as Figure.

File Lines
visualization/breaks.py 132, 254
visualization/diagnostics.py 267, 391
visualization/params.py 568

Fix: Use assert isinstance(fig, Figure) or handle the None/SubFigure cases.

unused-ignore (5 errors)

Stale # type: ignore comments that no longer match the actual error codes.

File Lines
visualization/breaks.py 132, 254
visualization/diagnostics.py 267, 391, 506

Fix: Remove or update the # type: ignore comments with correct error codes.

attr-defined (2 errors)

RegressionResultsBase has no attribute sigma.

File Lines
visualization/diagnostics.py 381, 627

Fix: Add sigma to RegressionResultsBase or narrow the type to a subclass that has it.

return-value (3 errors)

Incompatible return types (e.g., returning None where ndarray expected, complex vs floating array).

File Lines
models/ols.py 495
models/ar.py 78
models/adl.py 95

Fix: Adjust return type annotations or add runtime checks.

union-attr (1 error)

Accessing .get_figure() on Axes | Sequence[Axes].

File Line
visualization/params.py 568

Fix: Narrow the type before calling .get_figure().

call-overload (1 error)

pd.DataFrame constructor type mismatch with dict of ndarrays.

File Line
results/base.py 259

Fix: Adjust the dict value type or add a cast.

Files Affected

  1. src/regimes/models/ols.py (5 errors)
  2. src/regimes/models/ar.py (6 errors)
  3. src/regimes/models/adl.py (7 errors)
  4. src/regimes/rolling/ar.py (4 errors)
  5. src/regimes/rolling/adl.py (8 errors)
  6. src/regimes/tests/bai_perron.py (6 errors)
  7. src/regimes/results/base.py (3 errors)
  8. src/regimes/visualization/breaks.py (5 errors)
  9. src/regimes/visualization/diagnostics.py (7 errors)
  10. src/regimes/visualization/params.py (3 errors)

Suggested Approach

  1. Fix unused-ignore comments first (quick wins, reduces noise)
  2. Fix assignment / union-attr with type narrowing (assert isinstance(...))
  3. Fix no-any-return with explicit casts
  4. Fix arg-type dtype mismatches by broadening list type annotations
  5. Fix attr-defined by adding sigma to the base class or narrowing types
  6. Fix return-value issues with corrected annotations

CI Context

The Type Check job in CI uses continue-on-error: true so these errors are visible but non-blocking. Once resolved, we can remove continue-on-error to make mypy a hard gate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions