From 1e8487de35302af43c6c8cdff67ee3da3f549ef6 Mon Sep 17 00:00:00 2001 From: N R Navaneet Date: Fri, 4 Jul 2025 19:23:22 +0530 Subject: [PATCH 1/3] [MNT] Use Literal for loglevel in set_loglevel (#30257) --- lib/matplotlib/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index e98e8ea07502..bbbe61efdcc2 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -137,6 +137,7 @@ import atexit from collections import namedtuple +from typing import Literal from collections.abc import MutableMapping import contextlib import functools @@ -154,6 +155,7 @@ import sys import tempfile + from packaging.version import parse as parse_version # cbook must import matplotlib only within function @@ -281,7 +283,9 @@ def _ensure_handler(): return handler -def set_loglevel(level): +def set_loglevel( + level: Literal["notset", "debug", "info", "warning", "error", "critical"] +): """ Configure Matplotlib's logging levels. @@ -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()) From e7e441954629ebf18af581d0f85d8f25a2fac60e Mon Sep 17 00:00:00 2001 From: N R Navaneet <156576749+nrnavaneet@users.noreply.github.com> Date: Sun, 13 Jul 2025 01:43:55 +0530 Subject: [PATCH 2/3] Update __init__.py --- lib/matplotlib/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index bbbe61efdcc2..84f2c69165bc 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -283,9 +283,7 @@ def _ensure_handler(): return handler -def set_loglevel( - level: Literal["notset", "debug", "info", "warning", "error", "critical"] -): +def set_loglevel(level): """ Configure Matplotlib's logging levels. From 12f05602bfb0a9d96e77028977105949cd0c839f Mon Sep 17 00:00:00 2001 From: N R Navaneet <156576749+nrnavaneet@users.noreply.github.com> Date: Sun, 13 Jul 2025 01:44:25 +0530 Subject: [PATCH 3/3] Update __init__.py --- lib/matplotlib/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 84f2c69165bc..4903739e8936 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -137,7 +137,6 @@ import atexit from collections import namedtuple -from typing import Literal from collections.abc import MutableMapping import contextlib import functools