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

Skip to content

Commit f1f5795

Browse files
committed
ENH : change failed validations into warnings
Catch exceptions raised due to failed validations, force setting the (un validated!) value, and print a warning.
1 parent 4cc899c commit f1f5795

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

lib/matplotlib/__init__.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def _is_writable_dir(p):
245245

246246
return True
247247

248+
248249
class Verbose:
249250
"""
250251
A class to handle reporting. Set the fileo attribute to any file
@@ -808,6 +809,14 @@ def matplotlib_fname():
808809
_all_deprecated = set(chain(_deprecated_ignore_map,
809810
_deprecated_map, _obsolete_set))
810811

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

812821
class RcParams(dict):
813822

@@ -827,7 +836,14 @@ class RcParams(dict):
827836
# validate values on the way in
828837
def __init__(self, *args, **kwargs):
829838
for k, v in six.iteritems(dict(*args, **kwargs)):
830-
self[k] = v
839+
try:
840+
self[k] = v
841+
except (ValueError, RuntimeError):
842+
# force the issue
843+
warnings.warn(_rcparam_warn_str.format(key=repr(k),
844+
value=repr(v),
845+
func='__init__'))
846+
dict.__setitem__(self, k, v)
831847

832848
def __setitem__(self, key, val):
833849
try:
@@ -866,9 +882,15 @@ def __getitem__(self, key):
866882
# all of the validation over-ride update to force
867883
# through __setitem__
868884
def update(self, *args, **kwargs):
869-
870885
for k, v in six.iteritems(dict(*args, **kwargs)):
871-
self[k] = v
886+
try:
887+
self[k] = v
888+
except (ValueError, RuntimeError):
889+
# force the issue
890+
warnings.warn(_rcparam_warn_str.format(key=repr(k),
891+
value=repr(v),
892+
func='update'))
893+
dict.__setitem__(self, k, v)
872894

873895
def __repr__(self):
874896
import pprint

0 commit comments

Comments
 (0)