Skip to content

Commit 4db147a

Browse files
committed
Handle suggestions in PR
1 parent e8be3e5 commit 4db147a

File tree

7 files changed

+42
-44
lines changed

7 files changed

+42
-44
lines changed

lib/matplotlib/axes/_axes.pyi

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ from matplotlib.patches import Rectangle, FancyArrow, Polygon, StepPatch, Wedge
2323
from matplotlib.quiver import Quiver, QuiverKey, Barbs
2424
from matplotlib.text import Annotation, Text
2525
from matplotlib.transforms import Transform
26+
from matplotlib.typing import CoordsType
2627
import matplotlib.tri as mtri
2728
import matplotlib.table as mtable
2829
import matplotlib.stackplot as mstack
@@ -122,8 +123,8 @@ class Axes(_AxesBase):
122123
text: str,
123124
xy: tuple[float, float],
124125
xytext: tuple[float, float] | None = ...,
125-
xycoords: coords_type = ...,
126-
textcoords: coords_type | None = ...,
126+
xycoords: CoordsType = ...,
127+
textcoords: CoordsType | None = ...,
127128
arrowprops: dict[str, Any] | None = ...,
128129
annotation_clip: bool | None = ...,
129130
**kwargs

lib/matplotlib/axes/_base.py

-17
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77
from operator import attrgetter
88
import re
99
import types
10-
from typing import Callable, Union
1110

1211
import numpy as np
1312

1413
import matplotlib as mpl
1514
from matplotlib import _api, cbook, _docstring, offsetbox
1615
import matplotlib.artist as martist
1716
import matplotlib.axis as maxis
18-
from matplotlib import backend_bases
1917
from matplotlib.cbook import _OrderedSet, _check_1d, index_of
2018
import matplotlib.collections as mcoll
2119
import matplotlib.colors as mcolors
@@ -34,21 +32,6 @@
3432
_log = logging.getLogger(__name__)
3533

3634

