mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[torchbind] fix error message when attr is a real tensor. (#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: https://github.com/pytorch/pytorch/pull/151944 Approved by: https://github.com/yushangdi
This commit is contained in:
committed by
PyTorch MergeBot
parent
9344da8bd1
commit
5f63789dd2
@ -155,7 +155,7 @@ def maybe_to_fake_obj(
|
||||
|
||||
for name in x._method_names(): # type: ignore[attr-defined]
|
||||
attr = getattr(fake_x, name, None)
|
||||
if attr:
|
||||
if attr is not None:
|
||||
if not callable(attr):
|
||||
raise RuntimeError(f"Expect {name} to be a callable but got {attr}.")
|
||||
|
||||
|
Reference in New Issue
Block a user