8000 Merge pull request #13104 from anntzer/1tuples · matplotlib/matplotlib@556c4d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 556c4d6

Browse files
authored
Merge pull request #13104 from anntzer/1tuples
Remove some more 1-tuples.
2 parents f99ff7e + fb87d77 commit 556c4d6

File tree

17 files changed

+48
-57
lines changed

17 files changed

+48
-57
lines changed

.flake8

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ per-file-ignores =
5353
mpl_toolkits/axes_grid1/axes_size.py: E272, E501
5454
mpl_toolkits/axes_grid1/colorbar.py: E225, E501
5555
mpl_toolkits/axes_grid1/inset_locator.py: E501
56-
mpl_toolkits/axes_grid1/mpl_axes.py: E501
5756
mpl_toolkits/axisartist/angle_helper.py: E221
5857
mpl_toolkits/axisartist/clip_path.py: E225, E501
5958
mpl_toolkits/axisartist/floating_axes.py: E225, E402, E501

examples/units/basic_units.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@ def __new__(cls, value, unit):
122122
# generate a new subclass for value
123123
value_class = type(value)
124124
try:
125-
subcls = type('TaggedValue_of_%s' % (value_class.__name__),
126-
tuple([cls, value_class]),
127-
{})
125+
subcls = type(f'TaggedValue_of_{value_class.__name__}',
126+
(cls, value_class), {})
128127
if subcls not in units.registry:
129128
units.registry[subcls] = basicConverter
130129
return object.__new__(subcls)
@@ -196,7 +195,7 @@ def __init__(self, name, fullname=None):
196195
self.conversions = dict()
197196

198197
def __repr__(self):
199-
return 'BasicUnit(%s)' % self.name
198+
return f'BasicUnit({self.name})'
200199

201200
def __str__(self):
202201
return self.fullname
@@ -314,9 +313,9 @@ def rad_fn(x, pos=None):
314313
elif n == -2:
315314
return r'$-\pi$'
316315
elif n % 2 == 0:
317-
return r'$%s\pi$' % (n//2,)
316+
return fr'${n//2}\pi$'
318317
else:
319-
return r'$%s\pi/2$' % (n,)
318+
return fr'${n}\pi/2$'
320319

321320

322321
class BasicUnitConverter(units.ConversionInterface):

lib/matplotlib/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,8 @@ def __setitem__(self, key, val):
718718
dict.__setitem__(self, key, cval)
719719
except KeyError:
720720
raise KeyError(
721-
'%s is not a valid rc parameter. See rcParams.keys() for a '
722-
'list of valid parameters.' % (key,))
721+
f"{key} is not a valid rc parameter (see rcParams.keys() for "
722+
f"a list of valid parameters)")
723723

724724
def __getitem__(self, key):
725725
if key in _deprecated_map:

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,8 +2287,7 @@ def margins(self, *margins, x=None, y=None, tight=True):
22872287

22882288
if x is None and y is None:
22892289
if tight is not True:
2290-
cbook._warn_external(
2291-
'ignoring tight=%r in get mode' % (tight,))
2290+
cbook._warn_external(f'ignoring tight={tight!r} in get mode')
22922291
return self._xmargin, self._ymargin
22932292

22942293
if x is not None:

lib/matplotlib/axes/_subplots.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@ def __init__(self, fig, *args, **kwargs):
5555
else:
5656
if num < 1 or num > rows*cols:
5757
raise ValueError(
58-
("num must be 1 <= num <= {maxn}, not {num}"
59-
).format(maxn=rows*cols, num=num))
58+
f"num must be 1 <= num <= {rows*cols}, not {num}")
6059
self._subplotspec = GridSpec(
6160
rows, cols, figure=self.figure)[int(num) - 1]
6261
# num - 1 for converting from MATLAB to python indexing
6362
else:
64-
raise ValueError('Illegal argument(s) to subplot: %s' % (args,))
63+
raise ValueError(f'Illegal argument(s) to subplot: {args}')
6564

6665
self.update_params()
6766

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ def recurse(obj, start, all, current_path):
864864
recurse(referent, start, all, current_path + [obj])
865865

866866
for obj in objects:
867-
outstream.write("Examining: %r\n" % (obj,))
867+
outstream.write(f"Examining: {obj!r}\n")
868868
recurse(obj, obj, {}, [])
869869

870870