37-
coords_type_base = Union[
38-
str,
39-
martist.Artist,
40-
mtransforms.Transform,
41-
Callable[
42-
[backend_bases.RendererBase],
43-
Union[mtransforms.Bbox, mtransforms.Transform]
44-
]
45-
]
46-
coords_type = Union[
47-
coords_type_base,
48-
tuple[coords_type_base, coords_type_base]
49-
]
50-
51-
5235
class _axis_method_wrapper:
5336
"""
5437
Helper to generate Axes methods wrapping Axis methods.

lib/matplotlib/axes/_base.pyi

-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ from numpy.typing import ArrayLike
2929
from typing import Any, Literal, TypeVar, overload
3030
from matplotlib.typing import ColorType
3131

32-
coords_type_base = str | Artist | Transform | Callable[[RendererBase], Bbox | Transform]
33-
coords_type = coords_type_base | tuple[coords_type_base, coords_type_base]
34-
3532
_T = TypeVar("_T", bound=Artist)
3633

3734
class _axis_method_wrapper:

lib/matplotlib/offsetbox.pyi

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ from matplotlib.font_manager import FontProperties
88
from matplotlib.image import BboxImage
99
from matplotlib.patches import FancyArrowPatch, FancyBboxPatch
1010
from matplotlib.transforms import Bbox, BboxBase, Transform
11+
from matplotlib.typing import CoordsType
1112

1213
import numpy as np
1314
from numpy.typing import ArrayLike
@@ -220,7 +221,7 @@ class AnnotationBbox(martist.Artist, mtext._AnnotationBase):
220221
offsetbox: OffsetBox
221222
arrowprops: dict[str, Any] | None
222223
xybox: tuple[float, float]
223-
boxcoords: coords_type
224+
boxcoords: CoordsType
224225
arrow_patch: FancyArrowPatch | None
225226
patch: FancyBboxPatch
226227
prop: FontProperties
@@ -229,8 +230,8 @@ class AnnotationBbox(martist.Artist, mtext._AnnotationBase):
229230
offsetbox: OffsetBox,
230231
xy: tuple[float, float],
231232
xybox: tuple[float, float] | None = ...,
232-
xycoords: coords_type = ...,
233-
boxcoords: coords_type | None = ...,
233+
xycoords: CoordsType = ...,
234+
boxcoords: CoordsType | None = ...,
234235
*,
235236
frameon: bool = ...,
236237
pad: float = ...,
@@ -248,11 +249,11 @@ class AnnotationBbox(martist.Artist, mtext._AnnotationBase):
248249
@property
249250
def anncoords(
250251
self,
251-
) -> coords_type: ...
252+
) -> CoordsType: ...
252253
@anncoords.setter
253254
def anncoords(
254255
self,
255-
coords: coords_type,
256+
coords: CoordsType,
256257
) -> None: ...
257258
def get_children(self) -> list[martist.Artist]: ...
258259
def set_figure(self, fig: Figure) -> None: ...

lib/matplotlib/pyplot.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
import matplotlib.artist
9595
import matplotlib.backend_bases
9696
from matplotlib.axis import Tick
97-
from matplotlib.axes._base import _AxesBase, coords_type
97+
from matplotlib.axes._base import _AxesBase
9898
from matplotlib.backend_bases import Event
9999
from matplotlib.cm import ScalarMappable
100100
from matplotlib.contour import ContourSet, QuadContourSet
@@ -119,7 +119,7 @@
119119
from matplotlib.patches import FancyArrow, StepPatch, Wedge
120120
from matplotlib.quiver import Barbs, Quiver, QuiverKey
121121
from matplotlib.scale import ScaleBase
122-
from matplotlib.typing import ColorType, LineStyleType, MarkerType, HashableList
122+
from matplotlib.typing import ColorType, CoordsType, LineStyleType, MarkerType, HashableList
123123
from matplotlib.widgets import SubplotTool
124124

125125
_P = ParamSpec('_P')
@@ -2857,8 +2857,8 @@ def annotate(
28572857
text: str,
28582858
xy: tuple[float, float],
28592859
xytext: tuple[float, float] | None = None,
2860-
xycoords: coords_type = "data",
2861-
textcoords: coords_type | None = None,
2860+
xycoords: CoordsType = "data",
2861+
textcoords: CoordsType | None = None,
28622862
arrowprops: dict[str, Any] | None = None,
28632863
annotation_clip: bool | None = None,
28642864
**kwargs,

lib/matplotlib/text.pyi

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from .artist import Artist
2-
from .axes._base import coords_type
32
from .backend_bases import RendererBase
43
from .font_manager import FontProperties
54
from .offsetbox import DraggableAnnotation
@@ -17,7 +16,7 @@ from .transforms import (
1716

1817
from collections.abc import Callable, Iterable
1918
from typing import Any, Literal
20-
from .typing import ColorType
19+
from .typing import ColorType, CoordsType
2120

2221
class Text(Artist):
2322
zorder: float
@@ -121,11 +120,11 @@ class OffsetFrom:
121120

122121
class _AnnotationBase:
123122
xy: tuple[float, float]
124-
xycoords: coords_type
123+
xycoords: CoordsType
125124
def __init__(
126125
self,
127126
xy,
128-
xycoords: coords_type = ...,
127+
xycoords: CoordsType = ...,
129128
annotation_clip: bool | None = ...,
130129
) -> None: ...
131130
def set_annotation_clip(self, b: bool | None) -> None: ...
@@ -142,40 +141,40 @@ class Annotation(Text, _AnnotationBase):
142141
text: str,
143142
xy: tuple[float, float],
144143
xytext: tuple[float, float] | None = ...,
145-
xycoords: coords_type = ...,
146-
textcoords: coords_type | None = ...,
144+
xycoords: CoordsType = ...,
145+
textcoords: CoordsType | None = ...,
147146
arrowprops: dict[str, Any] | None = ...,
148147
annotation_clip: bool | None = ...,
149148
**kwargs
150149
) -> None: ...
151150
@property
152151
def xycoords(
153152
self,
154-
) -> coords_type: ...
153+
) -> CoordsType: ...
155154
@xycoords.setter
156155
def xycoords(
157156
self,
158-
xycoords: coords_type,
157+
xycoords: CoordsType,
159158
) -> None: ...
160159
@property
161160
def xyann(self) -> tuple[float, float]: ...
162161
@xyann.setter
163162
def xyann(self, xytext: tuple[float, float]) -> None: ...
164163
def get_anncoords(
165164
self,
166-
) -> coords_type: ...
165+
) -> CoordsType: ...
167166
def set_anncoords(
168167
self,
169-
coords: coords_type,
168+
coords: CoordsType,
170169
) -> None: ...
171170
@property
172171
def anncoords(
173172
self,
174-
) -> coords_type: ...
173+
) -> CoordsType: ...
175174
@anncoords.setter
176175
def anncoords(
177176
self,
178-
coords: coords_type,
177+
coords: CoordsType,
179178
) -> None: ...
180179
def update_positions(self, renderer: RendererBase) -> None: ...
181180
# Drops `dpi` parameter from superclass

lib/matplotlib/typing.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
"""
1212
from collections.abc import Hashable, Sequence
1313
import pathlib
14-
from typing import Any, Literal, TypeVar, Union
14+
from typing import Any, Callable, Literal, TypeVar, Union
1515

1616
from . import path
1717
from ._enums import JoinStyle, CapStyle
18+
from .artist import Artist
19+
from .backend_bases import RendererBase
1820
from .markers import MarkerStyle
21+
from .transforms import Bbox, Transform
1922

2023
# The following are type aliases. Once python 3.9 is dropped, they should be annotated
2124
# using ``typing.TypeAlias`` and Unions should be converted to using ``|`` syntax.
@@ -48,6 +51,20 @@
4851
JoinStyleType = Union[JoinStyle, Literal["miter", "round", "bevel"]]
4952
CapStyleType = Union[CapStyle, Literal["butt", "projecting", "round"]]
5053

54+
CoordsBaseType = Union[
55+
str,
56+
Artist,
57+
Transform,
58+
Callable[
59+
[RendererBase],
60+
Union[Bbox, Transform]
61+
]
62+
]
63+
CoordsType = Union[
64+
CoordsBaseType,
65+
tuple[CoordsBaseType, CoordsBaseType]
66+
]
67+
5168
RcStyleType = Union[
5269
str,
5370
dict[str, Any],

0 commit comments

Comments
 (0)