[list] Implement list.remove (#156242)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/156242
Approved by: https://github.com/Skylion007, https://github.com/zou3519
ghstack dependencies: #153969, #156148
This commit is contained in:
Guilherme Leobas
2025-07-05 15:54:45 -03:00
committed by PyTorch MergeBot
parent e49acfc5c5
commit c1d69d5dd5
2 changed files with 7 additions and 1 deletions

View File

@ -509,6 +509,13 @@ class CommonListMethodsVariable(BaseListVariable):
self.items.reverse()
tx.output.side_effects.mutation(self)
return ConstantVariable.create(None)
elif name == "remove" and self.is_mutable():
if len(args) != 1 or kwargs:
raise_args_mismatch(tx, name)
idx = self.call_method(tx, "index", args, kwargs)
self.call_method(tx, "pop", [idx], {})
return ConstantVariable.create(None)
else:
return super().call_method(tx, name, args, kwargs)