8000 Rcparam validation fix by tacaswell · Pull Request #3564 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Rcparam validation fix #3564

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

Merged
merged 19 commits into from
Oct 14, 2014
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
BUG : make rcParams.update validates inputs
Close #3470

Over-ride `update` so that inputs are validated.
  • Loading branch information
tacaswell committed Sep 25, 2014
commit ec7276c1c1ae778653d9d801686c25a47956fe56
14 changes: 12 additions & 2 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ class RcParams(dict):
def __setitem__(self, key, val):
try:
if key in _deprecated_map:
alt_key, alt_val = _deprecated_map[key]
alt_key, alt_val = _deprecated_map[key]
warnings.warn(self.msg_depr % (key, alt_key))
key = alt_key
val = alt_val(val)
Expand All @@ -840,7 +840,7 @@ def __setitem__(self, key, val):

def __getitem__(self, key):
if key in _deprecated_map:
alt_key, alt_val = _deprecated_map[key]
alt_key, alt_val = _deprecated_map[key]
warnings.warn(self.msg_depr % (key, alt_key))
key = alt_key
elif key in _deprecated_ignore_map:
Expand All @@ -849,6 +849,16 @@ def __getitem__(self, key):
key = alt
return dict.__getitem__(self, key)

# http://stackoverflow.com/question 8000 s/2390827/how-to-properly-subclass-dict-and-override-get-set
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the comment is necessary (at all), but a test would be very welcome.

Copy link
Member

Choose a reason for hiding this comment

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

The comment could be shortened to one or two lines, but noting why update needs to be overridden is helpful; it's not obvious.

# the default dict `update` does not use __setitem__
# so rcParams.update(...) (such as in seaborn) side-steps
# 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

def __repr__(self):
import pprint
class_name = self.__class__.__name__
Expand Down
0