Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 85885a4

Browse filesBrowse 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
Copy full SHA for 85885a4
Expand file treeCollapse file tree

17 files changed

+32
-34
lines changed

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+1-2Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.pyi
+2-2Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.pyi
+1-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.pyi
+3-3Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/colorbar.pyi
+1-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/image.pyi
+1-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/legend.pyi
+1-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/lines.pyi
-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/offsetbox.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/offsetbox.pyi
+1-4Lines 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]

‎lib/matplotlib/projections/polar.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/projections/polar.pyi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class PolarAxes(Axes):
158158
def get_rmax(self) -> float: ...
159159
def set_rmin(self, rmin: float) -> None: ...
160160
def get_rmin(self) -> float: ...
161-
def set_rorigin(self, rorigin: float) -> None: ...
161+
def set_rorigin(self, rorigin: float | None) -> None: ...
162162
def get_rorigin(self) -> float: ...
163163
def get_rsign(self) -> float: ...
164164
def set_rlim(

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878

7979
import numpy as np
8080

81-
from typing import TYPE_CHECKING
81+
from typing import TYPE_CHECKING, cast
8282

8383
if TYPE_CHECKING:
8484
from collections.abc import Callable, Hashable, Iterable, Sequence
@@ -1803,7 +1803,7 @@ def twiny(ax: matplotlib.axes.Axes | None = None) -> _AxesBase:
18031803
return ax1
18041804

18051805

1806-
def subplot_tool(targetfig: Figure | None = None) -> SubplotTool:
1806+
def subplot_tool(targetfig: Figure | None = None) -> SubplotTool | None:
18071807
"""
18081808
Launch a subplot tool window for a figure.
18091809
@@ -1815,9 +1815,12 @@ def subplot_tool(targetfig: Figure | None = None) -> SubplotTool:
18151815
targetfig = gcf()
18161816
tb = targetfig.canvas.manager.toolbar # type: ignore[union-attr]
18171817
if hasattr(tb, "configure_subplots"): # toolbar2
1818-
return tb.configure_subplots()
1818+
from matplotlib.backend_bases import NavigationToolbar2
1819+
return cast(NavigationToolbar2, tb).configure_subplots()
18191820
elif hasattr(tb, "trigger_tool"): # toolmanager
1820-
return tb.trigger_tool("subplots")
1821+
from matplotlib.backend_bases import ToolContainerBase
1822+
cast(ToolContainerBase, tb).trigger_tool("subplots")
1823+
return None
18211824
else:
18221825
raise ValueError("subplot_tool can only be launched for figures with "
18231826
"an associated toolbar")

‎lib/matplotlib/scale.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/scale.pyi
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from typing import Literal
66
from numpy.typing import ArrayLike
77

88
class ScaleBase:
9-
def __init__(self, axis: Axis) -> None: ...
9+
def __init__(self, axis: Axis | None) -> None: ...
1010
def get_transform(self) -> Transform: ...
1111
def set_default_locators_and_formatters(self, axis: Axis) -> None: ...
1212
def limit_range_for_scale(
@@ -30,7 +30,7 @@ class FuncScale(ScaleBase):
3030
name: str
3131
def __init__(
3232
self,
33-
axis: Axis,
33+
axis: Axis | None,
3434
functions: tuple[
3535
Callable[[ArrayLike], ArrayLike], Callable[[ArrayLike], ArrayLike]
3636
],
@@ -57,7 +57,7 @@ class LogScale(ScaleBase):
5757
subs: Iterable[int] | None
5858
def __init__(
5959
self,
60-
axis: Axis,
60+
axis: Axis | None,
6161
*,
6262
base: float = ...,
6363
subs: Iterable[int] | None = ...,
@@ -70,7 +70,7 @@ class LogScale(ScaleBase):
7070
class FuncScaleLog(LogScale):
7171
def __init__(
7272
self,
73-
axis: Axis,
73+
axis: Axis | None,
7474
functions: tuple[
7575
Callable[[ArrayLike], ArrayLike], Callable[[ArrayLike], ArrayLike]
7676
],
@@ -104,7 +104,7 @@ class SymmetricalLogScale(ScaleBase):
104104
subs: Iterable[int] | None
105105
def __init__(
106106
self,
107-
axis: Axis,
107+
axis: Axis | None,
108108
*,
109109
base: float = ...,
110110
linthresh: float = ...,
@@ -138,7 +138,7 @@ class AsinhScale(ScaleBase):
138138
auto_tick_multipliers: dict[int, tuple[int, ...]]
139139
def __init__(
140140
self,
141-
axis: Axis,
141+
axis: Axis | None,
142142
*,
143143
linear_width: float = ...,
144144
base: float = ...,
@@ -165,7 +165,7 @@ class LogitScale(ScaleBase):
165165
name: str
166166
def __init__(
167167
self,
168-
axis: Axis,
168+
axis: Axis | None,
169169
nonpositive: Literal["mask", "clip"] = ...,
170170
*,
171171
one_half: str = ...,

‎lib/matplotlib/spines.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/spines.pyi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ from typing import Literal, TypeVar, overload
1111
class Spine(mpatches.Patch):
1212
axes: Axes
1313
spine_type: str
14-
axis: Path
14+
axis: Axis | None
1515
def __init__(self, axes: Axes, spine_type: str, path: Path, **kwargs) -> None: ...
1616
def set_patch_arc(
1717
self, center: tuple[float, float], radius: float, theta1: float, theta2: float

‎lib/matplotlib/table.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/table.pyi
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Cell(Rectangle):
2424
text: str = ...,
2525
loc: Literal["left", "center", "right"] | None = ...,
2626
fontproperties: dict[str, Any] | None = ...,
27-
visible_edges: str = ...
27+
visible_edges: str | None = ...
2828
) -> None: ...
2929
def get_text(self) -> Text: ...
3030
def set_fontsize(self, size: float) -> None: ...
@@ -38,7 +38,7 @@ class Cell(Rectangle):
3838
@property
3939
def visible_edges(self) -> str: ...
4040
@visible_edges.setter
41-
def visible_edges(self, value: str) -> None: ...
41+
def visible_edges(self, value: str | None) -> None: ...
4242
def get_path(self) -> Path: ...
4343

4444
CustomCell = Cell

‎lib/matplotlib/tri/_triangulation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tri/_triangulation.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Triangulation:
2828
For each triangle, the indices of the three points that make
2929
up the triangle, ordered in an anticlockwise manner. If you want to
3030
take the *mask* into account, use `get_masked_triangles` instead.
31-
mask : (ntri, 3) array of bool
31+
mask : (ntri, 3) array of bool or None
3232
Masked out triangles.
3333
is_delaunay : bool
3434
Whether the Triangulation is a calculated Delaunay

‎lib/matplotlib/tri/_triangulation.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/tri/_triangulation.pyi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from typing import Any
88
class Triangulation:
99
x: np.ndarray
1010
y: np.ndarray
11-
mask: np.ndarray
11+
mask: np.ndarray | None
1212
is_delaunay: bool
1313
triangles: np.ndarray
1414
def __init__(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.