Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b701820

Browse files
committed
Add testing for rcParams Literal type hints
And also add some new ones that were missing.
1 parent 3122d36 commit b701820

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

lib/matplotlib/tests/test_typing.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import re
2+
import typing
23
from pathlib import Path
34

45
import matplotlib.pyplot as plt
56
from matplotlib.colors import Colormap
7+
from matplotlib.typing import RcKeyType, RcGroupKeyType
68

79

810
def test_cm_stub_matches_runtime_colormaps():
@@ -30,3 +32,20 @@ def test_cm_stub_matches_runtime_colormaps():
3032
)
3133

3234
assert runtime_cmaps == stubbed_cmaps
35+
36+
37+
def test_rcparam_stubs():
38+
runtime_rc_keys = {
39+
name for name in plt.rcParamsDefault.keys()
40+
if not name.startswith('_')
41+
}
42+
43+
assert {*typing.get_args(RcKeyType)} == runtime_rc_keys
44+
45+
runtime_rc_group_keys = set()
46+
for name in runtime_rc_keys:
47+
groups = name.split('.')
48+
for i in range(1, len(groups)):
49+
runtime_rc_group_keys.add('.'.join(groups[:i]))
50+
51+
assert {*typing.get_args(RcGroupKeyType)} == runtime_rc_group_keys

lib/matplotlib/typing.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@
217217
"axes.ymargin",
218218
"axes.zmargin",
219219
"axes3d.automargin",
220+
"axes3d.depthshade",
221+
"axes3d.depthshade_minalpha",
220222
"axes3d.grid",
221223
"axes3d.mouserotationstyle",
222224
"axes3d.trackballborder",
@@ -304,6 +306,7 @@
304306
"figure.titlesize",
305307
"figure.titleweight",
306308
"font.cursive",
309+
"font.enable_last_resort",
307310
"font.family",
308311
"font.fantasy",
309312
"font.monospace",
@@ -318,6 +321,14 @@
318321
"grid.color",
319322
"grid.linestyle",
320323
"grid.linewidth",
324+
"grid.major.alpha",
325+
"grid.major.color",
326+
"grid.major.linestyle",
327+
"grid.major.linewidth",
328+
"grid.minor.alpha",
329+
"grid.minor.color",
330+
"grid.minor.linestyle",
331+
"grid.minor.linewidth",
321332
"hatch.color",
322333
"hatch.linewidth",
323334
"hist.bins",
@@ -492,7 +503,7 @@
492503
"ytick.minor.size",
493504
"ytick.minor.visible",
494505
"ytick.minor.width",
495-
"ytick.right"
506+
"ytick.right",
496507
]
497508

498509
RcGroupKeyType: TypeAlias = Literal[
@@ -524,6 +535,8 @@
524535
"figure.subplot",
525536
"font",
526537
"grid",
538+
"grid.major",
539+
"grid.minor",
527540
"hatch",
528541
"hist",
529542
"image",
@@ -546,6 +559,7 @@
546559
"scatter",
547560
"svg",
548561
"text",
562+
"text.latex",
549563
"tk",
550564
"webagg",
551565
"xaxis",
@@ -555,5 +569,5 @@
555569
"yaxis",
556570
"ytick",
557571
"ytick.major",
558-
"ytick.minor"
572+
"ytick.minor",
559573
]

0 commit comments

Comments
 (0)