Skip to content

Commit 3d7b644

Browse files
committed
Create connect overloads on pyplot
1 parent f3e2966 commit 3d7b644

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

lib/matplotlib/pyplot.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@
100100
import matplotlib.backend_bases
101101
from matplotlib.axis import Tick
102102
from matplotlib.axes._base import _AxesBase
103-
from matplotlib.backend_bases import Event
103+
from matplotlib.backend_bases import (
104+
CloseEvent,
105+
DrawEvent,
106+
KeyEvent,
107+
MouseEvent,
108+
PickEvent,
109+
ResizeEvent,
110+
)
104111
from matplotlib.cm import ScalarMappable
105112
from matplotlib.contour import ContourSet, QuadContourSet
106113
from matplotlib.collections import (
@@ -126,12 +133,17 @@
126133
from matplotlib.quiver import Barbs, Quiver, QuiverKey
127134
from matplotlib.scale import ScaleBase
128135
from matplotlib.typing import (
136+
CloseEventType,
129137
ColorType,
130138
CoordsType,
139+
DrawEventType,
131140
HashableList,
141+
KeyEventType,
132142
LineStyleType,
133143
MarkerType,
134-
EventType
144+
MouseEventType,
145+
PickEventType,
146+
ResizeEventType,
135147
)
136148
from matplotlib.widgets import SubplotTool
137149

@@ -1176,8 +1188,32 @@ def get_current_fig_manager() -> FigureManagerBase | None:
11761188
return gcf().canvas.manager
11771189

11781190

1191+
@overload
1192+
def connect(s: MouseEventType, func: Callable[[MouseEvent], Any]) -> int: ...
1193+
1194+
1195+
@overload
1196+
def connect(s: KeyEventType, func: Callable[[KeyEvent], Any]) -> int: ...
1197+
1198+
1199+
@overload
1200+
def connect(s: PickEventType, func: Callable[[PickEvent], Any]) -> int: ...
1201+
1202+
1203+
@overload
1204+
def connect(s: ResizeEventType, func: Callable[[ResizeEvent], Any]) -> int: ...
1205+
1206+
1207+
@overload
1208+
def connect(s: CloseEventType, func: Callable[[CloseEvent], Any]) -> int: ...
1209+
1210+
1211+
@overload
1212+
def connect(s: DrawEventType, func: Callable[[DrawEvent], Any]) -> int: ...
1213+
1214+
11791215
@_copy_docstring_and_deprecators(FigureCanvasBase.mpl_connect)
1180-
def connect(s: EventType, func: Callable[[Event], Any]) -> int:
1216+
def connect(s, func) -> int:
11811217
return gcf().canvas.mpl_connect(s, func)
11821218

11831219

0 commit comments

Comments
 (0)