Skip to content

Commit 94e6f7b

Browse files
committed
Redistribute types defined in _typing to their logical homes
1 parent 333de75 commit 94e6f7b

30 files changed

+94
-79
lines changed

Diff for: lib/matplotlib/_color_data.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ._typing import Color
1+
from .colors import Color
22

33
BASE_COLORS: dict[str, Color]
44
TABLEAU_COLORS: dict[str, Color]

Diff for: lib/matplotlib/axes/_axes.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ from matplotlib.collections import (
1212
EventCollection,
1313
QuadMesh,
1414
)
15-
from matplotlib.colors import Colormap, Normalize
15+
from matplotlib.colors import Color, Colormap, Normalize
1616
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
1717
from matplotlib.contour import ContourSet, QuadContourSet
1818
from matplotlib.image import AxesImage, PcolorImage
1919
from matplotlib.legend import Legend
2020
from matplotlib.legend_handler import HandlerBase
21-
from matplotlib.lines import Line2D
21+
from matplotlib.lines import Line2D, LineStyleType
22+
from matplotlib.markers import MarkerType
2223
from matplotlib.mlab import GaussianKDE
2324
from matplotlib.patches import Rectangle, FancyArrow, Polygon, StepPatch
2425
from matplotlib.quiver import Quiver, QuiverKey, Barbs
@@ -28,7 +29,6 @@ import matplotlib.tri as mtri
2829
import matplotlib.table as mtable
2930
import matplotlib.stackplot as mstack
3031
import matplotlib.streamplot as mstream
31-
from matplotlib._typing import Color, LineStyleType, MarkerType
3232

3333
import datetime
3434
import PIL

Diff for: lib/matplotlib/axes/_base.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from matplotlib.backend_bases import RendererBase, MouseButton, MouseEvent
99
from matplotlib.cbook import index_of
1010
from matplotlib.container import Container
1111
from matplotlib.collections import Collection
12+
from matplotlib.colors import Color
1213
from matplotlib.cm import ScalarMappable
1314
from matplotlib.legend import Legend
1415
from matplotlib.lines import Line2D
@@ -28,7 +29,6 @@ from cycler import Cycler
2829
import numpy as np
2930
from numpy.typing import ArrayLike
3031
from typing import Any, Callable, Literal, Iterable, Iterator, Sequence, Type, overload
31-
from matplotlib._typing import Color
3232

3333
class _axis_method_wrapper:
3434
attr_name: str

Diff for: lib/matplotlib/axes/_secondary_axes.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from matplotlib.axes._base import _AxesBase
22
from matplotlib.axis import Axis, Tick
33

4+
from matplotlib.colors import Color
45
from matplotlib.transforms import Transform
5-
from matplotlib._typing import Color
66

77
from typing import Literal, Callable, Iterable
88
from numpy.typing import ArrayLike

Diff for: lib/matplotlib/axis.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import matplotlib.artist as martist
22
from matplotlib import cbook
33
from matplotlib.axes import Axes
44
from matplotlib.backend_bases import RendererBase
5+
from matplotlib.colors import Color
56
from matplotlib.lines import Line2D
67
from matplotlib.text import Text
78
from matplotlib.ticker import Locator, Formatter
89
from matplotlib.transforms import Transform, Bbox
910

1011
import datetime
1112
from typing import Any, Literal, Type, Iterable, Callable
12-
from matplotlib._typing import Color
1313
import numpy as np
1414
from numpy.typing import ArrayLike
1515

Diff for: lib/matplotlib/backend_bases.pyi

+2-8
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@ from matplotlib.axes import Axes
1919
from matplotlib.backend_managers import ToolManager
2020
from matplotlib.backend_tools import Cursors, ToolBase
2121
from matplotlib.colorbar import Colorbar
22+
from matplotlib.colors import Color
2223
from matplotlib.figure import Figure
2324
from matplotlib.font_manager import FontProperties
25+
from matplotlib.lines import LineStyleType
2426
from matplotlib.path import Path
2527
from matplotlib.texmanager import TexManager
2628
from matplotlib.text import Text
2729
from matplotlib.transforms import Affine2D, Transform, TransformedPath, Bbox
28-
from matplotlib._typing import (
29-
Color,
30-
LineStyleType,
31-
FillStyleType,
32-
DrawStyleType,
33-
MarkerType,
34-
MarkEveryType,
35-
)
3630

3731
from typing import Any, Callable, Literal, NamedTuple, Sequence, Type, TypeVar
3832
from numpy.typing import ArrayLike

Diff for: lib/matplotlib/collections.pyi

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
from . import artist, cbook, cm, transforms
22
from .backend_bases import MouseEvent
33
from .artist import Artist
4-
from .colors import Normalize, Colormap
4+
from .colors import Color, Normalize, Colormap
5+
from .lines import LineStyleType
56
from .path import Path
67
from .patches import Patch
78
from .ticker import Locator, Formatter
89
from .tri import Triangulation
910
from ._enums import CapStyle, JoinStyle
10-
from ._typing import (
11-
LineStyleType,
12-
FillStyleType,
13-
DrawStyleType,
14-
MarkerType,
15-
MarkEveryType,
16-
Color,
17-
)
1811

1912
import numpy as np
2013
from numpy.typing import ArrayLike

Diff for: lib/matplotlib/colorbar.pyi

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ from matplotlib.axes import Axes
44
from matplotlib.patches import Patch
55
from matplotlib.ticker import Locator, Formatter
66

7-
from matplotlib._typing import Color
8-
97
import numpy as np
108
from numpy.typing import ArrayLike
119
from typing import Any, Literal, Sequence, overload
@@ -80,7 +78,7 @@ class Colorbar:
8078
def add_lines(
8179
self,
8280
levels: ArrayLike,
83-
colors: Color | Sequence[Color],
81+
colors: colors.Color | Sequence[colors.Color],
8482
linewidths: float | ArrayLike,
8583
erase: bool = ...,
8684
) -> None: ...

Diff for: lib/matplotlib/colors.py

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import itertools
4949
from numbers import Real
5050
import re
51+
from typing import Union
52+
5153
from PIL import Image
5254
from PIL.PngImagePlugin import PngInfo
5355

@@ -56,6 +58,12 @@
5658
from matplotlib import _api, _cm, cbook, scale
5759
from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS
5860

61+
Color = Union[
62+
tuple[float, float, float],
63+
tuple[float, float, float, float],
64+
str,
65+
]
66+
5967

6068
class _ColorMapping(dict):
6169
def __init__(self, mapping):

Diff for: lib/matplotlib/colors.pyi

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ from collections.abc import Mapping
33
from matplotlib import cbook, scale
44
import re
55

6-
from ._typing import Color
7-
from typing import Any, Callable, Sequence, Iterable, Iterator, Literal, Type, overload
6+
from typing import Any, Callable, Sequence, Iterable, Iterator, Literal, Type, Union, overload
87

98
import numpy as np
109
from numpy.typing import ArrayLike
1110

11+
Color = Union[tuple[float, float, float], tuple[float, float, float, float], str]
12+
1213
class _ColorMapping(dict[str, Color]):
1314
cache: dict[tuple[Color, float | None], tuple[float, float, float, float]]
1415
def __init__(self, mapping) -> None: ...

Diff for: lib/matplotlib/contour.pyi

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ from matplotlib.artist import Artist
33
from matplotlib.axes import Axes
44
from matplotlib.backend_bases import MouseButton
55
from matplotlib.collections import Collection, PathCollection
6-
from matplotlib.colors import Colormap, Normalize
6+
from matplotlib.colors import Color, Colormap, Normalize
77
from matplotlib.font_manager import FontProperties
88
from matplotlib.text import Text
99
from matplotlib.transforms import Transform
1010
from matplotlib.ticker import Locator, Formatter
1111

12-
from matplotlib._typing import Color
1312
from numpy.typing import ArrayLike
1413
import numpy as np
1514
from typing import Any, Callable, Literal, Iterable, Sequence

Diff for: lib/matplotlib/figure.pyi

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ from matplotlib.backend_bases import (
1212
NonGuiException,
1313
RendererBase,
1414
)
15-
from matplotlib.colors import Colormap, Normalize
15+
from matplotlib.colors import Color, Colormap, Normalize
1616
from matplotlib.colorbar import Colorbar
1717
from matplotlib.cm import ScalarMappable
1818
from matplotlib.gridspec import GridSpec, SubplotSpec
@@ -36,8 +36,6 @@ from matplotlib.transforms import (
3636
Transform,
3737
)
3838

39-
from matplotlib._typing import Color
40-
4139
import numpy as np
4240
from numpy.typing import ArrayLike
4341

Diff for: lib/matplotlib/legend.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from matplotlib.collections import (
1111
PolyCollection,
1212
RegularPolyCollection,
1313
)
14+
from matplotlib.colors import Color
1415
from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer
1516
from matplotlib.figure import Figure
1617
from matplotlib.font_manager import FontProperties
@@ -35,7 +36,6 @@ from matplotlib.transforms import (
3536
Transform,
3637
)
3738

38-
from matplotlib._typing import Color
3939

4040
import pathlib
4141
from typing import Any, Literal, Iterable, Type, overload

Diff for: lib/matplotlib/lines.py

+16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from numbers import Integral, Number, Real
88
import logging
9+
from typing import Literal, Sequence, Union
910

1011
import numpy as np
1112

@@ -1606,3 +1607,18 @@ def onpick(self, event):
16061607
lineMarkers = MarkerStyle.markers
16071608
drawStyles = Line2D.drawStyles
16081609
fillStyles = MarkerStyle.fillstyles
1610+
1611+
LineStyleType = Union[str, tuple[float, Sequence[float]]]
1612+
DrawStyleType = Literal[
1613+
"default", "steps", "steps-pre", "steps-mid", "steps-post"
1614+
]
1615+
MarkEveryType = Union[
1616+
None,
1617+
int,
1618+
tuple[int, int],
1619+
slice,
1620+
list[int],
1621+
float,
1622+
tuple[float, float],
1623+
list[bool],
1624+
]

Diff for: lib/matplotlib/lines.pyi

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from .artist import Artist, allow_rasterization
44
from .axes import Axes
55
from .backend_bases import MouseEvent, FigureCanvasBase
66
from .cbook import STEP_LOOKUP_MAP, ls_mapper, ls_mapper_r
7+
from .colors import Color
78
from .markers import (
89
CARETDOWN,
910
CARETDOWNBASE,
@@ -18,17 +19,11 @@ from .markers import (
1819
TICKRIGHT,
1920
TICKUP,
2021
MarkerStyle,
22+
MarkerType,
23+
FillStyleType,
2124
)
2225
from .path import Path
2326
from .transforms import Bbox, BboxTransformTo, TransformedPath, Transform
24-
from ._typing import (
25-
Color,
26-
LineStyleType,
27-
FillStyleType,
28-
DrawStyleType,
29-
MarkerType,
30-
MarkEveryType,
31-
)
3227

3328
from typing import Any, Literal, Sequence, Union, Callable, overload
3429
from numpy.typing import ArrayLike
@@ -158,4 +153,10 @@ class VertexSelector:
158153
lineStyles: dict[str, str]
159154
lineMarkers: dict[str | int, str]
160155
drawStyles: dict[str, str]
161-
fillStyles: tuple[str, ...]
156+
fillStyles: tuple[FillStyleType, ...]
157+
158+
LineStyleType = Union[str, tuple[float, Sequence[float]]]
159+
DrawStyleType = Literal["default", "steps", "steps-pre", "steps-mid", "steps-post"]
160+
MarkEveryType = Union[
161+
None, int, tuple[int, int], slice, list[int], float, tuple[float, float], list[bool]
162+
]

Diff for: lib/matplotlib/markers.py

+5
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
import copy
136136

137137
from collections.abc import Sized
138+
from typing import Union, Literal
138139

139140
import numpy as np
140141

@@ -921,3 +922,7 @@ def _set_x_filled(self):
921922
self._transform.rotate_deg(
922923
{'top': 0, 'left': 90, 'bottom': 180, 'right': 270}[fs])
923924
self._alt_transform = self._transform.frozen().rotate_deg(180)
925+
926+
927+
MarkerType = Union[str, Path, MarkerStyle]
928+
FillStyleType = Literal["full", "left", "right", "bottom", "top", "none"]

Diff for: lib/matplotlib/markers.pyi

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from .path import Path
44
from .transforms import Affine2D, IdentityTransform, Transform
55

66
from numpy.typing import ArrayLike
7-
from typing import Literal
7+
from typing import Literal, Union
88

99
TICKLEFT: int
1010
TICKRIGHT: int
@@ -22,12 +22,11 @@ CARETDOWNBASE: int
2222
class MarkerStyle:
2323
markers: dict[str | int, str]
2424
filled_markers: tuple[str, ...]
25-
fillstyles: tuple[str, ...]
25+
fillstyles: tuple[FillStyleType, ...]
2626
def __init__(
2727
self,
2828
marker: str | ArrayLike | Path | MarkerStyle | None = ...,
29-
fillstyle: Literal["full", "left", "right", "bottom", "top", "none"]
30-
| None = ...,
29+
fillstyle: FillStyleType | None = ...,
3130
transform: Transform | None = ...,
3231
capstyle: CapStyle | None = ...,
3332
joinstyle: JoinStyle | None = ...,
@@ -36,7 +35,7 @@ class MarkerStyle:
3635
def is_filled(self) -> bool: ...
3736
def get_fillstyle(
3837
self,
39-
) -> Literal["full", "left", "right", "bottom", "top", "none"]: ...
38+
) -> FillStyleType: ...
4039
def get_joinstyle(self) -> JoinStyle: ...
4140
def get_capstyle(self) -> CapStyle: ...
4241
def get_marker(self) -> str | ArrayLike | Path | MarkerStyle | None: ...
@@ -51,3 +50,6 @@ class MarkerStyle:
5150
self, *, deg: float | None = ..., rad: float | None = ...
5251
) -> MarkerStyle: ...
5352
def scaled(self, sx: float, sy: float | None = ...) -> MarkerStyle: ...
53+
54+
MarkerType = Union[str, Path, MarkerStyle]
55+
FillStyleType = Literal["full", "left", "right", "bottom", "top", "none"]

Diff for: lib/matplotlib/mathtext.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import os
33
from ._mathtext import RasterParse, VectorParse, get_unicode_index
44
from matplotlib.font_manager import FontProperties
55
from matplotlib.ft2font import FT2Image, LOAD_NO_HINTING
6-
from matplotlib._typing import Color
6+
from matplotlib.colors import Color
77

88
from typing import Literal
99

Diff for: lib/matplotlib/patches.pyi

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ from .bezier import (
1212
split_bezier_intersecting_with_closedpath,
1313
split_path_inout,
1414
)
15+
from .colors import Color
16+
from .lines import LineStyleType
1517
from .path import Path
1618
from .transforms import Transform, Bbox
17-
from ._typing import Color, LineStyleType
1819

1920
from typing import Any, Literal, Type, overload
2021

Diff for: lib/matplotlib/patheffects.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from matplotlib.backend_bases import RendererBase, GraphicsContextBase
2+
from matplotlib.colors import Color
23
from matplotlib.path import Path
34
from matplotlib.patches import Patch
45
from matplotlib.transforms import Transform
56

67
from typing import Iterable, Sequence
7-
from matplotlib._typing import Color
88

99
class AbstractPathEffect:
1010
def __init__(self, offset: tuple[float, float] = ...) -> None: ...

0 commit comments

Comments
 (0)