17
17
from functools import lru_cache , reduce
18
18
from numbers import Number
19
19
import operator
20
+ import os
20
21
import re
21
22
22
23
import numpy as np
@@ -198,6 +199,11 @@ def validator(s):
198
199
if (allow_none and
199
200
(s is None or isinstance (s , str ) and s .lower () == "none" )):
200
201
return None
202
+ if cls is str and not isinstance (s , str ):
203
+ _api .warn_deprecated (
204
+ "3.5" , message = "Support for setting an rcParam that expects a "
205
+ "str value to a non-str value is deprecated since %(since)s "
206
+ "and support will be removed %(removal)s." )
201
207
try :
202
208
return cls (s )
203
209
except (TypeError , ValueError ) as e :
@@ -224,6 +230,15 @@ def validator(s):
224
230
validate_float , doc = 'return a list of floats' )
225
231
226
232
233
+ def _validate_pathlike (s ):
234
+ if isinstance (s , (str , os .PathLike )):
235
+ # Store value as str because savefig.directory needs to distinguish
236
+ # between "" (cwd) and "." (cwd, but gets updated by user selections).
237
+ return os .fsdecode (s )
238
+ else :
239
+ return validate_string (s ) # Emit deprecation warning.
240
+
241
+
227
242
def validate_fonttype (s ):
228
243
"""
229
244
Confirm that this is a Postscript or PDF font type that we know how to
@@ -1154,7 +1169,7 @@ def _convert_validator_spec(key, conv):
1154
1169
"savefig.bbox" : validate_bbox , # "tight", or "standard" (= None)
1155
1170
"savefig.pad_inches" : validate_float ,
1156
1171
# default directory in savefig dialog box
1157
- "savefig.directory" : validate_string ,
1172
+ "savefig.directory" : _validate_pathlike ,
1158
1173
"savefig.transparent" : validate_bool ,
1159
1174
1160
1175
"tk.window_focus" : validate_bool , # Maintain shell focus for TkAgg
@@ -1224,15 +1239,15 @@ def _convert_validator_spec(key, conv):
1224
1239
# Additional arguments for HTML writer
1225
1240
"animation.html_args" : validate_stringlist ,
1226
1241
# Path to ffmpeg binary. If just binary name, subprocess uses $PATH.
1227
- "animation.ffmpeg_path" : validate_string ,
1242
+ "animation.ffmpeg_path" : _validate_pathlike ,
1228
1243
# Additional arguments for ffmpeg movie writer (using pipes)
1229
1244
"animation.ffmpeg_args" : validate_stringlist ,
1230
1245
# Path to AVConv binary. If just binary name, subprocess uses $PATH.
1231
- "animation.avconv_path" : validate_string ,
1246
+ "animation.avconv_path" : _validate_pathlike ,
1232
1247
# Additional arguments for avconv movie writer (using pipes)
1233
1248
"animation.avconv_args" : validate_stringlist ,
1234
1249
# Path to convert binary. If just binary name, subprocess uses $PATH.
1235
- "animation.convert_path" : validate_string ,
1250
+ "animation.convert_path" : _validate_pathlike ,
1236
1251
# Additional arguments for convert movie writer (using pipes)
1237
1252
"animation.convert_args" : validate_stringlist ,
1238
1253
0 commit comments