Revert "[BE]: Type previously untyped decorators (#153726)"

This reverts commit b7d08defe9cfe1595ff680f845b39f5e03a89555.

Reverted https://github.com/pytorch/pytorch/pull/153726 on behalf of https://github.com/yangw-dev due to sorry, it seems like your pr failed typecheck error internally, [D75155486](https://www.internalfb.com/diff/D75155486) ([comment](https://github.com/pytorch/pytorch/pull/153726#issuecomment-2901911114))
This commit is contained in:
PyTorch MergeBot
2025-05-22 16:49:08 +00:00
parent a15550b776
commit 7d3dab6b90
10 changed files with 45 additions and 58 deletions

View File

@ -31,10 +31,8 @@ from typing import ( # noqa: UP035, F401 # (Dict, List, Tuple) imported by tor
List,
Optional,
Tuple,
TypeVar,
Union,
)
from typing_extensions import ParamSpec
import torch
@ -49,9 +47,6 @@ from torch._sources import fake_range, get_source_lines_and_file, parse_def
from torch.futures import Future
_P = ParamSpec("_P")
_R = TypeVar("_R")
IS_PY310_PLUS: Final[bool] = sys.version_info >= (3, 10)
BuiltinUnionType: Union[type, tuple[type, ...]]
@ -670,7 +665,7 @@ class FunctionModifiers:
_DROP = "_drop (function is fully ignored, declaration can be unscriptable)"
def export(fn: Callable[_P, _R]) -> Callable[_P, _R]:
def export(fn):
"""
This decorator indicates that a method on an ``nn.Module`` is used as an entry point into a
:class:`ScriptModule` and should be compiled.
@ -712,11 +707,11 @@ def export(fn: Callable[_P, _R]) -> Callable[_P, _R]:
# any compiled methods and wasn't decorated with `@torch.jit.export`
m = torch.jit.script(MyModule())
"""
fn._torchscript_modifier = FunctionModifiers.EXPORT # type:ignore[attr-defined]
fn._torchscript_modifier = FunctionModifiers.EXPORT
return fn
def unused(fn: Callable[_P, _R]) -> Callable[_P, _R]:
def unused(fn):
"""
This decorator indicates to the compiler that a function or method should
be ignored and replaced with the raising of an exception. This allows you
@ -769,7 +764,7 @@ def unused(fn: Callable[_P, _R]) -> Callable[_P, _R]:
return prop
fn._torchscript_modifier = FunctionModifiers.UNUSED # type: ignore[attr-defined]
fn._torchscript_modifier = FunctionModifiers.UNUSED
return fn
@ -887,13 +882,13 @@ def ignore(drop=False, **kwargs):
return decorator
def _drop(fn: Callable[_P, _R]) -> Callable[_P, _R]:
fn._torchscript_modifier = FunctionModifiers._DROP # type: ignore[attr-defined]
def _drop(fn):
fn._torchscript_modifier = FunctionModifiers._DROP
return fn
def _copy_to_script_wrapper(fn: Callable[_P, _R]) -> Callable[_P, _R]:
fn._torchscript_modifier = FunctionModifiers.COPY_TO_SCRIPT_WRAPPER # type: ignore[attr-defined]
def _copy_to_script_wrapper(fn):
fn._torchscript_modifier = FunctionModifiers.COPY_TO_SCRIPT_WRAPPER
return fn