Skip to content

Shorter property deprecation. #18688

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 17, 2020
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: 2 additions & 8 deletions lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,7 @@ def __init__(self, default_font_prop, mathtext_backend=None):
self.fonts['default'] = default_font
self.fonts['regular'] = default_font

@cbook.deprecated("3.4")
@property
def pswriter(self):
return StringIO()
pswriter = cbook.deprecated("3.4")(property(lambda self: StringIO()))

def _get_font(self, font):
if font in self.fontmap:
Expand Down Expand Up @@ -1562,10 +1559,7 @@ class Glue(Node):
it's easier to stick to what TeX does.)
"""

@cbook.deprecated("3.3")
@property
def glue_subtype(self):
return "normal"
glue_subtype = cbook.deprecated("3.3")(property(lambda self: "normal"))

@cbook._delete_parameter("3.3", "copy")
def __init__(self, glue_type, copy=False):
Expand Down
7 changes: 2 additions & 5 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,11 +778,8 @@ class HTMLWriter(FileMovieWriter):
"""Writer for JavaScript-based HTML movies."""

supported_formats = ['png', 'jpeg', 'tiff', 'svg']

@cbook.deprecated("3.3")
@property
def args_key(self):
return 'animation.html_args'
args_key = cbook.deprecated("3.3")(property(
lambda self: 'animation.html_args'))

@classmethod
def isAvailable(cls):
Expand Down
8 changes: 3 additions & 5 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2709,6 +2709,9 @@ class FigureManagerBase:
figure.canvas.mpl_disconnect(
figure.canvas.manager.button_press_handler_id)
"""

statusbar = cbook.deprecated("3.3")(property(lambda self: None))

def __init__(self, canvas, num):
self.canvas = canvas
canvas.manager = self # store a pointer to parent
Expand All @@ -2735,11 +2738,6 @@ def notify_axes_change(fig):
if self.toolmanager is None and self.toolbar is not None:
self.toolbar.update()

@cbook.deprecated("3.3")
@property
def statusbar(self):
return None

