From de28b4d5e517127ce201c51795038323d33f1efe Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 18 Jul 2018 19:21:02 +0200 Subject: [PATCH] For property, use decorator or lambdas. Replace ``` def _get_foo(self): ... foo = property(_get_foo) ``` by ``` @property def foo(self): ... ``` or ``` foo = property(lambda self: ...) ``` (for the one-liner cases, when there are many of them, allowing to block them together without blank lines in between). Remove Affine2D.is_separable -- we can just inherit it from Affine2DBase.is_separable. --- .flake8 | 2 +- lib/matplotlib/backend_bases.py | 16 +++---- lib/matplotlib/mathtext.py | 8 ++-- lib/matplotlib/patches.py | 29 +++++++------ lib/matplotlib/textpath.py | 9 ++-- lib/matplotlib/transforms.py | 56 +++++++------------------ lib/mpl_toolkits/axes_grid1/mpl_axes.py | 19 ++++----- 7 files changed, 57 insertions(+), 82 deletions(-) diff --git a/.flake8 b/.flake8 index 0884c4406392..e4e2f3df4485 100644 --- a/.flake8 +++ b/.flake8 @@ -69,7 +69,7 @@ per-file-ignores = mpl_toolkits/axes_grid1/axes_size.py: E261, E501 mpl_toolkits/axes_grid1/colorbar.py: E225, E231, E261, E262, E302, E303, E501, E701 mpl_toolkits/axes_grid1/inset_locator.py: E501 - mpl_toolkits/axes_grid1/mpl_axes.py: E303, E501 + mpl_toolkits/axes_grid1/mpl_axes.py: E501 mpl_toolkits/axisartist/angle_helper.py: E201, E203, E221, E222, E225, E231, E251, E261, E262, E302, E303, E501 mpl_toolkits/axisartist/axis_artist.py: E201, E202, E221, E225, E228, E231, E251, E261, E262, E302, E303, E402, E501, E701, E711 mpl_toolkits/axisartist/axisline_style.py: E231, E261, E262, E302, E303 diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index ce15d9295fac..d11a30a90b6a 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1181,27 +1181,27 @@ def _timer_start(self): def _timer_stop(self): pass - def _get_interval(self): + @property + def interval(self): return self._interval - def _set_interval(self, interval): + @interval.setter + def interval(self, interval): # Force to int since none of the backends actually support fractional # milliseconds, and some error or give warnings. interval = int(interval) self._interval = interval self._timer_set_interval() - interval = property(_get_interval, _set_interval) - - def _get_single_shot(self): + @property + def single_shot(self): return self._single - def _set_single_shot(self, ss=True): + @single_shot.setter + def single_shot(self, ss): self._single = ss self._timer_set_single_shot() - single_shot = property(_get_single_shot, _set_single_shot) - def add_callback(self, func, *args, **kwargs): ''' Register `func` to be called by timer when the event fires. Any diff --git a/lib/matplotlib/mathtext.py b/lib/matplotlib/mathtext.py index 1d4328b44b9d..a01a2f455b62 100644 --- a/lib/matplotlib/mathtext.py +++ b/lib/matplotlib/mathtext.py @@ -2542,13 +2542,15 @@ def copy(self): self.fontsize, self.dpi) - def _get_font(self): + @property + def font(self): return self._font - def _set_font(self, name): + + @font.setter + def font(self, name): if name in ('rm', 'it', 'bf'): self.font_class = name self._font = name - font = property(_get_font, _set_font) def get_state(self): """ diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 932bf594275f..7e1be1aba787 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -835,38 +835,41 @@ def _update_transform(self): .rotate(self.orientation) \ .translate(*self.xy) - def _get_xy(self): + @property + def xy(self): return self._xy - def _set_xy(self, xy): + @xy.setter + def xy(self, xy): self._xy = xy self._update_transform() - xy = property(_get_xy, _set_xy) - def _get_orientation(self): + @property + def orientation(self): return self._orientation - def _set_orientation(self, orientation): + @orientation.setter + def orientation(self, orientation): self._orientation = orientation self._update_transform() - orientation = property(_get_orientation, _set_orientation) - def _get_radius(self): + @property + def radius(self): return self._radius - def _set_radius(self, radius): + @radius.setter + def radius(self, radius): self._radius = radius self._update_transform() - radius = property(_get_radius, _set_radius) - def _get_numvertices(self): + @property + def numvertices(self): return self._numVertices - def _set_numvertices(self, numVertices): + @numvertices.setter + def numvertices(self, numVertices): self._numVertices = numVertices - numvertices = property(_get_numvertices, _set_numvertices) - def get_path(self): return self._path diff --git a/lib/matplotlib/textpath.py b/lib/matplotlib/textpath.py index 2e7f92500ba7..5c0b668f8120 100644 --- a/lib/matplotlib/textpath.py +++ b/lib/matplotlib/textpath.py @@ -437,22 +437,21 @@ def get_size(self): """ return self._size - def _get_vertices(self): + @property + def vertices(self): """ Return the cached path after updating it if necessary. """ self._revalidate_path() return self._cached_vertices - def _get_codes(self): + @property + def codes(self): """ Return the codes """ return self._codes - vertices = property(_get_vertices) - codes = property(_get_codes) - def _revalidate_path(self): """ update the path if necessary. diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index 89942d87e319..7ba551091dd5 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -1702,17 +1702,9 @@ def set(self, child): self.invalidate() self._invalid = 0 - def _get_is_affine(self): - return self._child.is_affine - is_affine = property(_get_is_affine) - - def _get_is_separable(self): - return self._child.is_separable - is_separable = property(_get_is_separable) - - def _get_has_inverse(self): - return self._child.has_inverse - has_inverse = property(_get_has_inverse) + is_affine = property(lambda self: self._child.is_affine) + is_separable = property(lambda self: self._child.is_separable) + has_inverse = property(lambda self: self._child.has_inverse) class AffineBase(Transform): @@ -1799,10 +1791,10 @@ def frozen(self): return Affine2D(self.get_matrix().copy()) frozen.__doc__ = AffineBase.frozen.__doc__ - def _get_is_separable(self): + @property + def is_separable(self): mtx = self.get_matrix() - return mtx[0, 1] == 0.0 and mtx[1, 0] == 0.0 - is_separable = property(_get_is_separable) + return mtx[0, 1] == mtx[1, 0] == 0.0 def to_values(self): """ @@ -2075,11 +2067,6 @@ def skew_deg(self, xShear, yShear): """ return self.skew(np.deg2rad(xShear), np.deg2rad(yShear)) - def _get_is_separable(self): - mtx = self.get_matrix() - return mtx[0, 1] == 0.0 and mtx[1, 0] == 0.0 - is_separable = property(_get_is_separable) - class IdentityTransform(Affine2DBase): """ @@ -2181,13 +2168,9 @@ def contains_branch(self, other): # a blended transform cannot possibly contain a branch from two different transforms. return False - def _get_is_affine(self): - return self._x.is_affine and self._y.is_affine - is_affine = property(_get_is_affine) - - def _get_has_inverse(self): - return self._x.has_inverse and self._y.has_inverse - has_inverse = property(_get_has_inverse) + is_affine = property(lambda self: self._x.is_affine and self._y.is_affine) + has_inverse = property( + lambda self: self._x.has_inverse and self._y.has_inverse) def frozen(self): return blended_transform_factory(self._x.frozen(), self._y.frozen()) @@ -2410,17 +2393,12 @@ def _iter_break_from_left_to_right(self): for left, right in self._b._iter_break_from_left_to_right(): yield self._a + left, right - @property - def depth(self): - return self._a.depth + self._b.depth - - def _get_is_affine(self): - return self._a.is_affine and self._b.is_affine - is_affine = property(_get_is_affine) - - def _get_is_separable(self): - return self._a.is_separable and self._b.is_separable - is_separable = property(_get_is_separable) + depth = property(lambda self: self._a.depth + self._b.depth) + is_affine = property(lambda self: self._a.is_affine and self._b.is_affine) + is_separable = property( + lambda self: self._a.is_separable and self._b.is_separable) + has_inverse = property( + lambda self: self._a.has_inverse and self._b.has_inverse) def __str__(self): return ("{}(\n" @@ -2466,10 +2444,6 @@ def inverted(self): return CompositeGenericTransform(self._b.inverted(), self._a.inverted()) inverted.__doc__ = Transform.inverted.__doc__ - def _get_has_inverse(self): - return self._a.has_inverse and self._b.has_inverse - has_inverse = property(_get_has_inverse) - class CompositeAffine2D(Affine2DBase): """ diff --git a/lib/mpl_toolkits/axes_grid1/mpl_axes.py b/lib/mpl_toolkits/axes_grid1/mpl_axes.py index f59f47208c53..62c93003fdac 100644 --- a/lib/mpl_toolkits/axes_grid1/mpl_axes.py +++ b/lib/mpl_toolkits/axes_grid1/mpl_axes.py @@ -50,11 +50,10 @@ def _init_axis_artists(self, axes=None): left=SimpleAxisArtist(self.yaxis, 1, self.spines["left"]), right=SimpleAxisArtist(self.yaxis, 2, self.spines["right"])) - def _get_axislines(self): + @property + def axis(self): return self._axislines - axis = property(_get_axislines) - def cla(self): super().cla() self._init_axis_artists() @@ -74,24 +73,22 @@ def __init__(self, axis, axisnum, spine): raise ValueError("axis must be instance of XAxis or YAxis : %s is provided" % (axis,)) Artist.__init__(self) - - def _get_major_ticks(self): + @property + def major_ticks(self): tickline = "tick%dline" % self._axisnum return SimpleChainedObjects([getattr(tick, tickline) for tick in self._axis.get_major_ticks()]) - def _get_major_ticklabels(self): + @property + def major_ticklabels(self): label = "label%d" % self._axisnum return SimpleChainedObjects([getattr(tick, label) for tick in self._axis.get_major_ticks()]) - def _get_label(self): + @property + def label(self): return self._axis.label - major_ticks = property(_get_major_ticks) - major_ticklabels = property(_get_major_ticklabels) - label = property(_get_label) - def set_visible(self, b): self.toggle(all=b) self.line.set_visible(b) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy