Skip to content

Commit 6cf6532

Browse files
committed
add migration guide entry
1 parent adc2b5a commit 6cf6532

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

guide/src/migration.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,41 @@
33
This guide can help you upgrade code through breaking changes from one PyO3 version to the next.
44
For a detailed list of all changes, see the [CHANGELOG](changelog.md).
55

6+
## from 0.21.* to 0.22
7+
8+
### Deprecation of implicit default for trailing optional arguments
9+
<details open>
10+
<summary><small>Click to expand</small></summary>
11+
12+
With `pyo3` 0.22 the implicit `None` default for trailing `Option<T>` type argument is deprecated. To migrate, place a `#[pyo3(signature = (...))]` attribute on affected functions or methods and specify the desired behavior.
13+
The migration warning specifies the corresponding signature to keep the current behavior. With 0.23 the signature will be required for any function containing `Option<T>` type parameters to prevent accidental
14+
and unnoticed changes in behavior. With 0.24 this restriction will be lifted again and `Option<T>` type arguments will be treated as any other argument _without_ special handling.
15+
16+
Before:
17+
18+
```rust
19+
# #![allow(deprecated, dead_code)]
20+
# use pyo3::prelude::*;
21+
#[pyfunction]
22+
fn increment(x: u64, amount: Option<u64>) -> u64 {
23+
x + amount.unwrap_or(1)
24+
}
25+
```
26+
27+
After:
28+
29+
```rust
30+
# #![allow(dead_code)]
31+
# use pyo3::prelude::*;
32+
#[pyfunction]
33+
#[pyo3(signature = (x, amount=None))]
34+
fn increment(x: u64, amount: Option<u64>) -> u64 {
35+
x + amount.unwrap_or(1)
36+
}
37+
```
38+
39+
</details>
40+
641
## from 0.20.* to 0.21
742
<details open>
843
<summary><small>Click to expand</small></summary>

0 commit comments

Comments
 (0)