Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Better error message when providing wrong fontsizes #5025

Merged
merged 1 commit into from
Sep 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def validate_float(s):
raise ValueError('Could not convert "%s" to float' % s)
validate_floatlist = _listify_validator(validate_float)


def validate_float_or_None(s):
"""convert s to float, None or raise"""
# values directly from the rc file can only be strings,
Expand All @@ -150,6 +151,7 @@ def validate_float_or_None(s):
except ValueError:
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"""
if s == 'figure':
Expand All @@ -160,13 +162,15 @@ def validate_dpi(s):
raise ValueError('"%s" is not string "figure" or'
' could not convert "%s" to float' % (s, s))


def validate_int(s):
"""convert s to int or raise"""
try:
return int(s)
except ValueError:
raise ValueError('Could not convert "%s" to int' % s)


def validate_int_or_None(s):
"""if not None, tries to validate as an int"""
if s=='None':
Expand All @@ -178,6 +182,7 @@ def validate_int_or_None(s):
except ValueError:
raise ValueError('Could not convert "%s" to int' % s)


def validate_fonttype(s):
"""
confirm that this is a Postscript of PDF font type that we know how to
Expand Down Expand Up @@ -354,15 +359,19 @@ def validate_aspect(s):


def validate_fontsize(s):
fontsizes = ['xx-small', 'x-small', 'small', 'medium', 'large',
'x-large', 'xx-large', 'smaller', 'larger']
if isinstance(s, six.string_types):
s = s.lower()
if s in ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large',
'xx-large', 'smaller', 'larger']:
if s in fontsizes:
return s
try:
return float(s)
except ValueError:
raise ValueError('not a valid font size')
raise ValueError("%s is not a valid font size. Valid font sizes "
"are %s." % (s, ", ".join(fontsizes)))


validate_fontsizelist = _listify_validator(validate_fontsize)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8 question... does the 2 blank line rule have to be right after the function, or can it wait until after ancillary actions like munging of docstrings and such?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fix so, but I'm not sure.



Expand Down