Skip to content

Commit 41fb957

Browse files
authored
docs: update docstring on Python for Bound API (#4274)
1 parent 9ff3d23 commit 41fb957

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/marker.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -311,22 +311,25 @@ pub use nightly::Ungil;
311311
/// - It can be passed to functions that require a proof of holding the GIL, such as
312312
/// [`Py::clone_ref`].
313313
/// - Its lifetime represents the scope of holding the GIL which can be used to create Rust
314-
/// references that are bound to it, such as `&`[`PyAny`].
314+
/// references that are bound to it, such as [`Bound<'py, PyAny>`].
315315
///
316316
/// Note that there are some caveats to using it that you might need to be aware of. See the
317317
/// [Deadlocks](#deadlocks) and [Releasing and freeing memory](#releasing-and-freeing-memory)
318318
/// paragraphs for more information about that.
319319
///
320320
/// # Obtaining a Python token
321321
///
322-
/// The following are the recommended ways to obtain a [`Python`] token, in order of preference:
322+
/// The following are the recommended ways to obtain a [`Python<'py>`] token, in order of preference:
323+
/// - If you already have something with a lifetime bound to the GIL, such as [`Bound<'py, PyAny>`], you can
324+
/// use its `.py()` method to get a token.
323325
/// - In a function or method annotated with [`#[pyfunction]`](crate::pyfunction) or [`#[pymethods]`](crate::pymethods) you can declare it
324326
/// as a parameter, and PyO3 will pass in the token when Python code calls it.
325-
/// - If you already have something with a lifetime bound to the GIL, such as `&`[`PyAny`], you can
326-
/// use its `.py()` method to get a token.
327327
/// - When you need to acquire the GIL yourself, such as when calling Python code from Rust, you
328328
/// should call [`Python::with_gil`] to do that and pass your code as a closure to it.
329329
///
330+
/// The first two options are zero-cost; [`Python::with_gil`] requires runtime checking and may need to block
331+
/// to acquire the GIL.
332+
///
330333
/// # Deadlocks
331334
///
332335
/// Note that the GIL can be temporarily released by the Python interpreter during a function call
@@ -353,14 +356,8 @@ pub use nightly::Ungil;
353356
///
354357
/// # Releasing and freeing memory
355358
///
356-
/// The [`Python`] type can be used to create references to variables owned by the Python
359+
/// The [`Python<'py>`] type can be used to create references to variables owned by the Python
357360
/// interpreter, using functions such as [`Python::eval_bound`] and [`PyModule::import_bound`].
358-
///
359-
/// See the [Memory Management] chapter of the guide for more information about how PyO3 manages memory.
360-
///
361-
/// [scoping rules]: https://doc.rust-lang.org/stable/book/ch04-01-what-is-ownership.html#ownership-rules
362-
/// [`Py::clone_ref`]: crate::Py::clone_ref
363-
/// [Memory Management]: https://pyo3.rs/main/memory.html#gil-bound-memory
364361
#[derive(Copy, Clone)]
365362
pub struct Python<'py>(PhantomData<(&'py GILGuard, NotSend)>);
366363

0 commit comments

Comments
 (0)