def show(self):
"""
For GUI backends, show the figure window and redraw.
Expand Down
71 changes: 33 additions & 38 deletions lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,40 +91,40 @@ def attr(field):
return name, slant, weight


# Mappings used for deprecated properties in RendererCairo, see below.
_f_weights = {
100: cairo.FONT_WEIGHT_NORMAL,
200: cairo.FONT_WEIGHT_NORMAL,
300: cairo.FONT_WEIGHT_NORMAL,
400: cairo.FONT_WEIGHT_NORMAL,
500: cairo.FONT_WEIGHT_NORMAL,
600: cairo.FONT_WEIGHT_BOLD,
700: cairo.FONT_WEIGHT_BOLD,
800: cairo.FONT_WEIGHT_BOLD,
900: cairo.FONT_WEIGHT_BOLD,
'ultralight': cairo.FONT_WEIGHT_NORMAL,
'light': cairo.FONT_WEIGHT_NORMAL,
'normal': cairo.FONT_WEIGHT_NORMAL,
'medium': cairo.FONT_WEIGHT_NORMAL,
'regular': cairo.FONT_WEIGHT_NORMAL,
'semibold': cairo.FONT_WEIGHT_BOLD,
'bold': cairo.FONT_WEIGHT_BOLD,
'heavy': cairo.FONT_WEIGHT_BOLD,
'ultrabold': cairo.FONT_WEIGHT_BOLD,
'black': cairo.FONT_WEIGHT_BOLD,
}
_f_angles = {
'italic': cairo.FONT_SLANT_ITALIC,
'normal': cairo.FONT_SLANT_NORMAL,
'oblique': cairo.FONT_SLANT_OBLIQUE,
}


class RendererCairo(RendererBase):
@cbook.deprecated("3.3")
@property
def fontweights(self):
return {
100: cairo.FONT_WEIGHT_NORMAL,
200: cairo.FONT_WEIGHT_NORMAL,
300: cairo.FONT_WEIGHT_NORMAL,
400: cairo.FONT_WEIGHT_NORMAL,
500: cairo.FONT_WEIGHT_NORMAL,
600: cairo.FONT_WEIGHT_BOLD,
700: cairo.FONT_WEIGHT_BOLD,
800: cairo.FONT_WEIGHT_BOLD,
900: cairo.FONT_WEIGHT_BOLD,
'ultralight': cairo.FONT_WEIGHT_NORMAL,
'light': cairo.FONT_WEIGHT_NORMAL,
'normal': cairo.FONT_WEIGHT_NORMAL,
'medium': cairo.FONT_WEIGHT_NORMAL,
'regular': cairo.FONT_WEIGHT_NORMAL,
'semibold': cairo.FONT_WEIGHT_BOLD,
'bold': cairo.FONT_WEIGHT_BOLD,
'heavy': cairo.FONT_WEIGHT_BOLD,
'ultrabold': cairo.FONT_WEIGHT_BOLD,
'black': cairo.FONT_WEIGHT_BOLD,
}

@cbook.deprecated("3.3")
@property
def fontangles(self):
return {
'italic': cairo.FONT_SLANT_ITALIC,
'normal': cairo.FONT_SLANT_NORMAL,
'oblique': cairo.FONT_SLANT_OBLIQUE,
}
fontweights = cbook.deprecated("3.3")(property(lambda self: {*_f_weights}))
fontangles = cbook.deprecated("3.3")(property(lambda self: {*_f_angles}))
mathtext_parser = cbook.deprecated("3.4")(
property(lambda self: MathTextParser('Cairo')))

def __init__(self, dpi):
self.dpi = dpi
Expand All @@ -133,11 +133,6 @@ def __init__(self, dpi):
cairo.ImageSurface(cairo.FORMAT_ARGB32, 1, 1))
super().__init__()

@cbook.deprecated("3.4")
@property
def mathtext_parser(self):
return MathTextParser('Cairo')

def set_ctx_from_surface(self, surface):
self.gc.ctx = cairo.Context(surface)
# Although it may appear natural to automatically call
Expand Down
8 changes: 3 additions & 5 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ def resize(self, width, height):


class NavigationToolbar2GTK3(NavigationToolbar2, Gtk.Toolbar):
ctx = cbook.deprecated("3.3")(property(
lambda self: self.canvas.get_property("window").cairo_create()))

def __init__(self, canvas, window):
self.win = window
GObject.GObject.__init__(self)
Expand Down Expand Up @@ -541,11 +544,6 @@ def __init__(self, canvas, window):

NavigationToolbar2.__init__(self, canvas)

@cbook.deprecated("3.3")
@property
def ctx(self):
return self.canvas.get_property("window").cairo_create()

def set_message(self, s):
escaped = GLib.markup_escape_text(s)
self.message.set_markup(f'<small>{escaped}</small>')
Expand Down
6 changes: 1 addition & 5 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ class PdfPages:
'_info_dict',
'_metadata',
)
metadata = cbook.deprecated('3.3')(property(lambda self: self._metadata))

def __init__(self, filename, *, keep_empty=True, metadata=None):
"""
Expand Down Expand Up @@ -1006,11 +1007,6 @@ def __init__(self, filename, *, keep_empty=True, metadata=None):
self._info_dict = _create_pdf_info_dict('pgf', self._metadata)
self._file = BytesIO()

@cbook.deprecated('3.3')
@property
def metadata(self):
return self._metadata

def _write_header(self, width_inches, height_inches):
hyperref_options = ','.join(
_metadata_to_str(k, v) for k, v in self._info_dict.items())
Expand Down
15 changes: 5 additions & 10 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ class RendererPS(_backend_pdf_ps.RendererPDFPSBase):
_afm_font_dir = cbook._get_data_path("fonts/afm")
_use_afm_rc_name = "ps.useafm"

mathtext_parser = cbook.deprecated("3.4")(property(
lambda self: MathTextParser("PS")))
used_characters = cbook.deprecated("3.3")(property(
lambda self: self._character_tracker.used_characters))

def __init__(self, width, height, pswriter, imagedpi=72):
# Although postscript itself is dpi independent, we need to inform the
# image code about a requested dpi to generate high resolution images
Expand All @@ -249,16 +254,6 @@ def __init__(self, width, height, pswriter, imagedpi=72):

self._character_tracker = _backend_pdf_ps.CharacterTracker()

