Skip to content

Remove some more 1-tuples. #13104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ per-file-ignores =
mpl_toolkits/axes_grid1/axes_size.py: E272, E501
mpl_toolkits/axes_grid1/colorbar.py: E225, E501
mpl_toolkits/axes_grid1/inset_locator.py: E501
mpl_toolkits/axes_grid1/mpl_axes.py: E501
mpl_toolkits/axisartist/angle_helper.py: E221
mpl_toolkits/axisartist/clip_path.py: E225, E501
mpl_toolkits/axisartist/floating_axes.py: E225, E402, E501
Expand Down
11 changes: 5 additions & 6 deletions examples/units/basic_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ def __new__(cls, value, unit):
# generate a new subclass for value
value_class = type(value)
try:
subcls = type('TaggedValue_of_%s' % (value_class.__name__),
tuple([cls, value_class]),
{})
subcls = type(f'TaggedValue_of_{value_class.__name__}',
(cls, value_class), {})
if subcls not in units.registry:
units.registry[subcls] = basicConverter
return object.__new__(subcls)
Expand Down Expand Up @@ -196,7 +195,7 @@ def __init__(self, name, fullname=None):
self.conversions = dict()

def __repr__(self):
return 'BasicUnit(%s)' % self.name
return f'BasicUnit({self.name})'

def __str__(self):
return self.fullname
Expand Down Expand Up @@ -314,9 +313,9 @@ def rad_fn(x, pos=None):
elif n == -2:
return r'$-\pi$'
elif n % 2 == 0:
return r'$%s\pi$' % (n//2,)
return fr'${n//2}\pi$'
else:
return r'$%s\pi/2$' % (n,)
return fr'${n}\pi/2$'


class BasicUnitConverter(units.ConversionInterface):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,8 @@ def __setitem__(self, key, val):
dict.__setitem__(self, key, cval)
except KeyError:
raise KeyError(
'%s is not a valid rc parameter. See rcParams.keys() for a '
'list of valid parameters.' % (key,))
f"{key} is not a valid rc parameter (see rcParams.keys() for "
f"a list of valid parameters)")

def __getitem__(self, key):
if key in _deprecated_map:
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2291,8 +2291,7 @@ def margins(self, *margins, x=None, y=None, tight=True):

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

if x is not None:
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/axes/_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ def __init__(self, fig, *args, **kwargs):
else:
if num < 1 or num > rows*cols:
raise ValueError(
("num must be 1 <= num <= {maxn}, not {num}"
).format(maxn=rows*cols, num=num))
f"num must be 1 <= num <= {rows*cols}, not {num}")
self._subplotspec = GridSpec(
rows, cols, figure=self.figure)[int(num) - 1]
# num - 1 for converting from MATLAB to python indexing
else:
raise ValueError('Illegal argument(s) to subplot: %s' % (args,))
raise ValueError(f'Illegal argument(s) to subplot: {args}')

self.update_params()

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ def recurse(obj, start, all, current_path):
recurse(referent, start, all, current_path + [obj])

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


Expand Down
6 changes: 2 additions & 4 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,8 @@ def _set_label(self):
self.stale = True

def set_label(self, label, **kw):
'''
Label the long axis of the colorbar
'''
self._label = '%s' % (label, )
"""Label the long axis of the colorbar."""
self._label = str(label)
self._labelkw = kw
self._set_label()

Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ def set_label(self, s):

Parameters
----------
s : string or anything printable with '%s' conversion.
s : object
Any object other than None gets converted to its `str`.
"""
if s is not None:
self._label = '%s' % (s, )
self._label = str(s)
else:
self._label = None
self.pchanged()
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,9 +1951,9 @@ def __setstate__(self, state):
restore_to_pylab = state.pop('_restore_to_pylab', False)

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

self.__dict__ = state

Expand Down
33 changes: 14 additions & 19 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,30 +180,26 @@ def _slice_or_none(in_v, slc):
inds = inds.argmin(axis=1)
inds = np.unique(inds)
# return, we are done here
return Path(verts[inds],
_slice_or_none(codes, inds))
return Path(verts[inds], _slice_or_none(codes, inds))
else:
raise ValueError(
'`markevery` is a tuple with len 2, but its second element is '
'not an int or a float; markevery=%s' % (markevery,))
f"markevery={markevery!r} is a tuple with len 2, but its "
f"second element is not an int or a float")

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

elif np.iterable(markevery):
#fancy indexing
# fancy indexing
try:
return Path(verts[markevery], _slice_or_none(codes, markevery))

except (ValueError, IndexError):
raise ValueError('`markevery` is iterable but '
'not a valid form of numpy fancy indexing; '
'markevery=%s' % (markevery,))
raise ValueError(
f"markevery={markevery!r} is iterable but not a valid numpy "
f"fancy index")
else:
raise ValueError('Value of `markevery` is not '
'recognized; '
'markevery=%s' % (markevery,))
raise ValueError(f"markevery={markevery!r} is not a recognized value")


@cbook._define_aliases({
Expand Down Expand Up @@ -264,17 +260,16 @@ class Line2D(Artist):

def __str__(self):
if self._label != "":
return "Line2D(%s)" % (self._label)
return f"Line2D({self._label})"
elif self._x is None:
return "Line2D()"
elif len(self._x) > 3:
return "Line2D((%g,%g),(%g,%g),...,(%g,%g))"\
% (self._x[0], self._y[0], self._x[0],
self._y[0], self._x[-1], self._y[-1])
return "Line2D((%g,%g),(%g,%g),...,(%g,%g))" % (
self._x[0], self._y[0], self._x[0],
self._y[0], self._x[-1], self._y[-1])
else:
return "Line2D(%s)"\
% (",".join(["(%g,%g)" % (x, y) for x, y
in zip(self._x, self._y)]))
return "Line2D(%s)" % ",".join(
map("({:g},{:g})".format, self._x, self._y))

def __init__(self, xdata, ydata,
linewidth=None, # all Nones default to rc
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/testing/jpl_units/UnitDblConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def rad_fn(x, pos=None):
elif n == 2:
return r'$\pi$'
elif n % 2 == 0:
return r'$%s\pi$' % (n/2,)
return fr'${n//2}\pi$'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the basic_units example.
This clearly got missed during py2->3 transition.

else:
return r'$%s\pi/2$' % (n,)
return fr'${n}\pi/2$'


class UnitDblConverter(units.ConversionInterface):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def test_Bug_2543():
@pytest.mark.parametrize('color_type, param_dict, target', legend_color_tests,
ids=legend_color_test_ids)
def test_legend_colors(color_type, param_dict, target):
param_dict['legend.%scolor' % (color_type, )] = param_dict.pop('color')
get_func = 'get_%scolor' % (color_type, )
param_dict[f'legend.{color_type}color'] = param_dict.pop('color')
get_func = f'get_{color_type}color'

with mpl.rc_context(param_dict):
_, ax = plt.subplots()
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,12 +1145,14 @@ def set_text(self, s):

Parameters
----------
s : string or object castable to string (but ``None`` becomes ``''``)
s : object
Any object gets converted to its `str`, except ``None`` which
becomes ``''``.
"""
if s is None:
s = ''
if s != self._text:
self._text = '%s' % (s,)
self._text = str(s)
self.stale = True

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/axes_grid1/axes_divider.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def __init__(self, fig, *args, horizontal=None, vertical=None,
self._subplotspec = GridSpec(rows, cols)[int(num)-1]
# num - 1 for converting from MATLAB to python indexing
else:
raise ValueError('Illegal argument(s) to subplot: %s' % (args,))
raise ValueError(f'Illegal argument(s) to subplot: {args}')

# total = rows*cols
# num -= 1 # convert from matlab to python indexing
Expand Down
3 changes: 2 additions & 1 deletion lib/mpl_toolkits/axes_grid1/mpl_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def __init__(self, axis, axisnum, spine):
elif isinstance(axis, YAxis):
self._axis_direction = ["left", "right"][axisnum-1]
else:
raise ValueError("axis must be instance of XAxis or YAxis : %s is provided" % (axis,))
raise ValueError(
f"axis must be instance of XAxis or YAxis, but got {axis}")
Artist.__init__(self)

@property
Expand Down
3 changes: 1 addition & 2 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,7 @@ def margins(self, *margins, x=None, y=None, z=None, tight=True):

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

if x is not None:
Expand Down
7 changes: 3 additions & 4 deletions lib/mpl_toolkits/tests/test_axisartist_angle_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,11 @@ def test_formatters(Formatter, regex, direction, factor, values):
prev_degree = prev_minute = prev_second = None
for tick, value in zip(result, values):
m = regex.match(tick)
assert m is not None, '"%s" is not an expected tick format.' % (tick, )
assert m is not None, f'{tick!r} is not an expected tick format.'

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

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

prev_degree = degree
prev_minute = minute
Expand Down