Skip to content

CI mypy reports type errors in unrelated PRs #34292

Closed

Description

@virchan

First noticed in ba12cf9 and its revert ae8f42a, where the CI failed because mypy reported the following errors despite the changes being unrelated:

Error message
### Running mypy ###

sklearn/neighbors/tests/test_graph.py:84: error: List item 0 has incompatible type "type[KNeighborsTransformer]"; expected "type[NeighborsBase]"  [list-item]
sklearn/svm/tests/test_svm.py:631: error: List item 1 has incompatible type "tuple[type[NuSVC], str]"; expected "tuple[type[BaseSVC], str]"  [list-item]
sklearn/svm/tests/test_svm.py:650: error: List item 1 has incompatible type "tuple[type[NuSVC], dict[str, list[float]]]"; expected "tuple[type[BaseSVC], dict[str, list[float]]]"  [list-item]
sklearn/svm/tests/test_svm.py:1252: error: List item 0 has incompatible type "type[SVC]"; expected "type[BaseSVC]"  [list-item]
sklearn/svm/tests/test_svm.py:1267: error: List item 0 has incompatible type "type[SVC]"; expected "type[BaseSVC]"  [list-item]
sklearn/svm/tests/test_svm.py:1520: error: List item 1 has incompatible type "tuple[type[NuSVC], str]"; expected "tuple[type[BaseSVC], str]"  [list-item]
sklearn/svm/tests/test_svm.py:1529: error: List item 0 has incompatible type "type[SVC]"; expected "type[BaseSVC]"  [list-item]
sklearn/neighbors/tests/test_neighbors.py:335: error: List item 0 has incompatible type "type[KNeighborsClassifier]"; expected "type[NeighborsBase]"  [list-item]
sklearn/neighbors/tests/test_neighbors.py:336: error: List item 1 has incompatible type "type[KNeighborsRegressor]"; expected "type[NeighborsBase]"  [list-item]
sklearn/linear_model/tests/test_least_angle.py:209: error: List item 0 has incompatible type "type[Lars]"; expected "type[Lars]"  [list-item]
sklearn/linear_model/tests/test_least_angle.py:209: error: List item 1 has incompatible type "type[LarsCV]"; expected "type[Lars]"  [list-item]
sklearn/ensemble/tests/test_stacking.py:566: error: List item 1 has incompatible type "tuple[type[StackingRegressor], type[DummyRegressor], str, LinearRegression, Any, Any]"; expected "tuple[ABCMeta, type[BaseEstimator], str, BaseEstimator, Any, Any]"  [list-item]
sklearn/ensemble/tests/test_gradient_boosting.py:1351: error: List item 2 has incompatible type "tuple[type[GradientBoostingRegressor], Any, type[DummyRegressor]]"; expected "tuple[ABCMeta, Any, type[BaseEstimator]]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_warm_start.py:32: error: List item 1 has incompatible type "tuple[type[HistGradientBoostingRegressor], Any, Any]"; expected "tuple[type[BaseHistGradientBoosting], Any, Any]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_warm_start.py:54: error: List item 1 has incompatible type "tuple[type[HistGradientBoostingRegressor], Any, Any]"; expected "tuple[type[BaseHistGradientBoosting], Any, Any]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_warm_start.py:80: error: List item 1 has incompatible type "tuple[type[HistGradientBoostingRegressor], Any, Any]"; expected "tuple[type[BaseHistGradientBoosting], Any, Any]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_warm_start.py:108: error: List item 1 has incompatible type "tuple[type[HistGradientBoostingRegressor], Any, Any]"; expected "tuple[type[BaseHistGradientBoosting], Any, Any]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_warm_start.py:137: error: List item 1 has incompatible type "tuple[type[HistGradientBoostingRegressor], Any, Any]"; expected "tuple[type[BaseHistGradientBoosting], Any, Any]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_warm_start.py:157: error: List item 1 has incompatible type "tuple[type[HistGradientBoostingRegressor], Any, Any]"; expected "tuple[type[BaseHistGradientBoosting], Any, Any]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_warm_start.py:183: error: List item 1 has incompatible type "tuple[type[HistGradientBoostingRegressor], Any, Any]"; expected "tuple[type[BaseHistGradientBoosting], Any, Any]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py:66: error: List item 1 has incompatible type "tuple[type[HistGradientBoostingRegressor], Any, Any]"; expected "tuple[type[BaseHistGradientBoosting], Any, Any]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py:953: error: List item 1 has incompatible type "tuple[type[HistGradientBoostingRegressor], HalfSquaredError, Any, Any]"; expected "tuple[type[BaseHistGradientBoosting], BaseLoss, Any, Any]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py:970: error: List item 1 has incompatible type "tuple[type[HistGradientBoostingRegressor], Any, Any]"; expected "tuple[type[BaseHistGradientBoosting], Any, Any]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py:1461: error: List item 1 has incompatible type "tuple[type[HistGradientBoostingRegressor], Any]"; expected "tuple[type[BaseHistGradientBoosting], Any]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py:1554: error: List item 0 has incompatible type "type[HistGradientBoostingClassifier]"; expected "type[BaseHistGradientBoosting]"  [list-item]
sklearn/ensemble/_hist_gradient_boosting/tests/test_gradient_boosting.py:1609: error: List item 0 has incompatible type "type[HistGradientBoostingClassifier]"; expected "type[BaseHistGradientBoosting]"  [list-item]
sklearn/model_selection/tests/test_split.py:430: error: List item 0 has incompatible type "type[StratifiedKFold]"; expected "type[_BaseKFold]"  [list-item]
sklearn/model_selection/tests/test_split.py:457: error: List item 0 has incompatible type "type[StratifiedKFold]"; expected "type[_BaseKFold]"  [list-item]
sklearn/model_selection/tests/test_split.py:499: error: List item 0 has incompatible type "type[StratifiedKFold]"; expected "type[_BaseKFold]"  [list-item]
sklearn/model_selection/tests/test_split.py:542: error: List item 0 has incompatible type "type[KFold]"; expected "type[_BaseKFold]"  [list-item]
sklearn/model_selection/tests/test_split.py:542: error: List item 1 has incompatible type "type[StratifiedKFold]"; expected "type[_BaseKFold]"  [list-item]
sklearn/model_selection/tests/test_split.py:1660: error: List item 0 has incompatible type "type[GroupKFold]"; expected "type[_BaseKFold]"  [list-item]
Found 32 errors in 9 files (checked 596 source files)
Problems detected by mypy, please fix them

