Skip to content

Commit

Permalink
add migration guide entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Icxolu committed May 10, 2024
1 parent adc2b5a commit 6cf6532
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions guide/src/migration.md
Expand Up @@ -3,6 +3,41 @@
This guide can help you upgrade code through breaking changes from one PyO3 version to the next.
For a detailed list of all changes, see the [CHANGELOG](changelog.md).

## from 0.21.* to 0.22

### Deprecation of implicit default for trailing optional arguments
<details open>
<summary><small>Click to expand</small></summary>

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.
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
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.

Before:

```rust
# #![allow(deprecated, dead_code)]
# use pyo3::prelude::*;
#[pyfunction]
fn increment(x: u64, amount: Option<u64>) -> u64 {
x + amount.unwrap_or(1)
}
```

After:

```rust
# #![allow(dead_code)]
# use pyo3::prelude::*;
#[pyfunction]
#[pyo3(signature = (x, amount=None))]
fn increment(x: u64, amount: Option<u64>) -> u64 {
x + amount.unwrap_or(1)
}
```

</details>

## from 0.20.* to 0.21
<details open>
<summary><small>Click to expand</small></summary>
Expand Down

0 comments on commit 6cf6532

Please sign in to comment.