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

Skip to content

Commit 84c6ad4

Browse files
authored
Merge pull request #24306 from anntzer/unstr
Remove unnecessary/replaceable explicit str calls.
2 parents c8d1656 + 3886ea9 commit 84c6ad4

File tree

12 files changed

+29
-32
lines changed

12 files changed

+29
-32
lines changed

examples/event_handling/pong_sgskip.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,8 @@ def draw(self):
220220
for puck in self.pucks:
221221
if puck.update(self.pads):
222222
# we only get here if someone scored
223-
self.pads[0].disp.set_label(
224-
" " + str(self.pads[0].score))
225-
self.pads[1].disp.set_label(
226-
" " + str(self.pads[1].score))
223+
self.pads[0].disp.set_label(f" {self.pads[0].score}")
224+
self.pads[1].disp.set_label(f" {self.pads[1].score}")
227225
self.ax.legend(loc='center', framealpha=.2,
228226
facecolor='0.5',
229227
prop=FontProperties(size='xx-large',

examples/units/basic_units.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def __repr__(self):
153153
return 'TaggedValue({!r}, {!r})'.format(self.value, self.unit)
154154

155155
def __str__(self):
156-
return str(self.value) + ' in ' + str(self.unit)
156+
return f"{self.value} in {self.unit}"
157157

158158
def __len__(self):
159159
return len(self.value)

examples/user_interfaces/toolmanager_sgskip.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ class ListTools(ToolBase):
2727

2828
def trigger(self, *args, **kwargs):
2929
print('_' * 80)
30-
print("{0:12} {1:45} {2}".format(
31-
'Name (id)', 'Tool description', 'Keymap'))
30+
fmt_tool = "{:12} {:45} {}".format
31+
print(fmt_tool('Name (id)', 'Tool description', 'Keymap'))
3232
print('-' * 80)
3333
tools = self.toolmanager.tools
3434
for name in sorted(tools):
3535
if not tools[name].description:
3636
continue
3737
keys = ', '.join(sorted(self.toolmanager.get_tool_keymap(name)))
38-
print("{0:12} {1:45} {2}".format(
39-
name, tools[name].description, keys))
38+
print(fmt_tool(name, tools[name].description, keys))
4039
print('_' * 80)
40+
fmt_active_toggle = "{0!s:12} {1!s:45}".format
4141
print("Active Toggle tools")
42-
print("{0:12} {1:45}".format("Group", "Active"))
42+
print(fmt_active_toggle("Group", "Active"))
4343
print('-' * 80)
4444
for group, active in self.toolmanager.active_toggle.items():
45-
print("{0:12} {1:45}".format(str(group), str(active)))
45+
print(fmt_active_toggle(group, active))
4646

4747

4848
class GroupHideTool(ToolToggleBase):

lib/matplotlib/backends/backend_wx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ def save_figure(self, *args):
11491149
if mpl.rcParams["savefig.directory"]:
11501150
mpl.rcParams["savefig.directory"] = str(path.parent)
11511151
try:
1152-
self.canvas.figure.savefig(str(path), format=fmt)
1152+
self.canvas.figure.savefig(path, format=fmt)
11531153
except Exception as e:
11541154
dialog = wx.MessageDialog(
11551155
parent=self.canvas.GetParent(), message=str(e),

lib/matplotlib/font_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ def __init__(self, size=None, weight='normal'):
10841084
# Create list of font paths.
10851085
paths = [cbook._get_data_path('fonts', subdir)
10861086
for subdir in ['ttf', 'afm', 'pdfcorefonts']]
1087-
_log.debug('font search path %s', str(paths))
1087+
_log.debug('font search path %s', paths)
10881088

10891089
self.defaultFamily = {
10901090
'ttf': 'DejaVu Sans',

lib/matplotlib/patches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def _convert_xy_units(self, xy):
610610

611611
class Shadow(Patch):
612612
def __str__(self):
613-
return "Shadow(%s)" % (str(self.patch))
613+
return f"Shadow({self.patch})"
614614

615615
@_docstring.dedent_interpd
616616
def __init__(self, patch, ox, oy, **kwargs):

lib/matplotlib/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def iter_bezier(self, **kwargs):
460460
elif code == Path.STOP:
461461
return
462462
else:
463-
raise ValueError("Invalid Path.code_type: " + str(code))
463+
raise ValueError(f"Invalid Path.code_type: {code}")
464464
prev_vert = verts[-2:]
465465

466466
def cleaned(self, transform=None, remove_nans=False, clip=None,

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,13 @@ def _run_code(code, code_path, ns=None, function_name=None):
486486
try:
487487
os.chdir(setup.config.plot_working_directory)
488488
except OSError as err:
489-
raise OSError(str(err) + '\n`plot_working_directory` option in'
490-
'Sphinx configuration file must be a valid '
491-
'directory path') from err
489+
raise OSError(f'{err}\n`plot_working_directory` option in '
490+
f'Sphinx configuration file must be a valid '
491+
f'directory path') from err
492492
except TypeError as err:
493-
raise TypeError(str(err) + '\n`plot_working_directory` option in '
494-
'Sphinx configuration file must be a string or '
495-
'None') from err
493+
raise TypeError(f'{err}\n`plot_working_directory` option in '
494+
f'Sphinx configuration file must be a string or '
495+
f'None') from err
496496
elif code_path is not None:
497497
dirname = os.path.abspath(os.path.dirname(code_path))
498498
os.chdir(dirname)

lib/matplotlib/tests/test_png.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,17 @@ def test_pngsuite():
2626
plt.gca().set_xlim(0, len(files))
2727

2828

29-
def test_truncated_file(tmpdir):
30-
d = tmpdir.mkdir('test')
31-
fname = str(d.join('test.png'))
32-
fname_t = str(d.join('test_truncated.png'))
33-
plt.savefig(fname)
34-
with open(fname, 'rb') as fin:
29+
def test_truncated_file(tmp_path):
30+
path = tmp_path / 'test.png'
31+
path_t = tmp_path / 'test_truncated.png'
32+
plt.savefig(path)
33+
with open(path, 'rb') as fin:
3534
buf = fin.read()
36-
with open(fname_t, 'wb') as fout:
35+
with open(path_t, 'wb') as fout:
3736
fout.write(buf[:20])
3837

3938
with pytest.raises(Exception):
40-
plt.imread(fname_t)
39+
plt.imread(path_t)
4140

4241

4342
def test_truncated_buffer():

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ def _set_format(self):
804804
else:
805805
break
806806
sigfigs += 1
807-
self.format = '%1.' + str(sigfigs) + 'f'
807+
self.format = f'%1.{sigfigs}f'
808808
if self._usetex or self._useMathText:
809809
self.format = r'$\mathdefault{%s}$' % self.format
810810

lib/mpl_toolkits/axisartist/angle_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def __call__(self, direction, factor, values):
284284
return r
285285

286286
else: # factor > 3600.
287-
return [r"$%s^{\circ}$" % (str(v),) for v in ss*values]
287+
return [r"$%s^{\circ}$" % v for v in ss*values]
288288

289289

290290
class FormatterHMS(FormatterDMS):

setupext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def print_raw(*args, **kwargs): pass # Suppress our own output.
216216
def print_status(package, status):
217217
initial_indent = "%12s: " % package
218218
indent = ' ' * 18
219-
print_raw(textwrap.fill(str(status), width=80,
219+
print_raw(textwrap.fill(status, width=80,
220220
initial_indent=initial_indent,
221221
subsequent_indent=indent))
222222

0 commit comments

Comments
 (0)