Skip to content

[MNT] Typing: Use Literal for set_loglevel #30302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/matplotlib/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ from packaging.version import Version

from matplotlib._api import MatplotlibDeprecationWarning
from typing import Any, Literal, NamedTuple, overload
from matplotlib.typing import LogLevel


class _VersionInfo(NamedTuple):
major: int
Expand All @@ -52,7 +54,7 @@ __bibtex__: str
__version__: str
__version_info__: _VersionInfo

def set_loglevel(level: str) -> None: ...
def set_loglevel(level: LogLevel) -> None: ...

class _ExecInfo(NamedTuple):
executable: str
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
MouseEventType,
PickEventType,
ResizeEventType,
LogLevel
)
from matplotlib.widgets import SubplotTool

Expand Down Expand Up @@ -351,7 +352,7 @@ def uninstall_repl_displayhook() -> None:

# Ensure this appears in the pyplot docs.
@_copy_docstring_and_deprecators(matplotlib.set_loglevel)
def set_loglevel(level: str) -> None:
def set_loglevel(level: LogLevel) -> None:
return matplotlib.set_loglevel(level)


Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
CapStyleType: TypeAlias = CapStyle | Literal["butt", "projecting", "round"]
"""Line cap styles. See :doc:`/gallery/lines_bars_and_markers/capstyle`."""

LogLevel: TypeAlias = Literal["notset", "debug", "info", "warning", "error", "critical"]
"""Literal type for valid logging levels accepted by `set_loglevel()`."""

CoordsBaseType = Union[
str,
Artist,
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy