Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd231a25

Browse files
committed
Don't expose private styles in style.available
They remain in `style.library`, because that's how we look them up, butthis prevents them being exposed as something someone might use.Also, fix `reload_library`, which was accidentally modifying theoriginal base library information each time.Fixesitprojects/MasVisGtk#13
1 parent2899656 commitd231a25

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

‎lib/matplotlib/style/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
``context``
77
Context manager to use a style sheet temporarily.
88
``available``
9-
List available style sheets.
9+
List available style sheets. Underscore-prefixed names are considered private and
10+
not listed, though may still be accessed directly from ``library``.
1011
``library``
1112
A dictionary of style names and matplotlib settings.
1213
"""
@@ -245,8 +246,8 @@ def update_nested_dict(main_dict, new_dict):
245246
defreload_library():
246247
"""Reload the style library."""
247248
library.clear()
248-
library.update(_update_user_library(_base_library))
249-
available[:]=sorted(library.keys())
249+
library.update(_update_user_library(_base_library.copy()))
250+
available[:]=sorted(namefornameinlibraryifnotname.startswith('_'))
250251

251252

252253
reload_library()

‎lib/matplotlib/tests/test_style.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def temp_style(style_name, settings=None):
2121
ifnotsettings:
2222
settings=DUMMY_SETTINGS
2323
temp_file=f'{style_name}.mplstyle'
24+
orig_library_paths=style.USER_LIBRARY_PATHS
2425
try:
2526
withTemporaryDirectory()astmpdir:
2627
# Write style settings to file in the tmpdir.
@@ -32,6 +33,7 @@ def temp_style(style_name, settings=None):
3233
style.reload_library()
3334
yield
3435
finally:
36+
style.USER_LIBRARY_PATHS=orig_library_paths
3537
style.reload_library()
3638

3739

@@ -46,8 +48,17 @@ def test_invalid_rc_warning_includes_filename(caplog):
4648

4749

4850
deftest_available():
49-
withtemp_style('_test_',DUMMY_SETTINGS):
50-
assert'_test_'instyle.available
51+
# Private name should not be listed in available but still usable.
52+
assert'_classic_test_patch'notinstyle.available
53+
assert'_classic_test_patch'instyle.library
54+
55+
withtemp_style('_test_',DUMMY_SETTINGS),temp_style('dummy',DUMMY_SETTINGS):
56+
assert'dummy'instyle.available
57+
assert'dummy'instyle.library
58+
assert'_test_'notinstyle.available
59+
assert'_test_'instyle.library
60+
assert'dummy'notinstyle.available
61+
assert'_test_'notinstyle.available
5162

5263

5364
deftest_use():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp