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

Commitc505b7b

Browse files
committed
MAINT: deprecate validCap, validJoin
1 parent06514d2 commitc505b7b

File tree

6 files changed

+84
-34
lines changed

6 files changed

+84
-34
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/cbook/__init__.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
_rename_parameter,_delete_parameter,_make_keyword_only,
3535
_deprecate_method_override,_deprecate_privatize_attribute,
3636
_suppress_matplotlib_deprecation_warning,
37-
MatplotlibDeprecationWarning,mplDeprecation)
37+
MatplotlibDeprecationWarning,mplDeprecation,_classproperty)
3838

3939

4040
def_get_running_interactive_framework():
@@ -2281,30 +2281,6 @@ def type_name(tp):
22812281
type_name(type(v))))
22822282

22832283

2284-
class_classproperty:
2285-
"""
2286-
Like `property`, but also triggers on access via the class, and it is the
2287-
*class* that's passed as argument.
2288-
2289-
Examples
2290-
--------
2291-
::
2292-
2293-
class C:
2294-
@classproperty
2295-
def foo(cls):
2296-
return cls.__name__
2297-
2298-
assert C.foo == "C"
2299-
"""
2300-
2301-
def__init__(self,fget):
2302-
self._fget=fget
2303-
2304-
def__get__(self,instance,owner):
2305-
returnself._fget(owner)
2306-
2307-
23082284
def_backend_module_name(name):
23092285
"""
23102286
Convert a backend name (either a standard backend -- "Agg", "TkAgg", ... --

‎lib/matplotlib/cbook/deprecation.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,41 @@
44
importwarnings
55

66

7+
# has to be here to prevent circular import, since it's used by `deprecated`
8+
class_classproperty:
9+
"""
10+
Like `property`, but also triggers on access via the class, and it is the
11+
*class* that's passed as argument.
12+
13+
Examples
14+
--------
15+
::
16+
17+
class C:
18+
@_classproperty
19+
def foo(cls):
20+
return cls.__name__
21+
22+
assert C.foo == "C"
23+
"""
24+
25+
def__init__(self,fget,fset=None,fdel=None,doc=None):
26+
self._fget=fget
27+
iffsetisnotNoneorfdelisnotNone:
28+
raiseValueError('_classproperty only implements fget.')
29+
self.fset=fset
30+
self.fdel=fdel
31+
# docs are ignored for now
32+
self._doc=doc
33+
34+
def__get__(self,instance,owner):
35+
returnself._fget(owner)
36+
37+
@property
38+
deffget(self):
39+
returnself._fget
40+
41+
742
classMatplotlibDeprecationWarning(UserWarning):
843
"""
944
A class for issuing deprecation warnings for Matplotlib users.
@@ -189,15 +224,15 @@ def finalize(wrapper, new_doc):
189224
obj.__init__=functools.wraps(obj.__init__)(wrapper)
190225
returnobj
191226

192-
elifisinstance(obj,property):
227+
elifisinstance(obj,(property,_classproperty)):
193228
obj_type="attribute"
194229
func=None
195230
name=nameorobj.fget.__name__
196231
old_doc=obj.__doc__
197232

198-
class_deprecated_property(property):
233+
class_deprecated_property(type(obj)):
199234
def__get__(self,instance,owner):
200-
ifinstanceisnotNone:
235+
ifinstanceisnotNoneorownerisnotNone:
201236
emit_warning()
202237
returnsuper().__get__(instance,owner)
203238

@@ -218,7 +253,8 @@ def __set_name__(self, owner, set_name):
218253

219254
deffinalize(_,new_doc):
220255
return_deprecated_property(
221-
fget=obj.fget,fset=obj.fset,fdel=obj.fdel,doc=new_doc)
256+
fget=obj.fget,fset=obj.fset,fdel=obj.fdel,
257+
doc=new_doc)
222258

223259
else:
224260
ifobj_typeisNone:

‎lib/matplotlib/lines.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from .import_api,artist,cbook,colorsasmcolors,docstring,rcParams
1414
from .artistimportArtist,allow_rasterization
1515
from .cbookimport (
16-
_to_unmasked_float_array,ls_mapper,ls_mapper_r,STEP_LOOKUP_MAP)
16+
_to_unmasked_float_array,ls_mapper,ls_mapper_r,STEP_LOOKUP_MAP,
17+
deprecated,_classproperty)
1718
from .colorsimportis_color_like,get_named_colors_mapping
1819
from .markersimportMarkerStyle
1920
from .pathimportPath
@@ -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.0")
257+
@_classproperty
258+
defvalidCap(cls):
259+
return ('butt','round','projecting')
260+
261+
@deprecated("3.4.0")
262+
@_classproperty
263+
defvalidJoin(cls):
264+
return ('miter','round','bevel')
256265

257266
def__str__(self):
258267
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+
@cbook.deprecated("3.4.0")
39+
@cbook._classproperty
40+
defvalidCap(cls):
41+
withwarnings.catch_warnings():
42+
warnings.filterwarnings("ignore",category=DeprecationWarning)
43+
returnmlines.Line2D.validCap
44+
45+
@cbook.deprecated("3.4.0")
46+
@cbook._classproperty
47+
defvalidJoin(cls):
48+
withwarnings.catch_warnings():
49+
warnings.filterwarnings("ignore",category=DeprecationWarning)
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_cbook.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,3 +765,16 @@ def test_format_approx():
765765
assertf(0.0012345600001,5)=='0.00123'
766766
assertf(-0.0012345600001,5)=='-0.00123'
767767
assertf(0.0012345600001,8)==f(0.0012345600001,10)=='0.00123456'
768+
769+
770+
deftest_classproperty_deprecation():
771+
classA:
772+
@cbook.deprecated("0.0.0")
773+
@cbook._classproperty
774+
deff(cls):
775+
pass
776+
withpytest.warns(cbook.MatplotlibDeprecationWarning):
777+
A.f
778+
withpytest.warns(cbook.MatplotlibDeprecationWarning):
779+
a=A()
780+
a.f

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp