Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd3d9fad

Browse files
committed
Prefer warn_deprecated instead of warnings.warn.
warn_deprecated has the advantage of always listing the deprecationversion and removal version. Hopefully, in the future it will also beable to set the stacklevel more systematically.Redesign the way deprecation of rcParams is done to make it usewarn_deprecated. Merge obsolete_set into deprecated_ignore_map as theyare semantically similar, it's just that there's no alternative rcParamfor obsolete_set. Rename deprecated_set to deprecated_remain_as_none asthe former name really doesn't say anything about the deprecationsemantics.text.dvipnghack and axes.hold should be completely removed but that'llbe another PR.
1 parent1e6790f commitd3d9fad

File tree

7 files changed

+96
-81
lines changed

7 files changed

+96
-81
lines changed

‎doc/api/next_api_changes/2018-02-15-AL-deprecations.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ The following modules are deprecated:
1010

1111
The following classes, methods, functions, and attributes are deprecated:
1212

13+
- ``RcParams.msg_depr``, ``RcParams.msg_depr_ignore``,
14+
``RcParams.msg_depr_set``, ``RcParams.msg_obsolete``,
15+
``RcParams.msg_backend_obsolete``,
1316
- ``afm.parse_afm``,
1417
- ``backend_pgf.get_texcommand``,
1518
- ``backend_ps.get_bbox``,

‎lib/matplotlib/__init__.py

Lines changed: 80 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@
123123
importimportlib
124124
importinspect
125125
frominspectimportParameter
126-
importitertools
127126
importlocale
128127
importlogging
129128
importos
130129
frompathlibimportPath
130+
importpprint
131131
importre
132132
importshutil
133133
importstat
@@ -800,23 +800,29 @@ def gen_candidates():
800800
returnfname
801801

802802

803-
# names of keys to deprecate
804-
# the values are a tuple of (new_name, f_old_2_new, f_new_2_old)
805-
# the inverse function may be `None`
803+
# rcParams deprecated and automatically mapped to another key.
804+
# Values are tuples of (version, new_name, f_old2new, f_new2old).
806805
_deprecated_map= {}
807806

808-
_deprecated_ignore_map= {'nbagg.transparent':'figure.facecolor'}
807+
# rcParams deprecated; some can manually be mapped to another key.
808+
# Values are tuples of (version, new_name_or_None).
809+
_deprecated_ignore_map= {
810+
'text.dvipnghack': ('2.1',None),
811+
'nbagg.transparent': ('2.2','figure.facecolor'),
812+
'plugins.directory': ('2.2',None),
813+
'pgf.debug': ('3.0',None),
814+
}
809815

810-
_obsolete_set= {'pgf.debug','plugins.directory','text.dvipnghack'}
816+
# rcParams deprecated; can use None to suppress warnings; remain actually
817+
# listed in the rcParams (not included in _all_deprecated).
818+
# Values are typles of (version,)
819+
_deprecated_remain_as_none= {
820+
'axes.hold': ('2.1',),
821+
'backend.qt4': ('2.2',),
822+
'backend.qt5': ('2.2',),
823+
}
811824

812-
# The following may use a value of None to suppress the warning.
813-
# do NOT include in _all_deprecated
814-
_deprecated_set= {'axes.hold',
815-
'backend.qt4',
816-
'backend.qt5'}
817-
818-
_all_deprecated=set(itertools.chain(
819-
_deprecated_ignore_map,_deprecated_map,_obsolete_set))
825+
_all_deprecated= {*_deprecated_map,*_deprecated_ignore_map}
820826

821827

822828
classRcParams(MutableMapping,dict):
@@ -831,16 +837,35 @@ class RcParams(MutableMapping, dict):
831837
validate= {key:converter
832838
forkey, (default,converter)indefaultParams.items()
833839
ifkeynotin_all_deprecated}
834-
msg_depr="%s is deprecated and replaced with %s; please use the latter."
835-
msg_depr_set= ("%s is deprecated. Please remove it from your "
836-
"matplotlibrc and/or style files.")
837-
msg_depr_ignore="%s is deprecated and ignored. Use %s instead."
838-
msg_obsolete= ("%s is obsolete. Please remove it from your matplotlibrc "
839-
"and/or style files.")
840-
msg_backend_obsolete= ("The {} rcParam was deprecated in version 2.2. In"
841-
" order to force the use of a specific Qt binding,"
842-
" either import that binding first, or set the "
843-
"QT_API environment variable.")
840+
841+
@property
842+
@cbook.deprecated("3.0")
843+
defmsg_depr(self):
844+
return"%s is deprecated and replaced with %s; please use the latter."
845+
846+
@property
847+
@cbook.deprecated("3.0")
848+
defmsg_depr_ignore(self):
849+
return"%s is deprecated and ignored. Use %s instead."
850+
851+
@property
852+
@cbook.deprecated("3.0")
853+
defmsg_depr_set(self):
854+
return ("%s is deprecated. Please remove it from your matplotlibrc "
855+
"and/or style files.")
856+
857+
@property
858+
@cbook.deprecated("3.0")
859+
defmsg_obsolete(self):
860+
return ("%s is obsolete. Please remove it from your matplotlibrc "
861+
"and/or style files.")
862+
863+
@property
864+
@cbook.deprecated("3.0")
865+
defmsg_backend_obsolete(self):
866+
return ("The {} rcParam was deprecated in version 2.2. In order to "
867+
"force the use of a specific Qt binding, either import that "
868+
"binding first, or set the QT_API environment variable.")
844869

