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

Commit4f55d60

Browse files
committed
MAINT: deprecate validCap, validJoin
1 parent2b055a0 commit4f55d60

File tree

6 files changed

+84
-32
lines changed

6 files changed

+84
-32
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``.

‎lib/matplotlib/_api/deprecation.py

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

1818

19+
class_classproperty:
20+
"""
21+
Like `property`, but also triggers on access via the class, and it is the
22+
*class* that's passed as argument.
23+
24+
Examples
25+
--------
26+
::
27+
28+
class C:
29+
@_classproperty
30+
def foo(cls):
31+
return cls.__name__
32+
33+
assert C.foo == "C"
34+
"""
35+
36+
def__init__(self,fget,fset=None,fdel=None,doc=None):
37+
self._fget=fget
38+
iffsetisnotNoneorfdelisnotNone:
39+
raiseValueError('_classproperty only implements fget.')
40+
self.fset=fset
41+
self.fdel=fdel
42+
# docs are ignored for now
43+
self._doc=doc
44+
45+
def__get__(self,instance,owner):
46+
returnself._fget(owner)
47+
48+
@property
49+
deffget(self):
50+
returnself._fget
51+
52+
1953
classMatplotlibDeprecationWarning(UserWarning):
2054
"""
2155
A class for issuing deprecation warnings for Matplotlib users.
@@ -201,15 +235,15 @@ def finalize(wrapper, new_doc):
201235
obj.__init__=functools.wraps(obj.__init__)(wrapper)
202236
returnobj
203237

204-
elifisinstance(obj,property):
238+
elifisinstance(obj,(property,_classproperty)):
205239
obj_type="attribute"
206240
func=None
207241
name=nameorobj.fget.__name__
208242
old_doc=obj.__doc__
209243

210-
class_deprecated_property(property):
244+
class_deprecated_property(type(obj)):
211245
def__get__(self,instance,owner):
212-
ifinstanceisnotNone:
246+
ifinstanceisnotNoneorownerisnotNone:
213247
emit_warning()
214248
returnsuper().__get__(instance,owner)
215249

‎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: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
importmatplotlibasmpl
1313
from .import_api,artist,cbook,colorsasmcolors,docstring,rcParams
14+
from ._api.deprecationimportdeprecated,_classproperty
1415
from .artistimportArtist,allow_rasterization
1516
from .cbookimport (
1617
_to_unmasked_float_array,ls_mapper,ls_mapper_r,STEP_LOOKUP_MAP)
@@ -251,8 +252,16 @@ class Line2D(Artist):
251252
fillStyles=MarkerStyle.fillstyles
252253

253254
zorder=2
254-
validCap= ('butt','round','projecting')
255-
validJoin= ('miter','round','bevel')
255+
256+
@deprecated("3.4")
257+
@_classproperty
258+
defvalidCap(cls):
259+
return ('butt','round','projecting')
260+
261+
@deprecated("3.4")
262+
@_classproperty
263+
defvalidJoin(cls):
264+
return ('miter','round','bevel')
256265

257266
def__str__(self):
258267
ifself._label!="":

‎lib/matplotlib/patches.py

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

910
importnumpyasnp
1011

1112
importmatplotlibasmpl
1213
from .import (_api,artist,cbook,colors,docstring,hatchasmhatch,
1314
linesasmlines,transforms)
15+
from ._api.deprecationimportdeprecated,_classproperty
1416
from .bezierimport (
1517
NonIntersectingPathException,get_cos_sin,get_intersection,
1618
get_parallels,inside_circle,make_wedged_bezier2,
@@ -33,8 +35,20 @@ class Patch(artist.Artist):
3335
are *None*, they default to their rc params setting.
3436
"""
3537
zorder=1
36-
validCap=mlines.Line2D.validCap
37-
validJoin=mlines.Line2D.validJoin
38+
39+
@deprecated("3.4")
40+
@_classproperty
41+
defvalidCap(cls):
42+
withwarnings.catch_warnings():
43+
cbook._suppress_matplotlib_deprecation_warning()
44+
returnmlines.Line2D.validCap
45+
46+
@deprecated("3.4")
47+
@_classproperty
48+
defvalidJoin(cls):
49+
withwarnings.catch_warnings():
50+
cbook._suppress_matplotlib_deprecation_warning()
51+
returnmlines.Line2D.validJoin
3852

3953
# Whether to draw an edge by default. Set on a
4054
# 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