FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

MNT: Remove redundant f-strings by oscargus · Pull Request #22887 · matplotlib/matplotlib · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (29) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions doc/sphinxext/github.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def make_link_node(rawtext, app, type, slug, options):
base += '/'
except AttributeError as err:
raise ValueError(
f'github_project_url configuration value is not set '
'github_project_url configuration value is not set '
f'({err})') from err

ref = base + type + '/' + slug + '/'
Expand Down Expand Up @@ -143,7 +143,7 @@ def ghcommit_role(
base += '/'
except AttributeError as err:
raise ValueError(
f'github_project_url configuration value is not set '
'github_project_url configuration value is not set '
f'({err})') from err

ref = base + text
Expand Down
4 changes: 2 additions & 2 deletions doc/sphinxext/redirect_from.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def _generate_redirects(app, exception):
html = HTML_TEMPLATE.format(v=builder.get_relative_uri(k, v))
if p.is_file():
if p.read_text() != html:
logger.warning(f'A redirect-from directive is trying to '
logger.warning('A redirect-from directive is trying to '
f'create {p}, but that file already exists '
f'(perhaps you need to run "make clean")')
'(perhaps you need to run "make clean")')
else:
logger.info(f'making refresh html file: {k} redirect to {v}')
p.parent.mkdir(parents=True, exist_ok=True)
Expand Down
2 changes: 1 addition & 1 deletion examples/widgets/annotated_cursor.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def set_position(self, xpos, ypos):
lim = self.ax.get_ylim()
else:
raise ValueError(f"The data axis specifier {self.dataaxis} should "
f"be 'x' or 'y'")
"be 'x' or 'y'")

# If position is valid and in valid plot data range.
if pos is not None and lim[0] <= pos <= lim[-1]:
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def impl(args, regex, min_ver=None, ignore_exit_code=False):
parse_version("0.9") <= info.version < parse_version("1.0")):
raise ExecutableNotFoundError(
f"You have pdftops version {info.version} but the minimum "
f"version supported by Matplotlib is 3.0")
"version supported by Matplotlib is 3.0")
return info
else:
raise ValueError("Unknown executable: {!r}".format(name))
Expand Down Expand Up @@ -650,7 +650,7 @@ def __setitem__(self, key, val):
except KeyError as err:
raise KeyError(
f"{key} is not a valid rc parameter (see rcParams.keys() for "
f"a list of valid parameters)") from err
"a list of valid parameters)") from err

