Skip to content

Commit 76ca370

Browse files
authored
Disallow blanket ignores and remove unused noqa (#382)
1 parent d4aa725 commit 76ca370

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+183
-371
lines changed

pyproject.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,13 @@ target-version = "py39"
5656
extend-select = [
5757
"FA", # flake8-future-annotations
5858
"I", # isort
59+
"PGH", # pygrep-hooks
60+
"PGH", # pygrep-hooks and blanket-noqa
61+
"PIE790", # unnecessary-placeholder
5962
"PYI", # flake8-pyi
63+
"RUF", # Ruff-specific and unused-noqa
6064
"UP", # pyupgrade
6165
"W", # pycodestyle Warning
62-
"PIE790", # unnecessary-placeholder
6366
]
6467
ignore = [
6568
###
@@ -82,6 +85,11 @@ ignore = [
8285

8386
[tool.ruff.lint.per-file-ignores]
8487
"*.pyi" = [
88+
# Ruff 0.8.0 added sorting of __all__ and __slots_.
89+
# There is no consensus in typeshed on whether they want to apply this to stubs, so keeping the status quo.
90+
# See https://github.com/python/typeshed/pull/13108
91+
"RUF022", # `__all__` is not sorted
92+
"RUF023", # `{}.__slots__` is not sorted
8593
###
8694
# Rules that are out of the control of stub authors:
8795
###

stubs/matplotlib/backends/backend_qt.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class FigureCanvasQT(QtWidgets.QWidget, FigureCanvasBase):
4747
def keyPressEvent(self, event) -> None: ...
4848
def keyReleaseEvent(self, event) -> None: ...
4949
def resizeEvent(self, event) -> None: ...
50-
def sizeHint(self) -> QtCore.QSize: ... # type: ignore
51-
def minumumSizeHint(self) -> QtCore.QSize: ... # type: ignore
50+
def sizeHint(self) -> QtCore.QSize: ... # type: ignore[name-defined]
51+
def minumumSizeHint(self) -> QtCore.QSize: ... # type: ignore[name-defined]
5252
def flush_events(self) -> None: ...
5353
def start_event_loop(self, timeout=...) -> None: ...
5454
def stop_event_loop(self, event=...) -> None: ...
@@ -58,7 +58,7 @@ class FigureCanvasQT(QtWidgets.QWidget, FigureCanvasBase):
5858
def drawRectangle(self, rect) -> None: ...
5959

6060
class MainWindow(QtWidgets.QMainWindow):
61-
closing: QtCore.Signal = ... # type: ignore
61+
closing: QtCore.Signal = ... # type: ignore[name-defined]
6262
def closeEvent(self, event) -> None: ...
6363

6464
class FigureManagerQT(FigureManagerBase):
@@ -71,7 +71,7 @@ class FigureManagerQT(FigureManagerBase):
7171
def set_window_title(self, title) -> None: ...
7272

7373
class NavigationToolbar2QT(NavigationToolbar2, QtWidgets.QToolBar):
74-
message: QtCore.Signal = ... # type: ignore
74+
message: QtCore.Signal = ... # type: ignore[name-defined]
7575
toolitems: list = ...
7676
def __init__(self, canvas, parent=..., coordinates=...) -> None: ...
7777
def edit_parameters(self) -> None: ...

stubs/networkx/algorithms/approximation/kcomponents.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
import itertools
2-
from collections import defaultdict
31
from collections.abc import Mapping
42
from functools import cached_property
53

64
from ...classes.graph import Graph
7-
from ...exception import NetworkXError
8-
from ...utils import not_implemented_for
9-
from . import local_node_connectivity
105

116
__all__ = ["k_components"]
127

@@ -17,7 +12,7 @@ class _AntiGraph(Graph):
1712

1813
def single_edge_dict(self): ...
1914

20-
edge_attr_dict_factory = single_edge_dict # type: ignore
15+
edge_attr_dict_factory = single_edge_dict
2116

2217
def __getitem__(self, n) -> Mapping: ...
2318
def neighbors(self, n): ...

stubs/networkx/classes/digraph.pyi

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
from copy import deepcopy
21
from functools import cached_property
32

4-
import networkx.convert as convert
5-
6-
from ..classes.coreviews import AdjacencyView
73
from ..classes.graph import Graph
8-
from ..classes.reportviews import DiDegreeView, InDegreeView, InEdgeView, OutDegreeView, OutEdgeView
9-
from ..exception import NetworkXError
4+
from ..classes.reportviews import DiDegreeView, InEdgeView, OutEdgeView
105

116
__all__ = ["DiGraph"]
127

@@ -18,8 +13,8 @@ class _CachedPropertyResetterPred:
1813

1914
class DiGraph(Graph):
2015
graph = ...
21-
_adj = ... # type: ignore
22-
_succ = ... # type: ignore
16+
_adj = ...
17+
_succ = ...
2318
_pred = ...
2419

2520
def __init__(self, incoming_graph_data=None, **attr): ...

stubs/networkx/utils/decorators.pyi

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
1-
import bz2
2-
import collections
3-
import gzip
4-
import inspect
5-
import itertools
6-
import re
7-
from collections import defaultdict
81
from collections.abc import Sequence
9-
from contextlib import contextmanager
10-
from os.path import splitext
11-
from pathlib import Path
122
from typing import Callable
133

14-
from ..classes.graph import Graph
15-
from ..utils import create_py_random_state, create_random_state
16-
174
__all__ = [
185
"not_implemented_for",
196
"open_file",
@@ -30,7 +17,7 @@ def not_implemented_for(*graph_types): ...
3017
# To handle new extensions, define a function accepting a `path` and `mode`.
3118
# Then add the extension to _dispatch_dict.
3219
fopeners: dict = ...
33-
_dispatch_dict = ... # type: ignore
20+
_dispatch_dict = ...
3421

3522
def open_file(path_arg: str | int, mode: str = "r"): ...
3623
def nodes_or_number(which_args: str | int | Sequence[str]): ...

stubs/skimage/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ._shared import lazy as lazy
2-
from ._shared.tester import PytestTester as PytestTester # noqa
2+
from ._shared.tester import PytestTester as PytestTester
33
from ._shared.version_requirements import ensure_python_version as ensure_python_version
44

55
__version__: str = ...

stubs/skimage/data/_registry.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# flake8: noqa
2-
31
# This minimal dataset was available as part of
42
# scikit-image 0.15 and will be retained until
53
# further notice.
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
# This code is adapted for a large part from the astropy openmp helpers, which
2-
# can be found at: https://github.com/astropy/extension-helpers/blob/master/extension_helpers/_openmp_helpers.py # noqa
3-
41
def get_openmp_flag(compiler): ...
52
def check_openmp_support(): ...

stubs/sklearn/decomposition/_dict_learning.pyi

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ from numpy.random import RandomState
66

77
from .._typing import ArrayLike, Float, Int, MatrixLike
88
from ..base import BaseEstimator, ClassNamePrefixFeaturesOutMixin, TransformerMixin
9-
from ..utils import (
10-
deprecated,
11-
)
129

13-
# Author: Vlad Niculae, Gael Varoquaux, Alexandre Gramfort
14-
# License: BSD 3 clause
15-
16-
# XXX : could be moved to the linear_model module
1710
def sparse_encode(
1811
X: ArrayLike,
1912
dictionary: MatrixLike,
@@ -180,15 +173,6 @@ class MiniBatchDictionaryLearning(_BaseSparseCoding, BaseEstimator):
180173
tol: Float = 1e-3,
181174
max_no_improvement: Int = 10,
182175
) -> None: ...
183-
@deprecated("The attribute `iter_offset_` is deprecated in 1.1 and will be removed in 1.3.") # type: ignore
184-
@property
185-
def iter_offset_(self) -> int: ...
186-
@deprecated("The attribute `random_state_` is deprecated in 1.1 and will be removed in 1.3.") # type: ignore
187-
@property
188-
def random_state_(self) -> RandomState: ...
189-
@deprecated("The attribute `inner_stats_` is deprecated in 1.1 and will be removed in 1.3.") # type: ignore
190-
@property
191-
def inner_stats_(self) -> tuple[ndarray, ndarray]: ...
192176
def fit(self, X: MatrixLike, y: Any = None) -> Self: ...
193177
def partial_fit(
194178
self,

stubs/sklearn/decomposition/_pca.pyi

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ from numpy import ndarray
55
from numpy.random import RandomState
66

77
from .._typing import Float, Int, MatrixLike
8-
from ..utils.deprecation import deprecated
98
from ._base import _BasePCA
109

1110
class PCA(_BasePCA):
@@ -35,14 +34,6 @@ class PCA(_BasePCA):
3534
power_iteration_normalizer: Literal["auto", "QR", "LU", "none"] = "auto",
3635
random_state: RandomState | None | Int = None,
3736
) -> None: ...
38-
39-
# TODO(1.4): remove in 1.4
40-
# mypy error: Decorated property not supported
41-
@deprecated( # type: ignore
42-
"Attribute `n_features_` was deprecated in version 1.2 and will be removed in 1.4. Use `n_features_in_` instead."
43-
)
44-
@property
45-
def n_features_(self) -> int: ...
4637
def fit(self, X: MatrixLike, y: Any = None) -> Self: ...
4738
def fit_transform(self, X: MatrixLike, y: Any = None) -> ndarray: ...
4839
def score_samples(self, X: MatrixLike) -> ndarray: ...

stubs/sklearn/ensemble/_base.pyi

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from typing_extensions import Self
55

66
from .._typing import Int
77
from ..base import BaseEstimator, MetaEstimatorMixin
8-
from ..utils import Bunch, deprecated
8+
from ..utils import Bunch
99
from ..utils.metaestimators import _BaseComposition
1010

1111
class BaseEnsemble(MetaEstimatorMixin, BaseEstimator, metaclass=ABCMeta):
@@ -23,18 +23,6 @@ class BaseEnsemble(MetaEstimatorMixin, BaseEstimator, metaclass=ABCMeta):
2323
estimator_params: Sequence[str] = ...,
2424
base_estimator: Any = "deprecated",
2525
) -> None: ...
26-
27-
# TODO(1.4): remove
28-
# mypy error: Decorated property not supported
29-
@deprecated( # type: ignore
30-
"Attribute `base_estimator_` was deprecated in version 1.2 and will be removed in 1.4. Use `estimator_` instead."
31-
)
32-
@property
33-
def base_estimator_(self) -> BaseEstimator: ...
34-
35-
# TODO(1.4): remove
36-
@property
37-
def estimator_(self) -> BaseEstimator: ...
3826
def __len__(self) -> int: ...
3927
def __getitem__(self, index): ...
4028
def __iter__(self): ...

stubs/sklearn/ensemble/_gb.pyi

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ from numpy.random import RandomState
88

99
from .._typing import ArrayLike, Float, Int, MatrixLike
1010
from ..base import BaseEstimator, ClassifierMixin, RegressorMixin
11-
from ..utils import deprecated
1211
from ._base import BaseEnsemble
1312
from ._gb_losses import LossFunction
1413

@@ -57,11 +56,6 @@ class BaseGradientBoosting(BaseEnsemble, metaclass=ABCMeta):
5756
def feature_importances_(self) -> ndarray: ...
5857
def apply(self, X: MatrixLike | ArrayLike) -> ndarray: ...
5958

60-
# TODO(1.3): Remove
61-
# mypy error: Decorated property not supported
62-
@deprecated("Attribute `loss_` was deprecated in version 1.1 and will be removed in 1.3.") # type: ignore
63-
def loss_(self): ...
64-
6559
class GradientBoostingClassifier(ClassifierMixin, BaseGradientBoosting):
6660
max_features_: int = ...
6761
n_classes_: int = ...

stubs/sklearn/linear_model/_glm/glm.pyi

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ from ..._loss.loss import (
88
)
99
from ..._typing import ArrayLike, Float, Int, MatrixLike
1010
from ...base import BaseEstimator, RegressorMixin
11-
from ...utils import deprecated
1211

1312
class _GeneralizedLinearRegressor(RegressorMixin, BaseEstimator):
1413
_base_loss: BaseLoss = ...
@@ -46,10 +45,6 @@ class _GeneralizedLinearRegressor(RegressorMixin, BaseEstimator):
4645
sample_weight: None | ArrayLike = None,
4746
) -> Float: ...
4847

49-
# TODO(1.3): remove
50-
@deprecated("Attribute `family` was deprecated in version 1.1 and will be removed in 1.3.") # type: ignore
51-
def family(self): ...
52-
5348
class PoissonRegressor(_GeneralizedLinearRegressor):
5449
n_iter_: int = ...
5550
feature_names_in_: ndarray = ...

stubs/sklearn/stubtest_allowlist.txt

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,21 +1623,14 @@ sklearn.decomposition.FastICA.__init__
16231623
sklearn.decomposition.LatentDirichletAllocation.fit_transform
16241624
sklearn.decomposition.LatentDirichletAllocation.transform
16251625
sklearn.decomposition.MiniBatchDictionaryLearning.__init__
1626-
sklearn.decomposition.MiniBatchDictionaryLearning.inner_stats_
1627-
sklearn.decomposition.MiniBatchDictionaryLearning.iter_offset_
16281626
sklearn.decomposition.MiniBatchDictionaryLearning.partial_fit
1629-
sklearn.decomposition.MiniBatchDictionaryLearning.random_state_
16301627
sklearn.decomposition.MiniBatchNMF.__init__
16311628
sklearn.decomposition.MiniBatchSparsePCA.__init__
16321629
sklearn.decomposition.NMF.__init__
1633-
sklearn.decomposition.PCA.n_features_
16341630
sklearn.decomposition._dict_learning.DictionaryLearning.__init__
16351631
sklearn.decomposition._dict_learning.DictionaryLearning.fit_transform
16361632
sklearn.decomposition._dict_learning.MiniBatchDictionaryLearning.__init__
1637-
sklearn.decomposition._dict_learning.MiniBatchDictionaryLearning.inner_stats_
1638-
sklearn.decomposition._dict_learning.MiniBatchDictionaryLearning.iter_offset_
16391633
sklearn.decomposition._dict_learning.MiniBatchDictionaryLearning.partial_fit
1640-
sklearn.decomposition._dict_learning.MiniBatchDictionaryLearning.random_state_
16411634
sklearn.decomposition._dict_learning.dict_learning_online
16421635
sklearn.decomposition._fastica.FastICA.__init__
16431636
sklearn.decomposition._fastica.fastica
@@ -1650,7 +1643,6 @@ sklearn.decomposition._nmf._BaseNMF.__init__
16501643
sklearn.decomposition._nmf._BaseNMF.inverse_transform
16511644
sklearn.decomposition._nmf.non_negative_factorization
16521645
sklearn.decomposition._online_lda_fast.psi
1653-
sklearn.decomposition._pca.PCA.n_features_
16541646
sklearn.decomposition._sparse_pca.MiniBatchSparsePCA.__init__
16551647
sklearn.decomposition.dict_learning_online
16561648
sklearn.decomposition.fastica
@@ -1666,8 +1658,6 @@ sklearn.ensemble.BaggingClassifier.estimators_samples_
16661658
sklearn.ensemble.BaggingRegressor.__init__
16671659
sklearn.ensemble.BaggingRegressor.estimators_samples_
16681660
sklearn.ensemble.BaseEnsemble.__init__
1669-
sklearn.ensemble.BaseEnsemble.base_estimator_
1670-
sklearn.ensemble.BaseEnsemble.estimator_
16711661
sklearn.ensemble.ExtraTreesClassifier.__init__
16721662
sklearn.ensemble.ExtraTreesClassifier.feature_importances_
16731663
sklearn.ensemble.ExtraTreesRegressor.__init__
@@ -1702,8 +1692,6 @@ sklearn.ensemble._bagging.BaseBagging.estimators_samples_
17021692
sklearn.ensemble._bagging.BaseBagging.fit
17031693
sklearn.ensemble._bagging.MAX_INT
17041694
sklearn.ensemble._base.BaseEnsemble.__init__
1705-
sklearn.ensemble._base.BaseEnsemble.base_estimator_
1706-
sklearn.ensemble._base.BaseEnsemble.estimator_
17071695
sklearn.ensemble._forest.BaseForest.__init__
17081696
sklearn.ensemble._forest.ExtraTreesClassifier.__init__
17091697
sklearn.ensemble._forest.ExtraTreesClassifier.feature_importances_
@@ -1717,7 +1705,6 @@ sklearn.ensemble._forest.RandomForestClassifier.feature_importances_
17171705
sklearn.ensemble._forest.RandomForestRegressor.__init__
17181706
sklearn.ensemble._forest.RandomForestRegressor.feature_importances_
17191707
sklearn.ensemble._forest.RandomTreesEmbedding.feature_importances_
1720-
sklearn.ensemble._gb.BaseGradientBoosting.loss_
17211708
sklearn.ensemble._gb.GradientBoostingClassifier.feature_importances_
17221709
sklearn.ensemble._gb.GradientBoostingRegressor.feature_importances_
17231710
sklearn.ensemble._gb_losses
@@ -1912,8 +1899,6 @@ sklearn.linear_model._coordinate_descent.MultiTaskElasticNet.sparse_coef_
19121899
sklearn.linear_model._coordinate_descent.MultiTaskElasticNetCV.path
19131900
sklearn.linear_model._coordinate_descent.MultiTaskLasso.sparse_coef_
19141901
sklearn.linear_model._coordinate_descent.MultiTaskLassoCV.path
1915-
sklearn.linear_model._glm._GeneralizedLinearRegressor.family
1916-
sklearn.linear_model._glm.glm._GeneralizedLinearRegressor.family
19171902
sklearn.linear_model._least_angle.Lars.__init__
19181903
sklearn.linear_model._least_angle.LarsCV.__init__
19191904
sklearn.linear_model._least_angle.LassoLars.__init__
@@ -2158,17 +2143,14 @@ sklearn.svm.NuSVC.coef_
21582143
sklearn.svm.NuSVC.n_support_
21592144
sklearn.svm.NuSVC.probA_
21602145
sklearn.svm.NuSVC.probB_
2161-
sklearn.svm.NuSVR.class_weight_
21622146
sklearn.svm.NuSVR.coef_
21632147
sklearn.svm.NuSVR.n_support_
2164-
sklearn.svm.OneClassSVM.class_weight_
21652148
sklearn.svm.OneClassSVM.coef_
21662149
sklearn.svm.OneClassSVM.n_support_
21672150
sklearn.svm.SVC.coef_
21682151
sklearn.svm.SVC.n_support_
21692152
sklearn.svm.SVC.probA_
21702153
sklearn.svm.SVC.probB_
2171-
sklearn.svm.SVR.class_weight_
21722154
sklearn.svm.SVR.coef_
21732155
sklearn.svm.SVR.n_support_
21742156
sklearn.svm._base.BaseLibSVM.n_support_
@@ -2178,17 +2160,14 @@ sklearn.svm._classes.NuSVC.coef_
21782160
sklearn.svm._classes.NuSVC.n_support_
21792161
sklearn.svm._classes.NuSVC.probA_
21802162
sklearn.svm._classes.NuSVC.probB_
2181-
sklearn.svm._classes.NuSVR.class_weight_
21822163
sklearn.svm._classes.NuSVR.coef_
21832164
sklearn.svm._classes.NuSVR.n_support_
2184-
sklearn.svm._classes.OneClassSVM.class_weight_
21852165
sklearn.svm._classes.OneClassSVM.coef_
21862166
sklearn.svm._classes.OneClassSVM.n_support_
21872167
sklearn.svm._classes.SVC.coef_
21882168
sklearn.svm._classes.SVC.n_support_
21892169
sklearn.svm._classes.SVC.probA_
21902170
sklearn.svm._classes.SVC.probB_
2191-
sklearn.svm._classes.SVR.class_weight_
21922171
sklearn.svm._classes.SVR.coef_
21932172
sklearn.svm._classes.SVR.n_support_
21942173
sklearn.tests.random_seed

0 commit comments

Comments
 (0)