From 3a7f438fc806af3b0275c57636c403b6fda2a5ca Mon Sep 17 00:00:00 2001 From: Kevin Kirsche Date: Tue, 2 Aug 2022 18:51:38 -0400 Subject: [PATCH] refactor: prefer f-strings to other concatenation styles --- scripts/create_baseline_stubs.py | 2 +- scripts/stubsabot.py | 4 ++-- tests/mypy_test.py | 4 ++-- tests/pyright_test.py | 2 +- tests/stubtest_stdlib.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/create_baseline_stubs.py b/scripts/create_baseline_stubs.py index 58b9534f1723..8ac0f8b054b3 100755 --- a/scripts/create_baseline_stubs.py +++ b/scripts/create_baseline_stubs.py @@ -59,7 +59,7 @@ def copy_stubs(src_base_dir: str, package: str, stub_dir: str) -> None: if os.path.isdir(src_dir): shutil.copytree(src_dir, os.path.join(stub_dir, package)) else: - src_file = os.path.join("out", package + ".pyi") + src_file = os.path.join("out", f"{package}.pyi") if not os.path.isfile(src_file): sys.exit("Error: Cannot find generated stubs") shutil.copy(src_file, stub_dir) diff --git a/scripts/stubsabot.py b/scripts/stubsabot.py index 99228867bcde..d83d3c8dae72 100644 --- a/scripts/stubsabot.py +++ b/scripts/stubsabot.py @@ -148,7 +148,7 @@ async def package_contains_py_typed(release_to_download: dict[str, Any], session def _check_spec(updated_spec: str, version: packaging.version.Version) -> str: - assert version in packaging.specifiers.SpecifierSet("==" + updated_spec), f"{version} not in {updated_spec}" + assert version in packaging.specifiers.SpecifierSet(f"=={updated_spec}"), f"{version} not in {updated_spec}" return updated_spec @@ -183,7 +183,7 @@ async def determine_action(stub_path: Path, session: aiohttp.ClientSession) -> U return NoUpdate(stub_info.distribution, "no longer updated") pypi_info = await fetch_pypi_info(stub_info.distribution, session) - spec = packaging.specifiers.SpecifierSet("==" + stub_info.version_spec) + spec = packaging.specifiers.SpecifierSet(f"=={stub_info.version_spec}") if pypi_info.version in spec: return NoUpdate(stub_info.distribution, "up to date") diff --git a/tests/mypy_test.py b/tests/mypy_test.py index d48d7715b7cc..30559844e2a6 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -147,7 +147,7 @@ def parse_versions(fname: StrPath) -> dict[str, tuple[MinVersion, MaxVersion]]: if line == "": continue m = _VERSION_LINE_RE.match(line) - assert m, "invalid VERSIONS line: " + line + assert m, f"invalid VERSIONS line: {line}" mod: str = m.group(1) min_version = parse_version(m.group(2)) max_version = parse_version(m.group(3)) if m.group(3) else (99, 99) @@ -160,7 +160,7 @@ def parse_versions(fname: StrPath) -> dict[str, tuple[MinVersion, MaxVersion]]: def parse_version(v_str: str) -> tuple[int, int]: m = _VERSION_RE.match(v_str) - assert m, "invalid version: " + v_str + assert m, f"invalid version: {v_str}" return int(m.group(1)), int(m.group(2)) diff --git a/tests/pyright_test.py b/tests/pyright_test.py index 7fe776361102..ada9351b7203 100755 --- a/tests/pyright_test.py +++ b/tests/pyright_test.py @@ -27,7 +27,7 @@ def main() -> None: print("error running npx; is Node.js installed?", file=sys.stderr) sys.exit(1) - command = [npx, "-p", "pyright@" + _PYRIGHT_VERSION, "pyright"] + sys.argv[1:] + command = [npx, "-p", f"pyright@{_PYRIGHT_VERSION}", "pyright"] + sys.argv[1:] ret = subprocess.run(command).returncode sys.exit(ret) diff --git a/tests/stubtest_stdlib.py b/tests/stubtest_stdlib.py index c7d1a1b029a1..bc083049999e 100755 --- a/tests/stubtest_stdlib.py +++ b/tests/stubtest_stdlib.py @@ -46,7 +46,7 @@ def run_stubtest(typeshed_dir: Path) -> int: "\nNB: stubtest output depends on the Python version (and system) it is run with. " "See README.md for more details.\n" "NB: We only check positional-only arg accuracy for Python 3.10.\n" - "\nCommand run was: {}\n".format(" ".join(cmd)), + f"\nCommand run was: {' '.join(cmd)}\n", file=sys.stderr, ) print("\n\n", file=sys.stderr)