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: Contributing.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
@@ -184,7 +184,7 @@ PyO3 supports all officially supported Python versions, as well as the latest Py
184
184
If you plan to add support for a pre-release version of CPython, here's a (non-exhaustive) checklist:
185
185
186
186
-[ ] Wait until the last alpha release (usually alpha7), since ABI is not guaranteed until the first beta release
187
-
-[ ] Add prerelease_ver-dev (e.g. `3.14-dev`) to `.github/workflows/ci.yml`, and bump version in `noxfile.py`, `pyo3-ffi/Cargo.toml` under `max-version` within `[package.metadata.cpython]`, and `max` within `pyo3-ffi/build.rs`
187
+
-[ ] Add prerelease_ver-dev (e.g. `3.14-dev`) to `.github/workflows/ci.yml`, and bump version in `noxfile.py`, `pyo3-ffi/Cargo.toml` under `max-version` within `[package.metadata.cpython]`, and `max` within `pyo3-ffi/build.rs`
188
188
-[ ] Add a new abi3-prerelease feature for the version (e.g. `abi3-py314`)
189
189
- In `pyo3-build-config/Cargo.toml`, set abi3-most_current_stable to ["abi3-prerelease"] and abi3-prerelease to ["abi3"]
190
190
- In `pyo3-ffi/Cargo.toml`, set abi3-most_current_stable to ["abi3-prerelease", "pyo3-build-config/abi3-most_current_stable"] and abi3-prerelease to ["abi3", "pyo3-build-config/abi3-prerelease"]
Copy file name to clipboardExpand all lines: guide/pyclass-parameters.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@
9
9
|`eq_int`| Implements `__eq__` using `__int__` for simple enums. |
10
10
| <spanstyle="white-space: pre">`extends = BaseType`</span> | Use a custom baseclass. Defaults to [`PyAny`][params-1]|
11
11
| <spanstyle="white-space: pre">`freelist = N`</span> | Implements a [free list][params-2] of size N. This can improve performance for types that are often created and deleted in quick succession. Profile your code to see whether `freelist` is right for you. |
12
+
|`from_py_object`| Implement `FromPyObject` for this pyclass. Requires the pyclass to be `Clone`. |
12
13
| <spanstyle="white-space: pre">`frozen`</span> | Declares that your pyclass is immutable. It removes the borrow checker overhead when retrieving a shared reference to the Rust struct, but disables the ability to get a mutable reference. |
13
14
|`generic`| Implements runtime parametrization for the class following [PEP 560](https://peps.python.org/pep-0560/). |
14
15
|`get_all`| Generates getters for all fields of the pyclass. |
@@ -21,6 +22,7 @@
21
22
|`rename_all = "renaming_rule"`| Applies renaming rules to every getters and setters of a struct, or every variants of an enum. Possible values are: "camelCase", "kebab-case", "lowercase", "PascalCase", "SCREAMING-KEBAB-CASE", "SCREAMING_SNAKE_CASE", "snake_case", "UPPERCASE". |
22
23
|`sequence`| Inform PyO3 that this class is a [`Sequence`][params-sequence], and so leave its C-API mapping length slot empty. |
23
24
|`set_all`| Generates setters for all fields of the pyclass. |
25
+
|`skip_from_py_object`| Prevents this PyClass from participating in the `FromPyObject: PyClass + Clone` blanket implementation. This allows a custom `FromPyObject` impl, even if `self` is `Clone`. |
24
26
|`str`| Implements `__str__` using the `Display` implementation of the underlying Rust datatype or by passing an optional format string `str="<format string>"`. *Note: The optional format string is only allowed for structs. `name` and `rename_all` are incompatible with the optional format string. Additional details can be found in the discussion on this [PR](https://github.com/PyO3/pyo3/pull/4233).*|
25
27
|`subclass`| Allows other Python classes and `#[pyclass]` to inherit from this class. Enums cannot be subclassed. |
26
28
|`unsendable`| Required if your struct is not [`Send`][params-3]. Rather than using `unsendable`, consider implementing your struct in a thread-safe way by e.g. substituting [`Rc`][params-4] with [`Arc`][params-5]. By using `unsendable`, your class will panic when accessed by another thread. Also note the Python's GC is multi-threaded and while unsendable classes will not be traversed on foreign threads to avoid UB, this can lead to memory leaks. |
#### ⚠ Phase-Out of `FromPyObject` blanket implementation for cloneable PyClasses ⚠
539
+
Historically PyO3 has provided a blanket implementation for `#[pyclass]` types that also implement `Clone`, to allow extraction of such types by value. Over time this has turned out problematic for a few reasons, the major one being the prevention of custom conversions by downstream crates if their type is `Clone`. Over the next few releases the blanket implementation is gradually phased out, and eventually replaced by an opt-in option. As a first step of this migration a new `skip_from_py_object` option for `#[pyclass]` was introduced, to opt-out of the blanket implementation and allow downstream users to provide their own implementation:
540
+
```rust
541
+
# #![allow(dead_code)]
542
+
# usepyo3::prelude::*;
543
+
544
+
#[pyclass(skip_from_py_object)] // opt-out of the PyO3 FromPyObject blanket
As a second step the `from_py_object` option was introduced. This option also opts-out of the blanket implementation and instead generates a custom `FromPyObject` implementation for the pyclass which is functionally equivalent to the blanket.
562
+
538
563
### `IntoPyObject`
539
564
The [`IntoPyObject`] trait defines the to-python conversion for a Rust type. All types in PyO3 implement this trait,
540
565
as does a `#[pyclass]` which doesn't use `extends`.
0 commit comments