🌐 AI搜索 & 代理 主页
Skip to content

Commit 7dc5eaa

Browse files
committed
Update matplotlib typing definitions to remove RcGroupType and RcParamKeyType
`Remove tools/update_rcparam_typing.py script` `Update matplotlib rc function to accept string group instead of RcGroupType` `Remove unused imports and docstrings`
1 parent 7e43f41 commit 7dc5eaa

File tree

4 files changed

+11
-159
lines changed

4 files changed

+11
-159
lines changed

lib/matplotlib/__init__.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import contextlib
3939
from packaging.version import Version
4040

4141
from matplotlib._api import MatplotlibDeprecationWarning
42-
from matplotlib.typing import LogLevel, RcGroupType, RcParamKeyType
42+
from matplotlib.typing import LogLevel
4343
from typing import Any, Literal, NamedTuple, overload
4444

4545

@@ -80,8 +80,6 @@ class RcParams(dict[str, Any]):
8080
def _ensure_has_backend(self) -> None: ...
8181
def __setitem__(self, key: str, val: Any) -> None: ...
8282
def __getitem__(self, key: str) -> Any: ...
83-
def get_typed(self, key: RcParamKeyType) -> Any: ...
84-
def set_typed(self, key: RcParamKeyType, val: Any) -> None: ...
8583
def __iter__(self) -> Generator[str, None, None]: ...
8684
def __len__(self) -> int: ...
8785
def find_all(self, pattern: str) -> RcParams: ...
@@ -99,7 +97,7 @@ rcParams: RcParams
9997
rcParamsOrig: RcParams
10098
defaultParams: dict[str, Any]
10199

102-
def rc(group: RcGroupType, **kwargs) -> None: ...
100+
def rc(group: str, **kwargs) -> None: ...
103101
def rcdefaults() -> None: ...
104102
def rc_file_defaults() -> None: ...
105103
def rc_file(

lib/matplotlib/pyplot.py

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import sys
5151
import threading
5252
import time
53-
from typing import IO, TYPE_CHECKING, cast, overload
53+
from typing import TYPE_CHECKING, cast, overload
5454

5555
from cycler import cycler # noqa: F401
5656
import matplotlib
@@ -100,14 +100,7 @@
100100
import matplotlib.backend_bases
101101
from matplotlib.axis import Tick
102102
from matplotlib.axes._base import _AxesBase
103-
from matplotlib.backend_bases import (
104-
CloseEvent,
105-
DrawEvent,
106-
KeyEvent,
107-
MouseEvent,
108-
PickEvent,
109-
ResizeEvent,
110-
)
103+
from matplotlib.backend_bases import Event
111104
from matplotlib.cm import ScalarMappable
112105
from matplotlib.contour import ContourSet, QuadContourSet
113106
from matplotlib.collections import (
@@ -133,18 +126,11 @@
133126
from matplotlib.quiver import Barbs, Quiver, QuiverKey
134127
from matplotlib.scale import ScaleBase
135128
from matplotlib.typing import (
136-
CloseEventType,
137129
ColorType,
138130
CoordsType,
139-
DrawEventType,
140131
HashableList,
141-
KeyEventType,
142132
LineStyleType,
143133
MarkerType,
144-
MouseEventType,
145-
PickEventType,
146-
ResizeEventType,
147-
RcGroupType,
148134
)
149135
from matplotlib.widgets import SubplotTool
150136

@@ -352,8 +338,8 @@ def uninstall_repl_displayhook() -> None:
352338

353339
# Ensure this appears in the pyplot docs.
354340
@_copy_docstring_and_deprecators(matplotlib.set_loglevel)
355-
def set_loglevel(level: str) -> None:
356-
return matplotlib.set_loglevel(level)
341+
def set_loglevel(*args, **kwargs) -> None:
342+
return matplotlib.set_loglevel(*args, **kwargs)
357343

358344

359345
@_copy_docstring_and_deprecators(Artist.findobj)
@@ -787,9 +773,10 @@ def pause(interval: float) -> None:
787773

788774

789775
@_copy_docstring_and_deprecators(matplotlib.rc)
790-
def rc(group: RcGroupType, **kwargs) -> None:
776+
def rc(group: str, **kwargs) -> None:
791777
matplotlib.rc(group, **kwargs)
792778

779+
793780
@_copy_docstring_and_deprecators(matplotlib.rc_context)
794781
def rc_context(
795782
rc: dict[str, Any] | None = None,
@@ -1188,32 +1175,8 @@ def get_current_fig_manager() -> FigureManagerBase | None:
11881175
return gcf().canvas.manager
11891176

11901177

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-
12151178
@_copy_docstring_and_deprecators(FigureCanvasBase.mpl_connect)
1216-
def connect(s, func) -> int:
1179+
def connect(s: str, func: Callable[[Event], Any]) -> int:
12171180
return gcf().canvas.mpl_connect(s, func)
12181181

12191182

@@ -1296,11 +1259,11 @@ def draw() -> None:
12961259

12971260

12981261
@_copy_docstring_and_deprecators(Figure.savefig)
1299-
def savefig(fname: str | os.PathLike | IO, **kwargs) -> None:
1262+
def savefig(*args, **kwargs) -> None:
13001263
fig = gcf()
13011264
# savefig default implementation has no return, so mypy is unhappy
13021265
# presumably this is here because subclasses can return?
1303-
res = fig.savefig(fname, **kwargs) # type: ignore[func-returns-value]
1266+
res = fig.savefig(*args, **kwargs) # type: ignore[func-returns-value]
13041267
fig.canvas.draw_idle() # Need this if 'transparent=True', to reset colors.
13051268
return res
13061269

lib/matplotlib/typing.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,6 @@
8080
LogLevel: TypeAlias = Literal["notset", "debug", "info", "warning", "error", "critical"]
8181
"""Valid string values for logging levels used in `set_loglevel`."""
8282

83-
RcGroupType: TypeAlias = Literal[
84-
"animation", "axes", "axes3d", "backend", "boxplot", "contour", "date",
85-
"errorbar", "figure", "font", "grid", "hatch", "image", "interactive",
86-
"keymap", "legend", "lines", "markers", "patch", "path", "pdf", "pgf", "ps",
87-
"savefig", "scatter", "text", "tk", "toolbar", "xtick", "ytick"
88-
]
89-
"""Valid values for the `group` parameter in `rc(group=...)`."""
90-
91-
# --- START GENERATED RcParamKeyType ---
92-
RcParamKeyType: TypeAlias = Literal[
93-
"_internal.classic_mode",
94-
95-
]
96-
# --- END GENERATED RcParamKeyType ---
97-
"""The keys are extracted directly from the matplotlib runtime via:
98-
`generate_rc_keys_once.py`
99-
To regenerate this block:
100-
1. Run `python tools/update_rc_keys_once.py`
101-
2. Replace the content between the START and END markers below
102-
"""
10383

10484
JoinStyleType: TypeAlias = JoinStyle | Literal["miter", "round", "bevel"]
10585
"""Line join styles. See :doc:`/gallery/lines_bars_and_markers/joinstyle`."""

tools/update_rcparam_typing.py

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)