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

Skip to content

Commit 3ba7b19

Browse files
authored
Merge pull request #13932 from anntzer/unused
Remove many unused variables.
2 parents d7340c9 + c53017e commit 3ba7b19

24 files changed

+49
-78
lines changed

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/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: 3 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,8 @@ 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+
# Need to keep a reference to the tool.
586+
_tool = SubplotTool(self.canvas.figure, toolfig)
586587

587588
w = int(toolfig.bbox.width)
588589
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ 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+
# Need to keep a reference to the tool.
164+
_tool = SubplotTool(self.canvas.figure, toolfig)
164165
return canvas
165166

166167
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 in the dvi file
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/texmanager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def make_tex(self, tex, fontsize):
227227
else:
228228
try:
229229
fh.write(s.encode('ascii'))
230-
except UnicodeEncodeError as err:
230+
except UnicodeEncodeError:
231231
_log.info("You are using unicode and latex, but have not "
232232
"enabled the 'text.latex.unicode' rcParam.")
233233
raise
@@ -289,7 +289,7 @@ def make_tex_preview(self, tex, fontsize):
289289
else:
290290
try:
291291
fh.write(s.encode('ascii'))
292-
except UnicodeEncodeError as err:
292+
except UnicodeEncodeError:
293293
_log.info("You are using unicode and latex, but have not "
294294
"enabled the 'text.latex.unicode' rcParam.")
295295
raise

lib/matplotlib/textpath.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def get_glyphs_mathtext(self, prop, s, glyph_map=None,
254254
if char_id not in glyph_map:
255255
font.clear()
256256
font.set_size(self.FONT_SCALE, self.DPI)
257-
glyph = font.load_char(ccode, flags=LOAD_NO_HINTING)
257+
font.load_char(ccode, flags=LOAD_NO_HINTING)
258258
glyph_map_new[char_id] = font.get_path()
259259

260260
xpositions.append(ox)
@@ -371,9 +371,9 @@ def _get_ps_font_and_encoding(texname):
371371
# FreeType-synthesized charmap but the native ones (we can't
372372
# directly identify it but it's typically an Adobe charmap), and
373373
# directly load the dvi glyph indices using FT_Load_Char/load_char.
374-
for charmap_name, charmap_code in [
375-
("ADOBE_CUSTOM", 1094992451),
376-
("ADOBE_STANDARD", 1094995778),
374+
for charmap_code in [
375+
1094992451, # ADOBE_CUSTOM.
376+
1094995778, # ADOBE_STANDARD.
377377
]:
378378
try:
379379
font.select_charmap(charmap_code)
@@ -382,7 +382,6 @@ def _get_ps_font_and_encoding(texname):
382382
else:
383383
break
384384
else:
385-
charmap_name = ""
386385
_log.warning("No supported encoding in font (%s).",
387386
font_bunch.filename)
388387
enc = None

lib/mpl_toolkits/axes_grid1/axes_size.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_size(self, renderer):
111111
l1, l2 = self._axes.get_xlim()
112112
if self._aspect == "axes":
113113
ref_aspect = _get_axes_aspect(self._ref_ax)
114-
aspect = ref_aspect/_get_axes_aspect(self._axes)
114+
aspect = ref_aspect / _get_axes_aspect(self._axes)
115115
else:
116116
aspect = self._aspect
117117

lib/mpl_toolkits/axes_grid1/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ def on_changed(m):
788788
cb.set_clim(m.get_clim())
789789
cb.update_bruteforce(m)
790790

791-
cbid = mappable.callbacksSM.connect('changed', on_changed)
791+
mappable.callbacksSM.connect('changed', on_changed)
792792
mappable.colorbar = cb
793793
ax.figure.sca(ax)
794794
return cb

lib/mpl_toolkits/axisartist/angle_helper.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,16 @@ def select_step(v1, v2, nv, hour=False, include_last=True,
108108
cycle = 360.
109109

110110
# for degree
111-
if dv > 1./threshold_factor:
111+
if dv > 1 / threshold_factor:
112112
step, factor = _select_step(dv)
113113
else:
114114
step, factor = select_step_sub(dv*threshold_factor)
115115

116116
factor = factor * threshold_factor
117117

118-
f1, f2, fstep = v1*factor, v2*factor, step/factor
119-
levs = np.arange(np.floor(f1/step), np.ceil(f2/step)+0.5, dtype=int) * step
118+
levs = np.arange(np.floor(v1 * factor / step),
119+
np.ceil(v2 * factor / step) + 0.5,
120+
dtype=int) * step
120121

121122
# n : number of valid levels. If there is a cycle, e.g., [0, 90, 180,
122123
# 270, 360], the grid line needs to be extended from 0 to 360, so
@@ -128,7 +129,7 @@ def select_step(v1, v2, nv, hour=False, include_last=True,
128129
# we need to check the range of values
129130
# for example, -90 to 90, 0 to 360,
130131

131-
if factor == 1. and levs[-1] >= levs[0]+cycle: # check for cycle
132+
if factor == 1. and levs[-1] >= levs[0] + cycle: # check for cycle
132133
nv = int(cycle / step)
133134
if include_last:
134135
levs = levs[0] + np.arange(0, nv+1, 1) * step

lib/mpl_toolkits/axisartist/axis_artist.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,10 +1194,6 @@ def _draw_label2(self, renderer):
11941194
if not self.label.get_visible():
11951195
return
11961196

1197-
fontprops = font_manager.FontProperties(
1198-
size=rcParams['axes.labelsize'],
1199-
weight=rcParams['axes.labelweight'])
1200-
12011197
if self._ticklabel_add_angle != self._axislabel_add_angle:
12021198
if ((self.major_ticks.get_visible()
12031199
and not self.major_ticks.get_tick_out())

0 commit comments

Comments
 (0)