845870
# validate values on the way in
846871
def__init__(self,*args,**kwargs):
@@ -849,26 +874,25 @@ def __init__(self, *args, **kwargs):
849874
def__setitem__(self,key,val):
850875
try:
851876
ifkeyin_deprecated_map:
852-
alt_key,alt_val,inverse_alt=_deprecated_map[key]
853-
warnings.warn(self.msg_depr% (key,alt_key),
854-
mplDeprecation)
877+
version,alt_key,alt_val,inverse_alt=_deprecated_map[key]
878+
cbook.warn_deprecated(
879+
version,key,obj_type="rcparam",alternative=alt_key)
855880
key=alt_key
856881
val=alt_val(val)
857-
elifkeyin_deprecated_setandvalisnotNone:
882+
elifkeyin_deprecated_remain_as_noneandvalisnotNone:
883+
version,=_deprecated_remain_as_none[key]
884+
addendum=None
858885
ifkey.startswith('backend'):
859-
warnings.warn(self.msg_backend_obsolete.format(key),
860-
mplDeprecation)
861-
else:
862-
warnings.warn(self.msg_depr_set%key,
863-
mplDeprecation)
886+
addendum= (
887+
"In order to force the use of a specific Qt binding, "
888+
"either import that binding first, or set the QT_API "
889+
"environment variable.")
890+
cbook.warn_deprecated(
891+
"2.2",key,obj_type="rcparam",addendum=addendum)
864892
elifkeyin_deprecated_ignore_map:
865-
alt=_deprecated_ignore_map[key]
866-
warnings.warn(self.msg_depr_ignore% (key,alt),
867-
mplDeprecation)
868-
return
869-
elifkeyin_obsolete_set:
870-
warnings.warn(self.msg_obsolete% (key, ),
871-
mplDeprecation)
893+
version,alt_key=_deprecated_ignore_map[key]
894+
cbook.warn_deprecated(
895+
version,key,obj_type="rcparam",alternative=alt_key)
872896
return
873897
try:
874898
cval=self.validate[key](val)
@@ -881,42 +905,30 @@ def __setitem__(self, key, val):
881905
'list of valid parameters.'% (key,))
882906

883907
def__getitem__(self,key):
884-
inverse_alt=None
885908
ifkeyin_deprecated_map:
886-
alt_key,alt_val,inverse_alt=_deprecated_map[key]
887-
warnings.warn(self.msg_depr% (key,alt_key),
888-
mplDeprecation)
889-
key=alt_key
909+
version,alt_key,alt_val,inverse_alt=_deprecated_map[key]
910+
cbook.warn_deprecated(
911+
version,key,obj_type="rcparam",alternative=alt_key)
912+
returninverse_alt(dict.__getitem__(self,alt_key))
890913

891914
elifkeyin_deprecated_ignore_map:
892-
alt=_deprecated_ignore_map[key]
893-
warnings.warn(self.msg_depr_ignore% (key,alt),
894-
mplDeprecation)
895-
key=alt
896-
897-
elifkeyin_obsolete_set:
898-
warnings.warn(self.msg_obsolete% (key, ),
899-
mplDeprecation)
900-
returnNone
901-
902-
val=dict.__getitem__(self,key)
903-
ifinverse_altisnotNone:
904-
returninverse_alt(val)
905-
else:
906-
returnval
915+
version,alt_key=_deprecated_ignore_map[key]
916+
cbook.warn_deprecated(
917+
version,key,obj_type,alternative=alt_key)
918+
returndict.__getitem__(self,alt_key)ifalt_keyelseNone
919+
920+
returndict.__getitem__(self,key)
907921

908922
def__repr__(self):
909-
importpprint
910923
class_name=self.__class__.__name__
911924
indent=len(class_name)+1
912925
repr_split=pprint.pformat(dict(self),indent=1,
913926
width=80-indent).split('\n')
914927
repr_indented= ('\n'+' '*indent).join(repr_split)
915-
return'{0}({1})'.format(class_name,repr_indented)
928+
return'{}({})'.format(class_name,repr_indented)
916929

917930
def__str__(self):
918-
return'\n'.join('{0}: {1}'.format(k,v)
919-
fork,vinsorted(self.items()))
931+
return'\n'.join(map('{0[0]}: {0[1]}'.format,sorted(self.items())))
920932

