Revert "[Dynamo] Check for __bool__ attribute before accessing it (#120943)"

This reverts commit dd7aeedb72f8a96d0f168308292e0d41c095f01b.

Reverted https://github.com/pytorch/pytorch/pull/120943 on behalf of https://github.com/DanilBaibak due to Broken trunk ([comment](https://github.com/pytorch/pytorch/pull/120943#issuecomment-2063098295))
This commit is contained in:
PyTorch MergeBot
2024-04-18 06:34:32 +00:00
parent 8ff85b42f9
commit 6e86a40694
71 changed files with 4 additions and 8 deletions

View File

@ -409,14 +409,10 @@ def generic_jump(truth_fn: typing.Callable[[object], bool], push: bool):
self.push(value)
self.jump(inst)
elif isinstance(value, UserDefinedObjectVariable):
x = None
has_bool = value.call_hasattr(self, "__bool__")
if has_bool.is_python_constant() and has_bool.as_python_constant():
x = value.var_getattr(self, "__bool__")
else:
has_len = value.call_hasattr(self, "__len__")
if has_len.is_python_constant() and has_len.as_python_constant():
x = value.var_getattr(self, "__len__")
x = value.var_getattr(self, "__bool__")
# if __bool__ is missing, trying __len__ to infer a truth value.
if isinstance(x, GetAttrVariable):
x = value.var_getattr(self, "__len__")
# __bool__ or __len__ is function
if isinstance(x, UserMethodVariable):