diff --git a/tests/aliases/test_xexec.py b/tests/aliases/test_xexec.py index 6bc9b06e6..46ecdc7ca 100644 --- a/tests/aliases/test_xexec.py +++ b/tests/aliases/test_xexec.py @@ -38,7 +38,7 @@ def test_command_not_found(monkeypatch): assert xexec([command]) == ( None, - "xonsh: exec: file not found: {}: {}" "\n".format(dummy_error_msg, command), + f"xonsh: exec: file not found: {dummy_error_msg}: {command}" "\n", 1, ) diff --git a/tests/test_news.py b/tests/test_news.py index 70c1fd1c4..7a30a8483 100644 --- a/tests/test_news.py +++ b/tests/test_news.py @@ -32,9 +32,9 @@ def check_news_file(fname): cat = l[2:].rsplit(":")[0] if cat not in CATEGORIES: pytest.fail( - "{}:{}: {!r} not a proper category " - "must be one of {}" - "".format(name, i + 1, cat, list(CATEGORIES)), + f"{name}:{i + 1}: {cat!r} not a proper category " + f"must be one of {list(CATEGORIES)}" + "", pytrace=True, ) if l.endswith("None"): diff --git a/xonsh/aliases.py b/xonsh/aliases.py index 28ea675c7..c09a60811 100644 --- a/xonsh/aliases.py +++ b/xonsh/aliases.py @@ -747,7 +747,7 @@ def xexec_fn( except FileNotFoundError as e: return ( None, - "xonsh: exec: file not found: {}: {}" "\n".format(e.args[1], command[0]), + f"xonsh: exec: file not found: {e.args[1]}: {command[0]}" "\n", 1, ) diff --git a/xonsh/diff_history.py b/xonsh/diff_history.py index 02685e27e..c271d0d75 100644 --- a/xonsh/diff_history.py +++ b/xonsh/diff_history.py @@ -212,13 +212,7 @@ class HistoryDiffer: brtn = self.b["cmds"][j]["rtn"] if artn != brtn: s += ( - "Return vals {red}{artn}{reset} & {green}{brtn}{reset} differ\n" - ).format( - red=COLORS.RED, - green=COLORS.GREEN, - reset=COLORS.RESET, - artn=artn, - brtn=brtn, + f"Return vals {COLORS.RED}{artn}{COLORS.RESET} & {COLORS.GREEN}{brtn}{COLORS.RESET} differ\n" ) return s diff --git a/xonsh/dirstack.py b/xonsh/dirstack.py index a8d179fe2..c21c6d015 100644 --- a/xonsh/dirstack.py +++ b/xonsh/dirstack.py @@ -244,9 +244,9 @@ def cd(args, stdin=None): return ( "", ( - "cd takes 0 or 1 arguments, not {}. An additional `-P` " + f"cd takes 0 or 1 arguments, not {len(args)}. An additional `-P` " "flag can be passed in first position to follow symlinks." - "\n".format(len(args)) + "\n" ), 1, ) diff --git a/xonsh/history/base.py b/xonsh/history/base.py index 7f7547fa9..a270e40e4 100644 --- a/xonsh/history/base.py +++ b/xonsh/history/base.py @@ -109,7 +109,7 @@ class History: else: raise TypeError( "history indices must be integers " - "or slices, not {}".format(type(item)) + f"or slices, not {type(item)}" ) def __setitem__(self, *args): diff --git a/xonsh/parsers/base.py b/xonsh/parsers/base.py index 2d6fda5ce..4b8d5fcee 100644 --- a/xonsh/parsers/base.py +++ b/xonsh/parsers/base.py @@ -532,7 +532,7 @@ class BaseParser: def optfunc(self, p): p[0] = p[1] - optfunc.__doc__ = ("{0}_opt : empty\n" " | {0}").format(rulename) + optfunc.__doc__ = (f"{rulename}_opt : empty\n" f" | {rulename}") optfunc.__name__ = "p_" + rulename + "_opt" setattr(self.__class__, optfunc.__name__, optfunc) @@ -544,9 +544,7 @@ class BaseParser: def listfunc(self, p): p[0] = p[1] if len(p) == 2 else p[1] + p[2] - listfunc.__doc__ = ("{0}_list : {0}\n" " | {0}_list {0}").format( - rulename - ) + listfunc.__doc__ = (f"{rulename}_list : {rulename}\n" f" | {rulename}_list {rulename}") listfunc.__name__ = "p_" + rulename + "_list" setattr(self.__class__, listfunc.__name__, listfunc) diff --git a/xonsh/procs/specs.py b/xonsh/procs/specs.py index 76c0bbb70..45718f992 100644 --- a/xonsh/procs/specs.py +++ b/xonsh/procs/specs.py @@ -133,7 +133,7 @@ def get_script_subproc_command(fname, args): @xl.lazyobject def _REDIR_REGEX(): name = r"(o(?:ut)?|e(?:rr)?|a(?:ll)?|&?\d?)" - return re.compile("{r}(>?>|<){r}$".format(r=name)) + return re.compile(f"{name}(>?>|<){name}$") @xl.lazyobject diff --git a/xonsh/prompt/base.py b/xonsh/prompt/base.py index 36b46f34b..4ff245fcf 100644 --- a/xonsh/prompt/base.py +++ b/xonsh/prompt/base.py @@ -132,7 +132,7 @@ class PromptFormatter: try: return self.fields.pick(field) except Exception: # noqa - print("prompt: error: on field {!r}" "".format(field), file=sys.stderr) + print(f"prompt: error: on field {field!r}" "", file=sys.stderr) xt.print_exception() value = f"{{BACKGROUND_RED}}{{ERROR:{field}}}{{RESET}}" return value diff --git a/xonsh/timings.py b/xonsh/timings.py index 2ceb0351c..dd2ac91f1 100644 --- a/xonsh/timings.py +++ b/xonsh/timings.py @@ -231,11 +231,11 @@ def timeit_alias(args, stdin=None): # timing is 4 times faster than the slowest timing or not. if worst > 4 * best and best > 0 and worst > 1e-5: print( - ( - "The slowest run took {:0.2f} times longer than the " + + f"The slowest run took {worst / best:0.2f} times longer than the " "fastest. This could mean that an intermediate result " "is being cached." - ).format(worst / best) + ) print( f"{number} loops, best of {repeat}: {format_time(best, precision)} per loop" diff --git a/xonsh/tools.py b/xonsh/tools.py index e60c165a1..392f2de4c 100644 --- a/xonsh/tools.py +++ b/xonsh/tools.py @@ -2708,7 +2708,7 @@ def columnize(elems, width=80, newline="\n"): data = [elems[i * nrows : (i + 1) * nrows] for i in range(ncols)] colwidths = [max(map(len, d)) + pad for d in data] colwidths[-1] -= pad - row_t = "".join(["{{row[{i}]: <{{w[{i}]}}}}".format(i=i) for i in range(ncols)]) + row_t = "".join([f"{{row[{i}]: <{{w[{i}]}}}}" for i in range(ncols)]) row_t += newline lines = [ row_t.format(row=row, w=colwidths) diff --git a/xonsh/wizard.py b/xonsh/wizard.py index 80a57a073..5f8195775 100644 --- a/xonsh/wizard.py +++ b/xonsh/wizard.py @@ -508,7 +508,7 @@ class PrettyFormatter(Visitor): if node.path is None: s += "\n])" else: - s += "{0}],\n{0}path={1!r}\n)".format(self.indent, node.path) + s += f"{self.indent}],\n{self.indent}path={node.path!r}\n)" return s def visit_message(self, node): @@ -830,9 +830,7 @@ class PromptVisitor(StateVisitor): print_color(f"{{GREEN}}{fname!r} loaded.{{RESET}}") else: print_color( - ("{{RED}}{!r} could not be found, " "continuing.{{RESET}}").format( - fname - ) + f"{{RED}}{fname!r} could not be found, " "continuing.{{RESET}}" ) return fname