Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH : change failed validations into warnings
Catch exceptions raised due to failed validations, force
setting the (un validated!) value, and print a warning.
  • Loading branch information
tacaswell committed Oct 10, 2014
commit f1f5795ba0d6844cb50bf3d71f5bd405ac7cb6e0
28 changes: 25 additions & 3 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def _is_writable_dir(p):

return True


class Verbose:
"""
A class to handle reporting. Set the fileo attribute to any file
Expand Down Expand Up @@ -808,6 +809,14 @@ def matplotlib_fname():
_all_deprecated = set(chain(_deprecated_ignore_map,
_deprecated_map, _obsolete_set))

_rcparam_warn_str = ("Trying to set {key} to {value} via the {func} "
"method of RcParams which does not validate cleanly. "
"This warning will turn into an Exception in 1.5. "
"If you think {value} should validate correctly for "
"rcParams[{key}] "
"please create an issue on github."
)


class RcParams(dict):

Expand All @@ -827,7 +836,14 @@ class RcParams(dict):
# validate values on the way in
def __init__(self, *args, **kwargs):
for k, v in six.iteritems(dict(*args, **kwargs)):
self[k] = v
try:
self[k] = v
except (ValueError, RuntimeError):
# force the issue
warnings.warn(_rcparam_warn_str.format(key=repr(k),
value=repr(v),
func='__init__'))
dict.__setitem__(self, k, v)

def __setitem__(self, key, val):
try:
Expand Down Expand Up @@ -866,9 +882,15 @@ def __getitem__(self, key):
# all of the validation over-ride update to force
# through __setitem__
def update(self, *args, **kwargs):

for k, v in six.iteritems(dict(*args, **kwargs)):
self[k] = v
try:
self[k] = v
except (ValueError, RuntimeError):
# force the issue
warnings.warn(_rcparam_warn_str.format(key=repr(k),
value=repr(v),
func='update'))
dict.__setitem__(self, k, v)

def __repr__(self):
import pprint
Expand Down