From 2ea9371733fdad796962c02932abc6abb66d6405 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Mon, 21 Jul 2025 22:52:50 +0200 Subject: [PATCH 1/2] MNT: Prefer capitalized logging levels #30302 just introduced literals for the log levels. Previously, the situation was a bit vague: While the docstring described the levels as all lowercase, in fact any casing is accepted. This PR changes the preferred casing to be all-capitalized in analogy to the logging standard library, which only supports this casing. Lowercase remains supported because it's not worth an API breakage. We might later consider to also accept logging levels directly, i.e. `logging.DEBUG` to be more congruent with the logging library. But this can be done any time. It's important to get this PR in soon to not release the typing Literal in lowercase form. --- doc/devel/coding_guide.rst | 2 +- doc/devel/troubleshooting.rst | 2 +- doc/install/index.rst | 2 +- doc/users/faq.rst | 2 +- lib/matplotlib/__init__.py | 12 ++++++++---- lib/matplotlib/typing.py | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/doc/devel/coding_guide.rst b/doc/devel/coding_guide.rst index 2b156cedca05..fe7769909368 100644 --- a/doc/devel/coding_guide.rst +++ b/doc/devel/coding_guide.rst @@ -215,7 +215,7 @@ If an end-user of Matplotlib sets up `logging` to display at levels more verbose than ``logging.WARNING`` in their code with the Matplotlib-provided helper:: - plt.set_loglevel("debug") + plt.set_loglevel("DEBUG") or manually with :: diff --git a/doc/devel/troubleshooting.rst b/doc/devel/troubleshooting.rst index 74ce81b2da00..e57cfcb92bd6 100644 --- a/doc/devel/troubleshooting.rst +++ b/doc/devel/troubleshooting.rst @@ -23,7 +23,7 @@ mode:: git clean -xfd git pull python -m pip install -v . > build.out - python -c "from pylab import *; set_loglevel('debug'); plot(); show()" > run.out + python -c "from pylab import *; set_loglevel('DEBUG'); plot(); show()" > run.out and post :file:`build.out` and :file:`run.out` to the `matplotlib-devel `_ diff --git a/doc/install/index.rst b/doc/install/index.rst index 3e6452eb2f41..6ac79cc8c133 100644 --- a/doc/install/index.rst +++ b/doc/install/index.rst @@ -179,7 +179,7 @@ development environment such as :program:`IDLE` which add additional complexities. Open up a UNIX shell or a DOS command prompt and run, for example:: - python -c "from pylab import *; set_loglevel('debug'); plot(); show()" + python -c "from pylab import *; set_loglevel('DEBUG'); plot(); show()" This will give you additional information about which backends Matplotlib is loading, version information, and more. At this point you might want to make diff --git a/doc/users/faq.rst b/doc/users/faq.rst index c6bbc5ca8d87..d13625ec9907 100644 --- a/doc/users/faq.rst +++ b/doc/users/faq.rst @@ -367,7 +367,7 @@ provide the following information in your e-mail to the `mailing list * Matplotlib provides debugging information through the `logging` library, and a helper function to set the logging level: one can call :: - plt.set_loglevel("info") # or "debug" for more info + plt.set_loglevel("INFO") # or "DEBUG" for more info to obtain this debugging information. diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 03d288efe342..b7177c068f36 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -292,8 +292,8 @@ def set_loglevel(level): - set the root logger handler's level, creating the handler if it does not exist yet - Typically, one should call ``set_loglevel("info")`` or - ``set_loglevel("debug")`` to get additional debugging information. + Typically, one should call ``set_loglevel("INFO")`` or + ``set_loglevel("DEBUG")`` to get additional debugging information. Users or applications that are installing their own logging handlers may want to directly manipulate ``logging.getLogger('matplotlib')`` rather @@ -301,8 +301,12 @@ def set_loglevel(level): Parameters ---------- - level : {"notset", "debug", "info", "warning", "error", "critical"} - The log level of the handler. + level : {"NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"} + The log level as defined in `Python logging levels + `__. + + For backwards compatibility, the levels are case-insensitive, but + the capitalized version is preferred in analogy to `.Logger.setLevel`. Notes ----- diff --git a/lib/matplotlib/typing.py b/lib/matplotlib/typing.py index 440d888c20f4..899013f27bde 100644 --- a/lib/matplotlib/typing.py +++ b/lib/matplotlib/typing.py @@ -93,7 +93,7 @@ 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"] +LogLevel: TypeAlias = Literal["NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] """Literal type for valid logging levels accepted by `set_loglevel()`.""" CoordsBaseType = Union[ From afeeaf3e600f726960e2de19a435ff6938e59dd6 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Tue, 22 Jul 2025 07:05:07 +0200 Subject: [PATCH 2/2] Update lib/matplotlib/__init__.py Co-authored-by: Thomas A Caswell --- lib/matplotlib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index b7177c068f36..e9eba105c5e1 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -306,7 +306,7 @@ def set_loglevel(level): `__. For backwards compatibility, the levels are case-insensitive, but - the capitalized version is preferred in analogy to `.Logger.setLevel`. + the capitalized version is preferred in analogy to `logging.Logger.setLevel`. Notes ----- 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