Skip to content

Code improvements from new Ruff checks #11498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def main() -> None:
strict_params = _get_strict_params(path)
print(f"\nRunning Pyright ({'stricter' if strict_params else 'base' } configs) for Python {python_version}...")
pyright_result = subprocess.run(
[sys.executable, "tests/pyright_test.py", path, "--pythonversion", python_version] + strict_params,
[sys.executable, "tests/pyright_test.py", path, "--pythonversion", python_version, *strict_params],
stderr=subprocess.PIPE,
text=True,
)
Expand Down
4 changes: 2 additions & 2 deletions scripts/stubsabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def from_cmd_arg(cls, cmd_arg: str) -> ActionLevel:
try:
return cls[cmd_arg]
except KeyError:
raise argparse.ArgumentTypeError(f'Argument must be one of "{list(cls.__members__)}"')
raise argparse.ArgumentTypeError(f'Argument must be one of "{list(cls.__members__)}"') from None

nothing = 0, "make no changes"
local = 1, "make changes that affect local repo"
Expand Down Expand Up @@ -516,7 +516,7 @@ async def determine_action(stub_path: Path, session: aiohttp.ClientSession) -> U
)


@functools.lru_cache()
@functools.lru_cache
def get_origin_owner() -> str:
output = subprocess.check_output(["git", "remote", "get-url", "origin"], text=True).strip()
match = re.match(r"([email protected]:|https://github.com/)(?P<owner>[^/]+)/(?P<repo>[^/\s]+)", output)
Expand Down
4 changes: 1 addition & 3 deletions test_cases/stdlib/typing/check_all.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from __future__ import annotations

# pyright: reportWildcardImportFromLibrary=false

"""
This tests that star imports work when using "all += " syntax.
"""
from __future__ import annotations

import sys
from typing import * # noqa: F403
Expand Down
2 changes: 1 addition & 1 deletion tests/mypy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/pytype_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/regr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions tests/stubtest_third_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/typecheck_typeshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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})",
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]


# ====================================================================
Expand Down