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

Skip to content

Commit e405a68

Browse files
committed
Merge pull request #4647 from WeatherGod/validate_bbox_fix
Be more correct when validating bbox rc params
2 parents bf3095e + 6cfb937 commit e405a68

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,18 @@ def validate_float(s):
109109

110110

111111
def validate_float_or_None(s):
112-
"""convert s to float or raise"""
113-
if s is None:
112+
"""convert s to float, None or raise"""
113+
# values directly from the rc file can only be strings,
114+
# so we need to recognize the string "None" and convert
115+
# it into the object. We will be case-sensitive here to
116+
# avoid confusion between string values of 'none', which
117+
# can be a valid string value for some other parameters.
118+
if s is None or s == 'None':
114119
return None
115120
try:
116121
return float(s)
117122
except ValueError:
118-
raise ValueError('Could not convert "%s" to float' % s)
123+
raise ValueError('Could not convert "%s" to float or None' % s)
119124

120125
def validate_dpi(s):
121126
"""confirm s is string 'figure' or convert s to float or raise"""
@@ -476,6 +481,10 @@ def validate_bbox(s):
476481
if s == 'standard':
477482
return None
478483
raise ValueError("bbox should be 'tight' or 'standard'")
484+
elif s is not None:
485+
# Backwards compatibility. None is equivalent to 'standard'.
486+
raise ValueError("bbox should be 'tight' or 'standard'")
487+
return s
479488

480489
def validate_sketch(s):
481490
if isinstance(s, six.string_types):
@@ -790,7 +799,7 @@ def __call__(self, s):
790799
# value checked by backend at runtime
791800
'savefig.format': ['png', update_savefig_format],
792801
# options are 'tight', or 'standard'. 'standard' validates to None.
793-
'savefig.bbox': [None, validate_bbox],
802+
'savefig.bbox': ['standard', validate_bbox],
794803
'savefig.pad_inches': [0.1, validate_float],
795804
# default directory in savefig dialog box
796805
'savefig.directory': ['~', six.text_type],

0 commit comments

Comments
 (0)