Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all reportAssertTypeFailure+reportGeneralTypeIssues #339

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ extra-standard-library = [

[tool.pyright]
exclude = ["build", ".git"]
stubPath = "./stubs"
# Target oldest supported Python version
pythonversion = "3.9"
typeCheckingMode = "standard"
Expand All @@ -108,10 +109,6 @@ reportSelfClsParameterName = false
# Not an error by default in standard mode
reportUnsupportedDunderAll = "error"

# Error reports to fix in code
reportAssertTypeFailure = "none" # TODO
reportGeneralTypeIssues = "none" # TODO

[tool.mypy]
# Target oldest supported Python version
python_version = "3.9"
Expand Down
3 changes: 2 additions & 1 deletion stubs/matplotlib/figure.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class FigureBase(Artist):
def add_artist(self, artist: Artist, clip: bool = False) -> Artist: ...
def add_axes(self, *args, **kwargs) -> Axes: ...
@overload
def add_subplot(self, *args, projection: Literal["3d"], **kwargs) -> Axes3D: ...
# Decorators make this look like a callable. This is an upstream issue
def add_subplot(self, *args, projection: Literal["3d"], **kwargs) -> Axes3D: ... # pyright: ignore[reportGeneralTypeIssues]
@overload
def add_subplot(self, *args, projection: Literal["aitoff"], **kwargs) -> AitoffAxes: ...
@overload
Expand Down
1 change: 0 additions & 1 deletion stubs/sklearn/cluster/_kmeans.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ from ..utils._param_validation import (
)
from ..utils._readonly_array_wrapper import ReadonlyArrayWrapper as ReadonlyArrayWrapper
from ..utils.extmath import row_norms as row_norms, stable_cumsum as stable_cumsum
from ..utils.fixes import threadpool_info as threadpool_info, threadpool_limits as threadpool_limits
from ..utils.sparsefuncs import mean_variance_axis as mean_variance_axis
from ..utils.sparsefuncs_fast import assign_rows_csr as assign_rows_csr
from ..utils.validation import check_is_fitted as check_is_fitted
Expand Down
1 change: 0 additions & 1 deletion stubs/sklearn/conftest.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ from .datasets import (
fetch_rcv1 as fetch_rcv1,
)
from .tests import random_seed as random_seed
from .utils.fixes import parse_version as parse_version

dataset_fetchers: dict = ...

Expand Down
1 change: 0 additions & 1 deletion stubs/sklearn/cross_decomposition/_pls.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ from ..exceptions import ConvergenceWarning as ConvergenceWarning
from ..utils import check_array as check_array, check_consistent_length as check_consistent_length
from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions
from ..utils.extmath import svd_flip as svd_flip
from ..utils.fixes import parse_version as parse_version, sp_version as sp_version
from ..utils.validation import FLOAT_DTYPES as FLOAT_DTYPES, check_is_fitted as check_is_fitted

PLSSVD_Self = TypeVar("PLSSVD_Self", bound="PLSSVD")
Expand Down
1 change: 0 additions & 1 deletion stubs/sklearn/linear_model/_quantile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ from .._typing import ArrayLike, Float, MatrixLike
from ..base import BaseEstimator, RegressorMixin
from ..exceptions import ConvergenceWarning as ConvergenceWarning
from ..utils._param_validation import Hidden as Hidden, Interval as Interval, StrOptions as StrOptions
from ..utils.fixes import parse_version as parse_version, sp_version as sp_version
from ._base import LinearModel

QuantileRegressor_Self = TypeVar("QuantileRegressor_Self", bound="QuantileRegressor")
Expand Down
1 change: 0 additions & 1 deletion stubs/sklearn/manifold/_spectral_embedding.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ from ..metrics.pairwise import rbf_kernel as rbf_kernel
from ..neighbors import NearestNeighbors as NearestNeighbors, kneighbors_graph as kneighbors_graph
from ..utils import check_array as check_array, check_random_state as check_random_state, check_symmetric as check_symmetric
from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions
from ..utils.fixes import lobpcg

SpectralEmbedding_Self = TypeVar("SpectralEmbedding_Self", bound="SpectralEmbedding")

Expand Down
1 change: 0 additions & 1 deletion stubs/sklearn/metrics/pairwise.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ from ..utils import (
is_scalar_nan as is_scalar_nan,
)
from ..utils.extmath import row_norms as row_norms, safe_sparse_dot as safe_sparse_dot
from ..utils.fixes import parse_version as parse_version, sp_version as sp_version
from ..utils.parallel import Parallel as Parallel, delayed as delayed
from ..utils.validation import check_non_negative as check_non_negative
from ._pairwise_distances_reduction import ArgKmin as ArgKmin
Expand Down
1 change: 0 additions & 1 deletion stubs/sklearn/neighbors/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ from ..metrics._pairwise_distances_reduction import ArgKmin as ArgKmin, RadiusNe
from ..metrics.pairwise import PAIRWISE_DISTANCE_FUNCTIONS as PAIRWISE_DISTANCE_FUNCTIONS
from ..utils import check_array as check_array, gen_even_slices as gen_even_slices
from ..utils._param_validation import Interval as Interval, StrOptions as StrOptions
from ..utils.fixes import parse_version as parse_version, sp_version as sp_version
from ..utils.multiclass import check_classification_targets as check_classification_targets
from ..utils.parallel import Parallel as Parallel, delayed as delayed
from ..utils.validation import check_is_fitted as check_is_fitted, check_non_negative as check_non_negative
Expand Down
9 changes: 6 additions & 3 deletions stubs/sklearn/utils/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ from scipy.sparse import issparse as issparse
from .. import get_config as get_config
from .._typing import ArrayLike, Int, MatrixLike
from ..exceptions import DataConversionWarning as DataConversionWarning
from . import metadata_routing
from ._bunch import Bunch as Bunch
from ._estimator_html_repr import estimator_html_repr as estimator_html_repr
from .class_weight import compute_class_weight as compute_class_weight, compute_sample_weight as compute_sample_weight
from .deprecation import deprecated as deprecated
from .discovery import all_estimators as all_estimators
from .fixes import parse_version as parse_version, threadpool_info as threadpool_info
from .murmurhash import murmurhash3_32 as murmurhash3_32
from .validation import (
as_float_array as as_float_array,
Expand Down Expand Up @@ -59,17 +59,20 @@ __all__ = [
"check_scalar",
"indexable",
"check_symmetric",
"indices_to_mask",
"deprecated",
"parallel_backend",
"register_parallel_backend",
"resample",
"shuffle",
"check_matplotlib_support",
"all_estimators",
"DataConversionWarning",
"estimator_html_repr",
"Bunch",
"metadata_routing",
"safe_sqr",
"safe_mask",
"gen_batches",
"gen_even_slices",
]

IS_PYPY = ...
Expand Down
2 changes: 0 additions & 2 deletions stubs/sklearn/utils/_show_versions.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import platform
import sys

from ..utils.fixes import threadpool_info as threadpool_info

# License: BSD 3 clause

def show_versions(): ...
5 changes: 3 additions & 2 deletions stubs/sklearn/utils/_testing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ from numpy.testing import (
from .._typing import ArrayLike, Float, Int, MatrixLike
from ..metrics import accuracy_score as accuracy_score, r2_score as r2_score
from . import IS_PYPY as IS_PYPY
from .fixes import threadpool_info as threadpool_info
from .multiclass import check_classification_targets as check_classification_targets
from .validation import check_array as check_array, check_is_fitted as check_is_fitted, check_X_y as check_X_y

Expand All @@ -64,7 +63,8 @@ __all__ = [
"assert_array_less",
"assert_approx_equal",
"assert_allclose",
"assert_run_python_script",
"assert_run_python_script_without_output",
"assert_no_warnings",
"SkipTest",
]

Expand Down Expand Up @@ -116,6 +116,7 @@ class TempMemmap:
def __exit__(self, exc_type, exc_val, exc_tb): ...

def create_memmap_backed_data(data, mmap_mode: str = "r", return_folder: bool = False, aligned: bool = False): ...
def assert_run_python_script_without_output(source_code, pattern=".+", timeout=60) -> None: ...
def check_docstring_parameters(func: Callable, doc: None | str = None, ignore: Sequence | None = None) -> ndarray: ...
def assert_run_python_script(source_code: str, timeout: Int = 60): ...
def raises(
Expand Down
1 change: 0 additions & 1 deletion stubs/sklearn/utils/estimator_checks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ from ..utils._param_validation import (
generate_invalid_param_val as generate_invalid_param_val,
make_constraint as make_constraint,
)
from ..utils.fixes import parse_version as parse_version, sp_version as sp_version
from ..utils.validation import check_is_fitted as check_is_fitted
from . import IS_PYPY as IS_PYPY, is_scalar_nan as is_scalar_nan, shuffle as shuffle
from ._param_validation import Interval as Interval
Expand Down
60 changes: 20 additions & 40 deletions stubs/sklearn/utils/fixes.pyi
Original file line number Diff line number Diff line change
@@ -1,43 +1,23 @@
import sys
from importlib import resources as resources
from typing import Literal, Mapping

import numpy as np
import scipy
import scipy.stats
import sklearn
import threadpoolctl
from numpy import percentile as percentile
from scipy.linalg import eigh as _eigh
from scipy.optimize._linesearch import ( # explicitly re-exported
line_search_wolfe1 as line_search_wolfe1,
line_search_wolfe2 as line_search_wolfe2,
)
from threadpoolctl import _ThreadpoolLimiter

from ..externals._lobpcg import lobpcg as lobpcg
from ..externals._packaging.version import parse as parse_version
from .deprecation import deprecated
from .parallel import delayed
# Version-based re-exports
from numpy.exceptions import ComplexWarning as ComplexWarning, VisibleDeprecationWarning as VisibleDeprecationWarning
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simply regenerated this file

from scipy.integrate import trapezoid as trapezoid
from scipy.optimize._linesearch import line_search_wolfe1 as line_search_wolfe1, line_search_wolfe2 as line_search_wolfe2
from scipy.sparse.csgraph import laplacian as laplacian

np_version = ...
np_base_version = ...
sp_version = ...

class loguniform(scipy.stats.reciprocal): ...

def threadpool_limits(
limits: None | Mapping | str | int = None,
user_api: None | Literal["blas", "openmp"] = None,
) -> _ThreadpoolLimiter: ...

threadpool_limits.__doc__ = ...

def threadpool_info() -> list[dict[str, int | str] | dict[str, str | None | int]]: ...

threadpool_info.__doc__ = ...

@deprecated(
"The function `delayed` has been moved from `sklearn.utils.fixes` to "
"`sklearn.utils.parallel`. This import path will be removed in 1.5."
)
def delayed(function): ...
sp_base_version = ...
CSR_CONTAINERS = ...
CSC_CONTAINERS = ...
COO_CONTAINERS = ...
LIL_CONTAINERS = ...
DOK_CONTAINERS = ...
BSR_CONTAINERS = ...
DIA_CONTAINERS = ...
SPARRAY_PRESENT: bool
SPARSE_ARRAY_PRESENT: bool
percentile = ...

def pd_fillna(pd, frame): ...
def tarfile_extractall(tarfile, path) -> None: ...
4 changes: 3 additions & 1 deletion stubs/sympy-stubs/core/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ from sympy.core.function import (
expand_trig,
nfloat,
)
from sympy.core.intfunc import integer_log, integer_nthroot
from sympy.core.intfunc import integer_log, integer_nthroot, num_digits, trailing
from sympy.core.kind import BooleanKind, NumberKind, UndefinedKind
from sympy.core.mod import Mod
from sympy.core.mul import Mul, prod
Expand Down Expand Up @@ -120,6 +120,8 @@ __all__ = [
"Pow",
"integer_nthroot",
"integer_log",
"num_digits",
"trailing",
"Mul",
"prod",
"Add",
Expand Down
2 changes: 1 addition & 1 deletion stubs/sympy-stubs/matrices/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from sympy.matrices.common import NonSquareMatrixError, ShapeError
from sympy.matrices.dense import (
GramSchmidt,
MutableDenseMatrix,
Expand All @@ -23,6 +22,7 @@ from sympy.matrices.dense import (
wronskian,
zeros,
)
from sympy.matrices.exceptions import NonSquareMatrixError, ShapeError
from sympy.matrices.expressions import (
Adjoint,
BlockDiagMatrix,
Expand Down
2 changes: 0 additions & 2 deletions stubs/sympy-stubs/ntheory/factor_.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def smoothness(n) -> tuple[Literal[1], Literal[1]] | tuple[Any, Any]: ...
def smoothness_p(
n, m=..., power=..., visual=...
) -> str | dict[Any, Any] | tuple[Any, ...] | tuple[int, list[tuple[Any, tuple[Any, ...]]]] | LiteralString: ...
def trailing(n) -> int: ...
def multiplicity(p, n) -> int: ...
def multiplicity_in_factorial(p, n): ...
def perfect_power(n, candidates=..., big=..., factor=...): ...
Expand Down Expand Up @@ -130,7 +129,6 @@ def mersenne_prime_exponent(
82589933,
]: ...
def is_perfect(n) -> bool | None: ...
def is_mersenne_prime(n) -> bool: ...
def abundance(n): ...
def is_abundant(n) -> bool: ...
def is_deficient(n) -> bool: ...
Expand Down
1 change: 1 addition & 0 deletions stubs/sympy-stubs/ntheory/primetest.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ def mr(n, bases) -> bool: ...
def is_lucas_prp(n) -> bool: ...
def is_strong_lucas_prp(n) -> bool: ...
def is_extra_strong_lucas_prp(n) -> bool: ...
def is_mersenne_prime(n) -> bool: ...
def isprime(n) -> bool: ...
def is_gaussian_prime(num) -> bool: ...
2 changes: 1 addition & 1 deletion stubs/sympy-stubs/polys/domains/gmpyintegerring.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GMPYIntegerRing(IntegerRing):
dtype = GMPYInteger
zero = dtype(0)
one = dtype(1)
tp = type(one)
tp: type[dtype]
alias = ...
def __init__(self) -> None: ...
def to_sympy(self, a) -> Integer: ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/sympy-stubs/polys/domains/gmpyrationalfield.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GMPYRationalField(RationalField):
dtype = GMPYRational
zero = dtype(0)
one = dtype(1)
tp = type(one)
tp: type[dtype]
alias = ...
def __init__(self) -> None: ...
def get_ring(self) -> Any: ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/sympy-stubs/polys/domains/integerring.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IntegerRing(Ring, CharacteristicZero, SimpleDomain): # type: ignore
dtype = MPZ
zero = dtype(0)
one = dtype(1)
tp = type(one)
tp: type[dtype]
is_ZZ = ...
is_Numerical = ...
is_PID = ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/sympy-stubs/polys/domains/rationalfield.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RationalField(Field, CharacteristicZero, SimpleDomain):
dtype = MPQ
zero = dtype(0)
one = dtype(1)
tp = type(one)
tp: type[dtype]
def __init__(self) -> None: ...
def get_ring(self) -> Any: ...
def to_sympy(self, a) -> Rational | Integer: ...
Expand Down
2 changes: 1 addition & 1 deletion utils/validate_stubs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/python
from __future__ import annotations

__doc__ = """Validate Stubs.

Expand All @@ -14,7 +15,6 @@
--function=<f> Restrict to the named function (or method if used with --class).
--class=<c> Restrict to the named class.
"""
from __future__ import annotations

import importlib
import importlib.machinery
Expand Down
Loading