10000 Merge pull request #11206 from anntzer/cleanups2 · matplotlib/matplotlib@c93957b · GitHub
[go: up one dir, main page]

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

+50
-75
lines changed

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.

lib/matplotlib/table.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,13 @@ def __init__(self, ax, loc=None, bbox=None, **kwargs):
241241

242242
Artist.__init__(self)
243243

244-
if isinstance(loc, str) and loc not in self.codes:
245-
warnings.warn('Unrecognized location %s. Falling back on '
246-
'bottom; valid locations are\n%s\t' %
247-
(loc, '\n\t'.join(self.codes)))
248-
loc = 'bottom'
249244
if isinstance(loc, str):
250-
loc = self.codes.get(loc, 1)
245+
if loc not in self.codes:
246+
warnings.warn('Unrecognized location %s. Falling back on '
247+
'bottom; valid locations are\n%s\t' %
248+
(loc, '\n\t'.join(self.codes)))
249+
loc = 'bottom'
250+
loc = self.codes[loc]
251251
self.set_figure(ax.figure)
252252
self._axes = ax
253253
self._loc = loc

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ def __init__(self, unit="", places=None, sep=" "):
12371237
def __call__(self, x, pos=None):
12381238
s = "%s%s" % (self.format_eng(x), self.unit)
12391239
# Remove the trailing separator when there is neither prefix nor unit
1240-
if len(self.sep) > 0 and s.endswith(self.sep):
1240+
if self.sep and s.endswith(self.sep):
12411241
s = s[:-len(self.sep)]
12421242
return self.fix_minus(s)
12431243

lib/matplotlib/tight_layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
315315

316316
subplots.append(ax)
317317

318-
if (len(nrows_list) == 0) or (len(ncols_list) == 0):
318+
if len(nrows_list) == 0 or len(ncols_list) == 0:
319319
return {}
320320

321321
max_nrows = max(nrows_list)

lib/matplotlib/tri/triangulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def get_from_args_and_kwargs(*args, **kwargs):
137137
# Check triangles in kwargs then args.
138138
triangles = kwargs.pop('triangles', None)
139139
from_args = False
140-
if triangles is None and len(args) > 0:
140+
if triangles is None and args:
141141
triangles = args[0]
142142
from_args = True
143143

lib/matplotlib/type1font.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _read(self, file):
8181
return rawdata
8282

8383
data = b''
84-
while len(rawdata) > 0:
84+
while rawdata:
8585
if not rawdata.startswith(b'\x80'):
8686
raise RuntimeError('Broken pfb file (expected byte 128, '
8787
'got %d)' % ord(rawdata[0]))

lib/matplotlib/widgets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ def on_text_change(self, func):
917917

918918
def on_submit(self, func):
919919
"""
920-
When the user hits enter or leaves the submision box, call this
920+
When the user hits enter or leaves the submission box, call this
921921
*func* with event.
922922
923923
A connection id is returned which can be used to disconnect.
@@ -928,8 +928,8 @@ def on_submit(self, func):
928928
return cid
929929

930930
def disconnect(self, cid):
931-
"""remove the observer with connection id *cid*"""
932-
for reg in (self.change_observ 10000 ers, self.submit_observers):
931+
"""Remove the observer with connection id *cid*."""
932+
for reg in [self.change_observers, self.submit_observers]:
933933
try:
934934
del reg[cid]
935935
except KeyError:

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True,
525525
# of data and decides how to scale the view portal to fit it.
526526
if tight is None:
527527
# if image data only just use the datalim
528-
_tight = self._tight or (len(self.images)>0 and
529-
len(self.lines)==0 and
530-
len(self.patches)==0)
528+
_tight = self._tight or (
529+
len(self.images) > 0
530+
and len(self.lines) == len(self.patches) == 0)
531531
else:
532532
_tight = self._tight = bool(tight)
533533

setupext.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def get_file_hash(filename):
251251
hasher = hashlib.sha256()
252252
with open(filename, 'rb') as fd:
253253
buf = fd.read(BLOCKSIZE)
254-
while len(buf) > 0:
254+
while buf:
255255
hasher.update(buf)
256256
buf = fd.read(BLOCKSIZE)
257257
return hasher.hexdigest()
@@ -268,11 +268,7 @@ def __init__(self):
268268
if sys.platform == 'win32':
269269
self.has_pkgconfig = False
270270
else:
271-
try:
272-
self.pkg_config = os.environ['PKG_CONFIG']
273-
except KeyError:
274-
self.pkg_config = 'pkg-config'
275-
271+
self.pkg_config = os.environ.get('PKG_CONFIG', 'pkg-config')
276272
self.set_pkgconfig_path()
277273
self.has_pkgconfig = shutil.which(self.pkg_config) is not None
278274
if not self.has_pkgconfig:

tools/gh_api.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
"""Functions for Github API requests."""
22

3-
try:
4-
input = raw_input
5-
except NameError:
6-
pass
7-
3+
import getpass
4+
import json
85
import os
96
import re
107
import sys
118

129
import requests
13-
import getpass
14-
import json
1510

1611
try:
1712
import requests_cache

0 commit comments

Comments
 (0)
0