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

Commitd9674c3

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

File tree

6 files changed

+87
-32
lines changed

6 files changed

+87
-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: 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: 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