From 5b08580becd5f7e36db6d65f7632b721c67ed92a Mon Sep 17 00:00:00 2001 From: Asher Foa <1268088+asherf@users.noreply.github.com> Date: Wed, 10 Nov 2021 17:22:53 -0800 Subject: [PATCH] [internal] use f-strings instead of str.format() --- .../backend/project_info/source_file_validator.py | 6 +++--- src/python/pants/bin/daemon_pants_runner.py | 2 +- src/python/pants/bin/remote_pants_runner.py | 4 ++-- src/python/pants/build_graph/build_configuration.py | 10 ++++------ src/python/pants/build_graph/build_file_aliases.py | 2 +- src/python/pants/goal/anonymous_telemetry.py | 12 ++++++------ 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/python/pants/backend/project_info/source_file_validator.py b/src/python/pants/backend/project_info/source_file_validator.py index cf41ebe547c..e8cd823cb9a 100644 --- a/src/python/pants/backend/project_info/source_file_validator.py +++ b/src/python/pants/backend/project_info/source_file_validator.py @@ -315,12 +315,12 @@ async def validate( if detail_level == DetailLevel.all or ( detail_level == DetailLevel.nonmatching and nonmatched_msg ): - console.print_stdout("{} {}:{}{}".format(icon, rmr.path, matched_msg, nonmatched_msg)) + console.print_stdout(f"{icon} {rmr.path}:{matched_msg}{nonmatched_msg}") if detail_level not in (DetailLevel.none, DetailLevel.names): - console.print_stdout("\n{} files matched all required patterns.".format(num_matched_all)) + console.print_stdout(f"\n{num_matched_all} files matched all required patterns.") console.print_stdout( - "{} files failed to match at least one required pattern.".format(num_nonmatched_some) + f"{num_nonmatched_some} files failed to match at least one required pattern." ) if num_nonmatched_some: diff --git a/src/python/pants/bin/daemon_pants_runner.py b/src/python/pants/bin/daemon_pants_runner.py index f9d6bef722d..70a132e915d 100644 --- a/src/python/pants/bin/daemon_pants_runner.py +++ b/src/python/pants/bin/daemon_pants_runner.py @@ -67,7 +67,7 @@ def should_keep_polling(now): acquired = self._run_lock.acquire(blocking=False) if not acquired: # If we don't acquire immediately, send an explanation. - length = "forever" if should_poll_forever else "up to {} seconds".format(timeout) + length = "forever" if should_poll_forever else f"up to {timeout} seconds" self._send_stderr( stderr_fileno, f"Another pants invocation is running. Will wait {length} for it to finish before giving up.\n" diff --git a/src/python/pants/bin/remote_pants_runner.py b/src/python/pants/bin/remote_pants_runner.py index 20d3d7778ae..bb23a7b8d06 100644 --- a/src/python/pants/bin/remote_pants_runner.py +++ b/src/python/pants/bin/remote_pants_runner.py @@ -71,14 +71,14 @@ def save_tty_flags(self): try: self._tty_flags = termios.tcgetattr(sys.stdin.fileno()) except termios.error as e: - logger.debug("masking tcgetattr exception: {!r}".format(e)) + logger.debug(f"masking tcgetattr exception: {e!r}") def restore_tty_flags(self): if self._tty_flags: try: termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, self._tty_flags) except termios.error as e: - logger.debug("masking tcsetattr exception: {!r}".format(e)) + logger.debug(f"masking tcsetattr exception: {e!r}") class RemotePantsRunner: diff --git a/src/python/pants/build_graph/build_configuration.py b/src/python/pants/build_graph/build_configuration.py index c82631322e5..ffbfbfedb4b 100644 --- a/src/python/pants/build_graph/build_configuration.py +++ b/src/python/pants/build_graph/build_configuration.py @@ -132,7 +132,7 @@ def register_aliases(self, aliases): :type aliases: :class:`pants.build_graph.build_file_aliases.BuildFileAliases` """ if not isinstance(aliases, BuildFileAliases): - raise TypeError("The aliases must be a BuildFileAliases, given {}".format(aliases)) + raise TypeError(f"The aliases must be a BuildFileAliases, given {aliases}") for alias, obj in aliases.objects.items(): self._register_exposed_object(alias, obj) @@ -147,9 +147,7 @@ def register_aliases(self, aliases): def _register_exposed_object(self, alias, obj): if alias in self._exposed_object_by_alias: - logger.debug( - "Object alias {} has already been registered. Overwriting!".format(alias) - ) + logger.debug(f"Object alias {alias} has already been registered. Overwriting!") self._exposed_object_by_alias[alias] = obj @@ -171,7 +169,7 @@ def register_subsystems( ): """Registers the given subsystem types.""" if not isinstance(subsystems, Iterable): - raise TypeError("The subsystems must be an iterable, given {}".format(subsystems)) + raise TypeError(f"The subsystems must be an iterable, given {subsystems}") subsystems = tuple(subsystems) if not subsystems: return @@ -191,7 +189,7 @@ def register_subsystems( def register_rules(self, plugin_or_backend: str, rules: Iterable[Rule | UnionRule]): """Registers the given rules.""" if not isinstance(rules, Iterable): - raise TypeError("The rules must be an iterable, given {!r}".format(rules)) + raise TypeError(f"The rules must be an iterable, given {rules!r}") # "Index" the rules to normalize them and expand their dependencies. rule_index = RuleIndex.create(rules) diff --git a/src/python/pants/build_graph/build_file_aliases.py b/src/python/pants/build_graph/build_file_aliases.py index 0180b84fe8a..fac70343b27 100644 --- a/src/python/pants/build_graph/build_file_aliases.py +++ b/src/python/pants/build_graph/build_file_aliases.py @@ -107,7 +107,7 @@ def merge(self, other: BuildFileAliases) -> BuildFileAliases: :API: public """ if not isinstance(other, BuildFileAliases): - raise TypeError("Can only merge other BuildFileAliases, given {}".format(other)) + raise TypeError(f"Can only merge other BuildFileAliases, given {other}") def merge(*items): merged: dict = {} diff --git a/src/python/pants/goal/anonymous_telemetry.py b/src/python/pants/goal/anonymous_telemetry.py index 9abcf2f9b11..f6bc7a74485 100644 --- a/src/python/pants/goal/anonymous_telemetry.py +++ b/src/python/pants/goal/anonymous_telemetry.py @@ -147,16 +147,16 @@ def __call__( # This is copied from humbug code, to ensure that future changes to humbug # don't add tags that inadvertently violate our anonymity promise. system_tags = [ - "source:{}".format(reporter.name), - "os:{}".format(reporter.system_information.os), - "arch:{}".format(reporter.system_information.machine), - "python:{}".format(reporter.system_information.python_version_major), + f"source:{reporter.name}", + f"os:{reporter.system_information.os}", + f"arch:{reporter.system_information.machine}", + f"python:{reporter.system_information.python_version_major}", "python:{}.{}".format( reporter.system_information.python_version_major, reporter.system_information.python_version_minor, ), - "python:{}".format(reporter.system_information.python_version), - "session:{}".format(reporter.session_id), + f"python:{reporter.system_information.python_version}", + f"session:{reporter.session_id}", ] tags = ( system_tags