From 46b18cc0a56a52987dc5c009c0a68f809fbacda8 Mon Sep 17 00:00:00 2001 From: Gabriel Levcovitz Date: Fri, 20 Sep 2024 13:12:12 -0300 Subject: [PATCH] update docs --- guide/src/python-from-rust/calling-existing-code.md | 5 ----- src/sync.rs | 2 +- src/types/module.rs | 3 +++ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/guide/src/python-from-rust/calling-existing-code.md b/guide/src/python-from-rust/calling-existing-code.md index 5069bc3c3bb..aae4317ae2c 100644 --- a/guide/src/python-from-rust/calling-existing-code.md +++ b/guide/src/python-from-rust/calling-existing-code.md @@ -23,11 +23,6 @@ fn main() -> PyResult<()> { } ``` -[`PyModule::import`] introduces an overhead each time it's called. To avoid this in functions that are called multiple times, -using a [`GILOnceCell`]({{#PYO3_DOCS_URL}}/pyo3/sync/struct.GILOnceCell.html) is recommended. Specifically, for importing types, -[`GILOnceCell::import`]({{#PYO3_DOCS_URL}}/pyo3/sync/struct.GILOnceCell.html#method.import) is provided -(check out the [example]({{#PYO3_DOCS_URL}}/pyo3/sync/struct.GILOnceCell.html#example-using-giloncecell-to-avoid-the-overhead-of-importing-a-class-multiple-times)). - [`PyModule::import`]: {{#PYO3_DOCS_URL}}/pyo3/types/struct.PyModule.html#method.import ## Want to run just an expression? Then use `eval`. diff --git a/src/sync.rs b/src/sync.rs index 8ed5336e345..b02b21def93 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -224,7 +224,7 @@ where /// /// # Example: Using `GILOnceCell` to store a class in a static variable. /// - /// `GILOnceCell` can be used to avoid importing a class multiple times + /// `GILOnceCell` can be used to avoid importing a class multiple times: /// ``` /// # use pyo3::prelude::*; /// # use pyo3::sync::GILOnceCell; diff --git a/src/types/module.rs b/src/types/module.rs index 7307dfd4c2d..aec3ea0c179 100644 --- a/src/types/module.rs +++ b/src/types/module.rs @@ -79,6 +79,9 @@ impl PyModule { /// ```python /// import antigravity /// ``` + /// + /// If you want to import a class, you can store a reference to it with + /// [`GILOnceCell::import`][crate::sync::GILOnceCell#method.import]. pub fn import(py: Python<'_>, name: N) -> PyResult> where N: IntoPy>,