@cbook.deprecated("3.3")
@property
def mathtext_parser(self):
return MathTextParser("PS")
Comment on lines -252 to -255
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be the wrong 'since' version, I guess?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes (#18002)


@cbook.deprecated("3.3")
@property
def used_characters(self):
return self._character_tracker.used_characters

@cbook.deprecated("3.3")
def track_characters(self, *args, **kwargs):
"""Keep track of which characters are required from each font."""
Expand Down
25 changes: 14 additions & 11 deletions lib/matplotlib/cbook/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,24 @@ def finalize(wrapper, new_doc):
class _deprecated_property(property):
def __get__(self, instance, owner):
if instance is not None:
from . import _warn_external
_warn_external(warning)
emit_warning()
return super().__get__(instance, owner)

def __set__(self, instance, value):
if instance is not None:
from . import _warn_external
_warn_external(warning)
emit_warning()
return super().__set__(instance, value)

def __delete__(self, instance):
if instance is not None:
from . import _warn_external
_warn_external(warning)
emit_warning()
return super().__delete__(instance)

def __set_name__(self, owner, set_name):
nonlocal name
if name == "<lambda>":
name = set_name

def finalize(_, new_doc):
return _deprecated_property(
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc)
Expand All @@ -224,13 +226,14 @@ def finalize(wrapper, new_doc):
wrapper.__doc__ = new_doc
return wrapper

warning = _generate_deprecation_warning(
since, message, name, alternative, pending, obj_type, addendum,
removal=removal)
def emit_warning():
warn_deprecated(
since, message=message, name=name, alternative=alternative,
pending=pending, obj_type=obj_type, addendum=addendum,
removal=removal)

def wrapper(*args, **kwargs):
from . import _warn_external
_warn_external(warning)
emit_warning()
return func(*args, **kwargs)

old_doc = inspect.cleandoc(old_doc or '').strip('\n')
Expand Down
7 changes: 2 additions & 5 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ class ContourSet(cm.ScalarMappable, ContourLabeler):
%(contour_set_attributes)s
"""

ax = cbook.deprecated("3.3")(property(lambda self: self.axes))

def __init__(self, ax, *args,
levels=None, filled=False, linewidths=None, linestyles=None,
hatches=(None,), alpha=None, origin=None, extent=None,
Expand Down Expand Up @@ -907,11 +909,6 @@ def __init__(self, ax, *args,
cbook._warn_external('The following kwargs were not used by '
'contour: ' + s)

@cbook.deprecated("3.3")
@property
def ax(self):
return self.axes

def get_transform(self):
"""
Return the :class:`~matplotlib.transforms.Transform`
Expand Down
45 changes: 14 additions & 31 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,43 +80,26 @@ class TexManager:
'computer modern sans serif': ('cmss', r'\usepackage{type1ec}'),
'computer modern typewriter': ('cmtt', r'\usepackage{type1ec}')}

@cbook.deprecated("3.3", alternative="matplotlib.get_cachedir()")
@property
def cachedir(self):
return mpl.get_cachedir()

@cbook.deprecated("3.3")
@property
def rgba_arrayd(self):
return {}
cachedir = cbook.deprecated(
"3.3", alternative="matplotlib.get_cachedir()")(
property(lambda self: mpl.get_cachedir()))
rgba_arrayd = cbook.deprecated("3.3")(property(lambda self: {}))
_fonts = {} # Only for deprecation period.
serif = cbook.deprecated("3.3")(property(
lambda self: self._fonts.get("serif", ('cmr', ''))))
sans_serif = cbook.deprecated("3.3")(property(
lambda self: self._fonts.get("sans-serif", ('cmss', ''))))
cursive = cbook.deprecated("3.3")(property(
lambda self:
self._fonts.get("cursive", ('pzc', r'\usepackage{chancery}'))))
monospace = cbook.deprecated("3.3")(property(
lambda self: self._fonts.get("monospace", ('cmtt', ''))))

@functools.lru_cache() # Always return the same instance.
def __new__(cls):
Path(cls.texcache).mkdir(parents=True, exist_ok=True)
return object.__new__(cls)

_fonts = {} # Only for deprecation period.

@cbook.deprecated("3.3")
@property
def serif(self):
return self._fonts.get("serif", ('cmr', ''))

@cbook.deprecated("3.3")
@property
def sans_serif(self):
return self._fonts.get("sans-serif", ('cmss', ''))

@cbook.deprecated("3.3")
@property
def cursive(self):
return self._fonts.get("cursive", ('pzc', r'\usepackage{chancery}'))

@cbook.deprecated("3.3")
@property
def monospace(self):
return self._fonts.get("monospace", ('cmtt', ''))

def get_font_config(self):
ff = rcParams['font.family']
if len(ff) == 1 and ff[0].lower() in self.font_families:
Expand Down
Loading