[4/N] Apply ruff UP035 rule to python code (#164206)

Follows #164104

Pull Request resolved: https://github.com/pytorch/pytorch/pull/164206
Approved by: https://github.com/albanD
This commit is contained in:
Yuanyuan Chen 2025-10-01 19:05:49 +00:00 committed by PyTorch MergeBot
parent 8c590cab9d
commit 315ffdc1e4
65 changed files with 158 additions and 105 deletions

View File

@ -22,9 +22,9 @@ import platform
import sys import sys
import textwrap import textwrap
import threading import threading
from collections.abc import Callable as _Callable
from typing import ( from typing import (
Any as _Any, Any as _Any,
Callable as _Callable,
get_origin as _get_origin, get_origin as _get_origin,
Optional as _Optional, Optional as _Optional,
overload as _overload, overload as _overload,

View File

@ -4,7 +4,8 @@ circular dependencies.
""" """
import functools import functools
from typing import Callable, Optional, overload, TypeVar, Union from collections.abc import Callable
from typing import Optional, overload, TypeVar, Union
from typing_extensions import ParamSpec from typing_extensions import ParamSpec

View File

@ -14,16 +14,7 @@ from abc import abstractmethod
from collections import defaultdict from collections import defaultdict
from contextlib import contextmanager from contextlib import contextmanager
from dataclasses import dataclass from dataclasses import dataclass
from typing import ( from typing import Any, Generic, NamedTuple, Optional, TYPE_CHECKING, TypeVar, Union
Any,
Callable,
Generic,
NamedTuple,
Optional,
TYPE_CHECKING,
TypeVar,
Union,
)
import torch import torch
from torch.utils import _pytree as pytree from torch.utils import _pytree as pytree
@ -36,7 +27,7 @@ log = logging.getLogger(__name__)
if TYPE_CHECKING: if TYPE_CHECKING:
from collections.abc import Generator, Iterator from collections.abc import Callable, Generator, Iterator
from types import CodeType from types import CodeType
import sympy import sympy

View File

@ -1,9 +1,9 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
import math import math
from collections.abc import Sequence from collections.abc import Callable, Sequence
from enum import Enum from enum import Enum
from functools import wraps from functools import wraps
from typing import Callable, Optional, TypeVar, Union from typing import Optional, TypeVar, Union
from typing_extensions import ParamSpec from typing_extensions import ParamSpec
import torch import torch

View File

@ -6,19 +6,19 @@ import importlib
import inspect import inspect
import sys import sys
import types import types
from collections.abc import Iterator from collections.abc import Callable, Iterator
from functools import cached_property from functools import cached_property
from typing import ( from typing import (
Any, Any,
Callable,
ClassVar, ClassVar,
Concatenate,
final, final,
Generic, Generic,
Optional, Optional,
TYPE_CHECKING, TYPE_CHECKING,
Union, Union,
) )
from typing_extensions import Concatenate, ParamSpec, TypeVar from typing_extensions import ParamSpec, TypeVar
import torch import torch
import torch.utils._pytree as pytree import torch.utils._pytree as pytree

View File

@ -4,10 +4,11 @@ import enum
import functools import functools
import warnings import warnings
from collections import OrderedDict from collections import OrderedDict
from collections.abc import Callable
from copy import deepcopy from copy import deepcopy
from numbers import Number from numbers import Number
from typing import Any, Callable, cast, Optional, TypeVar, Union from typing import Any, cast, Concatenate, Optional, TypeVar, Union
from typing_extensions import Concatenate, ParamSpec from typing_extensions import ParamSpec
import torch import torch
import torch._C as _C import torch._C as _C

View File

@ -7,8 +7,9 @@ import sys
import traceback import traceback
import warnings import warnings
from collections import defaultdict from collections import defaultdict
from collections.abc import Callable
from types import ModuleType from types import ModuleType
from typing import Any, Callable, Generic, Optional, TYPE_CHECKING from typing import Any, Generic, Optional, TYPE_CHECKING
from typing_extensions import deprecated, ParamSpec from typing_extensions import deprecated, ParamSpec
import torch import torch

View File

@ -5,7 +5,8 @@ import os
import sys import sys
import tempfile import tempfile
import typing_extensions import typing_extensions
from typing import Any, Callable, Optional, TypeVar from collections.abc import Callable
from typing import Any, Optional, TypeVar
from typing_extensions import ParamSpec from typing_extensions import ParamSpec
import torch import torch

View File

@ -1,6 +1,7 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
import functools import functools
from typing import Any, Callable, Optional, Union from collections.abc import Callable
from typing import Any, Optional, Union
from typing_extensions import deprecated from typing_extensions import deprecated
import torch import torch

View File

@ -27,6 +27,7 @@ import warnings
from _codecs import encode from _codecs import encode
from collections import Counter, OrderedDict from collections import Counter, OrderedDict
from collections.abc import Callable
from pickle import ( from pickle import (
APPEND, APPEND,
APPENDS, APPENDS,
@ -68,7 +69,7 @@ from pickle import (
) )
from struct import unpack from struct import unpack
from sys import maxsize from sys import maxsize
from typing import Any, Callable, Union from typing import Any, Union
import torch import torch
from torch._utils import _sparse_tensors_to_validate, IMPORT_MAPPING, NAME_MAPPING from torch._utils import _sparse_tensors_to_validate, IMPORT_MAPPING, NAME_MAPPING

View File

@ -1,5 +1,6 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
from typing import Any, Callable, Optional, Union from collections.abc import Callable
from typing import Any, Optional, Union
import torch import torch
import torch.ao.nn.quantized as nnq import torch.ao.nn.quantized as nnq

View File

@ -1,5 +1,6 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
from typing import Callable, Optional, Union from collections.abc import Callable
from typing import Optional, Union
import torch import torch

View File

@ -1,7 +1,8 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
from collections.abc import Callable
from itertools import chain from itertools import chain
from operator import getitem from operator import getitem
from typing import Callable, Optional, Union from typing import Optional, Union
import torch import torch
import torch.nn.functional as F import torch.nn.functional as F

View File

@ -4,7 +4,8 @@ Collection of conversion functions for linear / conv2d structured pruning
Also contains utilities for bias propagation Also contains utilities for bias propagation
""" """
from typing import Callable, cast, Optional from collections.abc import Callable
from typing import cast, Optional
import torch import torch
from torch import nn, Tensor from torch import nn, Tensor

View File

@ -1,5 +1,6 @@
import warnings import warnings
from typing import Callable, Union from collections.abc import Callable
from typing import Union
from torch.ao.pruning.sparsifier.base_sparsifier import BaseSparsifier from torch.ao.pruning.sparsifier.base_sparsifier import BaseSparsifier

View File

@ -1,7 +1,8 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
import operator import operator
from collections.abc import Callable
from functools import reduce from functools import reduce
from typing import Callable, Optional, Union from typing import Optional, Union
import torch import torch
import torch.nn.functional as F import torch.nn.functional as F

View File

@ -1,7 +1,8 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
import sys import sys
from typing import Callable, Optional, Union from collections.abc import Callable
from typing import Optional, Union
import torch import torch
from torch import Tensor from torch import Tensor

View File

@ -2,7 +2,8 @@
import copy import copy
import operator import operator
from collections import namedtuple from collections import namedtuple
from typing import Callable, Union from collections.abc import Callable
from typing import Union
import torch import torch
import torch.ao.nn.intrinsic as nni import torch.ao.nn.intrinsic as nni

View File

@ -3,12 +3,14 @@ from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from enum import Enum from enum import Enum
from typing import Any, Callable, Optional, TYPE_CHECKING, Union from typing import Any, Optional, TYPE_CHECKING, Union
import torch import torch
if TYPE_CHECKING: if TYPE_CHECKING:
from collections.abc import Callable
from torch.ao.quantization.utils import Pattern from torch.ao.quantization.utils import Pattern

View File

@ -1,5 +1,6 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
from typing import Any, Callable, Union from collections.abc import Callable
from typing import Any, Union
import torch import torch
import torch.nn as nn import torch.nn as nn

View File

@ -1,6 +1,7 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
import copy import copy
from typing import Any, Callable, Optional, Union from collections.abc import Callable
from typing import Any, Optional, Union
import torch import torch
from torch.ao.quantization.experimental.adaround_fake_quantize import ( from torch.ao.quantization.experimental.adaround_fake_quantize import (

View File

@ -1,4 +1,5 @@
from typing import Any, Callable from collections.abc import Callable
from typing import Any
import torch import torch
from torch import Tensor from torch import Tensor

View File

@ -1,6 +1,7 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
import itertools import itertools
from typing import Any, Callable, Optional, Union from collections.abc import Callable
from typing import Any, Optional, Union
import torch.ao.nn.intrinsic as nni import torch.ao.nn.intrinsic as nni
import torch.nn as nn import torch.nn as nn

View File

@ -1,8 +1,8 @@
import copy import copy
import logging import logging
from collections.abc import Sequence from collections.abc import Callable, Sequence
from dataclasses import dataclass from dataclasses import dataclass
from typing import Callable, Optional from typing import Optional
import torch import torch
from torch.ao.ns.fx.utils import compute_sqnr from torch.ao.ns.fx.utils import compute_sqnr

View File

@ -2,8 +2,8 @@
import itertools import itertools
import operator import operator
from collections import OrderedDict from collections import OrderedDict
from collections.abc import Sequence from collections.abc import Callable, Sequence
from typing import Any, Callable, Optional, Union from typing import Any, Optional, Union
import torch import torch
from torch.export import ExportedProgram from torch.export import ExportedProgram

View File

@ -3,7 +3,8 @@ import copy
import dataclasses import dataclasses
import itertools import itertools
import operator import operator
from typing import Any, Callable, Optional, TYPE_CHECKING from collections.abc import Callable
from typing import Any, Optional, TYPE_CHECKING
import torch import torch
import torch.nn.functional as F import torch.nn.functional as F

View File

@ -1,7 +1,8 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
from collections.abc import Callable
from dataclasses import dataclass from dataclasses import dataclass
from functools import partial from functools import partial
from typing import Any, Callable, Optional from typing import Any, Optional
import torch import torch
from torch._export.utils import _disable_aten_to_metadata_assertions from torch._export.utils import _disable_aten_to_metadata_assertions

View File

@ -1,7 +1,8 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
import operator import operator
import types import types
from typing import Any, Callable, Optional, Union from collections.abc import Callable
from typing import Any, Optional, Union
import torch import torch
import torch.ao.quantization.pt2e._affine_quantization # noqa: F401 import torch.ao.quantization.pt2e._affine_quantization # noqa: F401

View File

@ -2,7 +2,7 @@
from __future__ import annotations from __future__ import annotations
from collections import OrderedDict from collections import OrderedDict
from typing import Any, Callable, Union from typing import Any, TYPE_CHECKING, Union
import torch import torch
@ -26,6 +26,10 @@ from .qconfig import (
) )
if TYPE_CHECKING:
from collections.abc import Callable
__all__ = [ __all__ = [
"get_default_qconfig_mapping", "get_default_qconfig_mapping",
"get_default_qat_qconfig_mapping", "get_default_qat_qconfig_mapping",

View File

@ -1,5 +1,6 @@
import copy import copy
from typing import Any, Callable, Optional, Union from collections.abc import Callable
from typing import Any, Optional, Union
import torch import torch
import torch.ao.nn as ao_nn import torch.ao.nn as ao_nn

View File

@ -1,7 +1,8 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from collections.abc import Callable
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import Annotated, Callable, Optional, Union from typing import Annotated, Optional, Union
import torch import torch
from torch import Tensor from torch import Tensor

View File

@ -1,4 +1,5 @@
from typing import Callable, Optional from collections.abc import Callable
from typing import Optional
from torch.ao.quantization.pt2e.utils import _is_sym_size_node from torch.ao.quantization.pt2e.utils import _is_sym_size_node
from torch.ao.quantization.quantizer.quantizer import ( from torch.ao.quantization.quantizer.quantizer import (

View File

@ -3,10 +3,9 @@ import functools
import itertools import itertools
import operator import operator
import warnings import warnings
from collections.abc import Sequence from collections.abc import Callable, Sequence
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any, Callable, Optional, TYPE_CHECKING, Union from typing import Any, Optional, TYPE_CHECKING, TypeAlias, Union
from typing_extensions import TypeAlias
import torch import torch
import torch.nn.functional as F import torch.nn.functional as F

View File

@ -4,7 +4,7 @@ from __future__ import annotations
import copy import copy
import functools import functools
import typing_extensions import typing_extensions
from typing import Any, Callable, Optional, TYPE_CHECKING from typing import Any, Optional, TYPE_CHECKING
import torch import torch
import torch._dynamo as torchdynamo import torch._dynamo as torchdynamo
@ -35,6 +35,8 @@ from torch.fx._compatibility import compatibility
if TYPE_CHECKING: if TYPE_CHECKING:
from collections.abc import Callable
from torch.ao.quantization.qconfig import _ObserverOrFakeQuantizeConstructor from torch.ao.quantization.qconfig import _ObserverOrFakeQuantizeConstructor
from torch.fx import Node from torch.fx import Node

View File

@ -1,8 +1,9 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
import itertools import itertools
import typing import typing
from collections.abc import Callable
from dataclasses import dataclass from dataclasses import dataclass
from typing import Callable, NamedTuple, Optional from typing import NamedTuple, Optional
import torch import torch
import torch.nn.functional as F import torch.nn.functional as F

View File

@ -7,8 +7,9 @@ import functools
import sys import sys
import warnings import warnings
from collections import OrderedDict from collections import OrderedDict
from collections.abc import Callable
from inspect import getfullargspec, signature from inspect import getfullargspec, signature
from typing import Any, Callable, Optional, Union from typing import Any, Optional, Union
import torch import torch
from torch.ao.quantization.quant_type import QuantType from torch.ao.quantization.quant_type import QuantType

View File

@ -4,8 +4,9 @@ import inspect
import itertools import itertools
import warnings import warnings
from collections import OrderedDict from collections import OrderedDict
from typing import Any, Callable, Optional, TypeVar from collections.abc import Callable
from typing_extensions import Concatenate, deprecated, ParamSpec from typing import Any, Concatenate, Optional, TypeVar
from typing_extensions import deprecated, ParamSpec
import torch import torch
import torch._C as _C import torch._C as _C

View File

@ -2,9 +2,9 @@
import collections import collections
import functools import functools
import warnings import warnings
from collections.abc import Iterable from collections.abc import Callable, Iterable
from itertools import product from itertools import product
from typing import Callable, Optional, Union from typing import Optional, Union
from typing_extensions import deprecated from typing_extensions import deprecated
import torch import torch

View File

@ -4,18 +4,24 @@ import functools
import logging import logging
import threading import threading
from collections import defaultdict, deque from collections import defaultdict, deque
from collections.abc import Generator, Iterable, Iterator, MutableMapping, Sequence from collections.abc import (
Callable,
Generator,
Iterable,
Iterator,
MutableMapping,
Sequence,
)
from typing import ( from typing import (
Any, Any,
Callable,
cast, cast,
Literal, Literal,
NamedTuple, NamedTuple,
Optional, Optional,
TYPE_CHECKING, TYPE_CHECKING,
TypeAlias,
Union, Union,
) )
from typing_extensions import TypeAlias
from weakref import WeakKeyDictionary, WeakValueDictionary from weakref import WeakKeyDictionary, WeakValueDictionary
import torch import torch

View File

@ -17,8 +17,9 @@ import sys
import threading import threading
import traceback import traceback
import warnings import warnings
from collections.abc import Callable
from functools import lru_cache from functools import lru_cache
from typing import Any, Callable, cast, NewType, Optional, TYPE_CHECKING, Union from typing import Any, cast, NewType, Optional, TYPE_CHECKING, Union
import torch import torch
import torch._C import torch._C

View File

@ -1,4 +1,4 @@
from typing import Callable from collections.abc import Callable
from torch._utils import CallbackRegistry from torch._utils import CallbackRegistry

View File

@ -1,6 +1,7 @@
import os import os
import sys import sys
from typing import Callable, Optional from collections.abc import Callable
from typing import Optional
import torch import torch
from torch.types import Storage from torch.types import Storage

View File

@ -2,8 +2,9 @@ from __future__ import annotations
import gc import gc
import typing import typing
from typing import Callable, Optional, overload, TYPE_CHECKING, Union from collections.abc import Callable
from typing_extensions import ParamSpec, Self, TypeAlias, TypeVar from typing import Optional, overload, TYPE_CHECKING, TypeAlias, Union
from typing_extensions import ParamSpec, Self, TypeVar
import torch import torch
from torch import Tensor from torch import Tensor

View File

@ -1,6 +1,6 @@
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
import re import re
from typing import Callable from collections.abc import Callable
import torch import torch
from torch import Tensor from torch import Tensor

View File

@ -6,8 +6,8 @@ import re
import sys import sys
import traceback import traceback
import weakref import weakref
from collections.abc import Sequence from collections.abc import Callable, Sequence
from typing import Any, Callable, Optional, overload, TYPE_CHECKING, TypeVar, Union from typing import Any, Optional, overload, TYPE_CHECKING, TypeVar, Union
from typing_extensions import deprecated, ParamSpec from typing_extensions import deprecated, ParamSpec
import torch import torch

View File

@ -14,7 +14,7 @@ __all__ = [
"ONNXProgram", "ONNXProgram",
] ]
from typing import Any, Callable, TYPE_CHECKING from typing import Any, TYPE_CHECKING
import torch import torch
from torch._C import _onnx as _C_onnx from torch._C import _onnx as _C_onnx
@ -45,7 +45,7 @@ from .errors import OnnxExporterError
if TYPE_CHECKING: if TYPE_CHECKING:
import os import os
from collections.abc import Collection, Mapping, Sequence from collections.abc import Callable, Collection, Mapping, Sequence
# Set namespace for exposed private names # Set namespace for exposed private names
ONNXProgram.__module__ = "torch.onnx" ONNXProgram.__module__ = "torch.onnx"

View File

@ -9,7 +9,7 @@ import dataclasses
import datetime import datetime
import logging import logging
import pathlib import pathlib
from typing import Any, Callable, TYPE_CHECKING from typing import Any, TYPE_CHECKING
import torch import torch
from torch.onnx import _flags from torch.onnx import _flags
@ -17,6 +17,7 @@ from torch.onnx import _flags
if TYPE_CHECKING: if TYPE_CHECKING:
import os import os
from collections.abc import Callable
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -7,8 +7,8 @@ from __future__ import annotations
import io import io
import logging import logging
import warnings import warnings
from collections.abc import Mapping, Sequence from collections.abc import Callable, Mapping, Sequence
from typing import Any, Callable, TYPE_CHECKING from typing import Any, TYPE_CHECKING
import torch import torch
from torch.onnx import _constants as onnx_constants from torch.onnx import _constants as onnx_constants

View File

@ -12,8 +12,8 @@ import pathlib
import textwrap import textwrap
import traceback import traceback
import typing import typing
from collections.abc import Mapping, Sequence from collections.abc import Callable, Mapping, Sequence
from typing import Any, Callable, Literal from typing import Any, Literal
import onnxscript import onnxscript
import onnxscript.evaluator import onnxscript.evaluator

View File

@ -2,13 +2,15 @@
from __future__ import annotations from __future__ import annotations
import itertools import itertools
from typing import Callable, TYPE_CHECKING from typing import TYPE_CHECKING
import torch import torch
import torch._ops import torch._ops
if TYPE_CHECKING: if TYPE_CHECKING:
from collections.abc import Callable
from torch.onnx._internal.exporter import _registration from torch.onnx._internal.exporter import _registration

View File

@ -2,8 +2,8 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
from collections.abc import Sequence from collections.abc import Callable, Sequence
from typing import Any, Callable from typing import Any
from onnxscript import ir from onnxscript import ir

View File

@ -3,10 +3,14 @@
from __future__ import annotations from __future__ import annotations
import functools import functools
from typing import Callable, TypeVar from typing import TYPE_CHECKING, TypeVar
from typing_extensions import ParamSpec from typing_extensions import ParamSpec
if TYPE_CHECKING:
from collections.abc import Callable
_is_onnx_exporting = False _is_onnx_exporting = False
# Use ParamSpec to preserve parameter types instead of erasing to Any # Use ParamSpec to preserve parameter types instead of erasing to Any

View File

@ -5,10 +5,14 @@ from __future__ import annotations
import multiprocessing import multiprocessing
import os import os
import warnings import warnings
from typing import Any, Callable, TypeVar, TypeVarTuple, Union, Unpack from typing import Any, TYPE_CHECKING, TypeVar, TypeVarTuple, Union, Unpack
from typing_extensions import ParamSpec from typing_extensions import ParamSpec
if TYPE_CHECKING:
from collections.abc import Callable
_P = ParamSpec("_P") _P = ParamSpec("_P")
_R = TypeVar("_R") _R = TypeVar("_R")
_Ts = TypeVarTuple("_Ts") _Ts = TypeVarTuple("_Ts")

View File

@ -13,8 +13,8 @@ import os
import tempfile import tempfile
import textwrap import textwrap
import warnings import warnings
from collections.abc import Sequence from collections.abc import Callable, Sequence
from typing import Any, Callable, TYPE_CHECKING from typing import Any, TYPE_CHECKING
import torch import torch
from torch.onnx._internal._lazy_import import onnx, onnxscript_apis, onnxscript_ir as ir from torch.onnx._internal._lazy_import import onnx, onnxscript_apis, onnxscript_ir as ir

View File

@ -18,8 +18,8 @@ import logging
import math import math
import operator import operator
import types import types
from typing import Callable, Literal, Union from collections.abc import Callable
from typing_extensions import TypeAlias from typing import Literal, TypeAlias, Union
import torch import torch
import torch._ops import torch._ops

View File

@ -8,8 +8,8 @@ from __future__ import annotations
__all__ = ["onnx_impl", "get_torchlib_ops"] __all__ = ["onnx_impl", "get_torchlib_ops"]
import logging import logging
from collections.abc import Sequence from collections.abc import Callable, Sequence
from typing import Any, Callable, TypeVar from typing import Any, TypeVar
from typing_extensions import ParamSpec from typing_extensions import ParamSpec
import onnxscript import onnxscript

View File

@ -2,8 +2,8 @@
"""Module for handling symbolic function registration.""" """Module for handling symbolic function registration."""
import warnings import warnings
from collections.abc import Collection, Sequence from collections.abc import Callable, Collection, Sequence
from typing import Callable, Generic, Optional, TypeVar, Union from typing import Generic, Optional, TypeVar, Union
from typing_extensions import ParamSpec from typing_extensions import ParamSpec
from torch.onnx import _constants, errors from torch.onnx import _constants, errors

View File

@ -103,8 +103,14 @@ import math
import sys import sys
import typing import typing
import warnings import warnings
from typing import Any, Callable, Literal, NoReturn, TypeVar as _TypeVar from typing import (
from typing_extensions import Concatenate as _Concatenate, ParamSpec as _ParamSpec Any,
Concatenate as _Concatenate,
Literal,
NoReturn,
TypeVar as _TypeVar,
)
from typing_extensions import ParamSpec as _ParamSpec
import torch import torch
import torch._C._onnx as _C_onnx import torch._C._onnx as _C_onnx
@ -115,7 +121,7 @@ from torch.onnx._internal.torchscript_exporter._globals import GLOBALS
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from collections.abc import Sequence from collections.abc import Callable, Sequence
from torch.types import Number from torch.types import Number

View File

@ -14,7 +14,7 @@ import functools
import math import math
import sys import sys
import warnings import warnings
from typing import Callable, TYPE_CHECKING from typing import TYPE_CHECKING
from typing_extensions import deprecated from typing_extensions import deprecated
import torch import torch
@ -33,7 +33,7 @@ from torch.onnx._internal.torchscript_exporter._globals import GLOBALS
if TYPE_CHECKING: if TYPE_CHECKING:
from collections.abc import Sequence from collections.abc import Callable, Sequence
from torch.types import Number from torch.types import Number

View File

@ -62,7 +62,7 @@ import inspect
import re import re
import typing import typing
import warnings import warnings
from typing import Any, Callable, cast from typing import Any, cast
from typing_extensions import deprecated from typing_extensions import deprecated
import torch import torch
@ -80,7 +80,7 @@ from torch.onnx._internal.torchscript_exporter._globals import GLOBALS
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from collections.abc import Collection, Mapping, Sequence from collections.abc import Callable, Collection, Mapping, Sequence
# TODO(justinchuby): Remove dependency to this global variable from constant_fold.cpp # TODO(justinchuby): Remove dependency to this global variable from constant_fold.cpp

View File

@ -17,14 +17,14 @@ __all__ = [
] ]
from typing import Callable, TYPE_CHECKING from typing import TYPE_CHECKING
import torch import torch
from torch.onnx.ops import _impl, _symbolic_impl from torch.onnx.ops import _impl, _symbolic_impl
if TYPE_CHECKING: if TYPE_CHECKING:
from collections.abc import Sequence from collections.abc import Callable, Sequence
# https://github.com/onnx/onnx/blob/f542e1f06699ea7e1db5f62af53355b64338c723/onnx/onnx.proto#L597 # https://github.com/onnx/onnx/blob/f542e1f06699ea7e1db5f62af53355b64338c723/onnx/onnx.proto#L597

View File

@ -1,6 +1,7 @@
# flake8: noqa: B950 # flake8: noqa: B950
import math import math
from typing import Callable, Optional, TypeVar from collections.abc import Callable
from typing import Optional, TypeVar
from typing_extensions import ParamSpec from typing_extensions import ParamSpec
import torch import torch

View File

@ -27,9 +27,9 @@ import contextlib
import functools import functools
import types import types
import warnings import warnings
from collections.abc import Iterable from collections.abc import Callable, Iterable
from functools import wraps from functools import wraps
from typing import Any, Callable, Optional, TypeVar from typing import Any, Optional, TypeVar
from typing_extensions import ParamSpec from typing_extensions import ParamSpec
import torch import torch

View File

@ -13,10 +13,11 @@ import tarfile
import tempfile import tempfile
import threading import threading
import warnings import warnings
from collections.abc import Callable
from contextlib import closing, contextmanager from contextlib import closing, contextmanager
from enum import Enum from enum import Enum
from typing import Any, Callable, cast, Generic, IO, Optional, TypeVar, Union from typing import Any, cast, Generic, IO, Optional, TypeAlias, TypeVar, Union
from typing_extensions import TypeAlias, TypeIs from typing_extensions import TypeIs
import torch import torch
import torch._weights_only_unpickler as _weights_only_unpickler import torch._weights_only_unpickler as _weights_only_unpickler

View File

@ -12,8 +12,8 @@ from builtins import ( # noqa: F401
str as _str, str as _str,
) )
from collections.abc import Sequence from collections.abc import Sequence
from typing import Any, IO, TYPE_CHECKING, Union from typing import Any, IO, TYPE_CHECKING, TypeAlias, Union
from typing_extensions import Self, TypeAlias from typing_extensions import Self
# `as` imports have better static analysis support than assignment `ExposedType: TypeAlias = HiddenType` # `as` imports have better static analysis support than assignment `ExposedType: TypeAlias = HiddenType`
from torch import ( # noqa: F401 from torch import ( # noqa: F401