From 1da2601173f92bafd0858751386c55babb7aaeff Mon Sep 17 00:00:00 2001 From: Yuji Kanagawa Date: Tue, 18 Feb 2020 12:31:45 +0900 Subject: [PATCH] Apply suggestions from davidhewitt's review Co-Authored-By: David Hewitt <1939362+davidhewitt@users.noreply.github.com> --- guide/src/class.md | 6 +++--- pyo3-derive-backend/src/module.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/guide/src/class.md b/guide/src/class.md index 3d0d40af5d1..02a6abc38f9 100644 --- a/guide/src/class.md +++ b/guide/src/class.md @@ -116,7 +116,7 @@ from Rust code (e.g., for testing it). `PyCell` is always allocated in the Python heap, so we don't have the ownership of it. We can get `&PyCell`, not `PyCell`. -Thus, to mutate data behind `&PyCell` safely, we employs +Thus, to mutate data behind `&PyCell` safely, we employ the [Interior Mutability Pattern](https://doc.rust-lang.org/book/ch15-05-interior-mutability.html) like [std::cell::RefCell](https://doc.rust-lang.org/std/cell/struct.RefCell.html). @@ -145,13 +145,13 @@ let obj = PyCell::new(py, MyClass { num: 3, debug: true }).unwrap(); { let obj_ref = obj.borrow(); // Get PyRef assert_eq!(obj_ref.num, 3); - // You cannot get PyRefMut unless all PyRef drop + // You cannot get PyRefMut unless all PyRefs are dropped assert!(obj.try_borrow_mut().is_err()); } { let mut obj_mut = obj.borrow_mut(); // Get PyRefMut obj_mut.num = 5; - // You cannot get PyRef unless all PyRefMut drop + // You cannot get any other refs until the PyRefMut is dropped assert!(obj.try_borrow().is_err()); } // You can convert `&PyCell` to Python object diff --git a/pyo3-derive-backend/src/module.rs b/pyo3-derive-backend/src/module.rs index 05046fdd0d3..4293dbf3235 100644 --- a/pyo3-derive-backend/src/module.rs +++ b/pyo3-derive-backend/src/module.rs @@ -57,7 +57,7 @@ pub fn process_functions_in_module(func: &mut syn::ItemFn) { fn wrap_fn_argument<'a>(cap: &'a syn::PatType, name: &'a Ident) -> method::FnArg<'a> { let (mutability, by_ref, ident) = match *cap.pat { syn::Pat::Ident(ref patid) => (&patid.mutability, &patid.by_ref, &patid.ident), - _ => panic!("unsupported argument: {:?}", cap.pat), + _ => return syn::Error::new_spanned(cap.pat, "Unsupported argument"), }; let py = crate::utils::if_type_is_python(&cap.ty);