8000 ENH: add inverse function to _deprecated_map by tacaswell · Pull Request #4719 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

ENH: add inverse function to _deprecated_map #4719

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 1 commit into from
Jul 21, 2015
Merged
Changes from all commits
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
32 changes: 21 additions & 11 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,16 +813,19 @@ def matplotlib_fname():
return fname


# names of keys to deprecate
# the values are a tuple of (new_name, f_old_2_new, f_new_2_old)
# the inverse function may be `None`
_deprecated_map = {
'text.fontstyle': ('font.style', lambda x: x),
'text.fontangle': ('font.style', lambda x: x),
'text.fontvariant': ('font.variant', lambda x: x),
'text.fontweight': ('font.weight', lambda x: x),
'text.fontsize': ('font.size', lambda x: x),
'tick.size': ('tick.major.size', lambda x: x),
'text.fontstyle': ('font.style', lambda x: x, None),
'text.fontangle': ('font.style', lambda x: x, None),
'text.fontvariant': ('font.variant', lambda x: x, None),
'text.fontweight': ('font.weight', lambda x: x, None),
'text.fontsize': ('font.size', lambda x: x, None),
'tick.size': ('tick.major.size', lambda x: x, None),
'svg.embed_char_paths': ('svg.fonttype',
lambda x: "path" if x else "none"),
'savefig.extension': ('savefig.format', lambda x: x),
lambda x: "path" if x else "none", None),
'savefig.extension': ('savefig.format', lambda x: x, None),
}

_deprecated_ignore_map = {
Expand Down Expand Up @@ -856,7 +859,7 @@ def __init__(self, *args, **kwargs):
def __setitem__(self, key, val):
try:
if key in _deprecated_map:
alt_key, alt_val = _deprecated_map[key]
alt_key, alt_val, inverse_alt = _deprecated_map[key]
warnings.warn(self.msg_depr % (key, alt_key))
key = alt_key
val = alt_val(val)
Expand All @@ -874,15 +877,22 @@ def __setitem__(self, key, val):
See rcParams.keys() for a list of valid parameters.' % (key,))

def __getitem__(self, key):
inverse_alt = None
if key in _deprecated_map:
alt_key, alt_val = _deprecated_map[key]
alt_key, alt_val, inverse_alt = _deprecated_map[key]
warnings.warn(self.msg_depr % (key, alt_key))
key = alt_key

elif key in _deprecated_ignore_map:
alt = _deprecated_ignore_map[key]
warnings.warn(self.msg_depr_ignore % (key, alt))
key = alt
return dict.__getitem__(self, key)

val = dict.__getitem__(self, key)
if inverse_alt is not None:
return inverse_alt(val)
else:
return val

# http://stackoverflow.com/questions/2390827
# (how-to-properly-subclass-dict-and-override-get-set)
Expand Down
0