Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
glevco committed Sep 20, 2024
1 parent 5d95fba commit 46b18cc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
5 changes: 0 additions & 5 deletions guide/src/python-from-rust/calling-existing-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/types/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<N>(py: Python<'_>, name: N) -> PyResult<Bound<'_, PyModule>>
where
N: IntoPy<Py<PyString>>,
Expand Down

0 comments on commit 46b18cc

Please sign in to comment.