Skip to content

Commit 1da2601

Browse files
kngwyudavidhewitt
andauthored
Apply suggestions from davidhewitt's review
Co-Authored-By: David Hewitt <[email protected]>
1 parent daca04e commit 1da2601

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

guide/src/class.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ from Rust code (e.g., for testing it).
116116
`PyCell<T: PyClass>` is always allocated in the Python heap, so we don't have the ownership of it.
117117
We can get `&PyCell<T>`, not `PyCell<T>`.
118118

119-
Thus, to mutate data behind `&PyCell` safely, we employs
119+
Thus, to mutate data behind `&PyCell` safely, we employ the
120120
[Interior Mutability Pattern](https://doc.rust-lang.org/book/ch15-05-interior-mutability.html)
121121
like [std::cell::RefCell](https://doc.rust-lang.org/std/cell/struct.RefCell.html).
122122

@@ -145,13 +145,13 @@ let obj = PyCell::new(py, MyClass { num: 3, debug: true }).unwrap();
145145
{
146146
let obj_ref = obj.borrow(); // Get PyRef
147147
assert_eq!(obj_ref.num, 3);
148-
// You cannot get PyRefMut unless all PyRef drop
148+
// You cannot get PyRefMut unless all PyRefs are dropped
149149
assert!(obj.try_borrow_mut().is_err());
150150
}
151151
{
152152
let mut obj_mut = obj.borrow_mut(); // Get PyRefMut
153153
obj_mut.num = 5;
154-
// You cannot get PyRef unless all PyRefMut drop
154+
// You cannot get any other refs until the PyRefMut is dropped
155155
assert!(obj.try_borrow().is_err());
156156
}
157157
// You can convert `&PyCell` to Python object

pyo3-derive-backend/src/module.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn process_functions_in_module(func: &mut syn::ItemFn) {
5757
fn wrap_fn_argument<'a>(cap: &'a syn::PatType, name: &'a Ident) -> method::FnArg<'a> {
5858
let (mutability, by_ref, ident) = match *cap.pat {
5959
syn::Pat::Ident(ref patid) => (&patid.mutability, &patid.by_ref, &patid.ident),
60-
_ => panic!("unsupported argument: {:?}", cap.pat),
60+
_ => return syn::Error::new_spanned(cap.pat, "Unsupported argument"),
6161
};
6262

6363
let py = crate::utils::if_type_is_python(&cap.ty);

0 commit comments

Comments
 (0)