Skip to content

Commit 5f63789

Browse files
ydwu4pytorchmergebot
authored andcommitted
[torchbind] fix error message when attr is a real tensor. (pytorch#151944)
Summary: Previously, when attr is defined, "if attr" will try to evaluate the data of attr, which is not intendended and we get a ugly error stack if the attr is not evaluable (like a fake tensor) before the callable(attr) check. Test Plan: Existing tests. Reviewed By: yushangdi, henryoier Differential Revision: D73460905 Pull Request resolved: pytorch#151944 Approved by: https://github.com/yushangdi
1 parent 9344da8 commit 5f63789

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

torch/_library/fake_class_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def maybe_to_fake_obj(
155155

156156
for name in x._method_names(): # type: ignore[attr-defined]
157157
attr = getattr(fake_x, name, None)
158-
if attr:
158+
if attr is not None:
159159
if not callable(attr):
160160
raise RuntimeError(f"Expect {name} to be a callable but got {attr}.")
161161

0 commit comments

Comments
 (0)