Skip to content

[MNT] Use Literal for level parameter in set_loglevel (#30257) #30260

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@

import atexit
from collections import namedtuple
from typing import Literal
from collections.abc import MutableMapping
import contextlib
import functools
Expand All @@ -154,6 +155,7 @@
import sys
import tempfile


from packaging.version import parse as parse_version

# cbook must import matplotlib only within function
Expand Down Expand Up @@ -281,7 +283,9 @@ def _ensure_handler():
return handler


def set_loglevel(level):
def set_loglevel(
level: Literal["notset", "debug", "info", "warning", "error", "critical"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have in-line types anywhere else in the code. I think this belongs in the pyi file. Note that this function is basically obsolete.

):
"""
Configure Matplotlib's logging levels.

Expand Down Expand Up @@ -309,7 +313,6 @@ def set_loglevel(level):
The first time this function is called, an additional handler is attached
to Matplotlib's root handler; this handler is reused every time and this
function simply manipulates the logger and handler's level.

"""
_log.setLevel(level.upper())
_ensure_handler().setLevel(level.upper())
Expand Down
Loading