Skip to content

Commit 807d662

Browse files
committed
Fix up image module type hints
The resample function from `_image` was missing, and bbox is allowed to be a function like `get_window_extent`.
1 parent 418ee6a commit 807d662

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

lib/matplotlib/image.pyi

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,56 @@
1+
from collections.abc import Callable, Sequence
12
import os
23
import pathlib
4+
from typing import Any, BinaryIO, Literal
5+
6+
import numpy as np
7+
from numpy.typing import ArrayLike, NDArray
8+
import PIL # type: ignore
39

4-
from matplotlib._image import *
510
import matplotlib.artist as martist
611
from matplotlib.axes import Axes
712
from matplotlib import cm
813
from matplotlib.backend_bases import RendererBase, MouseEvent
914
from matplotlib.colors import Colormap, Normalize
1015
from matplotlib.figure import Figure
11-
from matplotlib.transforms import (
12-
Affine2D,
13-
BboxBase,
14-
)
16+
from matplotlib.transforms import Affine2D, BboxBase, Bbox, Transform
1517

16-
from collections.abc import Sequence
17-
from typing import Any, BinaryIO, Literal
18-
import numpy as np
19-
from numpy.typing import ArrayLike
18+
#
19+
# These names are re-exported from matplotlib._image.
20+
#
2021

21-
import PIL # type: ignore
22+
BESSEL: int
23+
BICUBIC: int
24+
BILINEAR: int
25+
BLACKMAN: int
26+
CATROM: int
27+
GAUSSIAN: int
28+
HAMMING: int
29+
HANNING: int
30+
HERMITE: int
31+
KAISER: int
32+
LANCZOS: int
33+
MITCHELL: int
34+
NEAREST: int
35+
QUADRIC: int
36+
SINC: int
37+
SPLINE16: int
38+
SPLINE36: int
2239

23-
BESSEL: int = ...
24-
BICUBIC: int = ...
25-
BILINEAR: int = ...
26-
BLACKMAN: int = ...
27-
CATROM: int = ...
28-
GAUSSIAN: int = ...
29-
HAMMING: int = ...
30-
HANNING: int = ...
31-
HERMITE: int = ...
32-
KAISER: int = ...
33-
LANCZOS: int = ...
34-
MITCHELL: int = ...
35-
NEAREST: int = ...
36-
QUADRIC: int = ...
37-
SINC: int = ...
38-
SPLINE16: int = ...
39-
SPLINE36: int = ...
40+
def resample(
41+
input_array: NDArray[np.float32] | NDArray[np.float64] | NDArray[np.int8],
42+
output_array: NDArray[np.float32] | NDArray[np.float64] | NDArray[np.int8],
43+
transform: Transform,
44+
interpolation: int = ...,
45+
resample: bool = ...,
46+
alpha: float = ...,
47+
norm: bool = ...,
48+
radius: float = ...,
49+
) -> None: ...
50+
51+
#
52+
# END names re-exported from matplotlib._image.
53+
#
4054

4155
interpolations_names: set[str]
4256

@@ -156,7 +170,7 @@ class BboxImage(_ImageBase):
156170
bbox: BboxBase
157171
def __init__(
158172
self,
159-
bbox: BboxBase,
173+
bbox: BboxBase | Callable[[RendererBase | None], Bbox],
160174
*,
161175
cmap: str | Colormap | None = ...,
162176
norm: str | Normalize | None = ...,
@@ -167,10 +181,10 @@ class BboxImage(_ImageBase):
167181
resample: bool = ...,
168182
**kwargs
169183
) -> None: ...
170-
def get_window_extent(self, renderer: RendererBase | None = ...): ...
184+
def get_window_extent(self, renderer: RendererBase | None = ...) -> Bbox: ...
171185

172186
def imread(
173-
fname: str | pathlib.Path | BinaryIO, format: str | None = ...
187+
fname: str | pathlib.Path | BinaryIO, format: str | None = ...
174188
) -> np.ndarray: ...
175189
def imsave(
176190
fname: str | os.PathLike | BinaryIO,

src/_image_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* */
1010

1111
const char* image_resample__doc__ =
12-
"resample(input_array, output_array, transform, interpolation=NEAREST, alpha=1.0, norm=False, radius=1)\n"
12+
"resample(input_array, output_array, transform, interpolation=NEAREST, resample=False, alpha=1.0, norm=False, radius=1.0)\n"
1313
"--\n\n"
1414

1515
"Resample input_array, blending it in-place into output_array, using an\n"

0 commit comments

Comments
 (0)