Skip to content

Commit

Permalink
fixup migration guide examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Sep 3, 2024
1 parent e33212c commit f1bf682
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions guide/src/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ was not needed in the first place.

Before:

```rust,ignore
```rust
# fn main() {
# #[cfg(not(Py_GIL_DISABLED))] {
# use pyo3::prelude::*;
use pyo3::sync::GILProtected;
use pyo3::types::{PyDict, PyNone};
Expand All @@ -232,14 +234,13 @@ use std::cell::RefCell;
static OBJECTS: GILProtected<RefCell<Vec<Py<PyDict>>>> =
GILProtected::new(RefCell::new(Vec::new()));

fn main() {
Python::with_gil(|py: Python| {
let d = PyDict::new(py);
// stand-in for something that executes arbitrary python code
d.set_item(PyNone::get(py), PyNone::get(py)).unwrap();
OBJECTS.get(py).borrow_mut().push(d.unbind());
});
}
Python::with_gil(|py| {
// stand-in for something that executes arbitrary python code
let d = PyDict::new(py);
d.set_item(PyNone::get(py), PyNone::get(py)).unwrap();
OBJECTS.get(py).borrow_mut().push(d.unbind());
});
# }}
```

After:
Expand All @@ -262,8 +263,8 @@ static OBJECTS: Mutex<Vec<Py<PyDict>>> = Mutex::new(Vec::new());

fn main() {
Python::with_gil(|py| {
let d = PyDict::new(py);
// stand-in for something that executes arbitrary python code
let d = PyDict::new(py);
d.set_item(PyNone::get(py), PyNone::get(py)).unwrap();
#[cfg(not(Py_GIL_DISABLED))]
OBJECTS.get(py).borrow_mut().push(d.unbind());
Expand Down

0 comments on commit f1bf682

Please sign in to comment.