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

Skip to content

Commit 6f381a4

Browse files
committed
Removed the explicit typecaste of Path to str for plt.style.use(). Updated code and comments according to reviews
1 parent c9aff74 commit 6f381a4

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

lib/matplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
948948
949949
Parameters
950950
----------
951-
fname : str
951+
fname : str, Path
952952
Name of file parsed for Matplotlib settings.
953953
fail_on_error : bool
954954
If True, raise an error when the parser fails to convert a parameter.

lib/matplotlib/style/core.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def use(style):
7272
7373
Parameters
7474
----------
75-
style : str, dict, list or Path object
75+
style : str, dict, Path or list object
7676
A style specification. Valid options are:
7777
7878
+------+-------------------------------------------------------------+
@@ -91,8 +91,7 @@ def use(style):
9191
"""
9292
style_alias = {'mpl20': 'default',
9393
'mpl15': 'classic'}
94-
if isinstance(style, str) or hasattr(style, 'keys') or \
95-
isinstance(style, Path):
94+
if isinstance(style, (str, Path)) or hasattr(style, 'keys'):
9695
# If name is a single str, Path or dict, make it a single element list.
9796
styles = [style]
9897
else:
@@ -101,7 +100,7 @@ def use(style):
101100
styles = (style_alias.get(s, s) if isinstance(s, str) else s
102101
for s in styles)
103102
for style in styles:
104-
if not isinstance(style, str) and not isinstance(style, Path):
103+
if not isinstance(style, (str, Path)):
105104
_apply_style(style)
106105
elif style == 'default':
107106
# Deprecation warnings were already handled when creating
@@ -111,8 +110,6 @@ def use(style):
111110
elif style in library:
112111
_apply_style(library[style])
113112
else:
114-
if isinstance(style, Path):
115-
style = str(style)
116113
try:
117114
rc = rc_params_from_file(style, use_default_template=False)
118115
_apply_style(rc)
@@ -129,7 +126,7 @@ def context(style, after_reset=False):
129126
130127
Parameters
131128
----------
132-
style : str, dict, or list
129+
style : str, dict, Path or list
133130
A style specification. Valid options are:
134131
135132
+------+-------------------------------------------------------------+
@@ -139,8 +136,10 @@ def context(style, after_reset=False):
139136
| dict | Dictionary with valid key/value pairs for |
140137
| | `matplotlib.rcParams`. |
141138
+------+-------------------------------------------------------------+
142-
| list | A list of style specifiers (str or dict) applied from first |
143-
| | to last in the list. |
139+
| Path | A Path object which is a path to a style file. |
140+
+------+-------------------------------------------------------------+
141+
| list | A list of style specifiers (str, Path or dict) applied from |
142+
| | first to last in the list. |
144143
+------+-------------------------------------------------------------+
145144
146145
after_reset : bool

0 commit comments

Comments
 (0)