You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guide/src/conversions/tables.md
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
## Mapping of Rust types to Python types
2
2
3
-
When writing functions callable from Python (such as a `#[pyfunction]` or in a `#[pymethods]` block), the trait `FromPyObject` is required for function arguments, and `IntoPy<PyObject>` is required for function return values.
3
+
When writing functions callable from Python (such as a `#[pyfunction]` or in a `#[pymethods]` block), the trait `FromPyObject` is required for function arguments, and `IntoPyObject` is required for function return values.
4
4
5
5
Consult the tables in the following section to find the Rust types provided by PyO3 which implement these traits.
6
6
@@ -54,7 +54,6 @@ It is also worth remembering the following special types:
54
54
|`Python<'py>`| A GIL token, used to pass to PyO3 constructors to prove ownership of the GIL. |
55
55
|`Bound<'py, T>`| A Python object connected to the GIL lifetime. This provides access to most of PyO3's APIs. |
56
56
|`Py<T>`| A Python object isolated from the GIL lifetime. This can be sent to other threads. |
57
-
|`PyObject`| An alias for `Py<PyAny>`|
58
57
|`PyRef<T>`| A `#[pyclass]` borrowed immutably. |
59
58
|`PyRefMut<T>`| A `#[pyclass]` borrowed mutably. |
Copy file name to clipboardExpand all lines: guide/src/migration.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,14 @@ For this reason we chose to rename these to more modern terminology introduced i
16
16
-`pyo3::prepare_freethreaded_python` is now called `Python::initialize`.
17
17
</details>
18
18
19
+
### Deprecation of `PyObject` type alias
20
+
<detailsopen>
21
+
<summary><small>Click to expand</small></summary>
22
+
23
+
The type alias `PyObject` (aka `Py<PyAny>`) is often confused with the identically named FFI definition `pyo3::ffi::PyObject`. For this reason we are deprecating its usage. To migrate simply replace its usage by the target type `Py<PyAny>`.
24
+
25
+
</details>
26
+
19
27
### Deprecation of `GILProtected`
20
28
<detailsopen>
21
29
<summary><small>Click to expand</small></summary>
@@ -186,6 +194,7 @@ impl ToPyObject for MyPyObjectWrapper {
Copy file name to clipboardExpand all lines: guide/src/python-from-rust/function-calls.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,9 +12,9 @@ Both of these APIs take `args` and `kwargs` arguments (for positional and keywor
12
12
*[`call1`]({{#PYO3_DOCS_URL}}/pyo3/types/trait.PyAnyMethods.html#tymethod.call1) and [`call_method1`]({{#PYO3_DOCS_URL}}/pyo3/types/trait.PyAnyMethods.html#tymethod.call_method1) to call only with positional `args`.
13
13
*[`call0`]({{#PYO3_DOCS_URL}}/pyo3/types/trait.PyAnyMethods.html#tymethod.call0) and [`call_method0`]({{#PYO3_DOCS_URL}}/pyo3/types/trait.PyAnyMethods.html#tymethod.call_method0) to call with no arguments.
14
14
15
-
For convenience the [`Py<T>`](../types.md#pyt-and-pyobject) smart pointer also exposes these same six API methods, but needs a `Python` token as an additional first argument to prove the GIL is held.
15
+
For convenience the [`Py<T>`](../types.md#pyt) smart pointer also exposes these same six API methods, but needs a `Python` token as an additional first argument to prove the GIL is held.
16
16
17
-
The example below calls a Python function behind a `PyObject` (aka `Py<PyAny>`) reference:
17
+
The example below calls a Python function behind a `Py<PyAny>` reference:
Copy file name to clipboardExpand all lines: guide/src/trait-bounds.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ How could we expose this solver to Python thanks to PyO3 ?
44
44
## Implementation of the trait bounds for the Python class
45
45
46
46
If a Python class implements the same three methods as the `Model` trait, it seems logical it could be adapted to use the solver.
47
-
However, it is not possible to pass a `PyObject` to it as it does not implement the Rust trait (even if the Python model has the required methods).
47
+
However, it is not possible to pass a `Py<PyAny>` to it as it does not implement the Rust trait (even if the Python model has the required methods).
48
48
49
49
In order to implement the trait, we must write a wrapper around the calls in Rust to the Python model.
50
50
The method signatures must be the same as the trait, keeping in mind that the Rust trait cannot be changed for the purpose of making the code available in Python.
0 commit comments