Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41c530e

Browse files
committed
TYP: Clean up CapStyle/FillStyle type hints
Inputs generally accept either the enum or the raw string (literal), outputs are only the string literals plotnine passes string literals, which are accepted, but did not previously type check
1 parent 7103779 commit 41c530e

File tree

6 files changed

+45
-36
lines changed

6 files changed

+45
-36
lines changed

doc/api/typing_api.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
.. autodata:: matplotlib.typing.DrawStyleType
99
.. autodata:: matplotlib.typing.MarkEveryType
1010
.. autodata:: matplotlib.typing.FillStyleType
11+
.. autodata:: matplotlib.typing.CapStyleType
12+
.. autodata:: matplotlib.typing.JoinStyleType
1113
.. autodata:: matplotlib.typing.RcStyleType

lib/matplotlib/backend_bases.pyi

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ from matplotlib import (
1111
widgets,
1212
_api,
1313
)
14-
from matplotlib._enums import CapStyle, JoinStyle
1514
from matplotlib._pylab_helpers import Gcf
1615
from matplotlib.artist import Artist
1716
from matplotlib.axes import Axes
@@ -28,7 +27,7 @@ from matplotlib.transforms import Affine2D, Transform, TransformedPath, Bbox
2827
from collections.abc import Callable, Iterable, Sequence
2928
from typing import Any, IO, Literal, NamedTuple, TypeVar
3029
from numpy.typing import ArrayLike
31-
from .typing import ColorType, LineStyleType
30+
from .typing import ColorType, LineStyleType, CapStyleType, JoinStyleType
3231

