From 3122d36047e7833b296bb902a6a227937ebe1b50 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 29 Oct 2025 23:06:42 -0400 Subject: [PATCH 1/2] TST: Rename test_cm_stubs to be more general --- lib/matplotlib/tests/{test_cm_stubs.py => test_typing.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/matplotlib/tests/{test_cm_stubs.py => test_typing.py} (100%) diff --git a/lib/matplotlib/tests/test_cm_stubs.py b/lib/matplotlib/tests/test_typing.py similarity index 100% rename from lib/matplotlib/tests/test_cm_stubs.py rename to lib/matplotlib/tests/test_typing.py From b7018203d0660b37efa8acd5d989da6d3427c8df Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 30 Oct 2025 01:54:06 -0400 Subject: [PATCH 2/2] Add testing for rcParams Literal type hints And also add some new ones that were missing. --- lib/matplotlib/tests/test_typing.py | 19 +++++++++++++++++++ lib/matplotlib/typing.py | 18 ++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_typing.py b/lib/matplotlib/tests/test_typing.py index 2305c91a5301..c9fc8e5b162f 100644 --- a/lib/matplotlib/tests/test_typing.py +++ b/lib/matplotlib/tests/test_typing.py @@ -1,8 +1,10 @@ import re +import typing from pathlib import Path import matplotlib.pyplot as plt from matplotlib.colors import Colormap +from matplotlib.typing import RcKeyType, RcGroupKeyType def test_cm_stub_matches_runtime_colormaps(): @@ -30,3 +32,20 @@ def test_cm_stub_matches_runtime_colormaps(): ) assert runtime_cmaps == stubbed_cmaps + + +def test_rcparam_stubs(): + runtime_rc_keys = { + name for name in plt.rcParamsDefault.keys() + if not name.startswith('_') + } + + assert {*typing.get_args(RcKeyType)} == runtime_rc_keys + + runtime_rc_group_keys = set() + for name in runtime_rc_keys: + groups = name.split('.') + for i in range(1, len(groups)): + runtime_rc_group_keys.add('.'.join(groups[:i])) + + assert {*typing.get_args(RcGroupKeyType)} == runtime_rc_group_keys diff --git a/lib/matplotlib/typing.py b/lib/matplotlib/typing.py index 10bbe6334328..3a9f74e2cfd1 100644 --- a/lib/matplotlib/typing.py +++ b/lib/matplotlib/typing.py @@ -217,6 +217,8 @@ "axes.ymargin", "axes.zmargin", "axes3d.automargin", + "axes3d.depthshade", + "axes3d.depthshade_minalpha", "axes3d.grid", "axes3d.mouserotationstyle", "axes3d.trackballborder", @@ -304,6 +306,7 @@ "figure.titlesize", "figure.titleweight", "font.cursive", + "font.enable_last_resort", "font.family", "font.fantasy", "font.monospace", @@ -318,6 +321,14 @@ "grid.color", "grid.linestyle", "grid.linewidth", + "grid.major.alpha", + "grid.major.color", + "grid.major.linestyle", + "grid.major.linewidth", + "grid.minor.alpha", + "grid.minor.color", + "grid.minor.linestyle", + "grid.minor.linewidth", "hatch.color", "hatch.linewidth", "hist.bins", @@ -492,7 +503,7 @@ "ytick.minor.size", "ytick.minor.visible", "ytick.minor.width", - "ytick.right" + "ytick.right", ] RcGroupKeyType: TypeAlias = Literal[ @@ -524,6 +535,8 @@ "figure.subplot", "font", "grid", + "grid.major", + "grid.minor", "hatch", "hist", "image", @@ -546,6 +559,7 @@ "scatter", "svg", "text", + "text.latex", "tk", "webagg", "xaxis", @@ -555,5 +569,5 @@ "yaxis", "ytick", "ytick.major", - "ytick.minor" + "ytick.minor", ]