Skip to content

Remove unused imports in private modules #370

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 8 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,10 @@ ignore = [
"PYI014",
"PYI053",

# TODO: Fixing these would change which symbols are even visible for Pylance.
# Which may negatively affect users, especially if the symbol wasn't meant to be re-exported.
# Manually evaluate each violation.
"F401",

# TODO: Investigate and fix or configure
"PYI051", # Request for autofix: https://github.com/astral-sh/ruff/issues/14185
]

[tool.ruff.lint.per-file-ignores]
"*.pyi" = [
###
Expand All @@ -100,6 +96,13 @@ ignore = [
# We keep docstrings in sklearn
"stubs/sklearn/**" = ["PYI021"]

# TODO: For public modules, manually evaluate each violation.
# Removing unused imports change which symbols are even visible for Pylance.
# Which may negatively affect users, especially if the symbol wasn't meant to be re-exported.
# We do assume no public re-exports were meant from private modules
"!_*.pyi" = ["F401"]
"__init__.pyi" = ["F401"]

[tool.ruff.lint.isort]
combine-as-imports = true
extra-standard-library = [
Expand Down
2 changes: 0 additions & 2 deletions stubs/matplotlib/_afm.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import numpy as np

from ._typing import *

CharMetrics = ...
Expand Down
1 change: 0 additions & 1 deletion stubs/matplotlib/_mathtext.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import enum
import functools
from sre_parse import State
from tkinter.tix import HList
from typing import Literal

Expand Down
1 change: 0 additions & 1 deletion stubs/matplotlib/axes/_axes.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
from collections.abc import Sequence
from re import L
from typing import Callable, Literal, overload

import matplotlib.tri as mtri
Expand Down
1 change: 0 additions & 1 deletion stubs/matplotlib/axes/_secondary_axes.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Callable, Literal

import numpy as np
from matplotlib._typing import *
from matplotlib.axes._base import _AxesBase
from matplotlib.transforms import Transform
Expand Down
2 changes: 0 additions & 2 deletions stubs/skimage/_shared/_dependency_checks.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from .version_requirements import is_installed

has_mpl = ...
2 changes: 0 additions & 2 deletions stubs/skimage/_shared/_geometry.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
__all__ = ["polygon_clip", "polygon_area"]

import numpy as np

from .version_requirements import require

@require("matplotlib", ">=3.0.3")
Expand Down
2 changes: 0 additions & 2 deletions stubs/skimage/_shared/_tempfile.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
from contextlib import contextmanager
from tempfile import NamedTemporaryFile

@contextmanager
def temporary_file(suffix: str = ""): ...
5 changes: 0 additions & 5 deletions stubs/skimage/_shared/_warnings.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import functools
import os
import re
import sys
import warnings
from contextlib import contextmanager

__all__ = ["all_warnings", "expected_warnings", "warn"]
Expand Down
3 changes: 0 additions & 3 deletions stubs/skimage/data/_binary_blobs.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import numpy as np
from numpy.typing import NDArray

from .._shared.filters import gaussian

def binary_blobs(
length: int = 512,
blob_size_fraction: float = 0.1,
Expand Down
9 changes: 0 additions & 9 deletions stubs/skimage/data/_fetchers.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import os
import os.path as osp
import shutil
from os import PathLike

import numpy as np
from packaging import version

from .. import __version__
from ._registry import legacy_registry, registry, registry_urls

legacy_data_dir = ...
skimage_distribution_dir = ...

Expand Down
4 changes: 0 additions & 4 deletions stubs/skimage/draw/_polygon2mask.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import numpy as np

from . import draw

def polygon2mask(image_shape, polygon): ...
7 changes: 1 addition & 6 deletions stubs/skimage/draw/_random_shapes.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import math

import numpy as np

from .._shared.utils import deprecate_multichannel_kwarg, warn
from . import disk as draw_disk, ellipse as draw_ellipse, polygon as draw_polygon
from .._shared.utils import deprecate_multichannel_kwarg

def _generate_rectangle_mask(point, image, shape, random): ...
def _generate_circle_mask(point, image, shape, random): ...
Expand Down
5 changes: 0 additions & 5 deletions stubs/skimage/feature/_basic_features.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import itertools
from concurrent.futures import ThreadPoolExecutor
from itertools import combinations_with_replacement

import numpy as np
from numpy.typing import NDArray

from .._shared import utils
Expand Down
6 changes: 0 additions & 6 deletions stubs/skimage/feature/_canny.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import numpy as np
import scipy.ndimage as ndi

from .._shared.filters import gaussian
from .._shared.utils import check_nD

def _preprocess(image, mask, sigma, mode, cval): ...
def _set_local_maxima(magnitude, pts, w_num, w_denum, row_slices, col_slices, out): ...
def _get_local_maxima(isobel, jsobel, magnitude, eroded_mask): ...
Expand Down
10 changes: 0 additions & 10 deletions stubs/skimage/feature/_daisy.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import math

import numpy as np
from numpy import arctan2, exp, pi, sqrt
from numpy.typing import ArrayLike

from .. import draw
from .._shared.filters import gaussian
from .._shared.utils import check_nD

def daisy(
image,
step: int = 4,
Expand Down
2 changes: 0 additions & 2 deletions stubs/skimage/feature/_hessian_det_appx_pythran.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import numpy as np

def _clip(x, low, high): ...
def _integ(img, r, c, rl, cl): ...

Expand Down
2 changes: 0 additions & 2 deletions stubs/skimage/feature/_hog.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import numpy as np

from .._shared import utils

def _hog_normalize_block(block, method, eps=1e-5): ...
Expand Down
4 changes: 0 additions & 4 deletions stubs/skimage/feature/_orb_descriptor_positions.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import os

import numpy as np

# Putting this in cython was giving strange bugs for different versions
# of cython which seemed to indicate troubles with the __file__ variable
# not being defined. Keeping it in pure python makes it more reliable
Expand Down
3 changes: 0 additions & 3 deletions stubs/skimage/future/graph/_ncut.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import networkx as nx
import numpy as np
from numpy.typing import NDArray
from scipy import sparse

from .rag import RAG

Expand Down
2 changes: 0 additions & 2 deletions stubs/skimage/measure/_blur_effect.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Callable

import numpy as np
import scipy.ndimage as ndi
from numpy.typing import NDArray

__all__ = ["blur_effect"]
Expand Down
4 changes: 0 additions & 4 deletions stubs/skimage/measure/_find_contours.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from collections import deque

import numpy as np

from .._shared.utils import deprecate_kwarg

_param_options = ...
Expand Down
2 changes: 0 additions & 2 deletions stubs/skimage/measure/_label.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from scipy import ndimage

from .._shared.utils import deprecate_kwarg

def _label_bool(image, background=None, return_num=False, connectivity=None): ...
Expand Down
3 changes: 0 additions & 3 deletions stubs/skimage/measure/_marching_cubes_classic.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import numpy as np
import scipy.ndimage as ndi

def _marching_cubes_classic(volume, level, spacing, gradient_direction): ...
def mesh_surface_area(verts, faces) -> float: ...
def _correct_mesh_orientation(volume, actual_verts, faces, spacing=(1.0, 1.0, 1.0), gradient_direction="descent"): ...
7 changes: 0 additions & 7 deletions stubs/skimage/measure/_marching_cubes_lewiner.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import base64

import numpy as np

from . import _marching_cubes_lewiner_luts as mcluts
from ._marching_cubes_classic import _marching_cubes_classic

def marching_cubes(
volume,
level: float | None = None,
Expand Down
5 changes: 0 additions & 5 deletions stubs/skimage/measure/_moments.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import itertools

import numpy as np
from numpy.typing import ArrayLike

from .._shared.utils import _supported_float_type, check_nD

def moments_coords(coords, order: int = 3): ...
def moments_coords_central(coords, center: tuple[float, ...] | None = None, order: int = 3): ...
def moments(image, order: int = 3): ...
Expand Down
3 changes: 0 additions & 3 deletions stubs/skimage/measure/_polygon.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import numpy as np
from scipy import signal

def approximate_polygon(coords, tolerance: float): ...

# B-Spline subdivision
Expand Down
10 changes: 0 additions & 10 deletions stubs/skimage/measure/_regionprops.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import inspect
from collections.abc import Mapping
from functools import wraps
from math import atan2, pi as PI, sqrt
from warnings import warn

import numpy as np
from numpy.typing import ArrayLike
from scipy import ndimage as ndi
from scipy.spatial.distance import pdist

from . import _moments
from ._find_contours import find_contours
from ._marching_cubes_lewiner import marching_cubes
from ._regionprops_utils import euler_number, perimeter, perimeter_crofton

__all__ = ["regionprops", "euler_number", "perimeter", "perimeter_crofton"]
Expand Down
5 changes: 0 additions & 5 deletions stubs/skimage/measure/_regionprops_utils.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
from math import sqrt

import numpy as np
from scipy import ndimage as ndi

STREL_4 = ...
STREL_8 = ...

Expand Down
2 changes: 0 additions & 2 deletions stubs/skimage/morphology/_flood_fill.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
from numpy.typing import NDArray

from .._shared.utils import deprecate_kwarg
from ._util import _offsets_to_raveled_neighbors, _resolve_neighborhood, _set_border_values

@deprecate_kwarg(
kwarg_mapping={"selem": "footprint"},
Expand Down
4 changes: 1 addition & 3 deletions stubs/skimage/morphology/_skeletonize.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import Literal

import numpy as np
from numpy.typing import NDArray
from scipy import ndimage as ndi

from .._shared.utils import check_nD, deprecate_kwarg
from .._shared.utils import deprecate_kwarg

def skeletonize(image, *, method: Literal["zhang", "lee"] | None = None) -> NDArray: ...
def skeletonize_2d(image) -> NDArray: ...
Expand Down
3 changes: 0 additions & 3 deletions stubs/skimage/morphology/_util.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import numpy as np
from scipy import ndimage as ndi

def _validate_connectivity(image_dim, connectivity, offset): ...
def _raveled_offsets_and_distances(
image_shape,
Expand Down
6 changes: 0 additions & 6 deletions stubs/skimage/transform/_geometric.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import math
import textwrap
from collections.abc import Sequence

import numpy as np
from numpy.typing import ArrayLike
from scipy import spatial

from .._shared.utils import get_bound_method_class, safe_as_int

def _affine_matrix_from_vector(v): ...
def _center_and_normalize_points(points): ...
Expand Down
12 changes: 0 additions & 12 deletions stubs/skimage/transform/_warps.pyi
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
from collections.abc import Iterable, Mapping
from typing import Literal

import numpy as np
import scipy
from numpy.lib import NumpyVersion
from numpy.typing import NDArray
from scipy import ndimage as ndi

from .._shared.utils import (
_to_ndimage_mode,
_validate_interpolation_order,
channel_as_last_axis,
convert_to_float,
deprecate_multichannel_kwarg,
get_bound_method_class,
safe_as_int,
warn,
)
from ..measure import block_reduce
from ._geometric import AffineTransform, ProjectiveTransform, SimilarityTransform

HOMOGRAPHY_TRANSFORMS = ...

Expand Down
2 changes: 0 additions & 2 deletions stubs/sklearn/_config.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os
import threading
from collections.abc import Iterator
from contextlib import contextmanager as contextmanager
from typing import Literal
Expand Down
2 changes: 0 additions & 2 deletions stubs/sklearn/_min_dependencies.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import argparse
import platform
from collections import defaultdict as defaultdict

SCIPY_MIN_VERSION: str = ...
Expand Down
2 changes: 0 additions & 2 deletions stubs/sklearn/cluster/_affinity_propagation.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import warnings
from numbers import Integral as Integral, Real as Real
from typing import Any, ClassVar, Literal
from typing_extensions import Self

import numpy as np
from numpy import ndarray
from numpy.random import RandomState

Expand Down
2 changes: 0 additions & 2 deletions stubs/sklearn/cluster/_agglomerative.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import warnings
from heapq import heapify as heapify, heappop as heappop, heappush as heappush, heappushpop as heappushpop
from numbers import Integral as Integral, Real as Real
from typing import Any, Callable, ClassVar, Literal
from typing_extensions import Self

import numpy as np
from joblib import Memory
from numpy import ndarray
from scipy import sparse as sparse
Expand Down
1 change: 0 additions & 1 deletion stubs/sklearn/cluster/_bicluster.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ from numbers import Integral as Integral
from typing import Any, ClassVar, Literal
from typing_extensions import Self

import numpy as np
from numpy import ndarray
from numpy.random import RandomState
from scipy.linalg import norm as norm
Expand Down
2 changes: 0 additions & 2 deletions stubs/sklearn/cluster/_birch.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import warnings
from math import sqrt as sqrt
from numbers import Integral as Integral, Real as Real
from typing import Any, ClassVar
from typing_extensions import Self

import numpy as np
from numpy import ndarray
from scipy import sparse as sparse
from scipy.sparse import spmatrix
Expand Down
Loading
Loading