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

Commitaed162f

Browse files
committed
MAINT: deprecate validCap, validJoin
1 parent82e2f94 commitaed162f

File tree

7 files changed

+92
-33
lines changed

7 files changed

+92
-33
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Line2D and Patch no longer duplicate ``validJoin`` and ``validCap``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Validation of joinstyle and capstyles is now centralized in ``rcsetup``.

‎doc/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
importshutil
1414
importsubprocess
1515
importsys
16+
importwarnings
1617

1718
importmatplotlib
19+
frommatplotlib._api.deprecationimportMatplotlibDeprecationWarning
1820
importsphinx
1921

2022
fromdatetimeimportdatetime
@@ -109,6 +111,11 @@ def _check_dependencies():
109111
autodoc_docstring_signature=True
110112
autodoc_default_options= {'members':None,'undoc-members':None}
111113

114+
# make sure to ignore warnings that stem from simply inspecting deprecated
115+
# class-level attributes
116+
warnings.filterwarnings('ignore',category=MatplotlibDeprecationWarning,
117+
module='sphinx.util.inspect')
118+
112119
# missing-references names matches sphinx>=3 behavior, so we can't be nitpicky
113120
# for older sphinxes.
114121
nitpicky=sphinx.version_info>= (3,)

‎lib/matplotlib/_api/deprecation.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,42 @@
1616
importwarnings
1717

1818

19+
# has to be here (instead of cbook) to prevent circular import, since
20+
# deprecation.deprecated is *used* during cbook's import
21+
class_classproperty:
22+
"""
23+
Like `property`, but also triggers on access via the class, and it is the
24+
*class* that's passed as argument.
25+
26+
Examples
27+
--------
28+
::
29+
30+
class C:
31+
@_classproperty
32+
def foo(cls):
33+
return cls.__name__
34+
35+
assert C.foo == "C"
36+
"""
37+
38+
def__init__(self,fget,fset=None,fdel=None,doc=None):
39+
self._fget=fget
40+
iffsetisnotNoneorfdelisnotNone:
41+
raiseValueError('_classproperty only implements fget.')
42+
self.fset=fset
43+
self.fdel=fdel
44+
# docs are ignored for now
45+
self._doc=doc
46+
47+
def__get__(self,instance,owner):
48+
returnself._fget(owner)
49+
50+
@property
51+
deffget(self):
52+
returnself._fget
53+
54+
1955
classMatplotlibDeprecationWarning(UserWarning):
2056
"""
2157
A class for issuing deprecation warnings for Matplotlib users.
@@ -201,15 +237,16 @@ def finalize(wrapper, new_doc):
201237
obj.__init__=functools.wraps(obj.__init__)(wrapper)
202238
returnobj
203239

204-
elifisinstance(obj,property):
240+
elifisinstance(obj,(property,_classproperty)):
205241
obj_type="attribute"
206242
func=None
207243
name=nameorobj.fget.__name__
208244
old_doc=obj.__doc__
209245

210-
class_deprecated_property(property):
246+
class_deprecated_property(type(obj)):
211247
def__get__(self,instance,owner):
212-
ifinstanceisnotNone:
248+
ifinstanceisnotNoneorownerisnotNone \
249+
andisinstance(self,_classproperty):
213250
emit_warning()
214251
returnsuper().__get__(instance,owner)
215252

‎lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
_rename_parameter,_delete_parameter,_make_keyword_only,
3636
_deprecate_method_override,_deprecate_privatize_attribute,
3737
_suppress_matplotlib_deprecation_warning,
38-
MatplotlibDeprecationWarning,mplDeprecation)
38+
MatplotlibDeprecationWarning,mplDeprecation,_classproperty)
3939

4040

4141
def_get_running_interactive_framework():
@@ -2262,30 +2262,6 @@ def type_name(tp):
22622262
type_name(type(v))))
22632263

22642264

2265-
class_classproperty:
2266-
"""
2267-
Like `property`, but also triggers on access via the class, and it is the
2268-
*class* that's passed as argument.
2269-
2270-
Examples
2271-
--------
2272-
::
2273-
2274-
class C:
2275-
@classproperty
2276-
def foo(cls):
2277-
return cls.__name__
2278-
2279-
assert C.foo == "C"
2280-
"""
2281-
2282-
def__init__(self,fget):
2283-
self._fget=fget
2284-
2285-
def__get__(self,instance,owner):
2286-
returnself._fget(owner)
2287-
2288-
22892265
def_backend_module_name(name):
22902266
"""
22912267
Convert a backend name (either a standard backend -- "Agg", "TkAgg", ... --

‎lib/matplotlib/lines.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
colors.
44
"""
55

6-
# TODO: expose cap and join style attrs
76
fromnumbersimportIntegral,Number,Real
87
importlogging
98

@@ -251,8 +250,16 @@ class Line2D(Artist):
251250
fillStyles=MarkerStyle.fillstyles
252251

253252
zorder=2
254-
validCap= ('butt','round','projecting')
255-
validJoin= ('miter','round','bevel')
253+
254+
@_api.deprecated("3.4")
255+
@_api._classproperty
256+
defvalidCap(cls):
257+
return ('butt','round','projecting')
258+
259+
@_api.deprecated("3.4")
260+
@_api._classproperty
261+
defvalidJoin(cls):
262+
return ('miter','round','bevel')
256263

257264
def__str__(self):
258265
ifself._label!="":

‎lib/matplotlib/patches.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
fromnumbersimportNumber
66
importtextwrap
77
fromcollectionsimportnamedtuple
8+
importwarnings
89

910
importnumpyasnp
1011

@@ -33,8 +34,20 @@ class Patch(artist.Artist):
3334
are *None*, they default to their rc params setting.
3435
"""
3536
zorder=1
36-
validCap=mlines.Line2D.validCap
37-
validJoin=mlines.Line2D.validJoin
37+
38+
@_api.deprecated("3.4")
39+
@_api._classproperty
40+
defvalidCap(cls):
41+
withwarnings.catch_warnings():
42+
cbook._suppress_matplotlib_deprecation_warning()
43+
returnmlines.Line2D.validCap
44+
45+
@_api.deprecated("3.4")
46+
@_api._classproperty
47+
defvalidJoin(cls):
48+
withwarnings.catch_warnings():
49+
cbook._suppress_matplotlib_deprecation_warning()
50+
returnmlines.Line2D.validJoin
3851

3952
# Whether to draw an edge by default. Set on a
4053
# subclass-by-subclass basis.

‎lib/matplotlib/tests/test_api.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
importpytest
55

66
frommatplotlibimport_api
7+
frommatplotlib.cbookimport (
8+
_classproperty,MatplotlibDeprecationWarning)
9+
frommatplotlib._api.deprecationimportdeprecated
710

811

912
@pytest.mark.parametrize('target,test_shape',
@@ -19,3 +22,16 @@ def test_check_shape(target, test_shape):
1922
data=np.zeros(test_shape)
2023
withpytest.raises(ValueError,match=error_pattern):
2124
_api.check_shape(target,aardvark=data)
25+
26+
27+
deftest_classproperty_deprecation():
28+
classA:
29+
@deprecated("0.0.0")
30+
@_classproperty
31+
deff(cls):
32+
pass
33+
withpytest.warns(MatplotlibDeprecationWarning):
34+
A.f
35+
withpytest.warns(MatplotlibDeprecationWarning):
36+
a=A()
37+
a.f

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp