From a87445ca84f6d51c8e84a11059d0b621eab3be4a Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 27 Feb 2018 21:20:20 -0800 Subject: [PATCH] Boring style fixes. --- examples/statistics/barchart_demo.py | 8 ++++---- examples/units/basic_units.py | 6 +++--- lib/matplotlib/backends/backend_ps.py | 11 ++++++----- lib/matplotlib/cbook/__init__.py | 2 +- lib/matplotlib/collections.py | 2 +- lib/matplotlib/figure.py | 4 ++-- lib/matplotlib/gridspec.py | 2 +- lib/matplotlib/legend.py | 2 +- lib/matplotlib/lines.py | 5 +---- lib/matplotlib/patches.py | 4 ++-- lib/matplotlib/path.py | 2 +- lib/matplotlib/tests/test_patches.py | 2 +- lib/matplotlib/tests/test_text.py | 2 +- lib/matplotlib/ticker.py | 8 ++++---- lib/matplotlib/tri/triinterpolate.py | 2 +- lib/matplotlib/widgets.py | 4 ++-- lib/mpl_toolkits/axes_grid1/axes_grid.py | 2 +- lib/mpl_toolkits/axisartist/axis_artist.py | 10 +++++----- lib/mpl_toolkits/axisartist/floating_axes.py | 3 +-- .../axisartist/grid_helper_curvelinear.py | 3 +-- setupext.py | 2 +- 21 files changed, 41 insertions(+), 45 deletions(-) diff --git a/examples/statistics/barchart_demo.py b/examples/statistics/barchart_demo.py index e4ea9022806c..c8642a3ec745 100644 --- a/examples/statistics/barchart_demo.py +++ b/examples/statistics/barchart_demo.py @@ -77,9 +77,9 @@ def attach_ordinal(num): 1 -> 1st 56 -> 56th """ - suffixes = dict((str(i), v) for i, v in - enumerate(['th', 'st', 'nd', 'rd', 'th', - 'th', 'th', 'th', 'th', 'th'])) + suffixes = {str(i): v + for i, v in enumerate(['th', 'st', 'nd', 'rd', 'th', + 'th', 'th', 'th', 'th', 'th'])} v = str(num) # special case early teens @@ -170,7 +170,7 @@ def plot_student_results(student, scores, cohort_size): rankStr = attach_ordinal(width) # The bars aren't wide enough to print the ranking inside - if (width < 5): + if width < 5: # Shift the text to the right side of the right edge xloc = width + 1 # Black against white background diff --git a/examples/units/basic_units.py b/examples/units/basic_units.py index 67ffa36f6fac..0af2e1dd576d 100644 --- a/examples/units/basic_units.py +++ b/examples/units/basic_units.py @@ -249,13 +249,13 @@ def get_unit(self): class UnitResolver(object): def addition_rule(self, units): for unit_1, unit_2 in zip(units[:-1], units[1:]): - if (unit_1 != unit_2): + if unit_1 != unit_2: return NotImplemented return units[0] def multiplication_rule(self, units): non_null = [u for u in units if u] - if (len(non_null) > 1): + if len(non_null) > 1: return NotImplemented return non_null[0] @@ -268,7 +268,7 @@ def multiplication_rule(self, units): '__rsub__': addition_rule} def __call__(self, operation, units): - if (operation not in self.op_dict): + if operation not in self.op_dict: return NotImplemented return self.op_dict[operation](self, units) diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index d72a1d69d398..b705fc867ad8 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -266,15 +266,16 @@ def set_linedash(self, offset, seq, store=1): self.linedash = (offset, seq) def set_font(self, fontname, fontsize, store=1): - if rcParams['ps.useafm']: return - if (fontname,fontsize) != (self.fontname,self.fontsize): + if rcParams['ps.useafm']: + return + if (fontname, fontsize) != (self.fontname,self.fontsize): out = ("/%s findfont\n" "%1.3f scalefont\n" "setfont\n" % (fontname, fontsize)) - self._pswriter.write(out) - if store: self.fontname = fontname - if store: self.fontsize = fontsize + if store: + self.fontname = fontname + self.fontsize = fontsize def create_hatch(self, hatch): sidelen = 72 diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 35bed7f46f3c..13e8d66d82db 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -1095,7 +1095,7 @@ def delete_masked_points(*args): """ if not len(args): return () - if isinstance(args[0], str) or not iterable(args[0]): + if is_scalar_or_string(args[0]): raise ValueError("First argument must be a sequence") nrecs = len(args[0]) margs = [] diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index d2f7c11ba305..674167c3057f 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -964,7 +964,7 @@ def set_verts(self, verts, closed=True): def set_verts_and_codes(self, verts, codes): '''This allows one to initialize vertices with path codes.''' - if (len(verts) != len(codes)): + if len(verts) != len(codes): raise ValueError("'codes' must be a 1D list or array " "with the same length of 'verts'") self._paths = [] diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index ef400898d802..30827ce49a46 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -737,9 +737,9 @@ def suptitle(self, t, **kwargs): x = kwargs.pop('x', 0.5) y = kwargs.pop('y', 0.98) - if ('horizontalalignment' not in kwargs) and ('ha' not in kwargs): + if 'horizontalalignment' not in kwargs and 'ha' not in kwargs: kwargs['horizontalalignment'] = 'center' - if ('verticalalignment' not in kwargs) and ('va' not in kwargs): + if 'verticalalignment' not in kwargs and 'va' not in kwargs: kwargs['verticalalignment'] = 'top' if 'fontproperties' not in kwargs: diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index a9cfc5e9ffbc..9e4faa2b98a9 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -212,7 +212,7 @@ def __init__(self, nrows, ncols, figure=None, width_ratios=width_ratios, height_ratios=height_ratios) - if (self.figure is None) or not self.figure.get_constrained_layout(): + if self.figure is None or not self.figure.get_constrained_layout(): self._layoutbox = None else: self.figure.init_layoutbox() diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index 00e63951cd18..22801e6c2641 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -1242,7 +1242,7 @@ def _get_legend_handles_labels(axs, legend_handler_map=None): for handle in _get_legend_handles(axs, legend_handler_map): label = handle.get_label() - if (label and not label.startswith('_')): + if label and not label.startswith('_'): handles.append(handle) labels.append(label) return handles, labels diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 3f30770767d3..dc0c4cdcc0e7 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -882,10 +882,7 @@ def get_markeredgewidth(self): return self._markeredgewidth def _get_markerfacecolor(self, alt=False): - if alt: - fc = self._markerfacecoloralt - else: - fc = self._markerfacecolor + fc = self._markerfacecoloralt if alt else self._markerfacecolor if cbook._str_lower_equal(fc, 'auto'): if self.get_fillstyle() == 'none': return 'none' diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 1b037751c19b..932bf594275f 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -71,9 +71,9 @@ def __init__(self, self._hatch_color = colors.to_rgba(mpl.rcParams['hatch.color']) self._fill = True # needed for set_facecolor call if color is not None: - if (edgecolor is not None or facecolor is not None): + if edgecolor is not None or facecolor is not None: warnings.warn("Setting the 'color' property will override" - "the edgecolor or facecolor properties. ") + "the edgecolor or facecolor properties.") self.set_color(color) else: self.set_edgecolor(edgecolor) diff --git a/lib/matplotlib/path.py b/lib/matplotlib/path.py index e2cee67974bf..3fb70ed8d3ac 100644 --- a/lib/matplotlib/path.py +++ b/lib/matplotlib/path.py @@ -131,7 +131,7 @@ def __init__(self, vertices, codes=None, _interpolation_steps=1, if codes is not None: codes = np.asarray(codes, self.code_type) - if (codes.ndim != 1) or len(codes) != len(vertices): + if codes.ndim != 1 or len(codes) != len(vertices): raise ValueError("'codes' must be a 1D list or array with the " "same length of 'vertices'") if len(codes) and codes[0] != self.MOVETO: diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index f81e066046d4..1d0319b138ba 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -250,7 +250,7 @@ def test_wedge_movement(): 'theta1': (0, 30, 'set_theta1'), 'theta2': (45, 50, 'set_theta2')} - init_args = dict((k, v[0]) for (k, v) in param_dict.items()) + init_args = {k: v[0] for k, v in param_dict.items()} w = mpatches.Wedge(**init_args) for attr, (old_v, new_v, func) in param_dict.items(): diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index 4474099738c5..b9228523abef 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -435,7 +435,7 @@ def test_two_2line_texts(spacing1, spacing2): # line spacing only affects height assert box1.width == box2.width - if (spacing1 == spacing2): + if spacing1 == spacing2: assert box1.height == box2.height else: assert box1.height != box2.height diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index abac4392dca6..a967f8e8bc4a 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2410,12 +2410,12 @@ def tick_values(self, vmin, vmax): ticklocs = [] if decade_min <= -1: expo = np.arange(decade_min, min(0, decade_max + 1)) - ticklocs.extend(list(10**expo)) + ticklocs.extend(10**expo) if decade_min <= 0 <= decade_max: ticklocs.append(0.5) if decade_max >= 1: expo = -np.arange(max(1, decade_min), decade_max + 1) - ticklocs.extend(list(1 - 10**expo)) + ticklocs.extend(1 - 10**expo) # minor ticks else: @@ -2423,13 +2423,13 @@ def tick_values(self, vmin, vmax): if decade_min <= -2: expo = np.arange(decade_min, min(-1, decade_max)) newticks = np.outer(np.arange(2, 10), 10**expo).ravel() - ticklocs.extend(list(newticks)) + ticklocs.extend(newticks) if decade_min <= 0 <= decade_max: ticklocs.extend([0.2, 0.3, 0.4, 0.6, 0.7, 0.8]) if decade_max >= 2: expo = -np.arange(max(2, decade_min), decade_max + 1) newticks = 1 - np.outer(np.arange(2, 10), 10**expo).ravel() - ticklocs.extend(list(newticks)) + ticklocs.extend(newticks) return self.raise_if_exceeds(np.array(ticklocs)) diff --git a/lib/matplotlib/tri/triinterpolate.py b/lib/matplotlib/tri/triinterpolate.py index 1aefc77e64a6..48d9d5c82681 100644 --- a/lib/matplotlib/tri/triinterpolate.py +++ b/lib/matplotlib/tri/triinterpolate.py @@ -175,7 +175,7 @@ def _interpolate_multikeys(self, x, y, tri_index=None, if tri_index is None: tri_index = self._trifinder(x, y) else: - if (tri_index.shape != sh_ret): + if tri_index.shape != sh_ret: raise ValueError( "tri_index array is provided and shall" " have same shape as x and y. Given: " diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index c8f6411914bf..65e11e10a232 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -413,7 +413,7 @@ def _update(self, event): event.canvas.release_mouse(self.ax) return val = self._value_in_bounds(event.xdata) - if (val is not None) and (val != self.val): + if val not in [None, self.val]: self.set_val(val) def set_val(self, val): @@ -474,7 +474,7 @@ def disconnect(self, cid): def reset(self): """Reset the slider to the initial value""" - if (self.val != self.valinit): + if self.val != self.valinit: self.set_val(self.valinit) diff --git a/lib/mpl_toolkits/axes_grid1/axes_grid.py b/lib/mpl_toolkits/axes_grid1/axes_grid.py index d640c8870e67..5a7f9057f16e 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_grid.py +++ b/lib/mpl_toolkits/axes_grid1/axes_grid.py @@ -169,7 +169,7 @@ def __init__(self, fig, if ngrids is None: ngrids = self._nrows * self._ncols else: - if (ngrids > self._nrows * self._ncols) or (ngrids <= 0): + if not 0 < ngrids <= self._nrows * self._ncols: raise Exception("") self.ngrids = ngrids diff --git a/lib/mpl_toolkits/axisartist/axis_artist.py b/lib/mpl_toolkits/axisartist/axis_artist.py index 1ae2f7dbea01..be51bd57db88 100644 --- a/lib/mpl_toolkits/axisartist/axis_artist.py +++ b/lib/mpl_toolkits/axisartist/axis_artist.py @@ -216,7 +216,7 @@ def __init__(self, ticksize, tick_out=False, *, axis=None, **kwargs): if self._axis is not None: if "color" not in kwargs: kwargs["color"] = "auto" - if ("mew" not in kwargs) and ("markeredgewidth" not in kwargs): + if "mew" not in kwargs and "markeredgewidth" not in kwargs: kwargs["markeredgewidth"] = "auto" Line2D.__init__(self, [0.], [0.], **kwargs) @@ -1125,8 +1125,8 @@ def _draw_ticks(self, renderer): self.minor_ticks.draw(renderer) self.minor_ticklabels.draw(renderer) - - if (self.major_ticklabels.get_visible() or self.minor_ticklabels.get_visible()): + if (self.major_ticklabels.get_visible() + or self.minor_ticklabels.get_visible()): self._draw_offsetText(renderer) return extents @@ -1169,8 +1169,8 @@ def _draw_ticks2(self, renderer): self.minor_ticks.draw(renderer) self.minor_ticklabels.draw(renderer) - - if (self.major_ticklabels.get_visible() or self.minor_ticklabels.get_visible()): + if (self.major_ticklabels.get_visible() + or self.minor_ticklabels.get_visible()): self._draw_offsetText(renderer) return self.major_ticklabels.get_window_extents(renderer) diff --git a/lib/mpl_toolkits/axisartist/floating_axes.py b/lib/mpl_toolkits/axisartist/floating_axes.py index a1070558d6a5..917ef31fc225 100644 --- a/lib/mpl_toolkits/axisartist/floating_axes.py +++ b/lib/mpl_toolkits/axisartist/floating_axes.py @@ -66,8 +66,7 @@ def get_axislabel_pos_angle(self, axes): trans_passingthrough_point = axes.transData + axes.transAxes.inverted() p = trans_passingthrough_point.transform_point([xx1[0], yy1[0]]) - - if (0. <= p[0] <= 1.) and (0. <= p[1] <= 1.): + if 0 <= p[0] <= 1 and 0 <= p[1] <= 1: xx1c, yy1c = axes.transData.transform_point([xx1[0], yy1[0]]) xx2, yy2 = grid_finder.transform_xy([xx0+dxx], [yy0+dyy]) xx2c, yy2c = axes.transData.transform_point([xx2[0], yy2[0]]) diff --git a/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py b/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py index 01dbd1eae1aa..856d6c177a8a 100644 --- a/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py +++ b/lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py @@ -175,8 +175,7 @@ def get_axislabel_pos_angle(self, axes): trans_passingthrough_point = axes.transData + axes.transAxes.inverted() p = trans_passingthrough_point.transform_point([xx1[0], yy1[0]]) - - if (0. <= p[0] <= 1.) and (0. <= p[1] <= 1.): + if 0 <= p[0] <= 1 and 0 <= p[1] <= 1: xx1c, yy1c = axes.transData.transform_point([xx1[0], yy1[0]]) xx2, yy2 = grid_finder.transform_xy([xx0+dxx], [yy0+dyy]) xx2c, yy2c = axes.transData.transform_point([xx2[0], yy2[0]]) diff --git a/setupext.py b/setupext.py index b42dbca58406..27c315fff1d7 100644 --- a/setupext.py +++ b/setupext.py @@ -478,7 +478,7 @@ def _check_for_pkg_config(self, package, include_file, min_version=None, "Requires patches that have not been merged upstream.") if min_version and version != 'unknown': - if (not is_min_version(version, min_version)): + if not is_min_version(version, min_version): raise CheckFailed( "Requires %s %s or later. Found %s." % (package, min_version, version))