Skip to content

Commit

Permalink
TYP: Fix xycoords and friends
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Jul 9, 2024
1 parent 0fd212d commit c21a83d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 87 deletions.
18 changes: 7 additions & 11 deletions lib/matplotlib/axes/_axes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ import numpy as np
from numpy.typing import ArrayLike
from matplotlib.typing import ColorType, MarkerType, LineStyleType

_coords_type_base = (
str | Artist | Transform | Callable[[RendererBase], Bbox | Transform]
)
_coords_type = _coords_type_base | tuple[_coords_type_base, _coords_type_base]

class Axes(_AxesBase):
def get_title(self, loc: Literal["left", "center", "right"] = ...) -> str: ...
def set_title(
Expand Down Expand Up @@ -122,17 +127,8 @@ class Axes(_AxesBase):
text: str,
xy: tuple[float, float],
xytext: tuple[float, float] | None = ...,
xycoords: str
| Artist
| Transform
| Callable[[RendererBase], Bbox | Transform]
| tuple[float, float] = ...,
textcoords: str
| Artist
| Transform
| Callable[[RendererBase], Bbox | Transform]
| tuple[float, float]
| None = ...,
xycoords: _coords_type = ...,
textcoords: _coords_type = ...,
arrowprops: dict[str, Any] | None = ...,
annotation_clip: bool | None = ...,
**kwargs
Expand Down
28 changes: 6 additions & 22 deletions lib/matplotlib/offsetbox.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import matplotlib.artist as martist
from matplotlib.axes._axes import _coords_type
from matplotlib.backend_bases import RendererBase, Event, FigureCanvasBase
from matplotlib.colors import Colormap, Normalize
import matplotlib.text as mtext
Expand Down Expand Up @@ -219,9 +220,7 @@ class AnnotationBbox(martist.Artist, mtext._AnnotationBase):
offsetbox: OffsetBox
arrowprops: dict[str, Any] | None
xybox: tuple[float, float]
boxcoords: str | tuple[str, str] | martist.Artist | Transform | Callable[
[RendererBase], Bbox | Transform
]
boxcoords: _coords_type
arrow_patch: FancyArrowPatch | None
patch: FancyBboxPatch
prop: FontProperties
Expand All @@ -230,17 +229,8 @@ class AnnotationBbox(martist.Artist, mtext._AnnotationBase):
offsetbox: OffsetBox,
xy: tuple[float, float],
xybox: tuple[float, float] | None = ...,
xycoords: str
| tuple[str, str]
| martist.Artist
| Transform
| Callable[[RendererBase], Bbox | Transform] = ...,
boxcoords: str
| tuple[str, str]
| martist.Artist
| Transform
| Callable[[RendererBase], Bbox | Transform]
| None = ...,
xycoords: _coords_type = ...,
boxcoords: _coords_type = ...,
*,
frameon: bool = ...,
pad: float = ...,
Expand All @@ -258,17 +248,11 @@ class AnnotationBbox(martist.Artist, mtext._AnnotationBase):
@property
def anncoords(
self,
) -> str | tuple[str, str] | martist.Artist | Transform | Callable[
[RendererBase], Bbox | Transform
]: ...
) -> _coords_type: ...
@anncoords.setter
def anncoords(
self,
coords: str
| tuple[str, str]
| martist.Artist
| Transform
| Callable[[RendererBase], Bbox | Transform],
coords: _coords_type,
) -> None: ...
def get_children(self) -> list[martist.Artist]: ...
def set_figure(self, fig: Figure) -> None: ...
Expand Down
13 changes: 2 additions & 11 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2858,17 +2858,8 @@ def annotate(
text: str,
xy: tuple[float, float],
xytext: tuple[float, float] | None = None,
xycoords: str
| Artist
| Transform
| Callable[[RendererBase], Bbox | Transform]
| tuple[float, float] = "data",
textcoords: str
| Artist
| Transform
| Callable[[RendererBase], Bbox | Transform]
| tuple[float, float]
| None = None,
xycoords: _coords_type = "data",
textcoords: _coords_type = None,
arrowprops: dict[str, Any] | None = None,
annotation_clip: bool | None = None,
**kwargs,
Expand Down
54 changes: 11 additions & 43 deletions lib/matplotlib/text.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .artist import Artist
from .axes._axes import _coords_type
from .backend_bases import RendererBase
from .font_manager import FontProperties
from .offsetbox import DraggableAnnotation
Expand Down Expand Up @@ -120,17 +121,11 @@ class OffsetFrom:

class _AnnotationBase:
xy: tuple[float, float]
xycoords: str | tuple[str, str] | Artist | Transform | Callable[
[RendererBase], Bbox | Transform
]
xycoords: _coords_type
def __init__(
self,
xy,
xycoords: str
| tuple[str, str]
| Artist
| Transform
| Callable[[RendererBase], Bbox | Transform] = ...,
xycoords: _coords_type = ...,
annotation_clip: bool | None = ...,
) -> None: ...
def set_annotation_clip(self, b: bool | None) -> None: ...
Expand All @@ -147,67 +142,40 @@ class Annotation(Text, _AnnotationBase):
text: str,
xy: tuple[float, float],
xytext: tuple[float, float] | None = ...,
xycoords: str
| tuple[str, str]
| Artist
| Transform
| Callable[[RendererBase], Bbox | Transform] = ...,
textcoords: str
| tuple[str, str]
| Artist
| Transform
| Callable[[RendererBase], Bbox | Transform]
| None = ...,
xycoords: _coords_type = ...,
textcoords: _coords_type = ...,
arrowprops: dict[str, Any] | None = ...,
annotation_clip: bool | None = ...,
**kwargs
) -> None: ...
@property
def xycoords(
self,
) -> str | tuple[str, str] | Artist | Transform | Callable[
[RendererBase], Bbox | Transform
]: ...
) -> _coords_type: ...
@xycoords.setter
def xycoords(
self,
xycoords: str
| tuple[str, str]
| Artist
| Transform
| Callable[[RendererBase], Bbox | Transform],
xycoords: _coords_type,
) -> None: ...
@property
def xyann(self) -> tuple[float, float]: ...
@xyann.setter
def xyann(self, xytext: tuple[float, float]) -> None: ...
def get_anncoords(
self,
) -> str | tuple[str, str] | Artist | Transform | Callable[
[RendererBase], Bbox | Transform
]: ...
) -> _coords_type: ...
def set_anncoords(
self,
coords: str
| tuple[str, str]
| Artist
| Transform
| Callable[[RendererBase], Bbox | Transform],
coords: _coords_type,
) -> None: ...
@property
def anncoords(
self,
) -> str | tuple[str, str] | Artist | Transform | Callable[
[RendererBase], Bbox | Transform
]: ...
) -> _coords_type: ...
@anncoords.setter
def anncoords(
self,
coords: str
| tuple[str, str]
| Artist
| Transform
| Callable[[RendererBase], Bbox | Transform],
coords: _coords_type,
) -> None: ...
def update_positions(self, renderer: RendererBase) -> None: ...
# Drops `dpi` parameter from superclass
Expand Down

0 comments on commit c21a83d

Please sign in to comment.