Run pyupgrade on the tests directory (#7880)

This commit is contained in:
Alex Waygood
2022-05-19 14:16:53 +01:00
committed by GitHub
parent 6f2c53f3b0
commit aa72cb1dcf
3 changed files with 13 additions and 13 deletions

View File

@@ -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)

View File

@@ -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.")

View File

@@ -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,