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

Skip to content

Commit a7cacc7

Browse files
committed
FIX: re-jigger deprecation of rcParams using machinery in __init__
1 parent cd31afd commit a7cacc7

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

doc/api/api_changes/2018-02-04-AL.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Deprecation of qt binding rcparams
2+
``````````````````````````````````
3+
4+
The :rc:`backend.qt4` and :rc:`backend.qt5` rcParams were deprecated
5+
in version 2.2. In order to force the use of a specific Qt binding,
6+
either import that binding first, or set the ``QT_API`` environment
7+
variable.

lib/matplotlib/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,8 @@ def gen_candidates():
848848
_obsolete_set = {'plugins.directory', 'text.dvipnghack'}
849849

850850
# The following may use a value of None to suppress the warning.
851-
_deprecated_set = {'axes.hold'} # do NOT include in _all_deprecated
851+
_deprecated_set = {'axes.hold',
852+
'backend.qt4', 'backend.qt5'} # do NOT include in _all_deprecated
852853

853854
_all_deprecated = set(itertools.chain(
854855
_deprecated_ignore_map, _deprecated_map, _obsolete_set))
@@ -872,6 +873,10 @@ class RcParams(MutableMapping, dict):
872873
msg_depr_ignore = "%s is deprecated and ignored. Use %s instead."
873874
msg_obsolete = ("%s is obsolete. Please remove it from your matplotlibrc "
874875
"and/or style files.")
876+
msg_backend_obsolete = ("The {} rcParam was deprecated in version 2.2. In"
877+
" order to force the use of a specific Qt binding,"
878+
" either import that binding first, or set the "
879+
"QT_API environment variable.")
875880

876881
# validate values on the way in
877882
def __init__(self, *args, **kwargs):
@@ -886,8 +891,12 @@ def __setitem__(self, key, val):
886891
key = alt_key
887892
val = alt_val(val)
888893
elif key in _deprecated_set and val is not None:
889-
warnings.warn(self.msg_depr_set % key,
890-
mplDeprecation)
894+
if key.startswith('backend'):
895+
warnings.warn(self.msg_backend_obsolete.format(key),
896+
mplDeprecation)
897+
else:
898+
warnings.warn(self.msg_depr_set % key,
899+
mplDeprecation)
891900
elif key in _deprecated_ignore_map:
892901
alt = _deprecated_ignore_map[key]
893902
warnings.warn(self.msg_depr_ignore % (key, alt),

lib/matplotlib/backends/qt_compat.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@
8383
if QT_API is None:
8484
# No ETS environment or incompatible so use rcParams.
8585
if rcParams['backend'] == 'Qt5Agg':
86-
QT_API = rcParams['backend.qt5']
86+
QT_API = QT_API_PYQT5
8787
elif rcParams['backend'] == 'Qt4Agg':
88-
QT_API = rcParams['backend.qt4']
88+
QT_API = QT_API_PYQT
8989
else:
9090
# A non-Qt backend was specified, no version of the Qt
9191
# bindings is imported, but we still got here because a Qt
9292
# related file was imported. This is allowed, fall back to Qt5
9393
# using which ever binding the rparams ask for.
9494
_fallback_to_qt4 = True
95-
QT_API = rcParams['backend.qt5']
95+
QT_API = QT_API_PYQT5
9696

9797
# We will define an appropriate wrapper for the differing versions
9898
# of file dialog.
@@ -142,7 +142,7 @@
142142
except ImportError:
143143
if _fallback_to_qt4:
144144
# fell through, tried PyQt5, failed fall back to PyQt4
145-
QT_API = rcParams['backend.qt4']
145+
QT_API = QT_API_PYQT
146146
QT_RC_MAJOR_VERSION = 4
147147
else:
148148
raise

lib/matplotlib/rcsetup.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -268,25 +268,13 @@ def validate_backend(s):
268268

269269
def validate_qt4(s):
270270
if s is None:
271-
# return a reasonable default for deprecation period
272-
return 'PyQt4'
273-
cbook.warn_deprecated(
274-
"2.2",
275-
"The backend.qt4 rcParam was deprecated in version 2.2. In order "
276-
"to force the use of a specific Qt4 binding, either import that "
277-
"binding first, or set the QT_API environment variable.")
271+
return None
278272
return ValidateInStrings("backend.qt4", ['PyQt4', 'PySide', 'PyQt4v2'])(s)
279273

280274

281275
def validate_qt5(s):
282276
if s is None:
283-
# return a reasonable default for deprecation period
284-
return 'PyQt5'
285-
cbook.warn_deprecated(
286-
"2.2",
287-
"The backend.qt5 rcParam was deprecated in version 2.2. In order "
288-
"to force the use of a specific Qt5 binding, either import that "
289-
"binding first, or set the QT_API environment variable.")
277+
return None
290278
return ValidateInStrings("backend.qt5", ['PyQt5', 'PySide2'])(s)
291279

292280

0 commit comments

Comments
 (0)