Skip to content

MNT: let bad rcParam keys pass #19588

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
18 changes: 12 additions & 6 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,12 +830,18 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
rcParamsOrig = RcParams(rcParams.copy())
# This also checks that all rcParams are indeed listed in the template.
# Assigning to rcsetup.defaultParams is left only for backcompat.
defaultParams = rcsetup.defaultParams = {
# We want to resolve deprecated rcParams, but not backend...
key: [(rcsetup._auto_backend_sentinel if key == "backend" else
rcParamsDefault[key]),
validator]
for key, validator in rcsetup._validators.items()}
defaultParams = {}
for key, validator in rcsetup._validators.items():
if key == 'backend':
defaultParams['backend'] = [rcsetup._auto_backend_sentinel,
validator]
elif key in rcParamsDefault.keys():
defaultParams[key] = [rcParamsDefault[key], validator]
else:
_api.warn_external(f'rcsetup key "{key}" not in the default'
' rcParams')
rcsetup.defaultParams = defaultParams

if rcParams['axes.formatter.use_locale']:
locale.setlocale(locale.LC_ALL, '')

Expand Down
18 changes: 18 additions & 0 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from matplotlib import _api, _c_internal_utils
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import matplotlib.rcsetup as rcsetup
import numpy as np
from matplotlib.rcsetup import (
validate_bool,
Expand All @@ -31,6 +32,23 @@
_listify_validator)


def test_rc_validators_in_sync():
# make sure that matplotlibrc.template and rcsetup._validators
# are in sync.
rc = mpl._rc_params_in_file(
'matplotlibrc.template',
# Strip leading comment.
transform=lambda line: line[1:] if line.startswith("#") else line,
fail_on_error=True)
for key, validator in rcsetup._validators.items():
if (key not in mpl._deprecated_remain_as_none and
key not in mpl._deprecated_ignore_map and
key[0] != '_'):
assert key in list(rc.keys())
for key in list(rc.keys()):
assert key in list(rcsetup._validators.keys())


def test_rcparams(tmpdir):
mpl.rc('text', usetex=False)
mpl.rc('lines', linewidth=22)
Expand Down