Repository navigation
Closed
Labels
Description
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 themThe same errors are appearing in newly created PRs as well, e.g. #34289, #34290, #34291.
Reacted by Olivier Grisel and Anne Beyer
Activity
ogrisel commentedon Jun 15, 2026
As anyone any idea on what change caused this?
MarcoGorelli commentedon Jun 15, 2026
the new pytest release from 2 days ago, probably
ogrisel commentedon Jun 15, 2026
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.
AnneBeyer commentedon Jun 15, 2026
Should I open a PR to pin
pytestto the min version similar toruffandmypyin the line mentioned above?If I understand correctly, @MarcoGorelli's fix would still become relevant once
9.1.0becomes the min version (currently it is7.1.2in_min_dependencies.py).ogrisel commentedon Jun 15, 2026
EDIT: comment moved to the PR.
betatim commentedon Jun 16, 2026
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 :-/
betatim commentedon Jun 16, 2026
#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.
MarcoGorelli commentedon Jun 16, 2026
pytest exports its types, so some typing improvements on their side surfaced some lists of classes with incompatible constructors (which mypy doesn't allow)