Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Machinery for deprecating properties. #12247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,30 +781,30 @@ class RcParams(MutableMapping, dict):
for key, (default, converter) in defaultParams.items()
if key not in _all_deprecated}

@property
@cbook.deprecated("3.0")
@property
def msg_depr(self):
return "%s is deprecated and replaced with %s; please use the latter."

@property
@cbook.deprecated("3.0")
@property
def msg_depr_ignore(self):
return "%s is deprecated and ignored. Use %s instead."

@property
@cbook.deprecated("3.0")
@property
def msg_depr_set(self):
return ("%s is deprecated. Please remove it from your matplotlibrc "
"and/or style files.")

@property
@cbook.deprecated("3.0")
@property
def msg_obsolete(self):
return ("%s is obsolete. Please remove it from your matplotlibrc "
"and/or style files.")

@property
@cbook.deprecated("3.0")
@property
def msg_backend_obsolete(self):
return ("The {} rcParam was deprecated in version 2.2. In order to "
"force the use of a specific Qt binding, either import that "
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class Artist(object):

Typically, all visible elements in a figure are subclasses of Artist.
"""
@property
@cbook.deprecated("3.1")
@property
def aname(self):
return 'Artist'

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class Axes(_AxesBase):
"""
### Labelling, legend and texts

@property
@cbook.deprecated("3.1")
@property
def aname(self):
return 'Axes'

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,8 +1094,8 @@ def cla(self):

self.stale = True

@property
@cbook.deprecated("3.0")
@property
def mouseover_set(self):
return frozenset(self._mouseover_set)

Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,13 +774,12 @@ def _set_scale(self, value, **kwargs):
def limit_range_for_scale(self, vmin, vmax):
return self._scale.limit_range_for_scale(vmin, vmax, self.get_minpos())

@property
@cbook.deprecated("2.2.0")
@property
def unit_data(self):
return self.units

@unit_data.setter
@cbook.deprecated("2.2.0")
def unit_data(self, unit_data):
self.set_units(unit_data)

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@ def fontName(self, fontprop):

return Fx

@property
@cbook.deprecated("3.0")
@property
def texFontMap(self):
# lazy-load texFontMap, it takes a while to parse
# and usetex is a relatively rare use case
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class PsBackendHelper(object):
def __init__(self):
self._cached = {}

@property
@cbook.deprecated("3.1")
@property
def gs_exe(self):
"""
executable name of ghostscript.
Expand All @@ -64,8 +64,8 @@ def gs_exe(self):
self._cached["gs_exe"] = str(gs_exe)
return str(gs_exe)

@property
@cbook.deprecated("3.1")
@property
def gs_version(self):
"""
version of ghostscript.
Expand All @@ -87,8 +87,8 @@ def gs_version(self):
self._cached["gs_version"] = gs_version
return gs_version

@property
@cbook.deprecated("3.1")
@property
def supports_ps2write(self):
"""
True if the installed ghostscript supports ps2write device.
Expand Down
5 changes: 1 addition & 4 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,18 +377,15 @@ def keyReleaseEvent(self, event):
if key is not None:
FigureCanvasBase.key_release_event(self, key, guiEvent=event)

@cbook.deprecated("3.0", alternative="event.guiEvent.isAutoRepeat")
@property
@cbook.deprecated("3.0", "Manually check `event.guiEvent.isAutoRepeat()` "
"in the event handler.")
def keyAutoRepeat(self):
"""
If True, enable auto-repeat for key events.
"""
return self._keyautorepeat

@keyAutoRepeat.setter
@cbook.deprecated("3.0", "Manually check `event.guiEvent.isAutoRepeat()` "
"in the event handler.")
def keyAutoRepeat(self, val):
self._keyautorepeat = bool(val)

Expand Down
37 changes: 31 additions & 6 deletions lib/matplotlib/cbook/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def warn_deprecated(
def deprecated(since, message='', name='', alternative='', pending=False,
obj_type=None, addendum='', *, removal=''):
"""
Decorator to mark a function or a class as deprecated.
Decorator to mark a function, a class, or a property as deprecated.

When deprecating a classmethod, a staticmethod, or a property, the
``@deprecated`` decorator should go *under* the ``@classmethod``, etc.
Expand Down Expand Up @@ -145,7 +145,7 @@ def deprecated(since, message='', name='', alternative='', pending=False,

def new_function():
...
oldFunction = new_function
old_function = new_function

alternative : str, optional
An alternative API that the user may use in place of the deprecated
Expand Down Expand Up @@ -183,22 +183,47 @@ def the_function_to_deprecate():

def deprecate(obj, message=message, name=name, alternative=alternative,
pending=pending, addendum=addendum):

if not name:
name = obj.__name__

if isinstance(obj, type):
obj_type = "class"
func = obj.__init__
name = name or obj.__name__
old_doc = obj.__doc__

def finalize(wrapper, new_doc):
obj.__doc__ = new_doc
obj.__init__ = wrapper
return obj

elif isinstance(obj, property):
obj_type = "attribute"
func = None
name = name or obj.fget.__name__
old_doc = obj.__doc__

class _deprecated_property(property):
def __get__(self, instance, owner):
from . import _warn_external
_warn_external(message, category)
return super().__get__(instance, owner)

def __set__(self, instance, value):
from . import _warn_external
_warn_external(message, category)
return super().__set__(instance, value)

def __delete__(self, instance):
from . import _warn_external
_warn_external(message, category)
return super().__delete__(instance)

def finalize(_, new_doc):
return _deprecated_property(
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc)

else:
obj_type = "function"
func = obj
name = name or obj.__name__
old_doc = func.__doc__

def finalize(wrapper, new_doc):
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ def clabel(self, *args,
self.labelTextsList = cbook.silent_list('text.Text', self.labelTexts)
return self.labelTextsList

cl = property(cbook.deprecated("3.0", alternative="labelTexts")(
cl = cbook.deprecated("3.0", alternative="labelTexts")(property(
lambda self: self.labelTexts))
cl_xy = property(cbook.deprecated("3.0", alternative="labelXYs")(
cl_xy = cbook.deprecated("3.0", alternative="labelXYs")(property(
lambda self: self.labelXYs))
cl_cvalues = property(cbook.deprecated("3.0", alternative="labelCValues")(
cl_cvalues = cbook.deprecated("3.0", alternative="labelCValues")(property(
lambda self: self.labelCValues))

def print_label(self, linecontour, labelwidth):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,13 +984,13 @@ def __init__(self, size=None, weight='normal'):
self.afmlist = createFontList(afmfiles, fontext='afm')
self.defaultFont['afm'] = afmfiles[0] if afmfiles else None

@property
@cbook.deprecated("3.0")
@property
def ttffiles(self):
return [font.fname for font in self.ttflist]

@property
@cbook.deprecated("3.0")
@property
def afmfiles(self):
return [font.fname for font in self.afmlist]

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class TexManager(object):
# Caches.
rgba_arrayd = {}
grey_arrayd = {}
postscriptd = property(mpl.cbook.deprecated("2.2")(lambda self: {}))
pscnt = property(mpl.cbook.deprecated("2.2")(lambda self: 0))
postscriptd = mpl.cbook.deprecated("2.2")(property(lambda self: {}))
pscnt = mpl.cbook.deprecated("2.2")(property(lambda self: 0))

serif = ('cmr', '')
sans_serif = ('cmss', '')
Expand Down