[3/N] Apply py39 ruff fixes (#142115)

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/142115
Approved by: https://github.com/ezyang
This commit is contained in:
cyy
2024-12-11 17:50:07 +00:00
committed by PyTorch MergeBot
parent f7e621c3ce
commit 82aaf64422
31 changed files with 137 additions and 91 deletions

View File

@ -7,7 +7,7 @@ import subprocess
import sys
import tempfile
import urllib.request
from typing import cast, List, NoReturn, Optional
from typing import cast, NoReturn, Optional
def parse_arguments() -> argparse.Namespace:
@ -74,7 +74,7 @@ def get_pytorch_path() -> str:
try:
import torch
torch_paths: List[str] = cast(List[str], torch.__path__)
torch_paths: list[str] = cast(list[str], torch.__path__)
torch_path: str = torch_paths[0]
parent_path: str = os.path.dirname(torch_path)
print(f"PyTorch is installed at: {torch_path}")
@ -114,9 +114,10 @@ def download_patch(pr_number: int, repo_url: str, download_dir: str) -> str:
patch_file = os.path.join(download_dir, f"pr-{pr_number}.patch")
print(f"Downloading PR #{pr_number} patch from {patch_url}...")
try:
with urllib.request.urlopen(patch_url) as response, open(
patch_file, "wb"
) as out_file:
with (
urllib.request.urlopen(patch_url) as response,
open(patch_file, "wb") as out_file,
):
shutil.copyfileobj(response, out_file)
if not os.path.isfile(patch_file):
print(f"Failed to download patch for PR #{pr_number}")