def __getitem__(self, key):
if key in _deprecated_map:
Expand Down Expand Up @@ -1211,9 +1211,9 @@ def _init_tests():
if (ft2font.__freetype_version__ != LOCAL_FREETYPE_VERSION or
ft2font.__freetype_build_type__ != 'local'):
_log.warning(
f"Matplotlib is not built with the correct FreeType version to "
f"run tests. Rebuild without setting system_freetype=1 in "
f"mplsetup.cfg. Expect many image comparison failures below. "
"Matplotlib is not built with the correct FreeType version to "
"run tests. Rebuild without setting system_freetype=1 in "
"mplsetup.cfg. Expect many image comparison failures below. "
f"Expected freetype version {LOCAL_FREETYPE_VERSION}. "
f"Found freetype version {ft2font.__freetype_version__}. "
"Freetype build type is {}local".format(
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/_api/deprecation.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def wrapper(*args, **kwargs):
warn_deprecated(
since, message=f"The {old!r} parameter of {func.__name__}() "
f"has been renamed {new!r} since Matplotlib {since}; support "
f"for the old name will be dropped %(removal)s.")
"for the old name will be dropped %(removal)s.")
kwargs[new] = kwargs.pop(old)
return func(*args, **kwargs)

Expand Down Expand Up @@ -385,21 +385,21 @@ def wrapper(*inner_args, **inner_kwargs):
arguments = signature.bind(*inner_args, **inner_kwargs).arguments
if is_varargs and arguments.get(name):
warn_deprecated(
since, message=f"Additional positional arguments to "
since, message="Additional positional arguments to "
f"{func.__name__}() are deprecated since %(since)s and "
f"support for them will be removed %(removal)s.")
"support for them will be removed %(removal)s.")
elif is_varkwargs and arguments.get(name):
warn_deprecated(
since, message=f"Additional keyword arguments to "
since, message="Additional keyword arguments to "
f"{func.__name__}() are deprecated since %(since)s and "
f"support for them will be removed %(removal)s.")
"support for them will be removed %(removal)s.")
# We cannot just check `name not in arguments` because the pyplot
# wrappers always pass all arguments explicitly.
elif any(name in d and d[name] != _deprecated_parameter
for d in [arguments, arguments.get(kwargs_name, {})]):
deprecation_addendum = (
f"If any parameter follows {name!r}, they should be passed as "
f"keyword, not positionally.")
"keyword, not positionally.")
warn_deprecated(
since,
name=repr(name),
Expand Down
16 changes: 8 additions & 8 deletions lib/matplotlib/axes/_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2401,15 +2401,15 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
except TypeError as e:
raise TypeError(f'the dtypes of parameters x ({x.dtype}) '
f'and width ({width.dtype}) '
f'are incompatible') from e
'are incompatible') from e
bottom = y
elif orientation == 'horizontal':
try:
bottom = y - height / 2
except TypeError as e:
raise TypeError(f'the dtypes of parameters y ({y.dtype}) '
f'and height ({height.dtype}) '
f'are incompatible') from e
'are incompatible') from e
left = x
elif align == 'edge':
left = x
Expand Down Expand Up @@ -3391,7 +3391,7 @@ def _upcast_err(err):
else:
raise ValueError(
f'errorevery={errorevery!r} is a not a tuple of two '
f'integers')
'integers')
elif isinstance(errorevery, slice):
pass
elif not isinstance(errorevery, str) and np.iterable(errorevery):
Expand All @@ -3401,7 +3401,7 @@ def _upcast_err(err):
except (ValueError, IndexError) as err:
raise ValueError(
f"errorevery={errorevery!r} is iterable but not a valid "
f"NumPy fancy index to match 'xerr'/'yerr'") from err
"NumPy fancy index to match 'xerr'/'yerr'") from err
else:
raise ValueError(
f"errorevery={errorevery!r} is not a recognized value")
Expand Down Expand Up @@ -3502,7 +3502,7 @@ def apply_mask(arrays, mask): return [array[mask] for array in arrays]
except ValueError:
raise ValueError(
f"'{dep_axis}err' (shape: {np.shape(err)}) must be a "
f"scalar or a 1D or (2, n) array-like whose shape matches "
"scalar or a 1D or (2, n) array-like whose shape matches "
f"'{dep_axis}' (shape: {np.shape(dep)})") from None
if np.any(err < -err): # like err<0, but also works for timedelta.
raise ValueError(
Expand Down Expand Up @@ -4296,8 +4296,8 @@ def invalid_shape_exception(csize, xsize):
# Both the mapping *and* the RGBA conversion failed: pretty
# severe failure => one may appreciate a verbose feedback.
raise ValueError(
f"'c' argument must be a color, a sequence of colors, "
f"or a sequence of numbers, not {c}") from err
"'c' argument must be a color, a sequence of colors, "
f"or a sequence of numbers, not {c!r}") from err
else:
if len(colors) not in (0, 1, xsize):
# NB: remember that a single color is also acceptable.
Expand Down Expand Up @@ -6603,7 +6603,7 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
else:
color = mcolors.to_rgba_array(color)
if len(color) != nx:
raise ValueError(f"The 'color' keyword argument must have one "
raise ValueError("The 'color' keyword argument must have one "
f"color per dataset, but {nx} datasets and "
f"{len(color)} colors were provided")

Expand Down
36 changes: 18 additions & 18 deletions lib/matplotlib/axes/_base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ def __call__(self, *args, data=None, **kwargs):
if replaced[1] is not args[1]: # case 2a)
_api.warn_external(
f"Second argument {args[1]!r} is ambiguous: could "
f"be a format string but is in 'data'; using as "
f"data. If it was intended as data, set the "
f"format string to an empty string to suppress "
f"this warning. If it was intended as a format "
f"string, explicitly pass the x-values as well. "
f"Alternatively, rename the entry in 'data'.",
"be a format string but is in 'data'; using as "
"data. If it was intended as data, set the "
"format string to an empty string to suppress "
"this warning. If it was intended as a format "
"string, explicitly pass the x-values as well. "
"Alternatively, rename the entry in 'data'.",
RuntimeWarning)
label_namer_idx = 1
else: # case 2b)
Expand Down Expand Up @@ -479,7 +479,7 @@ def _plot_args(self, tup, kwargs, return_kwargs=False):
f"{prop_name} is redundantly defined by the "
f"'{prop_name}' keyword argument and the fmt string "
f'"{fmt}" (-> {prop_name}={val!r}). The keyword '
f"argument will take precedence.")
"argument will take precedence.")
kw[prop_name] = val

