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

Conversation

nrnavaneet
Copy link
Contributor

Summary

This PR replaces the str type annotation with typing.Literal for the level parameter in matplotlib.set_loglevel. This improves static type checking and IDE autocompletion for common log levels.

Changes

  • Introduced Literal type for accepted log level values: "notset", "debug", "info", "warning", "error", "critical"
  • Helps clarify valid values to users and tooling without changing runtime behavior

Notes

  • No logic has been changed
  • No tests were added since this is strictly a typing improvement

Closes #30257

@timhoffm
Copy link
Member

timhoffm commented Jul 4, 2025

Please apply the same change to pyplot.set_loglevel

@@ -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.

@ZPyrolink
Copy link
Contributor

I think create a new TypeAlias in matplotlib.typing can be a good idea. With this, we have the Literal in a single file, and we can use it everywhere is required (matplotlib and pyplot here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MNT] [TYPING]: Use of Literal
4 participants