The same errors are appearing in newly created PRs as well, e.g. #34289, #34290, #34291.

Activity

  1. added
    Needs Investigation
    on Jun 15, 2026
  2. ogrisel commented on Jun 15, 2026

    @ogrisel
    Member

    As anyone any idea on what change caused this?

  3. MarcoGorelli commented on Jun 15, 2026

    @MarcoGorelli
    Contributor

    As anyone any idea on what change caused this?

    the new pytest release from 2 days ago, probably

  4. ogrisel commented on Jun 15, 2026

    @ogrisel
    Member

    Indeed, we do not lock the pytest version in the linting CI workflow. This is probably an oversight:

    https://github.com/scikit-learn/scikit-learn/blob/main/.github/workflows/lint.yml#L37

    I think we should.

  5. AnneBeyer commented on Jun 15, 2026

    @AnneBeyer
    Member

    Should I open a PR to pin pytest to the min version similar to ruff and mypy in the line mentioned above?
    If I understand correctly, @MarcoGorelli's fix would still become relevant once 9.1.0 becomes the min version (currently it is 7.1.2 in _min_dependencies.py).

  6. ogrisel commented on Jun 15, 2026

    @ogrisel
    Member

    EDIT: comment moved to the PR.

  7. removed
    Needs Investigation
    on Jun 15, 2026
  8. betatim commented on Jun 16, 2026

    @betatim
    Member

    For my education, why would changing the pytest version make mypy unhappy? Is it because the way mypy detects what files were changed??

    I'm happy with the fix but confused why this happened/what the interaction is :-/

  9. betatim commented on Jun 16, 2026

    @betatim
    Member

    #34300 (comment) This is a good discussion of the fix, but it still has me wondering why changing the pytest version made this "type annotation bug" appear.

  10. MarcoGorelli commented on Jun 16, 2026

    @MarcoGorelli
    Contributor

    pytest exports its types, so some typing improvements on their side surfaced some lists of classes with incompatible constructors (which mypy doesn't allow)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions