Skip to content

Commit 85885a4

Browse files
committed
TYP: Mark more items as optional
These can be set to `None` in their `__init__` or the property setter.
1 parent 503cbb2 commit 85885a4

17 files changed

+32
-34
lines changed

lib/matplotlib/artist.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,7 @@ def set_clip_box(self, clipbox):
757757
758758
Parameters
759759
----------
760-
clipbox : `.Bbox`
761-
760+
clipbox : `.Bbox` or None
762761
Typically would be created from a `.TransformedBbox`. For
763762
instance ``TransformedBbox(Bbox([[0, 0], [1, 1]]), ax.transAxes)``
764763
is the default clipping for an artist added to an Axes.

lib/matplotlib/artist.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Artist:
5151
def remove_callback(self, oid: int) -> None: ...
5252
def pchanged(self) -> None: ...
5353
def is_transform_set(self) -> bool: ...
54-
def set_transform(self, t: Transform) -> None: ...
54+
def set_transform(self, t: Transform | None) -> None: ...
5555
def get_transform(self) -> Transform: ...
5656
def get_children(self) -> list[Artist]: ...
5757
# TODO can these dicts be type narrowed? e.g. str keys
@@ -87,7 +87,7 @@ class Artist:
8787
def get_path_effects(self) -> list[AbstractPathEffect]: ...
8888
def get_figure(self) -> Figure | None: ...
8989
def set_figure(self, fig: Figure) -> None: ...
90-
def set_clip_box(self, clipbox: Bbox) -> None: ...
90+
def set_clip_box(self, clipbox: Bbox | None) -> None: ...
9191
def set_clip_path(
9292
self,
9393
path: Patch | Path | TransformedPath | TransformedPatchPath | None,

lib/matplotlib/axes/_axes.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Axes(_AxesBase):
5252
def get_legend_handles_labels(
5353
self, legend_handler_map: dict[type, HandlerBase] | None = ...
5454
) -> tuple[list[Artist], list[Any]]: ...
55-
legend_: Legend
55+
legend_: Legend | None
5656

5757
@overload
5858
def legend(self) -> Legend: ...

lib/matplotlib/backend_bases.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class GraphicsContextBase:
168168
def set_url(self, url: str | None) -> None: ...
169169
def set_gid(self, id: int | None) -> None: ...
170170
def set_snap(self, snap: bool | None) -> None: ...
171-
def set_hatch(self, hatch: str) -> None: ...
171+
def set_hatch(self, hatch: str | None) -> None: ...
172172
def get_hatch(self) -> str | None: ...
173173
def get_hatch_path(self, density: float = ...) -> Path: ...
174174
def get_hatch_color(self) -> ColorType: ...
@@ -386,8 +386,8 @@ class FigureManagerBase:
386386
num: int | str
387387
key_press_handler_id: int | None
388388
button_press_handler_id: int | None
389-
toolmanager: ToolManager
390-
toolbar: NavigationToolbar2
389+
toolmanager: ToolManager | None
390+
toolbar: NavigationToolbar2 | ToolContainerBase | None
391391
def __init__(self, canvas: FigureCanvasBase, num: int | str) -> None: ...
392392
@classmethod
393393
def create_with_canvas(

lib/matplotlib/colorbar.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Colorbar:
2323
n_rasterize: int
2424
mappable: cm.ScalarMappable
2525
ax: Axes
26-
alpha: float
26+
alpha: float | None
2727
cmap: colors.Colormap
2828
norm: colors.Normalize
2929
values: Sequence[float] | None

lib/matplotlib/image.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class _ImageBase(martist.Artist, cm.ScalarMappable):
7474
def set_array(self, A: ArrayLike | None) -> None: ...
7575
def get_shape(self) -> tuple[int, int, int]: ...
7676
def get_interpolation(self) -> str: ...
77-
def set_interpolation(self, s: str) -> None: ...
77+
def set_interpolation(self, s: str | None) -> None: ...
7878
def set_interpolation_stage(self, s: Literal["data", "rgba"]) -> None: ...
7979
def can_composite(self) -> bool: ...
8080
def set_resample(self, v: bool | None) -> None: ...

lib/matplotlib/legend.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class Legend(Artist):
128128
draw_frame = set_frame_on
129129
def get_bbox_to_anchor(self) -> BboxBase: ...
130130
def set_bbox_to_anchor(
131-
self, bbox: BboxBase, transform: Transform | None = ...
131+
self, bbox: BboxBase | None, transform: Transform | None = ...
132132
) -> None: ...
133133
@overload
134134
def set_draggable(

lib/matplotlib/lines.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class Line2D(Artist):
7676
def set_data(self, x: ArrayLike, y: ArrayLike) -> None: ...
7777
def recache_always(self) -> None: ...
7878
def recache(self, always: bool = ...) -> None: ...
79-
def set_transform(self, t: Transform) -> None: ...
8079
def get_antialiased(self) -> bool: ...
8180
def get_color(self) -> ColorType: ...
8281
def get_drawstyle(self) -> DrawStyleType: ...

lib/matplotlib/offsetbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _get_packed_offsets(widths, total, sep, mode="fixed"):
107107
Widths of boxes to be packed.
108108
total : float or None
109109
Intended total length. *None* if not used.
110-
sep : float
110+
sep : float or None
111111
Spacing between boxes.
112112
mode : {'fixed', 'expand', 'equal'}
113113
The packing mode.

lib/matplotlib/offsetbox.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def bbox_artist(*args, **kwargs) -> None: ...
1919
def _get_packed_offsets(
2020
widths: Sequence[float],
2121
total: float | None,
22-
sep: float,
22+
sep: float | None,
2323
mode: Literal["fixed", "expand", "equal"] = ...,
2424
) -> tuple[float, np.ndarray]: ...
2525

@@ -114,7 +114,6 @@ class DrawingArea(OffsetBox):
114114
@clip_children.setter
115115
def clip_children(self, val: bool) -> None: ...
116116
def get_transform(self) -> Transform: ...
117-
def set_transform(self, t: Transform) -> None: ...
118117

119118
# does not accept all options of superclass
120119
def set_offset(self, xy: tuple[float, float]) -> None: ... # type: ignore[override]
@@ -134,7 +133,6 @@ class TextArea(OffsetBox):
134133
def get_text(self) -> str: ...
135134
def set_multilinebaseline(self, t: bool) -> None: ...
136135
def get_multilinebaseline(self) -> bool: ...
137-
def set_transform(self, t: Transform) -> None: ...
138136

139137
# does not accept all options of superclass
140138
def set_offset(self, xy: tuple[float, float]) -> None: ... # type: ignore[override]
@@ -147,7 +145,6 @@ class AuxTransformBox(OffsetBox):
147145
def __init__(self, aux_transform: Transform) -> None: ...
148146
def add_artist(self, a: martist.Artist) -> None: ...
149147
def get_transform(self) -> Transform: ...
150-
def set_transform(self, t: Transform) -> None: ...
151148

152149
# does not accept all options of superclass
153150
def set_offset(self, xy: tuple[float, float]) -> None: ... # type: ignore[override]

0 commit comments

Comments
 (0)