Skip to content

[TYP] Change typing for texts to StrLike #26867

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions lib/matplotlib/artist.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ from .figure import Figure, SubFigure
from .path import Path
from .patches import Patch
from .patheffects import AbstractPathEffect
from .text import Text
from .transforms import (
BboxBase,
Bbox,
Transform,
TransformedPatchPath,
TransformedPath,
)
from .typing import StrLike

import numpy as np

Expand Down Expand Up @@ -117,8 +119,8 @@ class Artist:
def set_visible(self, b: bool) -> None: ...
def set_animated(self, b: bool) -> None: ...
def set_in_layout(self, in_layout: bool) -> None: ...
def get_label(self) -> object: ...
def set_label(self, s: object) -> None: ...
def get_label(self) -> str | Text | None: ...
def set_label(self, s: StrLike | None) -> None: ...
def get_zorder(self) -> float: ...
def set_zorder(self, level: float) -> None: ...
@property
Expand Down
18 changes: 9 additions & 9 deletions lib/matplotlib/axes/_axes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ from collections.abc import Callable, Sequence
from typing import Any, Literal, overload
import numpy as np
from numpy.typing import ArrayLike
from matplotlib.typing import ColorType, MarkerType, LineStyleType
from matplotlib.typing import ColorType, MarkerType, LineStyleType, StrLike

class Axes(_AxesBase):
def get_title(self, loc: Literal["left", "center", "right"] = ...) -> str: ...
def set_title(
self,
label: str,
label: StrLike,
fontdict: dict[str, Any] | None = ...,
loc: Literal["left", "center", "right"] | None = ...,
pad: float | None = ...,
Expand Down Expand Up @@ -111,13 +111,13 @@ class Axes(_AxesBase):
self,
x: float,
y: float,
s: str,
s: StrLike,
fontdict: dict[str, Any] | None = ...,
**kwargs
) -> Text: ...
def annotate(
self,
text: str,
text: StrLike,
xy: tuple[float, float],
xytext: tuple[float, float] | None = ...,
xycoords: str
Expand Down Expand Up @@ -164,7 +164,7 @@ class Axes(_AxesBase):
xmax: float | ArrayLike,
colors: ColorType | Sequence[ColorType] | None = ...,
linestyles: LineStyleType = ...,
label: str = ...,
label: StrLike = ...,
*,
data=...,
**kwargs
Expand All @@ -176,7 +176,7 @@ class Axes(_AxesBase):
ymax: float | ArrayLike,
colors: ColorType | Sequence[ColorType] | None = ...,
linestyles: LineStyleType = ...,
label: str = ...,
label: StrLike = ...,
*,
data=...,
**kwargs
Expand Down Expand Up @@ -289,7 +289,7 @@ class Axes(_AxesBase):
markerfmt: str | None = ...,
basefmt: str | None = ...,
bottom: float = ...,
label: str | None = ...,
label: StrLike | None = ...,
orientation: Literal["vertical", "horizontal"] = ...,
data=...,
) -> StemContainer: ...
Expand Down Expand Up @@ -443,7 +443,7 @@ class Axes(_AxesBase):
self, x: float, y: float, dx: float, dy: float, **kwargs
) -> FancyArrow: ...
def quiverkey(
self, Q: Quiver, X: float, Y: float, U: float, label: str, **kwargs
self, Q: Quiver, X: float, Y: float, U: float, label: StrLike, **kwargs
) -> QuiverKey: ...
def quiver(self, *args, data=..., **kwargs) -> Quiver: ...
def barbs(self, *args, data=..., **kwargs) -> Barbs: ...
Expand Down Expand Up @@ -549,7 +549,7 @@ class Axes(_AxesBase):
rwidth: float | None = ...,
log: bool = ...,
color: ColorType | Sequence[ColorType] | None = ...,
label: str | Sequence[str] | None = ...,
label: StrLike | Sequence[StrLike] | None = ...,
stacked: bool = ...,
*,
data=...,
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/axes/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ from cycler import Cycler
import numpy as np
from numpy.typing import ArrayLike
from typing import Any, Literal, TypeVar, overload
from matplotlib.typing import ColorType
from matplotlib.typing import ColorType, StrLike

_T = TypeVar("_T", bound=Artist)