3332
def register_backend(
3433
format: str, backend: str | type[FigureCanvasBase], description: str | None = ...
@@ -150,27 +149,27 @@ class GraphicsContextBase:
150149
def restore(self) -> None: ...
151150
def get_alpha(self) -> float: ...
152151
def get_antialiased(self) -> int: ...
153-
def get_capstyle(self) -> CapStyle: ...
152+
def get_capstyle(self) -> Literal["butt", "projecting", "round"]: ...
154153
def get_clip_rectangle(self) -> Bbox | None: ...
155154
def get_clip_path(
156155
self,
157156
) -> tuple[TransformedPath, Transform] | tuple[None, None]: ...
158157
def get_dashes(self) -> tuple[float, ArrayLike | None]: ...
159158
def get_forced_alpha(self) -> bool: ...
160-
def get_joinstyle(self) -> JoinStyle: ...
159+
def get_joinstyle(self) -> Literal["miter", "round", "bevel"]: ...
161160
def get_linewidth(self) -> float: ...
162161
def get_rgb(self) -> tuple[float, float, float, float]: ...
163162
def get_url(self) -> str | None: ...
164163
def get_gid(self) -> int | None: ...
165164
def get_snap(self) -> bool | None: ...
166165
def set_alpha(self, alpha: float) -> None: ...
167166
def set_antialiased(self, b: bool) -> None: ...
168-
def set_capstyle(self, cs: CapStyle) -> None: ...
167+
def set_capstyle(self, cs: CapStyleType) -> None: ...
169168
def set_clip_rectangle(self, rectangle: Bbox | None) -> None: ...
170169
def set_clip_path(self, path: TransformedPath | None) -> None: ...
171170
def set_dashes(self, dash_offset: float, dash_list: ArrayLike | None) -> None: ...
172171
def set_foreground(self, fg: ColorType, isRGBA: bool = ...) -> None: ...
173-
def set_joinstyle(self, js: JoinStyle) -> None: ...
172+
def set_joinstyle(self, js: JoinStyleType) -> None: ...
174173
def set_linewidth(self, w: float) -> None: ...
175174
def set_url(self, url: str | None) -> None: ...
176175
def set_gid(self, id: int | None) -> None: ...

lib/matplotlib/collections.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import numpy as np
1212
from numpy.typing import ArrayLike
1313
from collections.abc import Callable, Iterable, Sequence
1414
from typing import Literal
15-
from .typing import ColorType, LineStyleType
15+
from .typing import ColorType, LineStyleType, CapStyleType, JoinStyleType
1616

1717
class Collection(artist.Artist, cm.ScalarMappable):
1818
def __init__(
@@ -22,8 +22,8 @@ class Collection(artist.Artist, cm.ScalarMappable):
2222
facecolors: ColorType | Sequence[ColorType] | None = ...,
2323
linewidths: float | Sequence[float] | None = ...,
2424
linestyles: LineStyleType | Sequence[LineStyleType] = ...,
25-
capstyle: CapStyle | None = ...,
26-
joinstyle: JoinStyle | None = ...,
25+
capstyle: CapStyleType | None = ...,
26+
joinstyle: JoinStyleType | None = ...,
2727
antialiaseds: bool | Sequence[bool] | None = ...,
2828
offsets: tuple[float, float] | Sequence[tuple[float, float]] | None = ...,
2929
offset_transform: transforms.Transform | None = ...,
@@ -51,10 +51,10 @@ class Collection(artist.Artist, cm.ScalarMappable):
5151
def get_offsets(self) -> ArrayLike: ...
5252
def set_linewidth(self, lw: float | Sequence[float]) -> None: ...
5353
def set_linestyle(self, ls: LineStyleType | Sequence[LineStyleType]) -> None: ...
54-
def set_capstyle(self, cs: CapStyle | Sequence[CapStyle]) -> None: ...
55-
def get_capstyle(self) -> CapStyle | Sequence[CapStyle]: ...
56-
def set_joinstyle(self, js: JoinStyle | Sequence[JoinStyle]) -> None: ...
57-
def get_joinstyle(self) -> JoinStyle | Sequence[JoinStyle]: ...
54+
def set_capstyle(self, cs: CapStyleType) -> None: ...
55+
def get_capstyle(self) -> Literal["butt", "projecting", "round"]: ...
56+
def set_joinstyle(self, js: JoinStyleType) -> None: ...
57+
def get_joinstyle(self) -> Literal["miter", "round", "bevel"]: ...
5858
def set_antialiased(self, aa: bool | Sequence[bool]) -> None: ...
5959
def set_color(self, c: ColorType | Sequence[ColorType]) -> None: ...
6060
def set_facecolor(self, c: ColorType | Sequence[ColorType]) -> None: ...

lib/matplotlib/lines.pyi

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from . import cbook
2-
from ._enums import CapStyle, JoinStyle
32
from .artist import Artist, allow_rasterization
43
from .axes import Axes
54
from .backend_bases import MouseEvent, FigureCanvasBase
@@ -23,9 +22,16 @@ from .path import Path
2322
from .transforms import Bbox, BboxTransformTo, TransformedPath, Transform
2423

2524
from collections.abc import Callable, Sequence
26-
from typing import Any, overload
25+
from typing import Any, Literal, overload
2726
from .typing import (
28-
ColorType, DrawStyleType, FillStyleType, LineStyleType, MarkEveryType, MarkerType
27+
ColorType,
28+
DrawStyleType,
29+
FillStyleType,
30+
LineStyleType,
31+
CapStyleType,
32+
JoinStyleType,
33+
MarkEveryType,
34+
MarkerType,
2935
)
3036
from numpy.typing import ArrayLike
3137

@@ -59,10 +65,10 @@ class Line2D(Artist):
5965
markerfacecoloralt: ColorType = ...,
6066
fillstyle: FillStyleType | None = ...,
6167
antialiased: bool | None = ...,
62-
dash_capstyle: CapStyle | None = ...,
63-
solid_capstyle: CapStyle | None = ...,
64-
dash_joinstyle: JoinStyle | None = ...,
65-
solid_joinstyle: JoinStyle | None = ...,
68+
dash_capstyle: CapStyleType | None = ...,
69+
solid_capstyle: CapStyleType | None = ...,
70+
dash_joinstyle: JoinStyleType | None = ...,
71+
solid_joinstyle: JoinStyleType | None = ...,
6672
pickradius: float = ...,
6773
drawstyle: DrawStyleType | None = ...,
6874
markevery: MarkEveryType | None = ...,
@@ -121,14 +127,14 @@ class Line2D(Artist):
121127
def set_ydata(self, y: ArrayLike) -> None: ...
122128
def set_dashes(self, seq: Sequence[float] | tuple[None, None]) -> None: ...
123129
def update_from(self, other: Artist) -> None: ...
124-
def set_dash_joinstyle(self, s: JoinStyle) -> None: ...
125-
def set_solid_joinstyle(self, s: JoinStyle) -> None: ...
126-
def get_dash_joinstyle(self) -> str: ...
127-
def get_solid_joinstyle(self) -> str: ...
128-
def set_dash_capstyle(self, s: CapStyle) -> None: ...
129-
def set_solid_capstyle(self, s: CapStyle) -> None: ...
130-
def get_dash_capstyle(self) -> str: ...
131-
def get_solid_capstyle(self) -> str: ...
130+
def set_dash_joinstyle(self, s: JoinStyleType) -> None: ...
131+
def set_solid_joinstyle(self, s: JoinStyleType) -> None: ...
132+
def get_dash_joinstyle(self) -> Literal["miter", "round", "bevel"]: ...
133+
def get_solid_joinstyle(self) -> Literal["miter", "round", "bevel"]: ...
134+
def set_dash_capstyle(self, s: CapStyleType) -> None: ...
135+
def set_solid_capstyle(self, s: CapStyleType) -> None: ...
136+
def get_dash_capstyle(self) -> Literal["butt", "projecting", "round"]: ...
137+
def get_solid_capstyle(self) -> Literal["butt", "projecting", "round"]: ...
132138
def is_dashed(self) -> bool: ...
133139

134140
class _AxLine(Line2D):

lib/matplotlib/patches.pyi

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from . import artist, cbook, colors, transforms
22
from .axes import Axes
3-
from ._enums import CapStyle, JoinStyle
43
from .backend_bases import RendererBase, MouseEvent
54
from .bezier import (
65
NonIntersectingPathException,
@@ -19,7 +18,7 @@ from typing import Any, Literal, overload
1918

2019
import numpy as np
2120
from numpy.typing import ArrayLike
22-
from .typing import ColorType, LineStyleType
21+
from .typing import ColorType, LineStyleType, CapStyleType, JoinStyleType
2322

2423
class Patch(artist.Artist):
2524
zorder: float
@@ -34,8 +33,8 @@ class Patch(artist.Artist):
3433
antialiased: bool | None = ...,
3534
hatch: str | None = ...,
3635
fill: bool = ...,
37-
capstyle: CapStyle | None = ...,
38-
joinstyle: JoinStyle | None = ...,
36+
capstyle: CapStyleType | None = ...,
37+
joinstyle: JoinStyleType | None = ...,
3938
**kwargs,
4039
) -> None: ...
4140
def get_verts(self) -> ArrayLike: ...
@@ -65,10 +64,10 @@ class Patch(artist.Artist):
6564
def set_fill(self, b: bool) -> None: ...
6665
def get_fill(self) -> bool: ...
6766
fill = property(get_fill, set_fill)
68-
def set_capstyle(self, s: CapStyle) -> None: ...
69-
def get_capstyle(self) -> CapStyle: ...
70-
def set_joinstyle(self, s: JoinStyle) -> None: ...
71-
def get_joinstyle(self) -> JoinStyle: ...
67+
def set_capstyle(self, s: CapStyleType) -> None: ...
68+
def get_capstyle(self) -> Literal["butt", "projecting", "round"]: ...
69+
def set_joinstyle(self, s: JoinStyleType) -> None: ...
70+
def get_joinstyle(self) -> Literal["miter", "round", "bevel"]: ...
7271
def set_hatch(self, hatch: str) -> None: ...
7372
def get_hatch(self) -> str: ...
7473
def get_path(self) -> Path: ...

lib/matplotlib/typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from typing import Any, Hashable, Literal, Union
1515

1616
from . import path
17+
from ._enums import JoinStyle, CapStyle
1718
from .markers import MarkerStyle
1819

1920
# The following are type aliases. Once python 3.9 is dropped, they should be annotated
@@ -37,6 +38,8 @@
3738

3839
MarkerType = Union[str, path.Path, MarkerStyle]
3940
FillStyleType = Literal["full", "left", "right", "bottom", "top", "none"]
41+
JoinStyleType = JoinStyle | Literal["miter", "round", "bevel"]
42+
CapStyleType = CapStyle | Literal["butt", "projecting", "round"]
4043

4144
RcStyleType = Union[
4245
str, dict[str, Any], pathlib.Path, list[Union[str, pathlib.Path, dict[str, Any]]]

0 commit comments

Comments
 (0)