From 3a8b143d9a35ecd5c31edc0b65e9be9f385c3f1b Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 22 Mar 2018 00:52:28 +0100 Subject: [PATCH] More python3 cleanup --- lib/matplotlib/axes/_axes.py | 17 ++++------- lib/matplotlib/backends/qt_compat.py | 4 --- lib/matplotlib/pyplot.py | 12 +++----- lib/matplotlib/testing/jpl_units/Duration.py | 17 +---------- lib/matplotlib/testing/jpl_units/Epoch.py | 22 +++++++------- .../testing/jpl_units/EpochConverter.py | 11 ++----- .../testing/jpl_units/StrConverter.py | 5 +--- lib/matplotlib/testing/jpl_units/UnitDbl.py | 26 ++++------------ .../testing/jpl_units/UnitDblConverter.py | 18 ++++------- .../testing/jpl_units/UnitDblFormatter.py | 3 -- lib/matplotlib/testing/jpl_units/__init__.py | 2 -- lib/matplotlib/text.py | 30 +++++++------------ 12 files changed, 46 insertions(+), 121 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 49363dc7d611..0dbdaf397971 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -1,9 +1,3 @@ -from __future__ import (absolute_import, division, print_function, - unicode_literals) - -import six -from six.moves import zip, zip_longest - import functools import itertools import logging @@ -2764,7 +2758,7 @@ def get_next_color(): if autopct is not None: xt = x + pctdistance * radius * math.cos(thetam) yt = y + pctdistance * radius * math.sin(thetam) - if isinstance(autopct, six.string_types): + if isinstance(autopct, str): s = autopct % (100. * frac) elif callable(autopct): s = autopct(100. * frac) @@ -5606,8 +5600,7 @@ def pcolor(self, *args, **kwargs): # makes artifacts that are often disturbing. if 'antialiased' in kwargs: kwargs['antialiaseds'] = kwargs.pop('antialiased') - if 'antialiaseds' not in kwargs and ( - isinstance(ec, six.string_types) and ec.lower() == "none"): + if 'antialiaseds' not in kwargs and cbook._str_lower_equal(ec, "none"): kwargs['antialiaseds'] = False kwargs.setdefault('snap', False) @@ -6526,12 +6519,12 @@ def hist(self, x, bins=None, range=None, density=None, weights=None, if label is None: labels = [None] - elif isinstance(label, six.string_types): + elif isinstance(label, str): labels = [label] else: - labels = [six.text_type(lab) for lab in label] + labels = [str(lab) for lab in label] - for patch, lbl in zip_longest(patches, labels, fillvalue=None): + for patch, lbl in itertools.zip_longest(patches, labels): if patch: p = patch[0] p.update(kwargs) diff --git a/lib/matplotlib/backends/qt_compat.py b/lib/matplotlib/backends/qt_compat.py index d2892ea21133..e02e881a3969 100644 --- a/lib/matplotlib/backends/qt_compat.py +++ b/lib/matplotlib/backends/qt_compat.py @@ -1,9 +1,5 @@ """ A Qt API selector that can be used to switch between PyQt and PySide. """ -from __future__ import (absolute_import, division, print_function, - unicode_literals) - -import six import os import logging diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 12670fd63296..4c45124a9658 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -17,10 +17,6 @@ The object-oriented API is recommended for more complex plots. """ -from __future__ import (absolute_import, division, print_function, - unicode_literals) - -import six import inspect from numbers import Number @@ -504,7 +500,7 @@ def figure(num=None, # autoincrement if None, else integer from 1-N figLabel = '' if num is None: num = next_num - elif isinstance(num, six.string_types): + elif isinstance(num, str): figLabel = num allLabels = get_figlabels() if figLabel not in allLabels: @@ -655,13 +651,13 @@ def close(*args): arg = args[0] if arg == 'all': _pylab_helpers.Gcf.destroy_all() - elif isinstance(arg, six.integer_types): + elif isinstance(arg, int): _pylab_helpers.Gcf.destroy(arg) elif hasattr(arg, 'int'): # if we are dealing with a type UUID, we # can use its integer representation _pylab_helpers.Gcf.destroy(arg.int) - elif isinstance(arg, six.string_types): + elif isinstance(arg, str): allLabels = get_figlabels() if arg in allLabels: num = get_fignums()[allLabels.index(arg)] @@ -2449,7 +2445,7 @@ def plotfile(fname, cols=(0,), plotfuncs=None, def getname_val(identifier): 'return the name and column data for identifier' - if isinstance(identifier, six.string_types): + if isinstance(identifier, str): return identifier, r[identifier] elif isinstance(identifier, Number): name = r.dtype.names[int(identifier)] diff --git a/lib/matplotlib/testing/jpl_units/Duration.py b/lib/matplotlib/testing/jpl_units/Duration.py index 8c6d5b250176..bdfb4cfb5f9d 100644 --- a/lib/matplotlib/testing/jpl_units/Duration.py +++ b/lib/matplotlib/testing/jpl_units/Duration.py @@ -10,10 +10,6 @@ # ========================================================================== # Place all imports after here. # -from __future__ import (absolute_import, division, print_function, - unicode_literals) - -import six import operator # # Place all imports before here. @@ -66,20 +62,9 @@ def seconds(self): return self._seconds # ---------------------------------------------------------------------- - def __nonzero__(self): - """Compare two Durations. - - = INPUT VARIABLES - - rhs The Duration to compare against. - - = RETURN VALUE - - Returns -1 if self < rhs, 0 if self == rhs, +1 if self > rhs. - """ + def __bool__(self): return self._seconds != 0 - if six.PY3: - __bool__ = __nonzero__ - # ---------------------------------------------------------------------- def __eq__(self, rhs): return self._cmp(rhs, operator.eq) diff --git a/lib/matplotlib/testing/jpl_units/Epoch.py b/lib/matplotlib/testing/jpl_units/Epoch.py index 72ccbec5abac..8cf956366d53 100644 --- a/lib/matplotlib/testing/jpl_units/Epoch.py +++ b/lib/matplotlib/testing/jpl_units/Epoch.py @@ -10,10 +10,6 @@ # =========================================================================== # Place all imports after here. # -from __future__ import (absolute_import, division, print_function, - unicode_literals) - -import six import operator import math import datetime as DT @@ -68,16 +64,18 @@ def __init__(self, frame, sec=None, jd=None, daynum=None, dt=None): (daynum is not None and dt is not None) or (dt is not None and (sec is not None or jd is not None)) or ((dt is not None) and not isinstance(dt, DT.datetime))): - msg = "Invalid inputs. Must enter sec and jd together, " \ - "daynum by itself, or dt (must be a python datetime).\n" \ - "Sec = %s\nJD = %s\ndnum= %s\ndt = %s" \ - % (str(sec), str(jd), str(daynum), str(dt)) - raise ValueError(msg) + raise ValueError( + "Invalid inputs. Must enter sec and jd together, " + "daynum by itself, or dt (must be a python datetime).\n" + "Sec = %s\n" + "JD = %s\n" + "dnum= %s\n" + "dt = %s" % (sec, jd, daynum, dt)) if frame not in self.allowed: - msg = "Input frame '%s' is not one of the supported frames of %s" \ - % (frame, str(list(six.iterkeys(self.allowed)))) - raise ValueError(msg) + raise ValueError( + "Input frame '%s' is not one of the supported frames of %s" % + (frame, list(self.allowed.keys()))) self._frame = frame diff --git a/lib/matplotlib/testing/jpl_units/EpochConverter.py b/lib/matplotlib/testing/jpl_units/EpochConverter.py index 4892483b5f0e..cc85d104409a 100644 --- a/lib/matplotlib/testing/jpl_units/EpochConverter.py +++ b/lib/matplotlib/testing/jpl_units/EpochConverter.py @@ -10,11 +10,6 @@ # ========================================================================== # Place all imports after here. # -from __future__ import (absolute_import, division, print_function, - unicode_literals) - -import six - import matplotlib.units as units import matplotlib.dates as date_ticker from matplotlib.cbook import iterable @@ -121,8 +116,8 @@ def convert(value, unit, axis): isNotEpoch = True isDuration = False - if iterable(value) and not isinstance(value, six.string_types): - if (len(value) == 0): + if iterable(value) and not isinstance(value, str): + if len(value) == 0: return [] else: return [EpochConverter.convert(x, unit, axis) for x in value] @@ -156,7 +151,7 @@ def default_units(value, axis): - Returns the default units to use for value. """ frame = None - if iterable(value) and not isinstance(value, six.string_types): + if iterable(value) and not isinstance(value, str): return EpochConverter.default_units(value[0], axis) else: frame = value.frame() diff --git a/lib/matplotlib/testing/jpl_units/StrConverter.py b/lib/matplotlib/testing/jpl_units/StrConverter.py index 924e39a8884a..7b6d8b3847fa 100644 --- a/lib/matplotlib/testing/jpl_units/StrConverter.py +++ b/lib/matplotlib/testing/jpl_units/StrConverter.py @@ -10,12 +10,9 @@ # ========================================================================== # Place all imports after here. # -from __future__ import (absolute_import, division, print_function, - unicode_literals) - import matplotlib.units as units from matplotlib.cbook import iterable - +# # Place all imports before here. # ========================================================================== diff --git a/lib/matplotlib/testing/jpl_units/UnitDbl.py b/lib/matplotlib/testing/jpl_units/UnitDbl.py index 480ef6144cbc..b65b6a357bd6 100644 --- a/lib/matplotlib/testing/jpl_units/UnitDbl.py +++ b/lib/matplotlib/testing/jpl_units/UnitDbl.py @@ -10,10 +10,6 @@ # ========================================================================== # Place all imports after here. # -from __future__ import (absolute_import, division, print_function, - unicode_literals) - -import six import operator # # Place all imports before here. @@ -111,19 +107,9 @@ def __neg__(self): return UnitDbl(-self._value, self._units) # ---------------------------------------------------------------------- - def __nonzero__(self): - """Test a UnitDbl for a non-zero value. - - = RETURN VALUE - - Returns true if the value is non-zero. - """ - if six.PY3: - return self._value.__bool__() - else: - return self._value.__nonzero__() - - if six.PY3: - __bool__ = __nonzero__ + def __bool__(self): + """Return the truth value of a UnitDbl.""" + return bool(self._value) # ---------------------------------------------------------------------- def __eq__(self, rhs): @@ -292,9 +278,9 @@ def checkUnits(self, units): - units The string name of the units to check. """ if units not in self.allowed: - msg = "Input units '%s' are not one of the supported types of %s" \ - % (units, str(list(six.iterkeys(self.allowed)))) - raise ValueError(msg) + raise ValueError("Input units '%s' are not one of the supported " + "types of %s" % ( + units, list(self.allowed.keys()))) # ---------------------------------------------------------------------- def checkSameUnits(self, rhs, func): diff --git a/lib/matplotlib/testing/jpl_units/UnitDblConverter.py b/lib/matplotlib/testing/jpl_units/UnitDblConverter.py index f43fd581d649..cf2b4a2c4784 100644 --- a/lib/matplotlib/testing/jpl_units/UnitDblConverter.py +++ b/lib/matplotlib/testing/jpl_units/UnitDblConverter.py @@ -9,11 +9,6 @@ # ========================================================================== # Place all imports after here. # -from __future__ import (absolute_import, division, print_function, - unicode_literals) - -import six - import numpy as np import matplotlib.units as units import matplotlib.projections.polar as polar @@ -75,11 +70,8 @@ def axisinfo(unit, axis): # Check to see if the value used for units is a string unit value # or an actual instance of a UnitDbl so that we can use the unit # value for the default axis label value. - if (unit): - if (isinstance(unit, six.string_types)): - label = unit - else: - label = unit.label() + if unit: + label = unit if isinstance(unit, str) else unit.label() else: label = None @@ -109,8 +101,8 @@ def convert(value, unit, axis): isNotUnitDbl = True - if (iterable(value) and not isinstance(value, six.string_types)): - if (len(value) == 0): + if iterable(value) and not isinstance(value, str): + if len(value) == 0: return [] else: return [UnitDblConverter.convert(x, unit, axis) for x in value] @@ -153,7 +145,7 @@ def default_units(value, axis): # Determine the default units based on the user preferences set for # default units when printing a UnitDbl. - if (iterable(value) and not isinstance(value, six.string_types)): + if iterable(value) and not isinstance(value, str): return UnitDblConverter.default_units(value[0], axis) else: return UnitDblConverter.defaults[value.type()] diff --git a/lib/matplotlib/testing/jpl_units/UnitDblFormatter.py b/lib/matplotlib/testing/jpl_units/UnitDblFormatter.py index de2fb3fafacb..25ebf6042c78 100644 --- a/lib/matplotlib/testing/jpl_units/UnitDblFormatter.py +++ b/lib/matplotlib/testing/jpl_units/UnitDblFormatter.py @@ -10,9 +10,6 @@ # ========================================================================== # Place all imports after here. # -from __future__ import (absolute_import, division, print_function, - unicode_literals) - import matplotlib.ticker as ticker # # Place all imports before here. diff --git a/lib/matplotlib/testing/jpl_units/__init__.py b/lib/matplotlib/testing/jpl_units/__init__.py index 54c96d70e020..47e6c3dee554 100644 --- a/lib/matplotlib/testing/jpl_units/__init__.py +++ b/lib/matplotlib/testing/jpl_units/__init__.py @@ -31,8 +31,6 @@ """ # ====================================================================== -from __future__ import (absolute_import, division, print_function, - unicode_literals) from .Duration import Duration from .Epoch import Epoch diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 6001b8d2f522..77cf2313427b 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -1,10 +1,6 @@ """ Classes for including text in a figure. """ -from __future__ import absolute_import, division, print_function - -import six -from six.moves import zip import contextlib import logging @@ -63,10 +59,9 @@ def get_rotation(rotation): try: angle = float(rotation) except (ValueError, TypeError): - isString = isinstance(rotation, six.string_types) - if ((isString and rotation == 'horizontal') or rotation is None): + if cbook._str_equal(rotation, 'horizontal') or rotation is None: angle = 0. - elif (isString and rotation == 'vertical'): + elif cbook._str_equal(rotation, 'vertical'): angle = 90. else: raise ValueError("rotation is {0} expected either 'horizontal'" @@ -168,7 +163,7 @@ def __init__(self, color = rcParams['text.color'] if fontproperties is None: fontproperties = FontProperties() - elif isinstance(fontproperties, six.string_types): + elif isinstance(fontproperties, str): fontproperties = FontProperties(fontproperties) self._text = '' @@ -467,8 +462,7 @@ def set_bbox(self, rectprops): pad = 0.3 # boxstyle could be a callable or a string - if (isinstance(boxstyle, six.string_types) - and "pad" not in boxstyle): + if isinstance(boxstyle, str) and "pad" not in boxstyle: boxstyle += ",pad=%0.2f" % pad bbox_transmuter = props.pop("bbox_transmuter", None) @@ -1136,7 +1130,7 @@ def set_fontproperties(self, fp): ACCEPTS: a :class:`matplotlib.font_manager.FontProperties` instance """ - if isinstance(fp, six.string_types): + if isinstance(fp, str): fp = FontProperties(fp) self._fontproperties = fp.copy() self.stale = True @@ -1697,8 +1691,8 @@ def _get_xy_transform(self, renderer, s): return BboxTransformTo(s) elif isinstance(s, Transform): return s - elif not isinstance(s, six.string_types): - raise RuntimeError("unknown coordinate type : %s" % (s,)) + elif not isinstance(s, str): + raise RuntimeError("unknown coordinate type : %s" % s) if s == 'data': return self.axes.transData @@ -1761,20 +1755,18 @@ def _get_ref_xy(self, renderer): return x, y (in display coordinate) that is to be used for a reference of any offset coordinate """ + def is_offset(s): + return isinstance(s, str) and s.split()[0] == "offset" if isinstance(self.xycoords, tuple): s1, s2 = self.xycoords - if ((isinstance(s1, six.string_types) - and s1.split()[0] == "offset") - or (isinstance(s2, six.string_types) - and s2.split()[0] == "offset")): + if is_offset(s1) or is_offset(s2): raise ValueError("xycoords should not be an offset coordinate") x, y = self.xy x1, y1 = self._get_xy(renderer, x, y, s1) x2, y2 = self._get_xy(renderer, x, y, s2) return x1, y2 - elif (isinstance(self.xycoords, six.string_types) and - self.xycoords.split()[0] == "offset"): + elif is_offset(self.xycoords): raise ValueError("xycoords should not be an offset coordinate") else: x, y = self.xy