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

Skip to content

Commit c93957b

Browse files
authored
Merge pull request #11206 from anntzer/cleanups2
More cleanups
2 parents 78f204d + cfd2cdb commit c93957b

19 files changed

Lines changed: 50 additions & 75 deletions

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ def axis(self, *v, **kwargs):
16501650
matplotlib.axes.Axes.set_ylim
16511651
"""
16521652

1653-
if len(v) == 0 and len(kwargs) == 0:
1653+
if len(v) == len(kwargs) == 0:
16541654
xmin, xmax = self.get_xlim()
16551655
ymin, ymax = self.get_ylim()
16561656
return xmin, xmax, ymin, ymax

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def _iter_collection_uses_per_path(self, paths, all_transforms,
465465
is not the same for every path.
466466
"""
467467
Npaths = len(paths)
468-
if Npaths == 0 or (len(facecolors) == 0 and len(edgecolors) == 0):
468+
if Npaths == 0 or len(facecolors) == len(edgecolors) == 0:
469469
return 0
470470
Npath_ids = max(Npaths, len(all_transforms))
471471
N = max(Npath_ids, len(offsets))

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def _on_timer(self):
7171

7272
# Gtk timeout_add() requires that the callback returns True if it
7373
# is to be called again.
74-
if len(self.callbacks) > 0 and not self._single:
74+
if self.callbacks and not self._single:
7575
return True
7676
else:
7777
self._timer = None

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ def normalize_kwargs(kw, alias_mapping=None, required=(), forbidden=(),
18151815
"are in kwargs".format(keys=fail_keys))
18161816

