1717from functools import lru_cache , reduce
1818from numbers import Number
1919import operator
20+ import os
2021import re
2122
2223import numpy as np
@@ -198,6 +199,11 @@ def validator(s):
198199 if (allow_none and
199200 (s is None or isinstance (s , str ) and s .lower () == "none" )):
200201 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." )
201207 try :
202208 return cls (s )
203209 except (TypeError , ValueError ) as e :
@@ -224,6 +230,15 @@ def validator(s):
224230 validate_float , doc = 'return a list of floats' )
225231
226232
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+
227242def validate_fonttype (s ):
228243 """
229244 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):
11541169 "savefig.bbox" : validate_bbox , # "tight", or "standard" (= None)
11551170 "savefig.pad_inches" : validate_float ,
11561171 # default directory in savefig dialog box
1157- "savefig.directory" : validate_string ,
1172+ "savefig.directory" : _validate_pathlike ,
11581173 "savefig.transparent" : validate_bool ,
11591174
11601175 "tk.window_focus" : validate_bool , # Maintain shell focus for TkAgg
@@ -1224,15 +1239,15 @@ def _convert_validator_spec(key, conv):
12241239 # Additional arguments for HTML writer
12251240 "animation.html_args" : validate_stringlist ,
12261241 # Path to ffmpeg binary. If just binary name, subprocess uses $PATH.
1227- "animation.ffmpeg_path" : validate_string ,
1242+ "animation.ffmpeg_path" : _validate_pathlike ,
12281243 # Additional arguments for ffmpeg movie writer (using pipes)
12291244 "animation.ffmpeg_args" : validate_stringlist ,
12301245 # Path to AVConv binary. If just binary name, subprocess uses $PATH.
1231- "animation.avconv_path" : validate_string ,
1246+ "animation.avconv_path" : _validate_pathlike ,
12321247 # Additional arguments for avconv movie writer (using pipes)
12331248 "animation.avconv_args" : validate_stringlist ,
12341249 # Path to convert binary. If just binary name, subprocess uses $PATH.
1235- "animation.convert_path" : validate_string ,
1250+ "animation.convert_path" : _validate_pathlike ,
12361251 # Additional arguments for convert movie writer (using pipes)
12371252 "animation.convert_args" : validate_stringlist ,
12381253
0 commit comments