Skip to content

Commit fab135c

Browse files
authored
Merge pull request #1747 from PyO3/pycell_doc
pycell: proofread docstrings
2 parents 8e7737d + edd5ca9 commit fab135c

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

src/pycell.rs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ pub struct PyCellBase<T> {
2929

3030
unsafe impl<T, U> PyLayout<T> for PyCellBase<U> where U: PySizedLayout<T> {}
3131

32-
/// `PyCell` is the container type for [`PyClass`](../pyclass/trait.PyClass.html).
32+
/// `PyCell` is the container type for [`PyClass`](../pyclass/trait.PyClass.html) values.
3333
///
34-
/// From Python side, `PyCell<T>` is the concrete layout of `T: PyClass` in the Python heap,
34+
/// From the Python side, `PyCell<T>` is the concrete layout of `T: PyClass` in the Python heap,
3535
/// which means we can convert `*const PyClass<T>` to `*mut ffi::PyObject`.
3636
///
37-
/// From Rust side, `PyCell<T>` is the mutable container of `T`.
37+
/// From the Rust side, `PyCell<T>` is the mutable container of `T`.
3838
/// Since `PyCell<T: PyClass>` is always on the Python heap, we don't have the ownership of it.
3939
/// Thus, to mutate the data behind `&PyCell<T>` safely, we employ the
4040
/// [Interior Mutability Pattern](https://doc.rust-lang.org/book/ch15-05-interior-mutability.html)
@@ -46,7 +46,7 @@ unsafe impl<T, U> PyLayout<T> for PyCellBase<U> where U: PySizedLayout<T> {}
4646
/// # Examples
4747
///
4848
/// In most cases, `PyCell` is hidden behind `#[pymethods]`.
49-
/// However, you can construct `&PyCell` directly to test your pyclass in Rust code.
49+
/// However, you can construct a `&PyCell` directly to test your pyclass in Rust code.
5050
///
5151
/// ```
5252
/// # use pyo3::prelude::*;
@@ -67,7 +67,7 @@ unsafe impl<T, U> PyLayout<T> for PyCellBase<U> where U: PySizedLayout<T> {}
6767
/// });
6868
/// ```
6969
/// You can use `slf: &PyCell<Self>` as an alternative `self` receiver of `#[pymethod]`,
70-
/// though you rarely need it.
70+
/// though you'll rarely need it.
7171
/// ```
7272
/// # use pyo3::prelude::*;
7373
/// use std::collections::HashMap;
@@ -189,7 +189,7 @@ impl<T: PyClass> PyCell<T> {
189189
unsafe impl<T: PyClass> PyNativeType for PyCell<T> {}
190190

191191
impl<T: PyClass> PyCell<T> {
192-
/// Make a new `PyCell` on the Python heap and return the reference to it.
192+
/// Makes a new `PyCell` on the Python heap and return the reference to it.
193193
///
194194
/// In cases where the value in the cell does not need to be accessed immediately after
195195
/// creation, consider [`Py::new`](../instance/struct.Py.html#method.new) as a more efficient
@@ -202,7 +202,7 @@ impl<T: PyClass> PyCell<T> {
202202
}
203203
}
204204

205-
/// Immutably borrows the value `T`. This borrow lasts untill the returned `PyRef` exists.
205+
/// Immutably borrows the value `T`. This borrow lasts as long as the returned `PyRef` exists.
206206
///
207207
/// # Panics
208208
///
@@ -212,7 +212,7 @@ impl<T: PyClass> PyCell<T> {
212212
self.try_borrow().expect("Already mutably borrowed")
213213
}
214214

215-
/// Mutably borrows the value `T`. This borrow lasts untill the returned `PyRefMut` exists.
215+
/// Mutably borrows the value `T`. This borrow lasts as long as the returned `PyRefMut` exists.
216216
///
217217
/// # Panics
218218
///
@@ -223,7 +223,7 @@ impl<T: PyClass> PyCell<T> {
223223
}
224224

225225
/// Immutably borrows the value `T`, returning an error if the value is currently
226-
/// mutably borrowed. This borrow lasts untill the returned `PyRef` exists.
226+
/// mutably borrowed. This borrow lasts as long as the returned `PyRef` exists.
227227
///
228228
/// This is the non-panicking variant of [`borrow`](#method.borrow).
229229
///
@@ -257,7 +257,7 @@ impl<T: PyClass> PyCell<T> {
257257
}
258258

259259
/// Mutably borrows the value `T`, returning an error if the value is currently borrowed.
260-
/// This borrow lasts untill the returned `PyRefMut` exists.
260+
/// This borrow lasts as long as the returned `PyRefMut` exists.
261261
///
262262
/// This is the non-panicking variant of [`borrow_mut`](#method.borrow_mut).
263263
///
@@ -323,7 +323,7 @@ impl<T: PyClass> PyCell<T> {
323323
}
324324
}
325325

326-
/// Replaces the wrapped value with a new one, returning the old value,
326+
/// Replaces the wrapped value with a new one, returning the old value.
327327
///
328328
/// # Panics
329329
///
@@ -410,10 +410,12 @@ impl<T: PyClass + fmt::Debug> fmt::Debug for PyCell<T> {
410410
/// Wraps a borrowed reference to a value in a `PyCell<T>`.
411411
///
412412
/// See the [`PyCell`](struct.PyCell.html) documentation for more.
413+
///
413414
/// # Examples
414-
/// You can use `PyRef` as an alternative of `&self` receiver when
415-
/// - You need to access the pointer of `PyCell`.
416-
/// - You want to get super class.
415+
///
416+
/// You can use `PyRef` as an alternative to a `&self` receiver when
417+
/// - you need to access the pointer of the `PyCell`, or
418+
/// - you want to get a super class.
417419
/// ```
418420
/// # use pyo3::prelude::*;
419421
/// #[pyclass(subclass)]
@@ -449,8 +451,8 @@ pub struct PyRef<'p, T: PyClass> {
449451
}
450452

451453
impl<'p, T: PyClass> PyRef<'p, T> {
452-
/// Returns `Python` token.
453-
/// This function is safe since PyRef has the same lifetime as a `GILGuard`.
454+
/// Returns a `Python` token.
455+
/// This function is safe since `PyRef` has the same lifetime as a `GILGuard`.
454456
pub fn py(&self) -> Python {
455457
unsafe { Python::assume_gil_acquired() }
456458
}
@@ -471,8 +473,13 @@ where
471473
T: PyClass<BaseType = U>,
472474
U: PyClass,
473475
{
474-
/// Get `PyRef<T::BaseType>`.
475-
/// You can use this method to get super class of super class.
476+
/// Gets a `PyRef<T::BaseType>`.
477+
///
478+
/// While `as_ref()` returns a reference of type `&T::BaseType`, this cannot be
479+
/// used to get the base of `T::BaseType`.
480+
///
481+
/// But with the help of this method, you can get hold of instances of the
482+
/// super-superclass when needed.
476483
///
477484
/// # Examples
478485
/// ```
@@ -560,14 +567,14 @@ impl<T: PyClass + fmt::Debug> fmt::Debug for PyRef<'_, T> {
560567

561568
/// Wraps a mutable borrowed reference to a value in a `PyCell<T>`.
562569
///
563-
/// See the [`PyCell`](struct.PyCell.html) and [`PyRef`](struct.PyRef.html) documentations for more.
570+
/// See the [`PyCell`](struct.PyCell.html) and [`PyRef`](struct.PyRef.html) documentation for more.
564571
pub struct PyRefMut<'p, T: PyClass> {
565572
inner: &'p PyCell<T>,
566573
}
567574

568575
impl<'p, T: PyClass> PyRefMut<'p, T> {
569-
/// Returns `Python` token.
570-
/// This function is safe since PyRefMut has the same lifetime as a `GILGuard`.
576+
/// Returns a `Python` token.
577+
/// This function is safe since `PyRefMut` has the same lifetime as a `GILGuard`.
571578
pub fn py(&self) -> Python {
572579
unsafe { Python::assume_gil_acquired() }
573580
}
@@ -598,8 +605,8 @@ where
598605
T: PyClass<BaseType = U>,
599606
U: PyClass,
600607
{
601-
/// Get `PyRef<T::BaseType>`.
602-
/// See [`PyRef::into_super`](struct.PyRef.html#method.into_super) for more.
608+
/// Gets a `PyRef<T::BaseType>`.
609+
/// See [`PyRef::into_super`](struct.PyRef.html#method.into_super) for more.
603610
pub fn into_super(self) -> PyRefMut<'p, U> {
604611
let PyRefMut { inner } = self;
605612
std::mem::forget(self);
@@ -673,7 +680,7 @@ impl BorrowFlag {
673680

674681
/// An error returned by [`PyCell::try_borrow`](struct.PyCell.html#method.try_borrow).
675682
///
676-
/// In Python, you can catch this error by `except RuntimeError`.
683+
/// In Python, you can catch this error using `except RuntimeError`.
677684
pub struct PyBorrowError {
678685
_private: (),
679686
}
@@ -698,7 +705,7 @@ impl From<PyBorrowError> for PyErr {
698705

699706
/// An error returned by [`PyCell::try_borrow_mut`](struct.PyCell.html#method.try_borrow_mut).
700707
///
701-
/// In Python, you can catch this error by `except RuntimeError`.
708+
/// In Python, you can catch this error using `except RuntimeError`.
702709
pub struct PyBorrowMutError {
703710
_private: (),
704711
}

0 commit comments

Comments
 (0)