lib/matplotlib/colorbar.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,10 +644,8 @@ def _set_label(self):
644644
self.stale = True
645645

646646
def set_label(self, label, **kw):
647-
'''
648-
Label the long axis of the colorbar
649-
'''
650-
self._label = '%s' % (label, )
647+
"""Label the long axis of the colorbar."""
648+
self._label = str(label)
651649
self._labelkw = kw
652650
self._set_label()
653651

lib/matplotlib/container.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ def set_label(self, s):
5252
5353
Parameters
5454
----------
55-
s : string or anything printable with '%s' conversion.
55+
s : object
56+
Any object other than None gets converted to its `str`.
5657
"""
5758
if s is not None:
58-
self._label = '%s' % (s, )
59+
self._label = str(s)
5960
else:
6061
self._label = None
6162
self.pchanged()

lib/matplotlib/figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,9 +1951,9 @@ def __setstate__(self, state):
19511951
restore_to_pylab = state.pop('_restore_to_pylab', False)
19521952

19531953
if version != _mpl_version:
1954-
cbook._warn_external("This figure was saved with matplotlib "
1955-
"version %s and is unlikely to function "
1956-
"correctly." % (version,))
1954+
cbook._warn_external(
1955+
f"This figure was saved with matplotlib version {version} and "
1956+
f"is unlikely to function correctly.")
19571957

19581958
self.__dict__ = state
19591959

lib/matplotlib/lines.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -180,30 +180,26 @@ def _slice_or_none(in_v, slc):
180180
inds = inds.argmin(axis=1)
181181
inds = np.unique(inds)
182182
# return, we are done here
183-
return Path(verts[inds],
184-
_slice_or_none(codes, inds))
183+
return Path(verts[inds], _slice_or_none(codes, inds))
185184
else:
186185
raise ValueError(
187-
'`markevery` is a tuple with len 2, but its second element is '
188-
'not an int or a float; markevery=%s' % (markevery,))
186+
f"markevery={markevery!r} is a tuple with len 2, but its "
187+
f"second element is not an int or a float")
189188

190189
elif isinstance(markevery, slice):
191190
# mazol tov, it's already a slice, just return
192191
return Path(verts[markevery], _slice_or_none(codes, markevery))
193192

194193
elif np.iterable(markevery):
195-
#fancy indexing
194+
# fancy indexing
196195
try:
197196
return Path(verts[markevery], _slice_or_none(codes, markevery))
198-
199197
except (ValueError, IndexError):
200-
raise ValueError('`markevery` is iterable but '
201-
'not a valid form of numpy fancy indexing; '
202-
'markevery=%s' % (markevery,))
198+
raise ValueError(
199+
f"markevery={markevery!r} is iterable but not a valid numpy "
200+
f"fancy index")
203201
else:
204-
raise ValueError('Value of `markevery` is not '
205-
'recognized; '
206-
'markevery=%s' % (markevery,))
202+
raise ValueError(f"markevery={markevery!r} is not a recognized value")
207203

208204

209205
@cbook._define_aliases({
@@ -264,17 +260,16 @@ class Line2D(Artist):
264260

265261
def __str__(self):
266262
if self._label != "":
267-
return "Line2D(%s)" % (self._label)
263+
return f"Line2D({self._label})"
268264
elif self._x is None:
269265
return "Line2D()"
270266
elif len(self._x) > 3:
271-
return "Line2D((%g,%g),(%g,%g),...,(%g,%g))"\
272-
% (self._x[0], self._y[0], self._x[0],
273-
self._y[0], self._x[-1], self._y[-1])
267+
return "Line2D((%g,%g),(%g,%g),...,(%g,%g))" % (
268+
self._x[0], self._y[0], self._x[0],
269+
self._y[0], self._x[-1], self._y[-1])
274270
else:
275-
return "Line2D(%s)"\
276-
% (",".join(["(%g,%g)" % (x, y) for x, y
277-
in zip(self._x, self._y)]))
271+
return "Line2D(%s)" % ",".join(
272+
map("({:g},{:g})".format, self._x, self._y))
278273

279274
def __init__(self, xdata, ydata,
280275
linewidth=None, # all Nones default to rc

lib/matplotlib/testing/jpl_units/UnitDblConverter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ def rad_fn(x, pos=None):
2121
elif n == 2:
2222
return r'$\pi$'
2323
elif n % 2 == 0:
24-
return r'$%s\pi$' % (n/2,)
24+
return fr'${n//2}\pi$'
2525
else:
26-
return r'$%s\pi/2$' % (n,)
26+
return fr'${n}\pi/2$'
2727

2828

2929
class UnitDblConverter(units.ConversionInterface):

lib/matplotlib/tests/test_rcparams.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ def test_Bug_2543():
163163
@pytest.mark.parametrize('color_type, param_dict, target', legend_color_tests,
164164
ids=legend_color_test_ids)
165165
def test_legend_colors(color_type, param_dict, target):
166-
param_dict['legend.%scolor' % (color_type, )] = param_dict.pop('color')
167-
get_func = 'get_%scolor' % (color_type, )
166+
param_dict[f'legend.{color_type}color'] = param_dict.pop('color')
167+
get_func = f'get_{color_type}color'
168168

169169
with mpl.rc_context(param_dict):
170170
_, ax = plt.subplots()

lib/matplotlib/text.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,12 +1143,14 @@ def set_text(self, s):
11431143
11441144
Parameters
11451145
----------
1146-
s : string or object castable to string (but ``None`` becomes ``''``)
1146+
s : object
1147+
Any object gets converted to its `str`, except ``None`` which
1148+
becomes ``''``.
11471149
"""
11481150
if s is None:
11491151
s = ''
11501152
if s != self._text:
1151-
self._text = '%s' % (s,)
1153+
self._text = str(s)
11521154
self.stale = True
11531155

