mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Correctly handle OP_CONTAINS
(#158660)
CPython can fallback to `__iter__` if object doesn't implement `__contains__` Pull Request resolved: https://github.com/pytorch/pytorch/pull/158660 Approved by: https://github.com/zou3519
This commit is contained in:
committed by
PyTorch MergeBot
parent
7f649ed4f8
commit
b67f97c166
@ -666,6 +666,11 @@ class LocalGeneratorObjectVariable(VariableTracker):
|
||||
finally:
|
||||
counters["unimplemented"] |= counters["inline_call"]
|
||||
|
||||
def call_obj_hasattr(self, tx, name):
|
||||
if name in self.python_type().__dict__:
|
||||
return ConstantVariable.create(True)
|
||||
return ConstantVariable.create(False)
|
||||
|
||||
def has_unpack_var_sequence(self, tx):
|
||||
return False
|
||||
|
||||
@ -885,12 +890,6 @@ class LocalGeneratorObjectVariable(VariableTracker):
|
||||
else:
|
||||
raise_observed_exception(RuntimeError, tracer)
|
||||
return retval
|
||||
elif name == "__contains__":
|
||||
# The generator needs to be lazily consumed here to avoid unintended
|
||||
# side effects
|
||||
return variables.UserFunctionVariable(
|
||||
polyfills.generator___contains__
|
||||
).call_function(tx, [self, *args], {})
|
||||
|
||||
super().call_method(tx, name, args, kwargs)
|
||||
|
||||
|
Reference in New Issue
Block a user