Expand Down Expand Up @@ -305,7 +305,7 @@ class _AxesBase(martist.Artist):
def get_xlabel(self) -> str: ...
def set_xlabel(
self,
xlabel: str,
xlabel: StrLike,
fontdict: dict[str, Any] | None = ...,
labelpad: float | None = ...,
*,
Expand All @@ -331,7 +331,7 @@ class _AxesBase(martist.Artist):
def get_ylabel(self) -> str: ...
def set_ylabel(
self,
ylabel: str,
ylabel: StrLike,
fontdict: dict[str, Any] | None = ...,
labelpad: float | None = ...,
*,
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/axis.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ from matplotlib.lines import Line2D
from matplotlib.text import Text
from matplotlib.ticker import Locator, Formatter
from matplotlib.transforms import Transform, Bbox
from matplotlib.typing import ColorType
from matplotlib.typing import ColorType, StrLike


GRIDLINE_INTERPOLATION_STEPS: int
Expand Down Expand Up @@ -211,7 +211,7 @@ class Axis(martist.Artist):
def set_units(self, u) -> None: ...
def get_units(self): ...
def set_label_text(
self, label: str, fontdict: dict[str, Any] | None = ..., **kwargs
self, label: StrLike, fontdict: dict[str, Any] | None = ..., **kwargs
) -> Text: ...
def set_major_formatter(
self, formatter: Formatter | str | Callable[[float, float], str]
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/colorbar.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import numpy as np
from numpy.typing import ArrayLike
from collections.abc import Sequence
from typing import Any, Literal, overload
from .typing import ColorType
from .typing import ColorType, StrLike

class _ColorbarSpine(mspines.Spines):
def __init__(self, axes: Axes): ...
Expand Down Expand Up @@ -59,7 +59,7 @@ class Colorbar:
drawedges: bool = ...,
extendfrac: Literal["auto"] | float | Sequence[float] | None = ...,
extendrect: bool = ...,
label: str = ...,
label: StrLike = ...,
location: Literal["left", "right", "top", "bottom"] | None = ...
) -> None: ...
@property
Expand Down Expand Up @@ -108,7 +108,7 @@ class Colorbar:
) -> None: ...
def minorticks_on(self) -> None: ...
def minorticks_off(self) -> None: ...
def set_label(self, label: str, *, loc: str | None = ..., **kwargs) -> None: ...
def set_label(self, label: StrLike, *, loc: str | None = ..., **kwargs) -> None: ...
def set_alpha(self, alpha: float | np.ndarray) -> None: ...
def remove(self) -> None: ...
def drag_pan(self, button: Any, key: Any, x: float, y: float) -> None: ...
Expand Down
7 changes: 4 additions & 3 deletions lib/matplotlib/offsetbox.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from matplotlib.font_manager import FontProperties
from matplotlib.image import BboxImage
from matplotlib.patches import FancyArrowPatch, FancyBboxPatch
from matplotlib.transforms import Bbox, BboxBase, Transform
from matplotlib.typing import StrLike

import numpy as np
from numpy.typing import ArrayLike
Expand Down Expand Up @@ -117,12 +118,12 @@ class TextArea(OffsetBox):
offset_transform: Transform
def __init__(
self,
s: str,
s: StrLike,
*,
textprops: dict[str, Any] | None = ...,
multilinebaseline: bool = ...,
) -> None: ...
def set_text(self, s: str) -> None: ...
def set_text(self, s: StrLike) -> None: ...
def get_text(self) -> str: ...
def set_multilinebaseline(self, t: bool) -> None: ...
def get_multilinebaseline(self) -> bool: ...
Expand Down Expand Up @@ -180,7 +181,7 @@ class AnchoredText(AnchoredOffsetbox):
txt: TextArea
def __init__(
self,
s: str,
s: StrLike,
loc: str,
*,
pad: float = ...,
Expand Down
23 changes: 12 additions & 11 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
from matplotlib.quiver import Barbs, Quiver, QuiverKey
from matplotlib.scale import ScaleBase
from matplotlib.transforms import Transform, Bbox
from matplotlib.typing import ColorType, LineStyleType, MarkerType, HashableList
from matplotlib.typing import (ColorType, HashableList, LineStyleType, MarkerType,
StrLike)
from matplotlib.widgets import SubplotTool

_P = ParamSpec('_P')
Expand Down Expand Up @@ -2640,7 +2641,7 @@ def angle_spectrum(
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@_copy_docstring_and_deprecators(Axes.annotate)
def annotate(
text: str,
text: StrLike,
xy: tuple[float, float],
xytext: tuple[float, float] | None = None,
xycoords: str
Expand Down Expand Up @@ -3222,7 +3223,7 @@ def hist(
rwidth: float | None = None,
log: bool = False,
color: ColorType | Sequence[ColorType] | None = None,
label: str | Sequence[str] | None = None,
label: StrLike | Sequence[StrLike] | None = None,
stacked: bool = False,
*,
data=None,
Expand Down Expand Up @@ -3315,7 +3316,7 @@ def hlines(
xmax: float | ArrayLike,
colors: ColorType | Sequence[ColorType] | None = None,
linestyles: LineStyleType = "solid",
label: str = "",
label: StrLike = "",
*,
data=None,
**kwargs,
Expand Down Expand Up @@ -3670,7 +3671,7 @@ def quiver(*args, data=None, **kwargs) -> Quiver:
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@_copy_docstring_and_deprecators(Axes.quiverkey)
def quiverkey(
Q: Quiver, X: float, Y: float, U: float, label: str, **kwargs
Q: Quiver, X: float, Y: float, U: float, label: StrLike, **kwargs
) -> QuiverKey:
return gca().quiverkey(Q, X, Y, U, label, **kwargs)

Expand Down Expand Up @@ -3827,7 +3828,7 @@ def stem(
markerfmt: str | None = None,
basefmt: str | None = None,
bottom: float = 0,
label: str | None = None,
label: StrLike | None = None,
orientation: Literal["vertical", "horizontal"] = "vertical",
data=None,
) -> StemContainer:
Expand Down Expand Up @@ -3951,7 +3952,7 @@ def table(
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@_copy_docstring_and_deprecators(Axes.text)
def text(
x: float, y: float, s: str, fontdict: dict[str, Any] | None = None, **kwargs
x: float, y: float, s: StrLike, fontdict: dict[str, Any] | None = None, **kwargs
) -> Text:
return gca().text(x, y, s, fontdict=fontdict, **kwargs)

Expand Down Expand Up @@ -4077,7 +4078,7 @@ def vlines(
ymax: float | ArrayLike,
colors: ColorType | Sequence[ColorType] | None = None,
linestyles: LineStyleType = "solid",
label: str = "",
label: StrLike = "",
*,
data=None,
**kwargs,
Expand Down Expand Up @@ -4128,7 +4129,7 @@ def sci(im: ScalarMappable) -> None:
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@_copy_docstring_and_deprecators(Axes.set_title)
def title(
label: str,
label: StrLike,
fontdict: dict[str, Any] | None = None,
loc: Literal["left", "center", "right"] | None = None,
pad: float | None = None,
Expand All @@ -4142,7 +4143,7 @@ def title(
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@_copy_docstring_and_deprecators(Axes.set_xlabel)
def xlabel(
xlabel: str,
xlabel: StrLike,
fontdict: dict[str, Any] | None = None,
labelpad: float | None = None,
*,
Expand All @@ -4157,7 +4158,7 @@ def xlabel(
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@_copy_docstring_and_deprecators(Axes.set_ylabel)
def ylabel(
ylabel: str,
ylabel: StrLike,
fontdict: dict[str, Any] | None = None,
labelpad: float | None = None,
*,
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/quiver.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import numpy as np
from numpy.typing import ArrayLike
from collections.abc import Sequence
from typing import Any, Literal, overload
from matplotlib.typing import ColorType
from matplotlib.typing import ColorType, StrLike

class QuiverKey(martist.Artist):
halign: dict[Literal["N", "S", "E", "W"], Literal["left", "center", "right"]]
Expand All @@ -23,7 +23,7 @@ class QuiverKey(martist.Artist):
angle: float
coord: Literal["axes", "figure", "data", "inches"]
color: ColorType | None
label: str
label: StrLike
labelpos: Literal["N", "S", "E", "W"]
labelcolor: ColorType | None
fontproperties: dict[str, Any]
Expand All @@ -36,7 +36,7 @@ class QuiverKey(martist.Artist):
X: float,
Y: float,
U: float,
label: str,
label: StrLike,
*,
angle: float = ...,
coordinates: Literal["axes", "figure", "data", "inches"] = ...,
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/sankey.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from matplotlib.axes import Axes
from matplotlib.typing import StrLike

from collections.abc import Callable, Iterable
from typing import Any
Expand Down Expand Up @@ -46,7 +47,7 @@ class Sankey:
) -> None: ...
def add(
self,
patchlabel: str = ...,
patchlabel: StrLike = ...,
flows: Iterable[float] | None = ...,
orientations: Iterable[int] | None = ...,
labels: str | Iterable[str | None] = ...,
Expand Down
Loading