if len(xy) == 2:
Expand All @@ -494,10 +494,10 @@ def _plot_args(self, tup, kwargs, return_kwargs=False):
self.axes.yaxis.update_units(y)

if x.shape[0] != y.shape[0]:
raise ValueError(f"x and y must have same first dimension, but "
raise ValueError("x and y must have same first dimension, but "
f"have shapes {x.shape} and {y.shape}")
if x.ndim > 2 or y.ndim > 2:
raise ValueError(f"x and y can be no greater than 2D, but have "
raise ValueError("x and y can be no greater than 2D, but have "
f"shapes {x.shape} and {y.shape}")
if x.ndim == 1:
x = x[:, np.newaxis]
Expand All @@ -520,8 +520,8 @@ def _plot_args(self, tup, kwargs, return_kwargs=False):
n_datasets = max(ncx, ncy)
if n_datasets > 1 and not cbook.is_scalar_or_string(label):
if len(label) != n_datasets:
raise ValueError(f"label must be scalar or have the same "
f"length as the input data, but found "
raise ValueError("label must be scalar or have the same "
"length as the input data, but found "
f"{len(label)} for {n_datasets} datasets.")
labels = label
else:
Expand Down Expand Up @@ -2109,7 +2109,7 @@ def axis(self, *args, emit=True, **kwargs):
self.set_xlim(xmin, xmax, emit=emit, auto=xauto)
self.set_ylim(ymin, ymax, emit=emit, auto=yauto)
if kwargs:
raise TypeError(f"axis() got an unexpected keyword argument "
raise TypeError("axis() got an unexpected keyword argument "
f"'{next(iter(kwargs))}'")
return (*self.get_xlim(), *self.get_ylim())

Expand Down Expand Up @@ -3477,10 +3477,10 @@ def set_xlabel(self, xlabel, fontdict=None, labelpad=None, *,
protected_kw = ['x', 'horizontalalignment', 'ha']
if {*kwargs} & {*protected_kw}:
if loc is not None:
raise TypeError(f"Specifying 'loc' is disallowed when any of "
f"its corresponding low level keyword "
raise TypeError("Specifying 'loc' is disallowed when any of "
"its corresponding low level keyword "
f"arguments ({protected_kw}) are also "
f"supplied")
"supplied")

else:
loc = (loc if loc is not None
Expand Down Expand Up @@ -3766,10 +3766,10 @@ def set_ylabel(self, ylabel, fontdict=None, labelpad=None, *,
protected_kw = ['y', 'horizontalalignment', 'ha']
if {*kwargs} & {*protected_kw}:
if loc is not None:
raise TypeError(f"Specifying 'loc' is disallowed when any of "
f"its corresponding low level keyword "
raise TypeError("Specifying 'loc' is disallowed when any of "
"its corresponding low level keyword "
f"arguments ({protected_kw}) are also "
f"supplied")
"supplied")

else:
loc = (loc if loc is not None
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backend_bases.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ def _draw(renderer): raise Done(renderer)
return renderer
else:
raise RuntimeError(f"{print_method} did not call Figure.draw, so "
f"no renderer is available")
"no renderer is available")


def _no_output_draw(figure):
Expand Down Expand Up @@ -2775,7 +2775,7 @@ def show(self):
return
raise NonGuiException(
f"Matplotlib is currently using {get_backend()}, which is a "
f"non-GUI backend, so cannot show the figure.")
"non-GUI backend, so cannot show the figure.")

def destroy(self):
pass
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_pgf.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ def __init__(self):
except FileNotFoundError as err:
raise RuntimeError(
f"{self.texcommand} not found. Install it or change "
f"rcParams['pgf.texsystem'] to an available TeX "
f"implementation.") from err
"rcParams['pgf.texsystem'] to an available TeX "
"implementation.") from err
except OSError as err:
raise RuntimeError("Error starting process %r" %
self.texcommand) from err
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/backends/backend_ps.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
self._text2path.mathtext_parser.parse(s, 72, prop)
self.set_color(*gc.get_rgb())
self._pswriter.write(
f"gsave\n"
"gsave\n"
f"{x:g} {y:g} translate\n"
f"{angle:g} rotate\n")
lastfont = None
Expand Down Expand Up @@ -930,14 +930,14 @@ def print_figure_impl(fh):
if is_eps:
print("%!PS-Adobe-3.0 EPSF-3.0", file=fh)
else:
print(f"%!PS-Adobe-3.0\n"
print("%!PS-Adobe-3.0\n"
f"%%DocumentPaperSizes: {papertype}\n"
f"%%Pages: 1\n",
"%%Pages: 1\n",
end="", file=fh)
print(f"{dsc_comments}\n"
f"%%Orientation: {orientation.name}\n"
f"{get_bbox_header(bbox)[0]}\n"
f"%%EndComments\n",
"%%EndComments\n",
end="", file=fh)

Ndict = len(psDefs)
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/cbook/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2101,11 +2101,11 @@ def _check_and_log_subprocess(command, logger, **kwargs):
if isinstance(stderr, bytes):
stderr = stderr.decode()
raise RuntimeError(
f"The command\n"
"The command\n"
f" {_pformat_subprocess(command)}\n"
f"failed and generated the following output:\n"
"failed and generated the following output:\n"
f"{stdout}\n"
f"and the following error:\n"
"and the following error:\n"
f"{stderr}")
if proc.stdout:
logger.debug("stdout:\n%s", proc.stdout)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/colors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def _to_rgba_no_colorcycle(c, alpha=None):
if not (0 <= c <= 1):
raise ValueError(
f"Invalid string grayscale value {orig_c!r}. "
f"Value must be within 0-1 range")
"Value must be within 0-1 range")
return c, c, c, alpha if alpha is not None else 1.
raise ValueError(f"Invalid RGBA argument: {orig_c!r}")
# turn 2-D array into 1-D array
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/dates.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1419,9 +1419,9 @@ def get_locator(self, dmin, dmax):
else:
if not (self.interval_multiples and freq == DAILY):
_api.warn_external(
f"AutoDateLocator was unable to pick an appropriate "
f"interval for this date range. It may be necessary "
f"to add an interval value to the AutoDateLocator's "
"AutoDateLocator was unable to pick an appropriate "
"interval for this date range. It may be necessary "
"to add an interval value to the AutoDateLocator's "
f"intervald dictionary. Defaulting to {interval}.")

# Set some parameters as appropriate
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/dviread.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -878,11 +878,11 @@ def __getitem__(self, texname):
return self._parsed[texname]
except KeyError:
raise LookupError(
f"An associated PostScript font (required by Matplotlib) "
"An associated PostScript font (required by Matplotlib) "
f"could not be found for TeX font {texname.decode('ascii')!r} "
f"in {self._filename!r}; this problem can often be solved by "
f"installing a suitable PostScript font package in your TeX "
f"package manager") from None
"installing a suitable PostScript font package in your TeX "
"package manager") from None

def _parse_and_cache_line(self, line):
"""
Expand Down Expand Up @@ -1094,7 +1094,7 @@ def _find_tex_file(filename, format=None):
return path
else:
raise FileNotFoundError(
f"Matplotlib's TeX implementation searched for a file named "
"Matplotlib's TeX implementation searched for a file named "
f"{filename!r} in your texmf tree, but could not find it")


Expand All @@ -1108,7 +1108,7 @@ def find_tex_file(filename, format=None):
except FileNotFoundError as exc:
_api.warn_deprecated(
"3.6", message=f"{exc.args[0]}; in the future, this will raise a "
f"FileNotFoundError.")
"FileNotFoundError.")
return ""


Expand All @@ -1135,7 +1135,7 @@ def _fontfile(cls, suffix, texname):
with Dvi(args.filename, args.dpi) as dvi:
fontmap = PsfontsMap(_find_tex_file('pdftex.map'))
for page in dvi:
print(f"=== new page === "
print("=== new page === "
f"(w: {page.width}, h: {page.height}, d: {page.descent})")
for font, group in itertools.groupby(
page.text, lambda text: text.font):
Expand Down
Loading

Back | FazBrowse Home | New Git URL