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

Commit0b71fe0

Browse files
committed
MAINT: deprecate validCap, validJoin
1 parenteeef6e5 commit0b71fe0

File tree

8 files changed

+89
-35
lines changed

8 files changed

+89
-35
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._apiimportMatplotlibDeprecationWarning
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/__init__.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,44 @@
1919
deprecated,warn_deprecated,
2020
_rename_parameter,_delete_parameter,_make_keyword_only,
2121
_deprecate_method_override,_deprecate_privatize_attribute,
22-
_suppress_matplotlib_deprecation_warning,
22+
suppress_matplotlib_deprecation_warning,
2323
MatplotlibDeprecationWarning)
2424

2525

26+
classclassproperty:
27+
"""
28+
Like `property`, but also triggers on access via the class, and it is the
29+
*class* that's passed as argument.
30+
31+
Examples
32+
--------
33+
::
34+
35+
class C:
36+
@classproperty
37+
def foo(cls):
38+
return cls.__name__
39+
40+
assert C.foo == "C"
41+
"""
42+
43+
def__init__(self,fget,fset=None,fdel=None,doc=None):
44+
self._fget=fget
45+
iffsetisnotNoneorfdelisnotNone:
46+
raiseValueError('classproperty only implements fget.')
47+
self.fset=fset
48+
self.fdel=fdel
49+
# docs are ignored for now
50+
self._doc=doc
51+
52+
def__get__(self,instance,owner):
53+
returnself._fget(owner)
54+
55+
@property
56+
deffget(self):
57+
returnself._fget
58+
59+
2660
defcheck_in_list(_values,*,_print_supported_values=True,**kwargs):
2761
"""
2862
For each *key, value* pair in *kwargs*, check that *value* is in *_values*.

‎lib/matplotlib/_api/deprecation.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def the_function_to_deprecate():
186186

187187
defdeprecate(obj,message=message,name=name,alternative=alternative,
188188
pending=pending,obj_type=obj_type,addendum=addendum):
189+
frommatplotlib._apiimportclassproperty
189190

190191
ifisinstance(obj,type):
191192
ifobj_typeisNone:
@@ -202,15 +203,16 @@ def finalize(wrapper, new_doc):
202203
obj.__init__=functools.wraps(obj.__init__)(wrapper)
203204
returnobj
204205

205-
elifisinstance(obj,property):
206+
elifisinstance(obj,(property,classproperty)):
206207
obj_type="attribute"
207208
func=None
208209
name=nameorobj.fget.__name__
209210
old_doc=obj.__doc__
210211

211-
class_deprecated_property(property):
212+
class_deprecated_property(type(obj)):
212213
def__get__(self,instance,owner):
213-
ifinstanceisnotNone:
214+
ifinstanceisnotNoneorownerisnotNone \
215+
andisinstance(self,classproperty):
214216
emit_warning()
215217
returnsuper().__get__(instance,owner)
216218

@@ -518,7 +520,7 @@ def empty_with_docstring(): """doc"""
518520

519521

520522
@contextlib.contextmanager
521-
def_suppress_matplotlib_deprecation_warning():
523+
defsuppress_matplotlib_deprecation_warning():
522524
withwarnings.catch_warnings():
523525
warnings.simplefilter("ignore",MatplotlibDeprecationWarning)
524526
yield

‎lib/matplotlib/cbook/__init__.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929

3030
importmatplotlib
3131
frommatplotlibimport_c_internal_utils
32-
frommatplotlib._apiimportwarn_externalas_warn_external
32+
frommatplotlib._apiimport (
33+
warn_externalas_warn_external,classpropertyas_classproperty)
3334
frommatplotlib._api.deprecationimport (
3435
deprecated,warn_deprecated,
3536
_rename_parameter,_delete_parameter,_make_keyword_only,
3637
_deprecate_method_override,_deprecate_privatize_attribute,
38+
suppress_matplotlib_deprecation_warningas
3739
_suppress_matplotlib_deprecation_warning,
3840
MatplotlibDeprecationWarning,mplDeprecation)
3941

@@ -2262,30 +2264,6 @@ def type_name(tp):
22622264
type_name(type(v))))
22632265

22642266

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-
22892267
def_backend_module_name(name):
22902268
"""
22912269
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: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,18 @@ class Patch(artist.Artist):
3333
are *None*, they default to their rc params setting.
3434
"""
3535
zorder=1
36-
validCap=mlines.Line2D.validCap
37-
validJoin=mlines.Line2D.validJoin
36+
37+
@_api.deprecated("3.4")
38+
@_api.classproperty
39+
defvalidCap(cls):
40+
with_api.suppress_matplotlib_deprecation_warning():
41+
returnmlines.Line2D.validCap
42+
43+
@_api.deprecated("3.4")
44+
@_api.classproperty
45+
defvalidJoin(cls):
46+
with_api.suppress_matplotlib_deprecation_warning():
47+
returnmlines.Line2D.validJoin
3848

3949
# Whether to draw an edge by default. Set on a
4050
# subclass-by-subclass basis.

‎lib/matplotlib/tests/test_api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,16 @@ def test_check_shape(target, test_shape):
1919
data=np.zeros(test_shape)
2020
withpytest.raises(ValueError,match=error_pattern):
2121
_api.check_shape(target,aardvark=data)
22+
23+
24+
deftest_classproperty_deprecation():
25+
classA:
26+
@_api.deprecated("0.0.0")
27+
@_api.classproperty
28+
deff(cls):
29+
pass
30+
withpytest.warns(_api.MatplotlibDeprecationWarning):
31+
A.f
32+
withpytest.warns(_api.MatplotlibDeprecationWarning):
33+
a=A()
34+
a.f

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp