Skip to content

Commit c21a83d

Browse files
committed
TYP: Fix xycoords and friends
1 parent 0fd212d commit c21a83d

File tree

4 files changed

+26
-87
lines changed

4 files changed

+26
-87
lines changed

lib/matplotlib/axes/_axes.pyi

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ import numpy as np
3636
from numpy.typing import ArrayLike
3737
from matplotlib.typing import ColorType, MarkerType, LineStyleType
3838

39+
_coords_type_base = (
40+
str | Artist | Transform | Callable[[RendererBase], Bbox | Transform]
41+
)
42+
_coords_type = _coords_type_base | tuple[_coords_type_base, _coords_type_base]
43+
3944
class Axes(_AxesBase):
4045
def get_title(self, loc: Literal["left", "center", "right"] = ...) -> str: ...
4146
def set_title(
@@ -122,17 +127,8 @@ class Axes(_AxesBase):
122127
text: str,
123128
xy: tuple[float, float],
124129
xytext: tuple[float, float] | None = ...,
125-
xycoords: str
126-
| Artist
127-
| Transform
128-
| Callable[[RendererBase], Bbox | Transform]
129-
| tuple[float, float] = ...,
130-
textcoords: str
131-
| Artist
132-
| Transform
133-
| Callable[[RendererBase], Bbox | Transform]
134-
| tuple[float, float]
135-
| None = ...,
130+
xycoords: _coords_type = ...,
131+
textcoords: _coords_type = ...,
136132
arrowprops: dict[str, Any] | None = ...,
137133
annotation_clip: bool | None = ...,
138134
**kwargs

lib/matplotlib/offsetbox.pyi

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import matplotlib.artist as martist
2+
from matplotlib.axes._axes import _coords_type
23
from matplotlib.backend_bases import RendererBase, Event, FigureCanvasBase
34
from matplotlib.colors import Colormap, Normalize
45
import matplotlib.text as mtext
@@ -219,9 +220,7 @@ class AnnotationBbox(martist.Artist, mtext._AnnotationBase):
219220
offsetbox: OffsetBox
220221
arrowprops: dict[str, Any] | None
221222
xybox: tuple[float, float]
222-
boxcoords: str | tuple[str, str] | martist.Artist | Transform | Callable[
223-
[RendererBase], Bbox | Transform
224-
]
223+
boxcoords: _coords_type
225224
arrow_patch: FancyArrowPatch | None
226225
patch: FancyBboxPatch
227226
prop: FontProperties
@@ -230,17 +229,8 @@ class AnnotationBbox(martist.Artist, mtext._AnnotationBase):
230229
offsetbox: OffsetBox,
231230
xy: tuple[float, float],
232231
xybox: tuple[float, float] | None = ...,
233-
xycoords: str
234-
| tuple[str, str]
235-
| martist.Artist
236-
| Transform
237-
| Callable[[RendererBase], Bbox | Transform] = ...,
238-
boxcoords: str
239-
| tuple[str, str]
240-
| martist.Artist
241-
| Transform
242-
| Callable[[RendererBase], Bbox | Transform]
243-
| None = ...,
232+
xycoords: _coords_type = ...,
233+
boxcoords: _coords_type = ...,
244234
*,
245235
frameon: bool = ...,
246236
pad: float = ...,
@@ -258,17 +248,11 @@ class AnnotationBbox(martist.Artist, mtext._AnnotationBase):
258248
@property
259249
def anncoords(
260250
self,
261-
) -> str | tuple[str, str] | martist.Artist | Transform | Callable[
262-
[RendererBase], Bbox | Transform
263-
]: ...
251+
) -> _coords_type: ...
264252
@anncoords.setter
265253
def anncoords(
266254
self,
267-
coords: str
268-
| tuple[str, str]
269-
| martist.Artist
270-
| Transform
271-
| Callable[[RendererBase], Bbox | Transform],
255+
coords: _coords_type,
272256
) -> None: ...
273257
def get_children(self) -> list[martist.Artist]: ...
274258
def set_figure(self, fig: Figure) -> None: ...

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,17 +2858,8 @@ def annotate(
28582858
text: str,
28592859
xy: tuple[float, float],
28602860
xytext: tuple[float, float] | None = None,
2861-
xycoords: str
2862-
| Artist
2863-
| Transform
2864-
| Callable[[RendererBase], Bbox | Transform]
2865-
| tuple[float, float] = "data",
2866-
textcoords: str
2867-
| Artist
2868-
| Transform
2869-
| Callable[[RendererBase], Bbox | Transform]
2870-
| tuple[float, float]
2871-
| None = None,
2861+
xycoords: _coords_type = "data",
2862+
textcoords: _coords_type = None,
28722863
arrowprops: dict[str, Any] | None = None,
28732864
annotation_clip: bool | None = None,
28742865
**kwargs,

lib/matplotlib/text.pyi

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .artist import Artist
2+
from .axes._axes import _coords_type
23
from .backend_bases import RendererBase
34
from .font_manager import FontProperties
45
from .offsetbox import DraggableAnnotation
@@ -120,17 +121,11 @@ class OffsetFrom:
120121

121122
class _AnnotationBase:
122123
xy: tuple[float, float]
123-
xycoords: str | tuple[str, str] | Artist | Transform | Callable[
124-
[RendererBase], Bbox | Transform
125-
]
124+
xycoords: _coords_type
126125
def __init__(
127126
self,
128127
xy,
129-
xycoords: str
130-
| tuple[str, str]
131-
| Artist
132-
| Transform
133-
| Callable[[RendererBase], Bbox | Transform] = ...,
128+
xycoords: _coords_type = ...,
134129
annotation_clip: bool | None = ...,
135130
) -> None: ...
136131
def set_annotation_clip(self, b: bool | None) -> None: ...
@@ -147,67 +142,40 @@ class Annotation(Text, _AnnotationBase):
147142
text: str,
148143
xy: tuple[float, float],
149144
xytext: tuple[float, float] | None = ...,
150-
xycoords: str
151-
| tuple[str, str]
152-
| Artist
153-
| Transform
154-
| Callable[[RendererBase], Bbox | Transform] = ...,
155-
textcoords: str
156-
| tuple[str, str]
157-
| Artist
158-
| Transform
159-
| Callable[[RendererBase], Bbox | Transform]
160-
| None = ...,
145+
xycoords: _coords_type = ...,
146+
textcoords: _coords_type = ...,
161147
arrowprops: dict[str, Any] | None = ...,
162148
annotation_clip: bool | None = ...,
163149
**kwargs
164150
) -> None: ...
165151
@property
166152
def xycoords(
167153
self,
168-
) -> str | tuple[str, str] | Artist | Transform | Callable[
169-
[RendererBase], Bbox | Transform
170-
]: ...
154+
) -> _coords_type: ...
171155
@xycoords.setter
172156
def xycoords(
173157
self,
174-
xycoords: str
175-
| tuple[str, str]
176-
| Artist
177-
| Transform
178-
| Callable[[RendererBase], Bbox | Transform],
158+
xycoords: _coords_type,
179159
) -> None: ...
180160
@property
181161
def xyann(self) -> tuple[float, float]: ...
182162
@xyann.setter
183163
def xyann(self, xytext: tuple[float, float]) -> None: ...
184164
def get_anncoords(
185165
self,
186-
) -> str | tuple[str, str] | Artist | Transform | Callable[
187-
[RendererBase], Bbox | Transform
188-
]: ...
166+
) -> _coords_type: ...
189167
def set_anncoords(
190168
self,
191-
coords: str
192-
| tuple[str, str]
193-
| Artist
194-
| Transform
195-
| Callable[[RendererBase], Bbox | Transform],
169+
coords: _coords_type,
196170
) -> None: ...
197171
@property
198172
def anncoords(
199173
self,
200-
) -> str | tuple[str, str] | Artist | Transform | Callable[
201-
[RendererBase], Bbox | Transform
202-
]: ...
174+
) -> _coords_type: ...
203175
@anncoords.setter
204176
def anncoords(
205177
self,
206-
coords: str
207-
| tuple[str, str]
208-
| Artist
209-
| Transform
210-
| Callable[[RendererBase], Bbox | Transform],
178+
coords: _coords_type,
211179
) -> None: ...
212180
def update_positions(self, renderer: RendererBase) -> None: ...
213181
# Drops `dpi` parameter from superclass

0 commit comments

Comments
 (0)