| 685 | |
| 686 | #[pymethod] |
| 687 | fn add_note(self, note: PyStrRef, vm: &VirtualMachine) -> PyResult<()> { |
| 688 | let dict = self |
| 689 | .as_object() |
| 690 | .dict() |
| 691 | .ok_or_else(|| vm.new_attribute_error("Exception object has no __dict__"))?; |
| 692 | |
| 693 | let notes = if let Ok(notes) = dict.get_item("__notes__", vm) { |
| 694 | notes |
| 695 | } else { |
| 696 | let new_notes = vm.ctx.new_list(vec![]); |
| 697 | dict.set_item("__notes__", new_notes.clone().into(), vm)?; |
| 698 | new_notes.into() |
| 699 | }; |
| 700 | |
| 701 | let notes = notes |
| 702 | .downcast::<PyList>() |
| 703 | .map_err(|_| vm.new_type_error("__notes__ must be a list"))?; |
| 704 | |
| 705 | notes.borrow_vec_mut().push(note.into()); |
| 706 | Ok(()) |
| 707 | } |
| 708 | |
| 709 | #[pymethod] |
| 710 | fn __reduce__(self, vm: &VirtualMachine) -> PyTupleRef { |