From aa72cb1dcf02288a7037453139507003ebbda5df Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 19 May 2022 14:16:53 +0100 Subject: [PATCH] Run pyupgrade on the `tests` directory (#7880) --- tests/mypy_test.py | 10 +++++----- tests/pytype_test.py | 10 +++++----- tests/stubtest_stdlib.py | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/mypy_test.py b/tests/mypy_test.py index 5f19512f3..79d8ab8f0 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -143,14 +143,14 @@ def add_configuration(configurations: list[MypyDistConf], distribution: str) -> assert isinstance(mypy_tests_conf, dict), "mypy-tests should be a section" for section_name, mypy_section in mypy_tests_conf.items(): - assert isinstance(mypy_section, dict), "{} should be a section".format(section_name) + assert isinstance(mypy_section, dict), f"{section_name} should be a section" module_name = mypy_section.get("module_name") - assert module_name is not None, "{} should have a module_name key".format(section_name) - assert isinstance(module_name, str), "{} should be a key-value pair".format(section_name) + assert module_name is not None, f"{section_name} should have a module_name key" + assert isinstance(module_name, str), f"{section_name} should be a key-value pair" values = mypy_section.get("values") - assert values is not None, "{} should have a values section".format(section_name) + assert values is not None, f"{section_name} should have a values section" assert isinstance(values, dict), "values should be a section" configurations.append(MypyDistConf(module_name, values.copy())) @@ -176,7 +176,7 @@ def run_mypy( for dist_conf in configurations: temp.write("[mypy-%s]\n" % dist_conf.module_name) for k, v in dist_conf.values.items(): - temp.write("{} = {}\n".format(k, v)) + temp.write(f"{k} = {v}\n") temp.flush() flags = get_mypy_flags(args, major, minor, temp.name, custom_typeshed=custom_typeshed) diff --git a/tests/pytype_test.py b/tests/pytype_test.py index a7bb36466..0f807683e 100755 --- a/tests/pytype_test.py +++ b/tests/pytype_test.py @@ -104,13 +104,13 @@ def _get_module_name(filename: str) -> str: def _is_version(path: str, version: str) -> bool: - return any("{}{}{}".format(d, os.path.sep, version) in path for d in TYPESHED_SUBDIRS) + return any(f"{d}{os.path.sep}{version}" in path for d in TYPESHED_SUBDIRS) def check_subdirs_discoverable(subdir_paths: list[str]) -> None: for p in subdir_paths: if not os.path.isdir(p): - raise SystemExit("Cannot find typeshed subdir at {} (specify parent dir via --typeshed-location)".format(p)) + raise SystemExit(f"Cannot find typeshed subdir at {p} (specify parent dir via --typeshed-location)") def determine_files_to_test(*, typeshed_location: str, paths: Sequence[str]) -> list[str]: @@ -159,11 +159,11 @@ def run_all_tests(*, files_to_test: Sequence[str], typeshed_location: str, print runs = i + 1 if runs % 25 == 0: - print(" {:3d}/{:d} with {:3d} errors".format(runs, total_tests, errors)) + print(f" {runs:3d}/{total_tests:d} with {errors:3d} errors") - print("Ran pytype with {:d} pyis, got {:d} errors.".format(total_tests, errors)) + print(f"Ran pytype with {total_tests:d} pyis, got {errors:d} errors.") for f, v, err in bad: - print("{} ({}): {}".format(f, v, err)) + print(f"{f} ({v}): {err}") if errors: raise SystemExit("\nRun again with --print-stderr to get the full stacktrace.") diff --git a/tests/stubtest_stdlib.py b/tests/stubtest_stdlib.py index 6caf22cd1..b7915b2a0 100755 --- a/tests/stubtest_stdlib.py +++ b/tests/stubtest_stdlib.py @@ -14,9 +14,9 @@ from pathlib import Path def run_stubtest(typeshed_dir: Path) -> int: allowlist_dir = typeshed_dir / "tests" / "stubtest_allowlists" - version_allowlist = "py{}{}.txt".format(sys.version_info.major, sys.version_info.minor) - platform_allowlist = "{}.txt".format(sys.platform) - combined_allowlist = "{}-py{}{}.txt".format(sys.platform, sys.version_info.major, sys.version_info.minor) + version_allowlist = f"py{sys.version_info.major}{sys.version_info.minor}.txt" + platform_allowlist = f"{sys.platform}.txt" + combined_allowlist = f"{sys.platform}-py{sys.version_info.major}{sys.version_info.minor}.txt" cmd = [ sys.executable,