Use lock in both index and remove operation.
@@ -300,8 +300,8 @@ impl PyList {
if let Some(index) = index.into() {
// defer delete out of borrow
- let mut elements = self.borrow_vec_mut();
- Ok((index < elements.len()).then(move || elements.remove(index)))
+ let is_inside_range = index < self.borrow_vec().len();
+ Ok(is_inside_range.then(|| self.borrow_vec_mut().remove(index)))
} else {
Err(vm.new_value_error(format!("'{}' is not in list", needle.str(vm)?)))
}
