Skip to content

Commit 4d30640

Browse files
committed
MNT: Update code with Python 3.9+ syntax
Command: `pyupgrade --py39-plus` Manual updates to add some f-strings and ignore f-strings in tex formats.
1 parent 2403d74 commit 4d30640

File tree

108 files changed

+309
-331
lines changed

Some content is hidden

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

108 files changed

+309
-331
lines changed

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _check_dependencies():
141141
if missing:
142142
raise ImportError(
143143
"The following dependencies are missing to build the "
144-
"documentation: {}".format(", ".join(missing)))
144+
f"documentation: {', '.join(missing)}")
145145
if shutil.which('dot') is None:
146146
raise OSError(
147147
"No binary named dot - graphviz must be installed to build the "

doc/sphinxext/gallery_order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def __init__(self, src_dir):
114114
def __call__(self, item):
115115
"""Return a string determining the sort order."""
116116
if item in self.ordered_list:
117-
return "{:04d}".format(self.ordered_list.index(item))
117+
return f"{self.ordered_list.index(item):04d}"
118118
else:
119119
# ensure not explicitly listed items come last.
120120
return "zzz" + item

doc/sphinxext/missing_references.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def record_missing_reference(app, record, node):
6161
target = node["reftarget"]
6262
location = get_location(node, app)
6363

64-
domain_type = "{}:{}".format(domain, typ)
64+
domain_type = f"{domain}:{typ}"
6565

6666
record[(domain_type, target)].add(location)
6767

examples/color/color_cycle_default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
axs[1, icol].set_facecolor('k')
3232
axs[1, icol].xaxis.set_ticks(np.arange(0, 10, 2))
33-
axs[0, icol].set_title('line widths (pts): %g, %g' % (lwx, lwy),
33+
axs[0, icol].set_title(f'line widths (pts): {lwx:g}, {lwy:g}',
3434
fontsize='medium')
3535

3636
for irow in range(2):

examples/event_handling/cursor_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def on_mouse_move(self, event):
5858
# update the line positions
5959
self.horizontal_line.set_ydata(y)
6060
self.vertical_line.set_xdata(x)
61-
self.text.set_text('x=%1.2f, y=%1.2f' % (x, y))
61+
self.text.set_text(f'x={x:1.2f}, y={y:1.2f}')
6262
self.ax.figure.canvas.draw()
6363

6464

@@ -134,7 +134,7 @@ def on_mouse_move(self, event):
134134
x, y = event.xdata, event.ydata
135135
self.horizontal_line.set_ydata(y)
136136
self.vertical_line.set_xdata(x)
137-
self.text.set_text('x=%1.2f, y=%1.2f' % (x, y))
137+
self.text.set_text(f'x={x:1.2f}, y={y:1.2f}')
138138

139139
self.ax.figure.canvas.restore_region(self.background)
140140
self.ax.draw_artist(self.horizontal_line)
@@ -206,7 +206,7 @@ def on_mouse_move(self, event):
206206
# update the line positions
207207
self.horizontal_line.set_ydata(y)
208208
self.vertical_line.set_xdata(x)
209-
self.text.set_text('x=%1.2f, y=%1.2f' % (x, y))
209+
self.text.set_text(f'x={x:1.2f}, y={y:1.2f}')
210210
self.ax.figure.canvas.draw()
211211

212212

examples/event_handling/pick_event_demo2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def onpick(event):
4343
figi, axs = plt.subplots(N, squeeze=False)
4444
for ax, dataind in zip(axs.flat, event.ind):
4545
ax.plot(X[dataind])
46-
ax.text(.05, .9, 'mu=%1.3f\nsigma=%1.3f' % (xs[dataind], ys[dataind]),
46+
ax.text(.05, .9, f'mu={xs[dataind]:1.3f}\nsigma={ys[dataind]:1.3f}',
4747
transform=ax.transAxes, va='top')
4848
ax.set_ylim(-0.5, 1.5)
4949
figi.show()

examples/lines_bars_and_markers/bar_label_demo.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
ax.set_title('How fast do you want to go today?')
8181

8282
# Label with given captions, custom padding and annotate options
83-
ax.bar_label(hbars, labels=['±%.2f' % e for e in error],
83+
ax.bar_label(hbars, labels=[f'±{e:.2f}' for e in error],
8484
padding=8, color='b', fontsize=14)
8585
ax.set_xlim(right=16)
8686

@@ -106,9 +106,7 @@
106106
fig, ax = plt.subplots()
107107
bar_container = ax.bar(animal_names, mph_speed)
108108
ax.set(ylabel='speed in MPH', title='Running speeds', ylim=(0, 80))
109-
ax.bar_label(
110-
bar_container, fmt=lambda x: '{:.1f} km/h'.format(x * 1.61)
111-
)
109+
ax.bar_label(bar_container, fmt=lambda x: f'{x * 1.61:.1f} km/h')
112110

113111
# %%
114112
#

examples/scales/symlog_demo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
"""
32
===========
43
Symlog Demo

examples/shapes_and_collections/donut.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def make_circle(r):
5353
patch = mpatches.PathPatch(path, facecolor='#885500', edgecolor='black')
5454
ax.add_patch(patch)
5555

56-
ax.annotate("Outside %s,\nInside %s" % (wise(outside), wise(inside)),
56+
ax.annotate(f"Outside {wise(outside)},\nInside {wise(inside)}",
5757
(i * 2.5, -1.5), va="top", ha="center")
5858

5959
ax.set_xlim(-2, 10)

examples/user_interfaces/toolmanager_sgskip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def trigger(self, *args, **kwargs):
3737
keys = ', '.join(sorted(self.toolmanager.get_tool_keymap(name)))
3838
print(fmt_tool(name, tools[name].description, keys))
3939
print('_' * 80)
40-
fmt_active_toggle = "{0!s:12} {1!s:45}".format
40+
fmt_active_toggle = "{!s:12} {!s:45}".format
4141
print("Active Toggle tools")
4242
print(fmt_active_toggle("Group", "Active"))
4343
print('-' * 80)

0 commit comments

Comments
 (0)