18171817
if allowed is not None:
1818-
allowed_set = set(required) | set(allowed)
1818+
allowed_set = {*required, *allowed}
18191819
fail_keys = [k for k in ret if k not in allowed_set]
18201820
if fail_keys:
18211821
raise TypeError(

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,7 @@ def _get_extension_lengths(self, frac, automin, automax, default=0.05):
855855
if isinstance(frac, str):
856856
if frac.lower() == 'auto':
857857
# Use the provided values when 'auto' is required.
858-
extendlength[0] = automin
859-
extendlength[1] = automax
858+
extendlength[:] = [automin, automax]
860859
else:
861860
# Any other string is invalid.
862861
raise ValueError('invalid value for extendfrac')

lib/matplotlib/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def to_rgba_array(c, alpha=None):
248248
# Note that this occurs *after* handling inputs that are already arrays, as
249249
# `to_rgba(c, alpha)` (below) is expensive for such inputs, due to the need
250250
# to format the array in the ValueError message(!).
251-
if isinstance(c, str) and c.lower() == "none":
251+
if cbook._str_lower_equal(c, "none"):
252252
return np.zeros((0, 4), float)
253253
try:
254254
return np.array([to_rgba(c, alpha)], float)

lib/matplotlib/lines.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,8 @@ def __init__(self, xdata, ydata,
354354
if isinstance(linestyle, six.string_types):
355355
ds, ls = self._split_drawstyle_linestyle(linestyle)
356356
if ds is not None and drawstyle is not None and ds != drawstyle:
357-
raise ValueError("Inconsistent drawstyle ({0!r}) and "
358-
"linestyle ({1!r})".format(drawstyle,
359-
linestyle)
360-
)
357+
raise ValueError("Inconsistent drawstyle ({!r}) and linestyle "
358+
"({!r})".format(drawstyle, linestyle))
361359
linestyle = ls
362360

363361
if ds is not None:
@@ -863,7 +861,7 @@ def get_marker(self):
863861

864862
def get_markeredgecolor(self):
865863
mec = self._markeredgecolor
866-
if isinstance(mec, six.string_types) and mec == 'auto':
864+
if cbook._str_equal(mec, 'auto'):
867865
if rcParams['_internal.classic_mode']:
868866
if self._marker.get_marker() in ('.', ','):
869867
return self._color
@@ -1088,10 +1086,9 @@ def set_linestyle(self, ls):
10881086
try:
10891087
ls = ls_mapper_r[ls]
10901088
except KeyError:
1091-
raise ValueError(("You passed in an invalid linestyle, "
1092-
"`{0}`. See "
1093-
"docs of Line2D.set_linestyle for "
1094-
"valid values.").format(ls))
1089+
raise ValueError("Invalid linestyle {!r}; see docs of "
1090+
"Line2D.set_linestyle for valid values"
1091+
.format(ls))
10951092
self._linestyle = ls
10961093
else:
10971094
self._linestyle = '--'
@@ -1128,8 +1125,8 @@ def set_markeredgecolor(self, ec):
11281125
"""
11291126
if ec is None:
11301127
ec = 'auto'
1131-
if self._markeredgecolor is None or \
1132-
np.any(self._markeredgecolor != ec):
1128+
if (self._markeredgecolor is None
1129+
or np.any(self._markeredgecolor != ec)):
11331130
self.stale = True
11341131
self._markeredgecolor = ec
11351132

lib/matplotlib/markers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ def set_marker(self, marker):
249249
Path(marker)
250250
self._marker_function = self._set_vertices
251251
except ValueError:
252-
raise ValueError('Unrecognized marker style'
253-
' {0}'.format(marker))
252+
raise ValueError('Unrecognized marker style {!r}'
253+
.format(marker))
254254

255255
self._marker = marker
256256
self._recache()

lib/matplotlib/mathtext.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ def get_unicode_index(symbol, math=True):
6565
# length, usually longer than a hyphen.
6666
if symbol == '-':
6767
return 0x2212
68-
try:# This will succeed if symbol is a single unicode char
68+
try: # This will succeed if symbol is a single unicode char
6969
return ord(symbol)
7070
except TypeError:
7171
pass
72-
try:# Is symbol a TeX symbol (i.e. \alpha)
72+
try: # Is symbol a TeX symbol (i.e. \alpha)
7373
return tex2uni[symbol.strip("\\")]
7474
except KeyError:
75-
message = """'%(symbol)s' is not a valid Unicode character or
76-
TeX/Type1 symbol"""%locals()
77-
raise ValueError(message)
75+
raise ValueError(
76+
"'{}' is not a valid Unicode character or TeX/Type1 symbol"
77+
.format(symbol))
7878

7979

8080
unichr_safe = cbook.deprecated("3.0")(chr)

lib/matplotlib/rcsetup.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __call__(self, s):
6363
s = s.lower()
6464
if s in self.valid:
6565
return self.valid[s]
66-
raise ValueError('Unrecognized %s string "%s": valid strings are %s'
66+
raise ValueError('Unrecognized %s string %r: valid strings are %s'
6767
% (self.key, s, list(six.itervalues(self.valid))))
6868

6969

@@ -889,7 +889,7 @@ def validate_cycler(s):
889889

890890

891891
def validate_hist_bins(s):
892-
if isinstance(s, six.string_types) and s == 'auto':
892+
if cbook._str_equal(s, "auto"):
893893
return s
894894
try:
895895
return int(s)
@@ -942,25 +942,13 @@ def _validate_linestyle(ls):
942942
A validator for all possible line styles, the named ones *and*
943943
the on-off ink sequences.
944944
"""
945-
# Look first for a valid named line style, like '--' or 'solid'
946-
if isinstance(ls, six.string_types):
947-
try:
948-
return _validate_named_linestyle(ls)
949-
except (UnicodeDecodeError, KeyError):
950-
# On Python 2, string-like *ls*, like for example
951-
# 'solid'.encode('utf-16'), may raise a unicode error.
952-
raise ValueError("the linestyle string {!r} is not a valid "
953-
"string.".format(ls))
954-
955-
if isinstance(ls, (bytes, bytearray)):
956-
# On Python 2, a string-like *ls* should already have lead to a
957-
# successful return or to raising an exception. On Python 3, we have
958-
# to manually raise an exception in the case of a byte-like *ls*.
959-
# Otherwise, if *ls* is of even-length, it will be passed to the
960-
# instance of validate_nseq_float, which will return an absurd on-off
961-
# ink sequence...
962-
raise ValueError("linestyle {!r} neither looks like an on-off ink "
963-
"sequence nor a valid string.".format(ls))
945+
# Look first for a valid named line style, like '--' or 'solid' Also
946+
# includes bytes(-arrays) here (they all fail _validate_named_linestyle);
947+
# otherwise, if *ls* is of even-length, it will be passed to the instance
948+
# of validate_nseq_float, which will return an absurd on-off ink
949+
# sequence...
950+
if isinstance(ls, (str, bytes, bytearray)):
951+
return _validate_named_linestyle(ls)
964952

965953
# Look for an on-off ink sequence (in points) *of even length*.
966954
# Offset is set to None.

0 commit comments

Comments
 (0)