mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
[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:
committed by
PyTorch MergeBot
parent
470e2f61c3
commit
b2953f5643
@ -6,7 +6,7 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from typing import Callable
|
from collections.abc import Callable
|
||||||
|
|
||||||
from torch._inductor.utils import fresh_cache
|
from torch._inductor.utils import fresh_cache
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Callable, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from typing import Any, Callable
|
from collections.abc import Callable
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import time
|
import time
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Any, Callable, NamedTuple
|
from collections.abc import Callable
|
||||||
|
from typing import Any, NamedTuple
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from torch.autograd import functional
|
from torch.autograd import functional
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Callable, Optional, Union
|
from collections.abc import Callable
|
||||||
|
from typing import Optional, Union
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from torch import nn, Tensor
|
from torch import nn, Tensor
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import dataclasses
|
import dataclasses
|
||||||
from typing import Callable, Optional
|
from collections.abc import Callable
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
all_experiments: dict[str, Callable] = {}
|
all_experiments: dict[str, Callable] = {}
|
||||||
|
@ -9,8 +9,9 @@ import logging
|
|||||||
import time
|
import time
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from collections.abc import Callable
|
||||||
from dataclasses import asdict, dataclass, field
|
from dataclasses import asdict, dataclass, field
|
||||||
from typing import Any, Callable, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import itertools
|
import itertools
|
||||||
|
from collections.abc import Callable
|
||||||
from dataclasses import asdict, dataclass
|
from dataclasses import asdict, dataclass
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Callable, Union
|
from typing import Union
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
@ -3,10 +3,11 @@ import csv
|
|||||||
import itertools
|
import itertools
|
||||||
import random
|
import random
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from collections.abc import Callable
|
||||||
from contextlib import nullcontext
|
from contextlib import nullcontext
|
||||||
from dataclasses import asdict, dataclass
|
from dataclasses import asdict, dataclass
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import Callable, Optional, Union
|
from typing import Optional, Union
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import itertools
|
import itertools
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from collections.abc import Callable
|
||||||
from contextlib import nullcontext
|
from contextlib import nullcontext
|
||||||
from dataclasses import asdict, dataclass
|
from dataclasses import asdict, dataclass
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
@ -3,11 +3,11 @@ from __future__ import annotations
|
|||||||
import dis
|
import dis
|
||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
from typing import Any, Callable, Optional, TYPE_CHECKING, Union
|
from typing import Any, Optional, TYPE_CHECKING, Union
|
||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Sequence
|
from collections.abc import Callable, Sequence
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from torch.utils._pytree import tree_flatten, tree_map, tree_unflatten
|
from torch.utils._pytree import tree_flatten, tree_map, tree_unflatten
|
||||||
|
@ -5,7 +5,7 @@ Python implementation of function wrapping functionality for functorch.dim.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
from typing import Any, Callable, Optional
|
from typing import Any, Optional, TYPE_CHECKING
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from torch.utils._pytree import tree_map
|
from torch.utils._pytree import tree_map
|
||||||
@ -15,6 +15,10 @@ from ._enable_all_layers import EnableAllLayers
|
|||||||
from ._tensor_info import TensorInfo
|
from ._tensor_info import TensorInfo
|
||||||
|
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
|
||||||
def handle_from_tensor(tensor: torch.Tensor) -> torch.Tensor:
|
def handle_from_tensor(tensor: torch.Tensor) -> torch.Tensor:
|
||||||
"""Handle tensor conversion for torch function integration."""
|
"""Handle tensor conversion for torch function integration."""
|
||||||
return tensor
|
return tensor
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
# LICENSE file in the root directory of this source tree.
|
# LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
|
from collections.abc import Callable
|
||||||
from types import (
|
from types import (
|
||||||
BuiltinMethodType,
|
BuiltinMethodType,
|
||||||
FunctionType,
|
FunctionType,
|
||||||
@ -12,7 +13,7 @@ from types import (
|
|||||||
MethodDescriptorType,
|
MethodDescriptorType,
|
||||||
WrapperDescriptorType,
|
WrapperDescriptorType,
|
||||||
)
|
)
|
||||||
from typing import Any, Callable
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
FUNC_TYPES = (
|
FUNC_TYPES = (
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
from typing import Callable, TYPE_CHECKING, Union
|
from typing import TYPE_CHECKING, Union
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from functorch.dim import dims # noqa: F401
|
from functorch.dim import dims # noqa: F401
|
||||||
@ -16,7 +16,7 @@ from ._parsing import (
|
|||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Sequence
|
from collections.abc import Callable, Sequence
|
||||||
|
|
||||||
__all__ = ["rearrange"]
|
__all__ = ["rearrange"]
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import functools
|
import functools
|
||||||
from typing import Callable
|
from collections.abc import Callable
|
||||||
|
|
||||||
from torchgen.api.autograd import NativeFunctionWithDifferentiabilityInfo as NFWDI
|
from torchgen.api.autograd import NativeFunctionWithDifferentiabilityInfo as NFWDI
|
||||||
from torchgen.context import native_function_manager
|
from torchgen.context import native_function_manager
|
||||||
|
@ -36,7 +36,7 @@ from __future__ import annotations
|
|||||||
import itertools
|
import itertools
|
||||||
import re
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Callable, TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ from .gen_trace_type import should_trace
|
|||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Iterable, Sequence
|
from collections.abc import Callable, Iterable, Sequence
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from typing import Callable, TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from torchgen.api import cpp
|
from torchgen.api import cpp
|
||||||
from torchgen.api.autograd import (
|
from torchgen.api.autograd import (
|
||||||
@ -106,7 +106,7 @@ from .gen_trace_type import (
|
|||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
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
|
# We don't set or modify grad_fn on these methods. Generally, they return
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
# LICENSE file in the root directory of this source tree.
|
# LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Callable, Optional
|
from collections.abc import Callable
|
||||||
|
from typing import Any, Optional
|
||||||
|
|
||||||
|
|
||||||
class FlightRecorderLogger:
|
class FlightRecorderLogger:
|
||||||
|
@ -4,12 +4,16 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
from typing import Any, Callable, cast
|
from typing import Any, cast, TYPE_CHECKING
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
from urllib.request import Request, urlopen
|
from urllib.request import Request, urlopen
|
||||||
|
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
|
||||||
def gh_fetch_url_and_headers(
|
def gh_fetch_url_and_headers(
|
||||||
url: str,
|
url: str,
|
||||||
*,
|
*,
|
||||||
|
@ -5,7 +5,7 @@ import json
|
|||||||
import sys
|
import sys
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Callable, TYPE_CHECKING
|
from typing import Any, TYPE_CHECKING
|
||||||
|
|
||||||
|
|
||||||
_FILE = Path(__file__).absolute()
|
_FILE = Path(__file__).absolute()
|
||||||
@ -18,7 +18,7 @@ else:
|
|||||||
import _linter
|
import _linter
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Iterator, Sequence
|
from collections.abc import Callable, Iterator, Sequence
|
||||||
|
|
||||||
|
|
||||||
GRANDFATHER_LIST = _FILE.parent / "docstring_linter-grandfather.json"
|
GRANDFATHER_LIST = _FILE.parent / "docstring_linter-grandfather.json"
|
||||||
|
@ -22,11 +22,15 @@ import os
|
|||||||
import re
|
import re
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Callable, NamedTuple, Optional
|
from typing import Any, NamedTuple, Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from yaml import load
|
from yaml import load
|
||||||
|
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
|
||||||
# Safely load fast C Yaml loader/dumper if they are available
|
# Safely load fast C Yaml loader/dumper if they are available
|
||||||
try:
|
try:
|
||||||
from yaml import CSafeLoader as Loader
|
from yaml import CSafeLoader as Loader
|
||||||
|
@ -65,10 +65,11 @@ import textwrap
|
|||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from ast import literal_eval
|
from ast import literal_eval
|
||||||
|
from collections.abc import Callable
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from platform import system as platform_system
|
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:
|
if TYPE_CHECKING:
|
||||||
|
@ -7,10 +7,14 @@ import json
|
|||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Callable, cast
|
from typing import Any, cast, TYPE_CHECKING
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
|
||||||
REPO_ROOT = Path(__file__).resolve().parents[2]
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,13 +6,17 @@ import json
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from typing import Any, Callable, cast
|
from typing import Any, cast, TYPE_CHECKING
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
from urllib.request import Request, urlopen
|
from urllib.request import Request, urlopen
|
||||||
|
|
||||||
from tools.stats.upload_stats_lib import upload_to_s3
|
from tools.stats.upload_stats_lib import upload_to_s3
|
||||||
|
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
|
||||||
FILTER_OUT_USERS = {
|
FILTER_OUT_USERS = {
|
||||||
"pytorchmergebot",
|
"pytorchmergebot",
|
||||||
"facebook-github-bot",
|
"facebook-github-bot",
|
||||||
|
@ -9,12 +9,16 @@ import time
|
|||||||
import zipfile
|
import zipfile
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from pathlib import Path
|
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 boto3 # type: ignore[import]
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
|
||||||
PYTORCH_REPO = "https://api.github.com/repos/pytorch/pytorch"
|
PYTORCH_REPO = "https://api.github.com/repos/pytorch/pytorch"
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Callable
|
from typing import Any, TYPE_CHECKING
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
|
|
||||||
from tools.testing.target_determination.heuristics.interface import (
|
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
|
from tools.testing.test_run import TestRun
|
||||||
|
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
|
|
||||||
REPO_ROOT = Path(__file__).parents[3]
|
REPO_ROOT = Path(__file__).parents[3]
|
||||||
|
|
||||||
keyword_synonyms: dict[str, list[str]] = {
|
keyword_synonyms: dict[str, list[str]] = {
|
||||||
|
@ -4,7 +4,7 @@ import math
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
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.stats.import_test_stats import get_disabled_tests
|
||||||
from tools.testing.test_run import ShardedTest, TestRun
|
from tools.testing.test_run import ShardedTest, TestRun
|
||||||
@ -19,7 +19,7 @@ except ImportError:
|
|||||||
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Sequence
|
from collections.abc import Callable, Sequence
|
||||||
|
|
||||||
|
|
||||||
REPO_ROOT = Path(__file__).resolve().parents[2]
|
REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||||
|
Reference in New Issue
Block a user