add better error message for class method

Pull Request resolved: https://github.com/pytorch/pytorch/pull/78821

Approved by: https://github.com/ezyang
This commit is contained in:
samdow
2022-06-03 17:26:18 -04:00
committed by PyTorch MergeBot
parent d6be779ee0
commit 184e0065b3
4 changed files with 28 additions and 0 deletions

View File

@ -65,6 +65,9 @@ def enable_torch_dispatch_mode(mode, *, replace=None, ignore_preexisting=False)
def _wrap_torch_dispatch(f):
@functools.wraps(f)
def wrapped(self, *args, **kwargs):
if isinstance(f, classmethod):
raise RuntimeError("TorchDispatchMode's torch_dispatch function " +
"should be a normal method not a class method")
inner = getattr(self, "inner", None)
with enable_torch_dispatch_mode(inner):