[9/N] Apply ruff UP035 rule (#165515)

This is follow-up of #165214 to continue applying ruff UP035 rule to the code base.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/165515
Approved by: https://github.com/Lucaskabela
This commit is contained in:
Yuanyuan Chen
2025-10-17 00:09:49 +00:00
committed by PyTorch MergeBot
parent 470e2f61c3
commit b2953f5643
27 changed files with 72 additions and 33 deletions

View File

@ -1,5 +1,5 @@
import functools
from typing import Callable
from collections.abc import Callable
from torchgen.api.autograd import NativeFunctionWithDifferentiabilityInfo as NFWDI
from torchgen.context import native_function_manager

View File

@ -36,7 +36,7 @@ from __future__ import annotations
import itertools
import re
from collections import defaultdict
from typing import Callable, TYPE_CHECKING
from typing import TYPE_CHECKING
import yaml
@ -77,7 +77,7 @@ from .gen_trace_type import should_trace
if TYPE_CHECKING:
from collections.abc import Iterable, Sequence
from collections.abc import Callable, Iterable, Sequence
#

View File

@ -29,7 +29,7 @@
from __future__ import annotations
import re
from typing import Callable, TYPE_CHECKING
from typing import TYPE_CHECKING
from torchgen.api import cpp
from torchgen.api.autograd import (
@ -106,7 +106,7 @@ from .gen_trace_type import (
if TYPE_CHECKING:
from collections.abc import Sequence
from collections.abc import Callable, Sequence
# We don't set or modify grad_fn on these methods. Generally, they return

View File

@ -5,7 +5,8 @@
# LICENSE file in the root directory of this source tree.
import logging
from typing import Any, Callable, Optional
from collections.abc import Callable
from typing import Any, Optional
class FlightRecorderLogger:

View File

@ -4,12 +4,16 @@ from __future__ import annotations
import json
import os
from typing import Any, Callable, cast
from typing import Any, cast, TYPE_CHECKING
from urllib.error import HTTPError
from urllib.parse import quote
from urllib.request import Request, urlopen
if TYPE_CHECKING:
from collections.abc import Callable
def gh_fetch_url_and_headers(
url: str,
*,

View File

@ -5,7 +5,7 @@ import json
import sys
from functools import cached_property
from pathlib import Path
from typing import Any, Callable, TYPE_CHECKING
from typing import Any, TYPE_CHECKING
_FILE = Path(__file__).absolute()
@ -18,7 +18,7 @@ else:
import _linter
if TYPE_CHECKING:
from collections.abc import Iterator, Sequence
from collections.abc import Callable, Iterator, Sequence
GRANDFATHER_LIST = _FILE.parent / "docstring_linter-grandfather.json"

View File

@ -22,11 +22,15 @@ import os
import re
from enum import Enum
from pathlib import Path
from typing import Any, Callable, NamedTuple, Optional
from typing import Any, NamedTuple, Optional, TYPE_CHECKING
from yaml import load
if TYPE_CHECKING:
from collections.abc import Callable
# Safely load fast C Yaml loader/dumper if they are available
try:
from yaml import CSafeLoader as Loader

View File

@ -65,10 +65,11 @@ import textwrap
import time
import uuid
from ast import literal_eval
from collections.abc import Callable
from datetime import datetime
from pathlib import Path
from platform import system as platform_system
from typing import Any, Callable, cast, NamedTuple, TYPE_CHECKING, TypeVar
from typing import Any, cast, NamedTuple, TYPE_CHECKING, TypeVar
if TYPE_CHECKING:

View File

@ -7,10 +7,14 @@ import json
import os
import shutil
from pathlib import Path
from typing import Any, Callable, cast
from typing import Any, cast, TYPE_CHECKING
from urllib.request import urlopen
if TYPE_CHECKING:
from collections.abc import Callable
REPO_ROOT = Path(__file__).resolve().parents[2]

View File

@ -6,13 +6,17 @@ import json
import os
import time
import urllib.parse
from typing import Any, Callable, cast
from typing import Any, cast, TYPE_CHECKING
from urllib.error import HTTPError
from urllib.request import Request, urlopen
from tools.stats.upload_stats_lib import upload_to_s3
if TYPE_CHECKING:
from collections.abc import Callable
FILTER_OUT_USERS = {
"pytorchmergebot",
"facebook-github-bot",

View File

@ -9,12 +9,16 @@ import time
import zipfile
from functools import lru_cache
from pathlib import Path
from typing import Any, Callable, cast, Optional
from typing import Any, cast, Optional, TYPE_CHECKING
import boto3 # type: ignore[import]
import requests
if TYPE_CHECKING:
from collections.abc import Callable
PYTORCH_REPO = "https://api.github.com/repos/pytorch/pytorch"

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from collections import defaultdict
from functools import lru_cache
from pathlib import Path
from typing import Any, Callable
from typing import Any, TYPE_CHECKING
from warnings import warn
from tools.testing.target_determination.heuristics.interface import (
@ -17,6 +17,10 @@ from tools.testing.target_determination.heuristics.utils import (
from tools.testing.test_run import TestRun
if TYPE_CHECKING:
from collections.abc import Callable
REPO_ROOT = Path(__file__).parents[3]
keyword_synonyms: dict[str, list[str]] = {

View File

@ -4,7 +4,7 @@ import math
import os
import subprocess
from pathlib import Path
from typing import Callable, TYPE_CHECKING
from typing import TYPE_CHECKING
from tools.stats.import_test_stats import get_disabled_tests
from tools.testing.test_run import ShardedTest, TestRun
@ -19,7 +19,7 @@ except ImportError:
if TYPE_CHECKING:
from collections.abc import Sequence
from collections.abc import Callable, Sequence
REPO_ROOT = Path(__file__).resolve().parents[2]