921933
def__iter__(self):
922934
"""Yield sorted list of keys."""
@@ -1043,10 +1055,10 @@ def _rc_params_in_file(fname, fail_on_error=False):
10431055
warnings.warn('Bad val "%s" on %s\n\t%s'%
10441056
(val,error_details,msg))
10451057
elifkeyin_deprecated_ignore_map:
1046-
warnings.warn('%s is deprecated. Update your matplotlibrc to use '
1047-
'%s instead.'% (key,_deprecated_ignore_map[key]),
1048-
mplDeprecation)
1049-
1058+
version,alt_key=_deprecated_ignore_map[key]
1059+
cbook.warn_deprecated(
1060+
version,key,alternative=alt_key,
1061+
addendum="Please update your matplotlibrc.")
10501062
else:
10511063
print("""
10521064
Bad key "%s" on line %d in

‎lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,8 +1334,8 @@ def set_adjustable(self, adjustable, share=False):
13341334
and independently on each Axes as it is drawn.
13351335
"""
13361336
ifadjustable=='box-forced':
1337-
warnings.warn("The 'box-forced' keyword argument is deprecated"
1338-
" since2.2.",cbook.mplDeprecation)
1337+
cbook.warn_deprecated(
1338+
"2.2","box-forced",obj_type="keyword argument")
13391339
ifadjustablenotin ('box','datalim','box-forced'):
13401340
raiseValueError("argument must be 'box', or 'datalim'")
13411341
ifshare:

‎lib/matplotlib/axes/_subplots.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
frommatplotlibimportdocstring
55
importmatplotlib.artistasmartist
66
frommatplotlib.axes._axesimportAxes
7-
frommatplotlib.cbookimportmplDeprecation
87
frommatplotlib.gridspecimportGridSpec,SubplotSpec
98
importmatplotlib._layoutboxaslayoutbox
109

‎lib/matplotlib/cbook/deprecation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def _generate_deprecation_message(
4040
ifremovalelse
4141
"")))
4242
+"."
43-
+ (" Use {alternative} instead."ifalternativeelse""))
43+
+ (" Use {alternative} instead."ifalternativeelse"")
44+
+ (" {addendum}"ifaddendumelse""))
4445

4546
returnmessage.format(func=name,name=name,obj_type=obj_type,since=since,
4647
removal=removal,alternative=alternative)
@@ -99,7 +100,8 @@ def warn_deprecated(
99100
100101
"""
101102
message=_generate_deprecation_message(
102-
since,message,name,alternative,pending,obj_type,removal=removal)
103+
since,message,name,alternative,pending,obj_type,addendum,
104+
removal=removal)
103105
warnings.warn(message,mplDeprecation,stacklevel=2)
104106

105107

‎lib/matplotlib/gridspec.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
frommatplotlibimport_pylab_helpers,tight_layout,rcParams
2424
frommatplotlib.transformsimportBbox
2525
importmatplotlib._layoutboxaslayoutbox
26-
frommatplotlib.cbookimportmplDeprecation
2726

2827
_log=logging.getLogger(__name__)
2928

@@ -265,8 +264,8 @@ def get_subplot_params(self, figure=None, fig=None):
265264
parameters are from rcParams unless a figure attribute is set.
266265
"""
267266
iffigisnotNone:
268-
warnings.warn("the 'fig' kwarg is deprecated "
269-
"use 'figure' instead",mplDeprecation)
267+
cbook.warn_deprecated("2.2","fig",obj_type="keyword argument",
268+
alternative="figure")
270269
iffigureisNone:
271270
figure=fig
272271

@@ -355,8 +354,8 @@ def get_subplot_params(self, figure=None, fig=None):
355354
"""Return a dictionary of subplot layout parameters.
356355
"""
357356
iffigisnotNone:
358-
warnings.warn("the 'fig' kwarg is deprecated "
359-
"use 'figure' instead",mplDeprecation)
357+
cbook.warn_deprecated("2.2","fig",obj_type="keyword argument",
358+
alternative="figure")
360359
iffigureisNone:
361360
figure=fig
362361

‎lib/matplotlib/tests/test_rcparams.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def test_rcparams_reset_after_fail():
458458

459459
deftest_if_rctemplate_is_up_to_date():
460460
# This tests if the matplotlibrc.template file contains all valid rcParams.
461-
deprecated= {*mpl._all_deprecated,*mpl._deprecated_set}
461+
deprecated= {*mpl._all_deprecated,*mpl._deprecated_remain_as_none}
462462
path_to_rc=os.path.join(mpl.get_data_path(),'matplotlibrc')
463463
withopen(path_to_rc,"r")asf:
464464
rclines=f.readlines()
@@ -477,8 +477,8 @@ def test_if_rctemplate_is_up_to_date():
477477
ifnotfound:
478478
missing.update({k:v})
479479
ifmissing:
480-
raiseValueError("The following params are missing"+
481-
"in thematplotlibrc.template file: {}"
480+
raiseValueError("The following params are missingin the "
481+
"matplotlibrc.template file: {}"
482482
.format(missing.items()))
483483

484484

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp