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

Skip to content

Commit 088dbe1

Browse files
committed
Remove many unused variables.
They can be detected by removing the exclusion of F841 in .flake8. AFM parsing was made slightly stricter as a consequence (see changelog). Some other unused variables have been left in, either for symmetry in the code or because their lack of use may possibly indicate a bug that needs to be investigated.
1 parent b9fa7b7 commit 088dbe1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+271
-402
lines changed

doc/api/next_api_changes/2019-04-11-AL.rst

Whitespace-only changes.

doc/sphinxext/github.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def ghuser_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
103103
:param options: Directive options for customization.
104104
:param content: The directive content for customization.
105105
"""
106-
app = inliner.document.settings.env.app
107106
ref = 'https://www.github.com/' + text
108107
node = nodes.reference(rawtext, text, refuri=ref, **options)
109108
return [node], []

examples/axes_grid1/demo_axes_grid.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@ def demo_simple_grid(fig):
2828
axes_pad=0.05,
2929
label_mode="1",
3030
)
31-
3231
Z, extent = get_demo_image()
3332
for ax in grid:
34-
im = ax.imshow(Z, extent=extent, interpolation="nearest")
35-
36-
# This only affects axes in first column and second row as share_all =
37-
# False.
33+
ax.imshow(Z, extent=extent, interpolation="nearest")
34+
# This only affects axes in first column and second row as share_all=False.
3835
grid.axes_llc.set_xticks([-2, 0, 2])
3936
grid.axes_llc.set_yticks([-2, 0, 2])
4037

examples/axes_grid1/demo_edge_colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def demo_bottom_cbar(fig):
4141
im = grid[i].imshow(Z, extent=extent, interpolation="nearest",
4242
cmap=cmaps[i//2])
4343
if i % 2:
44-
cbar = grid.cbar_axes[i//2].colorbar(im)
44+
grid.cbar_axes[i//2].colorbar(im)
4545

4646
for cax in grid.cbar_axes:
4747
cax.toggle_label(True)

examples/event_handling/pick_event_demo.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def pick_simple():
8383
line, = ax1.plot(rand(100), 'o', picker=5) # 5 points tolerance
8484

8585
# pick the rectangle
86-
bars = ax2.bar(range(10), rand(10), picker=True)
86+
ax2.bar(range(10), rand(10), picker=True)
8787
for label in ax2.get_xticklabels(): # make the xtick labels pickable
8888
label.set_picker(True)
8989

@@ -157,18 +157,17 @@ def onpick3(event):
157157
print('onpick3 scatter:', ind, x[ind], y[ind])
158158

159159
fig, ax = plt.subplots()
160-
col = ax.scatter(x, y, 100*s, c, picker=True)
161-
#fig.savefig('pscoll.eps')
160+
ax.scatter(x, y, 100*s, c, picker=True)
162161
fig.canvas.mpl_connect('pick_event', onpick3)
163162

164163

165164
def pick_image():
166165
# picking images (matplotlib.image.AxesImage)
167166
fig, ax = plt.subplots()
168-
im1 = ax.imshow(rand(10, 5), extent=(1, 2, 1, 2), picker=True)
169-
im2 = ax.imshow(rand(5, 10), extent=(3, 4, 1, 2), picker=True)
170-
im3 = ax.imshow(rand(20, 25), extent=(1, 2, 3, 4), picker=True)
171-
im4 = ax.imshow(rand(30, 12), extent=(3, 4, 3, 4), picker=True)
167+
ax.imshow(rand(10, 5), extent=(1, 2, 1, 2), picker=True)
168+
ax.imshow(rand(5, 10), extent=(3, 4, 1, 2), picker=True)
169+
ax.imshow(rand(20, 25), extent=(1, 2, 3, 4), picker=True)
170+
ax.imshow(rand(30, 12), extent=(3, 4, 3, 4), picker=True)
172171
ax.axis([0, 5, 0, 5])
173172

174173
def onpick4(event):

examples/misc/demo_agg_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ def filtered_text(ax):
187187
Z = (Z1 - Z2) * 2
188188

189189
# draw
190-
im = ax.imshow(Z, interpolation='bilinear', origin='lower',
191-
cmap=cm.gray, extent=(-3, 3, -2, 2))
190+
ax.imshow(Z, interpolation='bilinear', origin='lower',
191+
cmap=cm.gray, extent=(-3, 3, -2, 2))
192192
levels = np.arange(-1.2, 1.6, 0.2)
193193
CS = ax.contour(Z, levels,
194194
origin='lower',

examples/units/basic_units.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ def __get__(self, obj, objtype=None):
2525
class TaggedValueMeta(type):
2626
def __init__(self, name, bases, dict):
2727
for fn_name in self._proxies:
28-
try:
29-
dummy = getattr(self, fn_name)
30-
except AttributeError:
28+
if not hasattr(self, fn_name):
3129
setattr(self, fn_name,
3230
ProxyDelegate(fn_name, self._proxies[fn_name]))
3331

examples/widgets/menu.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ def __init__(self, fig, menuitems):
132132
maxw = max(item.labelwidth for item in menuitems)
133133
maxh = max(item.labelheight for item in menuitems)
134134

135-
totalh = self.numitems*maxh + (self.numitems + 1)*2*MenuItem.pady
136-
137135
x0 = 100
138136
y0 = 400
139137

lib/matplotlib/afm.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,15 @@ def _parse_composites(fh):
325325
return composites
326326
vals = line.split(b';')
327327
cc = vals[0].split()
328-
name, numParts = cc[1], _to_int(cc[2])
329-
pccParts = []
328+
name, num_parts = cc[1], _to_int(cc[2])
329+
pcc_parts = []
330330
for s in vals[1:-1]:
331331
pcc = s.split()
332332
part = CompositePart(pcc[1], _to_float(pcc[2]), _to_float(pcc[3]))
333-
pccParts.append(part)
334-
composites[name] = pccParts
335-
333+
pcc_parts.append(part)
334+
if len(pcc_parts) != num_parts:
335+
break # Raise error on exit.
336+
composites[name] = pcc_parts
336337
raise RuntimeError('Bad composites parse')
337338

338339

lib/matplotlib/axes/_secondary_axes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,14 @@ def _set_lims(self):
295295
if self._orientation == 'x':
296296
lims = self._parent.get_xlim()
297297
set_lim = self.set_xlim
298-
trans = self.xaxis.get_transform()
299298
if self._orientation == 'y':
300299
lims = self._parent.get_ylim()
301300
set_lim = self.set_ylim
302-
trans = self.yaxis.get_transform()
303301
order = lims[0] < lims[1]
304302
lims = self._functions[0](np.array(lims))
305303
neworder = lims[0] < lims[1]
306304
if neworder != order:
307-
# flip because the transform will take care of the flipping..
305+
# Flip because the transform will take care of the flipping.
308306
lims = lims[::-1]
309307
set_lim(lims)
310308

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def motion_notify_event(self, widget, event):
235235
if event.is_hint:
236236
t, x, y, state = event.window.get_pointer()
237237
else:
238-
x, y, state = event.x, event.y, event.get_state()
238+
x, y = event.x, event.y
239239

240240
# flipy so y=0 is bottom of canvas
241241
y = self.get_allocation().height - y
@@ -582,7 +582,7 @@ def configure_subplots(self, button):
582582
toolfig = Figure(figsize=(6, 3))
583583
canvas = self._get_canvas(toolfig)
584584
toolfig.subplots_adjust(top=0.9)
585-
tool = SubplotTool(self.canvas.figure, toolfig)
585+
SubplotTool(self.canvas.figure, toolfig)
586586

587587
w = int(toolfig.bbox.width)
588588
h = int(toolfig.bbox.height)

lib/matplotlib/backends/backend_gtk3agg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ def blit(self, bbox=None):
6161
bbox = self.figure.bbox
6262

6363
allocation = self.get_allocation()
64-
w, h = allocation.width, allocation.height
6564
x = int(bbox.x0)
66-
y = h - int(bbox.y1)
65+
y = allocation.height - int(bbox.y1)
6766
width = int(bbox.x1) - int(bbox.x0)
6867
height = int(bbox.y1) - int(bbox.y0)
6968

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def prepare_configure_subplots(self):
160160
toolfig = Figure(figsize=(6, 3))
161161
canvas = FigureCanvasMac(toolfig)
162162
toolfig.subplots_adjust(top=0.9)
163-
tool = SubplotTool(self.canvas.figure, toolfig)
163+
SubplotTool(self.canvas.figure, toolfig)
164164
return canvas
165165

166166
def set_message(self, message):

lib/matplotlib/backends/backend_svg.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,15 +1026,10 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
10261026
font = self._get_font(prop)
10271027
font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
10281028

1029-
fontsize = prop.get_size_in_points()
1030-
1031-
fontfamily = font.family_name
1032-
fontstyle = prop.get_style()
1033-
10341029
attrib = {}
10351030
# Must add "px" to workaround a Firefox bug
1036-
style['font-size'] = short_float_fmt(fontsize) + 'px'
1037-
style['font-family'] = str(fontfamily)
1031+
style['font-size'] = short_float_fmt(prop.get_size()) + 'px'
1032+
style['font-family'] = str(font.family_name)
10381033
style['font-style'] = prop.get_style().lower()
10391034
style['font-weight'] = str(prop.get_weight()).lower()
10401035
attrib['style'] = generate_css(style)

lib/matplotlib/cbook/deprecation.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,7 @@ def _make_keyword_only(since, name, func=None):
394394
kwonly = [name for name in names[names.index(name):]
395395
if signature.parameters[name].kind == POK]
396396
func.__signature__ = signature.replace(parameters=[
397-
param.replace(kind=inspect.Parameter.KEYWORD_ONLY)
398-
if param.name in kwonly
399-
else param
397+
param.replace(kind=KWO) if param.name in kwonly else param
400398
for param in signature.parameters.values()])
401399

402400
@functools.wraps(func)

lib/matplotlib/collections.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,6 @@ def get_positions(self):
14971497
'''
14981498
return an array containing the floating-point values of the positions
14991499
'''
1500-
segments = self.get_segments()
15011500
pos = 0 if self.is_horizontal() else 1
15021501
return [segment[0, pos] for segment in self.get_segments()]
15031502

lib/matplotlib/colorbar.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -596,14 +596,9 @@ def update_ticks(self):
596596
called whenever the tick locator and/or tick formatter changes.
597597
"""
598598
ax = self.ax
599-
# get the locator and formatter. Defaults to
600-
# self.locator if not None..
599+
# Get the locator and formatter; defaults to self.locator if not None.
601600
locator, formatter = self._get_ticker_locator_formatter()
602-
if self.orientation == 'vertical':
603-
long_axis, short_axis = ax.yaxis, ax.xaxis
604-
else:
605-
long_axis, short_axis = ax.xaxis, ax.yaxis
606-
601+
long_axis = ax.yaxis if self.orientation == 'vertical' else ax.xaxis
607602
if self._use_auto_colorbar_locator():
608603
_log.debug('Using auto colorbar locator on colorbar')
609604
_log.debug('locator: %r', locator)
@@ -643,10 +638,8 @@ def get_ticks(self, minor=False):
643638
"""Return the x ticks as a list of locations."""
644639
if self._manual_tick_data_values is None:
645640
ax = self.ax
646-
if self.orientation == 'vertical':
647-
long_axis, short_axis = ax.yaxis, ax.xaxis
648-
else:
649-
long_axis, short_axis = ax.xaxis, ax.yaxis
641+
long_axis = (
642+
ax.yaxis if self.orientation == 'vertical' else ax.xaxis)
650643
return long_axis.get_majorticklocs()
651644
else:
652645
# We made the axes manually, the old way, and the ylim is 0-1,

lib/matplotlib/dviread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def _fnt_def_real(self, k, c, s, d, a, l):
455455

456456
@_dispatch(247, state=_dvistate.pre, args=('u1', 'u4', 'u4', 'u4', 'u1'))
457457
def _pre(self, i, num, den, mag, k):
458-
comment = self.file.read(k)
458+
self.file.read(k) # comment
459459
if i != 2:
460460
raise ValueError("Unknown dvi format %d" % i)
461461
if num != 25400000 or den != 7227 * 2**16:

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ def validate_webagg_address(s):
965965
import socket
966966
try:
967967
socket.inet_aton(s)
968-
except socket.error as e:
968+
except socket.error:
969969
raise ValueError("'webagg.address' is not a valid IP address")
970970
return s
971971
raise ValueError("'webagg.address' is not a valid IP address")

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def run_code(code, code_path, ns=None, function_name=None):
518518
if function_name is not None:
519519
exec(function_name + "()", ns)
520520

521-
except (Exception, SystemExit) as err:
521+
except (Exception, SystemExit):
522522
raise PlotError(traceback.format_exc())
523523
finally:
524524
os.chdir(pwd)
@@ -584,11 +584,11 @@ def render_figures(code, code_path, output_dir, output_base, context,
584584
output_dir)
585585
else:
586586
img = ImageFile('%s_%02d' % (output_base, j), output_dir)
587-
for format, dpi in formats:
588-
if out_of_date(code_path, img.filename(format)):
587+
for fmt, dpi in formats:
588+
if out_of_date(code_path, img.filename(fmt)):
589589
all_exists = False
590590
break
591-
img.formats.append(format)
591+
img.formats.append(fmt)
592592

