Skip to content
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

[internal] use f-strings instead of str.format() #13584

Merged
merged 1 commit into from
Nov 11, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/bin/daemon_pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/bin/remote_pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 4 additions & 6 deletions src/python/pants/build_graph/build_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/build_graph/build_file_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
12 changes: 6 additions & 6 deletions src/python/pants/goal/anonymous_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down