Code improvements from new Ruff checks (#11498)

This commit is contained in:
Avasam
2024-02-29 01:30:18 -05:00
committed by GitHub
parent c75ecf0bca
commit da69247514
9 changed files with 12 additions and 14 deletions

View File

@@ -279,7 +279,7 @@ def run_mypy(
flags.append("--no-site-packages")
mypy_args = [*flags, *map(str, files)]
mypy_command = [venv_info.python_exe, "-m", "mypy"] + mypy_args
mypy_command = [venv_info.python_exe, "-m", "mypy", *mypy_args]
if args.verbose:
print(colored(f"running {' '.join(mypy_command)}", "blue"))
result = subprocess.run(mypy_command, capture_output=True, text=True, env=env_vars)

View File

@@ -210,7 +210,7 @@ def run_all_tests(*, files_to_test: Sequence[str], print_stderr: bool, dry_run:
missing_modules = get_missing_modules(files_to_test)
print("Testing files with pytype...")
for i, f in enumerate(files_to_test):
python_version = "{0.major}.{0.minor}".format(sys.version_info)
python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
if dry_run:
stderr = None
else:

View File

@@ -211,7 +211,7 @@ def run_testcases(
continue
flags.append(str(path))
mypy_command = [python_exe, "-m", "mypy"] + flags
mypy_command = [python_exe, "-m", "mypy", *flags]
if verbosity is Verbosity.VERBOSE:
description = f"{package.name}/{version}/{platform}"
msg = f"{description}: {mypy_command=}\n"

View File

@@ -53,7 +53,7 @@ def run_stubtest(
# If tool.stubtest.stubtest_requirements exists, run "pip install" on it.
if stubtest_settings.stubtest_requirements:
pip_cmd = [pip_exe, "install"] + stubtest_settings.stubtest_requirements
pip_cmd = [pip_exe, "install", *stubtest_settings.stubtest_requirements]
try:
subprocess.run(pip_cmd, check=True, capture_output=True)
except subprocess.CalledProcessError as e:
@@ -67,7 +67,7 @@ def run_stubtest(
# TODO: Maybe find a way to cache these in CI
dists_to_install = [dist_req, get_mypy_req()]
dists_to_install.extend(requirements.external_pkgs) # Internal requirements are added to MYPYPATH
pip_cmd = [pip_exe, "install"] + dists_to_install
pip_cmd = [pip_exe, "install", *dists_to_install]
try:
subprocess.run(pip_cmd, check=True, capture_output=True)
except subprocess.CalledProcessError as e:
@@ -134,7 +134,7 @@ def run_stubtest(
print(file=sys.stderr)
else:
print(f"Re-running stubtest with --generate-allowlist.\nAdd the following to {allowlist_path}:", file=sys.stderr)
ret = subprocess.run(stubtest_cmd + ["--generate-allowlist"], env=stubtest_env, capture_output=True)
ret = subprocess.run([*stubtest_cmd, "--generate-allowlist"], env=stubtest_env, capture_output=True)
print_command_output(ret)
return False

View File

@@ -21,7 +21,7 @@ EMPTY: list[str] = []
parser = argparse.ArgumentParser(description="Run mypy on typeshed's own code in the `scripts` and `tests` directories.")
parser.add_argument(
"dir",
choices=DIRECTORIES_TO_TEST + (EMPTY,),
choices=(*DIRECTORIES_TO_TEST, EMPTY),
nargs="*",
action="extend",
help=f"Test only these top-level typeshed directories (defaults to {DIRECTORIES_TO_TEST!r})",

View File

@@ -119,7 +119,7 @@ def get_all_testcase_directories() -> list[PackageInfo]:
potential_testcase_dir = testcase_dir_from_package_name(package_name)
if potential_testcase_dir.is_dir():
testcase_directories.append(PackageInfo(package_name, potential_testcase_dir))
return [PackageInfo("stdlib", Path("test_cases"))] + sorted(testcase_directories)
return [PackageInfo("stdlib", Path("test_cases")), *sorted(testcase_directories)]
# ====================================================================