593593
# assume that if we have one, we have them all
594594
if not all_exists:
@@ -636,12 +636,12 @@ def render_figures(code, code_path, output_dir, output_base, context,
636636
img = ImageFile("%s_%02d_%02d" % (output_base, i, j),
637637
output_dir)
638638
images.append(img)
639-
for format, dpi in formats:
639+
for fmt, dpi in formats:
640640
try:
641-
figman.canvas.figure.savefig(img.filename(format), dpi=dpi)
642-
except Exception as err:
641+
figman.canvas.figure.savefig(img.filename(fmt), dpi=dpi)
642+
except Exception:
643643
raise PlotError(traceback.format_exc())
644-
img.formats.append(format)
644+
img.formats.append(fmt)
645645

646646
results.append((code_piece, images))
647647

lib/matplotlib/tests/test_agg.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from matplotlib import (
88
collections, path, pyplot as plt, transforms as mtransforms, rcParams)
99
from matplotlib.image import imread
10-
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
1110
from matplotlib.figure import Figure
1211
from matplotlib.testing.decorators import image_comparison
1312

@@ -17,7 +16,6 @@ def test_repeated_save_with_alpha():
1716
# alpha of 0.25.
1817

1918
fig = Figure([1, 0.4])
20-
canvas = FigureCanvas(fig)
2119
fig.set_facecolor((0, 1, 0.4))
2220
fig.patch.set_alpha(0.25)
2321

0 commit comments

Comments
 (0)