[BE] mypy: disallow untyped decorators (#131428)

Untyped decorators strip the types from their decorated function so even if the underlying function is fully typed then callers to it don't get any benefit from type annotations.

Step 1 - Enable the error and override in all the offending files.

#131429

Pull Request resolved: https://github.com/pytorch/pytorch/pull/131428
Approved by: https://github.com/justinchuby, https://github.com/oulgen
This commit is contained in:
Aaron Orenstein 2024-07-23 14:48:25 -07:00 committed by PyTorch MergeBot
parent e3ca4e79e1
commit 5a0068cc69
135 changed files with 135 additions and 0 deletions

View File

@ -12,6 +12,7 @@ show_error_codes = True
show_column_numbers = True
check_untyped_defs = True
disallow_untyped_defs = True
disallow_untyped_decorators = True
follow_imports = normal
local_partial_types = True
enable_error_code = possibly-undefined

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
# Owner(s): ["module: tests"]

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import functools
import itertools

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import inspect
from typing import Callable, Dict, List, Optional, Tuple

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import functools
from collections import defaultdict

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
from __future__ import annotations
import collections

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import collections
import contextlib

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import functools
from typing import Dict

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import copy
import dataclasses

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
# NOTE: We allow Dynamo to see this file (via torch/_dynamo/trace_rules.py) so that it can
# trace through functorch transforms.

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import torch.nn as nn
from torch._functorch.utils import exposed_in

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from collections import Counter
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import warnings
from typing import Any, Dict, List, Optional, Tuple, Union

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from enum import Enum
from typing import Any, Dict, Optional, Tuple, Union

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from typing import Callable, Tuple, Union

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import torch

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from __future__ import annotations

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import contextlib
import functools

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import functools
import logging

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from __future__ import annotations

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import functools
import itertools

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import copy
import functools

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from typing import List, Optional, Tuple, Union

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from __future__ import annotations

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import functools
import itertools

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import functools
from typing import List, Optional

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
"""
# Inductor Pattern Matcher

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import triton
import triton.language as tl

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: disallow-untyped-defs
from __future__ import annotations

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import inspect
import logging

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import inspect
import typing

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import math
from enum import Enum

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import builtins
import collections

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import torch
import torch._prims_common as utils

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
import math
from typing import Iterable, List, Literal, NamedTuple, Optional, Sequence, Tuple, Union

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from functools import partial

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import math
from functools import wraps

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import math
from typing import Optional, Union

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
from __future__ import annotations
import atexit

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import numbers
import warnings

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import torch
import torch.nn as nn

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from collections.abc import Iterable
import torch

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from typing import Optional

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import enum
import operator

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from typing import Tuple

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
"""Implements modules used to perform fake quantization."""

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import math
from typing import Optional, Tuple

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
"""
This module implements observers which are used to collect statistics about

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import itertools
import operator

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from typing import List, Optional

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from contextlib import contextmanager, nullcontext
from typing import Any, ContextManager, Dict, Optional, Tuple

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
from typing import List, NamedTuple, Optional, Tuple, Union
import torch

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import functools
import logging

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import functools
from typing import Any, cast, Iterable, List, NoReturn, Optional, Union

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
from typing import Callable, Iterable, Optional, Union
from typing_extensions import deprecated

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import weakref
from typing import Any, cast, Dict, Iterable, List, NoReturn, Optional, Set, Tuple

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
# Copyright (c) Meta Platforms, Inc. and affiliates
from typing import cast, List, Optional, Sequence, Tuple

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
import socket
import uuid

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
# Copyright (c) Meta Platforms, Inc. and affiliates
import inspect

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# Copyright (c) Meta Platforms, Inc. and affiliates
# implement matrix related ops for distributed tensor
from typing import List

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
# Copyright (c) Meta Platforms, Inc. and affiliates
# implement matrix related ops for distributed tensor

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# Copyright (c) Meta Platforms, Inc. and affiliates
# implement matrix related ops for distributed tensor

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
# Copyright (c) Meta Platforms, Inc. and affiliates
import math

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# Copyright (c) Meta Platforms, Inc. and affiliates
# implement matrix related ops for distributed tensor

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# Copyright (c) Meta Platforms, Inc. and affiliates
import torch
from torch.distributed._tensor._op_schema import (

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
# Copyright (c) Meta Platforms, Inc. and affiliates
from typing import cast, List, Optional, Sequence, Tuple

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
# Copyright (c) Meta Platforms, Inc. and affiliates
from dataclasses import dataclass

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import os
import warnings

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import inspect
import os

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import logging
from collections import defaultdict

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import collections

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import dataclasses
import functools

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import contextlib
import copy

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from contextlib import contextmanager

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import builtins
import copy

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from functools import reduce
import torch

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import torch
import operator

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import ast
import inspect

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from collections import defaultdict
from .node import Node, Argument, Target, map_arg, _type_repr, _get_qualified_name

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import contextlib
import copy

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from .graph_module import GraphModule
from ._lazy_graph_module import _make_graph_module

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# Nodes represent a definition of a value in our graph of operators.
from typing import TYPE_CHECKING, Union, Callable, Any, Tuple, List, Optional, Dict, Set
from ._compatibility import compatibility

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import torch
import inspect

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from typing import Any, Dict, List, NamedTuple, Optional

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import inspect
import logging

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import abc
import typing as t

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
from torch.fx.graph_module import GraphModule
from typing import Any, Callable, Dict, List, Tuple, Type
import torch

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import logging
import operator

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import inspect
from typing import Any, Callable, Dict, List, Optional, Set

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import copy
from dataclasses import dataclass, field

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import argparse
import copy

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from typing import List, Tuple, Union, Dict, Any, Set, Mapping, Optional
import collections

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from typing import Dict, Tuple

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import copy
from queue import SimpleQueue

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
from dataclasses import dataclass, field
from torch.fx.graph import Graph

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
from .graph_module import GraphModule
from .graph import Graph
from .node import Node

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import traceback
from contextlib import contextmanager

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import torch
from torch import Tensor

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-decorators
# mypy: allow-untyped-defs
import warnings
from typing import Any, List, Optional, Tuple, TYPE_CHECKING, Union

Some files were not shown because too many files have changed in this diff Show More