diff --git a/crates/stdlib/src/json.rs b/crates/stdlib/src/json.rs index 3842e1ced..89a6f5636 100644 --- a/crates/stdlib/src/json.rs +++ b/crates/stdlib/src/json.rs @@ -881,7 +881,7 @@ mod _json { fn add_note(exc: PyBaseExceptionRef, note: Wtf8Buf, vm: &VirtualMachine) -> PyBaseExceptionRef { // `PyBaseException::add_note` is `pub`, so call it directly instead // of going through the generic attribute-lookup + call machinery. - let _ = exc.clone().add_note(vm.ctx.new_str(note), vm); + let _ = exc.add_note(vm.ctx.new_str(note), vm); exc } diff --git a/crates/stdlib/src/pickle.rs b/crates/stdlib/src/pickle.rs index 6673db6b6..713715b71 100644 --- a/crates/stdlib/src/pickle.rs +++ b/crates/stdlib/src/pickle.rs @@ -2133,7 +2133,7 @@ mod _pickle { // saving fn add_note(err: PyBaseExceptionRef, note: String, vm: &VirtualMachine) -> PyBaseExceptionRef { - let _ = err.clone().add_note(vm.ctx.new_str(note), vm); + let _ = err.add_note(vm.ctx.new_str(note), vm); err } diff --git a/crates/vm/src/builtins/dict.rs b/crates/vm/src/builtins/dict.rs index 216405b79..a56b5f3c9 100644 --- a/crates/vm/src/builtins/dict.rs +++ b/crates/vm/src/builtins/dict.rs @@ -585,6 +585,16 @@ impl Py { fn __getitem__(&self, key: PyObjectRef, vm: &VirtualMachine) -> PyResult { self.inner_getitem(&*key, vm) } + + fn __ror__(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult { + let other_dict = other.downcast::(); + if let Ok(other) = other_dict { + let other_cp = other.copy(); + other_cp.merge_dict(self, true, vm)?; + return Ok(other_cp.into_pyobject(vm)); + } + Ok(vm.ctx.not_implemented()) + } } #[pyclass] @@ -613,16 +623,6 @@ impl PyRef { self.merge_object(other, vm)?; Ok(self) } - - fn __ror__(self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult { - let other_dict: Result = other.downcast(); - if let Ok(other) = other_dict { - let other_cp = other.copy(); - other_cp.merge_dict(&self, true, vm)?; - return Ok(other_cp.into_pyobject(vm)); - } - Ok(vm.ctx.not_implemented()) - } } impl DefaultConstructor for PyDict {} diff --git a/crates/vm/src/exceptions.rs b/crates/vm/src/exceptions.rs index e199bb464..56a87980b 100644 --- a/crates/vm/src/exceptions.rs +++ b/crates/vm/src/exceptions.rs @@ -786,18 +786,9 @@ impl Py { Err(i) => PyStr::from(format!("({})", i.format(", "))).into_ref(&vm.ctx), } } -} - -#[pyclass] -impl PyRef { - #[pymethod] - fn with_traceback(self, tb: Option) -> Self { - *self.traceback.write() = tb; - self - } #[pymethod] - pub fn add_note(self, note: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { + pub fn add_note(&self, note: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { let dict = crate::builtins::object::object_get_dict(self.as_object().to_owned(), vm) .map_err(|_| vm.new_attribute_error("Exception object has no __dict__"))?; @@ -818,7 +809,7 @@ impl PyRef { } #[pymethod] - fn __reduce__(self, vm: &VirtualMachine) -> PyTupleRef { + fn __reduce__(&self, vm: &VirtualMachine) -> PyTupleRef { if let Some(dict) = self.as_object().dict().filter(|x| !x.is_empty()) { vm.new_tuple((self.class().to_owned(), self.args(), dict)) } else { @@ -827,7 +818,7 @@ impl PyRef { } #[pymethod] - fn __setstate__(self, state: PyObjectRef, vm: &VirtualMachine) -> PyResult { + fn __setstate__(&self, state: PyObjectRef, vm: &VirtualMachine) -> PyResult { if !vm.is_none(&state) { let dict = state .downcast::() @@ -845,6 +836,15 @@ impl PyRef { } } +#[pyclass] +impl PyRef { + #[pymethod] + fn with_traceback(self, tb: Option) -> Self { + *self.traceback.write() = tb; + self + } +} + impl Constructor for PyBaseException { type Args = FuncArgs;