11541156
@staticmethod

lib/mpl_toolkits/axes_grid1/axes_divider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def __init__(self, fig, *args, horizontal=None, vertical=None,
396396
self._subplotspec = GridSpec(rows, cols)[int(num)-1]
397397
# num - 1 for converting from MATLAB to python indexing
398398
else:
399-
raise ValueError('Illegal argument(s) to subplot: %s' % (args,))
399+
raise ValueError(f'Illegal argument(s) to subplot: {args}')
400400

401401
# total = rows*cols
402402
# num -= 1 # convert from matlab to python indexing

lib/mpl_toolkits/axes_grid1/mpl_axes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ def __init__(self, axis, axisnum, spine):
7070
elif isinstance(axis, YAxis):
7171
self._axis_direction = ["left", "right"][axisnum-1]
7272
else:
73-
raise ValueError("axis must be instance of XAxis or YAxis : %s is provided" % (axis,))
73+
raise ValueError(
74+
f"axis must be instance of XAxis or YAxis, but got {axis}")
7475
Artist.__init__(self)
7576

7677
@property

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ def margins(self, *margins, x=None, y=None, z=None, tight=True):
440440

441441
if x is None and y is None and z is None:
442442
if tight is not True:
443-
cbook._warn_external(
444-
'ignoring tight=%r in get mode' % (tight,))
443+
cbook._warn_external(f'ignoring tight={tight!r} in get mode')
445444
return self._xmargin, self._ymargin, self._zmargin
446445

447446
if x is not None:

lib/mpl_toolkits/tests/test_axisartist_angle_helper.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,11 @@ def test_formatters(Formatter, regex, direction, factor, values):
118118
prev_degree = prev_minute = prev_second = None
119119
for tick, value in zip(result, values):
120120
m = regex.match(tick)
121-
assert m is not None, '"%s" is not an expected tick format.' % (tick, )
121+
assert m is not None, f'{tick!r} is not an expected tick format.'
122122

123123
sign = sum(m.group(sign + '_sign') is not None
124124
for sign in ('degree', 'minute', 'second'))
125-
assert sign <= 1, \
126-
'Only one element of tick "%s" may have a sign.' % (tick, )
125+
assert sign <= 1, f'Only one element of tick {tick!r} may have a sign.'
127126
sign = 1 if sign == 0 else -1
128127

129128
degree = float(m.group('degree') or prev_degree or 0)
@@ -135,7 +134,7 @@ def test_formatters(Formatter, regex, direction, factor, values):
135134
else:
136135
expected_value = pytest.approx(value / factor)
137136
assert sign * dms2float(degree, minute, second) == expected_value, \
138-
'"%s" does not match expected tick value.' % (tick, )
137+
f'{tick!r} does not match expected tick value.'
139138

140139
prev_degree = degree
141140
prev_minute = minute

0 commit comments

Comments
 (0)
0