From 36c40f1fe250900ed043f7f8d207bfde21c77f0f Mon Sep 17 00:00:00 2001 From: Benjamin Root Date: Sat, 11 Jul 2015 15:25:18 -0400 Subject: [PATCH 1/3] Be more correct when validating bbox rc params --- lib/matplotlib/rcsetup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 8615930499be..2a4028b18163 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -476,6 +476,10 @@ def validate_bbox(s): if s == 'standard': return None raise ValueError("bbox should be 'tight' or 'standard'") + elif s is not None: + # Backwards compatibility. None is equivalent to 'standard'. + raise ValueError("bbox should be 'tight' or 'standard'") + return s def validate_sketch(s): if isinstance(s, six.string_types): @@ -790,7 +794,7 @@ def __call__(self, s): # value checked by backend at runtime 'savefig.format': ['png', update_savefig_format], # options are 'tight', or 'standard'. 'standard' validates to None. - 'savefig.bbox': [None, validate_bbox], + 'savefig.bbox': ['standard', validate_bbox], 'savefig.pad_inches': [0.1, validate_float], # default directory in savefig dialog box 'savefig.directory': ['~', six.text_type], From 1642892799ae1431ddea662e1a4e06b94d760def Mon Sep 17 00:00:00 2001 From: Benjamin Root Date: Sat, 11 Jul 2015 16:15:01 -0400 Subject: [PATCH 2/3] Sneaking in another validator fix --- lib/matplotlib/rcsetup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 2a4028b18163..173d85aed778 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -110,7 +110,7 @@ def validate_float(s): def validate_float_or_None(s): """convert s to float or raise""" - if s is None: + if s is None or s == 'None': return None try: return float(s) From 6cfb937fff0d3ff2bd6d4b116b629581935068a1 Mon Sep 17 00:00:00 2001 From: Benjamin Root Date: Sun, 12 Jul 2015 09:04:00 -0400 Subject: [PATCH 3/3] Add comments and doc explaining comparison to None --- lib/matplotlib/rcsetup.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 173d85aed778..5263f34949af 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -109,13 +109,18 @@ def validate_float(s): def validate_float_or_None(s): - """convert s to float or raise""" + """convert s to float, None or raise""" + # values directly from the rc file can only be strings, + # so we need to recognize the string "None" and convert + # it into the object. We will be case-sensitive here to + # avoid confusion between string values of 'none', which + # can be a valid string value for some other parameters. if s is None or s == 'None': return None try: return float(s) except ValueError: - raise ValueError('Could not convert "%s" to float' % s) + raise ValueError('Could not convert "%s" to float or None' % s) def validate_dpi(s): """confirm s is string 'figure' or convert s to float or raise"""