Skip to content

Commit

Permalink
Prefer f-strings instead of str.format
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyNotHugo committed Feb 18, 2025
1 parent ebbdca9 commit 2478337
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
8 changes: 3 additions & 5 deletions piptools/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ def resolve(self, max_rounds: int = 10) -> set[InstallRequirement]:
raise RuntimeError(
"No stable configuration of concrete packages "
"could be found for the given constraints after "
"{max_rounds} rounds of resolving.\n"
"This is likely a bug.".format(max_rounds=max_rounds)
f"{max_rounds} rounds of resolving.\n"
"This is likely a bug."
)

log.debug("")
Expand Down Expand Up @@ -429,9 +429,7 @@ def get_best_match(self, ireq: InstallRequirement) -> InstallRequirement:

# Format the best match
log.debug(
"found candidate {} (constraint was {})".format(
format_requirement(best_match), format_specifier(ireq)
)
f"found candidate {format_requirement(best_match)} (constraint was {format_specifier(ireq)})"
)
best_match.comes_from = ireq.comes_from
if hasattr(ireq, "_source_ireqs"):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,14 +1058,14 @@ def test_generate_hashes_with_editable(pip_conf, runner):
fp.write(f"-e {small_fake_package_url}\n")
out = runner.invoke(cli, ["--no-annotate", "--generate-hashes"])
expected = (
"-e {}\n"
f"-e {small_fake_package_url}\n"
"small-fake-a==0.1 \\\n"
" --hash=sha256:5e6071ee6e4c59e0d0408d366f"
"e9b66781d2cf01be9a6e19a2433bb3c5336330\n"
"small-fake-b==0.1 \\\n"
" --hash=sha256:acdba8f8b8a816213c30d5310c"
"3fe296c0107b16ed452062f7f994a5672e3b3f\n"
).format(small_fake_package_url)
)
assert out.exit_code == 0
assert expected in out.stderr

Expand Down
4 changes: 1 addition & 3 deletions tests/test_cli_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ def test_pip_install_flags(run, cli_flags, expected_install_flags, runner):

call_args = [call[0][0] for call in run.call_args_list]
called_install_options = [args[6:] for args in call_args if args[3] == "install"]
assert called_install_options == [expected_install_flags], "Called args: {}".format(
call_args
)
assert called_install_options == [expected_install_flags], f"Called args: {call_args}"


@pytest.mark.parametrize(
Expand Down

0 comments on commit 2478337

Please sign in to comment.