Skip to content

Commit 0555206

Browse files
committed
Add Literal-based LogLevel type alias and use it in set_loglevel for stricter typing.
1 parent 1663e9a commit 0555206

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lib/matplotlib/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ from packaging.version import Version
4040

4141
from matplotlib._api import MatplotlibDeprecationWarning
4242
from typing import Any, Literal, NamedTuple, overload
43+
from matplotlib.typing import LogLevel
44+
4345

4446
class _VersionInfo(NamedTuple):
4547
major: int
@@ -52,7 +54,7 @@ __bibtex__: str
5254
__version__: str
5355
__version_info__: _VersionInfo
5456

55-
def set_loglevel(level: str) -> None: ...
57+
def set_loglevel(level: LogLevel) -> None: ...
5658

5759
class _ExecInfo(NamedTuple):
5860
executable: str

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
MouseEventType,
145145
PickEventType,
146146
ResizeEventType,
147+
LogLevel
147148
)
148149
from matplotlib.widgets import SubplotTool
149150

@@ -351,7 +352,7 @@ def uninstall_repl_displayhook() -> None:
351352

352353
# Ensure this appears in the pyplot docs.
353354
@_copy_docstring_and_deprecators(matplotlib.set_loglevel)
354-
def set_loglevel(level: str) -> None:
355+
def set_loglevel(level: LogLevel) -> None:
355356
return matplotlib.set_loglevel(level)
356357

357358

lib/matplotlib/typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@
8383
CapStyleType: TypeAlias = CapStyle | Literal["butt", "projecting", "round"]
8484
"""Line cap styles. See :doc:`/gallery/lines_bars_and_markers/capstyle`."""
8585

86+
LogLevel: TypeAlias = Literal["notset", "debug", "info", "warning", "error", "critical"]
87+
"""Literal type for valid logging levels accepted by `set_loglevel()`."""
88+
8689
CoordsBaseType = Union[
8790
str,
8891
Artist,

0 commit comments

Comments
 (0)